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:
@@ -29,6 +29,7 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -74,10 +75,10 @@ build_run(const char *driver, const char *src, const char *libdir,
|
||||
const char *tmpdir, char *outbin, size_t obsz)
|
||||
{
|
||||
char cmd[1024];
|
||||
snprintf(cmd, sizeof cmd, "cd %s && %s build -o %s/main %s -L %s -l c "
|
||||
"2>/dev/null", tmpdir, driver, tmpdir, src, libdir);
|
||||
if (runwait(cmd) != 0) return -1;
|
||||
snprintf(outbin, obsz, "%s/main", tmpdir);
|
||||
snprintf(cmd, sizeof cmd, "cd %s && %s build -o %s %s -L %s -l c "
|
||||
"2>/dev/null", tmpdir, driver, outbin, src, libdir);
|
||||
if (runwait(cmd) != 0) return -1;
|
||||
return runwait(outbin);
|
||||
}
|
||||
|
||||
@@ -111,12 +112,19 @@ main(void)
|
||||
snprintf(cdrv, sizeof cdrv, "%s/ww", bin);
|
||||
snprintf(wdrv, sizeof wdrv, "%s/ww_ww", bin);
|
||||
int have_ww = (access(wdrv, X_OK) == 0);
|
||||
char td[] = "/tmp/dynent_XXXXXX";
|
||||
if (mkdtemp(td) == NULL) {
|
||||
perror("dynentry mkdtemp");
|
||||
return 1;
|
||||
}
|
||||
int fail = 0, total = 0;
|
||||
|
||||
/* ---- big: ~160 gated dead PLT calls, return 42 ---- */
|
||||
char bigsrc[80];
|
||||
snprintf(bigsrc, sizeof bigsrc, "/tmp/dynent_big_%d.ww", getpid());
|
||||
char bigsrc[1024], smallsrc[1024];
|
||||
snprintf(bigsrc, sizeof bigsrc, "%s/big.ww", td);
|
||||
snprintf(smallsrc, sizeof smallsrc, "%s/small.ww", td);
|
||||
FILE *f = fopen(bigsrc, "wb");
|
||||
if (!f) return 1;
|
||||
if (!f) { perror(bigsrc); fail++; goto out; }
|
||||
fputs("package main;\n", f);
|
||||
for (int i = 0; i < ns; i++)
|
||||
fprintf(f, "@symbol(\"%s\") fn s%03d() void;\n", syms[i], i);
|
||||
@@ -124,31 +132,58 @@ main(void)
|
||||
for (int i = 0; i < ns; i++)
|
||||
fprintf(f, "\tif (g != 0) { s%03d(); };\n", i);
|
||||
fputs("\treturn 42;\n};\n", f);
|
||||
fclose(f);
|
||||
int writebad = ferror(f);
|
||||
if (fclose(f) != 0) writebad = 1;
|
||||
if (writebad) {
|
||||
perror(bigsrc);
|
||||
fail++;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* ---- small: 1 dyn sym, headers fit the page ---- */
|
||||
char smallsrc[80];
|
||||
snprintf(smallsrc, sizeof smallsrc, "/tmp/dynent_small_%d.ww", getpid());
|
||||
f = fopen(smallsrc, "wb");
|
||||
if (!f) return 1;
|
||||
if (!f) {
|
||||
perror(smallsrc);
|
||||
fail++;
|
||||
goto out;
|
||||
}
|
||||
fputs("package main;\n"
|
||||
"@symbol(\"getpid\") fn cgetpid() i32;\n"
|
||||
"let g: i32 = 0;\n"
|
||||
"export fn main() i32 = { if (g != 0) { cgetpid(); }; return 42; };\n",
|
||||
f);
|
||||
fclose(f);
|
||||
writebad = ferror(f);
|
||||
if (fclose(f) != 0) writebad = 1;
|
||||
if (writebad) {
|
||||
perror(smallsrc);
|
||||
fail++;
|
||||
goto out;
|
||||
}
|
||||
|
||||
struct { const char *label; const char *src; } cases[] = {
|
||||
{ "big", bigsrc }, { "small", smallsrc },
|
||||
};
|
||||
|
||||
int fail = 0, total = 0;
|
||||
for (int ci = 0; ci < 2; ci++) {
|
||||
total++;
|
||||
char ctd[80], wtd[80], cob[160], wob[160];
|
||||
snprintf(ctd, sizeof ctd, "/tmp/dynent_c_%d_%d", getpid(), ci);
|
||||
snprintf(wtd, sizeof wtd, "/tmp/dynent_w_%d_%d", getpid(), ci);
|
||||
mkdir(ctd, 0755); mkdir(wtd, 0755);
|
||||
char ctd[1024], wtd[1024], cob[1100], wob[1100];
|
||||
snprintf(ctd, sizeof ctd, "%s/c_%d", td, ci);
|
||||
snprintf(wtd, sizeof wtd, "%s/w_%d", td, ci);
|
||||
if (mkdir(ctd, 0755) != 0) {
|
||||
perror(ctd);
|
||||
fail++;
|
||||
continue;
|
||||
}
|
||||
if (mkdir(wtd, 0755) != 0) {
|
||||
perror(wtd);
|
||||
if (rmdir(ctd) != 0)
|
||||
fprintf(stderr, "dynentry[%s]: setup cleanup failed\n",
|
||||
cases[ci].label);
|
||||
fail++;
|
||||
continue;
|
||||
}
|
||||
snprintf(cob, sizeof cob, "%s/main", ctd);
|
||||
snprintf(wob, sizeof wob, "%s/main", wtd);
|
||||
|
||||
int crc = build_run(cdrv, cases[ci].src, libdir, ctd, cob, sizeof cob);
|
||||
if (crc != 42) {
|
||||
@@ -170,13 +205,38 @@ main(void)
|
||||
cases[ci].label);
|
||||
fail++;
|
||||
}
|
||||
unlink(wob);
|
||||
}
|
||||
unlink(cob);
|
||||
rmdir(ctd); rmdir(wtd);
|
||||
|
||||
char clean[2400];
|
||||
int cleanfail = 0;
|
||||
if (unlink(cob) != 0 && errno != ENOENT) cleanfail = 1;
|
||||
if (unlink(wob) != 0 && errno != ENOENT) cleanfail = 1;
|
||||
snprintf(clean, sizeof clean, "rm -rf %s/main.sepwork", ctd);
|
||||
if (runwait(clean) != 0) cleanfail = 1;
|
||||
snprintf(clean, sizeof clean, "rm -rf %s/main.sepwork", wtd);
|
||||
if (runwait(clean) != 0) cleanfail = 1;
|
||||
if (rmdir(ctd) != 0) cleanfail = 1;
|
||||
if (rmdir(wtd) != 0) cleanfail = 1;
|
||||
if (cleanfail) {
|
||||
fprintf(stderr, "dynentry[%s]: temporary cleanup failed\n",
|
||||
cases[ci].label);
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
|
||||
unlink(bigsrc); unlink(smallsrc);
|
||||
out:
|
||||
if (unlink(bigsrc) != 0 && errno != ENOENT) {
|
||||
perror(bigsrc);
|
||||
fail++;
|
||||
}
|
||||
if (unlink(smallsrc) != 0 && errno != ENOENT) {
|
||||
perror(smallsrc);
|
||||
fail++;
|
||||
}
|
||||
if (rmdir(td) != 0) {
|
||||
perror(td);
|
||||
fail++;
|
||||
}
|
||||
|
||||
if (fail) {
|
||||
fprintf(stderr, "dynentry_run: %d/%d check(s) failed\n", fail, total);
|
||||
|
||||
Reference in New Issue
Block a user