File: integration-tests

package info (click to toggle)
lava-tool 0.25-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 612 kB
  • sloc: python: 4,411; makefile: 148; sh: 93
file content (80 lines) | stat: -rwxr-xr-x 1,622 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
73
74
75
76
77
78
79
80
#!/bin/sh

set -e

green() {
    test -t 1 && printf "\033[0;32;40m$@\033[m\n" || echo "$@"
}

red() {
    test -t 2 && printf "\033[0;31;40m$@\033[m\n" >&2 || echo "$2" >&2
}

start_server() {
    server_dir="${base_tmpdir}/_server"
    mkdir -p "${server_dir}"
    server_log="${server_dir}/log"
    python integration-tests.d/lib/server.py > "${server_log}" 2>&1 &
    server_pid=$?
}

stop_server() {
    curl -q http://localhost:5000/exit
}

run_test() {
    local testfile="$1"
    local logfile="$2"
    rc=0
    if test -n "$VERBOSE"; then
        sh -x "$testfile" < /dev/null || rc=$?
    else
        sh -x "$testfile" > "${logfile}" 2>&1 < /dev/null || rc=$?
    fi
    if test $rc -eq 0; then
        green "$testname: PASS"
        passed=$(($passed + 1))
    else
        failed=$(($failed + 1))
        red "$testname: FAIL"
        if test -f "$logfile"; then
            cat "$logfile"
        fi
    fi
}

passed=0
failed=0
base_tmpdir=$(mktemp -d)
logs="${base_tmpdir}/logs"
mkdir "$logs"

export PATH="$(dirname $0)"/integration-tests.d/lib:$PATH

start_server

tests="$@"
if test -z "$tests"; then
    tests=$(echo integration-tests.d/*.sh)
fi

for testfile in $tests; do
    testname=$(basename "$testfile")
    logfile="${logs}/${testname}.log"
    export tmpdir="${base_tmpdir}/${testname}"
    export LAVACONFIG="${tmpdir}/config"
    mkdir "${tmpdir}"
    run_test "$testfile" "$logfile"
done

stop_server

rm -rf "${base_tmpdir}"

echo
if [ "$failed" -eq 0 ]; then
    green "$passed tests passed, $failed tests failed."
else
    red "$passed tests passed, $failed tests failed."
    exit 1
fi