From 84f976272375fed945ee93be66cfb19326048346 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Sun, 15 Nov 2026 15:46:43 +0000 Subject: [PATCH] make docker-check, the scripts on BSD's tools, the budget at 18,000 PLAN.md 5, step 2. containers/check/Dockerfile and make docker-check run make check in a linux/amd64 container, for a Mac until raz runs there; under Rosetta, test/check.sh skips the 9 tests Rosetta breaks (its own descriptors 3 to 6, its mmap under ulimit -v, a stack fault's locals), each saying why. The Makefile and scripts run on BSD's tools: test/nanos.sh for date +%s%N, shasum where sha256sum isn't, getconf for nproc. The budget is 18,000 lines of code, by the owner's word. --- diff --git a/CLAUDE.md b/CLAUDE.md index 4e3dc16..477330a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -10,6 +10,7 @@ make raz # the compiler, ./raz, built from src/ by the release BOOT names; its library is lib/ make check # every example and test against its expected output + make docker-check # make check in a linux/amd64 container, on a Mac; under Rosetta it skips 9 tests, each saying why make bench # must report at least 400,000 lines a second make prev-bench # the compiler's speed against BOOT's: more than a tenth slower fails make kernels # test/bench's kernels against FPC -O2's twins (apt-get install -y fp-compiler) @@ -60,8 +61,8 @@ `Luis <42945842+ldiaz94@users.noreply.github.com>`, unsigned (`--no-gpg-sign`), no attribution trailer. Push to `main`. No pull requests unless asked. -- Budget: never past 14,000 lines of code (raised from 8,500, then - from 11,000, by the owner's word, who dropped the soft limit; blank and +- Budget: never past 18,000 lines of code (raised from 8,500, then + from 11,000 and 14,000, the last for the arm64 macOS port, by the owner's word, who dropped the soft limit; blank and comment lines not counted), with the compiler documented and commented throughout, most of all where it is obscure or needs a compiler writer's knowledge; at least 400,000 lines of raz a second; diff --git a/Makefile b/Makefile index e78994d..6d85f6c 100644 --- a/Makefile +++ b/Makefile @@ -54,9 +54,9 @@ # the best of three runs; fails below 400,000 lines a second bench: raz | build sh test/genbench.sh 12000 > build/Bench.raz - @lines=$$(wc -l < build/Bench.raz); best=0; \ + @lines=$$(($$(wc -l < build/Bench.raz))); best=0; \ for i in 1 2 3; do \ - start=$$(date +%s%N); ./raz build/Bench.raz || exit 1; end=$$(date +%s%N); \ + start=$$(sh test/nanos.sh); ./raz build/Bench.raz || exit 1; end=$$(sh test/nanos.sh); \ t=$$((end - start)); if [ $$best = 0 ] || [ $$t -lt $$best ]; then best=$$t; fi; \ done; \ rate=$$((lines * 1000000000 / best)); \ @@ -207,4 +207,18 @@ site-check: build/site/Verify build/site/Verify -.PHONY: prev-bench fixpoint check gdb bench kernels stress alpine fmt loc man pdf dist site site-source site-check clean install uninstall +.PHONY: docker-image docker-check docker-shell prev-bench fixpoint check gdb bench kernels stress alpine fmt loc man pdf dist site site-source site-check clean install uninstall + +# `make check` in a linux/amd64 container, for a machine that isn't one +# (the repository is mounted at its own path, so git and the tests see +# the same names). DOCKERFLAGS is for what a host's runtime needs. +DOCKER = docker run --rm --platform linux/amd64 $(DOCKERFLAGS) -v $(CURDIR):$(CURDIR) -w $(CURDIR) +DOCKERIMAGE = raz-check +docker-image: + docker build --platform linux/amd64 -t $(DOCKERIMAGE) containers/check + +docker-check: docker-image + $(DOCKER) $(DOCKERIMAGE) sh -c "git config --global --add safe.directory '*' && make check" + +docker-shell: docker-image + $(DOCKER) -it $(DOCKERIMAGE) sh -c "git config --global --add safe.directory '*' && exec bash" diff --git a/PLAN.md b/PLAN.md index 443835c..b05d525 100644 --- a/PLAN.md +++ b/PLAN.md @@ -181,8 +181,8 @@ a table of quadwords, as GLOB_DAT does now; every address in data rebased, since the program is position-independent; its symbol table for lldb's backtraces; and an ad-hoc code signature, SHA-256 hashes - of its pages, without which arm64 macOS won't run it. No line - numbers for a debugger at first. + of its pages, without which arm64 macOS won't run it; and line + numbers for lldb, as DWARF in `__DWARF` (below). - `Host.darwin.raz`: the library beside the compiler by `_NSGetExecutablePath`, C always, a program run from a file written and made executable (no `memfd_create`). @@ -213,7 +213,7 @@ linux/amd64 container on the Mac until there is a Mac compiler): 1. Report 2026-11.0, for the owner's review. (This commit.) -2. A container to build and check in on the Mac (`make docker-check`), +2. Done. A container to build and check in on the Mac (`make docker-check`), the budget raised to 18,000 in `CLAUDE.md` and `doc/compiler.md`, and the Makefile and scripts made to run on BSD's tools as on GNU's (`sed -i`, `stat`, `sha256sum`). diff --git a/containers/check/Dockerfile b/containers/check/Dockerfile new file mode 100644 index 0000000..76289b0 --- /dev/null +++ b/containers/check/Dockerfile @@ -0,0 +1,8 @@ +# What `make check` needs, on the one target raz makes: Linux x86-64. +# Used by `make docker-check` to run the checks on a machine of +# another kind (an Apple Silicon Mac, over Rosetta). +FROM debian:stable-slim +RUN apt-get update && apt-get install -y --no-install-recommends \ + make curl ca-certificates gcc libc6-dev musl musl-tools \ + vim emacs-nox git \ + && rm -rf /var/lib/apt/lists/* diff --git a/doc/compiler.md b/doc/compiler.md index be36d4b..b924f1b 100644 --- a/doc/compiler.md +++ b/doc/compiler.md @@ -1,7 +1,7 @@ # Reading the raz compiler The compiler is twelve files of raz, about 13,100 lines of code (the -budget is 14,000). It is its own compiler: a release of it, the one +budget is 18,000). It is its own compiler: a release of it, the one `BOOT` names, builds `src/`, and `make fixpoint` checks that what it makes makes itself again, byte for byte. Each release was built by the one before it, back to v0.19.0, which the Pascal compiler it was ported diff --git a/src/bench.sh b/src/bench.sh index 614feb0..a66eb85 100755 --- a/src/bench.sh +++ b/src/bench.sh @@ -8,12 +8,12 @@ mkdir -p build/cmp/bench ln -sfn ../../lib build/cmp/lib sh test/genbench.sh 12000 >build/cmp/bench/Bench.raz -echo "$(wc -l &2; exit 1; } fi fi -if ! echo "$sum $d/$t" | sha256sum -c --quiet - >/dev/null 2>&1; then +# macOS has shasum, not sha256sum +if command -v sha256sum >/dev/null; then got=$(sha256sum < $d/$t); else got=$(shasum -a 256 < $d/$t); fi +if [ "${got%% *}" != "$sum" ]; then echo "boot: $d/$t isn't $tag's tarball: its SHA-256 isn't BOOT's" >&2 exit 1 fi diff --git a/test/bench/run.sh b/test/bench/run.sh index 501e147..2d5f5df 100755 --- a/test/bench/run.sh +++ b/test/bench/run.sh @@ -10,7 +10,7 @@ best() { # best program: the fewest milliseconds of five runs b=0 for i in 1 2 3 4 5; do - s=$(date +%s%N); $1 > /dev/null; e=$(date +%s%N) + s=$(sh test/nanos.sh); $1 > /dev/null; e=$(sh test/nanos.sh) t=$(( (e - s) / 1000000 )) if [ $b = 0 ] || [ $t -lt $b ]; then b=$t; fi done diff --git a/test/check.sh b/test/check.sh index eaff622..5fe86a7 100755 --- a/test/check.sh +++ b/test/check.sh @@ -30,6 +30,26 @@ ulimit -s 8192 # Linux's usual stack: StackOverflow's depth depends on it, and CI's runner gives more pass=0 fail=0 +skipped=0 + +# Rosetta, which runs x86 programs on an Apple Silicon Mac, differs from +# Linux in these ways; the tests that can't tell so are skipped there, +# each with its reason, until raz runs natively on the Mac. Elsewhere +# nothing is skipped. +rosetta= +grep -q VirtualApple /proc/cpuinfo 2>/dev/null && rosetta=1 +skip() { # skip name: whether to skip it, saying why + [ -n "$rosetta" ] || return 1 + case $1 in + test/run/ExecOpened|test/libc/ExecOpenedC) why='keeps descriptors 3 to 6 open' ;; + test/libc/SysTest|lib/Sys.linux-x86_64.raz) why='takes descriptor 9 in a child' ;; + test/run/StackOverflow|test/run/ThreadOverflow) why='reads a trap local as 0 after a stack fault' ;; + "Thread under a memory limit") why="aborts under ulimit -v" ;; + *) return 1 ;; + esac + echo "SKIP $1: Rosetta $why" + skipped=$((skipped + 1)) +} conform/check.sh $raz test/msg > $out/conform.out grep -v '^[0-9]* passed' $out/conform.out @@ -38,6 +58,7 @@ run() { # run dir name dir=$1; name=$2 + skip $dir/$name && return flags= [ $dir = examples ] || [ $dir = test/libc ] && flags=-Werror if ! $raz $flags $libc -I $dir/mods -o $out/$name $dir/$name.raz 2>$out/$name.cerr; then @@ -335,8 +356,12 @@ # raztest, which says what it counted on its last line; Sys over C is # tested in test/libc if $raz -Werror -o $out/raztest tools/Test.raz 2>$out/raztest.cerr; then - RAZ=$raz $out/raztest -j $(nproc 2>/dev/null || echo 1) -o $out/lib \ - $(for f in lib/*.raz; do [ $f != lib/Sys.raz ] && grep -q '^proc main\*' $f && echo $f; done) \ + libtests= + for f in lib/*.raz; do + [ $f != lib/Sys.raz ] && grep -q '^proc main\*' $f && ! skip $f && libtests="$libtests $f" + done + RAZ=$raz $out/raztest -j $(nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1) -o $out/lib \ + $libtests \ > $out/raztest.out 2>&1 set -- $(tail -1 $out/raztest.out) # N passed, F failed, T timed out, S if [ "$2" = passed, ] && [ "$6" = timed ]; then @@ -347,8 +372,8 @@ fi # and again with the debug heap, RAZ_HEAP=debug: guards after blocks, # freed blocks filled and quarantined - RAZ_HEAP=debug RAZ=$raz $out/raztest -j $(nproc 2>/dev/null || echo 1) -o $out/libdebug \ - $(for f in lib/*.raz; do [ $f != lib/Sys.raz ] && grep -q '^proc main\*' $f && echo $f; done) \ + RAZ_HEAP=debug RAZ=$raz $out/raztest -j $(nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1) -o $out/libdebug \ + $libtests \ > $out/raztest-debug.out 2>&1 set -- $(tail -1 $out/raztest-debug.out) if [ "$2" = passed, ] && [ "$6" = timed ]; then @@ -427,7 +452,8 @@ # Thread's test again, with too little memory for all its threads: # spawn must fail, with Thread.Failed -if (ulimit -v 60000; $out/lib/Thread.linux-x86_64 fail) > /dev/null 2>&1; then pass=$((pass + 1)) +if skip "Thread under a memory limit"; then : +elif (ulimit -v 60000; $out/lib/Thread.linux-x86_64 fail) > /dev/null 2>&1; then pass=$((pass + 1)) else echo "FAIL Thread under a memory limit"; fail=$((fail + 1)); fi # the compiler's way of going on after an error, in small: a parser @@ -463,5 +489,7 @@ # The compiler built with another host (test/host/Host.raz). if test/compiler-host.sh "$raz"; then pass=$((pass + 1)); else fail=$((fail + 1)); fi -echo "$pass passed, $fail failed" +summary="$pass passed, $fail failed" +[ $skipped = 0 ] || summary="$summary, $skipped skipped" +echo "$summary" [ $fail = 0 ] diff --git a/test/nanos.sh b/test/nanos.sh new file mode 100644 index 0000000..6dc67f5 --- /dev/null +++ b/test/nanos.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# The time in nanoseconds, for the timing scripts: date +%s%N is GNU's; +# BSD's date prints a literal N there, and perl, which macOS has, then +# gives the time. +n=$(date +%s%N) +case $n in +*N) perl -MTime::HiRes=time -e 'printf "%.0f\n", time * 1e9' ;; +*) echo "$n" ;; +esac