. "$BST_LIB" # ptest-runner is the headless ptest harness: it discovers the per-package ptest # directories installed under /usr/lib/*/ptest and runs each package's UPSTREAM # test suite non-interactively, framing every suite between BEGIN:/END: markers # and streaming the suite's own PASS:/FAIL: lines in between. # # This suite proves the harness, not any one package. The distinction matters, # because a sibling port's suite asks "did MY package pass its ptest" and this one # asks the prior question: can this platform run a ptest AT ALL. That question is # mostly about the process substrate -- ptest-runner pipe2()s two pipes, openpty()s # a controlling terminal, fork()s, setsid()s and poll()s the child's output, and it # treats a failure of the first three as fatal for every suite. wasm32-hwjs has no # obligation to provide any of them, so each is asserted separately below rather # than folded into a single pass/fail: a red on process-substrate is a platform # defect, while a red on cases-green is a defect in the package under test, and # the two route to different places. require ptest-runner ptest-runner/present # The binary loads and runs at all. -h is the cheapest possible exercise of that. check_out ptest-runner/usage "Usage:" ptest-runner -h # Discovery. -l enumerates the installed ptest directories; uthash is the image's # demonstration ptest (its bbappend carries PTEST_ENABLED, the image installs # uthash-ptest). An empty list here means the -ptest packages did not reach the # rootfs, which is a packaging fault, not a runtime one. check_out ptest-runner/discover "uthash" ptest-runner -l # The demonstration run. Captured once and asserted many ways: re-running the # suite per assertion would multiply a slow suite by the number of questions. _out=$(ptest-runner -t 900 uthash 2>&1) _rc=$? case "$_out" in *"START: ptest-runner"*) bst_ok ptest-runner/run-start ;; *) bst_notok ptest-runner/run-start "no START: line -- $(_bst_1line "$_out")" ;; esac # BEGIN:/END: bracket one suite. BEGIN present with END absent is the signature of # a suite that started and then died or was cut by -t, which is a different fault # from one that never started, so both markers are asserted. case "$_out" in *"BEGIN: /usr/lib/uthash/ptest"*) bst_ok ptest-runner/run-begin ;; *) bst_notok ptest-runner/run-begin "suite never began -- $(_bst_1line "$_out")" ;; esac case "$_out" in *"END: /usr/lib/uthash/ptest"*) bst_ok ptest-runner/run-end ;; *) bst_notok ptest-runner/run-end "suite began but never completed -- $(_bst_1line "$_out")" ;; esac case "$_out" in *"TIMEOUT: "*) bst_notok ptest-runner/no-timeout "suite hit the harness timeout" ;; *) bst_ok ptest-runner/no-timeout ;; esac # The three fatal substrate calls. ptest-runner reports each by name and abandons # the suite, so matching the message is exact rather than heuristic. case "$_out" in *"ERROR: pipe2()"*|*"ERROR: openpty()"*|*"ERROR: Fork "*) bst_notok ptest-runner/process-substrate "harness could not spawn a suite -- $(_bst_1line "$_out")" ;; *) bst_ok ptest-runner/process-substrate ;; esac # The suite's own verdict. Upstream's uthash run-ptest prints one PASS:/FAIL: per # test program, so these two counts are the demonstration's actual result. _pass=$(printf '%s\n' "$_out" | grep -c '^PASS: ') _fail=$(printf '%s\n' "$_out" | grep -c '^FAIL: ') if [ "$_pass" -gt 0 ]; then bst_ok ptest-runner/cases-ran else bst_notok ptest-runner/cases-ran "harness produced no PASS: line from the suite"; fi if [ "$_fail" -eq 0 ]; then bst_ok ptest-runner/cases-green else bst_notok ptest-runner/cases-green "$_fail of $((_pass + _fail)) uthash case(s) reported FAIL"; fi # ptest-runner's own exit status is what a CI caller keys on, so it is asserted # rather than inferred from the output it printed. check_eq ptest-runner/exit-status 0 "$_rc"