aboutsummaryrefslogtreecommitdiff
path: root/docker/scripts/run-unit-tests.sh
diff options
context:
space:
mode:
Diffstat (limited to 'docker/scripts/run-unit-tests.sh')
-rwxr-xr-xdocker/scripts/run-unit-tests.sh46
1 files changed, 46 insertions, 0 deletions
diff --git a/docker/scripts/run-unit-tests.sh b/docker/scripts/run-unit-tests.sh
new file mode 100755
index 0000000..60a8955
--- /dev/null
+++ b/docker/scripts/run-unit-tests.sh
@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+# Author: cirakg & claude ai
+# Summary: Build and run the Monkey C unit tests on each test device in the headless simulator.
+#
+# Usage: run-unit-tests.sh DEVICE [DEVICE ...]
+# Output: build/test/results/<DEVICE>.log (console) and <DEVICE>.xml (JUnit).
+#
+# Every test build is compiled first, so a compile error stops the run before
+# the simulator starts. One simulator then runs every device in turn.
+# monkeydo exits with 1 even when all tests pass, so the verdict comes from
+# tools/ciq_test_report.py; the script fails if any device fails.
+set -euo pipefail
+# shellcheck source=ciq-env.sh
+source "$(dirname "${BASH_SOURCE[0]}")/ciq-env.sh"
+
+# Longest a single device's test run may take before it counts as hung.
+readonly TEST_TIMEOUT_S=600
+
+(($# > 0)) || die "usage: run-unit-tests.sh DEVICE [DEVICE ...]"
+ciq_require_sdk
+ciq_require_key
+
+for device in "$@"; do
+ build-app.sh test "${device}"
+done
+
+ciq_start_display
+ciq_start_simulator
+
+results="${BUILD_DIR}/test/results"
+mkdir -p "${results}"
+failed=0
+for device in "$@"; do
+ log "running unit tests on ${device}"
+ # monkeydo's exit status is ignored on purpose (see above); a timeout leaves
+ # an incomplete log, which the report then rejects.
+ timeout "${TEST_TIMEOUT_S}" monkeydo "${BUILD_DIR}/test/${device}.prg" "${device}" -t \
+ >"${results}/${device}.log" 2>&1 || true
+ python3 /work/tools/ciq_test_report.py "${results}/${device}.log" \
+ --device "${device}" --junit "${results}/${device}.xml" || failed=1
+done
+
+if ((failed)); then
+ die "unit tests failed; console logs are in build/test/results/"
+fi
+log "unit tests passed on: $*"