boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

test.sh (3846B)


      1 #!/bin/sh
      2 ## test.sh — run the m1pp test suite under tests/m1pp/.
      3 ##
      4 ## Two fixture shapes, selected by file extension:
      5 ##
      6 ##   <name>.M1     — standalone P1v2 program (build-pipeline smoke test).
      7 ##                    Built, run with no args; stdout diffed against
      8 ##                    <name>.expected.
      9 ##
     10 ##   <name>.M1pp   — input for the m1pp expander (parity test).
     11 ##                    Runner builds m1pp/m1pp.P1 once, runs the resulting
     12 ##                    binary as `m1pp <name>.M1pp <tmp>/out`, and diffs
     13 ##                    that output file against <name>.expected.
     14 ##
     15 ## Filenames starting with `_` are skipped — used for ad-hoc debugging.
     16 ##
     17 ## Usage: m1pp/test.sh [fixture-name ...]
     18 ##   No args: run every non-`_` fixture under tests/m1pp/.
     19 
     20 set -eu
     21 
     22 REPO=$(cd "$(dirname "$0")/.." && pwd)
     23 PLATFORM=linux/arm64
     24 ## Share the tag that build.sh builds and runs under. build.sh creates it
     25 ## on first run from Containerfile.busybox — we assume it exists by the time
     26 ## a fixture is run (build_expander / per-fixture build.sh invocations
     27 ## produce it as a side effect).
     28 IMAGE=localhost/distroless-busybox:latest
     29 
     30 cd "$REPO"
     31 
     32 EXPANDER_BIN=build/m1pp/m1pp
     33 EXPANDER_SRC=m1pp/m1pp.P1
     34 EXPANDER_DEFS=build/p1v2/aarch64/p1_aarch64.M1
     35 EXPANDER_BUILT=0
     36 
     37 expander_up_to_date() {
     38     [ -x "$EXPANDER_BIN" ] || return 1
     39     [ "$EXPANDER_BIN" -nt "$EXPANDER_SRC" ] || return 1
     40     [ "$EXPANDER_BIN" -nt "$EXPANDER_DEFS" ] || return 1
     41     return 0
     42 }
     43 
     44 build_expander() {
     45     if [ "$EXPANDER_BUILT" = 0 ]; then
     46         if expander_up_to_date; then
     47             echo "  (m1pp up to date, skipping rebuild)"
     48         else
     49             sh m1pp/build.sh "$EXPANDER_SRC" "$EXPANDER_BIN" >/dev/null 2>&1 || {
     50                 echo "FATAL: failed to build $EXPANDER_SRC" >&2
     51                 sh m1pp/build.sh "$EXPANDER_SRC" "$EXPANDER_BIN" 2>&1 | sed 's/^/  /' >&2
     52                 exit 1
     53             }
     54         fi
     55         EXPANDER_BUILT=1
     56     fi
     57 }
     58 
     59 if [ "$#" -gt 0 ]; then
     60     NAMES="$*"
     61 else
     62     NAMES=$(ls tests/m1pp/ 2>/dev/null \
     63         | sed -n 's/^\([^_][^.]*\)\.\(M1\|M1pp\)$/\1/p' \
     64         | sort -u)
     65 fi
     66 
     67 if [ -z "$NAMES" ]; then
     68     echo "no fixtures to run" >&2
     69     exit 1
     70 fi
     71 
     72 pass=0
     73 fail=0
     74 for name in $NAMES; do
     75     expected=tests/m1pp/$name.expected
     76     m1_src=tests/m1pp/$name.M1
     77     m1pp_src=tests/m1pp/$name.M1pp
     78 
     79     if [ ! -e "$expected" ]; then
     80         echo "  SKIP $name (no .expected)"
     81         continue
     82     fi
     83 
     84     if [ -e "$m1pp_src" ]; then
     85         build_expander
     86         outfile=build/m1pp/$name.out
     87         rm -f "$outfile"
     88         podman run --rm --pull=never --platform "$PLATFORM" \
     89             -v "$REPO":/work -w /work "$IMAGE" \
     90             "./$EXPANDER_BIN" "$m1pp_src" "$outfile" >/dev/null 2>&1 || true
     91         if [ -e "$outfile" ]; then
     92             actual=$(cat "$outfile")
     93         else
     94             actual=""
     95         fi
     96     elif [ -e "$m1_src" ]; then
     97         bin=build/m1pp/$name
     98         sh m1pp/build.sh "$m1_src" "$bin" >/dev/null 2>&1 || {
     99             echo "  FAIL $name (build failed)"
    100             sh m1pp/build.sh "$m1_src" "$bin" 2>&1 | sed 's/^/    /'
    101             fail=$((fail + 1))
    102             continue
    103         }
    104         actual=$(podman run --rm --pull=never --platform "$PLATFORM" \
    105             -v "$REPO":/work -w /work "$IMAGE" \
    106             "./$bin" 2>&1 || true)
    107     else
    108         echo "  SKIP $name (no .M1 or .M1pp)"
    109         continue
    110     fi
    111 
    112     expected_content=$(cat "$expected")
    113 
    114     if [ "$actual" = "$expected_content" ]; then
    115         echo "  PASS $name"
    116         pass=$((pass + 1))
    117     else
    118         echo "  FAIL $name"
    119         echo "    --- expected ---"
    120         printf '%s\n' "$expected_content" | sed 's/^/    /'
    121         echo "    --- actual ---"
    122         printf '%s\n' "$actual" | sed 's/^/    /'
    123         fail=$((fail + 1))
    124     fi
    125 done
    126 
    127 echo "$pass passed, $fail failed"
    128 [ "$fail" -eq 0 ]