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