interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / browse / tests / run.sh
| 1 | #!/bin/sh |
| 2 | # browse/tests/run.sh: build the ForgeBrowse test programs with the pinned omc and run the |
| 3 | # Markdown fixtures (tests/md/*.md -> expected tests/md/*.html). Cores: taskset -c ${CORES:-6} (the |
| 4 | # caller's pool; ticket t_7c02d686). |
| 5 | # Usage: tests/run.sh [util.om] (default: tests/stubutil.om) |
| 6 | set -eu |
| 7 | here=$(cd "$(dirname "$0")" && pwd) |
| 8 | br=$(dirname "$here") |
| 9 | omv=${OMV:-$HOME/work/flux/omega-mv} |
| 10 | omc=$omv/seed/out/omc |
| 11 | util=${1:-$here/stubutil.om} |
| 12 | out=${OUT:-/tmp/forgebrowse} |
| 13 | mkdir -p "$out" |
| 14 | want=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194 |
| 15 | got=$(sha256sum "$omc" | cut -d' ' -f1) |
| 16 | [ "$got" = "$want" ] || { echo "omc sha256 $got != pinned $want" >&2; exit 2; } |
| 17 | run() { taskset -c "${CORES:-6}" nice -n 10 "$@"; } |
| 18 | { printf 'om2\n'; cat "$util" "$(dirname "$br")"/nodes/head.om "$br"/a_core.om "$br"/b_md.om "$here/mdmain.om"; } | run "$omc" > "$out/mdtest" || { |
| 19 | echo "compile mdtest failed" >&2; exit 1; } |
| 20 | chmod +x "$out/mdtest" |
| 21 | pass=0; fail=0 |
| 22 | for md in "$here"/md/*.md; do |
| 23 | exp=${md%.md}.html |
| 24 | got=$out/$(basename "${md%.md}").out |
| 25 | run "$out/mdtest" < "$md" > "$got" || { echo "FAIL (exit $?) $(basename "$md")"; fail=$((fail+1)); continue; } |
| 26 | if grep -qiE '<script|<style|style=|href="javascript:|src="javascript:' "$got"; then |
| 27 | fail=$((fail+1)); echo "FAIL (active content) $(basename "$md")"; continue; fi |
| 28 | if cmp -s "$got" "$exp"; then pass=$((pass+1)); echo "PASS $(basename "$md")" |
| 29 | else fail=$((fail+1)); echo "FAIL $(basename "$md")"; diff "$exp" "$got" | head -20; fi |
| 30 | done |
| 31 | # Bounded comment scans: 4 MiB of "<!--" openers with no "-->" (inline and at line starts) must |
| 32 | # render well inside the timeout (one rescan per opener would be about 10^12 byte reads here) and |
| 33 | # every opener must stay escaped text. |
| 34 | n=262144 |
| 35 | big=$out/comment-big.md |
| 36 | awk -v n=$n 'BEGIN { for (i = 0; i < n; i++) printf "a <!-- b\n<!-- c\n" }' > "$big" |
| 37 | rc=0 |
| 38 | run timeout 60 "$out/mdtest" < "$big" > "$out/comment-big.out" || rc=$? |
| 39 | k=$(grep -o '<!--' "$out/comment-big.out" | wc -l) |
| 40 | if [ "$rc" -ne 0 ]; then fail=$((fail+1)); echo "FAIL comment-big (exit $rc; 124 = timeout)" |
| 41 | elif [ "$k" -ne $((2 * n)) ]; then fail=$((fail+1)); echo "FAIL comment-big: $k escaped openers, want $((2 * n))" |
| 42 | else pass=$((pass+1)); echo "PASS comment-big (bounded scan)"; fi |
| 43 | # The README safety policy on every fixture and its four mutant renderers (tests/hostile.sh). |
| 44 | if sh "$here/hostile.sh" "$out/hostile" > "$out/hostile.log" 2>&1; then pass=$((pass+1)); echo "PASS hostile.sh ($(tail -1 "$out/hostile.log"))" |
| 45 | else fail=$((fail+1)); echo "FAIL hostile.sh"; grep '^FAIL' "$out/hostile.log" | head -20; fi |
| 46 | echo "md fixtures: $pass pass, $fail fail" |
| 47 | [ "$fail" -eq 0 ] |