# BST-TIMEOUT: 2700 # 21 upstream test functions; the public-key ones run # bignum arithmetic through libtommath on wasm32 and are # the slow half. Measured value in the test-plan entry. # # 2700 IS A MEASUREMENT, NOT A ROUND NUMBER, AND THE FIRST TRY AT IT WAS 1800. # The suite ran in elapsed=1705s -- 95s under an 1800s bound, i.e. 95% of it. # A bound a suite clears by 5% is not a bound, it is a coin toss against host # load: the next run on a busier host is killed at the same work and reports # libtomcrypt/suite-timeout, a red that says nothing about libtomcrypt. The # cost of being wrong is asymmetric -- a generous bound only lengthens the # worst case of a genuine hang, while a tight one manufactures a red in the # suite that is this port's entire acceptance gate. # # libtomcrypt's acceptance gate is upstream's own `test` programme, packaged as # libtomcrypt-tests by this layer's bbappend. It runs all 21 test functions # against their published vectors and reports pass/fail/nop per function plus a # summary line, so this suite's job is not to re-assert the cryptography -- it # is to run the programme honestly and turn each of its verdicts into a BST # case that a report can count. # # ONE CASE PER UPSTREAM FUNCTION, NOT ONE FOR THE SUMMARY. A single case keyed # on "SUCCESS" would collapse 21 independent verdicts into one bit, and the # first red would hide the other twenty results at exactly the moment they # matter most. . "$BST_LIB" # --------------------------------------------------------------------------- # 0. Locate the packaged programme. It is deliberately not on PATH (see the # bbappend), so `require` cannot find it and the lookup is by path. TDIR= for d in /usr/libexec/libtomcrypt-tests /usr/lib/libtomcrypt-tests; do [ -d "$d" ] && { TDIR=$d; break; } done if [ -z "$TDIR" ]; then bst_skip libtomcrypt/present "libtomcrypt-tests not installed on this image" exit 0 fi if [ ! -x "$TDIR/libtomcrypt-test" ]; then bst_notok libtomcrypt/present "$TDIR exists but libtomcrypt-test is missing or not executable" exit 0 fi bst_ok libtomcrypt/present # The data file file_test opens as a RELATIVE path. Asserted separately from # the run so a missing payload is not reported as a failing hash. if [ -f "$TDIR/tests/test.key" ]; then bst_ok libtomcrypt/data-present else bst_notok libtomcrypt/data-present "$TDIR/tests/test.key missing -- file_test will return CRYPT_FILE_NOTFOUND" fi # --------------------------------------------------------------------------- # 1. The library halves this port actually ships. The bare libtomcrypt package # is empty on this arm (no shared libraries for the guest), so the archive # and the header are the deliverable and their absence must not be inferred # from the programme running -- it is statically linked and would run fine # with neither installed. if [ -f /usr/lib/libtomcrypt.a ]; then bst_ok libtomcrypt/staticdev else bst_notok libtomcrypt/staticdev "/usr/lib/libtomcrypt.a not installed (libtomcrypt-staticdev missing from the image?)" fi if [ -f /usr/include/tomcrypt.h ]; then bst_ok libtomcrypt/headers else bst_notok libtomcrypt/headers "/usr/include/tomcrypt.h not installed (libtomcrypt-dev missing from the image?)" fi # --------------------------------------------------------------------------- # 2. Run it once. cd first: file_test opens "tests/test.key" relative to the # CWD, and the rootfs is read-only, so the run must happen where the data # file is rather than copying it somewhere writable. OUT=$(cd "$TDIR" && ./libtomcrypt-test 2>&1); RC=$? if bst_execfail "$OUT"; then bst_unrun libtomcrypt/run "$OUT" exit 0 fi # --------------------------------------------------------------------------- # 3. The math provider. libtomcrypt without a bignum backend silently 'nop's # every public-key function, which would read as a clean run that tested # nothing -- so the provider is asserted before the verdicts are counted. case "$OUT" in *"MP_PROVIDER = LibTomMath"*) bst_ok libtomcrypt/mp-provider ;; *"NO math provider selected"*) bst_notok libtomcrypt/mp-provider "built with no math provider: every MPI test will nop" ;; *) bst_notok libtomcrypt/mp-provider "no MP_PROVIDER line; $(_bst_1line "$OUT")" ;; esac # --------------------------------------------------------------------------- # 4. One case per upstream test function. # # The programme prints "", where is `passed # `, `nop`, or `failed () `. A function that printed nothing at # all is `not ok`, not absent: the run was cut short and the verdict is unknown, # which is the outcome that hides best in a summary that only counts what it # was given. # # `nop` is upstream's own word for "this build has nothing to test here" -- an # algorithm compiled out by tomcrypt_custom.h. That is a legitimate absence, so # it is `skip`, and the count of them is pinned in the test-plan entry so a # regression that silently disables an algorithm shows up as a verb change. fn_verdict() { printf '%s\n' "$OUT" | sed -n "s/^$1\\.\\.*//p" | head -1 } fn_case() { _v=$(fn_verdict "$1") case "$_v" in passed*) bst_ok "libtomcrypt/$1" ;; nop*) bst_skip "libtomcrypt/$1" "upstream reported nop -- algorithm not compiled into this build" ;; failed*) bst_notok "libtomcrypt/$1" "$(_bst_1line "$_v")" ;; "") bst_notok "libtomcrypt/$1" "no verdict line -- the run did not reach this function (rc=$RC)" ;; *) bst_notok "libtomcrypt/$1" "unrecognised verdict '$(_bst_1line "$_v")'" ;; esac } # The 21 functions of tests/test.c, in the order it runs them. for f in \ store_test rotate_test misc_test mpi_test cipher_hash_test mac_test \ modes_test der_test pkcs_1_test pkcs_1_pss_test pkcs_1_oaep_test \ pkcs_1_emsa_test pkcs_1_eme_test rsa_test dh_test ecc_tests dsa_test \ katja_test file_test multi_test prng_test do fn_case "$f" done # --------------------------------------------------------------------------- # 5. The programme's own summary, and its exit status. # # Asserted in ADDITION to the per-function cases rather than instead of them: # the summary is the only line that says the run reached its end, and the exit # status is the only thing that says the programme agreed with its own report. SUM=$(printf '%s\n' "$OUT" | sed -n 's/^\(SUCCESS\|FAILURE\): //p' | head -1) printf '#diag: summary rc=%s :: %s\n' "$RC" "${SUM:-}" if [ -z "$SUM" ]; then bst_notok libtomcrypt/summary "the run produced no summary line at all; rc=$RC $(_bst_1line "$OUT")" else case "$OUT" in *"SUCCESS: "*) if [ "$RC" -eq 0 ]; then bst_ok libtomcrypt/summary else bst_notok libtomcrypt/summary "reported SUCCESS but exited $RC"; fi ;; *) bst_notok libtomcrypt/summary "rc=$RC $SUM" ;; esac fi # A run in which every function 'nop'ped would print SUCCESS with passed=0 and # satisfy every case above while testing nothing. Pin the floor. PASSED=$(printf '%s\n' "$SUM" | sed -n 's/.*passed=\([0-9]*\).*/\1/p') if [ -n "$PASSED" ] && [ "$PASSED" -ge 10 ]; then bst_ok libtomcrypt/passed-floor else bst_notok libtomcrypt/passed-floor "passed=${PASSED:-}, expected at least 10 functions to actually run" fi