* https://bugs.libre-soc.org/show_bug.cgi?id=361
"""
+from contextlib import contextmanager
import inspect
import functools
import types
class TestAccumulatorBase:
-
def __init__(self):
+ self.__subtest_args = {}
+
self.test_data = []
# automatically identifies anything starting with "case_" and
# runs it. very similar to unittest auto-identification except
# reason and ignore
print(f"SKIPPED({n}):", str(e))
+ @contextmanager
+ def subTest(self, **kwargs):
+ old_subtest_args = self.__subtest_args
+ try:
+ self.__subtest_args = old_subtest_args.copy()
+ self.__subtest_args.update(**kwargs)
+ yield
+ finally:
+ self.__subtest_args = old_subtest_args
+
def add_case(self, prog, initial_regs=None, initial_sprs=None,
initial_cr=0, initial_msr=0,
initial_mem=None,
initial_svstate=0,
expected=None,
- stop_at_pc=None):
+ stop_at_pc=None,
+ src_loc_at=0):
- test_name = inspect.stack()[1][3] # name of caller of this function
+ # name of caller of this function
+ test_name = inspect.stack()[1 + src_loc_at][3]
# name of file containing test case
test_file = os.path.splitext(os.path.basename(
inspect.stack()[1][1]))[0]
svstate=initial_svstate,
expected=expected,
stop_at_pc=stop_at_pc,
- test_file=test_file)
+ test_file=test_file,
+ subtest_args=self.__subtest_args.copy())
self.test_data.append(tc)
svstate=0,
expected=None,
stop_at_pc=None,
- test_file=None):
+ test_file=None,
+ subtest_args=None):
self.program = program
self.name = name
self.expected = expected # expected results from the test
self.stop_at_pc = stop_at_pc # hard-stop address (do not attempt to run)
self.test_file = test_file
+ self.subtest_args = {} if subtest_args is None else dict(subtest_args)
class ALUHelpers:
# get each test, completely reset the core, and run it
for test in self.test_data:
-
- with self.subTest(test.name):
+ with self.subTest(test.name, **test.subtest_args):
###### PREPARATION PHASE AT START OF TEST #######