summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author angelosa <lordkale4@gmail.com>2021-02-15 00:10:31 +0100
committer angelosa <lordkale4@gmail.com>2021-02-15 00:10:31 +0100
commite9906b995b34d5d30d98f4dadd8edb093e762d05 (patch)
tree3b033c2ad94568981cae1927d7ebf0be37fe05eb
parentb8d21c8ea30d410d1a8c4796298c306837c6f55e (diff)
tool_tester: add optional arguments (single shot, verbose log output, work directory)
-rw-r--r--regtests/tool_tester/test_tools.py63
-rw-r--r--regtests/tool_tester/tool_tester/__init__.py9
-rw-r--r--regtests/tool_tester/tool_tester/_selfexe.py12
-rw-r--r--regtests/tool_tester/tool_tester/pngcmp.py5
-rw-r--r--regtests/tool_tester/tool_tester/romcmp.py23
-rw-r--r--regtests/tool_tester/tool_tester/unidasm.py5
-rw-r--r--src/mame/etc/gen_device_defs.py6
7 files changed, 96 insertions, 27 deletions
diff --git a/regtests/tool_tester/test_tools.py b/regtests/tool_tester/test_tools.py
index 5ae0a1c1659..47c2caa4126 100644
--- a/regtests/tool_tester/test_tools.py
+++ b/regtests/tool_tester/test_tools.py
@@ -4,31 +4,66 @@
## copyright-holders:Angelo Salese
##
import sys
+import os
from os.path import join, dirname, realpath
+import argparse
import logging
-from tool_tester.pngcmp import PngCmpTests
-from tool_tester.romcmp import RomCmpTests
-from tool_tester.unidasm import UnidasmTests
+from tool_tester import (
+ ORCHESTRATOR_POOL
+)
+
+def get_args():
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "-v",
+ "--verbose",
+ dest="verbose",
+ action="store_true",
+ help="Enable debug logging messages if enabled"
+ )
+ parser.add_argument(
+ "-work_dir",
+ dest="work_dir",
+ type=str,
+ default=os.getcwd(),
+ help="Work directory where tools lies"
+ )
+ parser.add_argument(
+ "-id",
+ dest="test_id",
+ type=str,
+ default=None,
+ help="If non-default run this test suite only, supported values: {0}".format(
+ repr([item.identifier for item in ORCHESTRATOR_POOL])
+ )
+ )
+ return parser.parse_args()
if __name__ == "__main__":
+ args = get_args()
+
# TODO: proper requirements.txt / setup.py or virtual env management
# dataclasses aren't supported in anything prior to 3.7 (dacite lib 3.6)
assert sys.version_info >= (3, 7), f"python version {sys.version_info.major}.{sys.version_info.minor} < 3.7"
+ log_level = logging.DEBUG if args.verbose else logging.INFO
# TODO: add colorized messages
- # TODO: argparse the logging level
- logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
+ # consider either using colorlog or make one that has support for all terminal flavours
+ logging.basicConfig(format='%(levelname)s: %(message)s', level=log_level)
- # TODO: for now I'll just use class handlers here to chain test sources
- # In an ideal world you want to collect items thru inspect module instead
- # https://docs.python.org/3/library/inspect.html
- # and isolate by handler name, so that an optional arg can be passed here and launch
- # a given test module on user demand
- chained_results = []
- # TODO: point to $(regtests)\assets, configure if necessary
+ # TODO: currently points to $(regtests)/assets, make it a configurable option?
assets_folder = join(dirname(dirname(realpath(__file__))), "assets")
- for test_cls in [PngCmpTests, RomCmpTests, UnidasmTests]:
- test_fn = test_cls(assets_folder)
+
+ chained_results = []
+ __single_test = args.test_id
+ if __single_test is None:
+ __EXECUTE_TESTS = ORCHESTRATOR_POOL
+ else:
+ __EXECUTE_TESTS = [item for item in ORCHESTRATOR_POOL if item.identifier == args.test_id]
+ assert __EXECUTE_TESTS, f"{args.test_id} not found in available tests"
+
+ for test_cls in __EXECUTE_TESTS:
+ test_fn = test_cls(args.work_dir, assets_folder)
logging.info("Start test suite: %s", test_fn.identifier)
chained_results.append(test_fn.execute_tests(test_fn.compose_tests()))
logging.debug("test results %s", repr(chained_results))
diff --git a/regtests/tool_tester/tool_tester/__init__.py b/regtests/tool_tester/tool_tester/__init__.py
index e69de29bb2d..edad4a282e8 100644
--- a/regtests/tool_tester/tool_tester/__init__.py
+++ b/regtests/tool_tester/tool_tester/__init__.py
@@ -0,0 +1,9 @@
+from tool_tester.pngcmp import PngCmpTests
+from tool_tester.romcmp import RomCmpTests
+from tool_tester.unidasm import UnidasmTests
+
+# TODO: for now I'll just use class handlers here to chain test sources
+# In an ideal world you eventually want to collect these items thru inspect module instead,
+# especially if this pool starts to get too big to mantain.
+# https://docs.python.org/3/library/inspect.html
+ORCHESTRATOR_POOL = [PngCmpTests, RomCmpTests, UnidasmTests]
diff --git a/regtests/tool_tester/tool_tester/_selfexe.py b/regtests/tool_tester/tool_tester/_selfexe.py
index 28f9c660616..7a42ecaa3d5 100644
--- a/regtests/tool_tester/tool_tester/_selfexe.py
+++ b/regtests/tool_tester/tool_tester/_selfexe.py
@@ -9,11 +9,13 @@ import subprocess
from typing import Dict, List
class SelfExeTests(ABC):
- def __init__(self, id_exe: str, assets_folder: str):
- self.identifier = id_exe
- self._exec_path = os.path.join(os.getcwd(), "{0}{1}".format(id_exe, ".exe" if os.name == 'nt' else ""))
- self._assets_path = assets_folder
- logging.debug("Setup %s executable exe at %s", id_exe, self._exec_path)
+ identifier: str
+
+ def __init__(self, work_path: str, assets_path: str):
+ __id_exe = self.identifier
+ self._exec_path = os.path.join(work_path, "{0}{1}".format(__id_exe, ".exe" if os.name == 'nt' else ""))
+ self._assets_path = assets_path
+ logging.debug("Setup %s executable exe at %s", __id_exe, self._exec_path)
def compose_tests(self) -> Dict:
"""Compose a list of tests to be later reused.
diff --git a/regtests/tool_tester/tool_tester/pngcmp.py b/regtests/tool_tester/tool_tester/pngcmp.py
index 0457584c7f6..21719e5f8af 100644
--- a/regtests/tool_tester/tool_tester/pngcmp.py
+++ b/regtests/tool_tester/tool_tester/pngcmp.py
@@ -22,9 +22,10 @@ class PngCmpTests(SelfExeTests):
Args:
SelfExeTests ([type]): [description]
"""
+ identifier = "pngcmp"
- def __init__(self, assets_path: str):
- super().__init__("pngcmp", assets_path)
+ def __init__(self, work_path: str, assets_path: str):
+ super().__init__(work_path, assets_path)
self._png_test_folder = os.path.join(assets_path, "png")
def _collect_tests(self):
diff --git a/regtests/tool_tester/tool_tester/romcmp.py b/regtests/tool_tester/tool_tester/romcmp.py
index 97971b69d30..326633e53be 100644
--- a/regtests/tool_tester/tool_tester/romcmp.py
+++ b/regtests/tool_tester/tool_tester/romcmp.py
@@ -1,19 +1,36 @@
+##
+## license:BSD-3-Clause
+## copyright-holders:Angelo Salese
+##
+
import os
from subprocess import CompletedProcess
from dataclasses import dataclass
import logging
from tool_tester._selfexe import SelfExeTests
-import difflib
+#import difflib
class RomCmpTests(SelfExeTests):
- def __init__(self, assets_path: str):
- super().__init__("romcmp", assets_path)
+ """Test out romcmp usage.
+
+ Simple tests, just verify output from a dummy binary format.
+
+ Args:
+ SelfExeTests ([type]): [description]
+ """
+ identifier = "romcmp"
+
+ def __init__(self, work_path: str, assets_path: str):
+ super().__init__(work_path, assets_path)
self._logs_folder = os.path.join(assets_path, self.identifier)
self._bin_test_folder = os.path.join(assets_path, self.identifier, "bin")
logging.debug(self._bin_test_folder)
def _collect_tests(self):
return {
+ # FIXME: on at least Windows this causes readback at root drive
+ # is it subprocess or romcmp fault?
+# "normal": ["", self._bin_test_folder],
"normal": [self._bin_test_folder],
"slower": ["-d", self._bin_test_folder],
"hash": ["-h", self._bin_test_folder]
diff --git a/regtests/tool_tester/tool_tester/unidasm.py b/regtests/tool_tester/tool_tester/unidasm.py
index 432e8880f1f..c91f39f195e 100644
--- a/regtests/tool_tester/tool_tester/unidasm.py
+++ b/regtests/tool_tester/tool_tester/unidasm.py
@@ -38,9 +38,10 @@ class UnidasmTests(SelfExeTests):
Args:
SelfExeTests ([type]): [description]
"""
+ identifier = "unidasm"
- def __init__(self, assets_path: str):
- super().__init__("unidasm", assets_path)
+ def __init__(self, work_path: str, assets_path: str):
+ super().__init__(work_path, assets_path)
self._asm_test_folder = os.path.join(assets_path, self.identifier, "asm")
self._bin_test_folder = os.path.join(assets_path, self.identifier, "bin")
logging.debug(self._asm_test_folder)
diff --git a/src/mame/etc/gen_device_defs.py b/src/mame/etc/gen_device_defs.py
index 1e98ce1d15a..f6e33c4d093 100644
--- a/src/mame/etc/gen_device_defs.py
+++ b/src/mame/etc/gen_device_defs.py
@@ -1,4 +1,8 @@
-# license: BSD-3-Clause
+#!/usr/bin/python
+##
+## license: BSD-3-Clause
+## copyright-holders:Angelo Salese
+##
"""Simple Python script to generate a new definition from the template_* files
"""
import argparse