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:
@@ -18,6 +18,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
static int
|
||||
@@ -35,16 +36,23 @@ static int
|
||||
run_miss(const char *bin)
|
||||
{
|
||||
int pid = getpid();
|
||||
char src[64], errf[64], outb[64], comb[80], cmd[2048], line[4096];
|
||||
snprintf(src, sizeof src, "/tmp/mp949_miss_%d.ww", pid);
|
||||
snprintf(errf, sizeof errf, "/tmp/mp949_miss_%d.err", pid);
|
||||
/* -o a writable /tmp stem (not /dev/null): post-T3 the intermediate
|
||||
* .combined.ww/.s/.o follow -o, so /dev/null would yield an
|
||||
* uncreatable /dev/null.combined.ww and mask the missing-pkg fatal. */
|
||||
snprintf(outb, sizeof outb, "/tmp/mp949_miss_%d.out", pid);
|
||||
snprintf(comb, sizeof comb, "/tmp/mp949_miss_%d.out.combined.ww", pid);
|
||||
char tmpdir[64], src[128], errf[128], outb[128], cmd[2048];
|
||||
char rmcmd[160], line[4096];
|
||||
/* source + binary + intermediates + .sepwork all under one tmpdir so
|
||||
* the compiler's output-derived .sepwork scratch lands here (not bare
|
||||
* /tmp where unlink/rmdir would never name it) and the single rm -rf
|
||||
* reclaims it on every exit path. */
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/mp949_miss_%d_d", pid);
|
||||
mkdir(tmpdir, 0755);
|
||||
snprintf(src, sizeof src, "%s/mp949_miss_%d.ww", tmpdir, pid);
|
||||
snprintf(errf, sizeof errf, "%s/mp949_miss_%d.err", tmpdir, pid);
|
||||
/* -o a writable stem inside tmpdir (not /dev/null): post-T3 the
|
||||
* intermediate .combined.ww/.s/.o follow -o, so /dev/null would yield
|
||||
* an uncreatable /dev/null.combined.ww and mask the missing-pkg fatal. */
|
||||
snprintf(outb, sizeof outb, "%s/mp949_miss_%d.out", tmpdir, pid);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
|
||||
FILE *f = fopen(src, "w");
|
||||
if (!f) { fprintf(stderr, "949 FAIL: stage miss\n"); return 1; }
|
||||
if (!f) { fprintf(stderr, "949 FAIL: stage miss\n"); runwait(rmcmd); return 1; }
|
||||
fputs("import nosuchpkg;\n"
|
||||
"export fn main() i32 = { return 0; };\n", f);
|
||||
fclose(f);
|
||||
@@ -54,7 +62,7 @@ run_miss(const char *bin)
|
||||
int rc = runwait(cmd);
|
||||
if (rc == 0) {
|
||||
fprintf(stderr, "949 FAIL: ww accepted a missing import\n");
|
||||
unlink(src); unlink(errf); unlink(outb); unlink(comb);
|
||||
runwait(rmcmd);
|
||||
return 1;
|
||||
}
|
||||
int found = 0;
|
||||
@@ -66,7 +74,7 @@ run_miss(const char *bin)
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
unlink(src); unlink(errf); unlink(outb); unlink(comb);
|
||||
runwait(rmcmd);
|
||||
if (!found) {
|
||||
fprintf(stderr, "949 FAIL: no 'cannot find package nosuchpkg' "
|
||||
"on stderr\n");
|
||||
@@ -82,11 +90,17 @@ static int
|
||||
run_inline(const char *bin)
|
||||
{
|
||||
int pid = getpid();
|
||||
char src[64], outb[64], cmd[2048];
|
||||
snprintf(src, sizeof src, "/tmp/mp949_inl_%d.ww", pid);
|
||||
snprintf(outb, sizeof outb, "/tmp/mp949_inl_%d", pid);
|
||||
char tmpdir[64], src[128], outb[128], cmd[2048], rmcmd[160];
|
||||
/* source + binary + .sepwork all under one tmpdir so the compiler's
|
||||
* source-derived .sepwork scratch lands here (not bare /tmp) and the
|
||||
* single rm -rf reclaims it. */
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/mp949_inl_%d_d", pid);
|
||||
mkdir(tmpdir, 0755);
|
||||
snprintf(src, sizeof src, "%s/mp949_inl_%d.ww", tmpdir, pid);
|
||||
snprintf(outb, sizeof outb, "%s/mp949_inl_%d", tmpdir, pid);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
|
||||
FILE *f = fopen(src, "w");
|
||||
if (!f) { fprintf(stderr, "949 FAIL: stage inline\n"); return 1; }
|
||||
if (!f) { fprintf(stderr, "949 FAIL: stage inline\n"); runwait(rmcmd); return 1; }
|
||||
fputs("package aa;\n"
|
||||
"export fn getv() i32 = { return 7; };\n"
|
||||
"package main;\n"
|
||||
@@ -94,19 +108,17 @@ run_inline(const char *bin)
|
||||
"export fn main() i32 = { return aa.getv(); };\n", f);
|
||||
fclose(f);
|
||||
|
||||
/* `ww build` emits the binary by basename in the cwd, so build from
|
||||
* /tmp to keep both source and output out of the tree. */
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"cd /tmp && %s/ww build mp949_inl_%d.ww >/dev/null 2>&1", bin, pid);
|
||||
"%s/ww build -o %s %s >/dev/null 2>&1", bin, outb, src);
|
||||
int rc = runwait(cmd);
|
||||
if (rc != 0) {
|
||||
fprintf(stderr, "949 FAIL: inline-package build failed "
|
||||
"(inline-skip branch regressed)\n");
|
||||
unlink(src);
|
||||
runwait(rmcmd);
|
||||
return 1;
|
||||
}
|
||||
int got = runwait(outb);
|
||||
unlink(src); unlink(outb);
|
||||
runwait(rmcmd);
|
||||
if (got != 7) {
|
||||
fprintf(stderr, "949 FAIL: inline-package exit=%d want=7\n", got);
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user