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:
@@ -68,6 +68,7 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -154,31 +155,47 @@ static const struct row rows[] = {
|
||||
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], cmd[1024];
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/aee_%d_d_%d", getpid(), i);
|
||||
snprintf(src, sizeof src, "%s/aee_%d_%d.ww", tmpdir, getpid(), i);
|
||||
snprintf(outbin, sizeof outbin, "%s/aee_%d_%d", tmpdir, getpid(), i);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
|
||||
snprintf(scratch, sizeof scratch, "%s.sepwork", outbin);
|
||||
|
||||
mkdir(tmpdir, 0755);
|
||||
if (mkdir(tmpdir, 0755) != 0) {
|
||||
perror(tmpdir);
|
||||
return -1;
|
||||
}
|
||||
int result = -1;
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (!f) { runwait(rmcmd); return -1; }
|
||||
if (!f) { perror(src); goto cleanup; }
|
||||
wwtest_fputs(r->src, f);
|
||||
fclose(f);
|
||||
if (fclose(f) != 0) { perror(src); goto cleanup; }
|
||||
|
||||
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);
|
||||
result = runwait(outbin);
|
||||
|
||||
runwait(rmcmd);
|
||||
return got;
|
||||
cleanup:
|
||||
/* `ww build -o` retains this exact caller-owned scratch tree. */
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s", scratch);
|
||||
int cleanfail = runwait(cmd) != 0;
|
||||
if (unlink(outbin) != 0 && errno != ENOENT) {
|
||||
perror(outbin); cleanfail = 1;
|
||||
}
|
||||
if (unlink(src) != 0 && errno != ENOENT) {
|
||||
perror(src); cleanfail = 1;
|
||||
}
|
||||
if (rmdir(tmpdir) != 0) {
|
||||
perror(tmpdir); cleanfail = 1;
|
||||
}
|
||||
if (cleanfail && result == r->want) result = -1;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* asm_byte_identical — generate .s via cstage's w6c and wwstage's
|
||||
@@ -188,33 +205,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/aee_asm_%d_%d.ww", getpid(), i);
|
||||
snprintf(cs, sizeof cs, "/tmp/aee_asm_%d_%d_c.s", getpid(), i);
|
||||
snprintf(ws, sizeof ws, "/tmp/aee_asm_%d_%d_w.s", getpid(), i);
|
||||
char tmpdir[64], src[128], cs[128], ws[128], cmd[1024];
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/aee_asm_%d_%d", getpid(), i);
|
||||
snprintf(src, sizeof src, "%s/input.ww", tmpdir);
|
||||
snprintf(cs, sizeof cs, "%s/c.s", tmpdir);
|
||||
snprintf(ws, sizeof ws, "%s/w.s", tmpdir);
|
||||
if (mkdir(tmpdir, 0755) != 0) {
|
||||
perror(tmpdir);
|
||||
return -1;
|
||||
}
|
||||
int rc = -1;
|
||||
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (!f) return -1;
|
||||
if (!f) { perror(src); goto cleanup; }
|
||||
wwtest_fputs(r->src, f);
|
||||
fclose(f);
|
||||
if (fclose(f) != 0) { perror(src); 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 {
|
||||
@@ -230,7 +251,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);
|
||||
|
||||
cleanup:
|
||||
if (unlink(src) != 0 && errno != ENOENT) {
|
||||
perror(src); rc = -1;
|
||||
}
|
||||
if (unlink(cs) != 0 && errno != ENOENT) {
|
||||
perror(cs); rc = -1;
|
||||
}
|
||||
if (unlink(ws) != 0 && errno != ENOENT) {
|
||||
perror(ws); rc = -1;
|
||||
}
|
||||
if (rmdir(tmpdir) != 0) {
|
||||
perror(tmpdir); rc = -1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user