xref: /kvm-unit-tests/run_tests.sh (revision 8b13a5b5cfdb26920c8f631a1e56e7a5eac917fe)
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        and those guarded by errata.
23    -g: Only execute tests in the given group
24    -j: Execute tests in parallel
25
26Set the environment variable QEMU=/path/to/qemu-system-ARCH to
27specify the appropriate qemu binary for ARCH-run.
28
29EOF
30}
31
32RUNTIME_arch_run="./$TEST_DIR/run"
33source scripts/runtime.bash
34
35while getopts "ag:hj:v" opt; do
36    case $opt in
37        a)
38            run_all_tests="yes"
39            export ERRATA_FORCE=y
40            ;;
41        g)
42            only_group=$OPTARG
43            ;;
44        h)
45            usage
46            exit
47            ;;
48        j)
49            unittest_run_queues=$OPTARG
50            if (( $unittest_run_queues <= 0 )); then
51                echo "Invalid -j option: $unittest_run_queues"
52                exit 2
53            fi
54            ;;
55        v)
56            verbose="yes"
57            ;;
58        *)
59            exit 2
60            ;;
61    esac
62done
63
64# RUNTIME_log_file will be configured later
65RUNTIME_log_stderr () { cat >> $RUNTIME_log_file; }
66RUNTIME_log_stdout () {
67    if [ "$PRETTY_PRINT_STACKS" = "yes" ]; then
68        ./scripts/pretty_print_stacks.py $1 >> $RUNTIME_log_file
69    else
70        cat >> $RUNTIME_log_file
71    fi
72}
73
74function run_task()
75{
76	local testname="$1"
77
78	while (( $(jobs | wc -l) == $unittest_run_queues )); do
79		# wait for any background test to finish
80		wait -n 2>/dev/null
81	done
82
83	RUNTIME_log_file="${unittest_log_dir}/${testname}.log"
84	if [ $unittest_run_queues = 1 ]; then
85		run "$@"
86	else
87		run "$@" &
88	fi
89}
90
91: ${unittest_log_dir:=logs}
92: ${unittest_run_queues:=1}
93config=$TEST_DIR/unittests.cfg
94
95rm -rf $unittest_log_dir.old
96[ -d $unittest_log_dir ] && mv $unittest_log_dir $unittest_log_dir.old
97mkdir $unittest_log_dir || exit 2
98
99echo "BUILD_HEAD=$(cat build-head)" > $unittest_log_dir/SUMMARY
100
101trap "wait; exit 130" SIGINT
102for_each_unittest $config run_task
103
104# wait until all tasks finish
105wait
106