9c0ac839074511056fdd41ddb024a357e2241e6c
[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 openpower.test.algorithms.svp64_utf_8_validation import \
6 SVP64UTF8ValidationTestCase
7 from openpower.test.runner import TestRunnerBase
8 from functools import lru_cache
9
10 # writing the test_caller invocation this way makes it work with pytest
11
12
13 @lru_cache()
14 def make_cases():
15 # cache globally, so we only have to create test_data once per process
16 return SVP64UTF8ValidationTestCase().test_data
17
18
19 class TestSVP64UTF8ValidationBase(TestRunnerBase):
20 __test__ = False
21
22 # split up test cases into SPLIT_COUNT tests, so we get some parallelism
23 SPLIT_COUNT = 64
24 SPLIT_INDEX = -1
25
26 def __init__(self, test):
27 assert test == 'test', f"test={test!r}"
28 cases = make_cases()
29 assert self.SPLIT_INDEX != -1, "must be overridden"
30 # split cases evenly over tests
31 start = (len(cases) * self.SPLIT_INDEX) // self.SPLIT_COUNT
32 end = (len(cases) * (self.SPLIT_INDEX + 1)) // self.SPLIT_COUNT
33 # if we have less cases than tests, move them all to the beginning,
34 # making finding failures faster
35 if len(cases) < self.SPLIT_COUNT:
36 start = 0
37 end = 0
38 if self.SPLIT_INDEX < len(cases):
39 start = self.SPLIT_INDEX
40 end = start + 1
41 # can't do raise SkipTest if `start == end`, it makes unittest break
42 super().__init__(cases[start:end])
43
44 @classmethod
45 def make_split_classes(cls):
46 for i in range(cls.SPLIT_COUNT):
47 exec(f"""
48 class TestSVP64UTF8Validation{i}(TestSVP64UTF8ValidationBase):
49 __test__ = True
50 SPLIT_INDEX = {i}
51
52 def test(self):
53 # dummy function to make unittest try to test this class
54 pass
55 """, globals())
56
57
58 TestSVP64UTF8ValidationBase.make_split_classes()
59
60 if __name__ == "__main__":
61 unittest.main()