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