aboutsummaryrefslogtreecommitdiff
path: root/docs/history/07-zygote/code/test.sh
diff options
context:
space:
mode:
authorGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
committerGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
commitecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 (patch)
tree70e0af76a1b13affff7c6cc8aac7b3e6ef960478 /docs/history/07-zygote/code/test.sh
a
Diffstat (limited to 'docs/history/07-zygote/code/test.sh')
-rwxr-xr-xdocs/history/07-zygote/code/test.sh18
1 files changed, 18 insertions, 0 deletions
diff --git a/docs/history/07-zygote/code/test.sh b/docs/history/07-zygote/code/test.sh
new file mode 100755
index 0000000..add0379
--- /dev/null
+++ b/docs/history/07-zygote/code/test.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+# builds the zygote for arm64 linux and runs it under qemu.
+# needs gcc, aarch64-linux-gnu-gcc and qemu-aarch64. on an arm64 mac or linux box,
+# build natively instead and drop the qemu prefix.
+cd "$(dirname "$0")"; T=$(mktemp -d); Q="timeout 60 qemu-aarch64"
+chk(){ if [ "$1" = "$2" ]; then echo "ok $3"; else echo "FAIL $3: got [$1]"; fi; }
+gcc -w mkgenome.c -o $T/mkg && cat gen.s aslib.s | $T/mkg >$T/g.h
+cmp -s $T/g.h genome.h && echo "ok genome.h is up to date" || echo "FAIL genome.h is stale, regenerate it"
+aarch64-linux-gnu-gcc -O2 -w -DJTYPE=int -static core.c io_linux.c -o $T/zy || exit 1
+chk "$($Q $T/zy <examples/hello.s)" "hello, world!" "hello"
+chk "$($Q $T/zy <examples/fact.s)" "1101110101111100000000" "recursive factorial"
+chk "$( (cat examples/echo.s; printf '`abc\n') | $Q $T/zy)" "abc" "echo after the backtick"
+chk "$($Q $T/zy <examples/sm.s | tr '\n' '/')" "B/ABA/" "self-patching"
+cat examples/asmain.s aslib.s >$T/asm.s
+(cat $T/asm.s; printf '`'; cat examples/hello.s) | $Q $T/zy >$T/a
+chk "$(od -An -td4 $T/a | tr -s ' \n' ' ' | sed 's/^ //;s/ $//')" "29 1 6 2 1 6 27 16 24 3 26 3 14 0 104 101 108 108 111 44 32 119 111 114 108 100 33 10 0" "self-hosted assembler, running on the zygote, assembles hello"
+chk "$( (cat repl.s; printf '`104 p 105 p 10 p r`121 p 111 p 10 p r') | $Q $T/zy | tr '\n' '/')" "hi/yo/" "repl with mutated assembler"
+rm -rf $T