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

@@ -177,28 +177,19 @@ file_has(const char *path, const char *needle)
}
static int
run_driver(const char *driver, const char *src, const char *label)
run_driver(const char *driver, const char *tmpdir, const char *src,
const char *label)
{
char tmpdir[128], cmd[1024];
snprintf(tmpdir, sizeof tmpdir, "/tmp/tves_%d_d", getpid());
mkdir(tmpdir, 0755);
snprintf(cmd, sizeof cmd, "cd %s && %s/%s build %s >/dev/null 2>&1",
tmpdir, g_bin, driver, src);
char cmd[1024], outbin[256];
snprintf(outbin, sizeof outbin, "%s/out_%s", tmpdir, driver);
snprintf(cmd, sizeof cmd, "%s/%s build -o %s %s >/dev/null 2>&1",
g_bin, driver, outbin, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "row[%s]: build via %s failed\n",
label, driver);
return -1;
}
const char *base = strrchr(src, '/');
base = base ? base + 1 : src;
char outbin[256];
snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base);
char *dot = strrchr(outbin, '.');
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
int got = runwait(outbin);
unlink(outbin);
rmdir(tmpdir);
return got;
return runwait(outbin);
}
int
@@ -219,20 +210,25 @@ main(void)
int total = 0, fail = 0;
for (int i = 0; i < n; i++) {
const struct row *r = &rows[i];
char src[128], cs_s[128], ww_s[128];
char cs_e[128], ww_e[128];
snprintf(src, sizeof src, "/tmp/tves_%d_%d.ww",
getpid(), i);
snprintf(cs_s, sizeof cs_s, "/tmp/tves_%d_%d_cs.s",
getpid(), i);
snprintf(ww_s, sizeof ww_s, "/tmp/tves_%d_%d_ww.s",
getpid(), i);
snprintf(cs_e, sizeof cs_e, "/tmp/tves_%d_%d_cs.err",
getpid(), i);
snprintf(ww_e, sizeof ww_e, "/tmp/tves_%d_%d_ww.err",
char tmpdir[128], rmcmd[160];
char src[160], cs_s[160], ww_s[160];
char cs_e[160], ww_e[160];
snprintf(tmpdir, sizeof tmpdir, "/tmp/tves_%d_d_%d",
getpid(), i);
mkdir(tmpdir, 0755);
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
snprintf(src, sizeof src, "%s/tves_%d_%d.ww",
tmpdir, getpid(), i);
snprintf(cs_s, sizeof cs_s, "%s/tves_%d_%d_cs.s",
tmpdir, getpid(), i);
snprintf(ww_s, sizeof ww_s, "%s/tves_%d_%d_ww.s",
tmpdir, getpid(), i);
snprintf(cs_e, sizeof cs_e, "%s/tves_%d_%d_cs.err",
tmpdir, getpid(), i);
snprintf(ww_e, sizeof ww_e, "%s/tves_%d_%d_ww.err",
tmpdir, getpid(), i);
FILE *f = fopen(src, "wb");
if (!f) return 1;
if (!f) { runwait(rmcmd); return 1; }
fputs("package main;\n\n", f);
fputs(r->src, f);
fclose(f);
@@ -244,8 +240,7 @@ main(void)
fprintf(stderr, "FAIL row[%s]: compile rc cs=%d "
"ww=%d\n", r->label, cs_rc, ww_rc);
fail++;
unlink(src); unlink(cs_s); unlink(ww_s);
unlink(cs_e); unlink(ww_e);
runwait(rmcmd);
continue;
}
if (!file_eq(cs_s, ww_s)) {
@@ -263,7 +258,7 @@ main(void)
r->label);
fail++;
}
int got_cs = run_driver("ww", src, r->label);
int got_cs = run_driver("ww", tmpdir, src, r->label);
if (got_cs != r->want) {
fprintf(stderr, "FAIL row[%s] cstage: want %d "
"got %d\n", r->label, r->want, got_cs);
@@ -272,7 +267,7 @@ main(void)
char wwdrv[600];
snprintf(wwdrv, sizeof wwdrv, "%s/ww_ww", g_bin);
if (access(wwdrv, X_OK) == 0) {
int got_ww = run_driver("ww_ww", src, r->label);
int got_ww = run_driver("ww_ww", tmpdir, src, r->label);
if (got_ww != r->want) {
fprintf(stderr, "FAIL row[%s] wwstage: "
"want %d got %d\n",
@@ -280,8 +275,7 @@ main(void)
fail++;
}
}
unlink(src); unlink(cs_s); unlink(ww_s);
unlink(cs_e); unlink(ww_e);
runwait(rmcmd);
}
if (fail) {
fprintf(stderr, "void_error_singleton_run: %d/%d rows "