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:
@@ -67,12 +67,20 @@ run_neg(const char *driver, const char *fixdir, const char *tag)
|
||||
{
|
||||
char src[64];
|
||||
snprintf(src, sizeof src, "neg_%s.ww", tag);
|
||||
char td[128];
|
||||
snprintf(td, sizeof td, "/tmp/psm_neg_%d_%s", getpid(), tag);
|
||||
mkdir(td, 0755);
|
||||
char cmd[2048];
|
||||
/* cd into the fixture dir so the driver's source-dir-first
|
||||
* import search resolves `use shadowmod;`. */
|
||||
* import search resolves `use shadowmod;`; -o moves the binary
|
||||
* and its <stem>.sepwork OUT of the tracked fixture tree. */
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"cd %s && %s build %s >/dev/null 2>&1", fixdir, driver, src);
|
||||
"cd %s && %s build -o %s/out %s >/dev/null 2>&1",
|
||||
fixdir, driver, td, src);
|
||||
int rc = runwait(cmd);
|
||||
char rmcmd[256];
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td);
|
||||
runwait(rmcmd);
|
||||
if (rc == 0) {
|
||||
fprintf(stderr,
|
||||
"param_shadow_mod[neg_%s]: build unexpectedly succeeded "
|
||||
@@ -85,20 +93,28 @@ run_neg(const char *driver, const char *fixdir, const char *tag)
|
||||
static int
|
||||
run_pos(const char *driver, const char *fixdir)
|
||||
{
|
||||
char td[128];
|
||||
snprintf(td, sizeof td, "/tmp/psm_pos_%d", getpid());
|
||||
mkdir(td, 0755);
|
||||
char rmcmd[256];
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td);
|
||||
char cmd[2048];
|
||||
/* keep cd for sibling-import resolution; -o moves the binary and
|
||||
* its pos_rename.sepwork OUT of the tracked fixture tree. */
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"cd %s && %s build pos_rename.ww >/dev/null 2>&1",
|
||||
fixdir, driver);
|
||||
"cd %s && %s build -o %s/out pos_rename.ww >/dev/null 2>&1",
|
||||
fixdir, driver, td);
|
||||
if (runwait(cmd) != 0) {
|
||||
runwait(rmcmd);
|
||||
fprintf(stderr,
|
||||
"param_shadow_mod[pos_rename]: build failed — rule "
|
||||
"over-triggered on the rename\n");
|
||||
return 1;
|
||||
}
|
||||
char bin[2048];
|
||||
snprintf(bin, sizeof bin, "%s/pos_rename", fixdir);
|
||||
snprintf(bin, sizeof bin, "%s/out", td);
|
||||
int got = runwait(bin);
|
||||
unlink(bin);
|
||||
runwait(rmcmd);
|
||||
if (got != 42) {
|
||||
fprintf(stderr,
|
||||
"param_shadow_mod[pos_rename]: exit=%d want=42\n", got);
|
||||
@@ -159,20 +175,28 @@ run_neg_selfimp(const char *comp, const char *fixdir, const char *tag)
|
||||
static int
|
||||
run_pos_crossmod(const char *driver, const char *fixdir)
|
||||
{
|
||||
char td[128];
|
||||
snprintf(td, sizeof td, "/tmp/psm_crossmod_%d", getpid());
|
||||
mkdir(td, 0755);
|
||||
char rmcmd[256];
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td);
|
||||
char cmd[2048];
|
||||
/* keep cd for sibling-import resolution; -o moves the binary and
|
||||
* its pos_crossmod.sepwork OUT of the tracked fixture tree. */
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"cd %s && %s build pos_crossmod.ww >/dev/null 2>&1",
|
||||
fixdir, driver);
|
||||
"cd %s && %s build -o %s/out pos_crossmod.ww >/dev/null 2>&1",
|
||||
fixdir, driver, td);
|
||||
if (runwait(cmd) != 0) {
|
||||
runwait(rmcmd);
|
||||
fprintf(stderr,
|
||||
"param_shadow_mod[pos_crossmod]: build failed — shadow "
|
||||
"rule over-triggered on a cross-module param\n");
|
||||
return 1;
|
||||
}
|
||||
char bin[2048];
|
||||
snprintf(bin, sizeof bin, "%s/pos_crossmod", fixdir);
|
||||
snprintf(bin, sizeof bin, "%s/out", td);
|
||||
int got = runwait(bin);
|
||||
unlink(bin);
|
||||
runwait(rmcmd);
|
||||
if (got != 2) {
|
||||
fprintf(stderr,
|
||||
"param_shadow_mod[pos_crossmod]: exit=%d want=2\n", got);
|
||||
|
||||
Reference in New Issue
Block a user