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

@@ -1,5 +1,5 @@
/*
* 946_structparam_run — runtime + byte-id + asm-pattern net for #165, the
* 946_structparam_run — byte-id + asm-pattern net for #165, the
* float-bearing struct-PARAM SysV ABI (the param twin of #171's struct
* RETURN, and the struct counterpart of #163's per-element tuple PARAM).
*
@@ -14,7 +14,7 @@
* NECESSARY-NOT-SUFFICIENT here (cf. 907_f32arg_run, same situation). The
* genuine defect is SysV register-CLASS conformance, observable only in
* the emitted asm (and at a real ABI boundary). The discriminating
* dimension is therefore the asm pattern (c) below.
* dimension is therefore the asm pattern below.
*
* THE FIX: per-EIGHTBYTE SysV classification (structs classify per
* eightbyte, unlike #163's per-element tuples). Each 8-byte eightbyte that
@@ -33,17 +33,17 @@
* f32f32 row asserts BOTH the correct round-tripped value AND the ABSENCE
* of an SSE receive, proving the gate caught it.
*
* Each row carries THREE dimensions:
* (a) cstage `ww build` + run — exit code (end-to-end round-trip).
* (b) w6c vs w6c_ww `.s` cmp — rule-10 byte-id (both stages identical).
* (c) asm-pattern on the CALLEE function's receive: a lone-f64 eightbyte
* The end-to-end values now live in r946_structparam_* fixtures. This carrier
* retains the two observations unavailable to the fixture grammar:
* (a) w6c vs w6c_ww `.s` cmp — rule-10 byte-id (both stages identical).
* (b) asm-pattern on the CALLEE function's receive: a lone-f64 eightbyte
* is received `MOVSD Xn, -off(BP)` (XMM -> slot); a GP eightbyte is
* `MOVQ DI, ...`. The marker is scoped to the callee `main.use` text
* (main's float-literal init also emits `MOVSD X0, -off(BP)`, so a
* whole-file grep would not discriminate). PRESENT for the SSE-routed
* rows, ABSENT for the GP / fallback rows. A pre-fix (or GP-regressed)
* build receives every struct eightbyte via MOVQ -> marker absent,
* which is exactly what (c) catches.
* which is exactly what the pattern check catches.
*/
#include <stdio.h>
#include <stdlib.h>
@@ -64,7 +64,6 @@ runwait(const char *cmd)
struct row {
const char *label;
const char *src;
int want_exit;
int want_sse; /* 1 = callee must receive an f64 eightbyte via XMM */
};
@@ -79,7 +78,7 @@ static const struct row rows[] = {
"\tlet s: pff = pff { a = 3.0, b = 5.0 };\n"
"\tif (use(s) != 8.0) { return 1; };\n"
"\treturn 0;\n"
"};\n", 0, 1 },
"};\n", 1 },
/* struct{f64,i64} — eb0 lone f64 (X0), eb1 pure-INT (DI). Class is
* independent of eightbyte position. (s.a:i64)+s.b = 3+5 = 8. */
{ "f64i64_arg",
@@ -90,7 +89,7 @@ static const struct row rows[] = {
"\tlet s: pfi = pfi { a = 3.0, b = 5 };\n"
"\tif (use(s) != 8) { return 1; };\n"
"\treturn 0;\n"
"};\n", 0, 1 },
"};\n", 1 },
/* struct{i64,f64} — order-swap: eb0 pure-INT (DI), eb1 lone f64 (X0,
* the first float still gets X0). Confirms the float lands in the next
* XMM regardless of position. s.a + (s.b:i64) = 3+5 = 8. */
@@ -102,7 +101,7 @@ static const struct row rows[] = {
"\tlet s: pif = pif { a = 3, b = 5.0 };\n"
"\tif (use(s) != 8) { return 1; };\n"
"\treturn 0;\n"
"};\n", 0, 1 },
"};\n", 1 },
/* GP REGRESSION — struct{i64,i64}: every eightbyte pure-INT, no float
* to route, so it STAYS on the GP transport unchanged (the in-tree
* byte-id case). Callee receives via MOVQ DI/SI -> no SSE marker. */
@@ -114,7 +113,7 @@ static const struct row rows[] = {
"\tlet s: pii = pii { a = 3, b = 5 };\n"
"\tif (use(s) != 8) { return 1; };\n"
"\treturn 0;\n"
"};\n", 0, 0 },
"};\n", 0 },
/* FALLBACK GATE — struct{f32,f32}: two f32 pack into ONE SSE eightbyte
* (8B struct). The gate rejects f32, so the struct stays GP-routed
* (received via MOVQ DI). The value still round-trips (the 8B MOVQ
@@ -129,7 +128,7 @@ static const struct row rows[] = {
"\tlet s: pf32 = pf32 { a = 3.0f32, b = 5.0f32 };\n"
"\tif (use(s) != 8) { return 1; };\n"
"\treturn 0;\n"
"};\n", 0, 0 },
"};\n", 0 },
/* CURSOR INDEPENDENCE — i64 scalar + struct{f64,f64}. n->DI (INTEGER
* cursor), s.a->X0, s.b->X1 (SSE cursor), independent counters.
* n + s.a + s.b = 2+3+5 = 10. SSE receive present. */
@@ -143,8 +142,8 @@ static const struct row rows[] = {
"\tlet s: pff = pff { a = 3.0, b = 5.0 };\n"
"\tif (use(2, s) != 10) { return 1; };\n"
"\treturn 0;\n"
"};\n", 0, 1 },
{ NULL, NULL, 0, 0 }
"};\n", 1 },
{ NULL, NULL, 0 }
};
static int
@@ -177,6 +176,12 @@ callee_receives_sse(const char *path)
if (!f) return -1;
static char buf[1 << 18];
size_t n = fread(buf, 1, sizeof buf - 1, f);
/* a .s larger than the buffer would silently drop the region the
* marker scan needs — refuse instead of scanning a truncated tail. */
if (n == sizeof buf - 1 && fgetc(f) != EOF) {
fclose(f);
return -1;
}
fclose(f);
buf[n] = '\0';
@@ -213,18 +218,21 @@ main(void)
int n = 0, fail = 0;
for (int i = 0; rows[i].src; i++, n++) {
/* src, binary, and both .s files all live under one tmpdir so
/* The source and both .s files live under one tmpdir so
* the compiler's path-derived .sepwork scratch stays inside it;
* a single `rm -rf` at the end of all phases reclaims it. */
char tmpdir[64], src[128], outbin[128];
char tmpdir[64], src[128];
char cs_s[128], ws_s[128], rmcmd[160];
snprintf(tmpdir, sizeof tmpdir, "/tmp/wwstp_%d_d_%d",
getpid(), i);
mkdir(tmpdir, 0755);
if (mkdir(tmpdir, 0755) != 0) {
/* not owned — must not rm a path we failed to create */
perror(tmpdir);
fail++;
continue;
}
snprintf(src, sizeof src, "%s/wwstp_%d_%d.ww",
tmpdir, getpid(), i);
snprintf(outbin, sizeof outbin, "%s/wwstp_%d_%d",
tmpdir, getpid(), i);
snprintf(cs_s, sizeof cs_s, "%s/wwstp_%d_%d_cs.s",
tmpdir, getpid(), i);
snprintf(ws_s, sizeof ws_s, "%s/wwstp_%d_%d_ww.s",
@@ -232,43 +240,25 @@ main(void)
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
FILE *f = fopen(src, "wb");
if (f == NULL) { runwait(rmcmd); fail++; continue; }
if (f == NULL) { fail++; goto rowdone; }
fputs(rows[i].src, f);
fclose(f);
char cmd[4096];
/* (a) cstage build + run. */
snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s",
bin, outbin, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "row[%s]: cstage build failed\n",
rows[i].label);
fail++;
runwait(rmcmd);
continue;
}
int got = runwait(outbin);
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++;
}
/* (b) cs==ww byte-id gate: emit .s from both stages, cmp. */
/* cs==ww byte-id gate: emit .s from both stages, cmp. */
snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null",
w6c, cs_s, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label);
fail++; runwait(rmcmd); continue;
fail++; goto rowdone;
}
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++; runwait(rmcmd); continue;
fail++; goto rowdone;
}
if (slurp_eq(cs_s, ws_s) != 0) {
fprintf(stderr,
@@ -277,8 +267,7 @@ main(void)
fail++;
}
/* (c) asm-pattern discriminator on the callee receive. byte-id
* (b) proves ww_s mirrors cs_s, so checking cs_s suffices. */
/* byte-id proves ww_s mirrors cs_s, so checking cs_s suffices. */
int sse = callee_receives_sse(cs_s);
if (sse < 0) {
fprintf(stderr, "row[%s]: cannot scan callee .s\n",
@@ -292,14 +281,20 @@ main(void)
rows[i].want_sse ? "present" : "absent");
fail++;
}
runwait(rmcmd);
rowdone:
/* a failed rm must fail the carrier, not leak silently. */
if (runwait(rmcmd) != 0) {
fprintf(stderr, "row[%s]: cleanup rm failed\n",
rows[i].label);
fail++;
}
}
if (fail) {
fprintf(stderr, "%d/%d struct-param tests failed\n", fail, n);
return 1;
}
printf("structparam: %d/%d ok (cstage run + cs==ww byte-id + "
printf("structparam: %d/%d ok (cs==ww byte-id + "
"SSE-receive asm)\n", n, n);
return 0;
}