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_nvrm_buddy.c
| 1 | /* Host-only check of nvrm_buddy_free_blocks_ge and of the 2 MiB-block part of |
| 2 | * the NV_ERR_NO_MEMORY report, nvrm_no_memory_blocks (DRA-351). No GPU: it reads a |
| 3 | * fixed buddy table. The DMA row is /proc/buddyinfo of the Spark at |
| 4 | * 2026-11-16T22:48:36Z verbatim (DRA-528 record 528-buddyinfo-20261116T224836Z.txt); |
| 5 | * the Normal row is the Normal row the DRA-351 R13 instr6 run recorded before |
| 6 | * it started (351-r13-instr6.buddy-pre), a table with no free 2 MiB block in |
| 7 | * the Normal zone. The NormalX row is synthetic, no kernel prints that zone: it |
| 8 | * guards exact zone-name matching. */ |
| 9 | #include "nvrm.h" |
| 10 | #include <limits.h> |
| 11 | #include <stdio.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <string.h> |
| 14 | #include <unistd.h> |
| 15 | |
| 16 | static const char *TABLE = |
| 17 | "Node 0, zone DMA 485 459 405 339 277 185 113 59 23 11 1 3 3 8 \n" |
| 18 | "Node 0, zone Normal 117938 93817 48619 75527 17579 215 346 4 1 0 0 0 0 0 \n" |
| 19 | "Node 0, zone NormalX 0 0 0 0 0 0 0 0 0 5 0 0 0 0 \n"; |
| 20 | |
| 21 | static int fails; |
| 22 | static void check(const char *what, unsigned long long got, unsigned long long want) { |
| 23 | printf("%-34s got %llu want %llu %s\n", what, got, want, got == want ? "PASS" : "FAIL"); |
| 24 | if (got != want) fails++; |
| 25 | } |
| 26 | static void check_text(const char *what, const char *got, const char *want) { |
| 27 | int ok = strcmp(got, want) == 0; |
| 28 | printf("%-34s got \"%s\" want \"%s\" %s\n", what, got, want, ok ? "PASS" : "FAIL"); |
| 29 | if (!ok) fails++; |
| 30 | } |
| 31 | |
| 32 | int main(void) { |
| 33 | char path[] = "/tmp/nvrm-buddy-XXXXXX"; |
| 34 | int fd = mkstemp(path); |
| 35 | if (fd < 0) { perror("mkstemp"); return 2; } |
| 36 | FILE *f = fdopen(fd, "w"); |
| 37 | if (!f || fputs(TABLE, f) == EOF || fclose(f) != 0) { perror("write"); unlink(path); return 2; } |
| 38 | |
| 39 | check("Normal zone, order >= 9", nvrm_buddy_free_blocks_ge(path, "Normal", 9), 0); |
| 40 | check("Normal zone, order >= 8", nvrm_buddy_free_blocks_ge(path, "Normal", 8), 1); |
| 41 | check("DMA zone, order >= 9", nvrm_buddy_free_blocks_ge(path, "DMA", 9), 26); |
| 42 | check("all zones, order >= 9", nvrm_buddy_free_blocks_ge(path, NULL, 9), 31); |
| 43 | check("prefix is not the zone (Norm)", nvrm_buddy_free_blocks_ge(path, "Norm", 9), 0); |
| 44 | char report[128]; |
| 45 | nvrm_no_memory_blocks(path, report, sizeof report); |
| 46 | check_text("report, Normal zone then all", report, "free 2 MiB blocks in the Normal zone 0 (all zones 31)"); |
| 47 | unlink(path); |
| 48 | check("unreadable table", nvrm_buddy_free_blocks_ge(path, "Normal", 9), ULLONG_MAX); |
| 49 | nvrm_no_memory_blocks(path, report, sizeof report); |
| 50 | check_text("report, unreadable table", report, "free 2 MiB blocks in the Normal zone UNKNOWN (all zones UNKNOWN)"); |
| 51 | |
| 52 | printf("NVRM_BUDDY_ZONE %s (%d failed)\n", fails ? "FAIL" : "PASS", fails); |
| 53 | return fails ? 1 : 0; |
| 54 | } |