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:
@@ -59,6 +59,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -143,8 +144,12 @@ run_ast_proof(const char *wwdump, const char *wwdump_ww,
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (!f) { fprintf(stderr, "848-ast[%s]: write\n", ac->label);
|
||||
rc = -1; goto done; }
|
||||
fputs(ac->src, f);
|
||||
fclose(f);
|
||||
int writebad = fputs(ac->src, f) == EOF || ferror(f);
|
||||
if (fclose(f) != 0) writebad = 1;
|
||||
if (writebad) {
|
||||
fprintf(stderr, "848-ast[%s]: write\n", ac->label);
|
||||
rc = -1; goto done;
|
||||
}
|
||||
|
||||
snprintf(cs, sizeof cs, "%s/cs.ast", dir);
|
||||
snprintf(ww, sizeof ww, "%s/ww.ast", dir);
|
||||
@@ -176,8 +181,21 @@ run_ast_proof(const char *wwdump, const char *wwdump_ww,
|
||||
rc = -1;
|
||||
}
|
||||
done:
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s", dir);
|
||||
(void)runwait(cmd);
|
||||
{
|
||||
int cleanfail = 0;
|
||||
snprintf(src, sizeof src, "%s/a.ww", dir);
|
||||
if (unlink(src) != 0 && errno != ENOENT) cleanfail = 1;
|
||||
snprintf(cs, sizeof cs, "%s/cs.ast", dir);
|
||||
if (unlink(cs) != 0 && errno != ENOENT) cleanfail = 1;
|
||||
snprintf(ww, sizeof ww, "%s/ww.ast", dir);
|
||||
if (unlink(ww) != 0 && errno != ENOENT) cleanfail = 1;
|
||||
if (rmdir(dir) != 0) cleanfail = 1;
|
||||
if (cleanfail) {
|
||||
fprintf(stderr, "848-ast[%s]: workspace cleanup failed\n",
|
||||
ac->label);
|
||||
if (rc == 0) rc = -1;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -308,47 +326,39 @@ run_scenario(const char *bin, const char *cdrv, const char *wdrv,
|
||||
FILE *f = fopen(path, "wb");
|
||||
if (!f) { fprintf(stderr, "848[%s]: write %s\n", sc->label,
|
||||
sc->files[i].name); rc = -1; goto done; }
|
||||
fputs(sc->files[i].src, f);
|
||||
fclose(f);
|
||||
int writebad = fputs(sc->files[i].src, f) == EOF || ferror(f);
|
||||
if (fclose(f) != 0) writebad = 1;
|
||||
if (writebad) {
|
||||
fprintf(stderr, "848[%s]: write %s\n", sc->label,
|
||||
sc->files[i].name);
|
||||
rc = -1; goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* #94 sep layout: cstage --sep build + run pins parse + runtime field
|
||||
* values; pin WW_PKGCACHE under the scratch dir. */
|
||||
/* Runtime values moved to wwfixtures. These builds intentionally keep
|
||||
* their caller-owned compiler artifacts for the byte assertion below. */
|
||||
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, "848[%s]: cstage build failed "
|
||||
"(qualified struct literal parse reject?)\n", sc->label);
|
||||
rc = -1; goto done;
|
||||
}
|
||||
snprintf(path, sizeof path, "%s/main", dir);
|
||||
int got = runwait(path);
|
||||
if (got != sc->want_exit) {
|
||||
fprintf(stderr, "848[%s]: cstage exit %d, want %d\n",
|
||||
sc->label, got, sc->want_exit);
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
/* rule-10 discriminator: the wwstage driver's --sep build emits
|
||||
* per-package w6c_ww asm that must be byte-identical to cstage's. The
|
||||
* root + each imported pkg compile to separate <stem>.sepwork/<pkg>.s;
|
||||
* concat (sorted glob, identical set both stages) for the compare. */
|
||||
/* rule-10 discriminator: this colocated two-file fixture composes into
|
||||
* the exact retained __root.s artifact, which must be byte-identical
|
||||
* across driver stages. */
|
||||
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, "848[%s]: ww_ww build failed "
|
||||
"(qualified struct literal parse reject?)\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(cs_s, sizeof cs_s, "%s/main.sepwork/__root.s", dir);
|
||||
snprintf(ws_s, sizeof ws_s, "%s/mainww.sepwork/__root.s", dir);
|
||||
if (slurp_eq(cs_s, ws_s) != 0) {
|
||||
fprintf(stderr, "848[%s]: cs.s/ww.s DIFFER (rule-10 byte-id "
|
||||
"violation)\n", sc->label);
|
||||
@@ -356,8 +366,31 @@ run_scenario(const char *bin, const char *cdrv, const char *wdrv,
|
||||
}
|
||||
|
||||
done:
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s", dir);
|
||||
(void)runwait(cmd);
|
||||
{
|
||||
int cleanfail = 0;
|
||||
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) cleanfail = 1;
|
||||
}
|
||||
const char *files[] = { "main", "mainww", NULL };
|
||||
for (int i = 0; files[i]; i++) {
|
||||
snprintf(path, sizeof path, "%s/%s", dir, files[i]);
|
||||
if (unlink(path) != 0 && errno != ENOENT) cleanfail = 1;
|
||||
}
|
||||
snprintf(path, sizeof path, "%s/main.sepwork", dir);
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s", path);
|
||||
if (runwait(cmd) != 0) cleanfail = 1;
|
||||
snprintf(path, sizeof path, "%s/mainww.sepwork", dir);
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s", path);
|
||||
if (runwait(cmd) != 0) cleanfail = 1;
|
||||
if (rmdir(dir) != 0) cleanfail = 1;
|
||||
if (cleanfail) {
|
||||
fprintf(stderr, "848[%s]: workspace cleanup failed\n",
|
||||
sc->label);
|
||||
if (rc == 0) rc = -1;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user