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:
@@ -224,34 +224,30 @@ static const struct row rows[] = {
|
||||
static int
|
||||
run_driver(const char *driver, const struct row *r, int i)
|
||||
{
|
||||
char src[64], tmpdir[64], cmd[1024];
|
||||
snprintf(src, sizeof src, "/tmp/pk51_%d_%d.ww", getpid(), i);
|
||||
char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024];
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/pk51_%d_d_%d", getpid(), i);
|
||||
mkdir(tmpdir, 0755);
|
||||
snprintf(src, sizeof src, "%s/pk51_%d_%d.ww", tmpdir, getpid(), i);
|
||||
snprintf(outbin, sizeof outbin, "%s/pk51_%d_%d", tmpdir, getpid(), i);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
|
||||
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (!f) return -2;
|
||||
if (!f) { runwait(rmcmd); return -2; }
|
||||
fputs(r->src, f);
|
||||
fclose(f);
|
||||
|
||||
mkdir(tmpdir, 0755);
|
||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
||||
tmpdir, driver, src);
|
||||
snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null",
|
||||
driver, outbin, src);
|
||||
int built = runwait(cmd);
|
||||
if (built != 0) {
|
||||
/* build failed (a reject, or a real error). Caller decides. */
|
||||
unlink(src); rmdir(tmpdir);
|
||||
runwait(rmcmd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *base = strrchr(src, '/');
|
||||
base = base ? base + 1 : src;
|
||||
char outbin[128];
|
||||
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(src); unlink(outbin); rmdir(tmpdir);
|
||||
runwait(rmcmd);
|
||||
return got;
|
||||
}
|
||||
|
||||
@@ -312,19 +308,20 @@ asm_byte_identical(const char *bin, const struct row *r, int i)
|
||||
static int
|
||||
wwi_roundtrip(const char *driver, int idx)
|
||||
{
|
||||
char root[80], libdir[128], appww[160], cmd[1024], outbin[200];
|
||||
char root[80], libdir[128], appww[160], cmd[1024], outbin[200], rm[200];
|
||||
snprintf(root, sizeof root, "/tmp/pk51w_%d_%d", getpid(), idx);
|
||||
snprintf(libdir, sizeof libdir, "%s/lib/pk2", root);
|
||||
snprintf(appww, sizeof appww, "%s/app/main.ww", root);
|
||||
snprintf(rm, sizeof rm, "rm -rf %s", root);
|
||||
|
||||
char mk[256];
|
||||
snprintf(mk, sizeof mk, "mkdir -p %s/lib/pk2 %s/app", root, root);
|
||||
if (runwait(mk) != 0) return -1;
|
||||
if (runwait(mk) != 0) { runwait(rm); return -1; }
|
||||
|
||||
char pk2[256];
|
||||
snprintf(pk2, sizeof pk2, "%s/lib/pk2/pk2.ww", root);
|
||||
FILE *f = fopen(pk2, "wb");
|
||||
if (!f) return -1;
|
||||
if (!f) { runwait(rm); return -1; }
|
||||
/* pk2 exports ONLY the packed type — no helper fns. The size/offset
|
||||
* are computed on the IMPORTER side (below), so the value depends on
|
||||
* the .wwi re-parse laying Ev out packed. (If evsize()/evoff() lived
|
||||
@@ -335,7 +332,7 @@ wwi_roundtrip(const char *driver, int idx)
|
||||
fclose(f);
|
||||
|
||||
f = fopen(appww, "wb");
|
||||
if (!f) return -1;
|
||||
if (!f) { runwait(rm); return -1; }
|
||||
/* importer computes layout from the re-parsed .wwi: packed → 9*10+1
|
||||
* = 91; a dropped @packed (unpacked Ev) would give 16*10+8 = 168. */
|
||||
fputs("package main;\n"
|
||||
@@ -350,16 +347,12 @@ wwi_roundtrip(const char *driver, int idx)
|
||||
"cd %s/app && %s build -I %s/lib -o m main.ww 2>/dev/null",
|
||||
root, driver, root);
|
||||
if (runwait(cmd) != 0) {
|
||||
char rm[200];
|
||||
snprintf(rm, sizeof rm, "rm -rf %s", root);
|
||||
runwait(rm);
|
||||
return -1;
|
||||
}
|
||||
snprintf(outbin, sizeof outbin, "%s/app/m", root);
|
||||
int got = runwait(outbin);
|
||||
|
||||
char rm[200];
|
||||
snprintf(rm, sizeof rm, "rm -rf %s", root);
|
||||
runwait(rm);
|
||||
return got;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user