Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tests/test_omega_genesis.c # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / test_omega_genesis.c` 118 lines ยท 5525 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* test_omega_genesis.c: the REAL Genesis Set VC-GENESIS-1 (src/omega_genesis.h), pinned. 18 * 19 * Changing the set (adding, removing or editing a member, or the set's name) is an ADR-level 20 * change. This test makes it impossible to do by accident: it fails until the pinned count and 21 * the audit record docs/osc/VC-GENESIS-1.md name exactly the same members as the table. 22 * What a LISTED member does is test_omega_genesis_set.c (a variant build with one member). 23 * Exit 0 only when every check passed. */ 24 #include 25 #include 26 #include 27 28 #include "omega_genesis.h" 29 #include "vc_fixture.h" 30 31 #define PINNED_COUNT 0u /* the audit result; edit only together with docs/osc/VC-GENESIS-1.md */ 32 33 static int g_total, g_failed; 34 static void check(const char *name, int ok) { 35 printf("%s %s\n", ok ? "PASS" : "FAIL", name); 36 g_total++; 37 if (!ok) g_failed++; 38 } 39 static void hx(const uint8_t *d, char out[65]) { 40 static const char h[] = "`0123456789abcdef`"; 41 for (int i = 0; i < 32; i++) { out[2 * i] = h[d[i] >> 4]; out[2 * i + 1] = h[d[i] & 15]; } 42 out[64] = 0; 43 } 44 static char *slurp(const char *path, size_t *n) { 45 FILE *f = fopen(path, "rb"); 46 if (!f) return NULL; 47 size_t cap = 1 << 16, len = 0; 48 char *b = malloc(cap + 1); 49 size_t r; 50 while (b && (r = fread(b + len, 1, cap - len, f)) > 0) { len += r; if (len == cap) { cap *= 2; b = realloc(b, cap + 1); } } 51 fclose(f); 52 if (!b) return NULL; 53 b[len] = 0; *n = len; 54 return b; 55 } 56 57 int main(void) { 58 check("set-name-is-vc-genesis-1", strcmp(OMEGA_GENESIS_SET_NAME, "VC-GENESIS-1") == 0); 59 check("member-count-is-the-pinned-audit-result", omega_genesis_count() == PINNED_COUNT && OMEGA_GENESIS_1_COUNT == PINNED_COUNT); 60 check("member-access-is-bounded", omega_genesis_member(omega_genesis_count()) == NULL && omega_genesis_member((size_t)-1) == NULL); 61 62 int sorted = 1, nonzero = 1, listed = 1; 63 static const uint8_t zero[32] = { 0 }; 64 for (size_t i = 0; i < omega_genesis_count(); i++) { 65 if (memcmp(omega_genesis_member(i), zero, 32) == 0) nonzero = 0; 66 if (i && memcmp(omega_genesis_member(i - 1), omega_genesis_member(i), 32) >= 0) sorted = 0; 67 if (!omega_genesis_contains(omega_genesis_member(i))) listed = 0; 68 } 69 check("table-rows-are-strictly-ascending-so-no-duplicates", sorted); 70 check("no-member-is-the-zero-id", nonzero); 71 check("every-member-is-contained", listed); 72 check("the-terminator-row-after-the-last-member-is-zero", memcmp(OMEGA_GENESIS_1[OMEGA_GENESIS_1_COUNT], zero, 32) == 0); 73 check("zero-id-and-null-are-never-members", omega_genesis_contains(zero) == 0 && omega_genesis_contains(NULL) == 0); 74 75 int none = 1; 76 for (int n = 0; n < 40; n++) if (omega_genesis_contains(vcfx((uint8_t)n)->id)) none = 0; 77 uint8_t junk[32]; memset(junk, 0xA5, 32); 78 check("no-program-we-know-and-no-junk-id-is-a-member", none && omega_genesis_contains(junk) == 0); 79 80 /* the audit record names exactly the table */ 81 size_t dn = 0; 82 char *doc = slurp("docs/osc/VC-GENESIS-1.md", &dn); 83 check("audit-record-exists", doc != NULL); 84 if (doc) { 85 char want[64]; 86 snprintf(want, sizeof want, "\nMembers: %zu\n", omega_genesis_count()); 87 check("audit-record-states-the-same-member-count", strstr(doc, want) != NULL && strstr(doc, "\nMembers: ") == strstr(doc, want)); 88 int all = 1; 89 for (size_t i = 0; i < omega_genesis_count(); i++) { char h[65]; hx(omega_genesis_member(i), h); if (!strstr(doc, h)) all = 0; } 90 check("audit-record-names-every-member-by-its-id", all); 91 /* no 64-hex id in the record that is not in the table: count them */ 92 size_t hexruns = 0, run = 0; 93 for (size_t i = 0; i <= dn; i++) { 94 char c = doc[i]; 95 if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f')) run++; 96 else { if (run == 64) hexruns++; run = 0; } 97 } 98 check("audit-record-lists-no-id-that-is-not-in-the-table", hexruns == omega_genesis_count()); 99 free(doc); 100 } 101 102 /* the header cannot be steered from outside: no environment, no files, no switches */ 103 size_t hn = 0; 104 char *hdr = slurp("src/omega_genesis.h", &hn); 105 check("header-is-readable", hdr != NULL); 106 if (hdr) { 107 static const char *const bad[] = { "getenv", "fopen", "#ifdef", "#ifndef OMEGA_GENESIS_1", "#if ", "#elif", "#include \"", "extern ", "argv", "secure_getenv" }; 108 int clean = 1; 109 for (size_t i = 0; i < sizeof bad / sizeof bad[0]; i++) if (strstr(hdr, bad[i])) { printf("note: header contains %s\n", bad[i]); clean = 0; } 110 check("header-has-no-environment-file-or-preprocessor-switch", clean); 111 free(hdr); 112 } 113 114 printf("%d checks, %d failed\n", g_total, g_failed); 115 if (g_failed) return 1; 116 printf("test-genesis-real: PASS\n"); 117 return 0; 118 }