test/wcc: c6 dual-path sep==combined soak gate (#46)

Make the sep-compile == combined-compile output equivalence a standing
regression test — the last criterion before M4 can delete the combined.ww
embedding model.

989_c6soak_run (phase-1): Tier-A/B + same-leaf collision soak. Two real
roots (utf8: encoding.utf8 dotted-path + strings; collide: strings.contains
+ bytes.contains) built both ways with isolated cold WW_PKGCACHE; asserts
combined-run-exit == sep-run-exit on both drivers, cs==ww per-pkg .s/.wwi,
and two distinct collision labels.

994_w6c_ww (phase-2): Tier-C folded into the existing w6c byte-id oracle.
A sep-built w6c emits byte-identical .s to a combined-built w6c on all five
bootstrap targets (w6c/wwdump/w6a/w6l/ww .combined.ww); .wwi is in the
compare set. The tool binaries themselves differ by a benign constant
link-layout delta — the oracle is tool OUTPUT, not tool-binary identity.

Test-only; the five wwstage binary pins are unchanged.
This commit is contained in:
2026-06-17 00:17:25 +09:00
parent 75a03a7d69
commit 4ae29d6949
3 changed files with 514 additions and 2 deletions

View File

@@ -17,6 +17,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include <dirent.h>
static int
runwait(const char *cmd)
@@ -105,6 +106,94 @@ write_file(const char *path, const char *content)
return 0;
}
static int
files_eq(const char *a, const char *b)
{
char *ba = NULL, *bb = NULL;
size_t na = 0, nb = 0;
if (slurp(a, &ba, &na) < 0 || slurp(b, &bb, &nb) < 0) {
free(ba); free(bb);
return -1;
}
int eq = (na == nb && memcmp(ba, bb, na) == 0);
free(ba); free(bb);
return eq ? 0 : 1;
}
/* Tier-C oracle helper (rob-c6-spec §2 / amendment-B): a sep-built w6c at
* `sepw6c` must EMIT byte-identical asm to the combined-built `w6c_ww` on
* `target`. (We assert OUTPUT equivalence, never `cmp` the tool binaries —
* sep vs combined differ by a constant link-layout delta.) Returns 0 on
* byte-identical .s, non-zero otherwise. */
static int
emit_eq(const char *sepw6c, const char *w6c_ww, const char *target,
const char *label)
{
char a[64], b[64], cmd[4096];
snprintf(a, sizeof a, "/tmp/wwc6tc_%d_sep.s", getpid());
snprintf(b, sizeof b, "/tmp/wwc6tc_%d_comb.s", getpid());
snprintf(cmd, sizeof cmd, "timeout 240 %s -o %s %s 2>/dev/null",
sepw6c, a, target);
if (runwait(cmd) != 0) {
fprintf(stderr, "Tier-C FAIL: sep-w6c emit errored on %s\n", label);
unlink(a);
return 1;
}
snprintf(cmd, sizeof cmd, "timeout 240 %s -o %s %s 2>/dev/null",
w6c_ww, b, target);
if (runwait(cmd) != 0) {
fprintf(stderr, "Tier-C FAIL: combined-w6c_ww emit errored on %s\n",
label);
unlink(a); unlink(b);
return 1;
}
int rc = files_eq(a, b);
if (rc != 0)
fprintf(stderr, "Tier-C FAIL: %s — sep-out != combined-out "
"(M4 output-equivalence broken)\n", label);
unlink(a); unlink(b);
return rc == 0 ? 0 : 1;
}
/* cs==ww over a sep-build's per-package artifacts: every .s/.o/.wwi the
* cstage driver produced in `csdir` must be byte-identical to the wwstage
* driver's same-named file in `wwdir` (rule 10; the .wwi interface files
* enter the compare set per rob-c6-spec §2). Returns the mismatch count
* (≥1 also on an unreadable / empty cs sepwork). */
static int
cmp_sepwork(const char *csdir, const char *wwdir)
{
DIR *d = opendir(csdir);
if (!d) {
fprintf(stderr, "Tier-C FAIL: no cs sepwork %s\n", csdir);
return 1;
}
int bad = 0, seen = 0;
struct dirent *ent;
while ((ent = readdir(d)) != NULL) {
const char *nm = ent->d_name;
size_t nl = strlen(nm);
int is_s = (nl > 2 && strcmp(nm + nl - 2, ".s") == 0);
int is_o = (nl > 2 && strcmp(nm + nl - 2, ".o") == 0);
int is_wwi = (nl > 4 && strcmp(nm + nl - 4, ".wwi") == 0);
if (!is_s && !is_o && !is_wwi) continue;
seen++;
char a[2048], b[2048];
snprintf(a, sizeof a, "%s/%s", csdir, nm);
snprintf(b, sizeof b, "%s/%s", wwdir, nm);
if (files_eq(a, b) != 0) {
fprintf(stderr, "Tier-C FAIL: cs!=ww for %s (rule 10)\n", nm);
bad++;
}
}
closedir(d);
if (seen == 0) {
fprintf(stderr, "Tier-C FAIL: no .s/.o/.wwi in %s\n", csdir);
bad++;
}
return bad;
}
int
main(void)
{
@@ -287,11 +376,91 @@ main(void)
n++;
}
/* ---- Tier-C capstone (#46 c6, rob-c6-spec §2 / amendment-B) ----------
* Fold the dual-path soak into this bootstrap oracle: a w6c built by
* SEPARATE compilation must EMIT byte-identical .s to the combined-built
* w6c_ww on every real bootstrap input, and both driver stages must
* sep-produce byte-identical per-package .s/.o/.wwi (cs==ww on the real
* tool's sep artifacts). This is the load-bearing M4 proof — the
* combined-out==sep-out leg the bootstrap fixed point alone cannot reach.
* We assert OBSERVABLE OUTPUT, never `cmp` the tool binaries (sep vs
* combined differ by a constant link-layout delta). COLD (pid-keyed
* scratch, wiped); heavy (≈ one bootstrap leg) → this gate is phase-2. */
{
char inc[4096], cmd[16384];
snprintf(inc, sizeof inc,
"-I %s/lib -I %s/lib/ww -I %s/selfhost/cmd/wcc", cwd, cwd, cwd);
char w6c_ww[2048], root[2048];
snprintf(w6c_ww, sizeof w6c_ww, "%s/w6c_ww", bin);
snprintf(root, sizeof root, "%s/selfhost/cmd/w6c/main.ww", cwd);
struct { const char *drv, *tag; char prog[2048]; int ok; }
stg[] = { { "ww", "cs", {0}, 0 }, { "ww_ww", "ww", {0}, 0 } };
for (int s = 0; s < 2; s++) {
snprintf(stg[s].prog, sizeof stg[s].prog,
"/tmp/wwc6tc_%d_%s", getpid(), stg[s].tag);
/* Isolated per-(pid,stage) WW_PKGCACHE → COLD + race-free
* (rob-c6-spec §4): the default out/.pkgcache is shared with
* the other phase-2 gates' `ww build`s and would both perturb
* this gate and corrupt under concurrent writes. */
snprintf(cmd, sizeof cmd,
"WW_PKGCACHE='%s.cache' timeout 600 %s/%s build --sep "
"%s -o %s %s >/dev/null 2>&1",
stg[s].prog, bin, stg[s].drv, inc, stg[s].prog, root);
if (runwait(cmd) != 0) {
fprintf(stderr, "Tier-C FAIL: %s build --sep w6c\n",
stg[s].drv);
fail++;
} else stg[s].ok = 1;
n++;
}
/* OUTPUT equivalence on every real bootstrap input: each built
* sep-w6c vs the combined w6c_ww (the M4 combined-out==sep-out bar;
* cs==ww follows since both sep stages match the same reference). */
const char *targ[] = {
"selfhost/cmd/w6c/main.combined.ww",
"selfhost/cmd/wwdump/main.combined.ww",
"selfhost/cmd/w6a/main.combined.ww",
"selfhost/cmd/w6l/main.combined.ww",
"selfhost/cmd/ww/main.combined.ww",
NULL,
};
for (int s = 0; s < 2; s++) {
if (!stg[s].ok) continue;
for (int i = 0; targ[i]; i++) {
char t[2048], label[256];
snprintf(t, sizeof t, "%s/%s", cwd, targ[i]);
snprintf(label, sizeof label, "sep-%s emit %s",
stg[s].tag, targ[i]);
if (emit_eq(stg[s].prog, w6c_ww, t, label) != 0) fail++;
n++;
}
}
/* cs==ww on the real tool's sep .s/.o/.wwi (rule 10). */
if (stg[0].ok && stg[1].ok) {
char csdir[2176], wwdir[2176];
snprintf(csdir, sizeof csdir, "%s.sepwork", stg[0].prog);
snprintf(wwdir, sizeof wwdir, "%s.sepwork", stg[1].prog);
fail += cmp_sepwork(csdir, wwdir);
n++;
}
for (int s = 0; s < 2; s++) {
snprintf(cmd, sizeof cmd, "rm -rf %s %s.sepwork %s.cache",
stg[s].prog, stg[s].prog, stg[s].prog);
runwait(cmd);
}
}
if (fail) {
fprintf(stderr, "w6c_ww: %d/%d diff(s) failed\n", fail, n);
return 1;
}
printf("w6c_ww: byte-identical to wwdump_ww -c on %d corpus inputs "
"(in-source + selfhost combined.ww)\n", n);
"(in-source + selfhost combined.ww) + Tier-C: sep-built w6c emits "
"== combined w6c_ww on all bootstrap inputs, cs==ww sep .s/.o/.wwi\n",
n);
return 0;
}