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

@@ -134,6 +134,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/wait.h>
@@ -1326,24 +1327,31 @@ errlog_has(const char *path, const char *needle)
static int
run_driver(const char *driver, const struct row *r, int i)
{
char tmpdir[64], src[128], outbin[128], errlog[128], rmcmd[160];
char tmpdir[] = "/tmp/plad_XXXXXX";
char src[128], outbin[128], errlog[128], scratch[160], rmcmd[192];
char cmd[1200];
snprintf(tmpdir, sizeof tmpdir, "/tmp/plad_%d_d_%d", getpid(), i);
mkdir(tmpdir, 0755);
int result = -2;
if (mkdtemp(tmpdir) == NULL) {
fprintf(stderr, "row[%s]: workspace acquisition failed\n", r->label);
return result;
}
snprintf(src, sizeof src, "%s/plad_%d_%d.ww", tmpdir, getpid(), i);
snprintf(outbin, sizeof outbin, "%s/plad_%d_%d", tmpdir, getpid(), i);
snprintf(errlog, sizeof errlog, "%s/err", tmpdir);
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
snprintf(scratch, sizeof scratch, "%s.sepwork", outbin);
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", scratch);
FILE *f = fopen(src, "wb");
if (!f) { runwait(rmcmd); return -1; }
if (!f) goto done;
fputs(r->src, f);
fclose(f);
int werr = ferror(f);
if (fclose(f) != 0) werr = 1;
if (werr) goto done;
snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>%s",
driver, outbin, src, errlog);
if (runwait(cmd) != 0) {
int rc = -1;
result = -1;
if (r->want != BUILD_FAIL) {
fprintf(stderr, "row[%s]: build via %s failed\n",
r->label, driver);
@@ -1352,16 +1360,29 @@ run_driver(const char *driver, const struct row *r, int i)
fprintf(stderr, "row[%s]: %s build failed without "
"expected diagnostic \"%s\"\n",
r->label, driver, r->expect_err);
rc = -3; /* failed, but for the wrong reason */
result = -3; /* failed, but for the wrong reason */
}
runwait(rmcmd);
return rc;
goto done;
}
int got = runwait(outbin);
result = runwait(outbin);
runwait(rmcmd);
return got;
done:
{
int cleanfail = 0;
if (runwait(rmcmd) != 0) cleanfail = 1;
if (unlink(errlog) != 0 && errno != ENOENT) cleanfail = 1;
if (unlink(outbin) != 0 && errno != ENOENT) cleanfail = 1;
if (unlink(src) != 0 && errno != ENOENT) cleanfail = 1;
if (rmdir(tmpdir) != 0) cleanfail = 1;
if (cleanfail) {
fprintf(stderr, "row[%s]: workspace cleanup failed\n", r->label);
int passed = r->want == BUILD_FAIL
? result == -1 : result == r->want;
if (passed) result = -2;
}
}
return result;
}
/* asm_byte_identical — generate .s via cstage's w6c and wwstage's
@@ -1371,33 +1392,37 @@ run_driver(const char *driver, const struct row *r, int i)
static int
asm_byte_identical(const char *bin, const struct row *r, int i)
{
char src[64], cs[64], ws[64], cmd[1024];
snprintf(src, sizeof src, "/tmp/plad_asm_%d_%d.ww", getpid(), i);
snprintf(cs, sizeof cs, "/tmp/plad_asm_%d_%d_c.s", getpid(), i);
snprintf(ws, sizeof ws, "/tmp/plad_asm_%d_%d_w.s", getpid(), i);
(void)i;
char dir[] = "/tmp/plad_asm_XXXXXX";
char src[128], cs[128], ws[128], cmd[1024];
int rc = -1;
if (mkdtemp(dir) == NULL) return -1;
snprintf(src, sizeof src, "%s/input.ww", dir);
snprintf(cs, sizeof cs, "%s/c.s", dir);
snprintf(ws, sizeof ws, "%s/w.s", dir);
FILE *f = fopen(src, "wb");
if (!f) return -1;
if (!f) goto done;
fputs(r->src, f);
fclose(f);
int werr = ferror(f);
if (fclose(f) != 0) werr = 1;
if (werr) goto done;
snprintf(cmd, sizeof cmd, "%s/w6c -o %s %s 2>/dev/null", bin, cs, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "row[%s]: w6c errored\n", r->label);
unlink(src);
return -1;
goto done;
}
snprintf(cmd, sizeof cmd, "%s/w6c_ww -o %s %s 2>/dev/null",
bin, ws, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "row[%s]: w6c_ww errored\n", r->label);
unlink(src); unlink(cs);
return -1;
goto done;
}
FILE *fc = fopen(cs, "rb");
FILE *fw = fopen(ws, "rb");
int rc = 0;
rc = 0;
if (!fc || !fw) {
rc = -1;
} else {
@@ -1413,7 +1438,20 @@ asm_byte_identical(const char *bin, const struct row *r, int i)
if (rc != 0)
fprintf(stderr, "row[%s]: cstage vs wwstage asm differs\n",
r->label);
unlink(src); unlink(cs); unlink(ws);
done:
{
int cleanfail = 0;
if (unlink(src) != 0 && errno != ENOENT) cleanfail = 1;
if (unlink(cs) != 0 && errno != ENOENT) cleanfail = 1;
if (unlink(ws) != 0 && errno != ENOENT) cleanfail = 1;
if (rmdir(dir) != 0) cleanfail = 1;
if (cleanfail) {
fprintf(stderr, "row[%s]: asm workspace cleanup failed\n",
r->label);
rc = -1;
}
}
return rc;
}