panic_check.sh raw

   1  #!/bin/bash
   2  # The wasm half of the panic contract: a panic in a spawned domain posts its
   3  # message to the page as stderr, and the page stops every domain it spawned for
   4  # the module. tests/wasm/panic_tree/main.mx makes both halves observable - the
   5  # panicker prints, the sibling would print 1.5 s later - and this harness runs
   6  # the module, waits three seconds, and requires exactly one of them.
   7  set -uo pipefail
   8  ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
   9  MOXIE="${MOXIE:-$ROOT/moxie}"
  10  TD="$(mktemp -d)"
  11  trap 'rm -rf "$TD"' EXIT
  12  
  13  fail() {
  14  	echo "FAIL: $1"
  15  	exit 1
  16  }
  17  
  18  if ! (cd "$ROOT" && MOXIEROOT="$ROOT" "$MOXIE" build -target wasm \
  19  	-o "$TD/app.wasm" "$ROOT/tests/wasm/panic_tree") >"$TD/build.log" 2>&1; then
  20  	fail "wasm build: $(tail -2 "$TD/build.log" | tr '\n' ' ')"
  21  fi
  22  
  23  RUN_SETTLE_MS=3000 timeout 60 python3 "$ROOT/tests/wasm/run.py" -q "$TD/app.wasm" \
  24  	>"$TD/out" 2>"$TD/err"
  25  rc=$?
  26  
  27  # The module must die: the page's loader rejects when the tree stops.
  28  [ "$rc" = "1" ] || fail "browser run exited $rc (want 1: the domain died)"
  29  # The diagnostic must be the panic's own text, on stderr where the page prints it.
  30  grep -q 'panic: sibling died' "$TD/err" || fail "stderr did not carry the panic: $(tail -3 "$TD/err" | tr '\n' ' ')"
  31  # The generic action itself must have run, not merely printed: the page records
  32  # it on the hook host.html defines.
  33  grep -q 'panic action:' "$TD/err" || fail "the page's panic action did not run"
  34  # The sibling must not have acted. Its print would have been forwarded through
  35  # the root worker, which is the observable proof the whole tree was stopped.
  36  if grep -q 'sibling survived' "$TD/out" "$TD/err"; then
  37  	fail "the sibling survived: the page did not stop the tree"
  38  fi
  39  echo "PASS: panic reached the page, the tree stopped"
  40