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

@@ -5,6 +5,8 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/wait.h>
@@ -1802,32 +1804,82 @@ main(void)
for (int i = 0; rows[i].src; i++, n++) {
char tmpdir[64];
snprintf(tmpdir, sizeof tmpdir, "/tmp/wwe2e_%d_d_%d", getpid(), i);
mkdir(tmpdir, 0755);
if (mkdir(tmpdir, 0755) != 0) {
fprintf(stderr, "row %d: mkdir %s: %s\n",
i, tmpdir, strerror(errno));
fail++;
continue;
}
/* #8: source + binary + .sepwork scratch all live INSIDE tmpdir
* (`-o` pins the binary, scratch lands next to the in-tmpdir
* source) so the recursive cleanup removes everything. */
char src[128], outbin[128], rmcmd[160];
/* Source, output, and the caller-owned output `.sepwork` all live
* inside this invocation-owned directory. */
char src[128], outbin[128], sepdir[160], rmcmd[192];
snprintf(src, sizeof src, "%s/wwe2e_%d_%d.ww", tmpdir, getpid(), i);
snprintf(outbin, sizeof outbin, "%s/wwe2e_%d_%d", tmpdir, getpid(), i);
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
snprintf(sepdir, sizeof sepdir, "%s.sepwork", outbin);
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", sepdir);
int row_failed = 0;
char cmd[1024];
int got;
FILE *f = fopen(src, "wb");
if (!f) {
fprintf(stderr, "row %d: fopen %s: %s\n",
i, src, strerror(errno));
row_failed = 1;
goto cleanup;
}
wwtest_fputs(rows[i].src, f);
fclose(f);
if (ferror(f)) {
fprintf(stderr, "row %d: write %s failed\n", i, src);
row_failed = 1;
}
if (fclose(f) != 0) {
fprintf(stderr, "row %d: close %s: %s\n",
i, src, strerror(errno));
row_failed = 1;
}
if (row_failed) goto cleanup;
char cmd[1024];
snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s",
bin, outbin, src);
if (runwait(cmd) != 0) { runwait(rmcmd); fail++; continue; }
if (runwait(cmd) != 0) {
row_failed = 1;
goto cleanup;
}
int got = runwait(outbin);
got = runwait(outbin);
if (got != rows[i].want_exit) {
fprintf(stderr, "row %d: exit %d, want %d\n src: %s\n",
i, got, rows[i].want_exit, rows[i].src);
fail++;
row_failed = 1;
}
runwait(rmcmd);
cleanup:
{
int cleanup_failed = 0;
if (runwait(rmcmd) != 0) {
fprintf(stderr, "row %d: remove %s failed\n", i, sepdir);
cleanup_failed = 1;
}
if (unlink(src) != 0 && errno != ENOENT) {
fprintf(stderr, "row %d: unlink %s: %s\n",
i, src, strerror(errno));
cleanup_failed = 1;
}
if (unlink(outbin) != 0 && errno != ENOENT) {
fprintf(stderr, "row %d: unlink %s: %s\n",
i, outbin, strerror(errno));
cleanup_failed = 1;
}
if (rmdir(tmpdir) != 0) {
fprintf(stderr, "row %d: rmdir %s: %s\n",
i, tmpdir, strerror(errno));
cleanup_failed = 1;
}
if (!row_failed && cleanup_failed) row_failed = 1;
}
if (row_failed) fail++;
}
if (fail) { fprintf(stderr, "%d/%d e2e tests failed\n", fail, n); return 1; }
printf("e2e: %d/%d ok\n", n, n);