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

@@ -32,6 +32,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/wait.h>
@@ -108,43 +109,48 @@ static const struct row ROWS[] = {
/* build+run one row through `driver`; return exit code or -1. */
static int
run_driver(const char *driver, const char *src, int idx)
run_driver(const char *driver, const char *src, int idx, int want)
{
char tmpdir[64], srcf[128], outbin[160], rmcmd[192], cmd[2400];
char tmpdir[64], srcf[128], outbin[160], scratch[192], rmcmd[224], cmd[2400];
int result = -1, cleanfail = 0;
snprintf(tmpdir, sizeof tmpdir, "/tmp/gpfs_%d_%d_d", getpid(), idx);
mkdir(tmpdir, 0755);
if (mkdir(tmpdir, 0755) != 0) return -1;
snprintf(srcf, sizeof srcf, "%s/t.ww", tmpdir);
snprintf(outbin, sizeof outbin, "%s/t", tmpdir);
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
snprintf(scratch, sizeof scratch, "%s.sepwork", outbin);
FILE *f = fopen(srcf, "wb");
if (!f) { runwait(rmcmd); return -1; }
fputs(src, f);
fclose(f);
if (!f) goto cleanup;
int writefail = fputs(src, f) == EOF;
if (fclose(f) != 0) writefail = 1;
if (writefail) goto cleanup;
snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null",
driver, outbin, srcf);
if (runwait(cmd) != 0) { runwait(rmcmd); return -1; }
int got = runwait(outbin);
runwait(rmcmd);
return got;
if (runwait(cmd) != 0) goto cleanup;
result = runwait(outbin);
cleanup:
snprintf(rmcmd, sizeof rmcmd, "rm -rf -- %s", scratch);
if (runwait(rmcmd) != 0) cleanfail = 1;
if (unlink(srcf) != 0 && errno != ENOENT) cleanfail = 1;
if (unlink(outbin) != 0 && errno != ENOENT) cleanfail = 1;
if (rmdir(tmpdir) != 0) cleanfail = 1;
if (cleanfail) {
fprintf(stderr, "globptr_field_store[%d]: temporary cleanup failed\n", idx);
if (result == want) return -1;
}
return result;
}
/* emit .s for `tool` (w6c / w6c_ww) into asmf; 0 ok, -1 on compile fail. */
/* Emit .s for `tool`; the caller owns srcf and asmf. */
static int
emit_asm(const char *bin, const char *tool, const char *src, int idx,
emit_asm(const char *bin, const char *tool, const char *srcf,
const char *asmf)
{
char srcf[80], cmd[2400];
snprintf(srcf, sizeof srcf, "/tmp/gpfs_asm_%d_%d.ww", getpid(), idx);
FILE *f = fopen(srcf, "wb");
if (!f) return -1;
fputs(src, f);
fclose(f);
char cmd[2400];
snprintf(cmd, sizeof cmd, "%s/%s -o %s %s 2>/dev/null",
bin, tool, asmf, srcf);
int rc = runwait(cmd);
unlink(srcf);
return rc == 0 ? 0 : -1;
}
@@ -184,7 +190,7 @@ main(void)
const struct row *r = &ROWS[i];
total++;
int gc = run_driver(cdrv, r->src, i);
int gc = run_driver(cdrv, r->src, i, r->want);
if (gc != r->want) {
fprintf(stderr, "globptr_field_store[%s,cstage]: run=%d want=%d\n",
r->name, gc, r->want);
@@ -192,7 +198,7 @@ main(void)
}
if (have_ww) {
total++;
int gw = run_driver(wdrv, r->src, i);
int gw = run_driver(wdrv, r->src, i, r->want);
if (gw != r->want) {
fprintf(stderr, "globptr_field_store[%s,wwstage]: run=%d want=%d\n",
r->name, gw, r->want);
@@ -202,18 +208,43 @@ main(void)
/* byte-id: w6c .s == w6c_ww .s */
if (have_ww) {
char csf[80], wwf[80];
snprintf(csf, sizeof csf, "/tmp/gpfs_cs_%d_%d.s", getpid(), i);
snprintf(wwf, sizeof wwf, "/tmp/gpfs_ww_%d_%d.s", getpid(), i);
char td[80], srcf[96], csf[96], wwf[96];
int ec = -1, ew = -1, same = 0, setupfail = 0, cleanfail = 0;
snprintf(td, sizeof td, "/tmp/gpfs_asm_%d_%d", getpid(), i);
snprintf(srcf, sizeof srcf, "%s/t.ww", td);
snprintf(csf, sizeof csf, "%s/c.s", td);
snprintf(wwf, sizeof wwf, "%s/w.s", td);
total++;
int ec = emit_asm(bin, "w6c", r->src, i, csf);
int ew = emit_asm(bin, "w6c_ww", r->src, i, wwf);
if (ec != 0 || ew != 0 || !files_identical(csf, wwf)) {
if (mkdir(td, 0755) == 0) {
FILE *f = fopen(srcf, "wb");
if (f) {
int writefail = fputs(r->src, f) == EOF;
if (fclose(f) != 0) writefail = 1;
if (!writefail) {
ec = emit_asm(bin, "w6c", srcf, csf);
ew = emit_asm(bin, "w6c_ww", srcf, wwf);
same = ec == 0 && ew == 0
&& files_identical(csf, wwf);
} else setupfail = 1;
} else setupfail = 1;
if (unlink(srcf) != 0 && errno != ENOENT) cleanfail = 1;
if (unlink(csf) != 0 && errno != ENOENT) cleanfail = 1;
if (unlink(wwf) != 0 && errno != ENOENT) cleanfail = 1;
if (rmdir(td) != 0) cleanfail = 1;
} else setupfail = 1;
if (setupfail)
fprintf(stderr, "globptr_field_store[%s]: temporary setup failed\n",
r->name);
if (!same) {
fprintf(stderr, "globptr_field_store[%s]: cs/ww .s NOT "
"byte-identical (ec=%d ew=%d)\n", r->name, ec, ew);
fail++;
}
unlink(csf); unlink(wwf);
if (cleanfail) {
fprintf(stderr, "globptr_field_store[%s]: temporary cleanup failed\n",
r->name);
if (same) fail++;
}
}
}