test/wcc: carrier ownership repair and driver-contract adaptation
Every surviving carrier now owns its artifacts: checked mkdir/mkdtemp/ fopen acquisition, one all-exit cleanup funnel per carrier, ENOENT- tolerant checked unlinks, exact-path deletion (rm -rf only for an owned pid-keyed dir or a .sepwork beneath one), and cleanup failure fails a passing carrier without overwriting its diagnostic. In the same pass the carriers adapt to the driver contract this branch lands: --sep and WW_PKGCACHE are gone, -S and the /tmp/ww_run_<pid> scratch contract are asserted, and rows whose runtime or reject coverage moved to test/wcc/data fixtures or test/lang @test owners are trimmed to the byte/artifact/diagnostic observations only they can make. Repair and adaptation ride together because most files interleave both in the same hunks; splitting would manufacture intermediate carrier states that never existed and cannot run against either driver.
This commit is contained in:
@@ -101,64 +101,111 @@ static const struct row rows[] = {
|
||||
3 },
|
||||
};
|
||||
|
||||
/* write_file — create `dir/rel` (mkdir -p its parents) with `content`. */
|
||||
/* write_file — create `dir/rel` in an already-owned package tree. */
|
||||
static int
|
||||
write_file(const char *dir, const char *rel, const char *content)
|
||||
write_file(const char *dir, const char *rel, const char *content, int *acquired)
|
||||
{
|
||||
char path[512], cmd[1024];
|
||||
char path[512];
|
||||
*acquired = 0;
|
||||
snprintf(path, sizeof path, "%s/%s", dir, rel);
|
||||
/* mkdir -p the parent of `path` */
|
||||
char parent[512];
|
||||
snprintf(parent, sizeof parent, "%s", path);
|
||||
char *slash = strrchr(parent, '/');
|
||||
if (slash) {
|
||||
*slash = '\0';
|
||||
snprintf(cmd, sizeof cmd, "mkdir -p '%s'", parent);
|
||||
if (runwait(cmd) != 0) return -1;
|
||||
}
|
||||
FILE *f = fopen(path, "wb");
|
||||
if (!f) return -1;
|
||||
fputs(content, f);
|
||||
fclose(f);
|
||||
return 0;
|
||||
*acquired = 1;
|
||||
int rc = fputs(content, f) == EOF ? -1 : 0;
|
||||
if (fclose(f) != 0) rc = -1;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* run_build — lay out the row's package tree + root under a temp dir,
|
||||
* build+run the root via `driver`; return the binary's exit code, or -1
|
||||
* on a build failure. */
|
||||
static int
|
||||
run_build(const char *driver, const struct row *r, int i)
|
||||
run_build(const char *driver, const struct row *r, int i, int *cleanup_failed)
|
||||
{
|
||||
char dir[64], cmd[2048];
|
||||
char dir[64], path[512], cmd[2048];
|
||||
int brc = -1, got = -2, cleanfail = 0;
|
||||
int aaowned = 0, bbowned = 0, topccowned = 0, deepccowned = 0;
|
||||
int fileowned[4] = { 0, 0, 0, 0 }, mainowned = 0, build_started = 0;
|
||||
*cleanup_failed = 0;
|
||||
snprintf(dir, sizeof dir, "/tmp/m1mangle_%d_%d", getpid(), i);
|
||||
snprintf(cmd, sizeof cmd, "rm -rf '%s' && mkdir -p '%s'", dir, dir);
|
||||
if (runwait(cmd) != 0) return -2;
|
||||
if (mkdir(dir, 0755) != 0) return -2;
|
||||
if (i == 3) {
|
||||
snprintf(path, sizeof path, "%s/cc", dir);
|
||||
if (mkdir(path, 0755) != 0) goto cleanup;
|
||||
topccowned = 1;
|
||||
} else {
|
||||
snprintf(path, sizeof path, "%s/aa", dir);
|
||||
if (mkdir(path, 0755) != 0) goto cleanup;
|
||||
aaowned = 1;
|
||||
snprintf(path, sizeof path, "%s/aa/bb", dir);
|
||||
if (mkdir(path, 0755) != 0) goto cleanup;
|
||||
bbowned = 1;
|
||||
if (i == 4) {
|
||||
snprintf(path, sizeof path, "%s/aa/bb/cc", dir);
|
||||
if (mkdir(path, 0755) != 0) goto cleanup;
|
||||
deepccowned = 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (int k = 0; r->files[k].path; k++)
|
||||
if (write_file(dir, r->files[k].path, r->files[k].content) != 0)
|
||||
return -2;
|
||||
if (write_file(dir, "main.ww", r->root) != 0) return -2;
|
||||
if (write_file(dir, r->files[k].path, r->files[k].content,
|
||||
&fileowned[k]) != 0)
|
||||
goto cleanup;
|
||||
if (write_file(dir, "main.ww", r->root, &mainowned) != 0) goto cleanup;
|
||||
|
||||
/* #94 sep layout: cd into the build dir so the source-dir-first search
|
||||
* path finds the sibling package tree (mirrors Hare's CWD ==
|
||||
* module-dir); --sep emits per-package units to main.sepwork/ and links
|
||||
* the runnable binary at main. Pin WW_PKGCACHE under the temp dir so
|
||||
* out/.pkgcache is untouched. #99 (imported-pkg `fn main` mangle under
|
||||
* module-dir); emits per-package units to main.sepwork/ and links
|
||||
* the runnable binary at main. #99 (imported-pkg `fn main` mangle under
|
||||
* sep) is what makes the imported_main row link here. */
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"cd '%s' && WW_PKGCACHE='%s/pkgc' %s build --sep -o main main.ww "
|
||||
"2>/dev/null", dir, dir, driver);
|
||||
int brc = runwait(cmd);
|
||||
"cd '%s' && %s build -o main main.ww "
|
||||
"2>/dev/null", dir, driver);
|
||||
build_started = 1;
|
||||
brc = runwait(cmd);
|
||||
|
||||
int got = -1;
|
||||
got = -1;
|
||||
if (brc == 0) {
|
||||
char outbin[128];
|
||||
snprintf(outbin, sizeof outbin, "%s/main", dir);
|
||||
got = runwait(outbin);
|
||||
}
|
||||
|
||||
snprintf(cmd, sizeof cmd, "rm -rf '%s'", dir);
|
||||
runwait(cmd);
|
||||
cleanup:
|
||||
if (build_started) {
|
||||
snprintf(path, sizeof path, "%s/main.sepwork", dir);
|
||||
snprintf(cmd, sizeof cmd, "rm -rf '%s'", path);
|
||||
if (runwait(cmd) != 0) cleanfail = 1;
|
||||
snprintf(path, sizeof path, "%s/main", dir);
|
||||
if (unlink(path) != 0 && access(path, F_OK) == 0) cleanfail = 1;
|
||||
}
|
||||
if (mainowned) {
|
||||
snprintf(path, sizeof path, "%s/main.ww", dir);
|
||||
if (unlink(path) != 0 && access(path, F_OK) == 0) cleanfail = 1;
|
||||
}
|
||||
for (int k = 0; r->files[k].path; k++) {
|
||||
if (!fileowned[k]) continue;
|
||||
snprintf(path, sizeof path, "%s/%s", dir, r->files[k].path);
|
||||
if (unlink(path) != 0 && access(path, F_OK) == 0) cleanfail = 1;
|
||||
}
|
||||
if (deepccowned) {
|
||||
snprintf(path, sizeof path, "%s/aa/bb/cc", dir);
|
||||
if (rmdir(path) != 0 && access(path, F_OK) == 0) cleanfail = 1;
|
||||
}
|
||||
if (topccowned) {
|
||||
snprintf(path, sizeof path, "%s/cc", dir);
|
||||
if (rmdir(path) != 0 && access(path, F_OK) == 0) cleanfail = 1;
|
||||
}
|
||||
if (bbowned) {
|
||||
snprintf(path, sizeof path, "%s/aa/bb", dir);
|
||||
if (rmdir(path) != 0 && access(path, F_OK) == 0) cleanfail = 1;
|
||||
}
|
||||
if (aaowned) {
|
||||
snprintf(path, sizeof path, "%s/aa", dir);
|
||||
if (rmdir(path) != 0 && access(path, F_OK) == 0) cleanfail = 1;
|
||||
}
|
||||
if (rmdir(dir) != 0) cleanfail = 1;
|
||||
*cleanup_failed = cleanfail;
|
||||
return brc == 0 ? got : -1;
|
||||
}
|
||||
|
||||
@@ -197,13 +244,20 @@ main(void)
|
||||
}
|
||||
for (int i = 0; i < n; i++) {
|
||||
total++;
|
||||
int got = run_build(drivers[d].drv, &rows[i], i);
|
||||
int cleanfail = 0;
|
||||
int got = run_build(drivers[d].drv, &rows[i], i,
|
||||
&cleanfail);
|
||||
if (got != rows[i].want_exit) {
|
||||
fprintf(stderr, "m1mangle_run[%s][%s]: exit=%d "
|
||||
"want=%d\n", drivers[d].name, rows[i].label,
|
||||
got, rows[i].want_exit);
|
||||
fail++;
|
||||
}
|
||||
if (cleanfail) {
|
||||
fprintf(stderr, "m1mangle_run[%s][%s]: temporary cleanup "
|
||||
"failed\n", drivers[d].name, rows[i].label);
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user