ww test: fork-isolated record-and-continue harness (lib/test, both stages)

lib/test/run.ww: fork+wait4 runner; each @test runs in its own child,
abort/SEGV/FPE decoded from wait-status, failures recorded and the run
continues; exit = fail count. Tests are hermetic: module globals do not
persist test-to-test (fresh fork image; sanctioned divergence from
harec's shared-process __test_main, no setjmp/signal layer needed).
-T synth (both stages) emits a module-global (str,*fn() void) table +
return run(table) instead of straight-line calls. Driver twins bundle
lib/test under test mode and gain ww test -c/-o (go test -c) so the
byte-id gates diff the same artifact the real path builds. Gates
989/910/997 rewired onto it; new 911 pins record-and-continue across
all three fault classes; 949 +3 rows. (#17-team commit-2)
This commit is contained in:
2026-06-11 00:08:39 +09:00
parent 08a76cf4c8
commit 16c83e70d3
15 changed files with 961 additions and 194 deletions

View File

@@ -54,9 +54,10 @@ static int
run_fixture(const char *bin, const char *comp, const char *drv)
{
int pid = getpid();
char src[256], comb[256], asmf[256], obj[256], exe[256];
char src[256], comb[256], binout[256], asmf[256], obj[256], exe[256];
char rt[1024], cmd[4096];
snprintf(src, sizeof src, "/tmp/at910_%s_%d.ww", comp, pid);
snprintf(binout, sizeof binout, "/tmp/at910_%s_%d", comp, pid);
snprintf(comb, sizeof comb, "/tmp/at910_%s_%d.combined.ww", comp, pid);
snprintf(asmf, sizeof asmf, "/tmp/at910_%s_%d.s", comp, pid);
snprintf(obj, sizeof obj, "/tmp/at910_%s_%d.o", comp, pid);
@@ -66,12 +67,12 @@ run_fixture(const char *bin, const char *comp, const char *drv)
snprintf(cmd, sizeof cmd, "cp test/wcc/data/attest_pass.ww %s", src);
if (runwait(cmd) != 0) { fprintf(stderr, "910 FAIL: cp\n"); return 1; }
/* Driver resolves `import rt` into <src>.combined.ww. The build
* itself exits nonzero (the @test-only fixture has no main — that
* is exactly what -T synthesizes), but the combined unit is written
* before any compile step, so we depend on the ARTIFACT, not the
* exit code. */
snprintf(cmd, sizeof cmd, "%s/%s build %s > /dev/null 2>&1", bin, drv, src);
/* `test -c -o <stem>` (compile-only) resolves imports AND auto-bundles
* lib/test (#17) into <stem>.combined.ww — the synth's run() callee
* must link below — WITHOUT running the harness. We depend on the
* combined ARTIFACT; `-o` keeps the binary off the CWD. */
snprintf(cmd, sizeof cmd, "%s/%s test -c -o %s %s > /dev/null 2>&1",
bin, drv, binout, src);
runwait(cmd);
if (access(comb, 0) != 0) {
fprintf(stderr, "910 FAIL: %s build produced no %s\n", drv, comb);
@@ -94,6 +95,10 @@ run_fixture(const char *bin, const char *comp, const char *drv)
return 1;
}
unlink(src); unlink(comb); unlink(asmf); unlink(obj); unlink(exe);
unlink(binout);
char tmp[300];
snprintf(tmp, sizeof tmp, "%s.s", binout); unlink(tmp);
snprintf(tmp, sizeof tmp, "%s.o", binout); unlink(tmp);
return 0;
}
@@ -161,9 +166,18 @@ nondrop(const char *bin, const char *comp)
fprintf(stderr, "910 FAIL: %s non-T nondrop compile\n", comp);
return 1;
}
/* The -T compile synthesizes a main that calls lib/test's run(), so it
* needs the lib/test-inclusive combined `ww test -c` writes (the plain
* compile above has no synth, so it stays on the raw fixture). */
char stem[256], comb[300];
snprintf(stem, sizeof stem, "/tmp/at910nd_%s_c_%d", comp, pid);
snprintf(comb, sizeof comb, "%s.combined.ww", stem);
snprintf(cmd, sizeof cmd,
"%s/%s -T test/wcc/data/attest_nondrop.ww -o %s 2>/dev/null",
bin, comp, tee);
"%s/ww test -c -o %s test/wcc/data/attest_nondrop.ww > /dev/null 2>&1",
bin, stem);
runwait(cmd);
snprintf(cmd, sizeof cmd,
"%s/%s -T %s -o %s 2>/dev/null", bin, comp, comb, tee);
if (runwait(cmd) != 0) {
fprintf(stderr, "910 FAIL: %s -T nondrop compile\n", comp);
return 1;
@@ -184,7 +198,11 @@ nondrop(const char *bin, const char *comp)
break;
}
}
unlink(plain); unlink(tee);
unlink(plain); unlink(tee); unlink(comb);
char tmp[300];
snprintf(tmp, sizeof tmp, "%s.s", stem); unlink(tmp);
snprintf(tmp, sizeof tmp, "%s.o", stem); unlink(tmp);
unlink(stem);
return rc;
}

