run_tests.sh 2.57 KB
Newer Older
Kevin Wolf's avatar
Kevin Wolf committed
1
2
#!/bin/bash

Andrew Jones's avatar
Andrew Jones committed
3
4
5
6
7
8
9
10
if [ ! -f config.mak ]; then
    echo "run ./configure && make first. See ./configure -h"
    exit
fi
source config.mak

config=$TEST_DIR/unittests.cfg
qemu=${QEMU:-qemu-system-$ARCH}
Kevin Wolf's avatar
Kevin Wolf committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
verbose=0

function run()
{
    local testname="$1"
    local groups="$2"
    local smp="$3"
    local kernel="$4"
    local opts="$5"
    local arch="$6"

    if [ -z "$testname" ]; then
        return
    fi

    if [ -n "$only_group" ] && ! grep -q "$only_group" <<<$groups; then
        return
    fi

    if [ -n "$arch" ] && [ "$arch" != "$ARCH" ]; then
        echo "skip $1 ($arch only)"
        return
    fi

Andrew Jones's avatar
Andrew Jones committed
35
    cmdline="./$TEST_DIR-run $kernel -smp $smp $opts"
Kevin Wolf's avatar
Kevin Wolf committed
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
    if [ $verbose != 0 ]; then
        echo $cmdline
    fi

    # extra_params in the config file may contain backticks that need to be
    # expanded, so use eval to start qemu
    eval $cmdline >> test.log

    if [ $? -le 1 ]; then
        echo -e "\e[32mPASS\e[0m $1"
    else
        echo -e "\e[31mFAIL\e[0m $1"
    fi
}

function run_all()
{
    local config="$1"
    local testname
    local smp
    local kernel
    local opts
    local groups
    local arch

    exec {config_fd}<$config

    while read -u $config_fd line; do
        if [[ "$line" =~ ^\[(.*)\]$ ]]; then
            run "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch"
            testname=${BASH_REMATCH[1]}
            smp=1
            kernel=""
            opts=""
            groups=""
            arch=""
        elif [[ $line =~ ^file\ *=\ *(.*)$ ]]; then
Andrew Jones's avatar
Andrew Jones committed
73
            kernel=$TEST_DIR/${BASH_REMATCH[1]}
Kevin Wolf's avatar
Kevin Wolf committed
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
        elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then
            smp=${BASH_REMATCH[1]}
        elif [[ $line =~ ^extra_params\ *=\ *(.*)$ ]]; then
            opts=${BASH_REMATCH[1]}
        elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then
            groups=${BASH_REMATCH[1]}
        elif [[ $line =~ ^arch\ *=\ *(.*)$ ]]; then
            arch=${BASH_REMATCH[1]}
        fi
    done

    run "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch"

    exec {config_fd}<&-
}

function usage()
{
cat <<EOF

Usage: $0 [-g group] [-h] [-v]

    -g: Only execute tests in the given group
    -h: Output this help text
    -v: Enables verbose mode

Andrew Jones's avatar
Andrew Jones committed
100
101
Set the environment variable QEMU=/path/to/qemu-system-ARCH to
specify the appropriate qemu binary for ARCH-run.
Kevin Wolf's avatar
Kevin Wolf committed
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125

EOF
}

echo > test.log
while getopts "g:hv" opt; do
    case $opt in
        g)
            only_group=$OPTARG
            ;;
        h)
            usage
            exit
            ;;
        v)
            verbose=1
            ;;
        *)
            exit
            ;;
    esac
done

run_all $config