nx_clock_reserved_pure_v2_ar.nx source
↩ module page · 69 lines · 5220 B
1// Pure activation/service tests for the local scheduler candidate. Not a native scheduling/liveness proof.
2import "nx_clock_sched_reserved_v2_ar.nx"
3import "nx_gate_verdict.nx"
4const CRG_N: i64 = 2
5func crg_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
6func crg_put(dst: *u8, value: *u8) -> i64 {
7 var i: i64 = 0
8 while value[i] != (0 as u8) { dst[i] = value[i]; i = i + 1 }
9 dst[i] = 0 as u8; return i
10}
11func main() -> i64 {
12 let c: *i64 = gv_ctr()
13 let names: *u8 = sys_mmap(CRG_N*CLK_NAMEW)
14 let cmds: *u8 = sys_mmap(CRG_N*CLK_NAMEW)
15 let iv: *i64 = sys_mmap(CRG_N*8) as *i64
16 crg_put(clk_slot(names,0),"ordinary" as *u8)
17 crg_put(clk_slot(names,1),"ioconfirmbeat" as *u8)
18 crg_put(clk_slot(cmds,0),"fixture-slow.elf" as *u8)
19 crg_put(clk_slot(cmds,1),"nx_ioconfirm.elf beat" as *u8)
20 iv[0] = 60; iv[1] = 300
21 let good: *u8 = "ioconfirmbeat\tnx_ioconfirm.elf beat\n" as *u8
22 let crlf: *u8 = "# reservation\r\n\r\nioconfirmbeat\tnx_ioconfirm.elf beat\r\n" as *u8
23 let blank: *u8 = "# no reservation\n\n" as *u8
24 let wrong: *u8 = "ioconfirmbeat\tnx_ioconfirm.elf\n" as *u8
25 let prefix: *u8 = "ioconfirm\tnx_ioconfirm.elf beat\n" as *u8
26 let duplicate: *u8 = "ioconfirmbeat\tnx_ioconfirm.elf beat\nioconfirmbeat\tnx_ioconfirm.elf beat\n" as *u8
27 let trailing: *u8 = "ioconfirmbeat\tnx_ioconfirm.elf beat\textra\n" as *u8
28 let heavy: *u8 = "ioconfirmbeat\n" as *u8
29 gv_head("CLOCK RESERVE PURE ACTIVATION AND SLOT RULES" as *u8)
30 gv_check_eq("exact reservation" as *u8,clk_reserved_resolve(good,crg_len(good),names,cmds,iv,CRG_N,0 as *u8,0),1,c)
31 gv_check_eq("CRLF comments" as *u8,clk_reserved_resolve(crlf,crg_len(crlf),names,cmds,iv,CRG_N,0 as *u8,0),1,c)
32 gv_check_eq("absent disabled" as *u8,clk_reserved_resolve(0 as *u8,0,names,cmds,iv,CRG_N,0 as *u8,0),CLKRS_NONE,c)
33 gv_check_eq("comments disabled" as *u8,clk_reserved_resolve(blank,crg_len(blank),names,cmds,iv,CRG_N,0 as *u8,0),CLKRS_NONE,c)
34 gv_check_eq("command must match" as *u8,clk_reserved_resolve(wrong,crg_len(wrong),names,cmds,iv,CRG_N,0 as *u8,0),CLKRS_INVALID,c)
35 gv_check_eq("name must match" as *u8,clk_reserved_resolve(prefix,crg_len(prefix),names,cmds,iv,CRG_N,0 as *u8,0),CLKRS_INVALID,c)
36 gv_check_eq("duplicate reservation refused" as *u8,clk_reserved_resolve(duplicate,crg_len(duplicate),names,cmds,iv,CRG_N,0 as *u8,0),CLKRS_INVALID,c)
37 gv_check_eq("extra field refused" as *u8,clk_reserved_resolve(trailing,crg_len(trailing),names,cmds,iv,CRG_N,0 as *u8,0),CLKRS_INVALID,c)
38 gv_check_eq("heavy cannot reserve" as *u8,clk_reserved_resolve(good,crg_len(good),names,cmds,iv,CRG_N,heavy,crg_len(heavy)),CLKRS_INVALID,c)
39 iv[1] = 0
40 gv_check_eq("zero interval refused" as *u8,clk_reserved_resolve(good,crg_len(good),names,cmds,iv,CRG_N,0 as *u8,0),CLKRS_INVALID,c)
41 iv[1] = 300
42 crg_put(clk_slot(names,0),"ioconfirmbeat" as *u8)
43 crg_put(clk_slot(cmds,0),"nx_ioconfirm.elf beat" as *u8)
44 gv_check_eq("duplicate registry name refused" as *u8,clk_reserved_resolve(good,crg_len(good),names,cmds,iv,CRG_N,0 as *u8,0),CLKRS_INVALID,c)
45 gv_check_eq("due alongside foreground" as *u8,clk_reserved_due(1,0,0,10,10,1),1,c)
46 gv_check_eq("not early" as *u8,clk_reserved_due(1,0,0,11,10,1),0,c)
47 gv_check_eq("occupied slot no duplicate" as *u8,clk_reserved_due(1,0,123,10,10,1),0,c)
48 gv_check_eq("same foreground no duplicate" as *u8,clk_reserved_due(1,1,0,10,10,1),0,c)
49 gv_check_eq("disabled no assist" as *u8,clk_reserved_due(CLKRS_NONE,0,0,10,10,1),0,c)
50 gv_check_eq("foreground reaped no new child" as *u8,clk_reserved_due(1,0,0,10,10,0),0,c)
51 crg_put(clk_slot(names,0),"alias-name" as *u8)
52 gv_check_eq("different name same reserved command refused" as *u8,clk_reserved_resolve(good,crg_len(good),names,cmds,iv,CRG_N,0 as *u8,0),CLKRS_INVALID,c)
53 gv_check_eq("owned wait running" as *u8,clk_reserved_wait_kind(0,123),CLKRS_WAIT_RUNNING,c)
54 gv_check_eq("owned wait exact reap" as *u8,clk_reserved_wait_kind(123,123),CLKRS_WAIT_REAPED,c)
55 gv_check_eq("EINTR retains ownership" as *u8,clk_reserved_wait_kind(CLKRS_EINTR,123),CLKRS_WAIT_INTERRUPTED,c)
56 gv_check_eq("ECHILD loses ownership" as *u8,clk_reserved_wait_kind(0-10,123),CLKRS_WAIT_LOST,c)
57 gv_check_eq("other wait error loses ownership" as *u8,clk_reserved_wait_kind(0-22,123),CLKRS_WAIT_LOST,c)
58 gv_check_eq("unexpected positive PID loses ownership" as *u8,clk_reserved_wait_kind(124,123),CLKRS_WAIT_LOST,c)
59 gv_check_eq("nonpositive PID never owned" as *u8,clk_reserved_wait_kind(0,0),CLKRS_WAIT_LOST,c)
60 let out: *i64 = sys_mmap(CLKRS_OUT_N*8) as *i64
61 gv_check_eq("normal output does not halt" as *u8,clk_reserved_halt_required(out),0,c)
62 out[CLKRS_OUT_ERRORS] = 1
63 gv_check_eq("nonfatal errors remain observable without halt" as *u8,clk_reserved_halt_required(out),0,c)
64 out[CLKRS_OUT_FATAL] = 1
65 gv_check_eq("fatal output requires driver halt" as *u8,clk_reserved_halt_required(out),1,c)
66 let rc: i64 = gv_verdict("CLOCK-RESERVE-PURE",c,"activation, wait classification and halt decision only; native child scheduling still required" as *u8)
67 sys_exit(rc); return rc
68}
69