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-cortex / cortex_test.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note aienux/crates/aienos-cortex/cortex_test.om: Behavioral self-test for aienos-cortex. |
| 3 | note Compose with: si/directives/om2.om om/tls/sha2.om aienux/crates/aienos-cortex/cortex.om aienux/crates/aienos-cortex/cortex_test.om |
| 4 | |
| 5 | text ct_s_obs "UART0 base physical address is 0x09000000" |
| 6 | text ct_p_dt "device_tree" |
| 7 | text ct_r_uart "phys_uart0_reg" |
| 8 | text ct_s_inf1 "Driver can safely bind to UART0 MMIO" |
| 9 | text ct_m_llama "llama3-spark" |
| 10 | text ct_s_inf2 "Early console can initialize without Linux driver" |
| 11 | text ct_s_hall "The system has 1024 GB10 GPUs connected" |
| 12 | text ct_m_spec "speculative_model" |
| 13 | text ct_s_ca "Claim A is true because Claim B is true" |
| 14 | text ct_s_cb "Claim B is true because Claim A is true" |
| 15 | text ct_m_circ "model_hallucination" |
| 16 | text ct_s_forged "Secret backdoors exist in kernel" |
| 17 | text ct_m_adv "adversarial_prompt" |
| 18 | text ct_s_fab "Fabricated premise with zero grounding" |
| 19 | text ct_m_mal "malicious_model" |
| 20 | text ct_s_mix "Hybrid inference based on observation AND fabrication" |
| 21 | text ct_m_hyb "hybrid_model" |
| 22 | text ct_s_hyp "Hypothesis derived from valid observation" |
| 23 | text ct_a_exp "explorer_agent" |
| 24 | text ct_s_tr "Inference deduced from verified hypothesis" |
| 25 | text ct_m_rsn "reasoning_model" |
| 26 | text ct_reason "Hardware sensor disagrees with fabricated premise" |
| 27 | |
| 28 | text ct_p_obs "Boot completed at tick 42" |
| 29 | text ct_p_klog "kernel_log" |
| 30 | text ct_p_fact "SHA256 test vector passes FIPS 180-4" |
| 31 | text ct_p_tsuite "test_suite" |
| 32 | text ct_p_vtool "cargo_test" |
| 33 | text ct_p_proof "proof" |
| 34 | text ct_p_op "Promote Phase 3 to canonical state" |
| 35 | text ct_p_opsig "operator_ed25519_key" |
| 36 | |
| 37 | fn ct_test_grounding to int |
| 38 | cx_init |
| 39 | obs_id = new uchar 16 0 |
| 40 | inf_id = new uchar 16 0 |
| 41 | inf2_id = new uchar 16 0 |
| 42 | tmp_id = new uchar 16 0 |
| 43 | |
| 44 | note 1. Record raw hardware observation |
| 45 | cx_stage_reset |
| 46 | rc = cx_stage_set_payload ct_r_uart |
| 47 | rc = cx_record_observation ct_s_obs ct_p_dt 100 obs_id |
| 48 | if ne rc CORTEX_OK |
| 49 | ret 1 |
| 50 | end |
| 51 | |
| 52 | note 2. Valid inference derived from observation |
| 53 | cx_stage_reset |
| 54 | rc = cx_stage_add_parent view obs_id |
| 55 | if ne rc CORTEX_OK |
| 56 | ret 2 |
| 57 | end |
| 58 | cx_stage_set_conf 0.95f32 |
| 59 | rc = cx_record_inference ct_s_inf1 ct_m_llama 101 inf_id |
| 60 | if ne rc CORTEX_OK |
| 61 | ret 3 |
| 62 | end |
| 63 | |
| 64 | note Deep grounded inference: inf2 -> inf -> obs |
| 65 | cx_stage_reset |
| 66 | rc = cx_stage_add_parent view inf_id |
| 67 | if ne rc CORTEX_OK |
| 68 | ret 4 |
| 69 | end |
| 70 | cx_stage_set_conf 0.90f32 |
| 71 | rc = cx_record_inference ct_s_inf2 ct_m_llama 102 inf2_id |
| 72 | if ne rc CORTEX_OK |
| 73 | ret 5 |
| 74 | end |
| 75 | |
| 76 | note 3. Hallucination test: ungrounded inference (no parents) |
| 77 | cx_stage_reset |
| 78 | cx_stage_set_conf 0.99f32 |
| 79 | rc = cx_record_inference ct_s_hall ct_m_spec 103 tmp_id |
| 80 | if ne rc CORTEX_ERR_UNGROUNDED |
| 81 | ret 6 |
| 82 | end |
| 83 | |
| 84 | note 4. Circular inference with no ground truth (A <-> B) |
| 85 | cx_stage_reset |
| 86 | cx_stage_set_conf 0.8f32 |
| 87 | rc = cx_stage_build CORTEX_INFERENCE ct_s_ca ct_m_circ 104 |
| 88 | if ne rc CORTEX_OK |
| 89 | ret 7 |
| 90 | end |
| 91 | id_a = new uchar 16 0 |
| 92 | for i ulong 16 |
| 93 | put id_a i get cx_st_id i |
| 94 | end |
| 95 | slot_a = cx_insert_staged |
| 96 | if lt slot_a 0 |
| 97 | ret 8 |
| 98 | end |
| 99 | cx_stage_reset |
| 100 | rc = cx_stage_add_parent view id_a |
| 101 | cx_stage_set_conf 0.8f32 |
| 102 | rc = cx_stage_build CORTEX_INFERENCE ct_s_cb ct_m_circ 104 |
| 103 | id_b = new uchar 16 0 |
| 104 | for i ulong 16 |
| 105 | put id_b i get cx_st_id i |
| 106 | end |
| 107 | slot_b = cx_insert_staged |
| 108 | if lt slot_b 0 |
| 109 | ret 9 |
| 110 | end |
| 111 | put cx_pcnt ulong slot_a 1 |
| 112 | base_a = mul ulong slot_a mul CORTEX_MAX_PARENTS CORTEX_ID_LEN |
| 113 | for i ulong 16 |
| 114 | put cx_parents add base_a i get id_b i |
| 115 | end |
| 116 | if ne cx_verify_slot ulong slot_a CORTEX_ERR_CIRCULAR |
| 117 | ret 10 |
| 118 | end |
| 119 | |
| 120 | note 5. Hallucination referencing non-existent parent |
| 121 | forged = new uchar 16 0xaa |
| 122 | cx_stage_reset |
| 123 | rc = cx_stage_add_parent view forged |
| 124 | cx_stage_set_conf 0.8f32 |
| 125 | rc = cx_record_inference ct_s_forged ct_m_adv 105 tmp_id |
| 126 | if ne rc CORTEX_ERR_NOT_FOUND |
| 127 | ret 11 |
| 128 | end |
| 129 | |
| 130 | note 6. Mixed parent grounding rejection (obs + ungrounded premise) |
| 131 | cx_stage_reset |
| 132 | cx_stage_set_conf 0.9f32 |
| 133 | rc = cx_stage_build CORTEX_INFERENCE ct_s_fab ct_m_mal 106 |
| 134 | id_ungr = new uchar 16 0 |
| 135 | for i ulong 16 |
| 136 | put id_ungr i get cx_st_id i |
| 137 | end |
| 138 | slot_u = cx_insert_staged |
| 139 | if lt slot_u 0 |
| 140 | ret 12 |
| 141 | end |
| 142 | cx_stage_reset |
| 143 | rc = cx_stage_add_parent view obs_id |
| 144 | rc = cx_stage_add_parent view id_ungr |
| 145 | cx_stage_set_conf 0.85f32 |
| 146 | rc = cx_record_inference ct_s_mix ct_m_hyb 107 tmp_id |
| 147 | if ne rc CORTEX_ERR_UNGROUNDED |
| 148 | ret 13 |
| 149 | end |
| 150 | |
| 151 | note 7. Transitive grounding: Observation -> Hypothesis -> Inference |
| 152 | cx_stage_reset |
| 153 | rc = cx_stage_add_parent view obs_id |
| 154 | rc = cx_record_hypothesis ct_s_hyp ct_a_exp 108 tmp_id |
| 155 | if ne rc CORTEX_OK |
| 156 | ret 14 |
| 157 | end |
| 158 | cx_stage_reset |
| 159 | rc = cx_stage_add_parent view tmp_id |
| 160 | cx_stage_set_conf 0.95f32 |
| 161 | rc = cx_record_inference ct_s_tr ct_m_rsn 109 inf_id |
| 162 | if ne rc CORTEX_OK |
| 163 | ret 15 |
| 164 | end |
| 165 | |
| 166 | note 8. Flag contradiction between opposing records |
| 167 | rc = cx_flag_contradiction view obs_id view id_ungr ct_reason 110 tmp_id |
| 168 | if ne rc CORTEX_OK |
| 169 | ret 16 |
| 170 | end |
| 171 | slot_u = cx_find_by_id view tmp_id |
| 172 | if lt slot_u 0 |
| 173 | ret 17 |
| 174 | end |
| 175 | if ne get cx_status ulong slot_u CORTEX_CONTRADICTION |
| 176 | ret 18 |
| 177 | end |
| 178 | ret 0 |
| 179 | end |
| 180 | |
| 181 | fn ct_test_persistence to int |
| 182 | cx_init |
| 183 | obs_id = new uchar 16 0 |
| 184 | fact_id = new uchar 16 0 |
| 185 | op_id = new uchar 16 0 |
| 186 | |
| 187 | cx_stage_reset |
| 188 | rc = cx_record_observation ct_p_obs ct_p_klog 100 obs_id |
| 189 | if ne rc CORTEX_OK |
| 190 | ret 20 |
| 191 | end |
| 192 | cx_stage_reset |
| 193 | rc = cx_stage_add_parent view obs_id |
| 194 | rc = cx_stage_set_verifier ct_p_vtool |
| 195 | rc = cx_stage_set_payload ct_p_proof |
| 196 | rc = cx_record_verified_fact ct_p_fact ct_p_tsuite 101 fact_id |
| 197 | if ne rc CORTEX_OK |
| 198 | ret 21 |
| 199 | end |
| 200 | rc = cx_record_operator_decision ct_p_op ct_p_opsig 102 op_id |
| 201 | if ne rc CORTEX_OK |
| 202 | ret 22 |
| 203 | end |
| 204 | |
| 205 | if ne cx_count_by_status CORTEX_DIRECT_OBSERVATION 1 |
| 206 | ret 23 |
| 207 | end |
| 208 | if ne cx_count_by_status CORTEX_VERIFIED_FACT 1 |
| 209 | ret 24 |
| 210 | end |
| 211 | if ne cx_count_by_status CORTEX_OPERATOR_DECISION 1 |
| 212 | ret 25 |
| 213 | end |
| 214 | |
| 215 | jbuf = new uchar 4096 0 |
| 216 | jlen = cx_export_journal jbuf |
| 217 | if le jlen 38 |
| 218 | ret 26 |
| 219 | end |
| 220 | cx_init |
| 221 | if ne get cx_cnt 0 0 |
| 222 | ret 27 |
| 223 | end |
| 224 | imported = cx_import_journal view jbuf ulong jlen |
| 225 | if ne imported 3 |
| 226 | ret 28 |
| 227 | end |
| 228 | if lt cx_find_by_id view obs_id 0 |
| 229 | ret 29 |
| 230 | end |
| 231 | if lt cx_find_by_id view fact_id 0 |
| 232 | ret 30 |
| 233 | end |
| 234 | if lt cx_find_by_id view op_id 0 |
| 235 | ret 31 |
| 236 | end |
| 237 | |
| 238 | put jbuf 10 xor get jbuf 10 0xff |
| 239 | cx_init |
| 240 | if ne cx_import_journal view jbuf ulong jlen long CORTEX_ERR_CHECKSUM |
| 241 | ret 32 |
| 242 | end |
| 243 | ret 0 |
| 244 | end |
| 245 | |
| 246 | fn main to int |
| 247 | rc = ct_test_grounding |
| 248 | if ne rc 0 |
| 249 | ret rc |
| 250 | end |
| 251 | rc = ct_test_persistence |
| 252 | if ne rc 0 |
| 253 | ret rc |
| 254 | end |
| 255 | ret 0 |
| 256 | end |