nx_pathway_test.nx source
↩ module page · 123 lines · 4709 B
1// nx_pathway_test.nx -- smoke for nx_pathway.
2
3import "nx_syscalls.nx"
4import "nx_tier.nx"
5import "nx_budget.nx"
6import "nx_attention_class.nx"
7import "nx_metabolism.nx"
8import "nx_tropism.nx"
9import "nx_ribosome.nx"
10import "nx_pathway.nx"
11
12// Helper: build a populated NxCellSpec on the heap so the test can
13// pass *spec into add_cell.
14func _build_spec(cell_id: nx_int,
15 attention_class: nx_int,
16 tropism: nx_int,
17 ribosome: nx_int,
18 budget: *NxBudget,
19 site_id: nx_int,
20 tier: nx_int) -> *NxCellSpec {
21 let s: *NxCellSpec = (sys_mmap(64)) as *NxCellSpec
22 s.cell_id = cell_id
23 s.attention_class = attention_class
24 s.tropism_prefer = tropism
25 s.ribosome_target = ribosome
26 s.budget = budget
27 s.site_id_hint = site_id
28 s.initial_tier = tier
29 return s
30}
31
32func main() -> i64 {
33 // 1: construction
34 let p: *NxPathway = nx_pathway_new(8, 16)
35 if p.cell_capacity != 8 { return 1 }
36 if p.edge_capacity != 16 { return 2 }
37 if p.n_cells != 0 { return 3 }
38 if p.n_edges != 0 { return 4 }
39
40 // 2: add one cell, total accounting updates
41 let b1: *NxBudget = nx_budget_new(101, 1000, 2000, 0, 0, 0)
42 let s1: *NxCellSpec = _build_spec(101,
43 NX_AC_INTERACTIVE_FOREGROUND_GAME,
44 NX_TROP_LOCAL_GPU,
45 NX_RBT_PTX, b1, 555, NX_TIER_WORKSTATION)
46 if nx_pathway_add_cell(p, s1) != NX_PW_OK { return 5 }
47 if p.n_cells != 1 { return 6 }
48
49 // 3: invalid attention class rejected
50 let s_bad_ac: *NxCellSpec = _build_spec(102, 99,
51 NX_TROP_LOCAL_CPU, NX_RBT_X86_64,
52 (0 as i64) as *NxBudget, 0, NX_TIER_WORKSTATION)
53 if nx_pathway_add_cell(p, s_bad_ac) != NX_PW_ERR_BAD_CELL { return 7 }
54
55 // 4: invalid tropism rejected
56 let s_bad_tr: *NxCellSpec = _build_spec(103, NX_AC_DEV,
57 99, NX_RBT_X86_64,
58 (0 as i64) as *NxBudget, 0, NX_TIER_WORKSTATION)
59 if nx_pathway_add_cell(p, s_bad_tr) != NX_PW_ERR_BAD_CELL { return 8 }
60
61 // 5: invalid ribosome rejected
62 let s_bad_rb: *NxCellSpec = _build_spec(104, NX_AC_DEV,
63 NX_TROP_LOCAL_CPU, 99,
64 (0 as i64) as *NxBudget, 0, NX_TIER_WORKSTATION)
65 if nx_pathway_add_cell(p, s_bad_rb) != NX_PW_ERR_BAD_CELL { return 9 }
66
67 // 6: add second valid cell
68 let b2: *NxBudget = nx_budget_new(202, 500, 1000, 0, 0, 0)
69 let s2: *NxCellSpec = _build_spec(202, NX_AC_BACKGROUND_INFERENCE,
70 NX_TROP_PEER, NX_RBT_GCN, b2, 666, NX_TIER_SERVER)
71 if nx_pathway_add_cell(p, s2) != NX_PW_OK { return 10 }
72 if p.n_cells != 2 { return 11 }
73
74 // 7: add valid edge
75 if nx_pathway_add_edge(p, 101, 202, 0) != NX_PW_OK { return 12 }
76 if p.n_edges != 1 { return 13 }
77
78 // 8: edge to nonexistent cell rejected
79 if nx_pathway_add_edge(p, 101, 999, 0) != NX_PW_ERR_CELL_NOT_FOUND { return 14 }
80 if nx_pathway_add_edge(p, 999, 101, 0) != NX_PW_ERR_CELL_NOT_FOUND { return 15 }
81
82 // 9: get_cell roundtrip
83 let g: *NxCellSpec = nx_pathway_get_cell(p, 202)
84 if (g as i64) == 0 { return 16 }
85 if g.attention_class != NX_AC_BACKGROUND_INFERENCE { return 17 }
86 if g.ribosome_target != NX_RBT_GCN { return 18 }
87
88 // 10: missing cell get returns NULL
89 let none: *NxCellSpec = nx_pathway_get_cell(p, 9999)
90 if (none as i64) != 0 { return 19 }
91
92 // 11: resolve target uses ribosome with declared preference
93 let nullm: *NxMetabolism = (0 as i64) as *NxMetabolism
94 let t1: nx_int = nx_pathway_resolve_target(p, 101, nullm)
95 if t1 != NX_RBT_PTX { return 20 }
96
97 // 12: aggregate budgets across cells
98 let total_ram: nx_size = nx_pathway_aggregate_ram_max(p)
99 if total_ram != 1500 { return 21 } // 1000 + 500
100 let total_vram: nx_size = nx_pathway_aggregate_vram_max(p)
101 if total_vram != 3000 { return 22 } // 2000 + 1000
102
103 // 13: count remote cells
104 let remote: nx_size = nx_pathway_count_remote_cells(p)
105 if remote != 1 { return 23 } // only cell 202 is PEER
106
107 // 14: fill to capacity then FULL
108 var k: nx_int = 0
109 while k < 6 { // 2 already added; capacity 8
110 let bk: *NxBudget = nx_budget_new(k + 1000, 100, 100, 0, 0, 0)
111 let sk: *NxCellSpec = _build_spec(k + 1000,
112 NX_AC_DEV, NX_TROP_LOCAL_CPU, NX_RBT_X86_64,
113 bk, k, NX_TIER_WORKSTATION)
114 if nx_pathway_add_cell(p, sk) != NX_PW_OK { return 24 }
115 k = k + 1
116 }
117 let b_extra: *NxBudget = nx_budget_new(9999, 1, 1, 0, 0, 0)
118 let s_extra: *NxCellSpec = _build_spec(9999, NX_AC_DEV,
119 NX_TROP_LOCAL_CPU, NX_RBT_X86_64, b_extra, 0, NX_TIER_WORKSTATION)
120 if nx_pathway_add_cell(p, s_extra) != NX_PW_ERR_FULL { return 25 }
121
122 return 0
123}