xref: /kvm-unit-tests/run_tests.sh (revision d3aacb4f57d05f74f2030dbe12e7dfd6aa1b273d)
1#!/bin/bash
2
3if [ ! -f config.mak ]; then
4    echo "run ./configure && make first. See ./configure -h"
5    exit
6fi
7source config.mak
8
9config=$TEST_DIR/unittests.cfg
10qemu=${QEMU:-qemu-system-$ARCH}
11verbose=0
12
13function run()
14{
15    local testname="$1"
16    local groups="$2"
17    local smp="$3"
18    local kernel="$4"
19    local opts="$5"
20    local arch="$6"
21
22    if [ -z "$testname" ]; then
23        return
24    fi
25
26    if [ -n "$only_group" ] && ! grep -q "$only_group" <<<$groups; then
27        return
28    fi
29
30    if [ -n "$arch" ] && [ "$arch" != "$ARCH" ]; then
31        echo "skip $1 ($arch only)"
32        return
33    fi
34
35    cmdline="./$TEST_DIR-run $kernel -smp $smp $opts"
36    if [ $verbose != 0 ]; then
37        echo $cmdline
38    fi
39
40    # extra_params in the config file may contain backticks that need to be
41    # expanded, so use eval to start qemu
42    eval $cmdline >> test.log
43
44    if [ $? -le 1 ]; then
45        echo -e "\e[32mPASS\e[0m $1"
46    else
47        echo -e "\e[31mFAIL\e[0m $1"
48    fi
49}
50
51function run_all()
52{
53    local config="$1"
54    local testname
55    local smp
56    local kernel
57    local opts
58    local groups
59    local arch
60
61    exec {config_fd}<$config
62
63    while read -u $config_fd line; do
64        if [[ "$line" =~ ^\[(.*)\]$ ]]; then
65            run "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch"
66            testname=${BASH_REMATCH[1]}
67            smp=1
68            kernel=""
69            opts=""
70            groups=""
71            arch=""
72        elif [[ $line =~ ^file\ *=\ *(.*)$ ]]; then
73            kernel=$TEST_DIR/${BASH_REMATCH[1]}
74        elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then
75            smp=${BASH_REMATCH[1]}
76        elif [[ $line =~ ^extra_params\ *=\ *(.*)$ ]]; then
77            opts=${BASH_REMATCH[1]}
78        elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then
79            groups=${BASH_REMATCH[1]}
80        elif [[ $line =~ ^arch\ *=\ *(.*)$ ]]; then
81            arch=${BASH_REMATCH[1]}
82        fi
83    done
84
85    run "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch"
86
87    exec {config_fd}<&-
88}
89
90function usage()
91{
92cat <<EOF
93
94Usage: $0 [-g group] [-h] [-v]
95
96    -g: Only execute tests in the given group
97    -h: Output this help text
98    -v: Enables verbose mode
99
100Set the environment variable QEMU=/path/to/qemu-system-ARCH to
101specify the appropriate qemu binary for ARCH-run.
102
103EOF
104}
105
106echo > test.log
107while getopts "g:hv" opt; do
108    case $opt in
109        g)
110            only_group=$OPTARG
111            ;;
112        h)
113            usage
114            exit
115            ;;
116        v)
117            verbose=1
118            ;;
119        *)
120            exit
121            ;;
122    esac
123done
124
125run_all $config
126