test: contain sepwork scratch per-driver tmpdir, fix /tmp+in-repo leak (#8)

The wcc test drivers ran `ww build <bare-/tmp src>` with no -o, so the
compiler's <stem>.sepwork scratch landed beside the source and was never
cleaned: unbounded /tmp growth (2195 stale dirs observed) that fills tmpfs
and fabricates phantom test failures + silent harness aborts, and for
in-repo fixture builds leaked .sepwork into the tracked tree.

Each leaking build now writes its source + output inside a per-invocation
tmpdir, passes -o <tmpdir>/<stem> so the .sepwork lands inside it, and
rm -rf's the tmpdir on every exit path -- including fopen-fail and the
expected-fail reject builds (scratch is mkdir'd before the build can fail).
`ww run` and explicit-`-o`/byte-id helpers are left as-is; the 990/993
byte-id comparison logic is byte-for-byte unchanged.

Two items filed separately (this commit holds the no-Makefile / no-main.c
rail):
- #13: a stale <src>.s byte-id readback (749) silently no-ops since
  separate-compile emits .s to <ostem>.sepwork/__root.s; documented inline.
- #14: build-system Makefile recipes build selfhost/cmd/*/main.ww with no
  -o and leak main.sepwork in-tree (bounded, gitignored; own commit).

One concern -- sepwork leak hygiene -- across 228 drivers; uniform
transform applied per-file and two-round reviewed. make test: all 402
passed, zero net-new /tmp scratch, zero test-driven in-repo .sepwork.
This commit is contained in:
2026-06-22 23:29:39 +09:00
parent 6525e137ae
commit ce3a25a0b4
228 changed files with 3387 additions and 4484 deletions

View File

@@ -131,37 +131,33 @@ main(void)
}
int fail = 0;
char src[64], cmd[2048];
char src[128], outbin[128], cs_s[128], ws_s[128], cmd[2048];
/* fixture 1: vectors — cstage build+run, then byte-id */
snprintf(src, sizeof src, "/tmp/wwflit_%d.ww", getpid());
if (writesrc(src, vectors_src) != 0) return 1;
char tmpdir[64];
char tmpdir[64], rmcmd[160];
snprintf(tmpdir, sizeof tmpdir, "/tmp/wwflit_%d_d", getpid());
mkdir(tmpdir, 0755);
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", tmpdir, bin, src);
/* fixture 1: vectors — cstage build+run, then byte-id */
snprintf(src, sizeof src, "%s/wwflit_%d.ww", tmpdir, getpid());
if (writesrc(src, vectors_src) != 0) { runwait(rmcmd); return 1; }
snprintf(outbin, sizeof outbin, "%s/wwflit_%d", tmpdir, getpid());
snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", bin, outbin, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "floatlit: cstage build failed\n");
fail++;
} else {
char outbin[128];
snprintf(outbin, sizeof outbin, "%s/wwflit_%d", tmpdir,
getpid());
int got = runwait(outbin);
if (got != 0) {
fprintf(stderr, "floatlit: vector row %d has wrong "
"bits at runtime (cstage)\n", got);
fail++;
}
unlink(outbin);
}
rmdir(tmpdir);
char cs_s[64], ws_s[64];
snprintf(cs_s, sizeof cs_s, "/tmp/wwflit_%d_cs.s", getpid());
snprintf(ws_s, sizeof ws_s, "/tmp/wwflit_%d_ww.s", getpid());
snprintf(cs_s, sizeof cs_s, "%s/wwflit_%d_cs.s", tmpdir, getpid());
snprintf(ws_s, sizeof ws_s, "%s/wwflit_%d_ww.s", tmpdir, getpid());
snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "floatlit: w6c failed on vectors\n");
@@ -178,11 +174,10 @@ main(void)
fail++;
}
}
unlink(src); unlink(cs_s); unlink(ws_s);
/* fixture 2: overflow literal — BOTH stages must reject */
snprintf(src, sizeof src, "/tmp/wwflit_%d_ovf.ww", getpid());
if (writesrc(src, overflow_src) != 0) return 1;
snprintf(src, sizeof src, "%s/wwflit_%d_ovf.ww", tmpdir, getpid());
if (writesrc(src, overflow_src) != 0) { runwait(rmcmd); return 1; }
snprintf(cmd, sizeof cmd, "%s %s >/dev/null 2>&1", w6c, src);
if (runwait(cmd) == 0) {
fprintf(stderr, "floatlit: w6c ACCEPTED overflow literal\n");
@@ -193,7 +188,7 @@ main(void)
fprintf(stderr, "floatlit: w6c_ww ACCEPTED overflow literal\n");
fail++;
}
unlink(src);
runwait(rmcmd);
if (fail) {
fprintf(stderr, "floatlit: %d check(s) failed\n", fail);