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:
@@ -50,6 +50,7 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -194,91 +195,116 @@ static const char *neg[] = {
|
||||
static int
|
||||
run_driver(const char *driver, const struct row *r, int i)
|
||||
{
|
||||
char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024];
|
||||
char tmpdir[64], src[128], outbin[128], scratch[160], rmcmd[192], cmd[1024];
|
||||
int result = -1, setupfail = 0, cleanfail = 0;
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/slg_%d_d_%d", getpid(), i);
|
||||
mkdir(tmpdir, 0755);
|
||||
if (mkdir(tmpdir, 0755) != 0) return -1;
|
||||
snprintf(src, sizeof src, "%s/slg_%d_%d.ww", tmpdir, getpid(), i);
|
||||
snprintf(outbin, sizeof outbin, "%s/slg_%d_%d", tmpdir, getpid(), i);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
|
||||
snprintf(scratch, sizeof scratch, "%s.sepwork", outbin);
|
||||
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (!f) { runwait(rmcmd); return -1; }
|
||||
fputs(r->src, f);
|
||||
fclose(f);
|
||||
if (!f) { setupfail = 1; goto cleanup; }
|
||||
int writefail = fputs(r->src, f) == EOF;
|
||||
if (fclose(f) != 0) writefail = 1;
|
||||
if (writefail) { setupfail = 1; goto cleanup; }
|
||||
|
||||
/* #8: -o pins binary + .sepwork scratch under tmpdir; rm -rf on
|
||||
* every exit path removes the now-non-empty dir. */
|
||||
/* Ordinary build retains caller-owned .sepwork scratch beside -o. */
|
||||
snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null",
|
||||
driver, outbin, src);
|
||||
if (runwait(cmd) != 0) {
|
||||
fprintf(stderr, "row[%s]: build via %s failed\n",
|
||||
r->label, driver);
|
||||
runwait(rmcmd);
|
||||
return -1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
int got = runwait(outbin);
|
||||
|
||||
runwait(rmcmd);
|
||||
return got;
|
||||
result = runwait(outbin);
|
||||
cleanup:
|
||||
if (setupfail)
|
||||
fprintf(stderr, "row[%s]: temporary setup failed\n", r->label);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf -- %s", scratch);
|
||||
if (runwait(rmcmd) != 0) cleanfail = 1;
|
||||
if (unlink(src) != 0 && errno != ENOENT) cleanfail = 1;
|
||||
if (unlink(outbin) != 0 && errno != ENOENT) cleanfail = 1;
|
||||
if (rmdir(tmpdir) != 0) cleanfail = 1;
|
||||
if (cleanfail) {
|
||||
fprintf(stderr, "row[%s]: temporary cleanup failed\n", r->label);
|
||||
if (result == r->want) return -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* build_should_fail — returns 0 when the build correctly FAILS. */
|
||||
/* build_should_fail — 0 on the expected rejection, positive on an
|
||||
* unexpected successful build, negative on fixture infrastructure failure. */
|
||||
static int
|
||||
build_should_fail(const char *driver, const char *src, int i)
|
||||
{
|
||||
char tmpdir[64], s[128], outbin[128], rmcmd[160], cmd[1024];
|
||||
char tmpdir[64], s[128], outbin[128], scratch[160], rmcmd[192], cmd[1024];
|
||||
int result = -1, setupfail = 0, cleanfail = 0;
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/slgn_%d_d_%d", getpid(), i);
|
||||
mkdir(tmpdir, 0755);
|
||||
if (mkdir(tmpdir, 0755) != 0) return -1;
|
||||
snprintf(s, sizeof s, "%s/slgn_%d_%d.ww", tmpdir, getpid(), i);
|
||||
snprintf(outbin, sizeof outbin, "%s/slgn_%d_%d", tmpdir, getpid(), i);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
|
||||
snprintf(scratch, sizeof scratch, "%s.sepwork", outbin);
|
||||
|
||||
FILE *f = fopen(s, "wb");
|
||||
if (!f) { runwait(rmcmd); return -1; }
|
||||
fputs(src, f);
|
||||
fclose(f);
|
||||
if (!f) { setupfail = 1; goto cleanup; }
|
||||
int writefail = fputs(src, f) == EOF;
|
||||
if (fclose(f) != 0) writefail = 1;
|
||||
if (writefail) { setupfail = 1; goto cleanup; }
|
||||
|
||||
/* #8: -o pins binary + .sepwork scratch under tmpdir; a reject build
|
||||
* still mkdir's scratch, so rm -rf must run on this path too. */
|
||||
/* A rejected ordinary build can also leave caller-owned .sepwork. */
|
||||
snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null",
|
||||
driver, outbin, s);
|
||||
int rc = runwait(cmd);
|
||||
runwait(rmcmd);
|
||||
return rc == 0 ? -1 : 0; /* build must NOT succeed */
|
||||
result = rc == 0 ? 1 : 0; /* build must NOT succeed */
|
||||
cleanup:
|
||||
if (setupfail)
|
||||
fprintf(stderr, "slice_literal_global[neg%d]: temporary setup failed\n", i);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf -- %s", scratch);
|
||||
if (runwait(rmcmd) != 0) cleanfail = 1;
|
||||
if (unlink(s) != 0 && errno != ENOENT) cleanfail = 1;
|
||||
if (unlink(outbin) != 0 && errno != ENOENT) cleanfail = 1;
|
||||
if (rmdir(tmpdir) != 0) cleanfail = 1;
|
||||
if (cleanfail) {
|
||||
fprintf(stderr, "slice_literal_global[neg%d]: temporary cleanup failed\n", i);
|
||||
if (result == 0) return -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* asm_byte_identical — w6c vs w6c_ww .s for the same source must match. */
|
||||
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/slg_asm_%d_%d.ww", getpid(), i);
|
||||
snprintf(cs, sizeof cs, "/tmp/slg_asm_%d_%d_c.s", getpid(), i);
|
||||
snprintf(ws, sizeof ws, "/tmp/slg_asm_%d_%d_w.s", getpid(), i);
|
||||
char tmpdir[64], src[96], cs[96], ws[96], cmd[1024];
|
||||
int rc = -1, cleanfail = 0;
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/slg_asm_%d_%d", getpid(), i);
|
||||
if (mkdir(tmpdir, 0755) != 0) return -1;
|
||||
snprintf(src, sizeof src, "%s/t.ww", tmpdir);
|
||||
snprintf(cs, sizeof cs, "%s/c.s", tmpdir);
|
||||
snprintf(ws, sizeof ws, "%s/w.s", tmpdir);
|
||||
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (!f) return -1;
|
||||
fputs(r->src, f);
|
||||
fclose(f);
|
||||
if (!f) goto cleanup;
|
||||
int writefail = fputs(r->src, f) == EOF;
|
||||
if (fclose(f) != 0) writefail = 1;
|
||||
if (writefail) goto cleanup;
|
||||
|
||||
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 cleanup;
|
||||
}
|
||||
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 cleanup;
|
||||
}
|
||||
|
||||
FILE *fc = fopen(cs, "rb");
|
||||
FILE *fw = fopen(ws, "rb");
|
||||
int rc = 0;
|
||||
rc = 0;
|
||||
if (!fc || !fw) {
|
||||
rc = -1;
|
||||
} else {
|
||||
@@ -294,7 +320,15 @@ 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);
|
||||
cleanup:
|
||||
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(tmpdir) != 0) cleanfail = 1;
|
||||
if (cleanfail) {
|
||||
fprintf(stderr, "row[%s]: temporary cleanup failed\n", r->label);
|
||||
return -1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -347,12 +381,17 @@ main(void)
|
||||
}
|
||||
for (int i = 0; i < nn; i++) {
|
||||
total++;
|
||||
if (build_should_fail(drivers[d].path, neg[i],
|
||||
100 + i) != 0) {
|
||||
fprintf(stderr,
|
||||
"slice_literal_global[%s][neg%d]: built ok, "
|
||||
"expected a loud error\n",
|
||||
drivers[d].name, i);
|
||||
int nr = build_should_fail(drivers[d].path, neg[i], 100 + i);
|
||||
if (nr != 0) {
|
||||
if (nr > 0)
|
||||
fprintf(stderr,
|
||||
"slice_literal_global[%s][neg%d]: built ok, "
|
||||
"expected a loud error\n",
|
||||
drivers[d].name, i);
|
||||
else
|
||||
fprintf(stderr,
|
||||
"slice_literal_global[%s][neg%d]: fixture infrastructure failed\n",
|
||||
drivers[d].name, i);
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user