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/aienux/blob/main/native/kernel/ui/tests/boot_show_test.c # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / kernel / ui / tests / boot_show_test.c` 110 lines ยท 4641 bytes Raw Blame History 1 /* boot_show_test.c -- host test of the boot sequence's frame receipt 2 * (ui/boot_show.c) on Allen's home (ui/allen_ui.c). Run by 3 * scripts/ck_boot_show_test.sh. 4 * 5 * 1. A fake clock that moves 1 ms a step: the night draws at its 16 ms cap, 6 * no 60 Hz slot goes without a frame (0 dropped of 912). 7 * 2. The same clock moving 50 ms a step (a slow machine): 304 frames, every 8 * frame followed by two empty slots, 608 dropped of 912. 9 * 3. The present hook runs once per drawn frame. 10 * 4. The chirp position follows the night's clock (48 frames a ms). 11 * 5. Optional (argv[1] = WxH): the real clock of this host, one core, the 12 * whole night at that size; prints the receipt line (a host fixture, not a 13 * claim about any machine). */ 14 #include "../allen_ui.h" 15 #include "../boot_show.h" 16 #include 17 #include 18 #include 19 #include 20 21 static int fails, checks; 22 #define CHECK(c, what) \ 23 do { \ 24 checks++; \ 25 if (!(c)) { \ 26 fails++; \ 27 printf("FAIL %s\n", what); \ 28 } \ 29 } while (0) 30 31 static unsigned presents; 32 static void present(void *ctx) 33 { 34 (void)ctx; 35 presents++; 36 } 37 38 static uint64_t real_ns(void) 39 { 40 struct timespec ts; 41 clock_gettime(CLOCK_MONOTONIC, &ts); 42 return (uint64_t)ts.tv_sec * 1000000000u + (uint64_t)ts.tv_nsec; 43 } 44 45 static void run_fake(uint32_t w, uint32_t h, uint32_t step_ms, struct ck_boot_show_stats *st, unsigned *pres) 46 { 47 size_t mem_len = ck_allen_ui_mem_bytes(w, h); 48 uint32_t *fb = calloc((size_t)w * h, 4); 49 void *mem = calloc(1, mem_len); 50 presents = 0; 51 /* clock in ms; NULL clock: drawing time is not timed */ 52 if (!fb || !mem || ck_boot_show_start(fb, w, h, w, 1, mem, mem_len, 1000, 0, NULL, present, NULL)) { 53 CHECK(0, "start"); 54 exit(1); 55 } 56 uint64_t now = 0; 57 while (ck_boot_show_tick(now)) 58 now += step_ms; 59 ck_boot_show_stats(st); 60 *pres = presents; 61 free(fb); 62 free(mem); 63 } 64 65 int main(int argc, char **argv) 66 { 67 struct ck_boot_show_stats st; 68 unsigned pres; 69 70 CHECK(CK_BOOT_SHOW_SLOTS == 912u, "912 slots of 60 Hz in the 15.2 s night"); 71 72 run_fake(1280, 800, 1, &st, &pres); 73 printf("fake 1 ms steps: " CK_BOOT_SHOW_LINE, CK_BOOT_SHOW_ARGS(st, 1280u, 800u, "fake")); 74 CHECK(st.slots == 912u, "1 ms: slots"); 75 CHECK(st.dropped == 0u, "1 ms: nothing dropped"); 76 CHECK(st.frames == 950u, "1 ms: one frame every 16 ms (0..15184)"); 77 CHECK(st.ms == CK_BOOT_SHOW_MS, "1 ms: clock at the end"); 78 CHECK(pres == st.frames, "1 ms: one present per frame"); 79 80 run_fake(1280, 800, 50, &st, &pres); 81 printf("fake 50 ms steps: " CK_BOOT_SHOW_LINE, CK_BOOT_SHOW_ARGS(st, 1280u, 800u, "fake")); 82 CHECK(st.frames == 304u, "50 ms: 304 frames"); 83 CHECK(st.dropped == 608u, "50 ms: two empty slots after every frame"); 84 CHECK(pres == 304u, "50 ms: one present per frame"); 85 86 CHECK(ck_boot_show_audio_frame(1000) == 48000u, "chirp position: 48000 frames at 1 s"); 87 CHECK(ck_boot_show_ms(12000) == CK_NIGHT_MERGE_MS, "night clock: the merger at 12 s"); 88 89 if (argc > 1) { 90 unsigned w = 0, h = 0; 91 if (sscanf(argv[1], "%ux%u", &w, &h) != 2) { 92 CHECK(0, "size argument WxH"); 93 } else { 94 size_t mem_len = ck_allen_ui_mem_bytes(w, h); 95 uint32_t *fb = calloc((size_t)w * h, 4); 96 void *mem = calloc(1, mem_len); 97 CHECK(fb && mem && !ck_boot_show_start(fb, w, h, w, 1, mem, mem_len, 1000000000u, real_ns(), real_ns, 98 NULL, NULL), 99 "host start"); 100 while (ck_boot_show_tick(real_ns())) 101 ; 102 ck_boot_show_stats(&st); 103 printf("host one core: " CK_BOOT_SHOW_LINE, CK_BOOT_SHOW_ARGS(st, w, h, "host-memory")); 104 free(fb); 105 free(mem); 106 } 107 } 108 printf("BOOT_SHOW_TEST: %s (%d checks)\n", fails ? "FAIL" : "PASS", checks); 109 return fails ? 1 : 0; 110 }