xref: /kvm-unit-tests/scripts/runtime.bash (revision e9ae9613dfae8872a0162566d53d3906948fd739)
1: "${RUNTIME_arch_run?}"
2: ${MAX_SMP:=$(getconf _NPROCESSORS_CONF)}
3: ${TIMEOUT:=90s}
4
5PASS() { echo -ne "\e[32mPASS\e[0m"; }
6SKIP() { echo -ne "\e[33mSKIP\e[0m"; }
7FAIL() { echo -ne "\e[31mFAIL\e[0m"; }
8
9extract_summary()
10{
11    tail -1 | grep '^SUMMARY: ' | sed 's/^SUMMARY: /(/;s/$/)/'
12}
13
14function run()
15{
16    local testname="$1"
17    local groups="$2"
18    local smp="$3"
19    local kernel="$4"
20    local opts="$5"
21    local arch="$6"
22    local check="${CHECK:-$7}"
23    local accel="${ACCEL:-$8}"
24    local timeout="${9:-$TIMEOUT}" # unittests.cfg overrides the default
25
26    if [ -z "$testname" ]; then
27        return
28    fi
29
30    if [ -n "$only_group" ] && ! grep -q "$only_group" <<<$groups; then
31        return
32    fi
33
34    if [ -n "$arch" ] && [ "$arch" != "$ARCH" ]; then
35        echo "`SKIP` $1 ($arch only)"
36        return 2
37    fi
38
39    # check a file for a particular value before running a test
40    # the check line can contain multiple files to check separated by a space
41    # but each check parameter needs to be of the form <path>=<value>
42    for check_param in ${check[@]}; do
43        path=${check_param%%=*}
44        value=${check_param#*=}
45        if [ "$path" ] && [ "$(cat $path)" != "$value" ]; then
46            echo "`SKIP` $1 ($path not equal to $value)"
47            return 2
48        fi
49    done
50
51    cmdline="TESTNAME=$testname TIMEOUT=$timeout ACCEL=$accel $RUNTIME_arch_run $kernel -smp $smp $opts"
52    if [ "$verbose" = "yes" ]; then
53        echo $cmdline
54    fi
55
56    # extra_params in the config file may contain backticks that need to be
57    # expanded, so use eval to start qemu.  Use "> >(foo)" instead of a pipe to
58    # preserve the exit status.
59    summary=$(eval $cmdline > >(tee >(RUNTIME_log_stdout $kernel) | extract_summary))
60    ret=$?
61
62    if [ $ret -eq 0 ]; then
63        echo "`PASS` $1 $summary"
64    elif [ $ret -eq 77 ]; then
65        echo "`SKIP` $1 $summary"
66    elif [ $ret -eq 124 ]; then
67        echo "`FAIL` $1 (timeout; duration=$timeout)"
68    else
69        echo "`FAIL` $1 $summary"
70    fi
71
72    return $ret
73}
74
75#
76# Probe for MAX_SMP, in case it's less than the number of host cpus.
77#
78# This probing currently only works for ARM, as x86 bails on another
79# error first. Also, this probing isn't necessary for any ARM hosts
80# running kernels later than v4.3, i.e. those including ef748917b52
81# "arm/arm64: KVM: Remove 'config KVM_ARM_MAX_VCPUS'". So, at some
82# point when maintaining the while loop gets too tiresome, we can
83# just remove it...
84while $RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP \
85		|& grep -qi 'exceeds max CPUs'; do
86	((--MAX_SMP))
87done
88