aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / tests / test_gsp_seq.c
| 1 | /* test_gsp_seq.c -- the sequencer must match the pinned driver's rules, and a copy |
| 2 | * with the save-index check removed must fail the out-of-range case. */ |
| 3 | #include <stdio.h> |
| 4 | #include <string.h> |
| 5 | #include "gsp_seq.h" |
| 6 | |
| 7 | static int fails, checks; |
| 8 | #define CHECK(c, m) do { checks++; if (!(c)) { fails++; if (fails <= 20) printf("FAIL %s\n", m); } } while (0) |
| 9 | |
| 10 | static uint32_t regs[8]; |
| 11 | static uint32_t delays, core_ops; |
| 12 | |
| 13 | static uint32_t rd(void *c, uint32_t a) { (void)c; return a < 8 ? regs[a] : 0; } |
| 14 | static void wr(void *c, uint32_t a, uint32_t v) { (void)c; if (a < 8) regs[a] = v; } |
| 15 | static void delay(void *c, uint32_t us) { (void)c; delays += us; } |
| 16 | static int core(void *c, uint32_t op) { (void)c; core_ops++; return op == 99 ? -1 : 0; } |
| 17 | |
| 18 | static gsp_seq_io io(void) |
| 19 | { |
| 20 | gsp_seq_io x; |
| 21 | memset(&x, 0, sizeof x); |
| 22 | x.rd = rd; x.wr = wr; x.delay_us = delay; x.core = core; x.poll_budget = 4; |
| 23 | return x; |
| 24 | } |
| 25 | |
| 26 | int main(void) |
| 27 | { |
| 28 | const char *why = 0; |
| 29 | gsp_seq_io x = io(); |
| 30 | /* cmdIndex must be strictly inside bufferSize, as kernel_gsp.c asserts */ |
| 31 | uint32_t wr1[] = { GSP_SEQ_REG_WRITE, 1, 0xabc, 0 }; |
| 32 | CHECK(gsp_seq_run(wr1, 4, 4, &x, &why) != 0, "cmdIndex == bufferSize must refuse"); |
| 33 | CHECK(gsp_seq_run(wr1, 4, 3, &x, &why) == 0 && regs[1] == 0xabc, "REG_WRITE"); |
| 34 | regs[2] = 0xff; |
| 35 | uint32_t mod[] = { GSP_SEQ_REG_MODIFY, 2, 0x0f, 0x05, 0 }; |
| 36 | CHECK(gsp_seq_run(mod, 5, 4, &x, &why) == 0 && regs[2] == 0xf5, "REG_MODIFY (old & ~mask) | val"); |
| 37 | regs[3] = 0; |
| 38 | /* poll sees the value the write in the same buffer stored */ |
| 39 | uint32_t both[] = { GSP_SEQ_REG_WRITE, 3, 7, GSP_SEQ_REG_POLL, 3, 0xff, 7, 10, 1, 0 }; |
| 40 | CHECK(gsp_seq_run(both, 10, 9, &x, &why) == 0, "poll after write settles"); |
| 41 | regs[3] = 0; |
| 42 | uint32_t stuck[] = { GSP_SEQ_REG_POLL, 3, 1, 1, 10, 42, 0 }; |
| 43 | CHECK(gsp_seq_run(stuck, 7, 6, &x, &why) != 0, "poll that never settles refuses"); |
| 44 | uint32_t dly[] = { GSP_SEQ_DELAY_US, 25, 0 }; |
| 45 | delays = 0; |
| 46 | CHECK(gsp_seq_run(dly, 3, 2, &x, &why) == 0 && delays == 25, "DELAY_US is counted, not slept"); |
| 47 | regs[4] = 0x11; |
| 48 | uint32_t st[] = { GSP_SEQ_REG_STORE, 4, 0, 0 }; |
| 49 | CHECK(gsp_seq_run(st, 4, 3, &x, &why) == 0 && x.save[0] == 0x11, "REG_STORE"); |
| 50 | uint32_t st8[] = { GSP_SEQ_REG_STORE, 4, 8, 0 }; |
| 51 | CHECK(gsp_seq_run(st8, 4, 3, &x, &why) != 0, "save index 8 refuses"); |
| 52 | uint32_t bad[] = { 99, 0 }; |
| 53 | CHECK(gsp_seq_run(bad, 2, 1, &x, &why) != 0, "unknown opcode refuses"); |
| 54 | uint32_t cut[] = { GSP_SEQ_REG_WRITE, 1, 0 }; |
| 55 | CHECK(gsp_seq_run(cut, 4, 2, &x, &why) != 0, "short payload refuses"); |
| 56 | x.core = 0; |
| 57 | uint32_t resume[] = { GSP_SEQ_CORE_RESUME, 0 }; |
| 58 | CHECK(gsp_seq_run(resume, 2, 1, &x, &why) != 0, "CORE_RESUME with no callback refuses"); |
| 59 | x.core = core; |
| 60 | core_ops = 0; |
| 61 | CHECK(gsp_seq_run(resume, 2, 1, &x, &why) == 0 && core_ops == 1, "CORE_RESUME calls the callback once"); |
| 62 | CHECK(gsp_seq_run(0, 1, 0, &x, &why) != 0, "null buffer refuses"); |
| 63 | if (fails) { printf("GSP_SEQ_FAIL checks=%d failed=%d\n", checks, fails); return 1; } |
| 64 | printf("GSP_SEQ_PASS checks=%d\n", checks); |
| 65 | return 0; |
| 66 | } |