nx_workmix_gate.nx source
↩ module page · 139 lines · 11352 B
1// nx_workmix_gate.nx -- gate for THE WORK-MIX RULER (ecosystem EC56, nx_workmix_lib). In-process on PLANTED rows: a ledger,
2// two board plans and a class table, so every class, the re-land rule and the feature-deps index each meet a tooth and a
3// negative control. Nothing here reads the production ledger. The fixture asserts its own condition first.
4// license_tier: ORIGINAL No hw writes (Rule 26).
5import "nx_syscalls.nx"
6import "nx_workmix_lib.nx"
7import "nx_gate_verdict.nx"
8
9const G_I64: i64 = 8
10const G_LO: i64 = 1000 // the fixture window [1000, 2000): every planted epoch is placed against it
11const G_HI: i64 = 2000
12const G_BIG: i64 = 9000000000000000 // sixteen digits in every slot: the status line must still fit its derived bound
13const G_CONF: *u8 = "board|prod|product|x\nboard|ops|operations|x\nboard|bad|neither|x\n"
14const G_PLAN_PROD: *u8 = "rung|F1|t|-|n|Organ|2|ops:E1\nrung|F2|t|-|n|Organ|1|F1, E9\nrung|S1|t|-|n|Organ|1|-\nrungrole|S1|substrate|T1|why\nrungrole|X1|superseded|T1|why\nrung|X1|t|-|n|Organ|1|-\n"
15const G_PLAN_OPS: *u8 = "rung|E1|t|-|n|Organ|3|-\nrung|E2|t|-|n|Organ|1|-\nrung|C1|t|-|n|Organ|1|-\nrungrole|C1|contender|T1|why\n"
16const G_LEDGER: *u8 = "land|prod|F1|1100|20\nland|ops|E1|1150|5\nland|ops|E1|1200|30\nland|ops|E2|1300|10\nland|ops|C1|1400|10\nland|prod|S1|1500|10\nland|prod|X1|1600|10\nland|ghost|G1|1700|10\nretract|prod|F2|1750\nland|prod|F2|1800|10\nland|prod|F2|900|10\nland|prod|F1|2500|10\nland|prod|F1|bad|10\nland|prod|short\nopen|prod|O1|1050|1060|10\nopen|prod|O2|500|1900|10\n"
17
18func g_count_nl(b: *u8, n: i64) -> i64 {
19 var k: i64 = 0
20 var i: i64 = 0
21 while i < n { if b[i] == (CES_CH_NL as u8) { k = k + 1 } i = i + 1 }
22 return k
23}
24func g_contains(b: *u8, n: i64, lit: *u8) -> i64 {
25 let l: i64 = ces_slen(lit)
26 var i: i64 = 0
27 while i + l <= n {
28 if ces_span_is(b, i, l, lit) == 1 { return 1 }
29 i = i + 1
30 }
31 return 0
32}
33
34func main(argc: i64, argv: *i64) -> i64 {
35 let c: *i64 = gv_ctr()
36 gv_head("nx_workmix_gate -- the work-mix ruler: board class, rungrole, the class rule, re-land after retract, the feature-deps index, the census partition, the status line" as *u8)
37 let conf: *u8 = G_CONF
38 let cn: i64 = ces_slen(conf)
39 let pp: *u8 = G_PLAN_PROD
40 let ppn: i64 = ces_slen(pp)
41 let po: *u8 = G_PLAN_OPS
42 let pon: i64 = ces_slen(po)
43 let led: *u8 = G_LEDGER
44 let ln: i64 = ces_slen(led)
45 // the class table
46 gv_check_eq("board-class-product" as *u8, wm_board_class(conf, cn, "prod" as *u8), WM_B_PRODUCT, c)
47 gv_check_eq("board-class-operations" as *u8, wm_board_class(conf, cn, "ops" as *u8), WM_B_OPERATIONS, c)
48 gv_check_eq("neg-control-board-class-an-unlisted-board-is-NONE-never-a-default" as *u8, wm_board_class(conf, cn, "ghost" as *u8), WM_B_NONE, c)
49 gv_check_eq("neg-control-board-class-a-word-that-is-neither-is-NONE" as *u8, wm_board_class(conf, cn, "bad" as *u8), WM_B_NONE, c)
50 gv_check_eq("neg-control-board-class-a-PREFIX-of-a-listed-board-is-NONE (pro is not prod)" as *u8, wm_board_class(conf, cn, "pro" as *u8), WM_B_NONE, c)
51 // the rungrole read
52 gv_check_eq("role-substrate-is-read-off-the-plan (S1)" as *u8, wm_rung_role(pp, ppn, "S1" as *u8, 0, 2), LD_R_SUBSTRATE, c)
53 gv_check_eq("role-contender (C1)" as *u8, wm_rung_role(po, pon, "C1" as *u8, 0, 2), LD_R_CONTENDER, c)
54 gv_check_eq("neg-control-role-a-rung-with-no-rungrole-row-is-NONE (F1)" as *u8, wm_rung_role(pp, ppn, "F1" as *u8, 0, 2), LD_NONE, c)
55 gv_check_eq("neg-control-role-a-PREFIX-of-a-placed-rung-is-NONE (S is not S1)" as *u8, wm_rung_role(pp, ppn, "S1" as *u8, 0, 1), LD_NONE, c)
56 // the class rule
57 gv_check_eq("class-contender-is-FEATURE-even-on-an-operations-board" as *u8, wm_class_of(LD_R_CONTENDER, WM_B_OPERATIONS), WM_C_FEATURE, c)
58 gv_check_eq("class-arm-is-FEATURE" as *u8, wm_class_of(LD_R_ARM, WM_B_NONE), WM_C_FEATURE, c)
59 gv_check_eq("class-substrate-is-ENABLEMENT-even-on-a-product-board" as *u8, wm_class_of(LD_R_SUBSTRATE, WM_B_PRODUCT), WM_C_ENABLEMENT, c)
60 gv_check_eq("class-no-role-on-a-product-board-is-FEATURE" as *u8, wm_class_of(LD_NONE, WM_B_PRODUCT), WM_C_FEATURE, c)
61 gv_check_eq("class-no-role-on-an-operations-board-is-ENABLEMENT" as *u8, wm_class_of(LD_NONE, WM_B_OPERATIONS), WM_C_ENABLEMENT, c)
62 gv_check_eq("neg-control-class-no-role-and-no-board-class-is-UNCLASSED-never-a-guess" as *u8, wm_class_of(LD_NONE, WM_B_NONE), WM_C_UNCLASSED, c)
63 gv_check_eq("neg-control-class-superseded-is-UNCLASSED-whatever-the-board" as *u8, wm_class_of(LD_R_SUPERSEDED, WM_B_PRODUCT), WM_C_UNCLASSED, c)
64 // deps tokens
65 let dt: *u8 = "EC55, ops:E1;EC6" as *u8
66 let dtn: i64 = ces_slen(dt)
67 gv_check_eq("deps-a-qualified-token-is-found-between-separators" as *u8, wm_deps_has(dt, 0, dtn, "ops:E1" as *u8, 6), 1, c)
68 gv_check_eq("deps-the-last-token-is-found" as *u8, wm_deps_has(dt, 0, dtn, "EC6" as *u8, 3), 1, c)
69 gv_check_eq("neg-control-deps-a-PREFIX-of-a-token-never-matches (EC5 inside EC55)" as *u8, wm_deps_has(dt, 0, dtn, "EC5" as *u8, 3), 0, c)
70 gv_check_eq("neg-control-deps-an-empty-token-matches-nothing" as *u8, wm_deps_has(dt, 0, dtn, "" as *u8, 0), 0, c)
71 // the feature-deps index
72 let idx: *u8 = sys_mmap(wm_index_bound(ppn, "prod" as *u8) + wm_index_bound(pon, "ops" as *u8))
73 var idxn: i64 = wm_index_board(pp, ppn, "prod" as *u8, WM_B_PRODUCT, idx, 0)
74 idxn = wm_index_board(po, pon, "ops" as *u8, WM_B_OPERATIONS, idx, idxn)
75 let off: *i64 = sys_mmap(G_I64) as *i64
76 gv_check_eq("index-holds-one-row-per-FEATURE-rung-that-declares-deps (F1 and F2; S1 declares a dash, the ops rungs declare none)" as *u8, g_count_nl(idx, idxn), 2, c)
77 gv_check_eq("index-a-feature-rung-on-ANOTHER-board-names-the-rung-qualified (prod F1 stands on ops:E1)" as *u8, wm_named_by_feature(idx, idxn, "ops" as *u8, "E1" as *u8, "ops:E1" as *u8, off), 1, c)
78 gv_check_eq("index-a-feature-rung-on-the-SAME-board-names-the-rung-bare (prod F2 stands on F1)" as *u8, wm_named_by_feature(idx, idxn, "prod" as *u8, "F1" as *u8, "prod:F1" as *u8, off), 1, c)
79 gv_check_eq("neg-control-index-a-BARE-name-never-crosses-boards (ops has no F1 though prod names one)" as *u8, wm_named_by_feature(idx, idxn, "ops" as *u8, "F1" as *u8, "ops:F1" as *u8, off), 0, c)
80 gv_check_eq("neg-control-index-a-rung-nobody-names-is-unnamed (E2)" as *u8, wm_named_by_feature(idx, idxn, "ops" as *u8, "E2" as *u8, "ops:E2" as *u8, off), 0, c)
81 // the census
82 let names: *i64 = sys_mmap(2 * G_I64) as *i64
83 let pbuf: *i64 = sys_mmap(2 * G_I64) as *i64
84 let plen: *i64 = sys_mmap(2 * G_I64) as *i64
85 let nm0: *u8 = "prod" as *u8
86 let nm1: *u8 = "ops" as *u8
87 names[0] = nm0 as i64
88 names[1] = nm1 as i64
89 pbuf[0] = pp as i64
90 pbuf[1] = po as i64
91 plen[0] = ppn
92 plen[1] = pon
93 let acc: *i64 = sys_mmap(WM_A_SLOTS * G_I64) as *i64
94 let landed: i64 = wm_mix_census(led, ln, G_LO, G_HI, conf, cn, names, pbuf, plen, 2, idx, idxn, acc)
95 gv_check_eq("fixture-reached-the-condition: nine land rows fall inside the window (one before it, one after it and two malformed stay out)" as *u8, landed, 9, c)
96 gv_check_eq("census-FEATURE (F1 by its product board, C1 by its contender role)" as *u8, acc[WM_A_EV + WM_C_FEATURE], 2, c)
97 gv_check_eq("census-ENABLEMENT (E1 twice, E2, and S1 by its substrate role)" as *u8, acc[WM_A_EV + WM_C_ENABLEMENT], 4, c)
98 gv_check_eq("census-REWORK-is-a-land-whose-newest-earlier-event-is-a-retract (F2 at 1800 after the retract at 1750)" as *u8, acc[WM_A_EV + WM_C_REWORK], 1, c)
99 gv_check_eq("anti-vacuity-a-rung-that-lands-TWICE-is-not-rework-by-that-alone (E1 at 1150 and 1200 are both ENABLEMENT: a land row is a slice)" as *u8, acc[WM_A_RELANDS], 1, c)
100 gv_check_eq("census-UNCLASSED-is-its-own-bucket (X1 superseded, G1 on a board with no plan and no class)" as *u8, acc[WM_A_EV + WM_C_UNCLASSED], 2, c)
101 gv_check_eq("partition-the-classes-SUM-to-the-land-rows-of-the-window" as *u8, wm_class_sum(acc), acc[WM_A_LAND], c)
102 gv_check_eq("census-retracts-are-events-of-their-own" as *u8, acc[WM_A_RETRACTS], 1, c)
103 gv_check_eq("census-enablement-that-FEEDS-a-feature (E1, both slices)" as *u8, acc[WM_A_ENAB_NAMED], 2, c)
104 gv_check_eq("census-enablement-NO-feature-rung-names (E2 and S1): the class to shrink" as *u8, acc[WM_A_ENAB_UNNAMED], 2, c)
105 gv_check_eq("partition-named-plus-unnamed-is-ENABLEMENT" as *u8, acc[WM_A_ENAB_NAMED] + acc[WM_A_ENAB_UNNAMED], acc[WM_A_EV + WM_C_ENABLEMENT], c)
106 gv_check_eq("provenance-classed-by-a-rungrole-row (C1, S1)" as *u8, acc[WM_A_BY_ROLE], 2, c)
107 gv_check_eq("provenance-classed-by-the-board-table (F1, E1 twice, E2)" as *u8, acc[WM_A_BY_BOARD], 4, c)
108 gv_check_eq("census-a-land-row-on-a-board-whose-plan-was-not-read-is-counted (ghost)" as *u8, acc[WM_A_NOPLAN], 1, c)
109 gv_check_eq("census-started-in-the-window-and-not-landed (O1; O2 started before it)" as *u8, acc[WM_A_OPENED], 1, c)
110 gv_check_eq("neg-control-census-a-bad-epoch-and-a-short-row-are-MALFORMED: counted, never half-read" as *u8, acc[WM_A_MALFORMED], 2, c)
111 gv_check_eq("cost-FEATURE-deci-u (20 + 10)" as *u8, acc[WM_A_DECIU + WM_C_FEATURE], 30, c)
112 gv_check_eq("cost-ENABLEMENT-deci-u (5 + 30 + 10 + 10)" as *u8, acc[WM_A_DECIU + WM_C_ENABLEMENT], 55, c)
113 gv_check_eq("cost-the-LAST-class-slot-is-written (UNCLASSED 10 + 10)" as *u8, acc[WM_A_DECIU + WM_C_UNCLASSED], 20, c)
114 // an empty window
115 let acc0: *i64 = sys_mmap(WM_A_SLOTS * G_I64) as *i64
116 gv_check_eq("neg-control-an-EMPTY-window-lands-nothing" as *u8, wm_mix_census(led, ln, 5000, 6000, conf, cn, names, pbuf, plen, 2, idx, idxn, acc0), 0, c)
117 gv_check_eq("neg-control-an-empty-window-has-NO-feature-share, never a zero share" as *u8, wm_permil(acc0[WM_A_EV + WM_C_FEATURE], acc0[WM_A_LAND]), CES_NONE, c)
118 gv_check_eq("share-feature-permil-is-over-EVERY-land-row (2 of 9)" as *u8, wm_permil(acc[WM_A_EV + WM_C_FEATURE], acc[WM_A_LAND]), 222, c)
119 // the status line
120 let line: *u8 = sys_mmap(wm_line_bound())
121 let lo: i64 = wm_line(line, 0, 1234, 7, 2, acc)
122 gv_check("line-carries-the-partition-in-order" as *u8, g_contains(line, lo, " land_rows=9 FEATURE=2 ENABLEMENT=4 REWORK=1 UNCLASSED=2 sum=9 feature_permil=222 classed_permil=777 " as *u8), c)
123 gv_check("line-the-verdict-is-LAST" as *u8, ces_span_is(line, lo - ces_slen(" verdict=CENSUSED\n" as *u8), ces_slen(" verdict=CENSUSED\n" as *u8), " verdict=CENSUSED\n" as *u8), c)
124 var z: i64 = 0
125 while z < WM_A_SLOTS { acc0[z] = G_BIG; z = z + 1 }
126 let big: i64 = wm_line(line, 0, G_BIG, G_BIG, G_BIG, acc0)
127 gv_check("line-sixteen-digit-numbers-in-every-slot-still-fit-the-derived-bound" as *u8, (big < wm_line_bound()) as i64, c)
128 gv_values_head()
129 gv_kv("land_rows" as *u8, acc[WM_A_LAND])
130 gv_kv("feature" as *u8, acc[WM_A_EV + WM_C_FEATURE])
131 gv_kv("enablement" as *u8, acc[WM_A_EV + WM_C_ENABLEMENT])
132 gv_kv("rework" as *u8, acc[WM_A_EV + WM_C_REWORK])
133 gv_kv("unclassed" as *u8, acc[WM_A_EV + WM_C_UNCLASSED])
134 gv_kv("index_bytes" as *u8, idxn)
135 gv_kv("line_bytes" as *u8, lo)
136 gv_kv("line_bytes_big" as *u8, big)
137 gv_kv("line_bound" as *u8, wm_line_bound())
138 return gv_verdict("nx_workmix_gate" as *u8, c, "the work-mix ruler proven on planted rows" as *u8)
139}