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

@@ -43,6 +43,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/wait.h>
@@ -75,6 +76,7 @@ struct row {
* the same u16 sequence strconv used, so the expected exits are unchanged
* (idx0→0, idx2→0x0801&0xFF=1, idx4→0x1006&0xFF=6). */
#define PROBE_MOD \
"package wcmodarr;\n" \
"export let probe_table: [8]u16 = [0u16, 0x0800u16, 0x0801u16, " \
"0x0803u16, 0x1006u16, 0x1009u16, 0x100Du16, 0x1812u16];\n"
@@ -169,62 +171,93 @@ main(void)
int n = 0, fail = 0;
for (int i = 0; rows[i].src; i++, n++) {
char tmpdir[96];
snprintf(tmpdir, sizeof tmpdir, "/tmp/wwmoda_%d_d_%d",
getpid(), i);
mkdir(tmpdir, 0755);
char src[160];
char tmpdir[] = "/tmp/wwmoda_XXXXXX";
char src[160], moddir[224] = {0}, modf[320] = {0};
char stem[200] = {0}, scratch[232] = {0};
char cs_s[200] = {0}, ws_s[200] = {0}, cmd[2048];
int rowfail = 0, moddir_owned = 0;
if (mkdtemp(tmpdir) == NULL) {
fprintf(stderr, "row[%s]: workspace acquisition failed\n",
rows[i].label);
fail++;
continue;
}
snprintf(src, sizeof src, "%s/main915.ww", tmpdir);
FILE *f = fopen(src, "wb");
if (f == NULL) { fail++; rmdir(tmpdir); continue; }
if (f == NULL) {
fprintf(stderr, "row[%s]: source create failed\n",
rows[i].label);
rowfail = 1;
goto row_done;
}
fputs(rows[i].src, f);
fclose(f);
int werr = ferror(f);
if (fclose(f) != 0) werr = 1;
if (werr) {
fprintf(stderr, "row[%s]: source write failed\n",
rows[i].label);
rowfail = 1;
goto row_done;
}
char cmd[2048];
/* Exported-probe-table package lives at <tmpdir>/<mod>/<mod>.ww
* so the sep dep-scan (rooted at the entry's dir) resolves the
* `import <mod>;`. */
if (rows[i].modname != NULL) {
char moddir[224], modf[320];
snprintf(moddir, sizeof moddir, "%s/%s", tmpdir,
rows[i].modname);
mkdir(moddir, 0755);
if (mkdir(moddir, 0755) != 0) {
fprintf(stderr, "row[%s]: module directory create failed\n",
rows[i].label);
rowfail = 1;
goto row_done;
}
moddir_owned = 1;
snprintf(modf, sizeof modf, "%s/%s.ww", moddir,
rows[i].modname);
FILE *mf = fopen(modf, "wb");
if (mf == NULL) {
fail++;
snprintf(cmd, sizeof cmd, "rm -rf %s", tmpdir);
(void)runwait(cmd);
continue;
fprintf(stderr, "row[%s]: module source create failed\n",
rows[i].label);
rowfail = 1;
goto row_done;
}
fputs(rows[i].modsrc, mf);
fclose(mf);
werr = ferror(mf);
if (fclose(mf) != 0) werr = 1;
if (werr) {
fprintf(stderr, "row[%s]: module source write failed\n",
rows[i].label);
rowfail = 1;
goto row_done;
}
}
/* Single-file runtime behavior moved to r915_arr_* wwfixtures.
* Keep auxiliary-package rows here because the fixture grammar
* cannot materialize their directory/import topology. */
if (rows[i].modname != NULL) {
/* #93 sep layout: build via `--sep -o <stem>` (the exported
/* #93 sep layout: build via `-o <stem>` (the exported
* probe table links across packages under separate compilation);
* WW_PKGCACHE pinned under tmpdir. */
char stem[200];
* all outputs stay under tmpdir. */
snprintf(stem, sizeof stem, "%s/main915", tmpdir);
snprintf(scratch, sizeof scratch, "%s.sepwork", stem);
snprintf(cmd, sizeof cmd,
"cd %s && WW_PKGCACHE=%s/pkgc %s/ww build --sep -o %s %s "
">/dev/null 2>&1", tmpdir, tmpdir, bin, stem, src);
"cd %s && %s/ww build -o %s %s "
">/dev/null 2>&1", tmpdir, bin, stem, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "row[%s]: cstage build failed\n",
rows[i].label);
fail++;
snprintf(cmd, sizeof cmd, "rm -rf %s", tmpdir);
(void)runwait(cmd);
continue;
rowfail = 1;
goto row_done;
}
int got = runwait(stem);
if (got != rows[i].want_exit) {
fprintf(stderr, "row[%s]: cstage exit %d, want %d\n",
rows[i].label, got, rows[i].want_exit);
fail++;
rowfail = 1;
}
}
/* Byte-id leg — bare w6c vs w6c_ww (the compiler binaries, NOT
@@ -232,7 +265,6 @@ main(void)
* fed standalone; the module rows' runtime exit IS their gate
* (+ the 994 bootstrap corpus for the cross-stage byte-id). */
if (rows[i].modname == NULL) {
char cs_s[200], ws_s[200];
snprintf(cs_s, sizeof cs_s, "%s/cs.s", tmpdir);
snprintf(ws_s, sizeof ws_s, "%s/ww.s", tmpdir);
snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null",
@@ -240,26 +272,49 @@ main(void)
if (runwait(cmd) != 0) {
fprintf(stderr, "row[%s]: w6c failed\n",
rows[i].label);
fail++;
rowfail = 1;
} else {
snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null",
w6c_ww, ws_s, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "row[%s]: w6c_ww failed\n",
rows[i].label);
fail++;
rowfail = 1;
} else if (slurp_eq(cs_s, ws_s) != 0) {
fprintf(stderr,
"row[%s]: cstage/wwstage .s DIFFER "
"(rule-10 byte-id violation)\n",
rows[i].label);
fail++;
rowfail = 1;
}
}
}
snprintf(cmd, sizeof cmd, "rm -rf %s", tmpdir);
(void)runwait(cmd);
row_done:
{
int cleanfail = 0;
if (cs_s[0] && unlink(cs_s) != 0 && errno != ENOENT)
cleanfail = 1;
if (ws_s[0] && unlink(ws_s) != 0 && errno != ENOENT)
cleanfail = 1;
if (scratch[0]) {
snprintf(cmd, sizeof cmd, "rm -rf %s", scratch);
if (runwait(cmd) != 0) cleanfail = 1;
}
if (stem[0] && unlink(stem) != 0 && errno != ENOENT)
cleanfail = 1;
if (modf[0] && unlink(modf) != 0 && errno != ENOENT)
cleanfail = 1;
if (moddir_owned && rmdir(moddir) != 0) cleanfail = 1;
if (unlink(src) != 0 && errno != ENOENT) cleanfail = 1;
if (rmdir(tmpdir) != 0) cleanfail = 1;
if (cleanfail) {
fprintf(stderr, "row[%s]: workspace cleanup failed\n",
rows[i].label);
rowfail = 1;
}
}
if (rowfail) fail++;
}
if (fail) {