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:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 946_structret_run — runtime + byte-id + asm-pattern net for #171a, the
|
||||
* 946_structret_run — byte-id + asm-pattern net for #171a, the
|
||||
* float-bearing struct-RETURN SysV ABI (the return twin of #165's struct
|
||||
* PARAM, and the struct counterpart of #164's per-element tuple RETURN).
|
||||
*
|
||||
@@ -14,7 +14,7 @@
|
||||
* value check are therefore NECESSARY-NOT-SUFFICIENT here (cf.
|
||||
* 946_structparam_run, the param twin). The genuine defect is SysV
|
||||
* register-CLASS conformance, observable only in the emitted asm (and at a
|
||||
* real ABI boundary). The discriminating dimension is the asm pattern (c).
|
||||
* real ABI boundary). The discriminating dimension is the asm pattern.
|
||||
*
|
||||
* THE FIX: per-EIGHTBYTE SysV classification (reusing struct_float_class /
|
||||
* structfloatclass verbatim from #165). Each 8-byte eightbyte that is a
|
||||
@@ -33,10 +33,10 @@
|
||||
* asserts BOTH the correct round-tripped value AND the ABSENCE of an SSE
|
||||
* return/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: the producer `main.mk` returns a lone-f64 eightbyte
|
||||
* The end-to-end values now live in r946_structret_* 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: the producer `main.mk` returns a lone-f64 eightbyte
|
||||
* as `MOVSD <off>(BP), Xn` (scratch -> XMM; a GP eightbyte is
|
||||
* `MOVQ <off>(BP), AX`), and the consumer `main` receives it as
|
||||
* `MOVSD Xn, -off(BP)` (XMM -> slot). The producer marker is scoped
|
||||
@@ -45,7 +45,7 @@
|
||||
* `TEXT main,` (a GP recv MOVQ's instead). PRESENT for the SSE-routed
|
||||
* rows, ABSENT for the GP / fallback rows. A pre-fix (or GP-regressed)
|
||||
* build routes every eightbyte via AX/DX/CX -> both markers absent,
|
||||
* which is exactly what (c) catches.
|
||||
* which is exactly what the pattern check catches.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -66,7 +66,6 @@ runwait(const char *cmd)
|
||||
struct row {
|
||||
const char *label;
|
||||
const char *src;
|
||||
int want_exit;
|
||||
int want_sse; /* 1 = struct return rides an XMM eightbyte */
|
||||
};
|
||||
|
||||
@@ -82,7 +81,7 @@ static const struct row rows[] = {
|
||||
"\tlet s: pff = mk();\n"
|
||||
"\tif ((s.a: i64) + (s.b: i64) != 8) { return 1; };\n"
|
||||
"\treturn 0;\n"
|
||||
"};\n", 0, 1 },
|
||||
"};\n", 1 },
|
||||
/* CURSOR INDEPENDENCE — struct{f64,i32}: eb0 lone f64 (X0), eb1
|
||||
* pure-INT (the i32 rides AX, NOT DX — the GP cursor starts at 0
|
||||
* regardless of the float ahead of it). (s.a:i64)+(s.b:i64) = 8. */
|
||||
@@ -94,7 +93,7 @@ static const struct row rows[] = {
|
||||
"\tlet s: pfi = mk();\n"
|
||||
"\tif ((s.a: i64) + (s.b: i64) != 8) { return 1; };\n"
|
||||
"\treturn 0;\n"
|
||||
"};\n", 0, 1 },
|
||||
"};\n", 1 },
|
||||
/* ORDER SWAP — struct{i64,f64}: eb0 pure-INT (AX), 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) = 8. */
|
||||
@@ -106,7 +105,7 @@ static const struct row rows[] = {
|
||||
"\tlet s: pif = mk();\n"
|
||||
"\tif (s.a + (s.b: i64) != 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 AX/DX/CX transport unchanged (the
|
||||
* in-tree byte-id case). No SSE return/receive marker. */
|
||||
@@ -118,7 +117,7 @@ static const struct row rows[] = {
|
||||
"\tlet s: pii = mk();\n"
|
||||
"\tif (s.a + s.b != 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
|
||||
* (returned/received via AX). The value still round-trips (the 8B MOVQ
|
||||
@@ -134,8 +133,8 @@ static const struct row rows[] = {
|
||||
"\tlet s: pf32 = mk();\n"
|
||||
"\tif ((s.a: i64) + (s.b: i64) != 8) { return 1; };\n"
|
||||
"\treturn 0;\n"
|
||||
"};\n", 0, 0 },
|
||||
{ NULL, NULL, 0, 0 }
|
||||
"};\n", 0 },
|
||||
{ NULL, NULL, 0 }
|
||||
};
|
||||
|
||||
static int
|
||||
@@ -186,6 +185,12 @@ ret_rides_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';
|
||||
|
||||
@@ -224,19 +229,22 @@ main(void)
|
||||
|
||||
int n = 0, fail = 0;
|
||||
for (int i = 0; rows[i].src; i++, n++) {
|
||||
/* src + outbin + cs.s + ww.s all live under one tmpdir so the
|
||||
/* The source and both .s files live under one tmpdir so the
|
||||
* compiler's .sepwork scratch (derived from the src path) lands
|
||||
* inside it; a single rm -rf at the end clears every phase. */
|
||||
char tmpdir[64];
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/wwsrt_%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;
|
||||
}
|
||||
|
||||
char src[128], outbin[128], cs_s[128], ws_s[128], rmcmd[160];
|
||||
char src[128], cs_s[128], ws_s[128], rmcmd[160];
|
||||
snprintf(src, sizeof src, "%s/wwsrt_%d_%d.ww",
|
||||
tmpdir, getpid(), i);
|
||||
snprintf(outbin, sizeof outbin, "%s/wwsrt_%d_%d",
|
||||
tmpdir, getpid(), i);
|
||||
snprintf(cs_s, sizeof cs_s, "%s/wwsrt_%d_%d_cs.s",
|
||||
tmpdir, getpid(), i);
|
||||
snprintf(ws_s, sizeof ws_s, "%s/wwsrt_%d_%d_ww.s",
|
||||
@@ -244,43 +252,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,
|
||||
@@ -289,8 +279,7 @@ main(void)
|
||||
fail++;
|
||||
}
|
||||
|
||||
/* (c) asm-pattern discriminator on the return/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 = ret_rides_sse(cs_s);
|
||||
if (sse < 0) {
|
||||
fprintf(stderr, "row[%s]: cannot scan .s (or SEND/RECV "
|
||||
@@ -304,14 +293,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-return tests failed\n", fail, n);
|
||||
return 1;
|
||||
}
|
||||
printf("structret: %d/%d ok (cstage run + cs==ww byte-id + "
|
||||
printf("structret: %d/%d ok (cs==ww byte-id + "
|
||||
"SSE-return asm)\n", n, n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user