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:
@@ -41,7 +41,6 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -174,66 +173,68 @@ main(void)
|
||||
|
||||
int n = 0, fail = 0;
|
||||
for (int i = 0; rows[i].src; i++, n++) {
|
||||
char src[64];
|
||||
snprintf(src, sizeof src, "/tmp/wwtup_%d_%d.ww", getpid(), i);
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (f == NULL) { fail++; continue; }
|
||||
fputs(rows[i].src, f);
|
||||
fclose(f);
|
||||
|
||||
/* (a) cstage build + run in a scratch dir so the output binary
|
||||
* (and any intermediates) land there. */
|
||||
char tmpdir[64];
|
||||
/* src reused across the build-phase (a) AND the w6c/w6c_ww
|
||||
* byte-id phase (b)/(c); keep src, outbin and both .s under one
|
||||
* tmpdir and defer a single rm -rf to the end so the compiler's
|
||||
* .sepwork scratch (derived from the source path) lands in
|
||||
* tmpdir, not bare /tmp. */
|
||||
char tmpdir[64], rmcmd[160];
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/wwtup_%d_d_%d",
|
||||
getpid(), i);
|
||||
mkdir(tmpdir, 0755);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
|
||||
|
||||
char src[128];
|
||||
snprintf(src, sizeof src, "%s/wwtup_%d_%d.ww",
|
||||
tmpdir, getpid(), i);
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (f == NULL) { fail++; runwait(rmcmd); continue; }
|
||||
fputs(rows[i].src, f);
|
||||
fclose(f);
|
||||
|
||||
/* (a) cstage build + run; -o pins the binary into tmpdir. */
|
||||
char outbin[128];
|
||||
snprintf(outbin, sizeof outbin, "%s/wwtup_%d_%d",
|
||||
tmpdir, getpid(), i);
|
||||
|
||||
char cmd[2048];
|
||||
snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s",
|
||||
tmpdir, bin, src);
|
||||
snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s",
|
||||
bin, outbin, src);
|
||||
if (runwait(cmd) != 0) {
|
||||
fprintf(stderr, "row[%s]: cstage build failed\n",
|
||||
rows[i].label);
|
||||
fail++;
|
||||
unlink(src); rmdir(tmpdir);
|
||||
runwait(rmcmd);
|
||||
continue;
|
||||
}
|
||||
|
||||
char outbin[128];
|
||||
const char *base = strrchr(src, '/');
|
||||
base = base ? base + 1 : src;
|
||||
snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base);
|
||||
char *dot = strrchr(outbin, '.');
|
||||
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
|
||||
|
||||
int got = runwait(outbin);
|
||||
if (got != rows[i].want_exit) {
|
||||
fprintf(stderr, "row[%s]: cstage exit %d, want %d\n",
|
||||
rows[i].label, got, rows[i].want_exit);
|
||||
fail++;
|
||||
}
|
||||
unlink(outbin); rmdir(tmpdir);
|
||||
|
||||
/* (b) cs==ww byte-id gate: emit .s from both stages, cmp.
|
||||
* FAILS on the pre-fix wwstage divergence (dropped MOVQ DX). */
|
||||
char cs_s[64], ws_s[64];
|
||||
snprintf(cs_s, sizeof cs_s, "/tmp/wwtup_%d_%d_cs.s",
|
||||
getpid(), i);
|
||||
snprintf(ws_s, sizeof ws_s, "/tmp/wwtup_%d_%d_ww.s",
|
||||
getpid(), i);
|
||||
char cs_s[128], ws_s[128];
|
||||
snprintf(cs_s, sizeof cs_s, "%s/wwtup_%d_%d_cs.s",
|
||||
tmpdir, getpid(), i);
|
||||
snprintf(ws_s, sizeof ws_s, "%s/wwtup_%d_%d_ww.s",
|
||||
tmpdir, getpid(), i);
|
||||
|
||||
snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null",
|
||||
w6c, cs_s, src);
|
||||
if (runwait(cmd) != 0) {
|
||||
fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label);
|
||||
fail++; unlink(src); continue;
|
||||
fail++; runwait(rmcmd); continue;
|
||||
}
|
||||
snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null",
|
||||
w6c_ww, ws_s, src);
|
||||
if (runwait(cmd) != 0) {
|
||||
fprintf(stderr, "row[%s]: w6c_ww failed\n",
|
||||
rows[i].label);
|
||||
fail++; unlink(src); unlink(cs_s); continue;
|
||||
fail++; runwait(rmcmd); continue;
|
||||
}
|
||||
if (slurp_eq(cs_s, ws_s) != 0) {
|
||||
fprintf(stderr,
|
||||
@@ -248,9 +249,9 @@ main(void)
|
||||
* pre-stamp (HEAD) w6c_ww fires asserttyped on the f64 binding
|
||||
* ident (nil n.type_). */
|
||||
if (rows[i].chk_stamped) {
|
||||
char errf[80];
|
||||
char errf[128];
|
||||
snprintf(errf, sizeof errf,
|
||||
"/tmp/wwtup_%d_%d_err.txt", getpid(), i);
|
||||
"%s/wwtup_%d_%d_err.txt", tmpdir, getpid(), i);
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"%s -o /dev/null %s 2>%s", w6c_ww, src, errf);
|
||||
runwait(cmd);
|
||||
@@ -262,9 +263,8 @@ main(void)
|
||||
"unstamped)\n", rows[i].label);
|
||||
fail++;
|
||||
}
|
||||
unlink(errf);
|
||||
}
|
||||
unlink(src); unlink(cs_s); unlink(ws_s);
|
||||
runwait(rmcmd);
|
||||
}
|
||||
|
||||
if (fail) {
|
||||
|
||||
Reference in New Issue
Block a user