aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/run-test.sh
blob: b0b6f73b499d82b766d4b8d10e622c732d900b6e (plain)
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
#!/bin/sh

# Copyright (c) 2020 The ZMK Contributors
# SPDX-License-Identifier: MIT

if [ -z "$1" ]; then
    echo "Usage: ./run-test.sh <path to testcase>"
    exit 1
fi

path="$1"
if [ $path = "all" ]; then
    path="tests"
fi

testcases=$(find $path -name native_posix_64.keymap -exec dirname \{\} \;)
num_cases=$(echo "$testcases" | wc -l)
if [ $num_cases -gt 1 ] || [ "$testcases" != "$path" ]; then
    echo "" > ./build/tests/pass-fail.log
    echo "$testcases" | xargs -L 1 -P ${J:-4} ./run-test.sh
    err=$?
    sort -k2 ./build/tests/pass-fail.log
    exit $err
fi

testcase="$path"
echo "Running $testcase:"

west build -d build/$testcase -b native_posix_64 -- -DCONFIG_ASSERT=y -DZMK_CONFIG="$(pwd)/$testcase" > /dev/null 2>&1
if [ $? -gt 0 ]; then
    echo "FAILED: $testcase did not build" | tee -a ./build/tests/pass-fail.log
    exit 1
fi

./build/$testcase/zephyr/zmk.exe | sed -e "s/.*> //" | tee build/$testcase/keycode_events_full.log | sed -n -f $testcase/events.patterns > build/$testcase/keycode_events.log
diff -auZ $testcase/keycode_events.snapshot build/$testcase/keycode_events.log
if [ $? -gt 0 ]; then
    if [ -f $testcase/pending ]; then
        echo "PENDING: $testcase" | tee -a ./build/tests/pass-fail.log
        exit 0
    fi


    if [ -n "${ZMK_TESTS_AUTO_ACCEPT}" ]; then
        echo "Auto-accepting failure for $testcase"
        cp build/$testcase/keycode_events.log $testcase/keycode_events.snapshot
    else
        echo "FAILED: $testcase" | tee -a ./build/tests/pass-fail.log
        exit 1
    fi
fi

echo "PASS: $testcase" | tee -a ./build/tests/pass-fail.log
exit 0