Files
ww/test/wcc/944_alias_accept_run.c
Hojun-Cho a95a7a316b 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.
2026-08-07 23:21:04 +09:00

181 lines
5.2 KiB
C

/*
* 944_alias_accept_run — SLIM CARRIER (#5-C3 alias fold-2). The 62 K_RUN value
* rows migrated to test/lang/alias_accept_test.ww (@test, cs==ww byte-id via
* test-lang-byteid); the cs!=ww NOID row (v2_struct2, #81) to
* test/lang/alias_accept_runonly_test.ww; the symmetric K_BUILDERR rejects
* (assert_stays_loud, v2_ambig, v2_ambig2, union_as_bound_54) + the two
* now-symmetric ex-K_BUILDERR_CS rows (binop_alias_vs_alias, untyped_nestvar,
* superseded at HEAD) to test/wcc/data/alias_<name>/case.ww runww //ww:error.
*
* What survives here is the IRREDUCIBLE per-stage-asymmetric pin no in-language
* surface can host: cstage builds+RUNS exit 0 while wwstage LOUD-REJECTS
* (@test needs ww to build; runww //ww:error needs BOTH to fail). Held
* divergence task #96: ww `&s.len` / `&s.cap` over an alias-typed slice PARAM
* is "unsupported address-of shape"; cstage classifies the address shape
* through the alias chase and runs correct. Drew-ruled slim-carrier home
* (#5-C3, 954_tuprecv precedent).
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.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;
}
/* a reject must fail WITH its diagnostic; a crash (no body) is vacuous. */
static int
errlog_has(const char *path, const char *needle)
{
FILE *f = fopen(path, "rb");
if (!f) return 0;
char buf[8192];
size_t got = fread(buf, 1, sizeof buf - 1, f);
fclose(f);
buf[got] = '\0';
return strstr(buf, needle) != NULL;
}
/* cstage builds+runs (exit 0); wwstage frontend (w6c_ww) loud-rejects wwerr. */
static int
run_row(const char *bin, const char *label, const char *src,
const char *wwerr, int i)
{
char dir[128], srcf[192], outbin[192], wwe[192], ss[192];
char scratch[208], cmd[2048];
snprintf(dir, sizeof dir, "/tmp/aacc_%d_%d_XXXXXX", getpid(), i);
if (mkdtemp(dir) == NULL) {
fprintf(stderr, "row[%s]: temporary directory acquisition failed\n",
label);
return -1;
}
snprintf(srcf, sizeof srcf, "%s/c.ww", dir);
snprintf(outbin, sizeof outbin, "%s/bin", dir);
snprintf(wwe, sizeof wwe, "%s/ww.err", dir);
snprintf(ss, sizeof ss, "%s/o.s", dir);
snprintf(scratch, sizeof scratch, "%s.sepwork", outbin);
FILE *f = fopen(srcf, "wb");
int ok = 1;
if (!f) {
fprintf(stderr, "row[%s]: source setup failed\n", label);
ok = 0;
goto cleanup;
}
fputs(src, f);
fclose(f);
snprintf(cmd, sizeof cmd,
"timeout 20 %s/ww build -o %s %s >/dev/null 2>&1", bin, outbin, srcf);
if (runwait(cmd) != 0) {
fprintf(stderr, "row[%s]: cstage build failed (want run)\n", label);
ok = 0;
} else if (runwait(outbin) != 0) {
fprintf(stderr, "row[%s]: cstage run != 0\n", label);
ok = 0;
}
snprintf(cmd, sizeof cmd, "%s/w6c_ww -o %s %s 2>%s", bin, ss, srcf, wwe);
int wrc = runwait(cmd);
if (!(wrc != 0 && errlog_has(wwe, wwerr))) {
fprintf(stderr, "row[%s]: wwstage expected reject \"%s\" (rc=%d)\n",
label, wwerr, wrc);
ok = 0;
}
cleanup:
{
int bad = 0;
snprintf(cmd, sizeof cmd, "rm -rf %s", scratch);
if (runwait(cmd) != 0) bad = 1;
if (unlink(ss) != 0 && errno != ENOENT) bad = 1;
if (unlink(wwe) != 0 && errno != ENOENT) bad = 1;
if (unlink(outbin) != 0 && errno != ENOENT) bad = 1;
if (unlink(srcf) != 0 && errno != ENOENT) bad = 1;
if (rmdir(dir) != 0) bad = 1;
if (bad) {
fprintf(stderr, "row[%s]: temporary cleanup failed\n", label);
ok = 0;
}
}
return ok ? 0 : 1;
}
struct row { const char *label; const char *src; const char *wwerr; };
static const struct row rows[] = {
{ "amplen1_bound96",
"package main;\n"
"type sl1 = []i64;\n"
"fn check(s: sl1) i32 = {\n"
" let p: *i64 = &s.len;\n"
" if (*p == 3) { return 0; };\n"
" return 1;\n"
"};\n"
"export fn main() i32 = {\n"
" let b: []i64 = [1, 2, 3];\n"
" return check(b);\n"
"};\n", "unsupported address-of shape" }, /* ww: task #96 */
{ "amplen2_bound96",
"package main;\n"
"type sl1 = []i64;\n"
"type sl2 = sl1;\n"
"fn check(s: sl2) i32 = {\n"
" let p: *i64 = &s.len;\n"
" if (*p == 3) { return 0; };\n"
" return 1;\n"
"};\n"
"export fn main() i32 = {\n"
" let b: []i64 = [1, 2, 3];\n"
" return check(b);\n"
"};\n", "unsupported address-of shape" }, /* ww: task #96 */
{ "ampcap2_bound96",
"package main;\n"
"type sl1 = []i64;\n"
"type sl2 = sl1;\n"
"fn check(s: sl2) i32 = {\n"
" let p: *i64 = &s.cap;\n"
" if (*p == 3) { return 0; };\n"
" return 1;\n"
"};\n"
"export fn main() i32 = {\n"
" let b: []i64 = [1, 2, 3];\n"
" return check(b);\n"
"};\n", "unsupported address-of shape" }, /* ww: task #96 */
};
int
main(void)
{
const char *bin = getenv("BIN");
if (!bin) bin = "out/bin";
char absbin[2080];
if (bin[0] != '/') {
char cwd[1024];
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin);
bin = absbin;
}
int n = (int)(sizeof rows / sizeof rows[0]);
int fail = 0;
for (int i = 0; i < n; i++)
if (run_row(bin, rows[i].label, rows[i].src, rows[i].wwerr, i) != 0)
fail++;
if (fail) {
fprintf(stderr, "alias_accept (slim): %d/%d rows failed\n", fail, n);
return 1;
}
printf("alias_accept (slim): %d/%d ok\n", n, n);
return 0;
}