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:
@@ -23,6 +23,10 @@
|
||||
* decodedsize_unalign_abort | decodedsize(5) | run aborts (rc!=0)
|
||||
* decodedsize_align_ok | decodedsize(8) == 6 | run rc == 0
|
||||
*
|
||||
* The five normal-return controls now live in r989_libprecond_* fixtures;
|
||||
* this wrapper retains the three signal/abort expectations unavailable in
|
||||
* the current fixture grammar.
|
||||
*
|
||||
* The abort rows BUILD clean and abort at RUNTIME (unlike a reject row,
|
||||
* which fails the build) — this harness builds then runs each fixture and
|
||||
* checks the run exit, not the build exit. Rows run on cstage `ww` and,
|
||||
@@ -31,6 +35,7 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -63,35 +68,16 @@ struct row {
|
||||
"export fn main() int = {\n"
|
||||
|
||||
static const struct row rows[] = {
|
||||
/* Success boundaries moved to r989_libprecond_* fixtures. */
|
||||
{ "u32n_zero_abort",
|
||||
RNG_HDR "\tlet x: u32 = random.u32n(&g, 0u32);\n\treturn 0;\n};\n",
|
||||
1, 0 },
|
||||
{ "u32n_valid_ok",
|
||||
RNG_HDR "\tlet x: u32 = random.u32n(&g, 10u32);\n"
|
||||
"\tif (x >= 10u32) { return 1; };\n\treturn 0;\n};\n",
|
||||
0, 0 },
|
||||
{ "u32n_one_ok", /* boundary: n=1 is the smallest VALID arg */
|
||||
RNG_HDR "\tlet x: u32 = random.u32n(&g, 1u32);\n"
|
||||
"\tif (x >= 1u32) { return 1; };\n\treturn 0;\n};\n",
|
||||
0, 0 },
|
||||
{ "u64n_zero_abort",
|
||||
RNG_HDR "\tlet x: u64 = random.u64n(&g, 0u64);\n\treturn 0;\n};\n",
|
||||
1, 0 },
|
||||
{ "u64n_valid_ok",
|
||||
RNG_HDR "\tlet x: u64 = random.u64n(&g, 10u64);\n"
|
||||
"\tif (x >= 10u64) { return 1; };\n\treturn 0;\n};\n",
|
||||
0, 0 },
|
||||
{ "u64n_one_ok", /* boundary: n=1 is the smallest VALID arg */
|
||||
RNG_HDR "\tlet x: u64 = random.u64n(&g, 1u64);\n"
|
||||
"\tif (x >= 1u64) { return 1; };\n\treturn 0;\n};\n",
|
||||
0, 0 },
|
||||
{ "decodedsize_unalign_abort",
|
||||
B64_HDR "\tlet c: i32 = base64.decodedsize(5i32);\n\treturn 0;\n};\n",
|
||||
1, 0 },
|
||||
{ "decodedsize_align_ok",
|
||||
B64_HDR "\tlet c: i32 = base64.decodedsize(8i32);\n"
|
||||
"\tif (c != 6i32) { return 1; };\n\treturn 0;\n};\n",
|
||||
0, 0 },
|
||||
};
|
||||
|
||||
/* Build `r->src` with `driver`, then run it. Returns the RUN exit code, or
|
||||
@@ -99,27 +85,46 @@ static const struct row rows[] = {
|
||||
* every row here must build clean — only the RUN may abort). `incs` is the
|
||||
* colon-free `-I a -I b ...` include flag string already composed by main. */
|
||||
static int
|
||||
build_and_run(const char *driver, const char *incs, const struct row *r, int i)
|
||||
build_and_run(const char *driver, const char *incs, const struct row *r, int i,
|
||||
int *cleanup_failed)
|
||||
{
|
||||
char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[2048];
|
||||
char tmpdir[64], src[128], outbin[128], sepwork[160], cmd[2048];
|
||||
int brc = -1, got = -2, setupfail = 1, cleanfail = 0;
|
||||
*cleanup_failed = 0;
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/lpc_%d_d_%d", getpid(), i);
|
||||
mkdir(tmpdir, 0755);
|
||||
if (mkdir(tmpdir, 0755) != 0) return -2;
|
||||
snprintf(src, sizeof src, "%s/lpc_%d_%d.ww", tmpdir, getpid(), i);
|
||||
snprintf(outbin, sizeof outbin, "%s/lpc_%d_%d", tmpdir, getpid(), i);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
|
||||
snprintf(sepwork, sizeof sepwork, "%s.sepwork", outbin);
|
||||
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (!f) { runwait(rmcmd); return -2; }
|
||||
if (!f) goto cleanup;
|
||||
fputs(r->src, f);
|
||||
fclose(f);
|
||||
if (fclose(f) != 0) goto cleanup;
|
||||
|
||||
snprintf(cmd, sizeof cmd, "%s build -o %s %s %s 2>/dev/null",
|
||||
driver, outbin, incs, src);
|
||||
int brc = runwait(cmd);
|
||||
brc = runwait(cmd);
|
||||
setupfail = 0;
|
||||
|
||||
int got = (brc == 0) ? runwait(outbin) : -1;
|
||||
if (brc == 0) {
|
||||
const char *base = strrchr(outbin, '/');
|
||||
base = base ? base + 1 : outbin;
|
||||
snprintf(cmd, sizeof cmd, "cd %s && ulimit -c 0 && ./%s", tmpdir,
|
||||
base);
|
||||
got = runwait(cmd);
|
||||
} else {
|
||||
got = -1;
|
||||
}
|
||||
|
||||
runwait(rmcmd);
|
||||
cleanup:
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s", sepwork);
|
||||
if (runwait(cmd) != 0) cleanfail = 1;
|
||||
if (unlink(outbin) != 0 && access(outbin, F_OK) == 0) cleanfail = 1;
|
||||
if (unlink(src) != 0 && access(src, F_OK) == 0) cleanfail = 1;
|
||||
if (rmdir(tmpdir) != 0) cleanfail = 1;
|
||||
*cleanup_failed = cleanfail;
|
||||
if (setupfail) return -2;
|
||||
return brc == 0 ? got : -1;
|
||||
}
|
||||
|
||||
@@ -166,8 +171,16 @@ main(void)
|
||||
}
|
||||
for (int i = 0; i < n; i++) {
|
||||
total++;
|
||||
int got = build_and_run(drivers[d].drv, incs, &rows[i], i);
|
||||
if (rows[i].want_abort) {
|
||||
int cleanfail = 0;
|
||||
int got = build_and_run(drivers[d].drv, incs, &rows[i], i,
|
||||
&cleanfail);
|
||||
if (got == -2) {
|
||||
fprintf(stderr, "libprecond_abort[%s][%s]: setup failed\n",
|
||||
drivers[d].name,
|
||||
rows[i].label);
|
||||
fail++;
|
||||
}
|
||||
if (got != -2 && rows[i].want_abort) {
|
||||
if (got == 0 || got < 0) {
|
||||
fprintf(stderr, "libprecond_abort[%s][%s]: run rc=%d, "
|
||||
"expected a loud abort (rc!=0)%s\n",
|
||||
@@ -175,7 +188,7 @@ main(void)
|
||||
got < 0 ? " [build failed]" : "");
|
||||
fail++;
|
||||
}
|
||||
} else {
|
||||
} else if (got != -2) {
|
||||
if (got != rows[i].want_exit) {
|
||||
fprintf(stderr, "libprecond_abort[%s][%s]: run rc=%d "
|
||||
"want=%d\n", drivers[d].name, rows[i].label, got,
|
||||
@@ -183,6 +196,11 @@ main(void)
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
if (cleanfail) {
|
||||
fprintf(stderr, "libprecond_abort[%s][%s]: temporary "
|
||||
"cleanup failed\n", drivers[d].name, rows[i].label);
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user