/* * 911_attest_record — #17 record-and-continue harness (lib/test + the * table-synth -T entry). Sibling of 989_septest_run + 911_attest_drop * (which pin the synth entry itself + the #6 non-T drop); this one pins * the RUNTIME behaviour the fork+wait4 runner adds: * * 1. RECORD-AND-CONTINUE — `ww test` the mixed fixture (one pass, then * assert-fail/SIGSEGV/SIGFPE, then a final pass). The runner must * proceed past every failure, emit the right per-test `name ... ok/ * FAIL` line (table-driven below), print the right `P passed, F * failed` summary, and clamp any failure set to exit 1. * 2. ALL-PASS — `ww test` the all-pass fixture exits 0 (no false * failure from the new runner). * 3. BYTE-ID (rule 10) — `ww test -c` the mixed fixture into a * lib/test-inclusive combined, then `w6c -T` and `w6c_ww -T` must * emit byte-identical asm (the table + fork loop, both stages). * * The fork changes failure OUTPUT, not pass behaviour: a passing fixture * still exits 0, so the 35 converted lib tests stay green (904/967/...). */ #include #include #include #include #include #include static int runwait(const char *cmd) { int rc = system(cmd); if (rc == -1) return -1; if (WIFEXITED(rc)) return WEXITSTATUS(rc); return 1; } static const char * absbin(void) { const char *b = getenv("BIN"); if (!b) b = "out/bin"; if (b[0] == '/') return b; static char buf[2048]; char cwd[1024]; if (getcwd(cwd, sizeof cwd) == NULL) return NULL; snprintf(buf, sizeof buf, "%s/%s", cwd, b); return buf; } static int slurp(const char *path, char *out, size_t outsz) { FILE *f = fopen(path, "rb"); if (!f) return -1; size_t n = fread(out, 1, outsz - 1, f); out[n] = '\0'; fclose(f); return 0; } /* Each expected per-test verdict line, in source/collection order. */ static const char *expect_lines[] = { "rec_pass_a ... ok", "rec_assert ... FAIL", "rec_segv ... FAIL", "rec_div0 ... FAIL", "rec_pass_b ... ok", "2 passed, 3 failed, 0 skipped, 0 harness errors", "5 discovered, 5 selected, 5 started, 5 completed", }; static int record_continue(const char *bin) { char dir[] = "/tmp/at911_record_XXXXXX"; char out[256], cmd[4096], buf[8192]; int result = 1; if (mkdtemp(dir) == NULL) { fprintf(stderr, "911 FAIL: record workspace acquisition failed\n"); return 1; } snprintf(out, sizeof out, "%s/output", dir); /* `ww test` builds the fixture (auto-bundling lib/test) and runs it; * three failures remain visible in output while the public exit clamps. */ snprintf(cmd, sizeof cmd, "%s/ww test test/wcc/data/attest_record.ww > %s 2>/dev/null", bin, out); int rc = runwait(cmd); if (rc != 1) { fprintf(stderr, "911 FAIL: record-and-continue exit %d " "(expected canonical failure exit 1)\n", rc); goto done; } if (slurp(out, buf, sizeof buf) != 0) { fprintf(stderr, "911 FAIL: cannot read runner output\n"); goto done; } for (size_t i = 0; i < sizeof expect_lines / sizeof expect_lines[0]; i++) { if (strstr(buf, expect_lines[i]) == NULL) { fprintf(stderr, "911 FAIL: missing runner line '%s'\n" "--- got ---\n%s\n", expect_lines[i], buf); goto done; } } result = 0; done: { int cleanfail = 0; if (unlink(out) != 0 && errno != ENOENT) cleanfail = 1; if (rmdir(dir) != 0) cleanfail = 1; if (cleanfail) { fprintf(stderr, "911 FAIL: record workspace cleanup failed\n"); result = 1; } } return result; } static int all_pass(const char *bin) { char cmd[4096]; snprintf(cmd, sizeof cmd, "%s/ww test test/wcc/data/attest_pass.ww > /dev/null 2>&1", bin); int rc = runwait(cmd); if (rc != 0) { fprintf(stderr, "911 FAIL: all-pass fixture exit %d " "(expected 0)\n", rc); return 1; } return 0; } static int byteid(const char *bin) { char dir[] = "/tmp/at911_bid_XXXXXX"; char stemc[256], stemw[256], cs[256], ws[256], cmd[4096]; char scratchc[288], scratchw[288]; int rc = 1; if (mkdtemp(dir) == NULL) { fprintf(stderr, "911 FAIL: byteid workspace acquisition failed\n"); return 1; } snprintf(stemc, sizeof stemc, "%s/cstage", dir); snprintf(stemw, sizeof stemw, "%s/wwstage", dir); snprintf(cs, sizeof cs, "%s/cstage.s", dir); snprintf(ws, sizeof ws, "%s/wwstage.s", dir); snprintf(scratchc, sizeof scratchc, "%s.sepwork", stemc); snprintf(scratchw, sizeof scratchw, "%s.sepwork", stemw); /* #94 sep layout: `ww test -c -o ` carries -T to the root * so w6c synthesizes the test table + fork loop, and emits per-package * asm to .sepwork/ (compile-only, no harness run). The cstage * build (w6c) and wwstage build (w6c_ww) * must produce byte-identical asm across all packages. */ snprintf(cmd, sizeof cmd, "%s/ww test -c -o %s " "test/wcc/data/attest_record.ww > /dev/null 2>&1", bin, stemc); if (runwait(cmd) != 0) { fprintf(stderr, "911 FAIL: cstage ww test -c \n"); goto done; } snprintf(cmd, sizeof cmd, "%s/ww_ww test -c -o %s " "test/wcc/data/attest_record.ww > /dev/null 2>&1", bin, stemw); if (runwait(cmd) != 0) { fprintf(stderr, "911 FAIL: wwstage ww_ww test -c \n"); goto done; } snprintf(cmd, sizeof cmd, "cat %s.sepwork/*.s > %s 2>/dev/null", stemc, cs); if (runwait(cmd) != 0) { fprintf(stderr, "911 FAIL: cstage asm aggregation failed\n"); goto done; } snprintf(cmd, sizeof cmd, "cat %s.sepwork/*.s > %s 2>/dev/null", stemw, ws); if (runwait(cmd) != 0) { fprintf(stderr, "911 FAIL: wwstage asm aggregation failed\n"); goto done; } char bc[262144], bw[262144]; rc = 0; if (slurp(cs, bc, sizeof bc) < 0 || slurp(ws, bw, sizeof bw) < 0) { fprintf(stderr, "911 FAIL: slurp byteid asm\n"); rc = 1; } else if (strcmp(bc, bw) != 0) { fprintf(stderr, "911 FAIL: -T asm differs between stages\n"); rc = 1; } done: { int cleanfail = 0; if (unlink(cs) != 0 && errno != ENOENT) cleanfail = 1; if (unlink(ws) != 0 && errno != ENOENT) cleanfail = 1; if (unlink(stemc) != 0 && errno != ENOENT) cleanfail = 1; if (unlink(stemw) != 0 && errno != ENOENT) cleanfail = 1; snprintf(cmd, sizeof cmd, "rm -rf %s", scratchc); if (runwait(cmd) != 0) cleanfail = 1; snprintf(cmd, sizeof cmd, "rm -rf %s", scratchw); if (runwait(cmd) != 0) cleanfail = 1; if (rmdir(dir) != 0) cleanfail = 1; if (cleanfail) { fprintf(stderr, "911 FAIL: byteid workspace cleanup failed\n"); rc = 1; } } return rc; } int main(void) { const char *bin = absbin(); if (!bin) { fprintf(stderr, "911 FAIL: getcwd\n"); return 1; } if (record_continue(bin) != 0) return 1; if (all_pass(bin) != 0) return 1; if (byteid(bin) != 0) return 1; printf("@test record-and-continue: 3 fault classes recorded + run " "proceeds + exact counts + failure exit clamps to 1 + all-pass " "exit 0 + cs/ww byte-id (#17)\n"); return 0; }