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:
@@ -54,6 +54,7 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -80,7 +81,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;
|
||||
}
|
||||
|
||||
@@ -260,15 +263,17 @@ run_scenario(const char *bin, const char *cdrv, const char *wdrv,
|
||||
FILE *f = fopen(path, "wb");
|
||||
if (!f) { fprintf(stderr, "784[%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, "784[%s]: write %s\n", sc->label,
|
||||
sc->files[i].name); rc = -1; goto done; }
|
||||
}
|
||||
|
||||
/* #94 sep layout: cstage --sep build + run pins runtime; pin
|
||||
* WW_PKGCACHE under the scratch dir so out/.pkgcache is untouched. */
|
||||
/* #94 sep layout: cstage build + run pins runtime; 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, "784[%s]: cstage build failed\n", sc->label);
|
||||
rc = -1; goto done;
|
||||
@@ -281,24 +286,36 @@ run_scenario(const char *bin, const char *cdrv, const char *wdrv,
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
/* Byte-id net (the #223 discriminator): the wwstage driver's --sep
|
||||
/* Byte-id net (the #223 discriminator): the wwstage driver's
|
||||
* build emits per-package w6c_ww asm; pre-fix the dispatcher diverges.
|
||||
* The root + each imported pkg compile to separate <stem>.sepwork/<pkg>.s;
|
||||
* concat (sorted glob, identical set both stages) for the compare. */
|
||||
char cs_s[1024], ws_s[1024];
|
||||
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, "784[%s]: ww_ww build failed\n", sc->label);
|
||||
rc = -1; goto done;
|
||||
}
|
||||
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, "784[%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, "784[%s]: wwstage asm aggregation failed\n",
|
||||
sc->label);
|
||||
rc = -1; goto done;
|
||||
}
|
||||
if (slurp_eq(cs_s, ws_s) != 0) {
|
||||
fprintf(stderr, "784[%s]: cs.s/ww.s DIFFER (rule-10 byte-id "
|
||||
"violation — #223 regression)\n", sc->label);
|
||||
@@ -306,9 +323,33 @@ run_scenario(const char *bin, const char *cdrv, const char *wdrv,
|
||||
}
|
||||
|
||||
done:
|
||||
/* Best-effort cleanup of the private dir. */
|
||||
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, "784[%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, "784[%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, "784[%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, "784[%s]: cleanup %s\n", sc->label,
|
||||
children[i]);
|
||||
rc = -1;
|
||||
}
|
||||
}
|
||||
if (rmdir(dir) != 0) {
|
||||
fprintf(stderr, "784[%s]: cleanup directory\n", sc->label);
|
||||
rc = -1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user