diff --git a/Makefile b/Makefile index 51761779..6d30bf36 100644 --- a/Makefile +++ b/Makefile @@ -255,6 +255,7 @@ TESTS = $(BIN)/test_smoke $(BIN)/test_lex $(BIN)/test_parse $(BIN)/test_check \ $(BIN)/test_match_slice_variant_run \ $(BIN)/test_str_abi_run \ $(BIN)/test_str_elem_cap_run \ + $(BIN)/test_str_field_cap_run \ $(BIN)/test_composite_call_arg \ $(BIN)/test_composite_call_arg_run \ $(BIN)/test_letdecl_zeroinit \ @@ -627,6 +628,12 @@ $(BIN)/test_str_elem_cap_run: test/wcc/932_str_elem_cap_run.c \ $(LIB)/libwwrt.a | $(BIN) $(CC) $(CFLAGS) -o $@ $< +$(BIN)/test_str_field_cap_run: test/wcc/933_str_field_cap_run.c \ + $(BIN)/ww $(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \ + $(BIN)/ww_ww $(BIN)/w6c_ww $(BIN)/w6a_ww $(BIN)/w6l_ww \ + $(LIB)/libwwrt.a | $(BIN) + $(CC) $(CFLAGS) -o $@ $< + $(BIN)/test_composite_call_arg: test/wcc/723_composite_call_arg.c \ $(BIN)/w6c $(BIN)/w6c_ww | $(BIN) $(CC) $(CFLAGS) -o $@ $< diff --git a/cmd/w6c/cgen.c b/cmd/w6c/cgen.c index 2549741e..1c13976a 100644 --- a/cmd/w6c/cgen.c +++ b/cmd/w6c/cgen.c @@ -5891,24 +5891,16 @@ cgexpr(Cg *c, Node *n, Local *locals) (void)is_global; break; } - /* str field: load (ptr, len) into (AX, BX) so the - * value flows through the str-rhs convention. */ - Type *str_fu = (f->type && f->type->kind == TY_NAMED) - ? f->type->under : f->type; - if (str_fu && str_fu->kind == TY_STR) { - ins2(c, A_MOVQ, - amem(base_reg, base_disp + (int)f->offset + 0), - areg(D_AX)); - ins2(c, A_MOVQ, - amem(base_reg, base_disp + (int)f->offset + 8), - areg(D_BX)); - break; - } - /* slice field: load (ptr, len, cap) into (AX, BX, CX) - * so the value flows through the slice-rhs convention. + /* str IS []u8 — same 3-word {ptr,len,cap} as a slice + * field: load (ptr, len, cap) into (AX, BX, CX) so the + * value flows through the slice-rhs convention. str + * folds onto the slice arm (#1/Phase 3 collapse). * base_reg may be CX for globals; load .cap LAST so * the base survives the earlier reads. */ - if (str_fu && str_fu->kind == TY_SLICE) { + Type *str_fu = (f->type && f->type->kind == TY_NAMED) + ? f->type->under : f->type; + if ((str_fu && str_fu->kind == TY_SLICE) || + type_isstr(f->type)) { ins2(c, A_MOVQ, amem(base_reg, base_disp + (int)f->offset + 0), areg(D_AX)); @@ -6008,27 +6000,16 @@ cgexpr(Cg *c, Node *n, Local *locals) areg(D_R8)); break; } - /* str field through *struct: read len into a - * scratch first (it's at +8) so loading ptr - * into AX last leaves (AX=ptr, BX=len). We - * use CX as the scratch, then move CX→BX. */ - Type *str_fu = (f->type && f->type->kind == TY_NAMED) - ? f->type->under : f->type; - if (str_fu && str_fu->kind == TY_STR) { - ins2(c, A_MOVQ, - amem(D_BX, (int)f->offset + 8), - areg(D_CX)); - ins2(c, A_MOVQ, - amem(D_BX, (int)f->offset + 0), - areg(D_AX)); - ins2(c, A_MOVQ, areg(D_CX), areg(D_BX)); - break; - } - /* slice field through *struct: load (ptr, len, + /* str IS []u8 — same 3-word {ptr,len,cap} as a + * slice field through *struct: load (ptr, len, * cap) into (AX, BX, CX). BX holds the *struct * pointer, so load .len LAST — the earlier loads - * still index off the original base. */ - if (str_fu && str_fu->kind == TY_SLICE) { + * still index off the original base. str folds + * onto the slice arm (#1/Phase 3 collapse). */ + Type *str_fu = (f->type && f->type->kind == TY_NAMED) + ? f->type->under : f->type; + if ((str_fu && str_fu->kind == TY_SLICE) || + type_isstr(f->type)) { ins2(c, A_MOVQ, amem(D_BX, (int)f->offset + 0), areg(D_AX)); diff --git a/selfhost/cmd/w6c/main.combined.ww b/selfhost/cmd/w6c/main.combined.ww index 9d385e8a..3fc849b1 100644 --- a/selfhost/cmd/w6c/main.combined.ww +++ b/selfhost/cmd/w6c/main.combined.ww @@ -15195,26 +15195,18 @@ fn cgdot(c: *cgen, n: *node) void = { fi.foff, tsz); return; }; - // str field via *struct: load len into a - // scratch first (so loading ptr into AX - // last leaves (AX=ptr, BX=len)). + // str IS []u8 — same 3-word {ptr,len,cap} + // as a slice field via *struct: load + // (ptr, len, cap) into (AX, BX, CX). BX + // holds the *struct pointer, so load .len + // LAST so the earlier reads still index + // off the base. str folds onto the slice + // arm (#1/Phase 3 collapse; cite cstage + // cgen.c N_DOT *struct S2). emitline("\tMOVQ\t"); emitoff(lc.off: i64); emitline("(BP), BX\n"); - if (isstrtype(c, fi.tnode)) { - emitline("\tMOVQ\t"); - emitdispreg((fi.foff + 8): i64, "BX"); - emitline(", CX\n"); - emitline("\tMOVQ\t"); - emitdispreg(fi.foff: i64, "BX"); - emitline(", AX\n"); - emitline("\tMOVQ\tCX, BX\n"); - } else { if (isslicetype(c, fi.tnode)) { - // slice field via *struct: load - // (ptr, len, cap) into (AX, BX, CX). - // BX holds the *struct pointer, so - // load .len LAST so the earlier - // reads still index off the base. + if (isstrtype(c, fi.tnode) || isslicetype(c, fi.tnode)) { emitline("\tMOVQ\t"); emitdispreg(fi.foff: i64, "BX"); emitline(", AX\n"); @@ -15244,7 +15236,7 @@ fn cgdot(c: *cgen, n: *node) void = { emitline("\t"); emitdispreg(fi.foff: i64, "BX"); emitline(", AX\n"); - }; }; }; + }; }; return; }; fi = fi.finext; @@ -15279,19 +15271,13 @@ fn cgdot(c: *cgen, n: *node) void = { lc.off + fi.foff, tsz); return; }; - // str field: load both halves so chained - // `.ptr` / `.len` see (AX=ptr, BX=len). - if (isstrtype(c, fi.tnode)) { - emitline("\tMOVQ\t"); - emitoff((lc.off + fi.foff): i64); - emitline("(BP), AX\n"); - emitline("\tMOVQ\t"); - emitoff((lc.off + fi.foff + 8): i64); - emitline("(BP), BX\n"); - } else { if (isslicetype(c, fi.tnode)) { - // slice field: load (ptr, len, cap) - // into (AX, BX, CX). Base is BP so - // no aliasing — order doesn't matter. + // str IS []u8 — same 3-word {ptr,len,cap} + // as a slice field: load (ptr, len, cap) + // into (AX, BX, CX). Base is BP so no + // aliasing — order doesn't matter. str + // folds onto the slice arm (#1/Phase 3 + // collapse; cite cstage cgen.c N_DOT S1). + if (isstrtype(c, fi.tnode) || isslicetype(c, fi.tnode)) { emitline("\tMOVQ\t"); emitoff((lc.off + fi.foff): i64); emitline("(BP), AX\n"); @@ -15317,7 +15303,7 @@ fn cgdot(c: *cgen, n: *node) void = { emitline("\t"); emitoff((lc.off + fi.foff): i64); emitline("(BP), AX\n"); - }; }; }; + }; }; return; }; fi = fi.finext; @@ -15509,6 +15495,12 @@ fn cgdot(c: *cgen, n: *node) void = { cgloadtaggedfield(c, "CX", fi.foff, tsz); return; }; + // str IS []u8 — 3-word {ptr,len,cap}, the local + // slice-field arm (BP) retargeted to the CX global + // base. cap→CX LAST: CX is the base, so .ptr/.len + // must read first. cstage folds local+global in one + // base_reg arm; ww splits them, so this global arm + // carries its own lift (filed divergence task). if (isstrtype(c, fi.tnode)) { emitline("\tMOVQ\t"); emitdispreg(fi.foff: i64, "CX"); @@ -15516,6 +15508,9 @@ fn cgdot(c: *cgen, n: *node) void = { emitline("\tMOVQ\t"); emitdispreg((fi.foff + 8): i64, "CX"); emitline(", BX\n"); + emitline("\tMOVQ\t"); + emitdispreg((fi.foff + 16): i64, "CX"); + emitline(", CX\n"); } else { if (isfloattype(c, fi.tnode)) { // f64/f32 global field: route through X0. let mov: str = "MOVSD"; diff --git a/selfhost/cmd/wcc/cgenexpr.ww b/selfhost/cmd/wcc/cgenexpr.ww index bea27797..7b1efb80 100644 --- a/selfhost/cmd/wcc/cgenexpr.ww +++ b/selfhost/cmd/wcc/cgenexpr.ww @@ -1367,26 +1367,18 @@ fn cgdot(c: *cgen, n: *node) void = { fi.foff, tsz); return; }; - // str field via *struct: load len into a - // scratch first (so loading ptr into AX - // last leaves (AX=ptr, BX=len)). + // str IS []u8 — same 3-word {ptr,len,cap} + // as a slice field via *struct: load + // (ptr, len, cap) into (AX, BX, CX). BX + // holds the *struct pointer, so load .len + // LAST so the earlier reads still index + // off the base. str folds onto the slice + // arm (#1/Phase 3 collapse; cite cstage + // cgen.c N_DOT *struct S2). emitline("\tMOVQ\t"); emitoff(lc.off: i64); emitline("(BP), BX\n"); - if (isstrtype(c, fi.tnode)) { - emitline("\tMOVQ\t"); - emitdispreg((fi.foff + 8): i64, "BX"); - emitline(", CX\n"); - emitline("\tMOVQ\t"); - emitdispreg(fi.foff: i64, "BX"); - emitline(", AX\n"); - emitline("\tMOVQ\tCX, BX\n"); - } else { if (isslicetype(c, fi.tnode)) { - // slice field via *struct: load - // (ptr, len, cap) into (AX, BX, CX). - // BX holds the *struct pointer, so - // load .len LAST so the earlier - // reads still index off the base. + if (isstrtype(c, fi.tnode) || isslicetype(c, fi.tnode)) { emitline("\tMOVQ\t"); emitdispreg(fi.foff: i64, "BX"); emitline(", AX\n"); @@ -1416,7 +1408,7 @@ fn cgdot(c: *cgen, n: *node) void = { emitline("\t"); emitdispreg(fi.foff: i64, "BX"); emitline(", AX\n"); - }; }; }; + }; }; return; }; fi = fi.finext; @@ -1451,19 +1443,13 @@ fn cgdot(c: *cgen, n: *node) void = { lc.off + fi.foff, tsz); return; }; - // str field: load both halves so chained - // `.ptr` / `.len` see (AX=ptr, BX=len). - if (isstrtype(c, fi.tnode)) { - emitline("\tMOVQ\t"); - emitoff((lc.off + fi.foff): i64); - emitline("(BP), AX\n"); - emitline("\tMOVQ\t"); - emitoff((lc.off + fi.foff + 8): i64); - emitline("(BP), BX\n"); - } else { if (isslicetype(c, fi.tnode)) { - // slice field: load (ptr, len, cap) - // into (AX, BX, CX). Base is BP so - // no aliasing — order doesn't matter. + // str IS []u8 — same 3-word {ptr,len,cap} + // as a slice field: load (ptr, len, cap) + // into (AX, BX, CX). Base is BP so no + // aliasing — order doesn't matter. str + // folds onto the slice arm (#1/Phase 3 + // collapse; cite cstage cgen.c N_DOT S1). + if (isstrtype(c, fi.tnode) || isslicetype(c, fi.tnode)) { emitline("\tMOVQ\t"); emitoff((lc.off + fi.foff): i64); emitline("(BP), AX\n"); @@ -1489,7 +1475,7 @@ fn cgdot(c: *cgen, n: *node) void = { emitline("\t"); emitoff((lc.off + fi.foff): i64); emitline("(BP), AX\n"); - }; }; }; + }; }; return; }; fi = fi.finext; @@ -1681,6 +1667,12 @@ fn cgdot(c: *cgen, n: *node) void = { cgloadtaggedfield(c, "CX", fi.foff, tsz); return; }; + // str IS []u8 — 3-word {ptr,len,cap}, the local + // slice-field arm (BP) retargeted to the CX global + // base. cap→CX LAST: CX is the base, so .ptr/.len + // must read first. cstage folds local+global in one + // base_reg arm; ww splits them, so this global arm + // carries its own lift (filed divergence task). if (isstrtype(c, fi.tnode)) { emitline("\tMOVQ\t"); emitdispreg(fi.foff: i64, "CX"); @@ -1688,6 +1680,9 @@ fn cgdot(c: *cgen, n: *node) void = { emitline("\tMOVQ\t"); emitdispreg((fi.foff + 8): i64, "CX"); emitline(", BX\n"); + emitline("\tMOVQ\t"); + emitdispreg((fi.foff + 16): i64, "CX"); + emitline(", CX\n"); } else { if (isfloattype(c, fi.tnode)) { // f64/f32 global field: route through X0. let mov: str = "MOVSD"; diff --git a/selfhost/cmd/wwdump/main.combined.ww b/selfhost/cmd/wwdump/main.combined.ww index ba37ee98..a2749bcc 100644 --- a/selfhost/cmd/wwdump/main.combined.ww +++ b/selfhost/cmd/wwdump/main.combined.ww @@ -15195,26 +15195,18 @@ fn cgdot(c: *cgen, n: *node) void = { fi.foff, tsz); return; }; - // str field via *struct: load len into a - // scratch first (so loading ptr into AX - // last leaves (AX=ptr, BX=len)). + // str IS []u8 — same 3-word {ptr,len,cap} + // as a slice field via *struct: load + // (ptr, len, cap) into (AX, BX, CX). BX + // holds the *struct pointer, so load .len + // LAST so the earlier reads still index + // off the base. str folds onto the slice + // arm (#1/Phase 3 collapse; cite cstage + // cgen.c N_DOT *struct S2). emitline("\tMOVQ\t"); emitoff(lc.off: i64); emitline("(BP), BX\n"); - if (isstrtype(c, fi.tnode)) { - emitline("\tMOVQ\t"); - emitdispreg((fi.foff + 8): i64, "BX"); - emitline(", CX\n"); - emitline("\tMOVQ\t"); - emitdispreg(fi.foff: i64, "BX"); - emitline(", AX\n"); - emitline("\tMOVQ\tCX, BX\n"); - } else { if (isslicetype(c, fi.tnode)) { - // slice field via *struct: load - // (ptr, len, cap) into (AX, BX, CX). - // BX holds the *struct pointer, so - // load .len LAST so the earlier - // reads still index off the base. + if (isstrtype(c, fi.tnode) || isslicetype(c, fi.tnode)) { emitline("\tMOVQ\t"); emitdispreg(fi.foff: i64, "BX"); emitline(", AX\n"); @@ -15244,7 +15236,7 @@ fn cgdot(c: *cgen, n: *node) void = { emitline("\t"); emitdispreg(fi.foff: i64, "BX"); emitline(", AX\n"); - }; }; }; + }; }; return; }; fi = fi.finext; @@ -15279,19 +15271,13 @@ fn cgdot(c: *cgen, n: *node) void = { lc.off + fi.foff, tsz); return; }; - // str field: load both halves so chained - // `.ptr` / `.len` see (AX=ptr, BX=len). - if (isstrtype(c, fi.tnode)) { - emitline("\tMOVQ\t"); - emitoff((lc.off + fi.foff): i64); - emitline("(BP), AX\n"); - emitline("\tMOVQ\t"); - emitoff((lc.off + fi.foff + 8): i64); - emitline("(BP), BX\n"); - } else { if (isslicetype(c, fi.tnode)) { - // slice field: load (ptr, len, cap) - // into (AX, BX, CX). Base is BP so - // no aliasing — order doesn't matter. + // str IS []u8 — same 3-word {ptr,len,cap} + // as a slice field: load (ptr, len, cap) + // into (AX, BX, CX). Base is BP so no + // aliasing — order doesn't matter. str + // folds onto the slice arm (#1/Phase 3 + // collapse; cite cstage cgen.c N_DOT S1). + if (isstrtype(c, fi.tnode) || isslicetype(c, fi.tnode)) { emitline("\tMOVQ\t"); emitoff((lc.off + fi.foff): i64); emitline("(BP), AX\n"); @@ -15317,7 +15303,7 @@ fn cgdot(c: *cgen, n: *node) void = { emitline("\t"); emitoff((lc.off + fi.foff): i64); emitline("(BP), AX\n"); - }; }; }; + }; }; return; }; fi = fi.finext; @@ -15509,6 +15495,12 @@ fn cgdot(c: *cgen, n: *node) void = { cgloadtaggedfield(c, "CX", fi.foff, tsz); return; }; + // str IS []u8 — 3-word {ptr,len,cap}, the local + // slice-field arm (BP) retargeted to the CX global + // base. cap→CX LAST: CX is the base, so .ptr/.len + // must read first. cstage folds local+global in one + // base_reg arm; ww splits them, so this global arm + // carries its own lift (filed divergence task). if (isstrtype(c, fi.tnode)) { emitline("\tMOVQ\t"); emitdispreg(fi.foff: i64, "CX"); @@ -15516,6 +15508,9 @@ fn cgdot(c: *cgen, n: *node) void = { emitline("\tMOVQ\t"); emitdispreg((fi.foff + 8): i64, "CX"); emitline(", BX\n"); + emitline("\tMOVQ\t"); + emitdispreg((fi.foff + 16): i64, "CX"); + emitline(", CX\n"); } else { if (isfloattype(c, fi.tnode)) { // f64/f32 global field: route through X0. let mov: str = "MOVSD"; diff --git a/test/wcc/933_str_field_cap_run.c b/test/wcc/933_str_field_cap_run.c new file mode 100644 index 00000000..680df3b2 --- /dev/null +++ b/test/wcc/933_str_field_cap_run.c @@ -0,0 +1,197 @@ +/* + * 933_str_field_cap_run — runtime coverage for the C4.6 fold: reading a + * str-typed FIELD of a struct (N_DOT value read) must load the full 24B + * {ptr,len,cap} header, not just {ptr,len}. str is 24B since Phase 2 (#1); + * pre-C4.6 the N_DOT str-field arms loaded 2 words and dropped cap. + * + * The byte-id gates (990-997) can't catch a symmetric 2-word miscompile: + * if both stages drop cap identically, byte-id passes silently. So this + * pins the *runtime* contract — build each fixture through both the cstage + * `ww` and the wwstage `ww_ww` driver and confirm the assertions hold + * (exit 0). The global row is the load-bearing case: in ww the global + * struct-field load is a separate arm with no slice sibling (cstage folds + * local+global in one base_reg arm; ww splits them), so a cap-drop there + * would hide from the local-field rows. + * + * Each row POISONS the source str so cap != len (a `.cap =` pseudo-field + * write, no malloc / no import — self-contained, so ww_ww writes + * intermediates only next to the /tmp source). A 2-word field read leaves + * cap = stale, so the read-back .cap mismatches the poison and the row + * fails. The cap word is observed through `let s: str = ` (a 3-word + * copy into the slot) then `s.cap` (an N_IDENT pseudo-field read off the + * slot) — mirrors the 932 observation shape. + * + * Sites (C4.6 S1 + S2, case A): + * - s1local : `st.f` — direct struct local field (base BP). + * - s1global : `g.f` — direct struct global field (base CX). + * - s2ptr : `pst.f` — field via a *struct local (base BX, deref). + */ +#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; +} + +struct row { const char *label; const char *src; int want; }; + +static const struct row rows[] = { + /* S1 local — `st.f` direct struct local field. Poison cap=8 + * (len=2). spoil() interposes a call between the field store and + * the read: a call clobbers caller-saved CX, so a broken 2-word + * read leaves cap = spoil's leftover (44), not the lingering store + * value — without it CX would coincidentally still hold the poison + * the `st.f = p` store left behind and the row wouldn't discriminate. */ + { "s1local_field", + "type rec = struct { f: str };\n" + "fn spoil() i32 = {\n" + " let z: str = \"zzzz\";\n" + " z.cap = 44i32;\n" + " let w: str = z;\n" + " return w.cap: i32;\n" + "};\n" + "export fn main() i32 = {\n" + " let p: str = \"hi\";\n" + " p.cap = 8i32;\n" + " let st: rec;\n" + " st.f = p;\n" + " let junk: i32 = spoil();\n" + " let s: str = st.f;\n" + " if (s.cap: i32 != 8) { return 1; };\n" + " if (s.len: i32 != 2) { return 2; };\n" + " if (junk != 44) { return 3; };\n" + " return 0;\n" + "};\n", + 0 }, + /* S1 global — `g.f` direct struct global field (base CX path). + * The no-local-sibling arm in ww; poison cap=9 (len=5). */ + { "s1global_field", + "type rec = struct { f: str };\n" + "let g: rec;\n" + "export fn main() i32 = {\n" + " let p: str = \"world\";\n" + " p.cap = 9i32;\n" + " g.f = p;\n" + " let s: str = g.f;\n" + " if (s.cap: i32 != 9) { return 1; };\n" + " if (s.len: i32 != 5) { return 2; };\n" + " return 0;\n" + "};\n", + 0 }, + /* S2 case A — `pst.f` field via a *struct local (deref, base BX). + * Poison cap=7 (len=3). */ + { "s2ptr_field", + "type rec = struct { f: str };\n" + "export fn main() i32 = {\n" + " let p: str = \"abc\";\n" + " p.cap = 7i32;\n" + " let st: rec;\n" + " st.f = p;\n" + " let pst: *rec = &st;\n" + " let s: str = pst.f;\n" + " if (s.cap: i32 != 7) { return 1; };\n" + " if (s.len: i32 != 3) { return 2; };\n" + " return 0;\n" + "};\n", + 0 }, +}; + +static int +run_driver(const char *driver, const struct row *r, int i) +{ + char src[96], tmpdir[96], cmd[1024]; + snprintf(src, sizeof src, "/tmp/strfieldcap_%d_%d.ww", getpid(), i); + snprintf(tmpdir, sizeof tmpdir, "/tmp/strfieldcap_%d_d_%d", getpid(), i); + + FILE *f = fopen(src, "wb"); + if (!f) return -1; + fputs(r->src, f); + fclose(f); + + mkdir(tmpdir, 0755); + snprintf(cmd, sizeof cmd, "cd %s && %s build %s", + tmpdir, driver, src); + if (runwait(cmd) != 0) { + fprintf(stderr, "row[%s]: build via %s failed\n", + r->label, driver); + unlink(src); rmdir(tmpdir); + return -1; + } + + const char *base = strrchr(src, '/'); + base = base ? base + 1 : src; + char outbin[160]; + snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); + char *dot = strrchr(outbin, '.'); + if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; + int got = runwait(outbin); + + unlink(src); unlink(outbin); rmdir(tmpdir); + return got; +} + +int +main(void) +{ + const char *bin = getenv("BIN"); + if (!bin) bin = "out/bin"; + char absbin[512]; + if (bin[0] != '/') { + char cwd[256]; + if (getcwd(cwd, sizeof cwd) == NULL) return 1; + snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin); + bin = absbin; + } + + char cdrv[640]; + snprintf(cdrv, sizeof cdrv, "%s/ww", bin); + char wdrv[640]; + snprintf(wdrv, sizeof wdrv, "%s/ww_ww", bin); + + struct { const char *name; const char *path; int gated_on_existence; } + drivers[] = { + { "cstage", cdrv, 0 }, + { "wwstage", wdrv, 1 }, + { NULL, NULL, 0 }, + }; + + int n = (int)(sizeof rows / sizeof rows[0]); + int total = 0, fail = 0; + for (int d = 0; drivers[d].name; d++) { + if (drivers[d].gated_on_existence + && access(drivers[d].path, X_OK) != 0) { + fprintf(stderr, + "str_field_cap_run: skip %s (no %s)\n", + drivers[d].name, drivers[d].path); + continue; + } + for (int i = 0; i < n; i++) { + int got = run_driver(drivers[d].path, &rows[i], i); + total++; + if (got != rows[i].want) { + fprintf(stderr, + "str_field_cap_run[%s][%s]: exit=%d want=%d\n", + drivers[d].name, rows[i].label, + got, rows[i].want); + fail++; + } + } + } + + if (fail) { + fprintf(stderr, "str_field_cap_run: %d/%d fixtures failed\n", + fail, total); + return 1; + } + printf("str_field_cap_run: %d/%d ok\n", total, total); + return 0; +}