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:
@@ -43,14 +43,15 @@
|
||||
* | — the #117 over-accept hazard) | |
|
||||
*
|
||||
* Cross-module via OWN 2-module fixtures in a PRIVATE mktemp dir (784
|
||||
* model) — NOT the real lib/ascii: the driver writes intermediates next
|
||||
* to traversed sources, so importing lib/ would race; a synthetic module
|
||||
* model) — NOT the real lib/ascii: ordinary build retains its caller-owned
|
||||
* <output>.sepwork tree, so importing lib/ would race; a synthetic module
|
||||
* `cc` exercises the IDENTICAL `&mod.fn` mangle (mafn(leaf, module)).
|
||||
* NNN<950 so test-unit runs it; the private mktemp dir makes the ww_ww
|
||||
* driver race-free (946 ww_ww-driver precedent).
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -164,19 +165,19 @@ static const struct scenario scenarios[] = {
|
||||
{ "nonfn_dotted_table", nonfn_dotted_files, K_BUILDERR, 0 },
|
||||
};
|
||||
|
||||
/* Build `driver build --sep -o <dir>/<stem>` in the fixture dir; returns
|
||||
/* Build `driver build -o <dir>/<stem>` in the fixture dir; returns
|
||||
* the driver's build rc and (for K_RUN) runs the produced binary, comparing
|
||||
* exit to want_exit. #94: the per-package asm lands in <dir>/<stem>.sepwork/
|
||||
* (cachetag keys a private WW_PKGCACHE so out/.pkgcache is untouched). */
|
||||
* exit to want_exit. #94: the caller-visible per-package asm is retained in
|
||||
* <dir>/<stem>.sepwork/ until this carrier finishes observing it. */
|
||||
static int
|
||||
build_run(const char *dir, const char *driver, const struct scenario *sc,
|
||||
const char *stem, const char *cachetag)
|
||||
const char *stem)
|
||||
{
|
||||
char cmd[4096], path[1024];
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"cd %s && WW_PKGCACHE=%s/pkgc_%s %s build --sep -I %s -o %s/%s "
|
||||
"cd %s && %s build -I %s -o %s/%s "
|
||||
"%s/main.ww >/dev/null 2>%s/err",
|
||||
dir, dir, cachetag, driver, dir, dir, stem, dir, dir);
|
||||
dir, driver, dir, dir, stem, dir, dir);
|
||||
int brc = runwait(cmd);
|
||||
if (sc->kind == K_BUILDERR) {
|
||||
if (brc == 0) {
|
||||
@@ -217,19 +218,25 @@ run_scenario(const char *bin, const struct scenario *sc)
|
||||
FILE *f = fopen(path, "wb");
|
||||
if (!f) { fprintf(stderr, "949[%s]: write %s\n", sc->label,
|
||||
sc->files[i].name); rc = -1; goto done; }
|
||||
fputs(sc->files[i].src, f);
|
||||
fclose(f);
|
||||
int writefail = fputs(sc->files[i].src, f) == EOF;
|
||||
if (fclose(f) != 0) writefail = 1;
|
||||
if (writefail) {
|
||||
fprintf(stderr, "949[%s]: write %s\n", sc->label,
|
||||
sc->files[i].name);
|
||||
rc = -1;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* cstage driver --sep build (+run for K_RUN) → <dir>/main_c.sepwork/. */
|
||||
/* cstage driver build (+run for K_RUN) → <dir>/main_c.sepwork/. */
|
||||
snprintf(csdrv, sizeof csdrv, "%s/ww", bin);
|
||||
if (build_run(dir, csdrv, sc, "main_c", "c") != 0) { rc = -1; goto done; }
|
||||
if (build_run(dir, csdrv, sc, "main_c") != 0) { rc = -1; goto done; }
|
||||
|
||||
/* wwstage driver --sep build (+run for K_RUN) — race-free in the
|
||||
/* wwstage driver build (+run for K_RUN) — race-free in the
|
||||
* private mktemp dir. Direct proof the wwstage emits a runnable
|
||||
* binary. Distinct stem so its sepwork doesn't clobber cstage's. */
|
||||
snprintf(wwdrv, sizeof wwdrv, "%s/ww_ww", bin);
|
||||
if (build_run(dir, wwdrv, sc, "main_w", "w") != 0) { rc = -1; goto done; }
|
||||
if (build_run(dir, wwdrv, sc, "main_w") != 0) { rc = -1; goto done; }
|
||||
|
||||
if (sc->kind == K_BUILDERR) goto done;
|
||||
|
||||
@@ -242,10 +249,16 @@ run_scenario(const char *bin, const struct scenario *sc)
|
||||
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_c.sepwork/*.s > %s 2>/dev/null",
|
||||
dir, cs_s); if (system(cmd)) {}
|
||||
dir, cs_s);
|
||||
int cs_cat = runwait(cmd);
|
||||
snprintf(cmd, sizeof cmd, "cat %s/main_w.sepwork/*.s > %s 2>/dev/null",
|
||||
dir, ws_s); if (system(cmd)) {}
|
||||
if (slurp_eq(cs_s, ws_s) != 0) {
|
||||
dir, ws_s);
|
||||
int ws_cat = runwait(cmd);
|
||||
if (cs_cat != 0 || ws_cat != 0) {
|
||||
fprintf(stderr, "949[%s]: could not aggregate retained "
|
||||
"sepwork asm\n", sc->label);
|
||||
rc = -1;
|
||||
} else if (slurp_eq(cs_s, ws_s) != 0) {
|
||||
fprintf(stderr, "949[%s]: cs.s/ww.s DIFFER (rule-10 "
|
||||
"byte-id violation)\n", sc->label);
|
||||
rc = -1;
|
||||
@@ -253,8 +266,30 @@ run_scenario(const char *bin, const struct scenario *sc)
|
||||
}
|
||||
|
||||
done:
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s", dir);
|
||||
(void)runwait(cmd);
|
||||
{
|
||||
int cleanfail = 0;
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s/main_c.sepwork", dir);
|
||||
if (runwait(cmd) != 0) cleanfail = 1;
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s/main_w.sepwork", dir);
|
||||
if (runwait(cmd) != 0) cleanfail = 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) cleanfail = 1;
|
||||
}
|
||||
const char *children[] = {
|
||||
"main_c", "main_w", "err", "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) cleanfail = 1;
|
||||
}
|
||||
if (rmdir(dir) != 0) cleanfail = 1;
|
||||
if (cleanfail) {
|
||||
fprintf(stderr, "949[%s]: temporary cleanup failed\n",
|
||||
sc->label);
|
||||
rc = -1;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user