|
3 | 3 | # Copyright (c) 2020 The ZMK Contributors |
4 | 4 | # SPDX-License-Identifier: MIT |
5 | 5 |
|
| 6 | +## |
| 7 | +# Optional environment variables, paths can be absolute or relative to $(pwd): |
| 8 | +# ZMK_SRC_DIR: Path to zmk/app (default is ./) |
| 9 | +# ZMK_BUILD_DIR: Path to build directory (default is $ZMK_SRC_DIR/build) |
| 10 | +# ZMK_EXTRA_MODULES: Path to at most one module (in addition to any in west.yml) |
| 11 | +# ZMK_TESTS_VERBOSE: Be more verbose |
| 12 | +# ZMK_TESTS_AUTO_ACCEPT: Replace snapshot files with new key events |
| 13 | +# J: Number of parallel jobs (default is 4) |
| 14 | + |
6 | 15 | if [ -z "$1" ]; then |
7 | 16 | echo "Usage: ./run-test.sh <path to testcase>" |
8 | 17 | exit 1 |
9 | 18 | fi |
10 | 19 |
|
11 | 20 | path="$1" |
12 | 21 | if [ $path = "all" ]; then |
13 | | - path="tests" |
| 22 | + path="${ZMK_SRC_DIR-.}/tests" |
14 | 23 | fi |
15 | 24 |
|
| 25 | +ZMK_BUILD_DIR=${ZMK_BUILD_DIR:-${ZMK_SRC_DIR:-.}/build} |
| 26 | +mkdir -p ${ZMK_BUILD_DIR}/tests |
| 27 | + |
16 | 28 | testcases=$(find $path -name native_posix_64.keymap -exec dirname \{\} \;) |
17 | 29 | num_cases=$(echo "$testcases" | wc -l) |
18 | 30 | if [ $num_cases -gt 1 ] || [ "$testcases" != "$path" ]; then |
19 | | - echo "" > ./build/tests/pass-fail.log |
20 | | - echo "$testcases" | xargs -L 1 -P ${J:-4} ./run-test.sh |
| 31 | + echo "" >${ZMK_BUILD_DIR}/tests/pass-fail.log |
| 32 | + echo "$testcases" | xargs -L 1 -P ${J:-4} ${0} |
21 | 33 | err=$? |
22 | | - sort -k2 ./build/tests/pass-fail.log |
| 34 | + sort -k2 ${ZMK_BUILD_DIR}/tests/pass-fail.log |
23 | 35 | exit $err |
24 | 36 | fi |
25 | 37 |
|
26 | | -testcase="$path" |
| 38 | +testcase=$(realpath $path | sed -n -e "s|.*/tests/||p") |
27 | 39 | echo "Running $testcase:" |
28 | 40 |
|
29 | | -west build -d build/$testcase -b native_posix_64 -- -DCONFIG_ASSERT=y -DZMK_CONFIG="$(pwd)/$testcase" > /dev/null 2>&1 |
| 41 | +build_cmd="west build ${ZMK_SRC_DIR:+-s $ZMK_SRC_DIR} -d ${ZMK_BUILD_DIR}/tests/$testcase \ |
| 42 | + -b native_posix_64 -p -- -DCONFIG_ASSERT=y -DZMK_CONFIG="$(realpath $path)" \ |
| 43 | + ${ZMK_EXTRA_MODULES:+-DZMK_EXTRA_MODULES="$(realpath ${ZMK_EXTRA_MODULES})"}" |
| 44 | + |
| 45 | +if [ -z ${ZMK_TESTS_VERBOSE} ]; then |
| 46 | + $build_cmd >/dev/null 2>&1 |
| 47 | +else |
| 48 | + echo "ZMK_SRC_DIR: ${ZMK_SRC_DIR:-.}" |
| 49 | + echo "ZMK_BUILD_DIR: $ZMK_BUILD_DIR" |
| 50 | + $build_cmd |
| 51 | +fi |
| 52 | + |
30 | 53 | if [ $? -gt 0 ]; then |
31 | | - echo "FAILED: $testcase did not build" | tee -a ./build/tests/pass-fail.log |
| 54 | + echo "FAILED: $testcase did not build" | tee -a ${ZMK_BUILD_DIR}/tests/pass-fail.log |
32 | 55 | exit 1 |
33 | 56 | fi |
34 | 57 |
|
35 | | -./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 |
36 | | -diff -auZ $testcase/keycode_events.snapshot build/$testcase/keycode_events.log |
| 58 | +${ZMK_BUILD_DIR}/tests/$testcase/zephyr/zmk.exe | |
| 59 | + sed -e "s/.*> //" | |
| 60 | + tee ${ZMK_BUILD_DIR}/tests/$testcase/keycode_events_full.log | |
| 61 | + sed -n -f $path/events.patterns >${ZMK_BUILD_DIR}/tests/$testcase/keycode_events.log |
| 62 | + |
| 63 | +diff -auZ $path/keycode_events.snapshot ${ZMK_BUILD_DIR}/tests/$testcase/keycode_events.log |
37 | 64 | if [ $? -gt 0 ]; then |
38 | | - if [ -f $testcase/pending ]; then |
39 | | - echo "PENDING: $testcase" | tee -a ./build/tests/pass-fail.log |
| 65 | + if [ -f $path/pending ]; then |
| 66 | + echo "PENDING: $testcase" | tee -a ${ZMK_BUILD_DIR}/tests/pass-fail.log |
40 | 67 | exit 0 |
41 | 68 | fi |
42 | 69 |
|
43 | | - |
44 | 70 | if [ -n "${ZMK_TESTS_AUTO_ACCEPT}" ]; then |
45 | 71 | echo "Auto-accepting failure for $testcase" |
46 | | - cp build/$testcase/keycode_events.log $testcase/keycode_events.snapshot |
| 72 | + cp ${ZMK_BUILD_DIR}/tests/$testcase/keycode_events.log $path/keycode_events.snapshot |
47 | 73 | else |
48 | | - echo "FAILED: $testcase" | tee -a ./build/tests/pass-fail.log |
| 74 | + echo "FAILED: $testcase" | tee -a ${ZMK_BUILD_DIR}/tests/pass-fail.log |
49 | 75 | exit 1 |
50 | 76 | fi |
51 | 77 | fi |
52 | 78 |
|
53 | | -echo "PASS: $testcase" | tee -a ./build/tests/pass-fail.log |
| 79 | +echo "PASS: $testcase" | tee -a ${ZMK_BUILD_DIR}/tests/pass-fail.log |
54 | 80 | exit 0 |
0 commit comments