1 #!/bin/bash
2 # Phase 5: wasm target validation.
3 #
4 # Every program with a main() is compiled twice - natively and for -target wasm
5 # - and both are run, the wasm one in a real browser. Native is the reference:
6 # the module must produce identical output. Linking is not the bar; matching
7 # output is. See tests/wasm/validate.sh for the comparison itself.
8 set -uo pipefail
9 10 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
11 ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
12 13 source "$SCRIPT_DIR/util.sh"
14 15 echo
16 echo "--- phase 5: wasm target ---"
17 18 # The browser run needs Playwright's Python package and a Chromium build.
19 # Without them the phase cannot produce evidence, so it skips rather than
20 # reporting a pass it did not earn.
21 if ! python3 -c 'import playwright' >/dev/null 2>&1; then
22 log_skip "wasm:validate" "playwright python package not installed"
23 exit 0
24 fi
25 if ! python3 -c '
26 from playwright.sync_api import sync_playwright
27 with sync_playwright() as p:
28 p.chromium.launch().close()
29 ' >/dev/null 2>&1; then
30 log_skip "wasm:validate" "chromium not available to playwright"
31 exit 0
32 fi
33 34 LOG="$TMPROOT/wasm-validate.log"
35 mkdir -p "$TMPROOT"
36 37 if MOXIE="$MOXIE" bash "$ROOT/tests/wasm/validate.sh" >"$LOG" 2>&1; then
38 rc=0
39 else
40 rc=$?
41 fi
42 43 # Report one result per target so the summary names what failed rather than
44 # collapsing the whole phase into a single line.
45 while read -r name verdict rest; do
46 case "$verdict" in
47 PASS) log_pass "wasm:$name" "output matches native" ;;
48 FAIL) log_fail "wasm:$name" "$rest" ;;
49 SKIP) log_skip "wasm:$name" "$rest" ;;
50 esac
51 done < <(grep -E '^[a-z_0-9]+ +(PASS|FAIL|SKIP)' "$LOG")
52 53 if ! grep -qE '^[a-z_0-9]+ +(PASS|FAIL|SKIP)' "$LOG"; then
54 log_fail "wasm:validate" "harness produced no per-target results"
55 tail -10 "$LOG"
56 fi
57 58 echo " (full log: $LOG)"
59 exit "$rc"
60