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 / tests / visor / test_visor_machine.c
| 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 | /* Lane 5: machine view tests. Prints "PASS n/n". */ |
| 18 | #include "visor_machine.h" |
| 19 | #include "visor.h" |
| 20 | |
| 21 | #include <stdio.h> |
| 22 | #include <string.h> |
| 23 | |
| 24 | static int g_pass, g_total; |
| 25 | #define CHECK(cond, msg) do { g_total++; if (cond) g_pass++; else fprintf(stderr, "FAIL: %s (%s:%d)\n", msg, __FILE__, __LINE__); } while (0) |
| 26 | |
| 27 | static char buf1[16384], buf2[16384]; |
| 28 | |
| 29 | int main(void) { |
| 30 | OmegaMachineGraph mg, mg2; |
| 31 | VisorMachineView v, v2; |
| 32 | |
| 33 | /* current machine: assumed profile, deterministic output */ |
| 34 | CHECK(visor_machine_current(&mg, &v) == 0, "visor_machine_current"); |
| 35 | CHECK(v.observed == false, "observed is false in V1"); |
| 36 | CHECK(strstr(v.provenance, "assumed:") == v.provenance, "provenance starts with assumed:"); |
| 37 | CHECK(strstr(v.provenance, "no physics descriptor ingested") != NULL, "provenance says no descriptor"); |
| 38 | CHECK(visor_machine_current(&mg2, &v2) == 0, "visor_machine_current again"); |
| 39 | int n1 = visor_machine_format_text(&v, buf1, sizeof(buf1)); |
| 40 | int n2 = visor_machine_format_text(&v2, buf2, sizeof(buf2)); |
| 41 | CHECK(n1 > 0 && n1 == n2 && strcmp(buf1, buf2) == 0, "text twice identical"); |
| 42 | n1 = visor_machine_format_json(&v, buf1, sizeof(buf1)); |
| 43 | n2 = visor_machine_format_json(&v2, buf2, sizeof(buf2)); |
| 44 | CHECK(n1 > 0 && n1 == n2 && strcmp(buf1, buf2) == 0 && buf1[0] == '{' && buf1[n1 - 1] == '}', "json twice identical"); |
| 45 | CHECK(strstr(buf1, "\"observed\":false") != NULL, "json observed false"); |
| 46 | CHECK(visor_machine_format_text(&v, buf1, 32) == -1, "truncation fails closed"); |
| 47 | |
| 48 | /* host facts drive the same choice as current() */ |
| 49 | VisorHostFacts hf; |
| 50 | CHECK(visor_machine_host_facts(&hf) == 0, "host facts"); |
| 51 | CHECK(visor_machine_from_facts(&hf, &mg2, &v2) == 0 && memcmp(&mg2.machine_id, &mg.machine_id, sizeof(SemanticId)) == 0, |
| 52 | "current == from_facts(host)"); |
| 53 | |
| 54 | /* both canonical profiles validate topology, ids stable and distinct */ |
| 55 | OmegaMachineGraph sp, sp2, qv, qv2; |
| 56 | CHECK(omega_machine_build_dgx_spark(&sp) == 0 && omega_machine_build_dgx_spark(&sp2) == 0, "build spark"); |
| 57 | CHECK(omega_machine_build_qemu_virt(&qv) == 0 && omega_machine_build_qemu_virt(&qv2) == 0, "build qemu"); |
| 58 | CHECK(memcmp(&sp.machine_id, &sp2.machine_id, sizeof(SemanticId)) == 0, "spark id stable"); |
| 59 | CHECK(memcmp(&qv.machine_id, &qv2.machine_id, sizeof(SemanticId)) == 0, "qemu id stable"); |
| 60 | CHECK(memcmp(&sp.machine_id, &qv.machine_id, sizeof(SemanticId)) != 0, "spark != qemu id"); |
| 61 | VisorMachineView vs, vq; |
| 62 | CHECK(visor_machine_view(&sp, &vs) == 0 && vs.topology_valid, "spark topology valid"); |
| 63 | CHECK(visor_machine_view(&qv, &vq) == 0 && vq.topology_valid, "qemu topology valid"); |
| 64 | CHECK(vs.issue_width == 4 && vq.issue_width == 2, "issue widths from builders"); |
| 65 | CHECK(vs.unit_count == 6 && vq.unit_count == 5 && strcmp(vs.units[0].type_name, "ALU") == 0, "units"); |
| 66 | CHECK(vs.cache_count == 4 && vq.cache_count == 3, "caches"); |
| 67 | CHECK(vs.physics_seal_is_placeholder && vq.physics_seal_is_placeholder, "builder seals flagged placeholder"); |
| 68 | char idtxt[72]; |
| 69 | visor_format_id(&sp.machine_id, idtxt); |
| 70 | CHECK(strcmp(idtxt, vs.id_text) == 0 && strncmp(idtxt, "sha256:", 7) == 0, "id text"); |
| 71 | |
| 72 | /* broken topology is reported, not hidden */ |
| 73 | OmegaMachineGraph bad = sp; |
| 74 | bad.registers.gpr_count = 7; |
| 75 | VisorMachineView vb; |
| 76 | CHECK(visor_machine_view(&bad, &vb) == 0 && !vb.topology_valid && vb.topology_error[0], "invalid topology reported"); |
| 77 | |
| 78 | /* profile selection from facts */ |
| 79 | VisorHostFacts f; |
| 80 | memset(&f, 0, sizeof(f)); |
| 81 | snprintf(f.uname_machine, sizeof(f.uname_machine), "aarch64"); |
| 82 | snprintf(f.dmi_product, sizeof(f.dmi_product), "NVIDIA_DGX_Spark"); |
| 83 | snprintf(f.cpu_parts, sizeof(f.cpu_parts), "0xd85,0xd87"); |
| 84 | CHECK(visor_machine_from_facts(&f, &mg2, &v2) == 0 && memcmp(&mg2.machine_id, &sp.machine_id, sizeof(SemanticId)) == 0, |
| 85 | "DGX Spark DMI -> dgx_spark profile"); |
| 86 | CHECK(strstr(v2.provenance, "do NOT match") != NULL && strstr(v2.provenance, "0xd85,0xd87") != NULL, |
| 87 | "provenance records core mismatch verbatim"); |
| 88 | CHECK(!v2.observed, "spark facts still assumed"); |
| 89 | snprintf(f.dmi_product, sizeof(f.dmi_product), "Some Board"); |
| 90 | snprintf(f.cpu_parts, sizeof(f.cpu_parts), "0xd4f"); |
| 91 | CHECK(visor_machine_from_facts(&f, &mg2, &v2) == 0 && memcmp(&mg2.machine_id, &sp.machine_id, sizeof(SemanticId)) == 0, |
| 92 | "Neoverse-V2 part -> dgx_spark profile"); |
| 93 | snprintf(f.uname_machine, sizeof(f.uname_machine), "x86_64"); |
| 94 | CHECK(visor_machine_from_facts(&f, &mg2, &v2) == 0 && memcmp(&mg2.machine_id, &qv.machine_id, sizeof(SemanticId)) == 0, |
| 95 | "non-aarch64 -> qemu_virt profile"); |
| 96 | snprintf(f.uname_machine, sizeof(f.uname_machine), "aarch64"); |
| 97 | snprintf(f.cpu_parts, sizeof(f.cpu_parts), "0xd0c"); |
| 98 | CHECK(visor_machine_from_facts(&f, &mg2, &v2) == 0 && memcmp(&mg2.machine_id, &qv.machine_id, sizeof(SemanticId)) == 0, |
| 99 | "unknown aarch64 -> qemu_virt profile"); |
| 100 | |
| 101 | /* declared targets: aarch64 + Blackwell (run refused) */ |
| 102 | CHECK(v.target_count == 2, "two targets"); |
| 103 | CHECK(strcmp(v.targets[0].name, VISOR_TARGET_AARCH64) == 0 && v.targets[0].linked, "aarch64 target"); |
| 104 | CHECK(strcmp(v.targets[1].name, VISOR_TARGET_BLACKWELL) == 0, "blackwell target declared"); |
| 105 | CHECK(v.targets[1].linked, "blackwell realize objects linked in this test"); |
| 106 | CHECK(!v.targets[1].runnable && strstr(v.targets[1].note, "requires GPU submit authority") != NULL, "blackwell run refused"); |
| 107 | SemanticId bw; |
| 108 | CHECK(visor_machine_blackwell_id(&bw) == 0 && strncmp(v.targets[1].machine_id, "sha256:", 7) == 0, "blackwell id"); |
| 109 | |
| 110 | |
| 111 | visor_machine_format_text(&v, buf1, sizeof(buf1)); |
| 112 | fputs(buf1, stdout); |
| 113 | printf("%s %d/%d\n", g_pass == g_total ? "PASS" : "FAIL", g_pass, g_total); |
| 114 | return g_pass == g_total ? 0 : 1; |
| 115 | } |