aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martínez <jjm@usebox.net>2021-10-02 12:33:04 +0000
committerJuan J. Martínez <jjm@usebox.net>2021-10-02 12:33:04 +0000
commitcaa22e5bbd158fd8d563588293aa763ca5801bed (patch)
tree0789e731afeb7844fd68976fc0b1ea53ec4517d7
parentc14900274f20d119c6704f910eec420bf2998866 (diff)
downloadubox-msx-lib-caa22e5bbd158fd8d563588293aa763ca5801bed.tar.gz
ubox-msx-lib-caa22e5bbd158fd8d563588293aa763ca5801bed.zip
Start the test suite
-rw-r--r--.gitignore1
-rw-r--r--.gitlab-ci.yml10
-rw-r--r--Makefile3
-rw-r--r--README.md4
-rw-r--r--tests/Makefile10
-rw-r--r--tests/README.md14
-rwxr-xr-xtests/test_rom.py37
7 files changed, 71 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index 51f70b1..d871fe5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,6 +19,7 @@ src/*/*.asm
*.cas
*.rom
*.lib
+*.pyc
Makefile.deps
bin/
lib/
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 0bf087c..0bd0a44 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,11 +1,5 @@
image: registry.gitlab.com/reidrac/ubox-msx-lib-ci:latest
-stages:
- - build
-
-build-job:
- stage: build
+build-and-test:
script:
- - echo "Compiling the code..."
- - make game
- - echo "Compile complete."
+ - make test
diff --git a/Makefile b/Makefile
index 46de89b..c897c2a 100644
--- a/Makefile
+++ b/Makefile
@@ -8,6 +8,9 @@ game: bin libs
make -C tools
make -C game all
+test: game
+ make -C tests test
+
docs:
make -C docs
diff --git a/README.md b/README.md
index 23c9067..86d7152 100644
--- a/README.md
+++ b/README.md
@@ -56,6 +56,10 @@ Add those directories in `SDCC`'s search path and you are ready to go.
Note: `make` is expected to be run from the root of the repo. The PATH env
variable will be set automatically.
+### Running tests
+
+There are tests that can be run with `make test`.
+
### Building the example
An example game is included with the libraries and it can be built with:
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644
index 0000000..6c1a9a4
--- /dev/null
+++ b/tests/Makefile
@@ -0,0 +1,10 @@
+default:
+ $(error Please use the Makefile from root directory)
+
+TESTS := $(wildcard test_*.py)
+
+test:
+ python3 -m unittest $(TESTS)
+
+.PHONY: test default
+
diff --git a/tests/README.md b/tests/README.md
new file mode 100644
index 0000000..c0139a8
--- /dev/null
+++ b/tests/README.md
@@ -0,0 +1,14 @@
+# ubox MSX lib test suite
+
+The tests are written in python 3 and follow this convention:
+
+| Test class | Filename |
+| --- | --- |
+| TestMyCase | test_my_case.py |
+
+See `test_rom.py` as an example.
+
+Remember to make the test file executable!
+
+**TODO**: add a module to support openMSX remote control.
+
diff --git a/tests/test_rom.py b/tests/test_rom.py
new file mode 100755
index 0000000..7ba6992
--- /dev/null
+++ b/tests/test_rom.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python3
+
+import unittest
+import struct
+
+
+class TestRom(unittest.TestCase):
+ """Test that the generated game ROM is correct."""
+
+ ROM_SIZE = 0x8000
+
+ @classmethod
+ def setUpClass(cls):
+ with open("../bin/game.rom", "rb") as fd:
+ cls.data = fd.read(cls.ROM_SIZE)
+
+ with open("../game/build/game.map", "rb") as fd:
+ game_map = fd.readlines()
+
+ cls.main_init = 0
+ for line in game_map:
+ if b"_main_init" in line:
+ cls.main_init = int(line.split()[0], 16)
+ break
+
+ def test_header_magic(self):
+ self.assertEqual(self.data[:2], b"AB")
+
+ def test_size(self):
+ self.assertEqual(len(self.data), self.ROM_SIZE)
+
+ def test_header_main_init_address(self):
+ self.assertEqual(struct.unpack("H", self.data[2:4]), (self.main_init,))
+
+
+if __name__ == '__main__':
+ unittest.main()