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 / core / test.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note aienux/kernel/core/test.om: Pure-Omega test suite for Aienux Kernel Core |
| 3 | note (Scheduler, Capability-Gated IPC, and AArch64 Stage-1 Page Tables). |
| 4 | note Compose with: si/directives/om2.om aienux/kernel/core/scheduler.om aienux/kernel/core/ipc.om aienux/kernel/core/pagetable.om aienux/kernel/core/test.om |
| 5 | |
| 6 | text s_pass "PASS " |
| 7 | text s_fail "FAIL " |
| 8 | text s_nl "\n" |
| 9 | text s_t01 "sched_madt_class_placement" |
| 10 | text s_t02 "sched_fair_equal_priority_and_priority_order" |
| 11 | text s_t03 "sched_background_anti_starvation" |
| 12 | text s_t04 "sched_work_stealing_leaves_high_prio" |
| 13 | text s_t05 "sched_remove_and_reuse_slot" |
| 14 | text s_t06 "sched_negative_controls" |
| 15 | text s_t07 "ipc_channel_fifo_and_bounds" |
| 16 | text s_t08 "ipc_capability_rights_and_wrong_resource" |
| 17 | text s_t09 "ipc_cross_principal_isolation" |
| 18 | text s_t10 "ipc_object_read_write_and_oob" |
| 19 | text s_t11 "ipc_attenuated_delegation_and_no_escalation" |
| 20 | text s_t12 "ipc_tree_revocation_cascades" |
| 21 | text s_t13 "pt_map_4k_2m_1g_and_translate" |
| 22 | text s_t14 "pt_high_half_canonical_kernel_va" |
| 23 | text s_t15 "pt_wx_and_device_exec_refused" |
| 24 | text s_t16 "pt_pxn_uxn_and_flag_roundtrip" |
| 25 | text s_t17 "pt_overlap_and_partial_unmap_refused" |
| 26 | text s_t18 "pt_unmap_and_frame_exhaustion" |
| 27 | text s_sum "KERNEL_CORE_TEST_PASS total=18 failed=0\n" |
| 28 | text s_fsum "KERNEL_CORE_TEST_FAIL\n" |
| 29 | |
| 30 | fn kwrite_all fd int buf view uchar * to bool |
| 31 | total = len buf |
| 32 | off = ulong 0 |
| 33 | note Each write advances off by at least 1 byte on progress; 4096 covers test output lines. |
| 34 | while lt off total bound 4096 |
| 35 | n = write fd buf off sub total off |
| 36 | if le n 0 |
| 37 | ret false |
| 38 | end |
| 39 | off = add off ulong n |
| 40 | end |
| 41 | ret true |
| 42 | end |
| 43 | |
| 44 | fn report name view uchar * ok bool to uint |
| 45 | if ok |
| 46 | w1 = kwrite_all 1 s_pass |
| 47 | w2 = kwrite_all 1 name |
| 48 | w3 = kwrite_all 1 s_nl |
| 49 | if and w1 and w2 w3 |
| 50 | ret 0 |
| 51 | end |
| 52 | ret 1 |
| 53 | end |
| 54 | w1 = kwrite_all 1 s_fail |
| 55 | w2 = kwrite_all 1 name |
| 56 | w3 = kwrite_all 1 s_nl |
| 57 | if and w1 and w2 w3 |
| 58 | ret 1 |
| 59 | end |
| 60 | ret 1 |
| 61 | end |
| 62 | |
| 63 | note ---- Scheduler Tests (01..06) ---- |
| 64 | |
| 65 | fn test_01_sched_placement to bool |
| 66 | cls = new uchar 4 0 |
| 67 | put cls 0 1 |
| 68 | put cls 1 3 |
| 69 | put cls 2 1 |
| 70 | put cls 3 3 |
| 71 | if ne sched_init 4 8 cls SCHED_OK |
| 72 | ret false |
| 73 | end |
| 74 | cpu = new ulong 1 0 |
| 75 | note Latency must land on class 3 (CPU 1 or 3) |
| 76 | if ne sched_enqueue 10 SCHED_PRIO_LATENCY cpu SCHED_OK |
| 77 | ret false |
| 78 | end |
| 79 | if ne get cls get cpu 0 3 |
| 80 | ret false |
| 81 | end |
| 82 | note Background must land on class 1 (CPU 0 or 2) |
| 83 | if ne sched_enqueue 20 SCHED_PRIO_BG cpu SCHED_OK |
| 84 | ret false |
| 85 | end |
| 86 | if ne get cls get cpu 0 1 |
| 87 | ret false |
| 88 | end |
| 89 | note Normal lands on shortest queue (length 0) |
| 90 | if ne sched_enqueue 30 SCHED_PRIO_NORMAL cpu SCHED_OK |
| 91 | ret false |
| 92 | end |
| 93 | if ne sched_queue_len get cpu 0 1 |
| 94 | ret false |
| 95 | end |
| 96 | ret true |
| 97 | end |
| 98 | |
| 99 | fn test_02_sched_fairness to bool |
| 100 | cls = new uchar 1 2 |
| 101 | if ne sched_init 1 8 cls SCHED_OK |
| 102 | ret false |
| 103 | end |
| 104 | cpu = new ulong 1 0 |
| 105 | if ne sched_enqueue 1 SCHED_PRIO_NORMAL cpu SCHED_OK |
| 106 | ret false |
| 107 | end |
| 108 | if ne sched_enqueue 2 SCHED_PRIO_NORMAL cpu SCHED_OK |
| 109 | ret false |
| 110 | end |
| 111 | if ne sched_enqueue 3 SCHED_PRIO_LATENCY cpu SCHED_OK |
| 112 | ret false |
| 113 | end |
| 114 | ran = new uchar 1 0 |
| 115 | tid = new uint 1 0 |
| 116 | note Latency task 3 always beats Normal tasks 1 & 2 |
| 117 | if ne sched_tick 0 ran tid SCHED_OK |
| 118 | ret false |
| 119 | end |
| 120 | if or eq get ran 0 0 ne get tid 0 3 |
| 121 | ret false |
| 122 | end |
| 123 | note Remove latency task 3 -> tasks 1 and 2 share 6 ticks evenly (3 each) |
| 124 | if ne sched_remove 3 SCHED_OK |
| 125 | ret false |
| 126 | end |
| 127 | i = uint 0 |
| 128 | while lt i 6 bound 8 |
| 129 | if ne sched_tick 0 ran tid SCHED_OK |
| 130 | ret false |
| 131 | end |
| 132 | i = add i 1 |
| 133 | end |
| 134 | if ne sched_task_ticks 1 3 |
| 135 | ret false |
| 136 | end |
| 137 | if ne sched_task_ticks 2 3 |
| 138 | ret false |
| 139 | end |
| 140 | ret true |
| 141 | end |
| 142 | |
| 143 | fn test_03_sched_bg_anti_starvation to bool |
| 144 | cls = new uchar 1 2 |
| 145 | if ne sched_init 1 4 cls SCHED_OK |
| 146 | ret false |
| 147 | end |
| 148 | cpu = new ulong 1 0 |
| 149 | if ne sched_enqueue 100 SCHED_PRIO_LATENCY cpu SCHED_OK |
| 150 | ret false |
| 151 | end |
| 152 | if ne sched_enqueue 200 SCHED_PRIO_BG cpu SCHED_OK |
| 153 | ret false |
| 154 | end |
| 155 | ran = new uchar 1 0 |
| 156 | tid = new uint 1 0 |
| 157 | note 8 contested ticks with interval 4 -> BG must get exactly 2 ticks, Latency 6 ticks |
| 158 | i = uint 0 |
| 159 | while lt i 8 bound 16 |
| 160 | if ne sched_tick 0 ran tid SCHED_OK |
| 161 | ret false |
| 162 | end |
| 163 | i = add i 1 |
| 164 | end |
| 165 | if ne sched_task_ticks 200 2 |
| 166 | ret false |
| 167 | end |
| 168 | if ne sched_task_ticks 100 6 |
| 169 | ret false |
| 170 | end |
| 171 | ret true |
| 172 | end |
| 173 | |
| 174 | fn test_04_sched_work_stealing to bool |
| 175 | cls = new uchar 2 0 |
| 176 | put cls 0 3 |
| 177 | put cls 1 1 |
| 178 | if ne sched_init 2 8 cls SCHED_OK |
| 179 | ret false |
| 180 | end |
| 181 | cpu = new ulong 1 0 |
| 182 | note Put two Latency tasks on CPU 0 (class 3), leaving CPU 1 idle |
| 183 | if ne sched_enqueue 10 SCHED_PRIO_LATENCY cpu SCHED_OK |
| 184 | ret false |
| 185 | end |
| 186 | if ne sched_enqueue 11 SCHED_PRIO_LATENCY cpu SCHED_OK |
| 187 | ret false |
| 188 | end |
| 189 | ran = new uchar 1 0 |
| 190 | tid = new uint 1 0 |
| 191 | note Tick CPU 0 once so task 10 has 1 tick, task 11 has 0 ticks |
| 192 | if ne sched_tick 0 ran tid SCHED_OK |
| 193 | ret false |
| 194 | end |
| 195 | note Tick idle CPU 1 -> must steal most-served task (10) from CPU 0 |
| 196 | if ne sched_tick 1 ran tid SCHED_OK |
| 197 | ret false |
| 198 | end |
| 199 | if or eq get ran 0 0 ne get tid 0 10 |
| 200 | ret false |
| 201 | end |
| 202 | if or ne sched_queue_len 0 1 ne sched_queue_len 1 1 |
| 203 | ret false |
| 204 | end |
| 205 | ret true |
| 206 | end |
| 207 | |
| 208 | fn test_05_sched_remove_reuse to bool |
| 209 | cls = new uchar 2 2 |
| 210 | if ne sched_init 2 8 cls SCHED_OK |
| 211 | ret false |
| 212 | end |
| 213 | cpu = new ulong 1 0 |
| 214 | if ne sched_enqueue 77 SCHED_PRIO_NORMAL cpu SCHED_OK |
| 215 | ret false |
| 216 | end |
| 217 | if ne sched_remove 77 SCHED_OK |
| 218 | ret false |
| 219 | end |
| 220 | note Re-enqueueing same ID after removal succeeds |
| 221 | if ne sched_enqueue 77 SCHED_PRIO_NORMAL cpu SCHED_OK |
| 222 | ret false |
| 223 | end |
| 224 | ret true |
| 225 | end |
| 226 | |
| 227 | fn test_06_sched_negatives to bool |
| 228 | cls = new uchar 2 1 |
| 229 | if ne sched_init 0 8 cls SCHED_ERR_NO_CPUS |
| 230 | ret false |
| 231 | end |
| 232 | if ne sched_init 2 8 cls SCHED_OK |
| 233 | ret false |
| 234 | end |
| 235 | cpu = new ulong 1 0 |
| 236 | if ne sched_enqueue 5 SCHED_PRIO_NORMAL cpu SCHED_OK |
| 237 | ret false |
| 238 | end |
| 239 | note Duplicate task ID refused |
| 240 | if ne sched_enqueue 5 SCHED_PRIO_NORMAL cpu SCHED_ERR_DUP_TASK |
| 241 | ret false |
| 242 | end |
| 243 | note Invalid CPU refused |
| 244 | ran = new uchar 1 0 |
| 245 | tid = new uint 1 0 |
| 246 | if ne sched_tick 2 ran tid SCHED_ERR_BAD_CPU |
| 247 | ret false |
| 248 | end |
| 249 | note Unknown task remove refused |
| 250 | if ne sched_remove 999 SCHED_ERR_UNKNOWN |
| 251 | ret false |
| 252 | end |
| 253 | note Fill remaining 63 slots -> 65th enqueue returns SCHED_ERR_FULL |
| 254 | i = uint 1 |
| 255 | while lt i 64 bound 64 |
| 256 | if ne sched_enqueue add 100 i SCHED_PRIO_NORMAL cpu SCHED_OK |
| 257 | ret false |
| 258 | end |
| 259 | i = add i 1 |
| 260 | end |
| 261 | if ne sched_enqueue 999 SCHED_PRIO_NORMAL cpu SCHED_ERR_FULL |
| 262 | ret false |
| 263 | end |
| 264 | ret true |
| 265 | end |
| 266 | |
| 267 | note ---- IPC Tests (07..12) ---- |
| 268 | |
| 269 | fn test_07_ipc_fifo_bounds to bool |
| 270 | hs = new ulong 1 0 |
| 271 | ho = new ulong 1 0 |
| 272 | hr = new ulong 1 0 |
| 273 | ipc_reset hs ho hr |
| 274 | msg = new IpcMsg 0 0 0 0 |
| 275 | note Empty recv refused |
| 276 | if ne ipc_channel_recv IPC_PRINCIPAL_B get hr 0 msg IPC_ERR_CH_EMPTY |
| 277 | ret false |
| 278 | end |
| 279 | note Fill 8 messages, 9th returns IPC_ERR_CH_FULL |
| 280 | i = ulong 0 |
| 281 | while lt i 8 bound 16 |
| 282 | put msg tag uint add 10 i |
| 283 | put msg sender IPC_PRINCIPAL_A |
| 284 | put msg arg0 mul i 100 |
| 285 | put msg arg1 add i 1 |
| 286 | if ne ipc_channel_send IPC_PRINCIPAL_A get hs 0 msg IPC_OK |
| 287 | ret false |
| 288 | end |
| 289 | i = add i 1 |
| 290 | end |
| 291 | if ne ipc_channel_send IPC_PRINCIPAL_A get hs 0 msg IPC_ERR_CH_FULL |
| 292 | ret false |
| 293 | end |
| 294 | note Receive in exact FIFO order |
| 295 | i = ulong 0 |
| 296 | while lt i 8 bound 16 |
| 297 | if ne ipc_channel_recv IPC_PRINCIPAL_B get hr 0 msg IPC_OK |
| 298 | ret false |
| 299 | end |
| 300 | if ne get msg tag uint add 10 i |
| 301 | ret false |
| 302 | end |
| 303 | if ne get msg arg0 mul i 100 |
| 304 | ret false |
| 305 | end |
| 306 | i = add i 1 |
| 307 | end |
| 308 | ret true |
| 309 | end |
| 310 | |
| 311 | fn test_08_ipc_rights_and_resource to bool |
| 312 | hs = new ulong 1 0 |
| 313 | ho = new ulong 1 0 |
| 314 | hr = new ulong 1 0 |
| 315 | ipc_reset hs ho hr |
| 316 | msg = new IpcMsg 1 0 11 22 |
| 317 | note Principal A has WRITE-only channel handle -> recv refused |
| 318 | if ne ipc_channel_recv IPC_PRINCIPAL_A get hs 0 msg IPC_ERR_MISSING_RIGHTS |
| 319 | ret false |
| 320 | end |
| 321 | note Principal B has READ-only channel handle -> send refused |
| 322 | if ne ipc_channel_send IPC_PRINCIPAL_B get hr 0 msg IPC_ERR_MISSING_RIGHTS |
| 323 | ret false |
| 324 | end |
| 325 | note Object handle has READ|WRITE but wrong resource for channel ops |
| 326 | if ne ipc_channel_send IPC_PRINCIPAL_A get ho 0 msg IPC_ERR_WRONG_RESOURCE |
| 327 | ret false |
| 328 | end |
| 329 | if ne ipc_channel_recv IPC_PRINCIPAL_A get ho 0 msg IPC_ERR_WRONG_RESOURCE |
| 330 | ret false |
| 331 | end |
| 332 | ret true |
| 333 | end |
| 334 | |
| 335 | fn test_09_ipc_principal_isolation to bool |
| 336 | hs = new ulong 1 0 |
| 337 | ho = new ulong 1 0 |
| 338 | hr = new ulong 1 0 |
| 339 | ipc_reset hs ho hr |
| 340 | val = new ulong 1 0 |
| 341 | note Principal B cannot use Principal A's object handle |
| 342 | if ne ipc_object_read IPC_PRINCIPAL_B get ho 0 0 val IPC_ERR_INVALID_HANDLE |
| 343 | ret false |
| 344 | end |
| 345 | note Forged generation handle refused |
| 346 | bad_h = xor get ho 0 0x100 |
| 347 | if ne ipc_object_read IPC_PRINCIPAL_A bad_h 0 val IPC_ERR_INVALID_HANDLE |
| 348 | ret false |
| 349 | end |
| 350 | ret true |
| 351 | end |
| 352 | |
| 353 | fn test_10_ipc_object_rw_oob to bool |
| 354 | hs = new ulong 1 0 |
| 355 | ho = new ulong 1 0 |
| 356 | hr = new ulong 1 0 |
| 357 | ipc_reset hs ho hr |
| 358 | val = new ulong 1 0 |
| 359 | if ne ipc_object_read IPC_PRINCIPAL_A get ho 0 0 val IPC_OK |
| 360 | ret false |
| 361 | end |
| 362 | if ne get val 0 0xc0ffee01 |
| 363 | ret false |
| 364 | end |
| 365 | if ne ipc_object_write IPC_PRINCIPAL_A get ho 0 2 0xdeadbeef12345678 IPC_OK |
| 366 | ret false |
| 367 | end |
| 368 | if ne ipc_object_read IPC_PRINCIPAL_A get ho 0 2 val IPC_OK |
| 369 | ret false |
| 370 | end |
| 371 | if ne get val 0 0xdeadbeef12345678 |
| 372 | ret false |
| 373 | end |
| 374 | note Out-of-bounds object offset refused |
| 375 | if ne ipc_object_read IPC_PRINCIPAL_A get ho 0 4 val IPC_ERR_WRONG_RESOURCE |
| 376 | ret false |
| 377 | end |
| 378 | if ne ipc_object_write IPC_PRINCIPAL_A get ho 0 4 0 IPC_ERR_WRONG_RESOURCE |
| 379 | ret false |
| 380 | end |
| 381 | ret true |
| 382 | end |
| 383 | |
| 384 | fn test_11_ipc_delegation_attenuation to bool |
| 385 | hs = new ulong 1 0 |
| 386 | ho = new ulong 1 0 |
| 387 | hr = new ulong 1 0 |
| 388 | ipc_reset hs ho hr |
| 389 | hb = new ulong 1 0 |
| 390 | note Attempt to delegate DERIVE right refused |
| 391 | if ne ipc_delegate_object IPC_PRINCIPAL_A get ho 0 IPC_PRINCIPAL_B or IPC_RIGHT_READ IPC_RIGHT_DERIVE hb IPC_ERR_MISSING_RIGHTS |
| 392 | ret false |
| 393 | end |
| 394 | note Attenuated READ-only delegation succeeds |
| 395 | if ne ipc_delegate_object IPC_PRINCIPAL_A get ho 0 IPC_PRINCIPAL_B IPC_RIGHT_READ hb IPC_OK |
| 396 | ret false |
| 397 | end |
| 398 | val = new ulong 1 0 |
| 399 | if ne ipc_object_read IPC_PRINCIPAL_B get hb 0 1 val IPC_OK |
| 400 | ret false |
| 401 | end |
| 402 | if ne get val 0 0x0badc0de |
| 403 | ret false |
| 404 | end |
| 405 | note B cannot write with READ-only delegated handle |
| 406 | if ne ipc_object_write IPC_PRINCIPAL_B get hb 0 1 99 IPC_ERR_MISSING_RIGHTS |
| 407 | ret false |
| 408 | end |
| 409 | ret true |
| 410 | end |
| 411 | |
| 412 | fn test_12_ipc_tree_revocation to bool |
| 413 | hs = new ulong 1 0 |
| 414 | ho = new ulong 1 0 |
| 415 | hr = new ulong 1 0 |
| 416 | ipc_reset hs ho hr |
| 417 | hb = new ulong 1 0 |
| 418 | if ne ipc_delegate_object IPC_PRINCIPAL_A get ho 0 IPC_PRINCIPAL_B IPC_RIGHT_READ hb IPC_OK |
| 419 | ret false |
| 420 | end |
| 421 | val = new ulong 1 0 |
| 422 | if ne ipc_object_read IPC_PRINCIPAL_B get hb 0 0 val IPC_OK |
| 423 | ret false |
| 424 | end |
| 425 | note Revoking Principal A's parent handle cascades to Principal B's derived handle |
| 426 | if ne ipc_revoke IPC_PRINCIPAL_A get ho 0 IPC_OK |
| 427 | ret false |
| 428 | end |
| 429 | if ne ipc_object_read IPC_PRINCIPAL_A get ho 0 0 val IPC_ERR_INVALID_HANDLE |
| 430 | ret false |
| 431 | end |
| 432 | if ne ipc_object_read IPC_PRINCIPAL_B get hb 0 0 val IPC_ERR_INVALID_HANDLE |
| 433 | ret false |
| 434 | end |
| 435 | ret true |
| 436 | end |
| 437 | |
| 438 | note ---- AArch64 Stage-1 PageTable Tests (13..18) ---- |
| 439 | |
| 440 | fn test_13_pt_4k_2m_1g_translate to bool |
| 441 | if ne pt_init 0x40000000 32 PT_OK |
| 442 | ret false |
| 443 | end |
| 444 | f = new PtFlags PT_MAIR_NORMAL_WB 1 0 0 1 1 |
| 445 | note 1 GiB block at 0x40000000 -> 0x80000000 |
| 446 | if ne pt_map 0x40000000 0x80000000 PT_BLOCK_1G f PT_OK |
| 447 | ret false |
| 448 | end |
| 449 | note 2 MiB block at 0x00200000 -> 0x10200000 |
| 450 | if ne pt_map 0x00200000 0x10200000 PT_BLOCK_2M f PT_OK |
| 451 | ret false |
| 452 | end |
| 453 | note 4 KiB page at 0x00001000 -> 0x20001000 |
| 454 | if ne pt_map 0x00001000 0x20001000 PT_PAGE_SIZE f PT_OK |
| 455 | ret false |
| 456 | end |
| 457 | tr = new PtTrans 0 0 0 0 0 0 0 0 |
| 458 | if ne pt_translate 0x40000123 tr PT_OK |
| 459 | ret false |
| 460 | end |
| 461 | if or ne get tr pa 0x80000123 ne get tr page_size PT_BLOCK_1G |
| 462 | ret false |
| 463 | end |
| 464 | if ne pt_translate 0x00200456 tr PT_OK |
| 465 | ret false |
| 466 | end |
| 467 | if or ne get tr pa 0x10200456 ne get tr page_size PT_BLOCK_2M |
| 468 | ret false |
| 469 | end |
| 470 | if ne pt_translate 0x00001789 tr PT_OK |
| 471 | ret false |
| 472 | end |
| 473 | if or ne get tr pa 0x20001789 ne get tr page_size PT_PAGE_SIZE |
| 474 | ret false |
| 475 | end |
| 476 | ret true |
| 477 | end |
| 478 | |
| 479 | fn test_14_pt_high_half_canonical to bool |
| 480 | if ne pt_init 0x40000000 32 PT_OK |
| 481 | ret false |
| 482 | end |
| 483 | f = new PtFlags PT_MAIR_NORMAL_WB 0 0 1 1 1 |
| 484 | note 48-bit canonical high-half kernel VA has bit 47 == 1 and bits 63..48 == 0xffff |
| 485 | hi_va = ulong 0xffff800040000000 |
| 486 | if ne pt_map hi_va 0x50000000 PT_PAGE_SIZE f PT_OK |
| 487 | ret false |
| 488 | end |
| 489 | tr = new PtTrans 0 0 0 0 0 0 0 0 |
| 490 | if ne pt_translate add hi_va 0x44 tr PT_OK |
| 491 | ret false |
| 492 | end |
| 493 | if ne get tr pa 0x50000044 |
| 494 | ret false |
| 495 | end |
| 496 | note Non-canonical VAs (both low-hole and high-hole where bit 47 != bits 63..48) refused |
| 497 | non_can1 = ulong 0x0001000000000000 |
| 498 | non_can2 = ulong 0xffff000040000000 |
| 499 | if ne pt_map non_can1 0x50001000 PT_PAGE_SIZE f PT_ERR_ADDR_OOB |
| 500 | ret false |
| 501 | end |
| 502 | if ne pt_map non_can2 0x50001000 PT_PAGE_SIZE f PT_ERR_ADDR_OOB |
| 503 | ret false |
| 504 | end |
| 505 | if ne pt_translate non_can1 tr PT_ERR_ADDR_OOB |
| 506 | ret false |
| 507 | end |
| 508 | ret true |
| 509 | end |
| 510 | |
| 511 | fn test_15_pt_wx_and_device_exec to bool |
| 512 | if ne pt_init 0x40000000 32 PT_OK |
| 513 | ret false |
| 514 | end |
| 515 | note W^X: writable + executable MUST be refused |
| 516 | wx = new PtFlags PT_MAIR_NORMAL_WB 1 0 1 1 1 |
| 517 | if ne pt_map 0x1000 0x1000 PT_PAGE_SIZE wx PT_ERR_WX |
| 518 | ret false |
| 519 | end |
| 520 | note Device-nGnRE + executable MUST be refused |
| 521 | devx = new PtFlags PT_MAIR_DEVICE_NGNRE 0 0 1 0 1 |
| 522 | if ne pt_map 0x2000 0x09000000 PT_PAGE_SIZE devx PT_ERR_DEVICE_EXEC |
| 523 | ret false |
| 524 | end |
| 525 | note Device-nGnRE non-executable writable succeeds |
| 526 | devrw = new PtFlags PT_MAIR_DEVICE_NGNRE 1 0 0 0 1 |
| 527 | if ne pt_map 0x2000 0x09000000 PT_PAGE_SIZE devrw PT_OK |
| 528 | ret false |
| 529 | end |
| 530 | ret true |
| 531 | end |
| 532 | |
| 533 | fn test_16_pt_pxn_uxn_flags to bool |
| 534 | if ne pt_init 0x40000000 32 PT_OK |
| 535 | ret false |
| 536 | end |
| 537 | kcode = new PtFlags PT_MAIR_NORMAL_WB 0 0 1 1 1 |
| 538 | ucode = new PtFlags PT_MAIR_NORMAL_WB 0 1 1 1 0 |
| 539 | kdata = new PtFlags PT_MAIR_NORMAL_WB 1 0 0 1 1 |
| 540 | if ne pt_map 0x1000 0x10000 PT_PAGE_SIZE kcode PT_OK |
| 541 | ret false |
| 542 | end |
| 543 | if ne pt_map 0x2000 0x20000 PT_PAGE_SIZE ucode PT_OK |
| 544 | ret false |
| 545 | end |
| 546 | if ne pt_map 0x3000 0x30000 PT_PAGE_SIZE kdata PT_OK |
| 547 | ret false |
| 548 | end |
| 549 | tr = new PtTrans 0 0 0 0 0 0 0 0 |
| 550 | if ne pt_translate 0x1000 tr PT_OK |
| 551 | ret false |
| 552 | end |
| 553 | if ne get tr executable 1 |
| 554 | ret false |
| 555 | end |
| 556 | if ne get tr user 0 |
| 557 | ret false |
| 558 | end |
| 559 | if ne get tr writable 0 |
| 560 | ret false |
| 561 | end |
| 562 | if ne pt_translate 0x2000 tr PT_OK |
| 563 | ret false |
| 564 | end |
| 565 | if ne get tr executable 1 |
| 566 | ret false |
| 567 | end |
| 568 | if ne get tr user 1 |
| 569 | ret false |
| 570 | end |
| 571 | if ne get tr global_flag 0 |
| 572 | ret false |
| 573 | end |
| 574 | if ne pt_translate 0x3000 tr PT_OK |
| 575 | ret false |
| 576 | end |
| 577 | if ne get tr executable 0 |
| 578 | ret false |
| 579 | end |
| 580 | if ne get tr writable 1 |
| 581 | ret false |
| 582 | end |
| 583 | if ne get tr user 0 |
| 584 | ret false |
| 585 | end |
| 586 | ret true |
| 587 | end |
| 588 | |
| 589 | fn test_17_pt_overlap_and_partial_unmap to bool |
| 590 | if ne pt_init 0x40000000 32 PT_OK |
| 591 | ret false |
| 592 | end |
| 593 | f = new PtFlags PT_MAIR_NORMAL_WB 1 0 0 1 1 |
| 594 | if ne pt_map 0x00200000 0x10200000 PT_BLOCK_2M f PT_OK |
| 595 | ret false |
| 596 | end |
| 597 | note Mapping 4 KiB inside existing 2 MiB block refused with PT_ERR_OVERLAP |
| 598 | if ne pt_map 0x00201000 0x20000000 PT_PAGE_SIZE f PT_ERR_OVERLAP |
| 599 | ret false |
| 600 | end |
| 601 | note Unmapping 4 KiB of a 2 MiB block refused with PT_ERR_MISALIGNED |
| 602 | if ne pt_unmap 0x00200000 PT_PAGE_SIZE PT_ERR_MISALIGNED |
| 603 | ret false |
| 604 | end |
| 605 | note Remapping same 4 KiB refused with PT_ERR_OVERLAP |
| 606 | if ne pt_map 0x1000 0x10000 PT_PAGE_SIZE f PT_OK |
| 607 | ret false |
| 608 | end |
| 609 | if ne pt_map 0x1000 0x20000 PT_PAGE_SIZE f PT_ERR_OVERLAP |
| 610 | ret false |
| 611 | end |
| 612 | ret true |
| 613 | end |
| 614 | |
| 615 | fn test_18_pt_unmap_and_exhaustion to bool |
| 616 | if ne pt_init 0x40000000 4 PT_OK |
| 617 | ret false |
| 618 | end |
| 619 | f = new PtFlags PT_MAIR_NORMAL_WB 1 0 0 1 1 |
| 620 | note Mapping a 4 KiB page consumes 4 frames (L0 root + L1 + L2 + L3) -> exact fit |
| 621 | if ne pt_map 0x1000 0x10000 PT_PAGE_SIZE f PT_OK |
| 622 | ret false |
| 623 | end |
| 624 | if ne pt_frames_used 4 |
| 625 | ret false |
| 626 | end |
| 627 | note Mapping in a different L1 subtree requires a 5th frame -> PT_ERR_NO_FRAMES |
| 628 | if ne pt_map 0x8000000000 0x20000 PT_PAGE_SIZE f PT_ERR_NO_FRAMES |
| 629 | ret false |
| 630 | end |
| 631 | note Unmap 0x1000 -> translate returns PT_ERR_NOT_MAPPED |
| 632 | if ne pt_unmap 0x1000 PT_PAGE_SIZE PT_OK |
| 633 | ret false |
| 634 | end |
| 635 | tr = new PtTrans 0 0 0 0 0 0 0 0 |
| 636 | if ne pt_translate 0x1000 tr PT_ERR_NOT_MAPPED |
| 637 | ret false |
| 638 | end |
| 639 | if ne pt_unmap 0x1000 PT_PAGE_SIZE PT_ERR_NOT_MAPPED |
| 640 | ret false |
| 641 | end |
| 642 | ret true |
| 643 | end |
| 644 | |
| 645 | fn main to int |
| 646 | failed = uint 0 |
| 647 | failed = add failed report s_t01 test_01_sched_placement |
| 648 | failed = add failed report s_t02 test_02_sched_fairness |
| 649 | failed = add failed report s_t03 test_03_sched_bg_anti_starvation |
| 650 | failed = add failed report s_t04 test_04_sched_work_stealing |
| 651 | failed = add failed report s_t05 test_05_sched_remove_reuse |
| 652 | failed = add failed report s_t06 test_06_sched_negatives |
| 653 | failed = add failed report s_t07 test_07_ipc_fifo_bounds |
| 654 | failed = add failed report s_t08 test_08_ipc_rights_and_resource |
| 655 | failed = add failed report s_t09 test_09_ipc_principal_isolation |
| 656 | failed = add failed report s_t10 test_10_ipc_object_rw_oob |
| 657 | failed = add failed report s_t11 test_11_ipc_delegation_attenuation |
| 658 | failed = add failed report s_t12 test_12_ipc_tree_revocation |
| 659 | failed = add failed report s_t13 test_13_pt_4k_2m_1g_translate |
| 660 | failed = add failed report s_t14 test_14_pt_high_half_canonical |
| 661 | failed = add failed report s_t15 test_15_pt_wx_and_device_exec |
| 662 | failed = add failed report s_t16 test_16_pt_pxn_uxn_flags |
| 663 | failed = add failed report s_t17 test_17_pt_overlap_and_partial_unmap |
| 664 | failed = add failed report s_t18 test_18_pt_unmap_and_exhaustion |
| 665 | if eq failed 0 |
| 666 | w = kwrite_all 1 s_sum |
| 667 | if w |
| 668 | ret 0 |
| 669 | end |
| 670 | ret 1 |
| 671 | end |
| 672 | w = kwrite_all 1 s_fsum |
| 673 | if w |
| 674 | ret 1 |
| 675 | end |
| 676 | ret 1 |
| 677 | end |