Skip to content

Commit

Permalink
Enable disassembly tests to run in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
skoolkid committed Sep 5, 2023
1 parent be190de commit 5b2ac91
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -55,15 +55,15 @@ 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
$(NOSE) --plugin=nose2.plugins.mp -N $(CORES)

.PHONY: test-all
test-all: write-disassembly-tests
$(NOSE)
$(NOSE) --plugin=nose2.plugins.mp -N $(CORES)

.PHONY: test3%
test3%: remove-disassembly-tests
Expand Down
3 changes: 1 addition & 2 deletions tests/disassemblytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 4 additions & 2 deletions tools/disassembly.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ 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:
@echo "Targets:"
@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 ""
Expand All @@ -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:
Expand All @@ -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
Expand Down
21 changes: 13 additions & 8 deletions tools/testwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os

PROLOGUE = """
import shutil
import sys
import os
Expand All @@ -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)
Expand Down

0 comments on commit 5b2ac91

Please sign in to comment.