-
Notifications
You must be signed in to change notification settings - Fork 27
/
run_tests.sh
executable file
·177 lines (155 loc) · 4.32 KB
/
run_tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env bash
verbose="no"
tap_output="no"
run_all_tests="no" # don't run nodefault tests
if [ ! -f config.mak ]; then
echo "run ./configure && make first. See ./configure -h"
exit 1
fi
source config.mak
source scripts/common.bash
function usage()
{
cat <<EOF
Usage: $0 [-h] [-v] [-a] [-g group] [-j NUM-TASKS] [-t]
-h, --help Output this help text
-v, --verbose Enables verbose mode
-a, --all Run all tests, including those flagged as 'nodefault'
and those guarded by errata.
-g, --group Only execute tests in the given group
-j, --parallel Execute tests in parallel
-t, --tap13 Output test results in TAP format
Set the environment variable QEMU=/path/to/qemu-system-ARCH to
specify the appropriate qemu binary for ARCH-run.
EOF
}
RUNTIME_arch_run="./$TEST_SUBDIR/run"
source scripts/runtime.bash
# require enhanced getopt
getopt -T > /dev/null
if [ $? -ne 4 ]; then
echo "Enhanced getopt is not available, add it to your PATH?"
exit 1
fi
only_tests=""
args=$(getopt -u -o ag:htj:v -l all,group:,help,tap13,parallel:,verbose -- $*)
[ $? -ne 0 ] && exit 2;
set -- $args;
while [ $# -gt 0 ]; do
case "$1" in
-a | --all)
run_all_tests="yes"
export ERRATA_FORCE=y
;;
-g | --group)
shift
only_group=$1
;;
-h | --help)
usage
exit
;;
-j | --parallel)
shift
unittest_run_queues=$1
if (( $unittest_run_queues <= 0 )); then
echo "Invalid -j option: $unittest_run_queues"
exit 2
fi
;;
-v | --verbose)
verbose="yes"
;;
-t | --tap13)
tap_output="yes"
;;
--)
;;
*)
only_tests="$only_tests $1"
;;
esac
shift
done
# RUNTIME_log_file will be configured later
if [[ $tap_output == "no" ]]; then
process_test_output() { cat >> $RUNTIME_log_file; }
postprocess_suite_output() { cat; }
else
process_test_output() {
local testname="$1"
CR=$'\r'
while read -r line; do
line="${line%$CR}"
case "${line:0:4}" in
PASS)
echo "ok TEST_NUMBER - ${testname}: ${line#??????}" >&3
;;
FAIL)
echo "not ok TEST_NUMBER - ${testname}: ${line#??????}" >&3
;;
SKIP)
echo "ok TEST_NUMBER - ${testname}: ${line#??????} # skip" >&3
;;
*)
;;
esac
echo "${line}"
done >> $RUNTIME_log_file
}
postprocess_suite_output() {
test_number=0
while read -r line; do
case "${line}" in
ok*|"not ok"*)
(( test_number++ ))
echo "${line/TEST_NUMBER/${test_number}}" ;;
*) echo "${line}" ;;
esac
done
echo "1..$test_number"
}
fi
RUNTIME_log_stderr () { process_test_output "$1"; }
RUNTIME_log_stdout () {
local testname="$1"
if [ "$PRETTY_PRINT_STACKS" = "yes" ]; then
local kernel="$2"
./scripts/pretty_print_stacks.py "$kernel" | process_test_output "$testname"
else
process_test_output "$testname"
fi
}
function run_task()
{
local testname="$1"
while (( $(jobs | wc -l) == $unittest_run_queues )); do
# wait for any background test to finish
wait -n 2>/dev/null
done
RUNTIME_log_file="${unittest_log_dir}/${testname}.log"
if [ $unittest_run_queues = 1 ]; then
run "$@"
else
run "$@" &
fi
}
: ${unittest_log_dir:=logs}
: ${unittest_run_queues:=1}
config=$TEST_DIR/unittests.cfg
rm -rf $unittest_log_dir.old
[ -d $unittest_log_dir ] && mv $unittest_log_dir $unittest_log_dir.old
mkdir $unittest_log_dir || exit 2
echo "BUILD_HEAD=$(cat build-head)" > $unittest_log_dir/SUMMARY
if [[ $tap_output == "yes" ]]; then
echo "TAP version 13"
fi
trap "wait; exit 130" SIGINT
(
# preserve stdout so that process_test_output output can write TAP to it
exec 3>&1
test "$tap_output" == "yes" && exec > /dev/null
for_each_unittest $config run_task
) | postprocess_suite_output
# wait until all tasks finish
wait