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 / si / architecture / verify / test.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note si/architecture/verify/test.om: positive & negative control test suite for |
| 3 | note aien-architecture-mv authority, capability register, and invariant verification engine. |
| 4 | note Compose with: |
| 5 | note si/directives/om2.om om/tls/sha2.om si/architecture/verify/authority.om si/architecture/verify/test.om |
| 6 | |
| 7 | text t_pass "PASS " |
| 8 | text t_fail "FAIL " |
| 9 | text t_nl "\n" |
| 10 | |
| 11 | text t_c1 "adr_id_parsing_and_supersession_cycle_controls" |
| 12 | text t_c2 "plan_authority_and_release_qualification_controls" |
| 13 | text t_c3 "capability_register_language_and_dirty_tree_controls" |
| 14 | text t_c4 "capability_register_emulator_vs_hardware_qualification" |
| 15 | text t_c5 "layer_dependency_monotonicity_and_inversion_controls" |
| 16 | text t_c6 "evidence_immutability_additions_only_controls" |
| 17 | text t_c7 "authority_record_digest_determinism_and_sensitivity" |
| 18 | text t_done "PASS aien-architecture-verify all 7 test suites passed\n" |
| 19 | |
| 20 | text t_adr_ok "ADR-0047" |
| 21 | text t_adr_zero "ADR-0000" |
| 22 | text t_adr_badpfx "RFC-0047" |
| 23 | text t_adr_short "ADR-47" |
| 24 | text t_adr_alpha "ADR-004a" |
| 25 | |
| 26 | text t_sha40_a "3a9fe6de80123456789abcdef0123456789abcde" |
| 27 | text t_sha40_b "0811840af0123456789abcdef0123456789abcde" |
| 28 | text t_sha40_bad "3a9fe6de8" |
| 29 | text t_sha64_ok "34d611ca0415eab1728d3234911d90e74af17ba9ab0c581d559f48274d7ca6d3" |
| 30 | text t_sha64_bad "zzzz11ca0415eab1728d3234911d90e74af17ba9ab0c581d559f48274d7ca6d3" |
| 31 | |
| 32 | fn report_case name view uchar * ok bool to int |
| 33 | if ok |
| 34 | w1 = arch_write_all int 1 t_pass |
| 35 | w2 = arch_write_all int 1 name |
| 36 | w3 = arch_write_all int 1 t_nl |
| 37 | if and w1 and w2 w3 |
| 38 | ret int 0 |
| 39 | end |
| 40 | ret int 1 |
| 41 | end |
| 42 | w4 = arch_write_all int 1 t_fail |
| 43 | w5 = arch_write_all int 1 name |
| 44 | w6 = arch_write_all int 1 t_nl |
| 45 | if and w4 and w5 w6 |
| 46 | ret int 1 |
| 47 | end |
| 48 | ret int 1 |
| 49 | end |
| 50 | |
| 51 | fn test_adr_ids to bool |
| 52 | if ne arch_parse_adr_id t_adr_ok long 47 |
| 53 | ret false |
| 54 | end |
| 55 | note Negative controls: ADR-0000, wrong prefix, short, non-digit |
| 56 | if ne arch_parse_adr_id t_adr_zero long -1 |
| 57 | ret false |
| 58 | end |
| 59 | if ne arch_parse_adr_id t_adr_badpfx long -1 |
| 60 | ret false |
| 61 | end |
| 62 | if ne arch_parse_adr_id t_adr_short long -1 |
| 63 | ret false |
| 64 | end |
| 65 | if ne arch_parse_adr_id t_adr_alpha long -1 |
| 66 | ret false |
| 67 | end |
| 68 | note Valid ACCEPTED ADR and valid forward supersession (47 -> 52) |
| 69 | if ne arch_validate_adr t_adr_ok AUTH_ACCEPTED ulong 0 ARCH_OK |
| 70 | ret false |
| 71 | end |
| 72 | if ne arch_validate_adr t_adr_ok AUTH_SUPERSEDED ulong 52 ARCH_OK |
| 73 | ret false |
| 74 | end |
| 75 | note Negative controls: self-supersession (47 -> 47), backward supersession (47 -> 10), nonzero superseded_by on ACCEPTED |
| 76 | if ne arch_validate_adr t_adr_ok AUTH_SUPERSEDED ulong 47 ARCH_ERR_CYCLE_SUPERSEDE |
| 77 | ret false |
| 78 | end |
| 79 | if ne arch_validate_adr t_adr_ok AUTH_SUPERSEDED ulong 10 ARCH_ERR_CYCLE_SUPERSEDE |
| 80 | ret false |
| 81 | end |
| 82 | if ne arch_validate_adr t_adr_ok AUTH_ACCEPTED ulong 52 ARCH_ERR_CYCLE_SUPERSEDE |
| 83 | ret false |
| 84 | end |
| 85 | ret true |
| 86 | end |
| 87 | |
| 88 | fn test_release_authority to bool |
| 89 | if not arch_adr_is_binding AUTH_ACCEPTED |
| 90 | ret false |
| 91 | end |
| 92 | if arch_adr_is_binding AUTH_PROPOSED |
| 93 | ret false |
| 94 | end |
| 95 | if arch_adr_is_binding AUTH_SUPERSEDED |
| 96 | ret false |
| 97 | end |
| 98 | if ne arch_check_release_authority AUTH_ACCEPTED t_sha40_a false ARCH_OK |
| 99 | ret false |
| 100 | end |
| 101 | note Negative controls: PROPOSED plan != qualified release, dirty tree refused, bad commit SHA refused |
| 102 | if ne arch_check_release_authority AUTH_PROPOSED t_sha40_a false ARCH_ERR_UNQUALIFIED_REL |
| 103 | ret false |
| 104 | end |
| 105 | if ne arch_check_release_authority AUTH_ACCEPTED t_sha40_a true ARCH_ERR_DIRTY_TREE |
| 106 | ret false |
| 107 | end |
| 108 | if ne arch_check_release_authority AUTH_ACCEPTED t_sha40_bad false ARCH_ERR_BAD_SHA |
| 109 | ret false |
| 110 | end |
| 111 | ret true |
| 112 | end |
| 113 | |
| 114 | fn test_cap_lang_and_dirty to bool |
| 115 | if ne arch_verify_cap_lang true LANG_OMEGA ARCH_OK |
| 116 | ret false |
| 117 | end |
| 118 | note Negative controls: new C or Rust capability must be refused |
| 119 | if ne arch_verify_cap_lang true LANG_C_LEGACY ARCH_ERR_NON_OMEGA_NEW |
| 120 | ret false |
| 121 | end |
| 122 | if ne arch_verify_cap_lang true LANG_RUST_LEGACY ARCH_ERR_NON_OMEGA_NEW |
| 123 | ret false |
| 124 | end |
| 125 | note Existing legacy capability tracked for migration is allowed |
| 126 | if ne arch_verify_cap_lang false LANG_C_LEGACY ARCH_OK |
| 127 | ret false |
| 128 | end |
| 129 | note Dirty tree refused even for PLANNED capability |
| 130 | if ne arch_verify_cap_hw CAP_PLANNED HW_HOST_EMULATOR true ARCH_ERR_DIRTY_TREE |
| 131 | ret false |
| 132 | end |
| 133 | ret true |
| 134 | end |
| 135 | |
| 136 | fn test_cap_hw_qualification to bool |
| 137 | note Host/emulator pass is valid for CAP_VERIFIED |
| 138 | if ne arch_verify_cap_hw CAP_VERIFIED HW_HOST_EMULATOR false ARCH_OK |
| 139 | ret false |
| 140 | end |
| 141 | if ne arch_verify_cap_receipts CAP_VERIFIED t_sha40_a t_sha64_ok ARCH_OK |
| 142 | ret false |
| 143 | end |
| 144 | note GB10 and bare_metal are valid for CAP_QUALIFIED_HW |
| 145 | if ne arch_verify_cap_hw CAP_QUALIFIED_HW HW_GB10 false ARCH_OK |
| 146 | ret false |
| 147 | end |
| 148 | if ne arch_verify_cap_hw CAP_QUALIFIED_HW HW_BARE_METAL false ARCH_OK |
| 149 | ret false |
| 150 | end |
| 151 | note Negative controls: emulator CANNOT claim CAP_QUALIFIED_HW; missing/bad receipt or SHA refused |
| 152 | if ne arch_verify_cap_hw CAP_QUALIFIED_HW HW_HOST_EMULATOR false ARCH_ERR_EMULATOR_AS_HW |
| 153 | ret false |
| 154 | end |
| 155 | if ne arch_verify_cap_receipts CAP_VERIFIED t_sha40_a t_sha64_bad ARCH_ERR_MISSING_RECEIPT |
| 156 | ret false |
| 157 | end |
| 158 | if ne arch_verify_cap_receipts CAP_VERIFIED t_sha40_bad t_sha64_ok ARCH_ERR_BAD_SHA |
| 159 | ret false |
| 160 | end |
| 161 | ret true |
| 162 | end |
| 163 | |
| 164 | fn test_layer_deps to bool |
| 165 | if ne arch_layer_dep_check LAYER_APPS LAYER_PROTOCOL ARCH_OK |
| 166 | ret false |
| 167 | end |
| 168 | if ne arch_layer_dep_check LAYER_CORE LAYER_SEED ARCH_OK |
| 169 | ret false |
| 170 | end |
| 171 | if ne arch_layer_dep_check LAYER_PROTOCOL LAYER_PROTOCOL ARCH_OK |
| 172 | ret false |
| 173 | end |
| 174 | note Negative controls: lower layer depending on higher layer is a layer inversion |
| 175 | if ne arch_layer_dep_check LAYER_SEED LAYER_PROTOCOL ARCH_ERR_LAYER_INVERSION |
| 176 | ret false |
| 177 | end |
| 178 | if ne arch_layer_dep_check LAYER_AIENUX LAYER_APPS ARCH_ERR_LAYER_INVERSION |
| 179 | ret false |
| 180 | end |
| 181 | if ne arch_layer_dep_check ulong 99 LAYER_SEED ARCH_ERR_BAD_LAYER |
| 182 | ret false |
| 183 | end |
| 184 | ret true |
| 185 | end |
| 186 | |
| 187 | fn test_evidence_immutability to bool |
| 188 | if ne arch_evidence_op_check EV_OP_ADD ARCH_OK |
| 189 | ret false |
| 190 | end |
| 191 | if ne arch_evidence_op_check EV_OP_MODIFY ARCH_ERR_EVIDENCE_MUTATION |
| 192 | ret false |
| 193 | end |
| 194 | if ne arch_evidence_op_check EV_OP_RENAME ARCH_ERR_EVIDENCE_MUTATION |
| 195 | ret false |
| 196 | end |
| 197 | if ne arch_evidence_op_check EV_OP_DELETE ARCH_ERR_EVIDENCE_MUTATION |
| 198 | ret false |
| 199 | end |
| 200 | ret true |
| 201 | end |
| 202 | |
| 203 | fn test_record_digest to bool |
| 204 | d1 = new uchar 32 0 |
| 205 | d2 = new uchar 32 0 |
| 206 | arch_record_digest ulong 47 AUTH_ACCEPTED CAP_QUALIFIED_HW t_sha40_a d1 |
| 207 | arch_record_digest ulong 47 AUTH_ACCEPTED CAP_QUALIFIED_HW t_sha40_a d2 |
| 208 | if not arch_digest_eq d1 d2 |
| 209 | ret false |
| 210 | end |
| 211 | arch_record_digest ulong 47 AUTH_ACCEPTED CAP_QUALIFIED_HW t_sha40_b d2 |
| 212 | if arch_digest_eq d1 d2 |
| 213 | ret false |
| 214 | end |
| 215 | ret true |
| 216 | end |
| 217 | |
| 218 | fn main to int |
| 219 | fail = int 0 |
| 220 | fail = add fail report_case t_c1 test_adr_ids |
| 221 | fail = add fail report_case t_c2 test_release_authority |
| 222 | fail = add fail report_case t_c3 test_cap_lang_and_dirty |
| 223 | fail = add fail report_case t_c4 test_cap_hw_qualification |
| 224 | fail = add fail report_case t_c5 test_layer_deps |
| 225 | fail = add fail report_case t_c6 test_evidence_immutability |
| 226 | fail = add fail report_case t_c7 test_record_digest |
| 227 | if ne fail int 0 |
| 228 | ret int 1 |
| 229 | end |
| 230 | ok = arch_write_all int 1 t_done |
| 231 | if not ok |
| 232 | ret int 1 |
| 233 | end |
| 234 | ret int 0 |
| 235 | end |