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 @@
|
||||
/*
|
||||
* 957_assert_builtin_run — runtime + byte-id + reject net for #58: the
|
||||
* 957_assert_builtin_run — stderr + byte-id net for #58: the
|
||||
* `assert(cond[, msg])` / `abort([msg])` builtins (the harec
|
||||
* EXPR_ASSERT family) in BOTH stages.
|
||||
*
|
||||
@@ -12,12 +12,9 @@
|
||||
* cmd/w6c/cgen.c:6618-6663). The fix mirrors that tag-then-lower pair
|
||||
* into check.ww exprtype N_CALL + cgenexpr.ww cgcall.
|
||||
*
|
||||
* THIS TEST MUST CATCH A WWSTAGE-ONLY DIVERGENCE, so every positive
|
||||
* row carries both dimensions (modelled on 953/954):
|
||||
* (a) cstage `ww build` + run, asserting the exit code AND the
|
||||
* runtime stderr (rt_abort writes msg verbatim; a NULL want_msg
|
||||
* pins the (NULL, 0) no-msg shape as EMPTY stderr).
|
||||
* (b) w6c vs w6c_ww `.s` cmp — FAILS if the stages diverge. On
|
||||
* Shared runtime and reject contracts live in r957_* fixtures. This carrier
|
||||
* retains runtime stderr for aborting rows and w6c vs w6c_ww `.s` identity.
|
||||
* The latter fails if the stages diverge. On
|
||||
* pre-fix master every assert/abort row diverges (wwstage emits
|
||||
* the bogus CALL).
|
||||
*
|
||||
@@ -26,18 +23,15 @@
|
||||
* and routes the regular call path in BOTH stages. The cross-module
|
||||
* row pins the CURRENT flat-scope semantics — if the #45 root (filed
|
||||
* as task #14: cross-module bare resolution of a foreign decl) is
|
||||
* later ruled a reject, that row flips to expect_fail with it.
|
||||
* later ruled a reject, its fixture should change polarity with it.
|
||||
*
|
||||
* Reject rows pin the checker mirror ON CONTENT: non-bool cond /
|
||||
* non-str msg / arity overflows fail the build in BOTH stages with the
|
||||
* shared diagnostic substring (cstage prefixes pos, wwstage's cerr is
|
||||
* bare — strstr covers both). The alias-cond row pins the rule-10
|
||||
* down-alignment: cstage compares ty_bool by identity (check.c:1560),
|
||||
* so wwstage must not alias-peel either (widening = task #5 alias arc).
|
||||
* The migrated reject fixtures retain the checker diagnostics and the
|
||||
* alias-cond rule-10 down-alignment.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -68,8 +62,7 @@ struct row {
|
||||
const char *src;
|
||||
int want_exit;
|
||||
const char *want_msg; /* run stderr must contain this; NULL = must be empty */
|
||||
int expect_fail; /* 1 = BOTH stages must reject; want_exit/want_msg ignored */
|
||||
const char *diag; /* reject rows: both stages' stderr must contain this */
|
||||
int observe_output;
|
||||
};
|
||||
|
||||
static const struct row rows[] = {
|
||||
@@ -80,35 +73,35 @@ static const struct row rows[] = {
|
||||
"\tassert(1 + 1 == 2);\n"
|
||||
"\tassert(2 > 1, \"never fires\");\n"
|
||||
"\treturn 42;\n"
|
||||
"};\n", 42, NULL, 0, NULL },
|
||||
"};\n", 42, NULL, 0 },
|
||||
/* Failing assert without msg: rt_abort(NULL, 0), exit 1, silent. */
|
||||
{ "fail_nomsg",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
"\tassert(1 == 2);\n"
|
||||
"\treturn 0;\n"
|
||||
"};\n", 1, NULL, 0, NULL },
|
||||
"};\n", 1, NULL, 1 },
|
||||
/* Failing assert with msg: rt_abort(ptr, len) writes it to stderr. */
|
||||
{ "fail_msg",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
"\tassert(false, \"assert fired\\n\");\n"
|
||||
"\treturn 0;\n"
|
||||
"};\n", 1, "assert fired", 0, NULL },
|
||||
"};\n", 1, "assert fired", 1 },
|
||||
/* abort with msg: unconditional rt_abort, exit 1, msg on stderr. */
|
||||
{ "abort_msg",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
"\tabort(\"boom\\n\");\n"
|
||||
"\treturn 0;\n"
|
||||
"};\n", 1, "boom", 0, NULL },
|
||||
"};\n", 1, "boom", 1 },
|
||||
/* bare abort(): rt_abort(NULL, 0), exit 1, silent. */
|
||||
{ "abort_bare",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
"\tabort();\n"
|
||||
"\treturn 0;\n"
|
||||
"};\n", 1, NULL, 0, NULL },
|
||||
"};\n", 1, NULL, 1 },
|
||||
/* assert inside an IMPORTED module's fn (single-file multi-package
|
||||
* form, like 953) — the regex fold-5 consumer shape. */
|
||||
{ "imported_mod",
|
||||
@@ -119,7 +112,7 @@ static const struct row rows[] = {
|
||||
"};\n"
|
||||
"package main;\n"
|
||||
"import m;\n"
|
||||
"export fn main() i32 = { return m.f(); };\n", 42, NULL, 0, NULL },
|
||||
"export fn main() i32 = { return m.f(); };\n", 42, NULL, 0 },
|
||||
/* SHADOW control, same-module: a user fn `assert` suppresses the
|
||||
* builtin; the call routes the regular path (no-op fn), so the
|
||||
* false cond does NOT abort. Exit 7 proves the user fn ran. */
|
||||
@@ -130,7 +123,7 @@ static const struct row rows[] = {
|
||||
"export fn main() i32 = {\n"
|
||||
"\tassert(false);\n"
|
||||
"\treturn g;\n"
|
||||
"};\n", 7, NULL, 0, NULL },
|
||||
"};\n", 7, NULL, 0 },
|
||||
/* SHADOW control, cross-module (#45 shape, task #14): a foreign
|
||||
* exported fn `assert` in the flat scope also suppresses the
|
||||
* builtin; bare `assert(false, ...)` binds it and does NOT abort. */
|
||||
@@ -142,44 +135,8 @@ static const struct row rows[] = {
|
||||
"export fn main() i32 = {\n"
|
||||
"\tassert(false, \"routed to m.assert\");\n"
|
||||
"\treturn 42;\n"
|
||||
"};\n", 42, NULL, 0, NULL },
|
||||
/* Checker rejects, mirrored both stages — pinned on diagnostic
|
||||
* CONTENT, not just a non-zero exit. */
|
||||
{ "reject_nonbool",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
"\tassert(\"not a bool\");\n"
|
||||
"\treturn 0;\n"
|
||||
"};\n", 0, NULL, 1, "assert: cond must be bool" },
|
||||
/* Alias-of-bool cond: ty_bool identity in cstage (check.c:1560)
|
||||
* → reject; wwstage aligned down (no resolvealias peel). */
|
||||
{ "reject_alias_cond",
|
||||
"package main;\n"
|
||||
"type myb = bool;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
"\tlet b: myb = true;\n"
|
||||
"\tassert(b);\n"
|
||||
"\treturn 0;\n"
|
||||
"};\n", 0, NULL, 1, "assert: cond must be bool" },
|
||||
{ "reject_assert_arity",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
"\tassert(true, \"m\", \"extra\");\n"
|
||||
"\treturn 0;\n"
|
||||
"};\n", 0, NULL, 1, "assert: at most two args" },
|
||||
{ "reject_abort_nonstr",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
"\tabort(42);\n"
|
||||
"\treturn 0;\n"
|
||||
"};\n", 0, NULL, 1, "abort: message must be str" },
|
||||
{ "reject_abort_arity",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
"\tabort(\"a\", \"b\");\n"
|
||||
"\treturn 0;\n"
|
||||
"};\n", 0, NULL, 1, "abort: at most one arg" },
|
||||
{ NULL, NULL, 0, NULL, 0, NULL }
|
||||
"};\n", 42, NULL, 0 },
|
||||
{ NULL, NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
static int
|
||||
@@ -224,105 +181,80 @@ main(void)
|
||||
char errbuf[4096];
|
||||
int n = 0, fail = 0;
|
||||
for (int i = 0; rows[i].src; i++, n++) {
|
||||
char tmpdir[64], src[128], errf[128], rmcmd[160];
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/wwasrt_%d_d_%d",
|
||||
getpid(), i);
|
||||
mkdir(tmpdir, 0755);
|
||||
char tmpdir[64] = "/tmp/wwasrt_XXXXXX";
|
||||
if (mkdtemp(tmpdir) == NULL) {
|
||||
perror("assert_builtin: mkdtemp");
|
||||
fail++;
|
||||
continue;
|
||||
}
|
||||
char src[128], errf[128], outbin[128], sepwork[160];
|
||||
char cs_s[128], ws_s[128], rmcmd[192];
|
||||
snprintf(src, sizeof src, "%s/wwasrt_%d_%d.ww",
|
||||
tmpdir, getpid(), i);
|
||||
snprintf(errf, sizeof errf, "%s/wwasrt_%d_%d.err",
|
||||
tmpdir, getpid(), i);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (f == NULL) { runwait(rmcmd); fail++; continue; }
|
||||
fputs(rows[i].src, f);
|
||||
fclose(f);
|
||||
|
||||
if (rows[i].expect_fail) {
|
||||
char cmd[2048];
|
||||
const char *stage[2] = { w6c, w6c_ww };
|
||||
const char *sname[2] = { "cstage", "wwstage" };
|
||||
for (int s = 0; s < 2; s++) {
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"%s -o /dev/null %s 2>%s",
|
||||
stage[s], src, errf);
|
||||
if (runwait(cmd) == 0) {
|
||||
fprintf(stderr, "row[%s]: %s accepted, "
|
||||
"expected reject\n",
|
||||
rows[i].label, sname[s]);
|
||||
fail++;
|
||||
continue;
|
||||
}
|
||||
if (slurp(errf, errbuf, sizeof errbuf) < 0 ||
|
||||
strstr(errbuf, rows[i].diag) == NULL) {
|
||||
fprintf(stderr, "row[%s]: %s rejected "
|
||||
"without \"%s\" on stderr\n",
|
||||
rows[i].label, sname[s],
|
||||
rows[i].diag);
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
runwait(rmcmd);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* (a) cstage build + run in a scratch dir. */
|
||||
char outbin[128];
|
||||
snprintf(outbin, sizeof outbin, "%s/wwasrt_%d_%d",
|
||||
tmpdir, getpid(), i);
|
||||
|
||||
char cmd[2048];
|
||||
snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s "
|
||||
">/dev/null 2>&1", bin, outbin, src);
|
||||
if (runwait(cmd) != 0) {
|
||||
fprintf(stderr, "row[%s]: cstage build failed\n",
|
||||
rows[i].label);
|
||||
fail++;
|
||||
runwait(rmcmd);
|
||||
continue;
|
||||
}
|
||||
|
||||
snprintf(cmd, sizeof cmd, "%s >/dev/null 2>%s", outbin, errf);
|
||||
int got = runwait(cmd);
|
||||
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++;
|
||||
}
|
||||
long elen = slurp(errf, errbuf, sizeof errbuf);
|
||||
if (rows[i].want_msg) {
|
||||
if (elen < 0 || strstr(errbuf, rows[i].want_msg) == NULL) {
|
||||
fprintf(stderr, "row[%s]: run stderr missing "
|
||||
"\"%s\"\n", rows[i].label,
|
||||
rows[i].want_msg);
|
||||
fail++;
|
||||
}
|
||||
} else if (elen != 0) {
|
||||
fprintf(stderr, "row[%s]: run stderr not empty "
|
||||
"(rt_abort no-msg must be (NULL, 0))\n",
|
||||
rows[i].label);
|
||||
fail++;
|
||||
}
|
||||
|
||||
/* (b) cs==ww byte-id gate. */
|
||||
char cs_s[128], ws_s[128];
|
||||
snprintf(sepwork, sizeof sepwork, "%s.sepwork", outbin);
|
||||
snprintf(cs_s, sizeof cs_s, "%s/wwasrt_%d_%d_cs.s",
|
||||
tmpdir, getpid(), i);
|
||||
snprintf(ws_s, sizeof ws_s, "%s/wwasrt_%d_%d_ww.s",
|
||||
tmpdir, getpid(), i);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", sepwork);
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (f == NULL) { fail++; goto cleanup; }
|
||||
fputs(rows[i].src, f);
|
||||
fclose(f);
|
||||
|
||||
char cmd[2048];
|
||||
if (rows[i].observe_output) {
|
||||
snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s "
|
||||
">/dev/null 2>&1", bin, outbin, src);
|
||||
if (runwait(cmd) != 0) {
|
||||
fprintf(stderr, "row[%s]: cstage build failed\n",
|
||||
rows[i].label);
|
||||
fail++;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
snprintf(cmd, sizeof cmd, "%s >/dev/null 2>%s", outbin, errf);
|
||||
int got = runwait(cmd);
|
||||
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++;
|
||||
}
|
||||
long elen = slurp(errf, errbuf, sizeof errbuf);
|
||||
if (rows[i].want_msg) {
|
||||
if (elen < 0 || strstr(errbuf, rows[i].want_msg) == NULL) {
|
||||
fprintf(stderr, "row[%s]: run stderr missing "
|
||||
"\"%s\"\n", rows[i].label,
|
||||
rows[i].want_msg);
|
||||
fail++;
|
||||
}
|
||||
} else if (elen != 0) {
|
||||
fprintf(stderr, "row[%s]: run stderr not empty "
|
||||
"(rt_abort no-msg must be (NULL, 0))\n",
|
||||
rows[i].label);
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
|
||||
/* cs==ww byte-id gate. */
|
||||
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 cleanup;
|
||||
}
|
||||
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 cleanup;
|
||||
}
|
||||
if (slurp_eq(cs_s, ws_s) != 0) {
|
||||
fprintf(stderr,
|
||||
@@ -330,7 +262,22 @@ main(void)
|
||||
"byte-id violation)\n", rows[i].label);
|
||||
fail++;
|
||||
}
|
||||
runwait(rmcmd);
|
||||
|
||||
cleanup: {
|
||||
int cleanbad = 0;
|
||||
if (unlink(src) != 0 && errno != ENOENT) cleanbad = 1;
|
||||
if (unlink(errf) != 0 && errno != ENOENT) cleanbad = 1;
|
||||
if (unlink(outbin) != 0 && errno != ENOENT) cleanbad = 1;
|
||||
if (unlink(cs_s) != 0 && errno != ENOENT) cleanbad = 1;
|
||||
if (unlink(ws_s) != 0 && errno != ENOENT) cleanbad = 1;
|
||||
if (runwait(rmcmd) != 0) cleanbad = 1;
|
||||
if (rmdir(tmpdir) != 0) cleanbad = 1;
|
||||
if (cleanbad) {
|
||||
fprintf(stderr, "row[%s]: temporary cleanup failed\n",
|
||||
rows[i].label);
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fail) {
|
||||
@@ -338,7 +285,7 @@ main(void)
|
||||
fail, n);
|
||||
return 1;
|
||||
}
|
||||
printf("assert_builtin: %d/%d ok (cstage run+stderr + cs==ww byte-id + reject diags)\n",
|
||||
printf("assert_builtin: %d/%d ok (stderr + cs==ww byte-id)\n",
|
||||
n, n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user