From 12a655da81a2c8b4a335b4b63ccecec01e78b7f6 Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Thu, 18 May 2023 18:01:08 -0700 Subject: [PATCH] parallelize fmv/fcvt unit tests --- .../decoder/isa/test_caller_fmv_fcvt.py | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/src/openpower/decoder/isa/test_caller_fmv_fcvt.py b/src/openpower/decoder/isa/test_caller_fmv_fcvt.py index cf5730b7..8bb90346 100644 --- a/src/openpower/decoder/isa/test_caller_fmv_fcvt.py +++ b/src/openpower/decoder/isa/test_caller_fmv_fcvt.py @@ -2,6 +2,7 @@ """ import unittest +from functools import lru_cache from openpower.test.fmv_fcvt.fmv_fcvt import (FMvFCvtCases, SVP64FMvFCvtCases) @@ -10,14 +11,52 @@ from openpower.test.runner import TestRunnerBase # writing the test_caller invocation this way makes it work with pytest -class TestFMvFCvtCases(TestRunnerBase): +@lru_cache() +def make_cases(): + # cache globally, so we only have to create test_data once per process + return FMvFCvtCases().test_data + + +class TestFMvFCvtBase(TestRunnerBase): + __test__ = False + + # split up test cases into SPLIT_COUNT tests, so we get some parallelism + SPLIT_COUNT = 16 + SPLIT_INDEX = -1 + def __init__(self, test): - assert test == 'test' - super().__init__(FMvFCvtCases().test_data, fp=True) + assert test == 'test', f"test={test!r}" + cases = make_cases() + assert self.SPLIT_INDEX != -1, "must be overridden" + # split cases evenly over tests + start = (len(cases) * self.SPLIT_INDEX) // self.SPLIT_COUNT + end = (len(cases) * (self.SPLIT_INDEX + 1)) // self.SPLIT_COUNT + # if we have less cases than tests, move them all to the beginning, + # making finding failures faster + if len(cases) < self.SPLIT_COUNT: + start = 0 + end = 0 + if self.SPLIT_INDEX < len(cases): + start = self.SPLIT_INDEX + end = start + 1 + # can't do raise SkipTest if `start == end`, it makes unittest break + super().__init__(cases[start:end], fp=True) + + @classmethod + def make_split_classes(cls): + for i in range(cls.SPLIT_COUNT): + exec(f""" +class TestFMvFCvt{i}(TestFMvFCvtBase): + __test__ = True + SPLIT_INDEX = {i} def test(self): # dummy function to make unittest try to test this class pass + """, globals()) + + +TestFMvFCvtBase.make_split_classes() class TestSVP64FMvFCvtCases(TestRunnerBase): -- 2.30.2