diff options
| author | Paul Oliver <contact@pauloliver.dev> | 2026-06-25 04:42:23 +0200 |
|---|---|---|
| committer | Paul Oliver <contact@pauloliver.dev> | 2026-06-28 02:50:18 +0200 |
| commit | 95fd6ae836ab5fee7387f4df46b727165a05b723 (patch) | |
| tree | 79c715d250f44c1aa1a0d05e65be313ae4cd3e15 /test/ui/v1/3rops | |
| parent | 0f5581f53f73a92d33826c4771553a9683376e67 (diff) | |
Adds v1 unit tests and fixes bugs found by them
Diffstat (limited to 'test/ui/v1/3rops')
| -rw-r--r-- | test/ui/v1/3rops/ui.c | 60 | ||||
| -rw-r--r-- | test/ui/v1/3rops/vars.py | 3 |
2 files changed, 63 insertions, 0 deletions
diff --git a/test/ui/v1/3rops/ui.c b/test/ui/v1/3rops/ui.c new file mode 100644 index 0000000..e4e2d83 --- /dev/null +++ b/test/ui/v1/3rops/ui.c @@ -0,0 +1,60 @@ +#if !defined(COMMAND_NEW) +#error +#endif + +int main(void) { + salis_init(); + + while (mvec_is_proc_owner(g_cores, g_cores->pvec->ip, g_cores->pcur)) { + uint8_t inst = mvec_get_inst(g_cores, g_cores->pvec->ip); + + if (inst != addn && inst != subn && inst != muln && inst != divn) { + salis_step(1); + continue; + } + + uint64_t *regs[3] = { + &g_cores->pvec->r0x, + &g_cores->pvec->r0x, + &g_cores->pvec->r0x, + }; + + for (uint64_t i = 0; i < 3; i++) { + uint8_t rmod = mvec_get_inst(g_cores, g_cores->pvec->ip + 1 + i); + if (rmod == nop0) regs[i] = &g_cores->pvec->r0x; + else if (rmod == nop1) regs[i] = &g_cores->pvec->r1x; + else if (rmod == nop2) regs[i] = &g_cores->pvec->r2x; + else if (rmod == nop3) regs[i] = &g_cores->pvec->r3x; + else break; + } + + uint64_t reg_vals[3] = {*regs[0], *regs[1], *regs[2]}; + salis_step(1); + uint64_t result = *regs[0]; + + switch (inst) { + case addn: + assert(result == reg_vals[1] + reg_vals[2]); + break; + case subn: + assert(result == reg_vals[1] - reg_vals[2]); + break; + case muln: + assert(result == reg_vals[1] * reg_vals[2]); + break; + case divn: + if (reg_vals[2] != 0) { + assert(result == reg_vals[1] / reg_vals[2]); + } else { + assert(*regs[0] == reg_vals[0]); + assert(*regs[1] == reg_vals[1]); + assert(*regs[2] == reg_vals[2]); + } + + break; + } + } + + salis_free(); + return 0; +} diff --git a/test/ui/v1/3rops/vars.py b/test/ui/v1/3rops/vars.py new file mode 100644 index 0000000..9c2a9f3 --- /dev/null +++ b/test/ui/v1/3rops/vars.py @@ -0,0 +1,3 @@ +flags = set() +defines = set() +links = set() |
