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:
@@ -19,6 +19,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
static int
|
||||
@@ -62,11 +63,11 @@ main(void)
|
||||
int total = 0, fail = 0;
|
||||
char errp[64];
|
||||
|
||||
/* ok: cross-pkg bare-leaf via dir-enum, both stages. */
|
||||
/* ok: cross-pkg bare-leaf via dir-enum, both stages. `ww run` routes
|
||||
* its scratch through /tmp/ww_run_<pid>.sepwork and removes it itself
|
||||
* (do_run keepscratch 0), so no per-invocation tmpdir is needed here. */
|
||||
{
|
||||
const char *src = "test/wcc/data/direnum/entry.ww";
|
||||
char tmp[64];
|
||||
snprintf(tmp, sizeof tmp, "/tmp/direnum_%d_ok", getpid());
|
||||
char cmd[2048];
|
||||
|
||||
snprintf(cmd, sizeof cmd, "%s run %s >/dev/null 2>&1", ww, src);
|
||||
@@ -85,7 +86,6 @@ main(void)
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
(void)tmp;
|
||||
}
|
||||
|
||||
/* bad: mismatched package decls in same dir → import-path mismatch
|
||||
@@ -98,10 +98,21 @@ main(void)
|
||||
const char *src = "test/wcc/data/direnum/bad_entry.ww";
|
||||
snprintf(errp, sizeof errp, "/tmp/direnum_%d_bad.err", getpid());
|
||||
|
||||
/* CLASS B: build INPUT stays the in-repo fixture, but -o points the
|
||||
* output stem (and thus its <stem>.sepwork scratch) at a unique /tmp
|
||||
* tmpdir so nothing leaks into the tracked tree — even on the
|
||||
* expected build failure, since scratch is mkdir'd before the reject.
|
||||
* rm -rf the tmpdir on every exit path. */
|
||||
char td[64], rmcmd[128];
|
||||
char cmd[2048];
|
||||
snprintf(cmd, sizeof cmd, "%s build %s 2>%s >/dev/null",
|
||||
ww, src, errp);
|
||||
|
||||
snprintf(td, sizeof td, "/tmp/direnum_%d_bad_c", getpid());
|
||||
mkdir(td, 0755);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td);
|
||||
snprintf(cmd, sizeof cmd, "%s build -o %s/out %s 2>%s >/dev/null",
|
||||
ww, td, src, errp);
|
||||
int rc = runwait(cmd);
|
||||
runwait(rmcmd);
|
||||
total++;
|
||||
if (rc == 0) {
|
||||
fprintf(stderr, "737[bad-cstage]: expected build failure, succeeded\n");
|
||||
@@ -113,9 +124,13 @@ main(void)
|
||||
unlink(errp);
|
||||
|
||||
if (access(ww_ww, X_OK) == 0) {
|
||||
snprintf(cmd, sizeof cmd, "%s build %s 2>%s >/dev/null",
|
||||
ww_ww, src, errp);
|
||||
snprintf(td, sizeof td, "/tmp/direnum_%d_bad_w", getpid());
|
||||
mkdir(td, 0755);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td);
|
||||
snprintf(cmd, sizeof cmd, "%s build -o %s/out %s 2>%s >/dev/null",
|
||||
ww_ww, td, src, errp);
|
||||
rc = runwait(cmd);
|
||||
runwait(rmcmd);
|
||||
total++;
|
||||
if (rc == 0) {
|
||||
fprintf(stderr, "737[bad-wwstage]: expected build failure, succeeded\n");
|
||||
@@ -138,10 +153,19 @@ main(void)
|
||||
const char *src = "test/wcc/data/direnum/bad_deep_entry.ww";
|
||||
snprintf(errp, sizeof errp, "/tmp/direnum_%d_baddeep.err", getpid());
|
||||
|
||||
/* CLASS B (see bad block): -o into a unique /tmp tmpdir keeps the
|
||||
* <stem>.sepwork scratch out of the tracked tree on the expected
|
||||
* reject; rm -rf on every exit path. */
|
||||
char td[64], rmcmd[128];
|
||||
char cmd[2048];
|
||||
snprintf(cmd, sizeof cmd, "%s build %s 2>%s >/dev/null",
|
||||
ww, src, errp);
|
||||
|
||||
snprintf(td, sizeof td, "/tmp/direnum_%d_baddeep_c", getpid());
|
||||
mkdir(td, 0755);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td);
|
||||
snprintf(cmd, sizeof cmd, "%s build -o %s/out %s 2>%s >/dev/null",
|
||||
ww, td, src, errp);
|
||||
int rc = runwait(cmd);
|
||||
runwait(rmcmd);
|
||||
total++;
|
||||
if (rc == 0) {
|
||||
fprintf(stderr, "737[bad-deep-cstage]: expected build failure, succeeded\n");
|
||||
@@ -153,9 +177,13 @@ main(void)
|
||||
unlink(errp);
|
||||
|
||||
if (access(ww_ww, X_OK) == 0) {
|
||||
snprintf(cmd, sizeof cmd, "%s build %s 2>%s >/dev/null",
|
||||
ww_ww, src, errp);
|
||||
snprintf(td, sizeof td, "/tmp/direnum_%d_baddeep_w", getpid());
|
||||
mkdir(td, 0755);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td);
|
||||
snprintf(cmd, sizeof cmd, "%s build -o %s/out %s 2>%s >/dev/null",
|
||||
ww_ww, td, src, errp);
|
||||
rc = runwait(cmd);
|
||||
runwait(rmcmd);
|
||||
total++;
|
||||
if (rc == 0) {
|
||||
fprintf(stderr, "737[bad-deep-wwstage]: expected build failure, succeeded\n");
|
||||
|
||||
Reference in New Issue
Block a user