1#!/bin/bash 2 3if [ ! -f config.mak ]; then 4 echo "run ./configure && make first. See ./configure -h" 5 exit 6fi 7source config.mak 8 9config=$TEST_DIR/unittests.cfg 10qemu=${QEMU:-qemu-system-$ARCH} 11verbose=0 12 13function run() 14{ 15 local testname="$1" 16 local groups="$2" 17 local smp="$3" 18 local kernel="$4" 19 local opts="$5" 20 local arch="$6" 21 local check="$7" 22 23 if [ -z "$testname" ]; then 24 return 25 fi 26 27 if [ -n "$only_group" ] && ! grep -q "$only_group" <<<$groups; then 28 return 29 fi 30 31 if [ -n "$arch" ] && [ "$arch" != "$ARCH" ]; then 32 echo "skip $1 ($arch only)" 33 return 34 fi 35 36 # check a file for a particular value before running a test 37 # the check line can contain multiple files to check separated by a space 38 # but each check parameter needs to be of the form <path>=<value> 39 for check_param in ${check[@]}; do 40 path=${check_param%%=*} 41 value=${check_param#*=} 42 if [ "$path" ] && [ "$(cat $path)" != "$value" ]; then 43 echo "skip $1 ($path not equal to $value)" 44 return 45 fi 46 done 47 48 cmdline="./$TEST_DIR-run $kernel -smp $smp $opts" 49 if [ $verbose != 0 ]; then 50 echo $cmdline 51 fi 52 53 # extra_params in the config file may contain backticks that need to be 54 # expanded, so use eval to start qemu 55 eval $cmdline >> test.log 56 57 if [ $? -le 1 ]; then 58 echo -e "\e[32mPASS\e[0m $1" 59 else 60 echo -e "\e[31mFAIL\e[0m $1" 61 fi 62} 63 64function run_all() 65{ 66 local config="$1" 67 local testname 68 local smp 69 local kernel 70 local opts 71 local groups 72 local arch 73 local check 74 75 exec {config_fd}<$config 76 77 while read -u $config_fd line; do 78 if [[ "$line" =~ ^\[(.*)\]$ ]]; then 79 run "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" 80 testname=${BASH_REMATCH[1]} 81 smp=1 82 kernel="" 83 opts="" 84 groups="" 85 arch="" 86 check="" 87 elif [[ $line =~ ^file\ *=\ *(.*)$ ]]; then 88 kernel=$TEST_DIR/${BASH_REMATCH[1]} 89 elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then 90 smp=${BASH_REMATCH[1]} 91 elif [[ $line =~ ^extra_params\ *=\ *(.*)$ ]]; then 92 opts=${BASH_REMATCH[1]} 93 elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then 94 groups=${BASH_REMATCH[1]} 95 elif [[ $line =~ ^arch\ *=\ *(.*)$ ]]; then 96 arch=${BASH_REMATCH[1]} 97 elif [[ $line =~ ^check\ *=\ *(.*)$ ]]; then 98 check=${BASH_REMATCH[1]} 99 fi 100 done 101 102 run "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" 103 104 exec {config_fd}<&- 105} 106 107function usage() 108{ 109cat <<EOF 110 111Usage: $0 [-g group] [-h] [-v] 112 113 -g: Only execute tests in the given group 114 -h: Output this help text 115 -v: Enables verbose mode 116 117Set the environment variable QEMU=/path/to/qemu-system-ARCH to 118specify the appropriate qemu binary for ARCH-run. 119 120EOF 121} 122 123echo > test.log 124while getopts "g:hv" opt; do 125 case $opt in 126 g) 127 only_group=$OPTARG 128 ;; 129 h) 130 usage 131 exit 132 ;; 133 v) 134 verbose=1 135 ;; 136 *) 137 exit 138 ;; 139 esac 140done 141 142run_all $config 143