1# 2# Function library: provide common functions 3# 4# Copyright (C) 2008, Intel Corp. 5# Author: Huang Ying <ying.huang@intel.com> 6# 7# This file is released under the GPLv2. 8# 9 10setup_path() 11{ 12 export PATH=$ROOT/bin:$PATH 13} 14 15script_dir() 16{ 17 local rd=$(dirname "$0") 18 (cd $rd; pwd) 19} 20 21relative_path() 22{ 23 local len1=${#1} 24 local len2=${#2} 25 if [ $len1 -eq 0 -o $len1 -ge $len2 -o "${2:0:$len1}" != "$1" ]; then 26 die "$2 is not the sub-path of $1!" 27 fi 28 len1=$((len1 + 1)) 29 echo "${2:$len1}" 30} 31 32die() 33{ 34 echo "DIE: $@" 35 echo "DIE: $@" 1>&2 36 exit -1 37} 38 39driver_prepare() 40{ 41 mkdir -p $WDIR/stamps 42} 43 44check_kern_warning_bug() 45{ 46 local f="$1" 47 [ -n "$f" ] || die "missing parameter for check_kern_warning" 48 grep -e '----\[ cut here \]---' $f > /dev/null || \ 49 grep -e 'BUG:' $f > /dev/null 50} 51 52random_sleep() 53{ 54 local s=$((RANDOM / 13107 + 5)) 55 sleep $s 56} 57 58start_background() 59{ 60 if [ -n "$BACKGROUND" ]; then 61 pid_background=$(bash -i -c "$BACKGROUND &>$WDIR/background_log & echo \$!") 62 if ! ps -p $pid_background > /dev/null; then 63 die "Failed to start background testing: $BACKGROUND" 64 fi 65 fi 66} 67 68stop_background() 69{ 70 if [ -n "$pid_background" ]; then 71 if ! kill -TERM -$pid_background &> /dev/null; then 72 kill $pid_background || true 73 fi 74 fi 75} 76 77filter_fake_panic() 78{ 79 local orig_klog=$1 80 local new_klog=$2 81 [ $# -eq 2 ] || die "missing parameter for filter_fake_panic" 82 83 local pn 84 pn=$(grep -n "Fake kernel panic" $orig_klog | cut -d ':' -f 1 | head -1) 85 if [ -z "$pn" ]; then 86 cp $orig_klog $new_klog 87 else 88 sed -n "1,${pn}p" < $orig_klog > $new_klog 89 fi 90} 91