boot2

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

test.sh (3336B)


      1 #!/bin/sh
      2 ## tests/p1/test.sh -- run the P1-language test suite.
      3 ##
      4 ## A P1 fixture is `<name>.P1pp`. For each fixture with a `<name>.expected`
      5 ## sibling, the runner builds the program for every backend arch via
      6 ## m1pp/build-p1.sh (which handles m1pp expansion, M1 stringification, and
      7 ## hex2 linking against the per-arch ELF header), runs it under the
      8 ## matching podman platform, and diffs stdout against the expectation.
      9 ## Cross-arch consistency falls out by transitivity.
     10 ##
     11 ## Filenames starting with `_` are skipped (parked).
     12 ##
     13 ## Usage: tests/p1/test.sh [--arch ARCH] [fixture-name ...]
     14 ##   No args: every non-`_` fixture under tests/p1/ for every arch.
     15 ##   --arch: restrict to a single arch (aarch64 | amd64 | riscv64).
     16 
     17 set -eu
     18 
     19 REPO=$(cd "$(dirname "$0")/../.." && pwd)
     20 cd "$REPO"
     21 
     22 ALL_ARCHES="aarch64 amd64 riscv64"
     23 
     24 PLATFORM_aarch64=linux/arm64
     25 PLATFORM_amd64=linux/amd64
     26 PLATFORM_riscv64=linux/riscv64
     27 
     28 IMAGE_aarch64=public.ecr.aws/docker/library/alpine@sha256:378c4c5418f7493bd500ad21ffb43818d0689daaad43e3261859fb417d1481a0
     29 IMAGE_amd64=public.ecr.aws/docker/library/alpine@sha256:4d889c14e7d5a73929ab00be2ef8ff22437e7cbc545931e52554a7b00e123d8b
     30 IMAGE_riscv64=public.ecr.aws/docker/library/alpine@sha256:667d07bf2f6239f094f64b5682c8ffbe24c9f3139b1fb854f85caf931a3d7439
     31 
     32 ARCHES="$ALL_ARCHES"
     33 NAMES=""
     34 while [ "$#" -gt 0 ]; do
     35     case "$1" in
     36         --arch)
     37             shift
     38             ARCHES="$1"
     39             ;;
     40         --arch=*)
     41             ARCHES="${1#--arch=}"
     42             ;;
     43         *)
     44             NAMES="$NAMES $1"
     45             ;;
     46     esac
     47     shift
     48 done
     49 
     50 if [ -z "$NAMES" ]; then
     51     NAMES=$(ls tests/p1/ 2>/dev/null \
     52         | sed -n 's/^\([^_][^.]*\)\.P1pp$/\1/p' \
     53         | sort -u)
     54 fi
     55 
     56 if [ -z "$NAMES" ]; then
     57     echo "no fixtures to run" >&2
     58     exit 1
     59 fi
     60 
     61 pass=0
     62 fail=0
     63 for name in $NAMES; do
     64     fixture=tests/p1/$name.P1pp
     65     expected=tests/p1/$name.expected
     66 
     67     if [ ! -e "$fixture" ]; then
     68         echo "  SKIP $name (no .P1pp)"
     69         continue
     70     fi
     71     if [ ! -e "$expected" ]; then
     72         echo "  SKIP $name (no .expected)"
     73         continue
     74     fi
     75 
     76     expected_content=$(cat "$expected")
     77 
     78     for arch in $ARCHES; do
     79         eval platform=\$PLATFORM_$arch
     80         eval image=\$IMAGE_$arch
     81         if [ -z "$platform" ]; then
     82             echo "  SKIP [$arch] $name (unknown arch)"
     83             continue
     84         fi
     85 
     86         binary=build/p1-tests/$arch/$name
     87 
     88         if ! sh m1pp/build-p1.sh "$arch" "$fixture" "$binary" >/dev/null 2>&1; then
     89             echo "  FAIL [$arch] $name (build failed)"
     90             sh m1pp/build-p1.sh "$arch" "$fixture" "$binary" 2>&1 | sed 's/^/    /'
     91             fail=$((fail + 1))
     92             continue
     93         fi
     94 
     95         actual=$(podman run --rm --pull=never --platform "$platform" \
     96             -v "$REPO":/work -w /work "$image" \
     97             "./$binary" 2>&1 || true)
     98 
     99         if [ "$actual" = "$expected_content" ]; then
    100             echo "  PASS [$arch] $name"
    101             pass=$((pass + 1))
    102         else
    103             echo "  FAIL [$arch] $name"
    104             echo "    --- expected ---"
    105             printf '%s\n' "$expected_content" | sed 's/^/    /'
    106             echo "    --- actual ---"
    107             printf '%s\n' "$actual" | sed 's/^/    /'
    108             fail=$((fail + 1))
    109         fi
    110     done
    111 done
    112 
    113 echo "$pass passed, $fail failed"
    114 [ "$fail" -eq 0 ]