1#!/usr/bin/env bash 2 3verbose="no" 4run_all_tests="no" # don't run nodefault tests 5 6if [ ! -f config.mak ]; then 7 echo "run ./configure && make first. See ./configure -h" 8 exit 1 9fi 10source config.mak 11source scripts/common.bash 12 13function usage() 14{ 15cat <<EOF 16 17Usage: $0 [-h] [-v] [-a] [-g group] [-j NUM-TASKS] 18 19 -h: Output this help text 20 -v: Enables verbose mode 21 -a: Run all tests, including those flagged as 'nodefault' 22 -g: Only execute tests in the given group 23 -j: Execute tests in parallel 24 25Set the environment variable QEMU=/path/to/qemu-system-ARCH to 26specify the appropriate qemu binary for ARCH-run. 27 28EOF 29} 30 31RUNTIME_arch_run="./$TEST_DIR/run" 32source scripts/runtime.bash 33 34while getopts "ag:hj:v" opt; do 35 case $opt in 36 a) 37 run_all_tests="yes" 38 ;; 39 g) 40 only_group=$OPTARG 41 ;; 42 h) 43 usage 44 exit 45 ;; 46 j) 47 unittest_run_queues=$OPTARG 48 if (( $unittest_run_queues <= 0 )); then 49 echo "Invalid -j option: $unittest_run_queues" 50 exit 2 51 fi 52 ;; 53 v) 54 verbose="yes" 55 ;; 56 *) 57 exit 2 58 ;; 59 esac 60done 61 62# RUNTIME_log_file will be configured later 63RUNTIME_log_stderr () { cat >> $RUNTIME_log_file; } 64RUNTIME_log_stdout () { 65 if [ "$PRETTY_PRINT_STACKS" = "yes" ]; then 66 ./scripts/pretty_print_stacks.py $1 >> $RUNTIME_log_file 67 else 68 cat >> $RUNTIME_log_file 69 fi 70} 71 72function run_task() 73{ 74 local testname="$1" 75 76 while (( $(jobs | wc -l) == $unittest_run_queues )); do 77 # wait for any background test to finish 78 wait -n 2>/dev/null 79 done 80 81 RUNTIME_log_file="${unittest_log_dir}/${testname}.log" 82 if [ $unittest_run_queues = 1 ]; then 83 run "$@" 84 else 85 run "$@" & 86 fi 87} 88 89: ${unittest_log_dir:=logs} 90: ${unittest_run_queues:=1} 91config=$TEST_DIR/unittests.cfg 92 93rm -rf $unittest_log_dir.old 94[ -d $unittest_log_dir ] && mv $unittest_log_dir $unittest_log_dir.old 95mkdir $unittest_log_dir || exit 2 96 97echo "BUILD_HEAD=$(cat build-head)" > $unittest_log_dir/SUMMARY 98 99trap "wait; exit 130" SIGINT 100for_each_unittest $config run_task 101 102# wait until all tasks finish 103wait 104