View File

@@ -0,0 +1,173 @@
/*
* 911_attest_record — #17 record-and-continue harness (lib/test + the
* table-synth -T entry). Sibling of 910_at_test (which pins the synth
* itself + the #6 non-T drop); this one pins the RUNTIME behaviour the
* fork+wait4 runner adds:
*
* 1. RECORD-AND-CONTINUE — `ww test` the mixed fixture (one pass, then
* assert-fail/SIGSEGV/SIGFPE, then a final pass). The runner must
* proceed past every failure, emit the right per-test `name ... ok/
* FAIL` line (table-driven below), print the right `P passed, F
* failed` summary, and exit with the failure count (nonzero).
* 2. ALL-PASS — `ww test` the all-pass fixture exits 0 (no false
* failure from the new runner).
* 3. BYTE-ID (rule 10) — `ww test -c` the mixed fixture into a
* lib/test-inclusive combined, then `w6c -T` and `w6c_ww -T` must
* emit byte-identical asm (the table + fork loop, both stages).
*
* The fork changes failure OUTPUT, not pass behaviour: a passing fixture
* still exits 0, so the 35 converted lib tests stay green (904/967/...).
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
static int
runwait(const char *cmd)
{
int rc = system(cmd);
if (rc == -1) return -1;
if (WIFEXITED(rc)) return WEXITSTATUS(rc);
return 1;
}
static const char *
absbin(void)
{
const char *b = getenv("BIN");
if (!b) b = "out/bin";
if (b[0] == '/') return b;
static char buf[2048];
char cwd[1024];
if (getcwd(cwd, sizeof cwd) == NULL) return NULL;
snprintf(buf, sizeof buf, "%s/%s", cwd, b);
return buf;
}
static int
slurp(const char *path, char *out, size_t outsz)
{
FILE *f = fopen(path, "rb");
if (!f) return -1;
size_t n = fread(out, 1, outsz - 1, f);
out[n] = '\0';
fclose(f);
return 0;
}
/* Each expected per-test verdict line, in source/collection order. */
static const char *expect_lines[] = {
"rec_pass_a ... ok",
"rec_assert ... FAIL",
"rec_segv ... FAIL",
"rec_div0 ... FAIL",
"rec_pass_b ... ok",
"2 passed, 3 failed",
};
static int
record_continue(const char *bin)
{
int pid = getpid();
char out[256], cmd[4096], buf[8192];
snprintf(out, sizeof out, "/tmp/at911_%d.out", pid);
/* `ww test` builds the fixture (auto-bundling lib/test) and runs it;
* the exit code is the runner's failure count. */
snprintf(cmd, sizeof cmd,
"%s/ww test test/wcc/data/attest_record.ww > %s 2>/dev/null",
bin, out);
int rc = runwait(cmd);
if (rc != 3) {
fprintf(stderr, "911 FAIL: record-and-continue exit %d "
"(expected 3 failures)\n", rc);
return 1;
}
if (slurp(out, buf, sizeof buf) != 0) {
fprintf(stderr, "911 FAIL: cannot read runner output\n");
return 1;
}
for (size_t i = 0; i < sizeof expect_lines / sizeof expect_lines[0]; i++) {
if (strstr(buf, expect_lines[i]) == NULL) {
fprintf(stderr, "911 FAIL: missing runner line '%s'\n"
"--- got ---\n%s\n", expect_lines[i], buf);
unlink(out);
return 1;
}
}
unlink(out);
return 0;
}
static int
all_pass(const char *bin)
{
char cmd[4096];
snprintf(cmd, sizeof cmd,
"%s/ww test test/wcc/data/attest_pass.ww > /dev/null 2>&1", bin);
int rc = runwait(cmd);
if (rc != 0) {
fprintf(stderr, "911 FAIL: all-pass fixture exit %d "
"(expected 0)\n", rc);
return 1;
}
return 0;
}
static int
byteid(const char *bin)
{
int pid = getpid();
char stem[256], comb[256], cs[256], ws[256], cmd[4096];
snprintf(stem, sizeof stem, "/tmp/at911_bid_%d", pid);
snprintf(comb, sizeof comb, "%s.combined.ww", stem);
snprintf(cs, sizeof cs, "/tmp/at911_bid_c_%d.s", pid);
snprintf(ws, sizeof ws, "/tmp/at911_bid_w_%d.s", pid);
/* `ww test -c -o <stem>` (compile-only) writes a lib/test-inclusive
* combined beside -o without running the harness. */
snprintf(cmd, sizeof cmd,
"%s/ww test -c -o %s test/wcc/data/attest_record.ww > /dev/null 2>&1",
bin, stem);
runwait(cmd);
if (access(comb, 0) != 0) {
fprintf(stderr, "911 FAIL: ww test -c produced no %s\n", comb);
return 1;
}
snprintf(cmd, sizeof cmd, "%s/w6c -T %s -o %s 2>/dev/null", bin, comb, cs);
if (runwait(cmd) != 0) { fprintf(stderr, "911 FAIL: w6c -T (byteid)\n"); return 1; }
snprintf(cmd, sizeof cmd, "%s/w6c_ww -T %s -o %s 2>/dev/null", bin, comb, ws);
if (runwait(cmd) != 0) { fprintf(stderr, "911 FAIL: w6c_ww -T (byteid)\n"); return 1; }
char bc[262144], bw[262144];
int rc = 0;
if (slurp(cs, bc, sizeof bc) < 0 || slurp(ws, bw, sizeof bw) < 0) {
fprintf(stderr, "911 FAIL: slurp byteid asm\n");
rc = 1;
} else if (strcmp(bc, bw) != 0) {
fprintf(stderr, "911 FAIL: -T asm differs between stages\n");
rc = 1;
}
unlink(comb); unlink(cs); unlink(ws);
snprintf(cmd, sizeof cmd, "%s.s", stem); unlink(cmd);
snprintf(cmd, sizeof cmd, "%s.o", stem); unlink(cmd);
unlink(stem);
return rc;
}
int
main(void)
{
const char *bin = absbin();
if (!bin) { fprintf(stderr, "911 FAIL: getcwd\n"); return 1; }
if (record_continue(bin) != 0) return 1;
if (all_pass(bin) != 0) return 1;
if (byteid(bin) != 0) return 1;
printf("@test record-and-continue: 3 fault classes recorded + run "
"proceeds + counts + all-pass exit 0 + cs/ww byte-id (#17)\n");
return 0;
}

