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:
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -37,31 +38,45 @@ runwait(const char *cmd)
|
||||
static int
|
||||
run_roundtrip(const char *driver, int id)
|
||||
{
|
||||
char dir[80], wrdir[112], wrp[176], mainp[160], cmd[1024], outbin[160];
|
||||
char dir[80], wrdir[112], wrp[176], mainp[160], cmd[1024];
|
||||
char outbin[160], scratch[176];
|
||||
snprintf(dir, sizeof dir, "/tmp/wwue_rt_%d_%d", getpid(), id);
|
||||
snprintf(wrdir, sizeof wrdir, "%s/wr", dir);
|
||||
mkdir(dir, 0755);
|
||||
mkdir(wrdir, 0755);
|
||||
snprintf(wrp, sizeof wrp, "%s/wr.ww", wrdir);
|
||||
snprintf(mainp, sizeof mainp, "%s/main.ww", dir);
|
||||
snprintf(outbin, sizeof outbin, "%s/main", dir);
|
||||
snprintf(scratch, sizeof scratch, "%s/main.sepwork", dir);
|
||||
|
||||
if (mkdir(dir, 0755) != 0) {
|
||||
perror(dir);
|
||||
return -1;
|
||||
}
|
||||
int got = -1;
|
||||
int wr_owned = 0;
|
||||
if (mkdir(wrdir, 0755) != 0) {
|
||||
perror(wrdir);
|
||||
goto cleanup;
|
||||
}
|
||||
wr_owned = 1;
|
||||
|
||||
FILE *f = fopen(wrp, "wb");
|
||||
if (!f) {
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s", dir);
|
||||
(void)system(cmd);
|
||||
return -1;
|
||||
perror(wrp);
|
||||
goto cleanup;
|
||||
}
|
||||
/* one def per serializer branch: \x (<=0xFF), \u (<=0xFFFF), \U. */
|
||||
fputs("package wr;\n"
|
||||
"export def EACUTE: rune = '\\u00e9';\n"
|
||||
"export def EURO: rune = '\\u20ac';\n"
|
||||
"export def SMILEY: rune = '\\U0001F600';\n", f);
|
||||
fclose(f);
|
||||
if (fclose(f) != 0) {
|
||||
perror(wrp);
|
||||
goto cleanup;
|
||||
}
|
||||
f = fopen(mainp, "wb");
|
||||
if (!f) {
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s", dir);
|
||||
(void)system(cmd);
|
||||
return -1;
|
||||
perror(mainp);
|
||||
goto cleanup;
|
||||
}
|
||||
fputs("package main;\n"
|
||||
"import wr;\n"
|
||||
@@ -74,19 +89,46 @@ run_roundtrip(const char *driver, int id)
|
||||
" if ((c: u32) != 128512u32) { return 3; };\n"
|
||||
" return 42;\n"
|
||||
"};\n", f);
|
||||
fclose(f);
|
||||
if (fclose(f) != 0) {
|
||||
perror(mainp);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
snprintf(cmd, sizeof cmd, "cd %s && %s build main.ww", dir, driver);
|
||||
if (runwait(cmd) != 0) {
|
||||
fprintf(stderr, "roundtrip: build via %s failed\n", driver);
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s", dir);
|
||||
(void)system(cmd);
|
||||
return -1;
|
||||
goto cleanup;
|
||||
}
|
||||
snprintf(outbin, sizeof outbin, "%s/main", dir);
|
||||
int got = runwait(outbin);
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s", dir);
|
||||
(void)system(cmd);
|
||||
got = runwait(outbin);
|
||||
|
||||
cleanup:
|
||||
/* `ww build` 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(mainp) != 0 && errno != ENOENT) {
|
||||
perror(mainp);
|
||||
cleanfail = 1;
|
||||
}
|
||||
if (wr_owned) {
|
||||
if (unlink(wrp) != 0 && errno != ENOENT) {
|
||||
perror(wrp);
|
||||
cleanfail = 1;
|
||||
}
|
||||
if (rmdir(wrdir) != 0) {
|
||||
perror(wrdir);
|
||||
cleanfail = 1;
|
||||
}
|
||||
}
|
||||
if (rmdir(dir) != 0) {
|
||||
perror(dir);
|
||||
cleanfail = 1;
|
||||
}
|
||||
if (cleanfail && got == 42)
|
||||
got = -1;
|
||||
return got;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user