interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / aienux / kernel / artifact / osc_launch_test.om

234 lines · 5731 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/kernel/artifact/osc_launch_test.om: Pure-Omega behavioral self-test suite for
3note Aienux Kernel OSC EL0 Launch Contract (aienux/kernel/artifact/osc_launch.om).
4note Compose with: si/directives/om2.om aienux/kernel/artifact/osc_launch.om aienux/kernel/artifact/osc_launch_test.om
5
6text o_pass "PASS "
7text o_fail "FAIL "
8text o_nl "\n"
9text o_t01 "osc_args_scalar_bounds_and_slice_aliasing"
10text o_t02 "osc_ranges_owned_and_disjoint_wrap"
11text o_t03 "osc_budget_stack_and_ws_limits"
12text o_t04 "osc_classify_svc_return_trap_and_rogue"
13text o_t05 "osc_classify_sync_brk_budget_and_lost"
14text o_sum "OSC_LAUNCH_TEST_PASS total=5 failed=0\n"
15text o_fsum "OSC_LAUNCH_TEST_FAIL\n"
16
17fn owrite_all fd int buf view uchar * to bool
18total = len buf
19off = ulong 0
20while lt off total bound 4096
21n = write fd buf off sub total off
22if le n 0
23ret false
24end
25off = add off ulong n
26end
27ret true
28end
29
30fn oreport name view uchar * ok bool to uint
31if ok
32w1 = owrite_all 1 o_pass
33w2 = owrite_all 1 name
34w3 = owrite_all 1 o_nl
35if and w1 and w2 w3
36ret 0
37end
38ret 1
39end
40w1 = owrite_all 1 o_fail
41w2 = owrite_all 1 name
42w3 = owrite_all 1 o_nl
43if and w1 and w2 w3
44ret 1
45end
46ret 1
47end
48
49fn test_01_args_and_alias to bool
50kinds = new uchar 6 0
51args = new ulong 6 0
52note bool(1), u8(2), i8(6), cells(12) + len
53put kinds 0 1
54put kinds 1 2
55put kinds 2 6
56put kinds 3 12
57put kinds 4 5
58put args 0 1
59put args 1 255
60put args 2 0xffffffffffffff80
61put args 3 0x20000
62put args 4 8
63if not osc_launch_args_ok kinds 5 args 5
64ret false
65end
66note Out-of-range bool(2) refused
67put args 0 2
68if osc_launch_args_ok kinds 5 args 5
69ret false
70end
71note Unaligned cells pointer refused
72put args 0 1
73put args 3 0x20004
74if osc_launch_args_ok kinds 5 args 5
75ret false
76end
77note Overlapping bytes(11) and cells(12) refused (aliasing writable workspace)
78put kinds 0 11
79put kinds 1 5
80put kinds 2 12
81put kinds 3 5
82put args 0 0x20010
83put args 1 16
84put args 2 0x20000
85put args 3 4
86if osc_launch_args_ok kinds 4 args 4
87ret false
88end
89note Disjoint bytes(11) and cells(12) accepted
90put args 0 0x10000
91if not osc_launch_args_ok kinds 4 args 4
92ret false
93end
94ret true
95end
96
97fn test_02_ranges_and_disjoint to bool
98kinds = new uchar 6 0
99args = new ulong 6 0
100put kinds 0 11
101put kinds 1 5
102put kinds 2 12
103put kinds 3 5
104put args 0 0x10000
105put args 1 64
106put args 2 0x20000
107put args 3 8
108win = new OscWindows 0x10000 4096 0x20000 4096
109if not osc_launch_ranges_owned kinds 4 args win
110ret false
111end
112note Bytes slice extending past input window refused
113put args 1 5000
114if osc_launch_ranges_owned kinds 4 args win
115ret false
116end
117note Disjoint checks including wrap-around refusal
118if not osc_launch_disjoint 0x1000 0x100 0x1100 0x100
119ret false
120end
121if osc_launch_disjoint 0x1000 0x101 0x1100 0x100
122ret false
123end
124if osc_launch_disjoint 0xffffffffffffff00 0x200 0x1000 0x10
125ret false
126end
127ret true
128end
129
130fn test_03_budgets to bool
131if ne osc_launch_budget 100 40 40
132ret false
133end
134if ne osc_launch_budget 100 200 100
135ret false
136end
137if ne osc_launch_budget 100 0 100
138ret false
139end
140if osc_launch_budget_expired 9 10
141ret false
142end
143if not osc_launch_budget_expired 10 10
144ret false
145end
146if not osc_launch_ws_pages_ok 32
147ret false
148end
149if osc_launch_ws_pages_ok 33
150ret false
151end
152if not osc_launch_stack_ok 4096 8192
153ret false
154end
155if osc_launch_stack_ok 8193 8192
156ret false
157end
158ret true
159end
160
161fn test_04_classify_svc to bool
162rt = ulong 0x400000
163r = new OscResult 0 0 0 0 0 0
164note Return stub (13): site = rt + 13*8, elr = site + 4, esr = (0x15<<26) | 13
165ev_ret = new OscEvent OSC_EV_SVC or shl ulong 0x15 26 OSC_SVC_RETURN add add rt mul OSC_SVC_RETURN 8 4 0x42 0
166osc_launch_classify ev_ret rt r
167if or ne get r cls OSC_RES_RETURNED ne get r val 0x42
168ret false
169end
170note Trap stub (2) with valid trap code 3 (BOUNDS)
171ev_tr = new OscEvent OSC_EV_SVC or shl ulong 0x15 26 OSC_SVC_TRAP add add rt mul OSC_SVC_TRAP 8 4 0 3
172osc_launch_classify ev_tr rt r
173if or ne get r cls OSC_RES_TRAPPED ne get r trap_code 3
174ret false
175end
176note Trap stub (2) with invalid trap code 99 -> UNKNOWN(TRAP_CODE_UNKNOWN)
177ev_tr_bad = new OscEvent OSC_EV_SVC or shl ulong 0x15 26 OSC_SVC_TRAP add add rt mul OSC_SVC_TRAP 8 4 0 99
178osc_launch_classify ev_tr_bad rt r
179if or ne get r cls OSC_RES_UNKNOWN ne get r unknown_reason OSC_UNK_TRAP_CODE_UNKNOWN
180ret false
181end
182note Rogue SVC outside runtime stubs -> UNKNOWN(FAULT)
183ev_rogue = new OscEvent OSC_EV_SVC or shl ulong 0x15 26 13 0x100004 0x42 0
184osc_launch_classify ev_rogue rt r
185if or ne get r cls OSC_RES_UNKNOWN ne get r unknown_reason OSC_UNK_FAULT
186ret false
187end
188ret true
189end
190
191fn test_05_classify_sync to bool
192rt = ulong 0x400000
193r = new OscResult 0 0 0 0 0 0
194note Direct brk (EC=0x3c) is UNKNOWN(FAULT), never TRAPPED
195ev_brk = new OscEvent OSC_EV_SYNC shl ulong 0x3c 26 0x10000 0 0
196osc_launch_classify ev_brk rt r
197if or ne get r cls OSC_RES_UNKNOWN ne get r unknown_reason OSC_UNK_FAULT
198ret false
199end
200note Budget overrun -> UNKNOWN(TICK_OVERRUN)
201ev_bud = new OscEvent OSC_EV_BUDGET 0 0 0 0
202osc_launch_classify ev_bud rt r
203if or ne get r cls OSC_RES_UNKNOWN ne get r unknown_reason OSC_UNK_TICK_OVERRUN
204ret false
205end
206note Launch lost -> UNKNOWN(LAUNCH_LOST)
207ev_lost = new OscEvent OSC_EV_LOST 0 0 0 0
208osc_launch_classify ev_lost rt r
209if or ne get r cls OSC_RES_UNKNOWN ne get r unknown_reason OSC_UNK_LAUNCH_LOST
210ret false
211end
212ret true
213end
214
215fn main to int
216failed = uint 0
217failed = add failed oreport o_t01 test_01_args_and_alias
218failed = add failed oreport o_t02 test_02_ranges_and_disjoint
219failed = add failed oreport o_t03 test_03_budgets
220failed = add failed oreport o_t04 test_04_classify_svc
221failed = add failed oreport o_t05 test_05_classify_sync
222if eq failed 0
223w = owrite_all 1 o_sum
224if w
225ret 0
226end
227ret 1
228end
229w = owrite_all 1 o_fsum
230if w
231ret 1
232end
233ret 1
234end