physics-mv
FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence.
Brought by drakestapleton
physics-mv / tests / test_forge_hwid.c
| 1 | #include "forge_descriptor.h" |
| 2 | #include <inttypes.h> |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <string.h> |
| 6 | |
| 7 | static int g_total = 0, g_passed = 0, g_failed = 0; |
| 8 | |
| 9 | static void report(const char *name, int ok) { |
| 10 | g_total++; |
| 11 | if (ok) { |
| 12 | g_passed++; |
| 13 | printf("[PASS] %s\n", name); |
| 14 | } else { |
| 15 | g_failed++; |
| 16 | printf("[FAIL] %s\n", name); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | int main(void) { |
| 21 | printf("============================================================\n"); |
| 22 | printf(" GATE 4: FORGE-HWID QUALIFICATION SUITE \n"); |
| 23 | printf("============================================================\n\n"); |
| 24 | |
| 25 | ForgeMachineDescriptor desc; |
| 26 | memset(&desc, 0, sizeof(desc)); |
| 27 | |
| 28 | /* 1. RAW_HARDWARE_PROBE_CAPTURED */ |
| 29 | int probe_rc = forge_probe_hardware(&desc); |
| 30 | printf("[*] forge_probe_hardware() result: %d\n", probe_rc); |
| 31 | if (probe_rc == 0) { |
| 32 | printf(" PCI BDF: %s\n", desc.pci_bdf); |
| 33 | printf(" PCI Vendor:Device: %04x:%04x\n", desc.pci_vendor_id, desc.pci_device_id); |
| 34 | printf(" PCI Subsystem: %04x:%04x\n", desc.pci_subsystem_vendor_id, desc.pci_subsystem_device_id); |
| 35 | printf(" RM Compute Class: 0x%x\n", desc.rm_compute_class); |
| 36 | printf(" RM SM Version: 0x%x\n", desc.rm_sm_version); |
| 37 | printf(" Driver Version: %s\n", desc.driver_version); |
| 38 | printf(" VBIOS Version: %s\n", desc.vbios_version); |
| 39 | printf(" Total Memory: %" PRIu64 " bytes (%.2f GiB)\n", |
| 40 | desc.total_system_memory_bytes, (double)desc.total_system_memory_bytes / (1024.0 * 1024.0 * 1024.0)); |
| 41 | printf(" DMA Mask: 0x%" PRIx64 "\n", desc.dma_mask); |
| 42 | printf(" Features: 0x%x\n", desc.features); |
| 43 | } |
| 44 | int raw_probe_ok = (probe_rc == 0) && |
| 45 | (desc.pci_vendor_id == 0x10de) && |
| 46 | (desc.pci_device_id != 0) && |
| 47 | (desc.pci_bdf[0] != '\0') && |
| 48 | (desc.rm_compute_class == 0xcec0) && |
| 49 | (desc.rm_sm_version == 0x0a04) && |
| 50 | (desc.driver_version[0] != '\0') && |
| 51 | (desc.total_system_memory_bytes > 0); |
| 52 | report("RAW_HARDWARE_PROBE_CAPTURED", raw_probe_ok); |
| 53 | |
| 54 | /* 2. FORGE_DESCRIPTOR_NORMALIZED */ |
| 55 | int norm_rc = forge_descriptor_normalize(&desc); |
| 56 | report("FORGE_DESCRIPTOR_NORMALIZED", norm_rc == 0); |
| 57 | |
| 58 | /* 3. DESCRIPTOR_DIGEST_BOUND */ |
| 59 | uint8_t digest1[FORGE_DESC_DIGEST_LEN]; |
| 60 | uint8_t digest2[FORGE_DESC_DIGEST_LEN]; |
| 61 | int d1_rc = forge_descriptor_compute_digest(&desc, digest1); |
| 62 | int d2_rc = forge_descriptor_compute_digest(&desc, digest2); |
| 63 | char hex_digest[65]; |
| 64 | forge_descriptor_digest_hex(digest1, hex_digest); |
| 65 | printf("[*] Observed Descriptor Digest: %s\n", hex_digest); |
| 66 | int digest_bound_ok = (d1_rc == 0) && (d2_rc == 0) && |
| 67 | (memcmp(digest1, digest2, FORGE_DESC_DIGEST_LEN) == 0); |
| 68 | report("DESCRIPTOR_DIGEST_BOUND", digest_bound_ok); |
| 69 | |
| 70 | /* 4. RECEIPT_HARDWARE_DERIVED (Derived alias sm_121 from observed facts) */ |
| 71 | const char *alias = forge_descriptor_derived_alias(&desc); |
| 72 | printf("[*] Derived Display Alias: %s\n", alias ? alias : "(none)"); |
| 73 | int alias_ok = (alias != NULL) && (strcmp(alias, "sm_121") == 0) && |
| 74 | (forge_descriptor_verify_alias(&desc, "sm_121") == 0); |
| 75 | report("RECEIPT_HARDWARE_DERIVED", alias_ok); |
| 76 | |
| 77 | /* 5. SERIALIZATION_KAT_VERIFIED */ |
| 78 | int kat_rc = forge_descriptor_run_kat(); |
| 79 | report("SERIALIZATION_KAT_VERIFIED", kat_rc == 0); |
| 80 | |
| 81 | /* --- NEGATIVE TESTS --- */ |
| 82 | printf("\n[*] Running Gate 4 Negative Tests...\n"); |
| 83 | |
| 84 | /* Neg 1: Missing required field (zeroed BDF) */ |
| 85 | ForgeMachineDescriptor missing_field = desc; |
| 86 | memset(missing_field.pci_bdf, 0, sizeof(missing_field.pci_bdf)); |
| 87 | int neg_missing_rc = forge_descriptor_normalize(&missing_field); |
| 88 | report("NEG_MISSING_REQUIRED_FIELD_REJECTED", neg_missing_rc != 0); |
| 89 | |
| 90 | /* Neg 2: Malformed PCI identity */ |
| 91 | ForgeMachineDescriptor malformed_pci = desc; |
| 92 | malformed_pci.pci_vendor_id = 0x8086; /* Non-NVIDIA */ |
| 93 | int neg_pci_rc = forge_descriptor_normalize(&malformed_pci); |
| 94 | report("NEG_MALFORMED_PCI_REJECTED", neg_pci_rc != 0); |
| 95 | |
| 96 | /* Neg 3: Unsupported compute class */ |
| 97 | ForgeMachineDescriptor unsupported_cc = desc; |
| 98 | unsupported_cc.rm_compute_class = 0xc7c0; /* Hopper or unrecognized */ |
| 99 | const char *unsupported_alias = forge_descriptor_derived_alias(&unsupported_cc); |
| 100 | report("NEG_UNSUPPORTED_COMPUTE_CLASS_REJECTED", unsupported_alias == NULL); |
| 101 | |
| 102 | /* Neg 4: Descriptor mutation causing digest mismatch */ |
| 103 | ForgeMachineDescriptor mutated = desc; |
| 104 | mutated.dma_mask ^= 0x1000; |
| 105 | uint8_t mutated_digest[FORGE_DESC_DIGEST_LEN]; |
| 106 | forge_descriptor_compute_digest(&mutated, mutated_digest); |
| 107 | int mutation_mismatch = (memcmp(digest1, mutated_digest, FORGE_DESC_DIGEST_LEN) != 0); |
| 108 | report("NEG_DESCRIPTOR_MUTATION_CAUSES_DIGEST_MISMATCH", mutation_mismatch); |
| 109 | |
| 110 | /* Neg 5: Hard-coded / unbound alias rejection */ |
| 111 | int unbound_rc = forge_descriptor_verify_alias(&desc, "sm_90"); |
| 112 | report("NEG_UNBOUND_ALIAS_REJECTED", unbound_rc != 0); |
| 113 | |
| 114 | printf("\nGate 4 Results: TOTAL=%d PASSED=%d FAILED=%d\n", g_total, g_passed, g_failed); |
| 115 | return (g_failed == 0) ? 0 : 1; |
| 116 | } |