test/wcc: carrier ownership repair and driver-contract adaptation

Every surviving carrier now owns its artifacts: checked mkdir/mkdtemp/
fopen acquisition, one all-exit cleanup funnel per carrier, ENOENT-
tolerant checked unlinks, exact-path deletion (rm -rf only for an
owned pid-keyed dir or a .sepwork beneath one), and cleanup failure
fails a passing carrier without overwriting its diagnostic. In the
same pass the carriers adapt to the driver contract this branch lands:
--sep and WW_PKGCACHE are gone, -S and the /tmp/ww_run_<pid> scratch
contract are asserted, and rows whose runtime or reject coverage moved
to test/wcc/data fixtures or test/lang @test owners are trimmed to the
byte/artifact/diagnostic observations only they can make.

Repair and adaptation ride together because most files interleave both
in the same hunks; splitting would manufacture intermediate carrier
states that never existed and cannot run against either driver.
This commit is contained in:
2026-08-07 23:02:47 +09:00
parent b2899dd8d3
commit a95a7a316b
132 changed files with 7573 additions and 6172 deletions

View File

@@ -18,8 +18,8 @@
* invalid | [255] | invalid | 4
* all_arms | all four, mixed | (1,2,4,3) | 219 (1243 % 256)
*
* Plus a byte-id gate: cstage.s == wwstage.s on the all_arms program
* (rule-10 — the cs==ww gate over the cross-module match the doc flagged).
* Runtime ownership is now r989_m1union_*; this wrapper retains all_arms
* solely for cstage.s == wwstage.s across the separate-package build.
*/
#include <stdio.h>
#include <stdlib.h>
@@ -57,44 +57,20 @@ struct row {
};
static const struct row rows[] = {
{ "rune",
"export fn main() int = {\n"
" let s: []u8 = [65u8];\n"
" let d = utf8.decode(s);\n"
" return classify(&d);\n"
"};\n", 1 },
{ "done",
"export fn main() int = {\n"
" let s: []u8 = [65u8];\n"
" let d = utf8.decode(s);\n"
" classify(&d);\n"
" return classify(&d);\n"
"};\n", 2 },
{ "more",
"export fn main() int = {\n"
" let s: []u8 = [195u8];\n"
" let d = utf8.decode(s);\n"
" return classify(&d);\n"
"};\n", 3 },
{ "invalid",
"export fn main() int = {\n"
" let s: []u8 = [255u8];\n"
" let d = utf8.decode(s);\n"
" return classify(&d);\n"
"};\n", 4 },
/* Runtime rows moved to r989_m1union_*; retain byte-id source only. */
{ "all_arms",
"export fn main() int = {\n"
" let g: []u8 = [65u8];\n"
" let dg = utf8.decode(g);\n"
" let a = classify(&dg);\n"
" let b = classify(&dg);\n"
" let bad: []u8 = [255u8];\n"
" let db = utf8.decode(bad);\n"
" let c = classify(&db);\n"
" let tr: []u8 = [195u8];\n"
" let dt = utf8.decode(tr);\n"
" let e = classify(&dt);\n"
" return a * 1000 + b * 100 + c * 10 + e;\n"
"\tlet g: []u8 = [65u8];\n"
"\tlet dg = utf8.decode(g);\n"
"\tlet a = classify(&dg);\n"
"\tlet b = classify(&dg);\n"
"\tlet bad: []u8 = [255u8];\n"
"\tlet db = utf8.decode(bad);\n"
"\tlet c = classify(&db);\n"
"\tlet tr: []u8 = [195u8];\n"
"\tlet dt = utf8.decode(tr);\n"
"\tlet e = classify(&dt);\n"
"\treturn a * 1000 + b * 100 + c * 10 + e;\n"
"};\n", 219 },
};
@@ -110,22 +86,6 @@ write_src(const char *path, const struct row *r)
return 0;
}
/* build_run — build `src` to `<stem>` binary via `driver`, run it; return
* the binary's exit code, or -1 on a build failure.
* #93 sep layout: `--sep -o <stem>` emits per-unit asm under
* <stem>.sepwork/ (root in __root.s, encoding.utf8 in encoding.utf8.s); the
* binary is still <stem>. WW_PKGCACHE is pinned beside <stem>. */
static int
build_run(const char *driver, const char *src, const char *stem)
{
char cmd[1024];
snprintf(cmd, sizeof cmd,
"WW_PKGCACHE='%s.pkgc' timeout 180 %s build --sep -o '%s' '%s' "
"2>/dev/null", stem, driver, stem, src);
if (runwait(cmd) != 0) return -1;
return runwait(stem);
}
int
main(void)
{
@@ -142,47 +102,10 @@ main(void)
snprintf(cdrv, sizeof cdrv, "%s/ww", bin);
snprintf(wdrv, sizeof wdrv, "%s/ww_ww", bin);
struct { const char *name; const char *drv; int gated; }
drivers[] = {
{ "cstage", cdrv, 0 },
{ "wwstage", wdrv, 1 },
{ NULL, NULL, 0 },
};
int n = (int)(sizeof rows / sizeof rows[0]);
int total = 0, fail = 0;
int pid = (int)getpid();
char src[80], stem[80];
for (int d = 0; drivers[d].name; d++) {
if (drivers[d].gated && access(drivers[d].drv, X_OK) != 0) {
fprintf(stderr, "m1union_run: skip %s (no %s)\n",
drivers[d].name, drivers[d].drv);
continue;
}
for (int i = 0; i < n; i++) {
total++;
snprintf(src, sizeof src, "/tmp/m1union_%d_%d_%d.ww",
pid, d, i);
snprintf(stem, sizeof stem, "/tmp/m1union_%d_%d_%d",
pid, d, i);
if (write_src(src, &rows[i]) != 0) { fail++; continue; }
int got = build_run(drivers[d].drv, src, stem);
if (got != rows[i].want_exit) {
fprintf(stderr, "m1union_run[%s][%s]: exit=%d "
"want=%d\n", drivers[d].name, rows[i].label,
got, rows[i].want_exit);
fail++;
}
char cmd[256];
/* #93: drop the sep scratch + pinned pkgcache too. */
snprintf(cmd, sizeof cmd, "rm -rf '%s' '%s' "
"'%s.sepwork' '%s.pkgc'", src, stem, stem, stem);
runwait(cmd);
}
}
/* rule-10 byte-id gate on the all_arms cross-module match. */
if (access(wdrv, X_OK) == 0) {
total++;
@@ -192,18 +115,25 @@ main(void)
snprintf(cstem, sizeof cstem, "/tmp/m1union_bid_c_%d", pid);
char wstem[80];
snprintf(wstem, sizeof wstem, "/tmp/m1union_bid_w_%d", pid);
if (write_src(csrc, r) == 0) {
if (write_src(csrc, r) != 0) {
/* a silent skip here would print "1/1 ok" having
* asserted nothing; nothing was created, so no
* cleanup is owed either. */
fprintf(stderr, "m1union_run: cannot write %s\n",
csrc);
fail++;
} else {
/* #93 sep layout: each stage emits per-unit asm under
* <stem>.sepwork/ (__root.s + encoding.utf8.s); the
* rule-10 byte-id gate becomes a recursive diff of the
* two sepwork trees. */
snprintf(cmd, sizeof cmd,
"WW_PKGCACHE='%s.pkgc' %s build --sep -o '%s' '%s' "
"2>/dev/null", cstem, cdrv, cstem, csrc);
"%s build -S -o '%s' '%s' "
"2>/dev/null", cdrv, cstem, csrc);
int cb = runwait(cmd);
snprintf(cmd, sizeof cmd,
"WW_PKGCACHE='%s.pkgc' %s build --sep -o '%s' '%s' "
"2>/dev/null", wstem, wdrv, wstem, csrc);
"%s build -S -o '%s' '%s' "
"2>/dev/null", wdrv, wstem, csrc);
int wb = runwait(cmd);
if (cb != 0 || wb != 0) {
fprintf(stderr, "m1union_run: byte-id build "
@@ -225,10 +155,22 @@ main(void)
fail++;
}
}
/* exact owned paths only (`build -S` writes solely
* under <stem>.sepwork/, plus the .scat concats) —
* no prefix glob; a failed rm must fail the carrier,
* not leak silently. */
snprintf(cmd, sizeof cmd,
"rm -rf '%s' '%s.scat' '%s.sepwork' "
"'%s.scat' '%s.sepwork'",
csrc, cstem, cstem, wstem, wstem);
if (runwait(cmd) != 0) {
fprintf(stderr,
"m1union_run: cleanup rm failed\n");
fail++;
}
}
snprintf(cmd, sizeof cmd, "rm -rf '%s' '%s'* '%s'*", csrc,
cstem, wstem);
runwait(cmd);
} else {
fprintf(stderr, "m1union_run: skip byte-id (no ww_ww)\n");
}
if (fail) {