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.
168 lines
4.8 KiB
C
168 lines
4.8 KiB
C
/*
|
|
* 989_m1mangle_sym — M1 (#22) symbol-name proof. Builds a fixture that
|
|
* imports the real nested DIRECTORY package `encoding.utf8` to `.s` on
|
|
* BOTH stages and asserts the emitted symbol table:
|
|
*
|
|
* needle | want | proves
|
|
* --------------------------+------+-----------------------------------
|
|
* "encoding.utf8.runesz" | yes | nested pkg path-mangles (the M1
|
|
* | | DELTA: leaf `utf8` → path
|
|
* | | `encoding.utf8`)
|
|
* "TEXT main," | yes | root entry stays BARE (#32)
|
|
* "TEXT utf8.runesz," | no | the pre-M1 leaf-only mangle is gone
|
|
*
|
|
* Plus cstage.s == wwstage.s byte-for-byte on the re-baselined names
|
|
* (rule-10 — the cs==ww gate over the new symbols).
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.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;
|
|
}
|
|
|
|
static int
|
|
file_has(const char *path, const char *needle)
|
|
{
|
|
FILE *f = fopen(path, "rb");
|
|
if (!f) return -1;
|
|
char line[4096];
|
|
int found = 0;
|
|
while (fgets(line, sizeof line, f)) {
|
|
if (strstr(line, needle)) { found = 1; break; }
|
|
}
|
|
fclose(f);
|
|
return found;
|
|
}
|
|
|
|
struct check { const char *needle; int want; };
|
|
|
|
static const struct check checks[] = {
|
|
{ "encoding.utf8.runesz", 1 },
|
|
{ "TEXT main,", 1 },
|
|
{ "TEXT utf8.runesz,", 0 },
|
|
};
|
|
|
|
/* build_s — build `src` via `driver`, leaving the unit asm at `<stem>.s`;
|
|
* returns 0 on success.
|
|
* #93 sep layout: `-o <stem>` splits the asm across
|
|
* <stem>.sepwork/<pkg>.s (root in __root.s, the imported encoding.utf8 in
|
|
* encoding.utf8.s). The mangled `encoding.utf8.runesz` definition lives in
|
|
* the per-pkg .s and `TEXT main,` in __root.s, so we CONCAT all the
|
|
* per-unit .s (sorted glob order is deterministic) into a single <stem>.s
|
|
* for the needle scans + the rule-10 cmp downstream. */
|
|
static int
|
|
build_s(const char *driver, const char *src, const char *stem)
|
|
{
|
|
char cmd[1024];
|
|
snprintf(cmd, sizeof cmd,
|
|
"timeout 180 %s build -S -o '%s' '%s' "
|
|
"2>/dev/null && cat '%s.sepwork/'*.s > '%s.s'",
|
|
driver, stem, src, stem, stem);
|
|
return runwait(cmd);
|
|
}
|
|
|
|
static int
|
|
checkall(const char *name, const char *sp)
|
|
{
|
|
int fail = 0;
|
|
for (int i = 0; i < (int)(sizeof checks / sizeof checks[0]); i++) {
|
|
int got = file_has(sp, checks[i].needle);
|
|
if (got != checks[i].want) {
|
|
fprintf(stderr, "m1mangle_sym[%s]: '%s' present=%d want=%d\n",
|
|
name, checks[i].needle, got, checks[i].want);
|
|
fail++;
|
|
}
|
|
}
|
|
return fail;
|
|
}
|
|
|
|
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/ww", bin);
|
|
snprintf(wdrv, sizeof wdrv, "%s/ww_ww", bin);
|
|
|
|
char src[64];
|
|
snprintf(src, sizeof src, "/tmp/m1sym_%d.ww", getpid());
|
|
FILE *f = fopen(src, "wb");
|
|
if (!f) return 1;
|
|
fputs("package main;\n"
|
|
"import encoding.utf8;\n"
|
|
"export fn main() int = { return utf8.runesz('A'): int; };\n", f);
|
|
fclose(f);
|
|
|
|
int fail = 0;
|
|
|
|
char cstem[64], cs[80];
|
|
snprintf(cstem, sizeof cstem, "/tmp/m1sym_c_%d", getpid());
|
|
snprintf(cs, sizeof cs, "%s.s", cstem);
|
|
if (build_s(cdrv, src, cstem) != 0) {
|
|
fprintf(stderr, "m1mangle_sym: cstage build failed\n");
|
|
fail++;
|
|
} else {
|
|
fail += checkall("cstage", cs);
|
|
}
|
|
|
|
int have_ww = (access(wdrv, X_OK) == 0);
|
|
char wstem[64], ws[80];
|
|
snprintf(wstem, sizeof wstem, "/tmp/m1sym_w_%d", getpid());
|
|
snprintf(ws, sizeof ws, "%s.s", wstem);
|
|
if (have_ww) {
|
|
if (build_s(wdrv, src, wstem) != 0) {
|
|
fprintf(stderr, "m1mangle_sym: wwstage build failed\n");
|
|
fail++;
|
|
} else {
|
|
fail += checkall("wwstage", ws);
|
|
/* rule-10: cs.s == ww.s on the new mangled names. */
|
|
char cmp[256];
|
|
snprintf(cmp, sizeof cmp, "cmp -s '%s' '%s'", cs, ws);
|
|
if (runwait(cmp) != 0) {
|
|
fprintf(stderr, "m1mangle_sym: cstage.s != "
|
|
"wwstage.s (byte-id break)\n");
|
|
fail++;
|
|
}
|
|
}
|
|
} else {
|
|
fprintf(stderr, "m1mangle_sym: skip wwstage (no ww_ww)\n");
|
|
}
|
|
|
|
char cmd[512];
|
|
/* #93: -rf also drops the per-stem .sepwork scratch. Exact owned
|
|
* paths only (`build -S` writes solely under <stem>.sepwork/, plus
|
|
* build_s's <stem>.s concat) — no prefix glob; a failed rm must fail
|
|
* the carrier, not leak silently. */
|
|
snprintf(cmd, sizeof cmd,
|
|
"rm -rf '%s' '%s.s' '%s.sepwork' '%s.s' '%s.sepwork'",
|
|
src, cstem, cstem, wstem, wstem);
|
|
if (runwait(cmd) != 0) {
|
|
fprintf(stderr, "m1mangle_sym: cleanup rm failed\n");
|
|
fail++;
|
|
}
|
|
|
|
if (fail) {
|
|
fprintf(stderr, "m1mangle_sym: %d checks failed\n", fail);
|
|
return 1;
|
|
}
|
|
printf("m1mangle_sym: ok\n");
|
|
return 0;
|
|
}
|