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.
147 lines
3.7 KiB
C
147 lines
3.7 KiB
C
/*
|
|
* 826_alias_tuple_coerce — residual asymmetric and assembly byte checks.
|
|
* Symmetric runtime ownership is the r826_* compiler fixture set; the three
|
|
* byte rows compile those exact files directly. Two negative controls remain
|
|
* embedded because cstage must reject them while wwstage still over-accepts
|
|
* them, so the symmetric fixture grammar cannot own that assertion.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <sys/wait.h>
|
|
|
|
static int
|
|
runwait(const char *cmd)
|
|
{
|
|
int rc = system(cmd);
|
|
if (rc == -1) return -1;
|
|
if (WIFEXITED(rc)) return WEXITSTATUS(rc);
|
|
return -1;
|
|
}
|
|
|
|
struct row { const char *label; const char *path; };
|
|
|
|
static const struct row rows[] = {
|
|
{ "init", "test/wcc/data/r826_alias_tuple_init/case.ww" },
|
|
{ "fnarg", "test/wcc/data/r826_alias_tuple_fnarg/case.ww" },
|
|
{ "ret", "test/wcc/data/r826_alias_tuple_ret/case.ww" },
|
|
};
|
|
|
|
static const char *neg[] = {
|
|
"package main;\n"
|
|
"type pair = (int, int);\n"
|
|
"export fn main() i32 = {\n"
|
|
"\tlet x: pair = (3, \"s\");\n"
|
|
"\treturn x.0: i32;\n"
|
|
"};\n",
|
|
|
|
"package main;\n"
|
|
"type pair = (int, int);\n"
|
|
"export fn main() i32 = {\n"
|
|
"\tlet x: pair = (3, 4, 5);\n"
|
|
"\treturn x.0: i32;\n"
|
|
"};\n",
|
|
};
|
|
|
|
static int
|
|
compile_should_fail(const char *compiler, const char *src, int i)
|
|
{
|
|
char s[128], outasm[128], cmd[1024];
|
|
snprintf(s, sizeof s, "/tmp/atc_neg_%d_%d.ww", getpid(), i);
|
|
snprintf(outasm, sizeof outasm, "/tmp/atc_neg_%d_%d.s", getpid(), i);
|
|
FILE *f = fopen(s, "wb");
|
|
if (!f) return -1;
|
|
fputs(src, f);
|
|
fclose(f);
|
|
snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null",
|
|
compiler, outasm, s);
|
|
int rc = runwait(cmd);
|
|
unlink(s);
|
|
unlink(outasm);
|
|
return rc == 0 ? -1 : 0;
|
|
}
|
|
|
|
static int
|
|
asm_byte_identical(const char *bin, const struct row *r, int i)
|
|
{
|
|
char cs[64], ws[64], cmd[1024];
|
|
snprintf(cs, sizeof cs, "/tmp/atc_asm_%d_%d_c.s", getpid(), i);
|
|
snprintf(ws, sizeof ws, "/tmp/atc_asm_%d_%d_w.s", getpid(), i);
|
|
snprintf(cmd, sizeof cmd, "%s/w6c -o %s %s 2>/dev/null",
|
|
bin, cs, r->path);
|
|
if (runwait(cmd) != 0) {
|
|
fprintf(stderr, "row[%s]: w6c errored\n", r->label);
|
|
return -1;
|
|
}
|
|
snprintf(cmd, sizeof cmd, "%s/w6c_ww -o %s %s 2>/dev/null",
|
|
bin, ws, r->path);
|
|
if (runwait(cmd) != 0) {
|
|
fprintf(stderr, "row[%s]: w6c_ww errored\n", r->label);
|
|
unlink(cs);
|
|
return -1;
|
|
}
|
|
FILE *fc = fopen(cs, "rb");
|
|
FILE *fw = fopen(ws, "rb");
|
|
int rc = 0;
|
|
if (!fc || !fw) rc = -1;
|
|
else {
|
|
for (;;) {
|
|
int a = fgetc(fc);
|
|
int b = fgetc(fw);
|
|
if (a != b) { rc = -1; break; }
|
|
if (a == EOF) break;
|
|
}
|
|
}
|
|
if (fc) fclose(fc);
|
|
if (fw) fclose(fw);
|
|
if (rc != 0)
|
|
fprintf(stderr, "row[%s]: cstage vs wwstage asm differs\n",
|
|
r->label);
|
|
unlink(cs);
|
|
unlink(ws);
|
|
return rc;
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
const char *bin = getenv("BIN");
|
|
if (!bin) bin = "out/bin";
|
|
char absbin[1024];
|
|
if (bin[0] != '/') {
|
|
char cwd[1024];
|
|
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
|
|
snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin);
|
|
bin = absbin;
|
|
}
|
|
char cdrv[1024], wdrv[1024];
|
|
snprintf(cdrv, sizeof cdrv, "%s/w6c", bin);
|
|
snprintf(wdrv, sizeof wdrv, "%s/w6c_ww", bin);
|
|
int n = (int)(sizeof rows / sizeof rows[0]);
|
|
int nneg = (int)(sizeof neg / sizeof neg[0]);
|
|
int total = 0, fail = 0;
|
|
for (int i = 0; i < nneg; i++) {
|
|
total++;
|
|
if (compile_should_fail(cdrv, neg[i], i) != 0) {
|
|
fprintf(stderr,
|
|
"alias_tuple_coerce[cstage][neg_%d]: built (should loud)\n",
|
|
i);
|
|
fail++;
|
|
}
|
|
}
|
|
if (access(wdrv, X_OK) == 0) {
|
|
for (int i = 0; i < n; i++) {
|
|
total++;
|
|
if (asm_byte_identical(bin, &rows[i], i) != 0) fail++;
|
|
}
|
|
}
|
|
if (fail) {
|
|
fprintf(stderr,
|
|
"alias_tuple_coerce: %d/%d residual checks failed\n",
|
|
fail, total);
|
|
return 1;
|
|
}
|
|
printf("alias_tuple_coerce: %d/%d residual checks ok\n", total, total);
|
|
return 0;
|
|
}
|