nx_robot_timing_gate.nx source
↩ module page · 103 lines · 4736 B
1// nx_robot_timing_gate.nx -- R-ROBO-7 GATE: step-timing / timer-ISR rung with never-brick max-rate.
2// VERIFIES:
3// (1) ACCEL profile: schedule starts slow (iv[0] big) and settles to the cruise floor (iv[n-1]==min);
4// (2) overall acceleration: an early interval is clearly larger than a later one;
5// (3) step count preserved;
6// (4) NEVER-BRICK max-rate: EVERY interval >= min_iv (instantaneous rate <= 1/min_iv);
7// (5) EXHAUSTIVE never-brick: sweep accel aggressiveness (incl. absurd) -> min interval always >= min_iv;
8// (6) TIMER-ISR monotonic: steps_fired_by rises with time, 0 at t=0, n at end;
9// (7) NEGATIVE CONTROL: the RAW (unfloored) interval at high index is < min_iv -> the floor (the
10// never-brick rate cap) is doing real work.
11// 100% sovereign, integer-only, hardware-rung-up. license_tier: ORIGINAL expect_exit: 0
12import "nx_syscalls.nx"
13import "nx_robot_timing.nx"
14
15func sw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
16func sn(v: i64) -> i64 {
17 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
18 var m: i64 = v
19 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
20 let d: *u8 = sys_mmap(24); var k: i64 = 0
21 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
22 let o: *u8 = sys_mmap(24); var i: i64 = 0
23 while i < k { o[i] = d[k - 1 - i]; i = i + 1 }
24 sys_write(1, o, k); return 0
25}
26func check(name: *u8, cond: i64, tot: *i64) -> i64 {
27 if cond == 1 { sw(" ok " as *u8); tot[0] = tot[0] + 1 }
28 else { sw(" FAIL " as *u8); tot[1] = tot[1] + 1 }
29 sw(name); sw("\n" as *u8)
30 return 0
31}
32
33func main() -> i64 {
34 let tot: *i64 = sys_mmap(16) as *i64
35 tot[0] = 0; tot[1] = 0
36 sw("=== nx_robot_timing_gate R-ROBO-7 -- step-timing / timer-ISR (never-brick max step rate) ===\n" as *u8)
37
38 let n: i64 = 20
39 let accel_k: i64 = 10000
40 let min_iv: i64 = 20
41 let iv: *i64 = sys_mmap(n * 8) as *i64
42 schedule_accel(n, accel_k, min_iv, iv)
43 sw(" iv[0]=" as *u8); sn(iv[0]); sw(" iv[3]=" as *u8); sn(iv[3]); sw(" iv[n-1]=" as *u8); sn(iv[n - 1]); sw(" total=" as *u8); sn(ti_total(iv, n)); sw("\n" as *u8)
44
45 // (1) starts slow, ends at cruise floor
46 var ok1: i64 = 0
47 if iv[0] > min_iv { if iv[n - 1] == min_iv { ok1 = 1 } }
48 check("ACCEL: starts slow (iv[0]>min) and settles to cruise floor (iv[n-1]==min)" as *u8, ok1, tot)
49
50 // (2) overall acceleration (early interval clearly bigger than later)
51 var ok2: i64 = 0
52 if iv[0] > iv[3] { ok2 = 1 }
53 check("acceleration: an early interval > a later interval" as *u8, ok2, tot)
54
55 // (3) step count
56 var cnt: i64 = 0
57 var i: i64 = 0
58 while i < n { if iv[i] > 0 { cnt = cnt + 1 } i = i + 1 }
59 var ok3: i64 = 0
60 if cnt == n { ok3 = 1 }
61 check("step count preserved (n intervals)" as *u8, ok3, tot)
62
63 // (4) never-brick: every interval >= min_iv
64 var ok4: i64 = 0
65 if ti_min_iv(iv, n) >= min_iv { ok4 = 1 }
66 sw(" min interval in schedule=" as *u8); sn(ti_min_iv(iv, n)); sw(" (>= min " as *u8); sn(min_iv); sw(")\n" as *u8)
67 check("NEVER-BRICK max-rate: every interval >= min_iv (rate <= 1/min_iv)" as *u8, ok4, tot)
68
69 // (5) exhaustive never-brick over accel aggressiveness
70 let iv2: *i64 = sys_mmap(n * 8) as *i64
71 var esc: i64 = 0
72 var ak: i64 = 100
73 while ak <= 100000000 {
74 schedule_accel(n, ak, min_iv, iv2)
75 if ti_min_iv(iv2, n) < min_iv { esc = 1 }
76 ak = ak * 10
77 }
78 var ok5: i64 = 0
79 if esc == 0 { ok5 = 1 }
80 check("EXHAUSTIVE never-brick: min interval >= min_iv across all accel rates" as *u8, ok5, tot)
81
82 // (6) timer-ISR monotonic
83 let total: i64 = ti_total(iv, n)
84 let f0: i64 = steps_fired_by(iv, n, 0)
85 let fmid: i64 = steps_fired_by(iv, n, total / 2)
86 let fend: i64 = steps_fired_by(iv, n, total)
87 sw(" ISR fired: t=0 -> " as *u8); sn(f0); sw(", t=mid -> " as *u8); sn(fmid); sw(", t=end -> " as *u8); sn(fend); sw("\n" as *u8)
88 var ok6: i64 = 0
89 if f0 == 0 { if fend == n { if fmid > 0 { if fmid < n { ok6 = 1 } } } }
90 check("TIMER-ISR: steps_fired_by monotonic (0 at t=0, n at end)" as *u8, ok6, tot)
91
92 // (7) negative control: raw (unfloored) interval at a high index is below min_iv
93 let raw_hi: i64 = ti_raw_iv(n - 1, accel_k)
94 sw(" raw (unfloored) iv at high index=" as *u8); sn(raw_hi); sw(" (< min " as *u8); sn(min_iv); sw(")\n" as *u8)
95 var ok7: i64 = 0
96 if raw_hi < min_iv { ok7 = 1 }
97 check("NEG-CONTROL: raw unfloored interval < min_iv (rate cap earns its keep)" as *u8, ok7, tot)
98
99 sw("=== VERDICT pass=" as *u8); sn(tot[0]); sw(" fail=" as *u8); sn(tot[1]); sw(" ===\n" as *u8)
100 if tot[1] == 0 { sys_exit(0) }
101 sys_exit(1)
102 return 1
103}