summaryrefslogtreecommitdiff
path: root/docker/scripts/run-unit-tests.sh
blob: a935db3ef19e88c9a84f3c2fc76f28e13d58b47f (plain) (blame)
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
#!/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, and the barcodes the tests dumped are decoded
# with zxing-cpp (tools/check_codes.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
  # README 12.4 check 2: the barcodes the encoders produced must decode.
  python3 /work/tools/check_codes.py "${results}/${device}.log" || failed=1
done

if ((failed)); then
  die "unit tests failed; console logs are in build/test/results/"
fi
log "unit tests passed on: $*"