pysvp64db: fix traversal
[openpower-isa.git] / src / openpower / decoder / isa / test_caller_svp64_utf_8_validation.py
1 # SPDX-License-Identifier: LGPL-3-or-later
2 # Copyright 2022 Jacob Lifshay
3
4 import unittest
5 from functools import lru_cache
6 import os
7 from openpower.test.algorithms.svp64_utf_8_validation import \
8 SVP64UTF8ValidationTestCase
9 from openpower.test.runner import TestRunnerBase
10
11 # writing the test_caller invocation this way makes it work with pytest
12
13
14 @lru_cache()
15 def make_cases():
16 # cache globally, so we only have to create test_data once per process
17 return SVP64UTF8ValidationTestCase().test_data
18
19
20 class TestSVP64UTF8ValidationBase(TestRunnerBase):
21 __test__ = False
22
23 # split up test cases into SPLIT_COUNT tests, so we get some parallelism
24 SPLIT_COUNT = 64
25 SPLIT_INDEX = -1
26
27 def __init__(self, test):
28 assert test == 'test', f"test={test!r}"
29 self.__old_silence_log = os.environ.get("SILENCELOG")
30 cases = make_cases()
31 assert self.SPLIT_INDEX != -1, "must be overridden"
32 # split cases evenly over tests
33 start = (len(cases) * self.SPLIT_INDEX) // self.SPLIT_COUNT
34 end = (len(cases) * (self.SPLIT_INDEX + 1)) // self.SPLIT_COUNT
35 # if we have less cases than tests, move them all to the beginning,
36 # making finding failures faster
37 if len(cases) < self.SPLIT_COUNT:
38 start = 0
39 end = 0
40 if self.SPLIT_INDEX < len(cases):
41 start = self.SPLIT_INDEX
42 end = start + 1
43 # can't do raise SkipTest if `start == end`, it makes unittest break
44 super().__init__(cases[start:end], use_mmap_mem=True)
45
46 def setUp(self):
47 super().setUp()
48 if self.__old_silence_log is None:
49 os.environ["SILENCELOG"] = "!*,default"
50
51 def tearDown(self):
52 super().tearDown()
53 if self.__old_silence_log is None:
54 del os.environ["SILENCELOG"]
55
56 @classmethod
57 def make_split_classes(cls):
58 for i in range(cls.SPLIT_COUNT):
59 exec(f"""
60 class TestSVP64UTF8Validation{i}(TestSVP64UTF8ValidationBase):
61 __test__ = True
62 SPLIT_INDEX = {i}
63
64 def test(self):
65 # dummy function to make unittest try to test this class
66 pass
67 """, globals())
68
69
70 TestSVP64UTF8ValidationBase.make_split_classes()
71
72 if __name__ == "__main__":
73 unittest.main()