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:
@@ -27,6 +27,7 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -132,18 +133,27 @@ static const struct row rows[] = {
|
||||
static int
|
||||
run_build(const char *driver, const char *libdir, const struct row *r, int i)
|
||||
{
|
||||
char src[128], tmpdir[64], outbin[128], cmd[1024], rmcmd[128];
|
||||
char src[128], tmpdir[64], outbin[128], work[160], cmd[1024];
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/ffivar_%d_%d", getpid(), i);
|
||||
mkdir(tmpdir, 0755);
|
||||
if (mkdir(tmpdir, 0755) != 0) {
|
||||
perror(tmpdir);
|
||||
return -2;
|
||||
}
|
||||
snprintf(src, sizeof src, "%s/ffivar_%d_%d.ww", tmpdir, getpid(), i);
|
||||
snprintf(outbin, sizeof outbin, "%s/out", tmpdir);
|
||||
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
|
||||
int result = -2, cleanfail = 0;
|
||||
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (!f) { runwait(rmcmd); return -2; }
|
||||
fputs(r->src, f);
|
||||
fclose(f);
|
||||
if (!f) {
|
||||
perror(src);
|
||||
goto cleanup;
|
||||
}
|
||||
int werr = fputs(r->src, f) == EOF;
|
||||
if (fclose(f) != 0) werr = 1;
|
||||
if (werr) {
|
||||
perror(src);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* explicit -o so both the binary and out.sepwork land INSIDE tmpdir */
|
||||
snprintf(cmd, sizeof cmd,
|
||||
@@ -153,9 +163,32 @@ run_build(const char *driver, const char *libdir, const struct row *r, int i)
|
||||
|
||||
int got = -1;
|
||||
if (brc == 0) got = runwait(outbin);
|
||||
result = brc == 0 ? got : -1;
|
||||
|
||||
runwait(rmcmd);
|
||||
return brc == 0 ? got : -1;
|
||||
cleanup:
|
||||
if (unlink(src) != 0 && errno != ENOENT) {
|
||||
perror(src);
|
||||
cleanfail = 1;
|
||||
}
|
||||
if (unlink(outbin) != 0 && errno != ENOENT) {
|
||||
perror(outbin);
|
||||
cleanfail = 1;
|
||||
}
|
||||
snprintf(work, sizeof work, "%s.sepwork", outbin);
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s", work);
|
||||
if (runwait(cmd) != 0) {
|
||||
fprintf(stderr, "ffivariadic[%s]: cleanup failed: %s\n", r->label, work);
|
||||
cleanfail = 1;
|
||||
}
|
||||
if (rmdir(tmpdir) != 0) {
|
||||
perror(tmpdir);
|
||||
cleanfail = 1;
|
||||
}
|
||||
if (cleanfail) {
|
||||
fprintf(stderr, "ffivariadic[%s]: temporary cleanup failed\n", r->label);
|
||||
if (result == r->want_exit) result = -2;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
Reference in New Issue
Block a user