diff options
| author | Paul Oliver <contact@pauloliver.dev> | 2026-06-18 00:08:54 +0200 |
|---|---|---|
| committer | Paul Oliver <contact@pauloliver.dev> | 2026-06-25 00:15:17 +0200 |
| commit | 0f5581f53f73a92d33826c4771553a9683376e67 (patch) | |
| tree | eab8172d21dc4a0b36714af541d22a82cec858f3 /test | |
| parent | 00a0cb3821ce2bd0fc589ae64ed9cbb791ce44bb (diff) | |
Adds unit testing scaffold and build tests
Diffstat (limited to 'test')
| -rw-r--r-- | test/anc/v1/noops.asm | 38 | ||||
| -rw-r--r-- | test/test_build.py | 80 | ||||
| -rw-r--r-- | test/test_general.py | 31 | ||||
| -rw-r--r-- | test/test_v1.py | 6 | ||||
| -rw-r--r-- | test/ui/null/ui.c | 10 | ||||
| -rw-r--r-- | test/ui/null/vars.py | 3 | ||||
| -rw-r--r-- | test/ui/v1/noops/ui.c | 114 | ||||
| -rw-r--r-- | test/ui/v1/noops/vars.py | 3 |
8 files changed, 285 insertions, 0 deletions
diff --git a/test/anc/v1/noops.asm b/test/anc/v1/noops.asm new file mode 100644 index 0000000..77862c4 --- /dev/null +++ b/test/anc/v1/noops.asm @@ -0,0 +1,38 @@ +noop +nop0 +nop1 +nop2 +nop3 + +keya +keyb +keyc +keyd +keye +keyf +keyg +keyh +keyi +keyj +keyk +keyl +keym +keyn +keyo +keyp +loka +lokb +lokc +lokd +loke +lokf +lokg +lokh +loki +lokj +lokk +lokl +lokm +lokn +loko +lokp diff --git a/test/test_build.py b/test/test_build.py new file mode 100644 index 0000000..e0fecef --- /dev/null +++ b/test/test_build.py @@ -0,0 +1,80 @@ +import signal + +from test_general import SalisTest + +class TestBuild(SalisTest): + def cmds_new(self, anc, arch): + return ( + f"./salis.py new -a{anc} -b -f -g{compiler} -H{self.tempdir.name} {optimized} -s{seed} -u{ui} -v{arch}" + for compiler in ["clang", "gcc"] + for optimized in ["", "-o"] + for seed in [-1, 0, 1234] + for ui in ["curses", "daemon"] + ) + + def cmds_new_dummy(self): + return self.cmds_new("0123", "dummy") + + def cmds_new_v1(self): + return self.cmds_new("55a", "v1") + + def cmds_load(self): + return ( + f"./salis.py load -b -g{compiler} -H{self.tempdir.name} {optimized} -u{ui}" + for compiler in ["clang", "gcc"] + for optimized in ["", "-o"] + for ui in ["curses", "daemon"] + ) + + def cmds_server(self): + return ( + f"./salis.py server -b -g{compiler} -H{self.tempdir.name} {optimized}" + for compiler in ["clang", "gcc"] + for optimized in ["", "-o"] + ) + + def cmds_client(self): + return ( + f"./salis.py client -b -g{c_compiler} {optimized} -x{cxx_compiler}" + for c_compiler in ["clang", "gcc"] + for cxx_compiler in ["clang", "gcc"] + for optimized in ["", "-o"] + ) + + def test_dummy_new(self): + for cmd in self.cmds_new_dummy(): + SalisTest.run_subprocess(cmd) + + def test_v1_new(self): + for cmd in self.cmds_new_v1(): + SalisTest.run_subprocess(cmd) + + def test_dummy_load(self): + SalisTest.run_subprocess(next(self.cmds_new_dummy())) + + for cmd in self.cmds_load(): + SalisTest.run_subprocess(cmd) + + def test_v1_load(self): + SalisTest.run_subprocess(next(self.cmds_new_v1())) + + for cmd in self.cmds_load(): + SalisTest.run_subprocess(cmd) + + def test_server(self): + SalisTest.run_subprocess(next(self.cmds_new_dummy())) + + for cmd in self.cmds_server(): + SalisTest.run_subprocess(cmd) + + @SalisTest.run_ui_test(anc="0123", anc_path="anc", name="def.sim", ui="null", ui_path="test/ui", vm_arch="dummy") + def test_client(self): + with SalisTest.run_pipe(f"./salis.py server -H{self.tempdir.name}") as server_proc: + for line in server_proc.stdout: + if "Listening..." in line: + break + + for cmd in self.cmds_client(): + SalisTest.run_subprocess(cmd) + + server_proc.send_signal(signal.SIGINT) diff --git a/test/test_general.py b/test/test_general.py new file mode 100644 index 0000000..eb3185d --- /dev/null +++ b/test/test_general.py @@ -0,0 +1,31 @@ +import subprocess +import unittest + +from tempfile import TemporaryDirectory + +class SalisTest(unittest.TestCase): + def setUp(self): + self.tempdir = TemporaryDirectory(prefix="salis_test_") + + def tearDown(self): + self.tempdir.cleanup() + + @staticmethod + def run_subprocess(cmd): + subprocess.run(cmd.split(), check=True, stdout=subprocess.DEVNULL) + + @staticmethod + def run_pipe(cmd): + return subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, text=True) + + @staticmethod + def run_ui_test(anc, anc_path, ui, ui_path, vm_arch, clones=1, cores=1, name="def.sim"): + def test_decorator(test_case): + def test_wrapper(self): + cmd = f"./salis.py new -a{anc} -A{anc_path} -C{clones} -c{cores} -H{self.tempdir.name} -n{name} -u{ui} -U{ui_path} -v{vm_arch}" + subprocess.run(cmd.split(), check=True, stdout=subprocess.DEVNULL) + test_case(self) + + return test_wrapper + + return test_decorator diff --git a/test/test_v1.py b/test/test_v1.py new file mode 100644 index 0000000..466e4bd --- /dev/null +++ b/test/test_v1.py @@ -0,0 +1,6 @@ +from test_general import SalisTest + +class TestV1(SalisTest): + @SalisTest.run_ui_test(anc="noops", anc_path="test/anc", ui="noops", ui_path="test/ui/v1", vm_arch="v1") + def test_ui_v1_noops(self): + pass diff --git a/test/ui/null/ui.c b/test/ui/null/ui.c new file mode 100644 index 0000000..5872342 --- /dev/null +++ b/test/ui/null/ui.c @@ -0,0 +1,10 @@ +int main(void) { +#if defined(COMMAND_NEW) + salis_init(); +#elif defined(COMMAND_LOAD) + salis_load(); +#endif + salis_save(SIM_PATH); + salis_free(); + return 0; +} diff --git a/test/ui/null/vars.py b/test/ui/null/vars.py new file mode 100644 index 0000000..9c2a9f3 --- /dev/null +++ b/test/ui/null/vars.py @@ -0,0 +1,3 @@ +flags = set() +defines = set() +links = set() diff --git a/test/ui/v1/noops/ui.c b/test/ui/v1/noops/ui.c new file mode 100644 index 0000000..230e98d --- /dev/null +++ b/test/ui/v1/noops/ui.c @@ -0,0 +1,114 @@ +#if !defined(COMMAND_NEW) +#error +#endif + +void check_invariants(void) { + assert(g_cores->mall == ANC_SIZE); + assert(g_cores->muta[0] == 0); + assert(g_cores->muta[1] == 0); + assert(g_cores->muta[2] == 0); + assert(g_cores->muta[3] == 0); + + assert(g_cores->pnum == 1); + assert(g_cores->pcap == 1); + assert(g_cores->pfst == 0); + assert(g_cores->plst == 0); + assert(g_cores->pcur == 0); + assert(g_cores->psli == 0); + + for (uint64_t i = 0; i < SYNC_INTERVAL; i++) { + assert(g_cores->ivav[i] == 0); + assert(g_cores->iviv[i] == 0); + } + + assert(g_cores->emb1 == 0); + assert(g_cores->eliv == 0); + assert(g_cores->edea == 0); + + for (uint64_t i = 0; i < MVEC_SIZE; i++) { + assert(g_cores->aeva[i] == 0); + assert(g_cores->beva[i] == 0); + } + + for (uint64_t i = 0; i < INST_COUNT; i++) { + assert(g_cores->ipop[i] == 0); + assert(g_cores->iwrt[i] == 0); + } + + assert(g_cores->wmb0 == 0); + assert(g_cores->wmb1 == 0); + assert(g_cores->wdea == 0); + + for (uint64_t i = 0; i < MVEC_SIZE; i++) { + assert(g_cores->weva[i] == 0); + assert(g_cores->xeva[i] == 0); + } + + assert(g_cores->pvec->mb0a == 0); + assert(g_cores->pvec->mb0s == ANC_SIZE); + assert(g_cores->pvec->mb1a == 0); + assert(g_cores->pvec->mb1s == 0); + assert(g_cores->pvec->r0x == 0); + assert(g_cores->pvec->r1x == 0); + assert(g_cores->pvec->r2x == 0); + assert(g_cores->pvec->r3x == 0); + assert(g_cores->pvec->s0 == 0); + assert(g_cores->pvec->s1 == 0); + assert(g_cores->pvec->s2 == 0); + assert(g_cores->pvec->s3 == 0); + assert(g_cores->pvec->s4 == 0); + assert(g_cores->pvec->s5 == 0); + assert(g_cores->pvec->s6 == 0); + assert(g_cores->pvec->s7 == 0); +} + +void check_variants(uint64_t step) { + assert(g_cores->cycl == step); + assert(g_cores->ivpt == step); + + assert(g_cores->emb0 == step); + + for (uint64_t i = 0; i < MVEC_SIZE; i++) { + assert(g_cores->eeva[i] == (i < step ? 1 : 0)); + } + + for (uint64_t i = 0; i < INST_COUNT; i++) { + uint64_t exed = 0; + + for (uint64_t j = 0; j < step; j++) { + if (mvec_get_inst(g_cores, j) == i) { + exed = 1; + } + } + + assert(g_cores->iexe[i] == exed); + } + + assert(g_cores->pvec->ip == step); + assert(g_cores->pvec->sp == step); +} + +void check_final(void) { + assert(g_cores->pvec->ip == ANC_SIZE); + assert(g_cores->pvec->sp == ANC_SIZE); +} + +int main(void) { + uint64_t step = 0; + + salis_init(); + check_invariants(); + check_variants(step); + + while (mvec_is_proc_owner(g_cores, g_cores->pvec->ip, g_cores->pcur)) { + salis_step(1); + step++; + + check_invariants(); + check_variants(step); + } + + check_final(); + salis_free(); + return 0; +} diff --git a/test/ui/v1/noops/vars.py b/test/ui/v1/noops/vars.py new file mode 100644 index 0000000..9c2a9f3 --- /dev/null +++ b/test/ui/v1/noops/vars.py @@ -0,0 +1,3 @@ +flags = set() +defines = set() +links = set() |
