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

@@ -56,6 +56,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/wait.h>
@@ -82,7 +83,9 @@ slurp_eq(const char *a, const char *b)
if (ca != cb) { rc = -1; break; }
if (ca == EOF) break;
}
fclose(fa); fclose(fb);
if (ferror(fa) || ferror(fb)) rc = -1;
if (fclose(fa) != 0) rc = -1;
if (fclose(fb) != 0) rc = -1;
return rc;
}
@@ -241,28 +244,30 @@ run_scenario(const char *bin, const char *cdrv, const char *wdrv,
FILE *f = fopen(path, "wb");
if (!f) { fprintf(stderr, "787[%s]: write %s\n", sc->label,
sc->files[i].name); rc = -1; goto done; }
fputs(sc->files[i].src, f);
fclose(f);
int bad = fputs(sc->files[i].src, f) == EOF;
if (fclose(f) != 0) bad = 1;
if (bad) { fprintf(stderr, "787[%s]: write %s\n", sc->label,
sc->files[i].name); rc = -1; goto done; }
}
if (sc->expect_reject) {
/* #94 sep layout: there is no combined unit to re-check. The
* checker reject now fires inside each driver's --sep w6c pass,
* checker reject now fires inside each driver's w6c pass,
* so BOTH driver builds MUST fail. w6c_ww (via ww_ww) accepting
* here is the #13 false-ACCEPT regression. */
snprintf(cmd, sizeof cmd,
"cd %s && WW_PKGCACHE=%s/pkgc_c %s build --sep -I %s "
"cd %s && %s build -I %s "
"-o %s/main %s/main.ww >/dev/null 2>&1",
dir, dir, cdrv, dir, dir, dir);
dir, cdrv, dir, dir, dir);
if (runwait(cmd) == 0) {
fprintf(stderr, "787[%s]: cstage build SUCCEEDED, "
"expected reject\n", sc->label);
rc = -1; goto done;
}
snprintf(cmd, sizeof cmd,
"cd %s && WW_PKGCACHE=%s/pkgc_w %s build --sep -I %s "
"cd %s && %s build -I %s "
"-o %s/mainww %s/main.ww >/dev/null 2>&1",
dir, dir, wdrv, dir, dir, dir);
dir, wdrv, dir, dir, dir);
if (runwait(cmd) == 0) {
fprintf(stderr, "787[%s]: ww_ww ACCEPTED foreign variant "
"(#13 false-accept), expected reject\n", sc->label);
@@ -271,11 +276,11 @@ run_scenario(const char *bin, const char *cdrv, const char *wdrv,
goto done;
}
/* cstage driver --sep build + run: pins runtime routing. Pin
* WW_PKGCACHE under the scratch dir so out/.pkgcache is untouched. */
/* cstage driver build + run: pins runtime routing. Pin
* all outputs stay under the scratch dir. */
snprintf(cmd, sizeof cmd,
"cd %s && WW_PKGCACHE=%s/pkgc_c %s build --sep -I %s -o %s/main %s/main.ww",
dir, dir, cdrv, dir, dir, dir);
"cd %s && %s build -I %s -o %s/main %s/main.ww",
dir, cdrv, dir, dir, dir);
if (runwait(cmd) != 0) {
fprintf(stderr, "787[%s]: cstage build failed\n", sc->label);
rc = -1; goto done;
@@ -288,15 +293,15 @@ run_scenario(const char *bin, const char *cdrv, const char *wdrv,
rc = -1;
}
/* The #13 discriminator: the wwstage driver's --sep build runs the
/* The #13 discriminator: the wwstage driver's build runs the
* wwstage checker over the same units. Pre-fix it REJECTED the
* cross-module variant arms (build fails); post-fix it accepts AND
* its per-package w6c_ww asm is byte-id with cstage's. The root +
* each imported pkg compile to separate <stem>.sepwork/<pkg>.s;
* concat (sorted glob, identical set both stages) for the compare. */
snprintf(cmd, sizeof cmd,
"cd %s && WW_PKGCACHE=%s/pkgc_w %s build --sep -I %s -o %s/mainww %s/main.ww",
dir, dir, wdrv, dir, dir, dir);
"cd %s && %s build -I %s -o %s/mainww %s/main.ww",
dir, wdrv, dir, dir, dir);
if (runwait(cmd) != 0) {
fprintf(stderr, "787[%s]: ww_ww build failed "
"(#13 cross-module variant reject?)\n", sc->label);
@@ -305,10 +310,22 @@ run_scenario(const char *bin, const char *cdrv, const char *wdrv,
char cs_s[1024], ws_s[1024];
snprintf(cs_s, sizeof cs_s, "%s/all_cs.s", dir);
snprintf(ws_s, sizeof ws_s, "%s/all_ww.s", dir);
snprintf(cmd, sizeof cmd, "cat %s/main.sepwork/*.s > %s 2>/dev/null",
dir, cs_s); if (system(cmd)) {}
snprintf(cmd, sizeof cmd, "cat %s/mainww.sepwork/*.s > %s 2>/dev/null",
dir, ws_s); if (system(cmd)) {}
snprintf(cmd, sizeof cmd,
"cat %s/main.sepwork/*.s > %s 2>/dev/null && test -s %s",
dir, cs_s, cs_s);
if (runwait(cmd) != 0) {
fprintf(stderr, "787[%s]: cstage asm aggregation failed\n",
sc->label);
rc = -1; goto done;
}
snprintf(cmd, sizeof cmd,
"cat %s/mainww.sepwork/*.s > %s 2>/dev/null && test -s %s",
dir, ws_s, ws_s);
if (runwait(cmd) != 0) {
fprintf(stderr, "787[%s]: wwstage asm aggregation failed\n",
sc->label);
rc = -1; goto done;
}
if (slurp_eq(cs_s, ws_s) != 0) {
fprintf(stderr, "787[%s]: cs.s/ww.s DIFFER (rule-10 byte-id "
"violation)\n", sc->label);
@@ -316,8 +333,33 @@ run_scenario(const char *bin, const char *cdrv, const char *wdrv,
}
done:
snprintf(cmd, sizeof cmd, "rm -rf %s", dir);
(void)runwait(cmd);
snprintf(cmd, sizeof cmd, "rm -rf %s/main.sepwork", dir);
if (runwait(cmd) != 0) { fprintf(stderr, "787[%s]: cleanup main.sepwork\n",
sc->label); rc = -1; }
snprintf(cmd, sizeof cmd, "rm -rf %s/mainww.sepwork", dir);
if (runwait(cmd) != 0) { fprintf(stderr, "787[%s]: cleanup mainww.sepwork\n",
sc->label); rc = -1; }
for (int i = 0; sc->files[i].name; i++) {
snprintf(path, sizeof path, "%s/%s", dir, sc->files[i].name);
if (unlink(path) != 0 && errno != ENOENT) {
fprintf(stderr, "787[%s]: cleanup %s\n", sc->label,
sc->files[i].name);
rc = -1;
}
}
const char *children[] = { "main", "mainww", "all_cs.s", "all_ww.s", NULL };
for (int i = 0; children[i]; i++) {
snprintf(path, sizeof path, "%s/%s", dir, children[i]);
if (unlink(path) != 0 && errno != ENOENT) {
fprintf(stderr, "787[%s]: cleanup %s\n", sc->label,
children[i]);
rc = -1;
}
}
if (rmdir(dir) != 0) {
fprintf(stderr, "787[%s]: cleanup directory\n", sc->label);
rc = -1;
}
return rc;
}