mirror of
https://github.com/zmkfirmware/zmk.git
synced 2026-03-19 20:45:18 -05:00
chore: Allow running tests from anywhere and support EXTRA_MODULES (#2725)
* Allow running tests from anywhere in the workspace * Trigger test workflow if run-test.sh changes
This commit is contained in:
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -4,12 +4,14 @@ on:
|
|||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- ".github/workflows/test.yml"
|
- ".github/workflows/test.yml"
|
||||||
|
- "app/run-test.sh"
|
||||||
- "app/tests/**"
|
- "app/tests/**"
|
||||||
- "app/src/**"
|
- "app/src/**"
|
||||||
- "app/include/**"
|
- "app/include/**"
|
||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
paths:
|
||||||
- ".github/workflows/test.yml"
|
- ".github/workflows/test.yml"
|
||||||
|
- "app/run-test.sh"
|
||||||
- "app/tests/**"
|
- "app/tests/**"
|
||||||
- "app/src/**"
|
- "app/src/**"
|
||||||
- "app/include/**"
|
- "app/include/**"
|
||||||
|
|||||||
@@ -3,6 +3,15 @@
|
|||||||
# Copyright (c) 2020 The ZMK Contributors
|
# Copyright (c) 2020 The ZMK Contributors
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
##
|
||||||
|
# Optional environment variables, paths can be absolute or relative to $(pwd):
|
||||||
|
# ZMK_SRC_DIR: Path to zmk/app (default is ./)
|
||||||
|
# ZMK_BUILD_DIR: Path to build directory (default is $ZMK_SRC_DIR/build)
|
||||||
|
# ZMK_EXTRA_MODULES: Path to at most one module (in addition to any in west.yml)
|
||||||
|
# ZMK_TESTS_VERBOSE: Be more verbose
|
||||||
|
# ZMK_TESTS_AUTO_ACCEPT: Replace snapshot files with new key events
|
||||||
|
# J: Number of parallel jobs (default is 4)
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
echo "Usage: ./run-test.sh <path to testcase>"
|
echo "Usage: ./run-test.sh <path to testcase>"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -10,45 +19,62 @@ fi
|
|||||||
|
|
||||||
path="$1"
|
path="$1"
|
||||||
if [ $path = "all" ]; then
|
if [ $path = "all" ]; then
|
||||||
path="tests"
|
path="${ZMK_SRC_DIR-.}/tests"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
ZMK_BUILD_DIR=${ZMK_BUILD_DIR:-${ZMK_SRC_DIR:-.}/build}
|
||||||
|
mkdir -p ${ZMK_BUILD_DIR}/tests
|
||||||
|
|
||||||
testcases=$(find $path -name native_posix_64.keymap -exec dirname \{\} \;)
|
testcases=$(find $path -name native_posix_64.keymap -exec dirname \{\} \;)
|
||||||
num_cases=$(echo "$testcases" | wc -l)
|
num_cases=$(echo "$testcases" | wc -l)
|
||||||
if [ $num_cases -gt 1 ] || [ "$testcases" != "$path" ]; then
|
if [ $num_cases -gt 1 ] || [ "$testcases" != "$path" ]; then
|
||||||
echo "" > ./build/tests/pass-fail.log
|
echo "" >${ZMK_BUILD_DIR}/tests/pass-fail.log
|
||||||
echo "$testcases" | xargs -L 1 -P ${J:-4} ./run-test.sh
|
echo "$testcases" | xargs -L 1 -P ${J:-4} ${0}
|
||||||
err=$?
|
err=$?
|
||||||
sort -k2 ./build/tests/pass-fail.log
|
sort -k2 ${ZMK_BUILD_DIR}/tests/pass-fail.log
|
||||||
exit $err
|
exit $err
|
||||||
fi
|
fi
|
||||||
|
|
||||||
testcase="$path"
|
testcase=$(realpath $path | sed -n -e "s|.*/tests/||p")
|
||||||
echo "Running $testcase:"
|
echo "Running $testcase:"
|
||||||
|
|
||||||
west build -d build/$testcase -b native_posix_64 -- -DCONFIG_ASSERT=y -DZMK_CONFIG="$(pwd)/$testcase" > /dev/null 2>&1
|
build_cmd="west build ${ZMK_SRC_DIR:+-s $ZMK_SRC_DIR} -d ${ZMK_BUILD_DIR}/tests/$testcase \
|
||||||
|
-b native_posix_64 -p -- -DCONFIG_ASSERT=y -DZMK_CONFIG="$(realpath $path)" \
|
||||||
|
${ZMK_EXTRA_MODULES:+-DZMK_EXTRA_MODULES="$(realpath ${ZMK_EXTRA_MODULES})"}"
|
||||||
|
|
||||||
|
if [ -z ${ZMK_TESTS_VERBOSE} ]; then
|
||||||
|
$build_cmd >/dev/null 2>&1
|
||||||
|
else
|
||||||
|
echo "ZMK_SRC_DIR: ${ZMK_SRC_DIR:-.}"
|
||||||
|
echo "ZMK_BUILD_DIR: $ZMK_BUILD_DIR"
|
||||||
|
$build_cmd
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $? -gt 0 ]; then
|
if [ $? -gt 0 ]; then
|
||||||
echo "FAILED: $testcase did not build" | tee -a ./build/tests/pass-fail.log
|
echo "FAILED: $testcase did not build" | tee -a ${ZMK_BUILD_DIR}/tests/pass-fail.log
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
${ZMK_BUILD_DIR}/tests/$testcase/zephyr/zmk.exe |
|
||||||
diff -auZ $testcase/keycode_events.snapshot build/$testcase/keycode_events.log
|
sed -e "s/.*> //" |
|
||||||
|
tee ${ZMK_BUILD_DIR}/tests/$testcase/keycode_events_full.log |
|
||||||
|
sed -n -f $path/events.patterns >${ZMK_BUILD_DIR}/tests/$testcase/keycode_events.log
|
||||||
|
|
||||||
|
diff -auZ $path/keycode_events.snapshot ${ZMK_BUILD_DIR}/tests/$testcase/keycode_events.log
|
||||||
if [ $? -gt 0 ]; then
|
if [ $? -gt 0 ]; then
|
||||||
if [ -f $testcase/pending ]; then
|
if [ -f $path/pending ]; then
|
||||||
echo "PENDING: $testcase" | tee -a ./build/tests/pass-fail.log
|
echo "PENDING: $testcase" | tee -a ${ZMK_BUILD_DIR}/tests/pass-fail.log
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ -n "${ZMK_TESTS_AUTO_ACCEPT}" ]; then
|
if [ -n "${ZMK_TESTS_AUTO_ACCEPT}" ]; then
|
||||||
echo "Auto-accepting failure for $testcase"
|
echo "Auto-accepting failure for $testcase"
|
||||||
cp build/$testcase/keycode_events.log $testcase/keycode_events.snapshot
|
cp ${ZMK_BUILD_DIR}/tests/$testcase/keycode_events.log $path/keycode_events.snapshot
|
||||||
else
|
else
|
||||||
echo "FAILED: $testcase" | tee -a ./build/tests/pass-fail.log
|
echo "FAILED: $testcase" | tee -a ${ZMK_BUILD_DIR}/tests/pass-fail.log
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "PASS: $testcase" | tee -a ./build/tests/pass-fail.log
|
echo "PASS: $testcase" | tee -a ${ZMK_BUILD_DIR}/tests/pass-fail.log
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
Reference in New Issue
Block a user