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 @@
|
||||
/*
|
||||
* 951_defdim_struct_run — runtime + byte-id net for #141: a struct
|
||||
* 951_defdim_struct_run — byte-id net for #141: a struct
|
||||
* field whose array dimension is a `def` (`[MAX]u8`, MAX a same-module
|
||||
* def), not an integer literal. BOTH stages were wrong, oppositely:
|
||||
*
|
||||
@@ -21,8 +21,8 @@
|
||||
* ww read a corrupted `end`; post-fix it round-trips and cs==ww byte-id.
|
||||
* Closes #13's def-dim half (the slice-repeat clause stays open).
|
||||
*
|
||||
* cstage `ww build` + run for exit code; w6c vs w6c_ww `.s` cmp for the
|
||||
* rule-10 byte-id gate. The byte-id leg compiles the `ww build`-produced
|
||||
* Runtime values live in r951_defdim_* fixtures. This carrier compares the
|
||||
* `ww build`-produced
|
||||
* .combined.ww, not the raw src: w6c does no import resolution, so the
|
||||
* cross-module row (C1, `import os`) only folds once concatenated, and a
|
||||
* same-module row combines to itself. The last row is the ACTUAL
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -46,7 +47,7 @@ runwait(const char *cmd)
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct row { const char *label; const char *src; int want_exit; };
|
||||
struct row { const char *label; const char *src; };
|
||||
|
||||
static const struct row rows[] = {
|
||||
/* TEETH: def-dim array FOLLOWED by a scalar; write both, read the
|
||||
@@ -61,7 +62,7 @@ static const struct row rows[] = {
|
||||
" s.b[3] = 9u8;\n"
|
||||
" s.end = 42;\n"
|
||||
" return s.end;\n"
|
||||
"};\n", 42 },
|
||||
"};\n" },
|
||||
/* the array element itself must survive too — read the last byte
|
||||
* (pre-fix the overlapping `end` write would clobber it). */
|
||||
{ "m4_belem",
|
||||
@@ -73,7 +74,7 @@ static const struct row rows[] = {
|
||||
" s.b[3] = 200u8;\n"
|
||||
" s.end = 7;\n"
|
||||
" return s.b[3]: i32;\n"
|
||||
"};\n", 200 },
|
||||
"};\n" },
|
||||
/* the ~4KB path::buffer shape — def MAX=4095, read the trailing
|
||||
* scalar after a 4095-byte array. */
|
||||
{ "m4095_end",
|
||||
@@ -85,7 +86,7 @@ static const struct row rows[] = {
|
||||
" s.b[4094] = 5u8;\n"
|
||||
" s.end = 99;\n"
|
||||
" return s.end;\n"
|
||||
"};\n", 99 },
|
||||
"};\n" },
|
||||
/* two scalars after the def-dim array — pins the cumulative offset
|
||||
* (a+c read their written values: 11+22=33). */
|
||||
{ "twoafter",
|
||||
@@ -97,7 +98,7 @@ static const struct row rows[] = {
|
||||
" s.a = 11;\n"
|
||||
" s.c = 22;\n"
|
||||
" return s.a + s.c;\n"
|
||||
"};\n", 33 },
|
||||
"};\n" },
|
||||
/* C1 (rob-mandatory): the ACTUAL path::buffer shape — a CROSS-
|
||||
* MODULE def dimension. `def MAX = os.PATH_MAX - 1` folds an N_DOT
|
||||
* (os.PATH_MAX) const-ref through eval_def_const's cross-module arm,
|
||||
@@ -115,8 +116,8 @@ static const struct row rows[] = {
|
||||
" s.b[4094] = 7u8;\n"
|
||||
" s.end = 77;\n"
|
||||
" return s.end;\n"
|
||||
"};\n", 77 },
|
||||
{ NULL, NULL, 0 }
|
||||
"};\n" },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static int
|
||||
@@ -162,14 +163,21 @@ main(void)
|
||||
char src[64];
|
||||
snprintf(src, sizeof src, "/tmp/wwdds_%d_%d.ww", getpid(), i);
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (f == NULL) { fail++; continue; }
|
||||
if (f == NULL) { perror(src); fail++; continue; }
|
||||
fputs(rows[i].src, f);
|
||||
fclose(f);
|
||||
|
||||
char tmpdir[64];
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/wwdds_%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++;
|
||||
if (unlink(src) != 0 && errno != ENOENT)
|
||||
perror(src);
|
||||
continue;
|
||||
}
|
||||
|
||||
char base[64];
|
||||
const char *b = strrchr(src, '/');
|
||||
@@ -178,36 +186,16 @@ main(void)
|
||||
char *dot = strrchr(base, '.');
|
||||
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
|
||||
|
||||
/* #94 sep layout: each driver's --sep build emits the runnable
|
||||
/* #94 sep layout: each driver's build emits the runnable
|
||||
* binary at <stem> + per-package asm under <stem>.sepwork/.
|
||||
* Distinct stems so the wwstage sepwork doesn't clobber cstage's;
|
||||
* pin WW_PKGCACHE under tmpdir so out/.pkgcache is untouched. A
|
||||
* pin all outputs stay under tmpdir. A
|
||||
* cross-module row's `import os` resolves per-package, a same-
|
||||
* module row is just __root — both compare via the sorted glob. */
|
||||
char cmd[2048], stem_c[160], stem_w[160];
|
||||
snprintf(stem_c, sizeof stem_c, "%s/%s_c", tmpdir, base);
|
||||
snprintf(stem_w, sizeof stem_w, "%s/%s_w", tmpdir, base);
|
||||
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"cd %s && WW_PKGCACHE=%s/pkgc_c %s/ww build --sep -o %s %s",
|
||||
tmpdir, tmpdir, bin, stem_c, src);
|
||||
if (runwait(cmd) != 0) {
|
||||
fprintf(stderr, "row[%s]: cstage build failed\n",
|
||||
rows[i].label);
|
||||
fail++;
|
||||
unlink(src);
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s", tmpdir);
|
||||
if (system(cmd)) {}
|
||||
continue;
|
||||
}
|
||||
|
||||
int got = runwait(stem_c);
|
||||
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++;
|
||||
}
|
||||
|
||||
char cs_s[64], ws_s[64];
|
||||
snprintf(cs_s, sizeof cs_s, "/tmp/wwdds_%d_%d_cs.s",
|
||||
getpid(), i);
|
||||
@@ -215,20 +203,38 @@ main(void)
|
||||
getpid(), i);
|
||||
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"cd %s && WW_PKGCACHE=%s/pkgc_w %s/ww_ww build --sep -o %s %s "
|
||||
">/dev/null 2>&1", tmpdir, tmpdir, bin, stem_w, src);
|
||||
"cd %s && %s/ww build -S -o %s %s",
|
||||
tmpdir, bin, stem_c, src);
|
||||
if (runwait(cmd) != 0) {
|
||||
fprintf(stderr, "row[%s]: cstage build failed\n",
|
||||
rows[i].label);
|
||||
fail++;
|
||||
goto rowdone;
|
||||
}
|
||||
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"cd %s && %s/ww_ww build -S -o %s %s "
|
||||
">/dev/null 2>&1", tmpdir, bin, stem_w, src);
|
||||
if (runwait(cmd) != 0) {
|
||||
fprintf(stderr, "row[%s]: ww_ww build failed\n",
|
||||
rows[i].label);
|
||||
fail++;
|
||||
} else {
|
||||
/* a failed cat (e.g. an empty sepwork glob) must fail
|
||||
* the row — two absent trees would compare equal-empty. */
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"cat %s.sepwork/*.s > %s 2>/dev/null", stem_c, cs_s);
|
||||
if (system(cmd)) {}
|
||||
int catc = runwait(cmd);
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"cat %s.sepwork/*.s > %s 2>/dev/null", stem_w, ws_s);
|
||||
if (system(cmd)) {}
|
||||
if (slurp_eq(cs_s, ws_s) != 0) {
|
||||
int catw = runwait(cmd);
|
||||
if (catc != 0 || catw != 0) {
|
||||
fprintf(stderr,
|
||||
"row[%s]: sepwork .s concat failed "
|
||||
"(cstage=%d wwstage=%d)\n",
|
||||
rows[i].label, catc, catw);
|
||||
fail++;
|
||||
} else if (slurp_eq(cs_s, ws_s) != 0) {
|
||||
fprintf(stderr,
|
||||
"row[%s]: cstage/wwstage .s DIFFER "
|
||||
"(rule-10 byte-id violation)\n",
|
||||
@@ -237,9 +243,29 @@ main(void)
|
||||
}
|
||||
}
|
||||
|
||||
rowdone:
|
||||
/* a failed cleanup must fail the carrier, not leak silently;
|
||||
* ENOENT is fine — an early leg may exit before creating the
|
||||
* concat files. */
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s", tmpdir);
|
||||
if (system(cmd)) {}
|
||||
unlink(src); unlink(cs_s); unlink(ws_s);
|
||||
int cleanfail = runwait(cmd) != 0;
|
||||
if (unlink(src) != 0 && errno != ENOENT) {
|
||||
perror(src);
|
||||
cleanfail = 1;
|
||||
}
|
||||
if (unlink(cs_s) != 0 && errno != ENOENT) {
|
||||
perror(cs_s);
|
||||
cleanfail = 1;
|
||||
}
|
||||
if (unlink(ws_s) != 0 && errno != ENOENT) {
|
||||
perror(ws_s);
|
||||
cleanfail = 1;
|
||||
}
|
||||
if (cleanfail) {
|
||||
fprintf(stderr, "row[%s]: cleanup failed\n",
|
||||
rows[i].label);
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
|
||||
if (fail) {
|
||||
@@ -247,7 +273,7 @@ main(void)
|
||||
fail, n);
|
||||
return 1;
|
||||
}
|
||||
printf("defdim_struct: %d/%d ok (cstage run + cs==ww byte-id)\n",
|
||||
printf("defdim_struct: %d/%d ok (cs==ww byte-id)\n",
|
||||
n, n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user