#!/bin/sh # cmocka's ptest, rewritten because meta-oe's does not run the tests. # # The stock recipes-test/cmocka/files/run-ptest is: # # for i in `ls *`; do # if [ ./$i ] ; then echo "PASS: $i"; else echo "FAIL: $i"; fi # done # # `[ ./$i ]` is a ONE-ARGUMENT test, so it asks whether the string "./test_alloc" # is non-empty. It always is. The binary is never executed, every file in the # directory is reported PASS, and a suite in which every single test aborted # reports a clean run. That is not a weak gate, it is no gate at all -- and this # port's whole acceptance criterion is the suite's result, so it had to go. # # BRINTOS-UPSTREAM-FIX: this is a meta-oe defect, carried here rather than filed # upstream, per the layer's standing rule for poky/meta-oe. # # SEVEN OF THE 23 TEST BINARIES FAIL ON PURPOSE, which is why the fix is not # simply "run it and check $?". cmocka's suite tests its own failure reporting: # test_ordering_fail exists to confirm that seven mis-ordered mock calls ARE # caught, and it exits 7 when it works. Upstream expresses that in CTest with # WILL_FAIL and PASS_REGULAR_EXPRESSION properties (tests/CMakeLists.txt), which # ptest cannot see. The table below transcribes those properties, so an expected # failure has to fail in the expected WAY -- a binary that segfaults on this arm # before reaching its first assertion does not get scored PASS for exiting # non-zero. # # cmocka's exit status is its count of failed tests, so the status is checked # exactly rather than as "non-zero": test_ordering_fail failing six ways instead # of seven is a red here. cd "$(dirname "$0")/tests" 2>/dev/null || { echo "FAIL: cmocka (no tests directory)"; exit 1; } # || # Empty regex means the status alone is the criterion. # Transcribed from tests/CMakeLists.txt: WILL_FAIL 1 -> non-zero status; # PASS_REGULAR_EXPRESSION -> the regex column. expectations=' test_alloc|0| test_assert_macros|0| test_assert_macros_fail|1|\[ FAILED \] tests: 1 test test_basics|0| test_cmockery|0| test_double_macros|0| test_exception_handler|3|Test failed with exception test_fixtures|0| test_float_macros|0| test_group_fixtures|0| test_group_setup_assert|1|\[ FAILED \] GROUP SETUP test_group_setup_fail|1|\[ FAILED \] GROUP SETUP test_groups|0| test_ordering|0| test_ordering_fail|7|\[ FAILED \] tests: 7 test test_returns|0| test_returns_fail|3|\[ FAILED \] alloc_tests: 3 test test_setup_fail|1|\[ ERROR \] int_test_ignored test_skip|0|\[ SKIPPED \] test_check_skip test_skip_filter|0| test_string|0| test_strmatch|0| test_wildcard|0| ' fails=0 ran=0 for bin in test_*; do [ -f "$bin" ] && [ -x "$bin" ] || continue row=$(printf '%s\n' "$expectations" | grep "^$bin|") if [ -z "$row" ]; then # A binary the table does not know about. Never silently ignored: either # upstream added a test and this table needs the new row, or something # else landed in the ptest directory. echo "FAIL: $bin (no expectation recorded for this binary)" fails=$((fails + 1)) ran=$((ran + 1)) continue fi want_rc=$(printf '%s' "$row" | cut -d'|' -f2) want_re=$(printf '%s' "$row" | cut -d'|' -f3) out=$(./"$bin" 2>&1) rc=$? ran=$((ran + 1)) if [ "$rc" != "$want_rc" ]; then echo "FAIL: $bin (exit $rc, expected $want_rc)" printf '%s\n' "$out" | sed 's/^/# /' fails=$((fails + 1)) continue fi if [ -n "$want_re" ] && ! printf '%s\n' "$out" | grep -qE "$want_re"; then echo "FAIL: $bin (exit $rc as expected, but output lacks /$want_re/)" printf '%s\n' "$out" | sed 's/^/# /' fails=$((fails + 1)) continue fi echo "PASS: $bin" done # A run that executed nothing must not read as a clean run -- the exact failure # mode the stock script had. if [ "$ran" -eq 0 ]; then echo "FAIL: cmocka (no test binaries found)" exit 1 fi # Deliberately not "TOTAL: n FAIL: n": ptest-runner prints a line of exactly that # shape for its own tally, and a consumer reading both streams cannot tell them # apart. 77-cmocka.test asserts each separately. echo "CMOCKA TOTAL: $ran FAIL: $fails" [ "$fails" -eq 0 ]