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

@@ -27,9 +27,9 @@
* combines lib/rt/malloc.ww into the fixture and would always supply
* the @symbol decl, masking the regression.
*
* The runtime `rows` below run the generated binary under cstage and
* (when present) wwstage; the exit code is the regression-catching
* gate. The cstage row is the cross-check oracle.
* The runtime rows moved to the test/wcc/data/r75_alloc_{str_singleton,
* i32_then_str,str_then_i32,two_str,f64_str_i32,str_readback} fixtures;
* this carrier retains only the asm-line checks below.
*
* Full asm byte-identity is intentionally NOT checked here — the
* `(BX)` (cstage txt.c omits zero displacement) vs `0(BX)` (wwstage
@@ -41,6 +41,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/wait.h>
@@ -54,119 +55,6 @@ runwait(const char *cmd)
return -1;
}
struct row { const char *label; const char *src; int want; };
static const struct row rows[] = {
/* Singleton str field. Pre-fix p.s.len stayed 0; post-fix 5. */
{ "alloc_str_singleton",
"package main;\n"
"import rt;\n"
"type holder = struct { s: str };\n"
"fn main() i32 = {\n"
" let p: *holder = alloc(holder { s = \"hello\" })!;\n"
" return p.s.len;\n"
"};\n",
5 },
/* i32 field before str. Verifies field iteration restarts cleanly
* after the str-field branch and that the i32 store path is
* unaffected. Pre-fix: 100 + 0 = 100; post-fix: 100 + 2 = 102. */
{ "alloc_i32_then_str",
"package main;\n"
"import rt;\n"
"type holder = struct { n: i32, s: str };\n"
"fn main() i32 = {\n"
" let p: *holder = alloc(holder { n = 100, s = \"hi\" })!;\n"
" return p.n + p.s.len;\n"
"};\n",
102 },
/* str field before i32. Verifies foff>0 routing for the trailing
* i32 store after the str-field branch. Pre-fix: 0 + 7 = 7;
* post-fix: 5 + 7 = 12. */
{ "alloc_str_then_i32",
"package main;\n"
"import rt;\n"
"type holder = struct { s: str, n: i32 };\n"
"fn main() i32 = {\n"
" let p: *holder = alloc(holder { s = \"world\", n = 7 })!;\n"
" return p.s.len + p.n;\n"
"};\n",
12 },
/* Two str fields. Pre-fix both lens stayed 0; post-fix 3 + 6 = 9.
* Pins that `fi = nil` advances correctly between str fields. */
{ "alloc_two_str",
"package main;\n"
"import rt;\n"
"type holder = struct { a: str, b: str };\n"
"fn main() i32 = {\n"
" let p: *holder = alloc(holder { a = \"foo\", b = \"barbaz\" })!;\n"
" return p.a.len + p.b.len;\n"
"};\n",
9 },
/* Float-then-str-then-int. Pre-fix str.len=0 so result is
* 0 + 10 = 10; post-fix 3 + 10 = 13. Confirms the str-field
* branch slots between the existing float and integer branches
* without disrupting either. */
{ "alloc_f64_str_i32",
"package main;\n"
"import rt;\n"
"type holder = struct { f: f64, s: str, n: i32 };\n"
"fn main() i32 = {\n"
" let p: *holder = alloc(holder { f = 1.5f64, s = \"abc\", n = 10 })!;\n"
" return p.s.len + p.n;\n"
"};\n",
13 },
/* Read-back via p.s[i]: confirms str.ptr survived the store
* (foff=0 case) while still pinning str.len. Pre-fix len=0 so
* the loop body never executes; post-fix sum is 'h'+'i' = 209.
* Indexes the string by hand to avoid pulling in stdlib. */
{ "alloc_str_readback",
"package main;\n"
"import rt;\n"
"type holder = struct { s: str };\n"
"fn main() i32 = {\n"
" let p: *holder = alloc(holder { s = \"hi\" })!;\n"
" let sum: i32 = 0;\n"
" let i: i32 = 0;\n"
" for (i < p.s.len) {\n"
" sum += p.s[i]: i32;\n"
" i += 1;\n"
" };\n"
" return sum;\n"
"};\n",
209 },
};
/* run_driver — compile r->src via the given driver and exec; return
* the process exit code. Mirror of 703/704. */
static int
run_driver(const char *driver, const struct row *r, int i)
{
char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024];
snprintf(tmpdir, sizeof tmpdir, "/tmp/wcas_%d_d_%d", getpid(), i);
mkdir(tmpdir, 0755);
snprintf(src, sizeof src, "%s/wcas_%d_%d.ww", tmpdir, getpid(), i);
snprintf(outbin, sizeof outbin, "%s/wcas_%d_%d", tmpdir, getpid(), i);
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
FILE *f = fopen(src, "wb");
if (!f) { runwait(rmcmd); return -1; }
fputs(r->src, f);
fclose(f);
snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "row[%s]: build via %s failed\n",
r->label, driver);
runwait(rmcmd);
return -1;
}
int got = runwait(outbin);
runwait(rmcmd);
return got;
}
/* asm_row — fixture for the ffiresolve CALL-line check. `want_sym`
* is the unqualified symbol expected inside `CALL\t<sym>(SB)` from
* both stages' .s output. Single-file `w6c` compile (no `ww build`
@@ -287,15 +175,15 @@ asm_call_check(const char *bin, const struct asm_row *r, int i)
snprintf(cmd, sizeof cmd, "%s/w6c -o %s %s 2>/dev/null", bin, cs, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "asm[%s]: w6c errored\n", r->label);
unlink(src);
return -1;
rc = -1;
goto cleanup;
}
snprintf(cmd, sizeof cmd, "%s/w6c_ww -o %s %s 2>/dev/null",
bin, ws, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "asm[%s]: w6c_ww errored\n", r->label);
unlink(src); unlink(cs);
return -1;
rc = -1;
goto cleanup;
}
char want[64];
@@ -351,7 +239,25 @@ asm_call_check(const char *bin, const struct asm_row *r, int i)
}
if (fc) fclose(fc);
if (fw) fclose(fw);
unlink(src); unlink(cs); unlink(ws);
cleanup:;
/* a failing compile can still leave a partial .s — ENOENT is the
* only tolerable unlink error on the never-created legs. */
int cleanfail = 0;
if (unlink(src) != 0 && errno != ENOENT) {
perror(src);
cleanfail = 1;
}
if (unlink(cs) != 0 && errno != ENOENT) {
perror(cs);
cleanfail = 1;
}
if (unlink(ws) != 0 && errno != ENOENT) {
perror(ws);
cleanfail = 1;
}
if (cleanfail && rc == 0)
rc = -1;
return rc;
}
@@ -398,15 +304,15 @@ asm_disp_check(const char *bin, const struct asm_disp_row *r, int i)
snprintf(cmd, sizeof cmd, "%s/w6c -o %s %s 2>/dev/null", bin, cs, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "disp[%s]: w6c errored\n", r->label);
unlink(src);
return -1;
rc = -1;
goto cleanup;
}
snprintf(cmd, sizeof cmd, "%s/w6c_ww -o %s %s 2>/dev/null",
bin, ws, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "disp[%s]: w6c_ww errored\n", r->label);
unlink(src); unlink(cs);
return -1;
rc = -1;
goto cleanup;
}
int chit = file_contains(cs, r->want_line);
@@ -419,7 +325,24 @@ asm_disp_check(const char *bin, const struct asm_disp_row *r, int i)
rc = -1;
}
unlink(src); unlink(cs); unlink(ws);
cleanup:;
/* a failing compile can still leave a partial .s — ENOENT is the
* only tolerable unlink error on the never-created legs. */
int cleanfail = 0;
if (unlink(src) != 0 && errno != ENOENT) {
perror(src);
cleanfail = 1;
}
if (unlink(cs) != 0 && errno != ENOENT) {
perror(cs);
cleanfail = 1;
}
if (unlink(ws) != 0 && errno != ENOENT) {
perror(ws);
cleanfail = 1;
}
if (cleanfail && rc == 0)
rc = -1;
return rc;
}
@@ -436,41 +359,8 @@ main(void)
bin = absbin;
}
char cdrv[1024];
snprintf(cdrv, sizeof cdrv, "%s/ww", bin);
char wdrv[1024];
snprintf(wdrv, sizeof wdrv, "%s/ww_ww", bin);
struct { const char *name; const char *path; int gated_on_existence; }
drivers[] = {
{ "cstage", cdrv, 0 },
{ "wwstage", wdrv, 1 },
{ NULL, NULL, 0 },
};
int n = (int)(sizeof rows / sizeof rows[0]);
int total = 0, fail = 0;
for (int d = 0; drivers[d].name; d++) {
if (drivers[d].gated_on_existence
&& access(drivers[d].path, X_OK) != 0) {
fprintf(stderr, "cgalloc_str_field: skip %s (no %s)\n",
drivers[d].name, drivers[d].path);
continue;
}
for (int i = 0; i < n; i++) {
int got = run_driver(drivers[d].path, &rows[i], i);
total++;
if (got != rows[i].want) {
fprintf(stderr,
"cgalloc_str_field[%s][%s]: exit=%d want=%d\n",
drivers[d].name, rows[i].label,
got, rows[i].want);
fail++;
}
}
}
/* Asm CALL-line check via direct w6c / w6c_ww. Gated on w6c_ww
* existence — when wwstage isn't built yet the cstage half alone
* can't catch the divergence. */