From 5b2ac91b72fe203521641dba7c1d88b1b2738b2f Mon Sep 17 00:00:00 2001 From: Richard Dymond Date: Tue, 5 Sep 2023 17:32:33 -0300 Subject: [PATCH] Enable disassembly tests to run in parallel --- Makefile | 6 +++--- tests/disassemblytest.py | 3 +-- tools/disassembly.mk | 6 ++++-- tools/testwriter.py | 21 +++++++++++++-------- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 7aba6079..21445777 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ usage: @echo " test3X run core tests with Python 3.X (8<=X<=11)" @echo " test-cover run core tests with coverage info" @echo " test-slow run slow tests in parallel" - @echo " test-all run core and disassembly tests" + @echo " test-all run core and disassembly tests in parallel" @echo " test3X-all run core and disassembly tests with Python 3.X (8<=X<=11)" @echo " release build a SkoolKit release tarball and zip archive" @echo " tarball build a SkoolKit release tarball" @@ -55,7 +55,7 @@ write-disassembly-tests: .PHONY: remove-disassembly-tests remove-disassembly-tests: - rm -f tests/test_hh_*.py* + rm -f tests/test_hh_*.py .PHONY: test test: remove-disassembly-tests @@ -63,7 +63,7 @@ test: remove-disassembly-tests .PHONY: test-all test-all: write-disassembly-tests - $(NOSE) + $(NOSE) --plugin=nose2.plugins.mp -N $(CORES) .PHONY: test3% test3%: remove-disassembly-tests diff --git a/tests/disassemblytest.py b/tests/disassemblytest.py index d59575c7..4f990d4c 100644 --- a/tests/disassemblytest.py +++ b/tests/disassemblytest.py @@ -105,8 +105,7 @@ def _test_ctl(self, options, skool=None, snapshot=None, ctl=None): class HtmlTestCase(DisassembliesTestCase): def setUp(self): DisassembliesTestCase.setUp(self) - self.odir = 'html-{0}'.format(os.getpid()) - self.tempdirs.append(self.odir) + self.odir = 'html' def _validate_xhtml(self): for root, dirs, files in os.walk(self.odir): diff --git a/tools/disassembly.mk b/tools/disassembly.mk index 4495f0d9..74b71f01 100644 --- a/tools/disassembly.mk +++ b/tools/disassembly.mk @@ -5,6 +5,7 @@ HTML_OPTIONS = $(HTML_OPTS) HTML_OPTIONS += -d $(BUILD)/html -t HTML_OPTIONS += $(foreach theme,$(THEMES),-T $(theme)) TESTS ?= asm ctl html +CORES ?= 0 .PHONY: usage usage: @@ -12,7 +13,7 @@ usage: @echo " usage show this help" @echo " html build the HTML disassembly" @echo " asm build the ASM disassembly" - @echo " test run tests with default Python 3 interpreter" + @echo " test run tests in parallel" @echo " test3X run tests with Python 3.X (8<=X<=11)" @$(MAKE) -s _targets @echo "" @@ -22,6 +23,7 @@ usage: @echo " THEMES CSS theme(s) to use" @echo " HTML_OPTS extra options passed to skool2html.py" @echo " ASM_OPTS options passed to skool2asm.py" + @echo " CORES number of processes to use when running tests in parallel" .PHONY: _targets _targets: @@ -43,7 +45,7 @@ write-tests: .PHONY: test test: write-tests - nose2-3 + nose2-3 --plugin=nose2.plugins.mp -N $(CORES) .PHONY: test3% test3%: write-tests diff --git a/tools/testwriter.py b/tools/testwriter.py index e3213ee1..a9091ddf 100644 --- a/tools/testwriter.py +++ b/tools/testwriter.py @@ -2,6 +2,7 @@ import os PROLOGUE = """ +import shutil import sys import os @@ -24,23 +25,27 @@ def _write_tests(test_type, sources, snapshot, output, skool, ctl, ref, clean): if skool: _add_variable(variables, 'SKOOL', skool) else: - _add_variable(variables, 'SNAPSHOT', os.path.abspath(snapshot)) - _add_variable(variables, 'CTL', os.path.abspath(ctl)) + _add_variable(variables, 'SNAPSHOT', os.path.basename(snapshot)) + _add_variable(variables, 'CTL', os.path.basename(ctl)) if test_type == 'asm': if not clean: _add_variable(variables, 'CLEAN', clean) elif test_type == 'html': _add_variable(variables, 'OUTPUT', output, True) if ref: - _add_variable(variables, 'REF', os.path.abspath(ref)) + _add_variable(variables, 'REF', os.path.basename(ref)) class_name = '{}TestCase'.format(test_type.capitalize()) print('class {0}(disassemblytest.{0}):'.format(class_name)) + print(' def setUp(self):') + print(' super().setUp()') if sources: - print(' @classmethod') - print(' def setUpClass(cls):') - print(' super().setUpClass()') - print(' os.chdir(SOURCEDIR)') - print('') + print(" shutil.copytree(SOURCEDIR, '.', dirs_exist_ok=True)") + else: + cwd = os.getcwd() + print(f" shutil.copy('{cwd}/{snapshot}', '.')") + print(f" shutil.copy('{cwd}/{ctl}', '.')") + print(f" shutil.copy('{cwd}/{ref}', '.')") + print('') for options in OPTIONS_LISTS[test_type]: method_name_suffix = options.replace('-', '_').replace(' ', '') method_name = 'test_{}{}'.format(test_type, method_name_suffix)