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 / crates / aienos-c1-tree / c1_tree_test.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note aienux/crates/aienos-c1-tree/c1_tree_test.om: Behavioral self-test for aienos-c1-tree. |
| 3 | note Compose with: si/directives/om2.om om/tls/sha2.om aienux/crates/aienos-c1-tree/c1_tree.om aienux/crates/aienos-c1-tree/c1_tree_test.om |
| 4 | |
| 5 | fn main to int |
| 6 | c1_init |
| 7 | |
| 8 | note 1. Create root branch with 200 tokens (4 physical pages: 64+64+64+8) |
| 9 | prompt = new uint 200 0 |
| 10 | for i ulong 200 |
| 11 | put prompt i uint add 1000 i |
| 12 | end |
| 13 | rc = c1_create_root 1 prompt |
| 14 | if ne rc C1_OK |
| 15 | ret 1 |
| 16 | end |
| 17 | init_pages = c1_pool_active_count |
| 18 | if ne init_pages 4 |
| 19 | ret 2 |
| 20 | end |
| 21 | init_bytes = c1_pool_memory_bytes |
| 22 | if ne init_bytes mul 4 C1_PAGE_KV_BYTES |
| 23 | ret 3 |
| 24 | end |
| 25 | |
| 26 | note 2. Fork into 8 child branches -> ZERO memory increase |
| 27 | for c ulong 8 |
| 28 | cid = add 10 c |
| 29 | rc = c1_fork_branch 1 cid |
| 30 | if ne rc C1_OK |
| 31 | ret 4 |
| 32 | end |
| 33 | end |
| 34 | if ne c1_pool_active_count init_pages |
| 35 | ret 5 |
| 36 | end |
| 37 | if ne c1_pool_memory_bytes init_bytes |
| 38 | ret 6 |
| 39 | end |
| 40 | |
| 41 | note 3. Divergent append on each child triggers CoW (+1 page per child) |
| 42 | extra = new uint 1 0 |
| 43 | readback = new uint 256 0 |
| 44 | for c ulong 8 |
| 45 | cid = add 10 c |
| 46 | put extra 0 uint add 9000 c |
| 47 | rc = c1_append_tokens cid extra |
| 48 | if ne rc C1_OK |
| 49 | ret 7 |
| 50 | end |
| 51 | got = c1_get_tokens cid readback |
| 52 | if ne got 201 |
| 53 | ret 8 |
| 54 | end |
| 55 | if ne get readback 200 uint add 9000 c |
| 56 | ret 9 |
| 57 | end |
| 58 | if ne get readback 0 uint 1000 |
| 59 | ret 10 |
| 60 | end |
| 61 | end |
| 62 | if ne c1_pool_active_count add init_pages 8 |
| 63 | ret 11 |
| 64 | end |
| 65 | |
| 66 | note 4. Metrics check: 200 + 8*201 = 1808 virtual tokens across 12 physical pages |
| 67 | c1_compute_metrics |
| 68 | if ne get c1_met_out 0 12 |
| 69 | ret 12 |
| 70 | end |
| 71 | if ne get c1_met_out 2 1808 |
| 72 | ret 13 |
| 73 | end |
| 74 | |
| 75 | note 5. Transactional reservation pass & quota exceeded |
| 76 | rc = c1_reserve_step 1 64 42 20 |
| 77 | if ne rc C1_OK |
| 78 | ret 14 |
| 79 | end |
| 80 | if ne get c1_res_out 2 1 |
| 81 | ret 15 |
| 82 | end |
| 83 | rc = c1_reserve_step 1 1000 43 20 |
| 84 | if ne rc C1_ERR_QUOTA |
| 85 | ret 16 |
| 86 | end |
| 87 | |
| 88 | note 6. Evict, reject read on evicted, then reconstruct with no page leak |
| 89 | rc = c1_evict_branch 1 |
| 90 | if ne rc C1_OK |
| 91 | ret 17 |
| 92 | end |
| 93 | got = c1_get_tokens 1 readback |
| 94 | if ne got long C1_ERR_EVICTED |
| 95 | ret 18 |
| 96 | end |
| 97 | rc = c1_reconstruct_branch 1 prompt |
| 98 | if ne rc C1_OK |
| 99 | ret 19 |
| 100 | end |
| 101 | pages_before = c1_pool_active_count |
| 102 | rc = c1_reconstruct_branch 1 prompt |
| 103 | if ne rc C1_OK |
| 104 | ret 20 |
| 105 | end |
| 106 | if ne c1_pool_active_count pages_before |
| 107 | ret 21 |
| 108 | end |
| 109 | |
| 110 | note 7. Corrupt checksum detection |
| 111 | put c1_p_toks 0 xor get c1_p_toks 0 1 |
| 112 | got = c1_get_tokens 10 readback |
| 113 | if ne got long C1_ERR_CORRUPT |
| 114 | ret 22 |
| 115 | end |
| 116 | note Restore checksum before cleanup |
| 117 | put c1_p_toks 0 xor get c1_p_toks 0 1 |
| 118 | |
| 119 | note 8. Remove all branches -> 0 active pages |
| 120 | rc = c1_remove_branch 1 |
| 121 | if ne rc C1_OK |
| 122 | ret 23 |
| 123 | end |
| 124 | for c ulong 8 |
| 125 | rc = c1_remove_branch add 10 c |
| 126 | if ne rc C1_OK |
| 127 | ret 24 |
| 128 | end |
| 129 | end |
| 130 | if ne c1_pool_active_count 0 |
| 131 | ret 25 |
| 132 | end |
| 133 | |
| 134 | ret 0 |
| 135 | end |