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:
2026-08-07 23:02:47 +09:00
parent b2899dd8d3
commit a95a7a316b
132 changed files with 7573 additions and 6172 deletions

View File

@@ -27,6 +27,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/wait.h>
@@ -142,32 +143,31 @@ main(void)
int n = 0, fail = 0;
for (int i = 0; rows[i].src; i++, n++) {
char tmpdir[64];
snprintf(tmpdir, sizeof tmpdir, "/tmp/wwsort_%d_%d", getpid(), i);
mkdir(tmpdir, 0755);
char tmpdir[64] = "/tmp/wwsort_XXXXXX";
if (mkdtemp(tmpdir) == NULL) {
perror("sort: mkdtemp");
fail++;
continue;
}
char rmcmd[128];
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
char src[128];
char src[128], outbin[128], sepwork[160], rmcmd[192];
snprintf(src, sizeof src, "%s/wwsort_%d_%d.ww", tmpdir, getpid(), i);
snprintf(outbin, sizeof outbin, "%s/out", tmpdir);
snprintf(sepwork, sizeof sepwork, "%s.sepwork", outbin);
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", sepwork);
FILE *f = fopen(src, "wb");
if (f == NULL) { fail++; runwait(rmcmd); continue; }
if (f == NULL) { fail++; goto cleanup; }
fputs(rows[i].src, f);
fclose(f);
char outbin[128];
snprintf(outbin, sizeof outbin, "%s/out", tmpdir);
char cmd[2048];
snprintf(cmd, sizeof cmd, "%s/ww build -I %s/lib -o %s %s",
bin, cwd, outbin, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "row[%s]: build failed\n", rows[i].label);
fail++;
runwait(rmcmd);
continue;
goto cleanup;
}
int got = runwait(outbin);
@@ -176,7 +176,19 @@ main(void)
rows[i].label, got, rows[i].want_exit);
fail++;
}
runwait(rmcmd);
cleanup: {
int cleanbad = 0;
if (unlink(src) != 0 && errno != ENOENT) cleanbad = 1;
if (unlink(outbin) != 0 && errno != ENOENT) cleanbad = 1;
if (runwait(rmcmd) != 0) cleanbad = 1;
if (rmdir(tmpdir) != 0) cleanbad = 1;
if (cleanbad) {
fprintf(stderr, "row[%s]: temporary cleanup failed\n",
rows[i].label);
fail++;
}
}
}
if (fail) {
fprintf(stderr, "%d/%d sort tests failed\n", fail, n);