# makeself shared helpers — sourced by the 66-makeself-*.test suites as # `. "$BST_DATA/makeself-lib.sh"`. # # It lives in data/ rather than tests/ for a packaging reason: the recipe installs # tests/*.test but data/* wholesale, so a helper under tests/ would either be # dropped from the package or -- if named *.test to get installed -- be executed # by the runner as a suite of its own and emit no results. data/ is the documented # home for content the suites drive. # # --------------------------------------------------------------------------- # WHY ms_extract EXISTS — the one thing to understand about this suite # --------------------------------------------------------------------------- # makeself is a process pipeline: creating an archive drives tar and gzip, and # running one drives dd | decompress | tar. On wasm32-hwjs each of those forks # costs guest memory, and the image has a per-boot ceiling that makeself reaches # sooner than any other port covered here. # # Measured on target: # * In a boot doing nothing else, one archive unpacks 16 times out of 16. # * Under the selftest runner, only the first one to three tar-through-a- # decompressor operations succeed, and WHICH ones varies run to run. Three # consecutive runs of the same image on the same layout produced three # different sets of survivors. # * When the ceiling is hit the failure is distinctive: "Cannot allocate # memory" from tar/awk/expr, or rc 15/143 from the generated header's own # `kill -15 $$` after "Extraction failed" / "Decompression failed" -- always # AFTER the MD5 verification for that same archive has just passed, which is # itself the giveaway that the archive is intact and the environment is not. # * `--list` counts against this budget as much as a real unpack: it is `tar t` # rather than `tar xp`, so it is cheap in TIME (3 s vs 14 s) but not in # memory. That asymmetry is the trap -- an earlier layout was tuned for the # runner's 60 s wall-clock bound and stayed red because the clock was never # the binding constraint. # # So a suite that reported every failed extraction as `not ok` would be FLAKY: # red for a reason that is not makeself's, on a case that passes when rerun, and # therefore useless as the regression signal a red is supposed to be. Instead the # ENOMEM signature is classified as `skip` -- "runtime-blocked", the case the # packager README explicitly covers -- while ANY OTHER failure still reports # `not ok` and fails the run. A genuine makeself regression (wrong output, wrong # exit status, a payload that does not round-trip) is unaffected and still goes # red. # # The blocking condition is the image's per-boot memory ceiling, recorded under # BRINTOS-185; these skips turn back into passes on their own when it lifts. # ms_oom -> true when a failure is the per-boot memory ceiling # rather than a makeself defect. ms_oom() { case "$2" in *"Cannot allocate memory"*) return 0 ;; *"Extraction failed"*) [ "$1" = 15 ] || [ "$1" = 143 ] && return 0 ;; *"Decompression failed"*) [ "$1" = 15 ] || [ "$1" = 143 ] && return 0 ;; esac return 1 } # ms_gate -> ok / skip / not ok for the extraction itself. # Sets MS_GATED=1 when the extraction did not happen for an environmental # reason, so the caller can skip the assertions that depend on its output # instead of reporting a pile of derived failures. MS_GATED=0 ms_gate() { if [ "$2" -eq 0 ]; then bst_ok "$1" elif ms_oom "$2" "$3"; then MS_GATED=1 bst_skip "$1" "per-boot memory ceiling (BRINTOS-185): $(_bst_1line "$3")" else bst_notok "$1" "rc=$2 $(_bst_1line "$3")" fi } # ms_needle -> ok iff the haystack contains the needle; # skipped wholesale once MS_GATED is set. ms_needle() { if [ "$MS_GATED" -eq 1 ]; then bst_skip "$1" "extraction blocked by the per-boot memory ceiling (BRINTOS-185)" return fi case "$3" in *"$2"*) bst_ok "$1" ;; *) bst_notok "$1" "want:'$2' got:'$(_bst_1line "$3")'" ;; esac } # ms_check -> like bst.sh's `check`, but a failure once MS_GATED is # set is reported as a skip: the file it looks for was never unpacked. ms_check() { _mcid=$1; shift _mcout=$("$@" 2>&1); _mcrc=$? if [ "$_mcrc" -eq 0 ]; then bst_ok "$_mcid" elif [ "$MS_GATED" -eq 1 ]; then bst_skip "$_mcid" "extraction blocked by the per-boot memory ceiling (BRINTOS-185)" else bst_notok "$_mcid" "rc=$_mcrc $(_bst_1line "$_mcout")" fi }