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:
@@ -29,7 +29,6 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -92,11 +91,11 @@ static const struct row rows[] = {
|
||||
};
|
||||
|
||||
static int
|
||||
build_with(const char *driver, const char *src_path, const char *tmpdir)
|
||||
build_with(const char *driver, const char *src_path, const char *outbin)
|
||||
{
|
||||
char cmd[1024];
|
||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
||||
tmpdir, driver, src_path);
|
||||
snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null",
|
||||
driver, outbin, src_path);
|
||||
return runwait(cmd);
|
||||
}
|
||||
|
||||
@@ -130,26 +129,22 @@ main(void)
|
||||
for (int i = 0; i < n; i++) {
|
||||
const struct row *r = &rows[i];
|
||||
|
||||
char src[64], tmpdir[64];
|
||||
snprintf(src, sizeof src, "/tmp/vararg_seq_%d_%d.ww",
|
||||
getpid(), i);
|
||||
char tmpdir[64], src[128], outbin[128], rmcmd[160];
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/vararg_seq_%d_d_%d",
|
||||
getpid(), i);
|
||||
mkdir(tmpdir, 0755);
|
||||
snprintf(src, sizeof src, "%s/vararg_seq_%d_%d.ww",
|
||||
tmpdir, getpid(), i);
|
||||
snprintf(outbin, sizeof outbin, "%s/vararg_seq_%d_%d",
|
||||
tmpdir, getpid(), i);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (!f) { fail++; total++; continue; }
|
||||
if (!f) { runwait(rmcmd); fail++; total++; continue; }
|
||||
fputs(r->src, f);
|
||||
fclose(f);
|
||||
mkdir(tmpdir, 0755);
|
||||
|
||||
const char *base = strrchr(src, '/');
|
||||
base = base ? base + 1 : src;
|
||||
char outbin[128];
|
||||
snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base);
|
||||
char *dot = strrchr(outbin, '.');
|
||||
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
|
||||
|
||||
total++;
|
||||
if (build_with(cdrv, src, tmpdir) != 0) {
|
||||
if (build_with(cdrv, src, outbin) != 0) {
|
||||
fprintf(stderr,
|
||||
"vararg_seq_percall[cs][%s]: build failed\n",
|
||||
r->label);
|
||||
@@ -167,7 +162,7 @@ main(void)
|
||||
|
||||
if (have_ww) {
|
||||
total++;
|
||||
if (build_with(wdrv, src, tmpdir) != 0) {
|
||||
if (build_with(wdrv, src, outbin) != 0) {
|
||||
fprintf(stderr,
|
||||
"vararg_seq_percall[ws][%s]: build failed\n",
|
||||
r->label);
|
||||
@@ -181,11 +176,9 @@ main(void)
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
unlink(outbin);
|
||||
}
|
||||
|
||||
unlink(src);
|
||||
rmdir(tmpdir);
|
||||
runwait(rmcmd);
|
||||
}
|
||||
|
||||
if (fail) {
|
||||
|
||||
Reference in New Issue
Block a user