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:
@@ -73,24 +73,25 @@ static int
|
||||
build_should_fail(const char *driver, const char *label, const char *src,
|
||||
const char *diag, int i)
|
||||
{
|
||||
char s[64], tmpdir[64], cmd[1024], bin[128], errf[64];
|
||||
snprintf(s, sizeof s, "/tmp/tuptc_%d_%d.ww", getpid(), i);
|
||||
char s[128], tmpdir[64], cmd[1024], bin[128], errf[128], rmcmd[160];
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/tuptc_%d_d_%d", getpid(), i);
|
||||
snprintf(errf, sizeof errf, "/tmp/tuptc_%d_e_%d.txt", getpid(), i);
|
||||
mkdir(tmpdir, 0755);
|
||||
snprintf(s, sizeof s, "%s/tuptc_%d_%d.ww", tmpdir, getpid(), i);
|
||||
snprintf(errf, sizeof errf, "%s/tuptc_%d_e_%d.txt", tmpdir, getpid(), i);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
|
||||
FILE *f = fopen(s, "wb");
|
||||
if (!f) return -1;
|
||||
if (!f) { runwait(rmcmd); return -1; }
|
||||
fputs(src, f);
|
||||
fclose(f);
|
||||
mkdir(tmpdir, 0755);
|
||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s",
|
||||
tmpdir, driver, s, errf);
|
||||
/* explicit -o INSIDE tmpdir so the binary AND its <stem>.sepwork land
|
||||
* under tmpdir and die with rm -rf; a reject leaks the mkdir'd scratch
|
||||
* too, so clean on every exit path. */
|
||||
outbin(bin, sizeof bin, tmpdir, s);
|
||||
snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s",
|
||||
driver, bin, s, errf);
|
||||
int rc = runwait(cmd);
|
||||
int hasmsg = filehas(errf, diag);
|
||||
outbin(bin, sizeof bin, tmpdir, s);
|
||||
unlink(s);
|
||||
unlink(bin);
|
||||
unlink(errf);
|
||||
rmdir(tmpdir);
|
||||
runwait(rmcmd);
|
||||
if (rc == 0) {
|
||||
fprintf(stderr, "tuptc[%s][%s]: built ok, expected a reject\n",
|
||||
driver, label);
|
||||
@@ -109,25 +110,26 @@ build_should_fail(const char *driver, const char *label, const char *src,
|
||||
static int
|
||||
run_build(const char *driver, const char *label, const char *src, int i)
|
||||
{
|
||||
char s[64], tmpdir[64], cmd[1024], bin[128];
|
||||
snprintf(s, sizeof s, "/tmp/tuptc_ok_%d_%d.ww", getpid(), i);
|
||||
char s[128], tmpdir[64], cmd[1024], bin[128], rmcmd[160];
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/tuptc_ok_%d_d_%d", getpid(), i);
|
||||
mkdir(tmpdir, 0755);
|
||||
snprintf(s, sizeof s, "%s/tuptc_ok_%d_%d.ww", tmpdir, getpid(), i);
|
||||
snprintf(bin, sizeof bin, "%s/tuptc_ok_%d_%d", tmpdir, getpid(), i);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
|
||||
FILE *f = fopen(s, "wb");
|
||||
if (!f) return -1;
|
||||
if (!f) { runwait(rmcmd); return -1; }
|
||||
fputs(src, f);
|
||||
fclose(f);
|
||||
mkdir(tmpdir, 0755);
|
||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
||||
tmpdir, driver, s);
|
||||
snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null",
|
||||
driver, bin, s);
|
||||
if (runwait(cmd) != 0) {
|
||||
fprintf(stderr, "tuptc[%s][%s]: build failed (a valid tuple "
|
||||
"must compile)\n", driver, label);
|
||||
unlink(s); rmdir(tmpdir);
|
||||
runwait(rmcmd);
|
||||
return -1;
|
||||
}
|
||||
outbin(bin, sizeof bin, tmpdir, s);
|
||||
int got = runwait(bin);
|
||||
unlink(s); unlink(bin); rmdir(tmpdir);
|
||||
runwait(rmcmd);
|
||||
return got;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user