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:
@@ -15,6 +15,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
static int
|
||||
@@ -168,16 +169,24 @@ run_build_fail(const char *bin, const char *driver)
|
||||
static int
|
||||
run_missing_pkg(const char *bin, const char *driver)
|
||||
{
|
||||
char src[64], errf[64];
|
||||
snprintf(src, sizeof src, "/tmp/ww_mp_%s_%d.ww", driver, getpid());
|
||||
snprintf(errf, sizeof errf, "/tmp/ww_mp_%s_%d.err", driver, getpid());
|
||||
char tmpdir[80], src[160], errf[160], outbin[160], rmcmd[200];
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/ww_mp_%s_%d", driver, getpid());
|
||||
mkdir(tmpdir, 0755);
|
||||
snprintf(src, sizeof src, "%s/mp.ww", tmpdir);
|
||||
snprintf(errf, sizeof errf, "%s/mp.err", tmpdir);
|
||||
snprintf(outbin, sizeof outbin, "%s/mp", tmpdir);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
|
||||
FILE *f = fopen(src, "w");
|
||||
if (!f) return 1;
|
||||
if (!f) { runwait(rmcmd); return 1; }
|
||||
fputs("import nosuchpkg;\nexport fn main() i32 = { return 0; };\n", f);
|
||||
fclose(f);
|
||||
|
||||
char cmd[256];
|
||||
snprintf(cmd, sizeof cmd, "%s/%s build %s 2>%s", bin, driver, src, errf);
|
||||
/* #8: the sep scratch is mkdir'd before the import-resolution failure,
|
||||
* so a no-o build leaks /tmp/ww_mp_*.sepwork. -o routes it under tmpdir;
|
||||
* rm -rf clears it. The missing-pkg error wording is -o-independent. */
|
||||
char cmd[512];
|
||||
snprintf(cmd, sizeof cmd, "%s/%s build -o %s %s 2>%s",
|
||||
bin, driver, outbin, src, errf);
|
||||
int rc = runwait(cmd);
|
||||
|
||||
int found = 0;
|
||||
@@ -189,7 +198,7 @@ run_missing_pkg(const char *bin, const char *driver)
|
||||
buf[n] = '\0';
|
||||
found = strstr(buf, "cannot find package nosuchpkg") != NULL;
|
||||
}
|
||||
unlink(src); unlink(errf);
|
||||
runwait(rmcmd);
|
||||
if (rc == 0 || !found) {
|
||||
fprintf(stderr, "ww_ww FAIL: %s missing-pkg rc=%d found=%d "
|
||||
"(want nonzero + 'cannot find package')\n", driver, rc, found);
|
||||
|
||||
Reference in New Issue
Block a user