94a of the C-mig2 split (rob rule-11): 13 Pattern-A gates that fed a .combined.ww to w6c/w6c_ww now drive two --sep builds (ww / ww_ww) and byte-diff the concatenated per-package .sepwork/*.s, mirroring #93's convention. Lands pre-flip while combined.ww still exists as the reversible safety net. Test-only; all 5 binary pins HOLD. 989_enumcap_run deferred to 94b (its decisive assertion is a combined.ww content diff, not a .s diff).
184 lines
5.5 KiB
C
184 lines
5.5 KiB
C
/*
|
|
* 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 exit with the failure count (nonzero).
|
|
* 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 <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 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",
|
|
};
|
|
|
|
static int
|
|
record_continue(const char *bin)
|
|
{
|
|
int pid = getpid();
|
|
char out[256], cmd[4096], buf[8192];
|
|
snprintf(out, sizeof out, "/tmp/at911_%d.out", pid);
|
|
|
|
/* `ww test` builds the fixture (auto-bundling lib/test) and runs it;
|
|
* the exit code is the runner's failure count. */
|
|
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 != 3) {
|
|
fprintf(stderr, "911 FAIL: record-and-continue exit %d "
|
|
"(expected 3 failures)\n", rc);
|
|
return 1;
|
|
}
|
|
if (slurp(out, buf, sizeof buf) != 0) {
|
|
fprintf(stderr, "911 FAIL: cannot read runner output\n");
|
|
return 1;
|
|
}
|
|
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);
|
|
unlink(out);
|
|
return 1;
|
|
}
|
|
}
|
|
unlink(out);
|
|
return 0;
|
|
}
|
|
|
|
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)
|
|
{
|
|
int pid = getpid();
|
|
char stemc[256], stemw[256], cs[256], ws[256], cmd[4096];
|
|
snprintf(stemc, sizeof stemc, "/tmp/at911_bid_c_%d", pid);
|
|
snprintf(stemw, sizeof stemw, "/tmp/at911_bid_w_%d", pid);
|
|
snprintf(cs, sizeof cs, "/tmp/at911_bid_cs_%d.s", pid);
|
|
snprintf(ws, sizeof ws, "/tmp/at911_bid_ws_%d.s", pid);
|
|
|
|
/* #94 sep layout: `ww test -c --sep -o <stem>` carries -T to the root
|
|
* so w6c synthesizes the test table + fork loop, and emits per-package
|
|
* asm to <stem>.sepwork/ (compile-only, no harness run; WW_PKGCACHE
|
|
* pinned to /tmp). The cstage build (w6c) and wwstage build (w6c_ww)
|
|
* must produce byte-identical asm across all packages. */
|
|
snprintf(cmd, sizeof cmd,
|
|
"WW_PKGCACHE=/tmp/at911_pkgc_c_%d %s/ww test -c --sep -o %s "
|
|
"test/wcc/data/attest_record.ww > /dev/null 2>&1", pid, bin, stemc);
|
|
if (runwait(cmd) != 0) {
|
|
fprintf(stderr, "911 FAIL: cstage ww test -c --sep\n");
|
|
return 1;
|
|
}
|
|
snprintf(cmd, sizeof cmd,
|
|
"WW_PKGCACHE=/tmp/at911_pkgc_w_%d %s/ww_ww test -c --sep -o %s "
|
|
"test/wcc/data/attest_record.ww > /dev/null 2>&1", pid, bin, stemw);
|
|
if (runwait(cmd) != 0) {
|
|
fprintf(stderr, "911 FAIL: wwstage ww_ww test -c --sep\n");
|
|
return 1;
|
|
}
|
|
snprintf(cmd, sizeof cmd, "cat %s.sepwork/*.s > %s 2>/dev/null", stemc, cs);
|
|
if (system(cmd)) {}
|
|
snprintf(cmd, sizeof cmd, "cat %s.sepwork/*.s > %s 2>/dev/null", stemw, ws);
|
|
if (system(cmd)) {}
|
|
|
|
char bc[262144], bw[262144];
|
|
int 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;
|
|
}
|
|
unlink(cs); unlink(ws);
|
|
snprintf(cmd, sizeof cmd, "rm -rf %s.sepwork %s.sepwork %s %s "
|
|
"/tmp/at911_pkgc_c_%d /tmp/at911_pkgc_w_%d",
|
|
stemc, stemw, stemc, stemw, pid, pid);
|
|
if (system(cmd)) {}
|
|
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 + counts + all-pass exit 0 + cs/ww byte-id (#17)\n");
|
|
return 0;
|
|
}
|