summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author angelosa <lordkale4@gmail.com>2021-01-29 03:22:46 +0100
committer angelosa <lordkale4@gmail.com>2021-01-29 03:22:46 +0100
commit560db771d58aa8bfc45f0483c083cb3f9c1673b4 (patch)
treea184346c61802b99b054306ea0f8d809765eb683
parent75e81ecb1f540b0734bdcbf3a554e9ec3bb571ef (diff)
regtests: disable faulty tests, make a preliminary new test suite for unidasm
-rw-r--r--regtests/regtests.mak13
-rw-r--r--regtests/unidasm/static/h6280.asm6
-rw-r--r--regtests/unidasm/static/h6280.binbin0 -> 10 bytes
-rw-r--r--regtests/unidasm/static/m6502.asm5
-rw-r--r--regtests/unidasm/static/m6502.binbin0 -> 8 bytes
-rw-r--r--regtests/unidasm/static/z80.asm4
-rw-r--r--regtests/unidasm/static/z80.binbin0 -> 9 bytes
-rw-r--r--regtests/unidasm/unidasm.py89
8 files changed, 113 insertions, 4 deletions
diff --git a/regtests/regtests.mak b/regtests/regtests.mak
index bb3d8c9b83b..6c76357fadb 100644
--- a/regtests/regtests.mak
+++ b/regtests/regtests.mak
@@ -43,9 +43,9 @@
#-------------------------------------------------
REGTESTS += \
- chdmantest \
- jedutiltest \
-
+ unidasmtest \
+# chdmantest \
+# jedutiltest \
#-------------------------------------------------
# chdman
@@ -64,5 +64,10 @@ jedutiltest:
@echo Running jedutil unittest
$(PYTHON) regtests/jedutil/jedtest.py
+#-------------------------------------------------
+# unidasm
+#-------------------------------------------------
-
+unidasmtest:
+ @echo Running unidasm unittest
+ $(PYTHON) regtests/unidasm/unidasm.py
diff --git a/regtests/unidasm/static/h6280.asm b/regtests/unidasm/static/h6280.asm
new file mode 100644
index 00000000000..73c34eff41a
--- /dev/null
+++ b/regtests/unidasm/static/h6280.asm
@@ -0,0 +1,6 @@
+0: 78 sei
+1: d4 csh
+2: d8 cld
+3: a9 ff lda #$FF
+5: 53 ff tam #$FF
+7: 4c 00 e0 jmp $E000
diff --git a/regtests/unidasm/static/h6280.bin b/regtests/unidasm/static/h6280.bin
new file mode 100644
index 00000000000..781727f523f
--- /dev/null
+++ b/regtests/unidasm/static/h6280.bin
Binary files differ
diff --git a/regtests/unidasm/static/m6502.asm b/regtests/unidasm/static/m6502.asm
new file mode 100644
index 00000000000..d578baa7df1
--- /dev/null
+++ b/regtests/unidasm/static/m6502.asm
@@ -0,0 +1,5 @@
+0: 78 sei
+1: d8 cld
+2: a2 ff ldx #$ff
+4: 9a txs
+5: 4c 00 e0 jmp $e000
diff --git a/regtests/unidasm/static/m6502.bin b/regtests/unidasm/static/m6502.bin
new file mode 100644
index 00000000000..853a3d957d3
--- /dev/null
+++ b/regtests/unidasm/static/m6502.bin
Binary files differ
diff --git a/regtests/unidasm/static/z80.asm b/regtests/unidasm/static/z80.asm
new file mode 100644
index 00000000000..e57d2dedf37
--- /dev/null
+++ b/regtests/unidasm/static/z80.asm
@@ -0,0 +1,4 @@
+0: f3 di
+1: ed 56 im 1
+3: 31 00 00 ld sp,$0000
+6: c3 00 00 jp $0000
diff --git a/regtests/unidasm/static/z80.bin b/regtests/unidasm/static/z80.bin
new file mode 100644
index 00000000000..824587e3465
--- /dev/null
+++ b/regtests/unidasm/static/z80.bin
Binary files differ
diff --git a/regtests/unidasm/unidasm.py b/regtests/unidasm/unidasm.py
new file mode 100644
index 00000000000..7e9cbc58a76
--- /dev/null
+++ b/regtests/unidasm/unidasm.py
@@ -0,0 +1,89 @@
+#!/usr/bin/python
+##
+## license:BSD-3-Clause
+## copyright-holders:Angelo Salese
+##
+import os
+import sys
+import logging
+import subprocess
+from typing import Callable
+
+def __assert_valid_filename(filehandle: str, target_arch: str, expected_extension: str):
+ """Checkout if derived file handle input is the expected one
+
+ Args:
+ filehandle (str): file handle
+ target_arch (str): the expected architecture base name
+ expected_extension (str): the expected extension that the file handle should have
+ """
+
+ assert filehandle.startswith(target_arch), f"{filehandle} {expected_extension} mismatch with arch {target_arch}"
+ assert filehandle.endswith(expected_extension), f"{filehandle} mismatch {expected_extension}"
+
+def run_process():
+ """Process our static directory, derive and execute tests
+
+ For unidasm the strategy is to point at the static folder and
+ derive unit tests based off what's in static directory itself.
+ To compose a new test for a given arch:
+
+ 1. craft a new binary file and save it in static subfolder, name it <test_arch>.bin,
+ where <test_arch> is the name as it is displayed by running unidasm.exe
+ with no additional params. Keep it simple & short, more sofisticated programs aren't really
+ the scope of this (we're just testing if the arch disassembles here).
+ 2. run unidasm $(thisfolder)/static/<test_arch>.bin -arch <test_arch> > $(thisfolder)/static/<test_arch>.asm
+ On windows the resulting asm file newlines must be converted to LF with this.
+ 3. now run make tests and check if the new test gets captured.
+
+ """
+ unidasm_exe = os.path.join(os.getcwd(), "unidasm{0}".format(".exe" if os.name == 'nt' else ""))
+ static_tests_folder = os.path.join(os.path.dirname(os.path.realpath(__file__)), "static")
+ static_tests = os.listdir(static_tests_folder)
+
+ test_pool = {
+ asm_filename.split(".")[0]: [asm_filename, bin_filename] for asm_filename, bin_filename in zip(static_tests[0::2], static_tests[1::2])
+ }
+
+ logging.info("Detected %s tests", len(test_pool))
+
+ for target_arch, params in test_pool.items():
+ assert len(params) == 2, f"{target_arch} Unexpected input test structure {params}"
+ asm_filename, bin_filename = params
+ __assert_valid_filename(asm_filename, target_arch, ".asm")
+ __assert_valid_filename(bin_filename, target_arch, ".bin")
+
+ logging.debug("Test arch %s passed internal validation, launching unidasm", target_arch)
+
+ with open(os.path.join(static_tests_folder, asm_filename), "r", encoding="utf-8", newline="\n") as txt_h:
+ expected_asm = txt_h.read()
+
+ # TODO: checkout how unidasm copes with endianness on 16/32-bit based CPUs
+ launch_process = subprocess.run(
+ [unidasm_exe] + [os.path.join(static_tests_folder, bin_filename), "-arch", target_arch],
+ encoding="utf-8",
+ capture_output=True,
+ check=True,
+ text=True,
+ shell=False
+ )
+ assert launch_process.returncode == 0, f"{target_arch} return code == {launch_process.returncode}"
+ # TODO: eventually use difflib
+ assert launch_process.stdout == expected_asm, "{1} expected:{0}{2}{0}actual:{0}{3}".format(
+ os.linesep,
+ target_arch,
+ repr(expected_asm),
+ repr(launch_process.stdout)
+ )
+ logging.info("Target arch test %s passed", target_arch)
+
+if __name__ == "__main__":
+ logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
+ try:
+ run_process()
+ except (subprocess.CalledProcessError, AssertionError) as ex:
+ logging.error(str(ex))
+ sys.exit(1)
+ raise
+ logging.info("unidasm test successful")
+ sys.exit(0)