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:
@@ -25,6 +25,7 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -50,55 +51,73 @@ static const char *SRC =
|
||||
static int
|
||||
run_driver(const char *driver)
|
||||
{
|
||||
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, cleanfail = 0;
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/agnd_%d_d", getpid());
|
||||
mkdir(tmpdir, 0755);
|
||||
if (mkdir(tmpdir, 0755) != 0) return -1;
|
||||
snprintf(src, sizeof src, "%s/agnd_%d.ww", tmpdir, getpid());
|
||||
snprintf(outbin, sizeof outbin, "%s/agnd_%d", tmpdir, getpid());
|
||||
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(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, src);
|
||||
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(src) != 0 && errno != ENOENT) cleanfail = 1;
|
||||
if (unlink(outbin) != 0 && errno != ENOENT) cleanfail = 1;
|
||||
if (rmdir(tmpdir) != 0) cleanfail = 1;
|
||||
if (cleanfail) {
|
||||
fprintf(stderr, "arrglob_nodup: temporary cleanup failed\n");
|
||||
if (result == 6) return -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* emit .s via `tool`, return the count of `DATAW main.g(SB)` rows, or -1. */
|
||||
static int
|
||||
dataw_rows(const char *bin, const char *tool)
|
||||
{
|
||||
char src[64], asmf[80], cmd[1024];
|
||||
snprintf(src, sizeof src, "/tmp/agnd_asm_%d.ww", getpid());
|
||||
snprintf(asmf, sizeof asmf, "/tmp/agnd_asm_%d_%s.s", getpid(), tool);
|
||||
char tmpdir[80], src[96], asmf[96], cmd[1024];
|
||||
int n = -1, cleanfail = 0;
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/agnd_asm_%d_%s", getpid(), tool);
|
||||
if (mkdir(tmpdir, 0755) != 0) return -1;
|
||||
snprintf(src, sizeof src, "%s/t.ww", tmpdir);
|
||||
snprintf(asmf, sizeof asmf, "%s/t.s", tmpdir);
|
||||
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (!f) 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/%s -o %s %s 2>/dev/null", bin, tool, asmf, src);
|
||||
if (runwait(cmd) != 0) { unlink(src); return -1; }
|
||||
if (runwait(cmd) != 0) goto cleanup;
|
||||
|
||||
FILE *a = fopen(asmf, "rb");
|
||||
int n = 0;
|
||||
n = 0;
|
||||
if (a) {
|
||||
char line[512];
|
||||
while (fgets(line, sizeof line, a))
|
||||
if (strncmp(line, "DATAW main.g(SB)", 16) == 0) n++;
|
||||
fclose(a);
|
||||
} else {
|
||||
n = -1;
|
||||
} else n = -1;
|
||||
cleanup:
|
||||
if (unlink(src) != 0 && errno != ENOENT) cleanfail = 1;
|
||||
if (unlink(asmf) != 0 && errno != ENOENT) cleanfail = 1;
|
||||
if (rmdir(tmpdir) != 0) cleanfail = 1;
|
||||
if (cleanfail) {
|
||||
fprintf(stderr, "arrglob_nodup[%s]: temporary cleanup failed\n", tool);
|
||||
if (n == 1) return -1;
|
||||
}
|
||||
unlink(src); unlink(asmf);
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user