From 8a4563d6d0c9e81fdaa42f6f760cae2b49cad431 Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Fri, 31 Jul 2026 00:06:20 +0200 Subject: Adds unit test framework --- test/test_build.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ test/test_general.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++ test/test_run.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ test/ui/push/links.json | 1 + test/ui/push/ui.c | 25 ++++++++++++++++++++++ 5 files changed, 191 insertions(+) create mode 100644 test/test_build.py create mode 100644 test/test_general.py create mode 100644 test/test_run.py create mode 100644 test/ui/push/links.json create mode 100644 test/ui/push/ui.c (limited to 'test') diff --git a/test/test_build.py b/test/test_build.py new file mode 100644 index 0000000..7c0126a --- /dev/null +++ b/test/test_build.py @@ -0,0 +1,56 @@ +# file : test/test_build.py +# project : Salis-VM +# author : Paul Oliver + +# index: +# [section] imports +# [section] constants +# [section] command lists +# [section] tests null + +# ------------------------------------------------------------------------------ +# [section] imports +# ------------------------------------------------------------------------------ +from test_general import SalisTest + +class TestBuild(SalisTest): + # -------------------------------------------------------------------------- + # [section] constants + # -------------------------------------------------------------------------- + SIM_NAME = "test-build.sim" + + # -------------------------------------------------------------------------- + # [section] command lists + # -------------------------------------------------------------------------- + def commands_new(self, anc, arch): + return [ + f"./salis.py new -a{anc} -b -f -g{compiler} -H{self.tempdir.name} -n{self.SIM_NAME} {optimized} -s{seed} -u{ui} -v{arch}" + for compiler in ["clang", "gcc", "tcc"] + for optimized in ["", "-o"] + for seed in [-1, 0, 1234] + for ui in ["daemon"] + ] + + def commands_load(self): + return [ + f"./salis.py load -b -g{compiler} -H{self.tempdir.name} -n{self.SIM_NAME} {optimized} -u{ui}" + for compiler in ["clang", "gcc", "tcc"] + for optimized in ["", "-o"] + for ui in ["daemon"] + ] + + # -------------------------------------------------------------------------- + # [section] tests null + # -------------------------------------------------------------------------- + def test_null_new(self): + for command in self.commands_new("0123", "null"): + self.run_subprocess(command) + self.assert_files_exist([f"{self.tempdir.name}/{self.SIM_NAME}/opts.json"]) + + def test_null_load(self): + self.run_subprocess(self.commands_new("0123", "null")[0]) + self.assert_files_exist([f"{self.tempdir.name}/{self.SIM_NAME}/opts.json"]) + + for command in self.commands_load(): + self.run_subprocess(command) + self.assert_files_exist([f"{self.tempdir.name}/{self.SIM_NAME}/opts.json"]) diff --git a/test/test_general.py b/test/test_general.py new file mode 100644 index 0000000..b4e0e85 --- /dev/null +++ b/test/test_general.py @@ -0,0 +1,54 @@ +# file : test/test_general.py +# project : Salis-VM +# author : Paul Oliver + +# index: +# [section] imports +# [section] setup/teardown +# [section] file lists +# [section] assertions +# [section] subprocess + +# ------------------------------------------------------------------------------ +# [section] imports +# ------------------------------------------------------------------------------ +import os +import subprocess +import unittest + +from tempfile import TemporaryDirectory + +class SalisTest(unittest.TestCase): + # -------------------------------------------------------------------------- + # [section] setup/teardown + # -------------------------------------------------------------------------- + def setUp(self): + self.tempdir = TemporaryDirectory(prefix="salis_test_") + + def tearDown(self): + self.tempdir.cleanup() + + # -------------------------------------------------------------------------- + # [section] file lists + # -------------------------------------------------------------------------- + def files_on_new(self, name): + return [ + f"{self.tempdir.name}/{name}/evas/evas-{0:016x}", + f"{self.tempdir.name}/{name}/opts.json", + f"{self.tempdir.name}/{name}/{name}", + f"{self.tempdir.name}/{name}/{name}-{0:016x}", + f"{self.tempdir.name}/{name}/{name}.sqlite3", + ] + + # -------------------------------------------------------------------------- + # [section] assertions + # -------------------------------------------------------------------------- + def assert_files_exist(self, files): + for file in files: + assert os.path.isfile(file), f"{file} does not exist" + + # -------------------------------------------------------------------------- + # [section] subprocess + # -------------------------------------------------------------------------- + def run_subprocess(self, command): + subprocess.run(command.split(), check=True, stdout=subprocess.DEVNULL) diff --git a/test/test_run.py b/test/test_run.py new file mode 100644 index 0000000..cab195c --- /dev/null +++ b/test/test_run.py @@ -0,0 +1,55 @@ +# file : test/test_run.py +# project : Salis-VM +# author : Paul Oliver + +# index: +# [section] imports +# [section] constants +# [section] command lists +# [section] file lists +# [section] tests null + +# ------------------------------------------------------------------------------ +# [section] imports +# ------------------------------------------------------------------------------ +from test_general import SalisTest + +class TestRun(SalisTest): + # -------------------------------------------------------------------------- + # [section] constants + # -------------------------------------------------------------------------- + SIM_NAME = "test-run.sim" + PUSH_POW = 8 + + # -------------------------------------------------------------------------- + # [section] command lists + # -------------------------------------------------------------------------- + def commands(self, anc, arch): + return [ + ( + f"./salis.py new -a{anc} -d{self.PUSH_POW} -f -g{compiler} -H{self.tempdir.name} -n{self.SIM_NAME} {optimized} -s{seed} -upush -Utest/ui/ -v{arch} -y{self.PUSH_POW}", + f"./salis.py load -g{compiler} -H{self.tempdir.name} -n{self.SIM_NAME} {optimized} -upush -Utest/ui/", + ) + for compiler in ["clang", "gcc", "tcc"] + for optimized in ["", "-o"] + for seed in [-1, 0, 1234] + ] + + # -------------------------------------------------------------------------- + # [section] file lists + # -------------------------------------------------------------------------- + def files_on_first_push(self): + return [*self.files_on_new(self.SIM_NAME), f"{self.tempdir.name}/{self.SIM_NAME}/evas/evas-{2 ** self.PUSH_POW:016x}"] + + def files_on_second_push(self): + return [*self.files_on_first_push(), f"{self.tempdir.name}/{self.SIM_NAME}/evas/evas-{2 * (2 ** self.PUSH_POW):016x}"] + + # -------------------------------------------------------------------------- + # [section] tests null + # -------------------------------------------------------------------------- + def test_null(self): + for command in self.commands("0123", "null"): + self.run_subprocess(command[0]) + self.assert_files_exist(self.files_on_first_push()) + self.run_subprocess(command[1]) + self.assert_files_exist(self.files_on_second_push()) diff --git a/test/ui/push/links.json b/test/ui/push/links.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/test/ui/push/links.json @@ -0,0 +1 @@ +[] diff --git a/test/ui/push/ui.c b/test/ui/push/ui.c new file mode 100644 index 0000000..53baac9 --- /dev/null +++ b/test/ui/push/ui.c @@ -0,0 +1,25 @@ +// file : test/ui/push/ui.c +// project : Salis-VM +// author : Paul Oliver + +#include +#include +#include +#include + +#include "arch_spec.h" +#include "compress.h" +#include "logger.h" +#include "salis.h" + +int main(void) { +#if defined(COMMAND_NEW) + salis_init(); +#elif defined(COMMAND_LOAD) + salis_load(); +#endif + + salis_step(DATA_PUSH_INTERVAL); + salis_free(); + return 0; +} -- cgit v1.3.1