View File

@@ -5,9 +5,11 @@
* build/run — a lone -I/-L/-l/-o (flag with no following argument) is a
* hard error "ww <cmd>: -X needs an argument" (rc 2), not a
* silently-swallowed positional.
* test — only -I carries meaning; -l/-L/-o and any unknown flag are
* rejected with "ww test: unknown flag" (rc 2); a lone -I is
* "ww test: -I needs an argument" (rc 2).
* test — -I/-c/-o carry meaning; -l/-L and any unknown flag are
* rejected with "ww test: unknown flag" (rc 2); a lone -I/-o
* is "ww test: -X needs an argument" (rc 2); -c/-o without a
* single test file is "ww test: -c/-o need a single test file"
* (rc 2, #17).
* Each row asserts the expected rc + stderr substring AND that the two
* drivers are byte-identical (rule 10): the cstage parse_build_flags /
* do_test must match the wwstage main.ww dobuild/dorun/dotest verbatim.
@@ -36,9 +38,14 @@ static const struct row rows[] = {
{ "run -o", 2, "ww run: -o needs an argument" },
{ "run -l", 2, "ww run: -l needs an argument" },
{ "test -l", 2, "ww test: unknown flag" },
{ "test -o x", 2, "ww test: unknown flag" },
{ "test -zz", 2, "ww test: unknown flag" },
{ "test -I", 2, "ww test: -I needs an argument" },
/* #17: -c (compile-only) + -o are now meaningful for `test`; a lone -o
* needs an arg, and -c/-o require a single test file (not the default
* "." directory enumeration). */
{ "test -o", 2, "ww test: -o needs an argument" },
{ "test -o x", 2, "ww test: -c/-o need a single test file" },
{ "test -c", 2, "ww test: -c/-o need a single test file" },
};
/* Run "<bin>/<drv> <args>" capturing rc + stderr text into err (NUL-

View File

@@ -254,18 +254,29 @@ check_one(const char *bin, const char *cwd, const struct ent *e, int idx)
}
/* exit deliberately ignored: the combined unit is written before
* codegen (cf 990 resolveunit) and only it matters here. */
snprintf(cmd, sizeof cmd,
"cd %s && timeout 180 %s/ww build %s %s >/dev/null 2>&1",
td, bin, incs, base);
* codegen (cf 990 resolveunit) and only it matters here. A @test
* fixture builds via `ww test -c -o <stem>` (compile-only) so the
* resolved unit AUTO-BUNDLES lib/test — the #17 synth's `run()` callee
* must resolve when w6c/w6c_ww -T compile the combined below. Both the
* `-o <stem>` (test) and the next-to-source (build) paths land the
* combined at <stem>.combined.ww. Import-probes carry their own main
* and stay a plain non-test build. */
char stem[512];
snprintf(stem, sizeof stem, "%s", base);
char *sd = strrchr(stem, '.');
if (sd) *sd = '\0';
if (e->fixture)
snprintf(cmd, sizeof cmd,
"cd %s && timeout 180 %s/ww test -c -o %s %s %s >/dev/null 2>&1",
td, bin, stem, incs, base);
else
snprintf(cmd, sizeof cmd,
"cd %s && timeout 180 %s/ww build %s %s >/dev/null 2>&1",
td, bin, incs, base);
runwait(cmd);
char comb[512];
snprintf(comb, sizeof comb, "%s/%s", td, base);
char *dot = strrchr(comb, '.');
if (dot) *dot = '\0';
size_t cn = strlen(comb);
snprintf(comb + cn, sizeof comb - cn, ".combined.ww");
snprintf(comb, sizeof comb, "%s/%s.combined.ww", td, stem);
if (access(comb, 0) != 0) {
fprintf(stderr, "lib_byteid FAIL: %s — no resolved unit\n", label);
goto out;
@@ -357,6 +368,10 @@ static const char *covered[] = {
"lib/io", "lib/math", "lib/rt", "lib/types", "lib/ww/parse",
/* module body dragged into the lib/strconv/test fixtures */
"lib/strconv",
/* #17: the @test runner is AUTO-BUNDLED into every -T combined, so
* every @test fixture above byte-ids it cs/ww; 911_attest_record also
* compares it directly. It has no _test.ww of its own. */
"lib/test",
NULL,
};

View File

@@ -66,9 +66,10 @@ static int
run_fixture(const char *bin)
{
int pid = getpid();
char src[256], comb[256], asmf[256], obj[256], exe[256];
char src[256], comb[256], binout[256], asmf[256], obj[256], exe[256];
char rt[1024], cmd[4096];
snprintf(src, sizeof src, "/tmp/at997_%d.ww", pid);
snprintf(binout, sizeof binout, "/tmp/at997_%d", pid);
snprintf(comb, sizeof comb, "/tmp/at997_%d.combined.ww", pid);
snprintf(asmf, sizeof asmf, "/tmp/at997_%d.s", pid);
snprintf(obj, sizeof obj, "/tmp/at997_%d.o", pid);
@@ -78,10 +79,12 @@ run_fixture(const char *bin)
snprintf(cmd, sizeof cmd, "cp test/wcc/data/attest_pass.ww %s", src);
if (runwait(cmd) != 0) { fprintf(stderr, "997 FAIL: cp\n"); return 1; }
/* ww_ww build resolves `import rt` into the combined unit; it exits
* nonzero (no main — that is what -T synthesizes), so we gate on the
* combined ARTIFACT existing, not the exit code. */
snprintf(cmd, sizeof cmd, "%s/ww_ww build %s > /dev/null 2>&1", bin, src);
/* `ww_ww test -c -o <stem>` (compile-only) resolves imports AND auto-
* bundles lib/test (#17) into <stem>.combined.ww — the synth's run()
* callee must link below — WITHOUT running the harness. We gate on the
* combined ARTIFACT existing; `-o` keeps the binary off the CWD. */
snprintf(cmd, sizeof cmd, "%s/ww_ww test -c -o %s %s > /dev/null 2>&1",
bin, binout, src);
runwait(cmd);
if (access(comb, 0) != 0) {
fprintf(stderr, "997 FAIL: ww_ww build produced no %s\n", comb);
@@ -101,23 +104,38 @@ run_fixture(const char *bin)
return 1;
}
unlink(src); unlink(comb); unlink(asmf); unlink(obj); unlink(exe);
unlink(binout);
char tmp[300];
snprintf(tmp, sizeof tmp, "%s.s", binout); unlink(tmp);
snprintf(tmp, sizeof tmp, "%s.o", binout); unlink(tmp);
return 0;
}
/* byteid — `w6c -T` and `w6c_ww -T` on the same source must agree. */
/* byteid — `w6c -T` and `w6c_ww -T` on the same unit must agree. The #17
* synth's run() callee only resolves against the auto-bundled lib/test, so
* we byte-compare the lib/test-INCLUSIVE combined (raw -T of the fixture
* would loud-reject the undefined run); `ww test -c` writes that combined. */
static int
byteid(const char *bin)
{
int pid = getpid();
char cs[256], ws[256], cmd[4096];
char stem[256], comb[256], cs[256], ws[256], cmd[4096];
snprintf(stem, sizeof stem, "/tmp/at997_bid_%d", pid);
snprintf(comb, sizeof comb, "%s.combined.ww", stem);
snprintf(cs, sizeof cs, "/tmp/at997_bid_c_%d.s", pid);
snprintf(ws, sizeof ws, "/tmp/at997_bid_w_%d.s", pid);
snprintf(cmd, sizeof cmd, "%s/w6c -T test/wcc/data/attest_pass.ww -o %s 2>/dev/null",
bin, cs);
snprintf(cmd, sizeof cmd,
"%s/ww test -c -o %s test/wcc/data/attest_pass.ww > /dev/null 2>&1",
bin, stem);
runwait(cmd);
if (access(comb, 0) != 0) {
fprintf(stderr, "997 FAIL: ww test -c produced no %s\n", comb);
return 1;
}
snprintf(cmd, sizeof cmd, "%s/w6c -T %s -o %s 2>/dev/null", bin, comb, cs);
if (runwait(cmd) != 0) { fprintf(stderr, "997 FAIL: w6c -T (byteid)\n"); return 1; }
snprintf(cmd, sizeof cmd, "%s/w6c_ww -T test/wcc/data/attest_pass.ww -o %s 2>/dev/null",
bin, ws);
snprintf(cmd, sizeof cmd, "%s/w6c_ww -T %s -o %s 2>/dev/null", bin, comb, ws);
if (runwait(cmd) != 0) { fprintf(stderr, "997 FAIL: w6c_ww -T (byteid)\n"); return 1; }
char *bc = NULL, *bw = NULL;
@@ -131,7 +149,11 @@ byteid(const char *bin)
rc = 1;
}
free(bc); free(bw);
unlink(cs); unlink(ws);
unlink(comb); unlink(cs); unlink(ws);
char tmp[300];
snprintf(tmp, sizeof tmp, "%s.s", stem); unlink(tmp);
snprintf(tmp, sizeof tmp, "%s.o", stem); unlink(tmp);
unlink(stem);
return rc;
}
@@ -180,10 +202,12 @@ static int
nondrop(const char *bin)
{
int pid = getpid();
char wp[256], wt[256], cp[256], cmd[4096];
char wp[256], wt[256], cp[256], stem[256], comb[300], cmd[4096];
snprintf(wp, sizeof wp, "/tmp/at997nd_wp_%d.s", pid);
snprintf(wt, sizeof wt, "/tmp/at997nd_wt_%d.s", pid);
snprintf(cp, sizeof cp, "/tmp/at997nd_cp_%d.s", pid);
snprintf(stem, sizeof stem, "/tmp/at997nd_c_%d", pid);
snprintf(comb, sizeof comb, "%s.combined.ww", stem);
snprintf(cmd, sizeof cmd,
"%s/w6c_ww test/wcc/data/attest_nondrop.ww -o %s 2>/dev/null", bin, wp);
@@ -191,8 +215,14 @@ nondrop(const char *bin)
fprintf(stderr, "997 FAIL: w6c_ww non-T nondrop compile\n");
return 1;
}
/* the -T compile synthesizes a main calling lib/test's run(), so it
* needs the lib/test-inclusive combined `ww test -c` writes. */
snprintf(cmd, sizeof cmd,
"%s/w6c_ww -T test/wcc/data/attest_nondrop.ww -o %s 2>/dev/null", bin, wt);
"%s/ww test -c -o %s test/wcc/data/attest_nondrop.ww > /dev/null 2>&1",
bin, stem);
runwait(cmd);
snprintf(cmd, sizeof cmd,
"%s/w6c_ww -T %s -o %s 2>/dev/null", bin, comb, wt);
if (runwait(cmd) != 0) {
fprintf(stderr, "997 FAIL: w6c_ww -T nondrop compile\n");
return 1;
@@ -232,7 +262,11 @@ nondrop(const char *bin)
}
free(bc); free(bw);
}
unlink(wp); unlink(wt); unlink(cp);
unlink(wp); unlink(wt); unlink(cp); unlink(comb);
char tmp[300];
snprintf(tmp, sizeof tmp, "%s.s", stem); unlink(tmp);
snprintf(tmp, sizeof tmp, "%s.o", stem); unlink(tmp);
unlink(stem);
return rc;
}

View File

@@ -0,0 +1,31 @@
// @test fixture for #17 record-and-continue: a mix of one passing test,
// then the three runtime fault classes the lib/test fork+wait4 runner
// must each catch and PROCEED past (failed assert → SIGABRT, nil deref →
// SIGSEGV, divide-by-zero → SIGFPE), then a final passing test to prove
// the run reaches the tail after every failure. Driver:
// test/wcc/911_attest_record.c. The runner reports in source order, so
// the expected per-test verdicts are pinned positionally there.
package data;
@test fn rec_pass_a() void = {
assert(1 + 1 == 2);
};
@test fn rec_assert() void = {
assert(1 == 2);
};
@test fn rec_segv() void = {
let p: *i32 = nil: *i32;
*p = 7i32;
};
@test fn rec_div0() void = {
let z: i32 = 0;
let _: i32 = 1 / z;
};
@test fn rec_pass_b() void = {
assert(true);
};