convert CR test to accumulator style
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 26 Jul 2020 10:58:33 +0000 (11:58 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 26 Jul 2020 10:58:33 +0000 (11:58 +0100)
src/soc/fu/compunits/test/test_cr_compunit.py
src/soc/fu/cr/test/test_pipe_caller.py
src/soc/fu/test/common.py

index 8d685835a9d0375879eac5da9a2fbbe04c0d6b80..a054ea14e1425f16e6ce5483120c9b613c625e61 100644 (file)
@@ -56,7 +56,7 @@ class CRTestRunner(TestRunner):
 if __name__ == "__main__":
     unittest.main(exit=False)
     suite = unittest.TestSuite()
-    suite.addTest(CRTestRunner(CRTestCase.test_data))
+    suite.addTest(CRTestRunner(CRTestCase().test_data))
 
     runner = unittest.TextTestRunner()
     runner.run(suite)
index f933636fc3d86ae0e948732dd9fdfd6f30c72f80..4c389d345b2341d1b7412d785cec8b2b286c6847 100644 (file)
@@ -12,7 +12,7 @@ from soc.simulator.program import Program
 from soc.decoder.isa.all import ISA
 from soc.config.endian import bigendian
 
-from soc.fu.test.common import TestCase, ALUHelpers
+from soc.fu.test.common import TestAccumulatorBase, TestCase, ALUHelpers
 from soc.fu.cr.pipeline import CRBasePipe
 from soc.fu.cr.pipe_data import CRPipeSpec
 import random
@@ -37,20 +37,9 @@ import random
 # takes around 3 seconds
 
 
-class CRTestCase(FHDLTestCase):
-    test_data = []
+class CRTestCase(TestAccumulatorBase):
 
-    def __init__(self, name):
-        super().__init__(name)
-        self.test_name = name
-
-    def run_tst_program(self, prog, initial_regs=None, initial_sprs=None,
-                        initial_cr=0):
-        tc = TestCase(prog, self.test_name,
-                      regs=initial_regs, sprs=initial_sprs, cr=initial_cr)
-        self.test_data.append(tc)
-
-    def test_crop(self):
+    def case_crop(self):
         insns = ["crand", "cror", "crnand", "crnor", "crxor", "creqv",
                  "crandc", "crorc"]
         for i in range(40):
@@ -60,62 +49,62 @@ class CRTestCase(FHDLTestCase):
             bt = random.randint(0, 31)
             lst = [f"{choice} {ba}, {bb}, {bt}"]
             cr = random.randint(0, (1 << 32)-1)
-            self.run_tst_program(Program(lst, bigendian), initial_cr=cr)
+            self.add_case(Program(lst, bigendian), initial_cr=cr)
 
-    def test_crand(self):
+    def case_crand(self):
         for i in range(20):
             lst = ["crand 0, 11, 13"]
             cr = random.randint(0, (1 << 32)-1)
-            self.run_tst_program(Program(lst, bigendian), initial_cr=cr)
+            self.add_case(Program(lst, bigendian), initial_cr=cr)
 
-    def test_1_mcrf(self):
+    def case_1_mcrf(self):
         for i in range(20):
             src = random.randint(0, 7)
             dst = random.randint(0, 7)
             lst = [f"mcrf {src}, {dst}"]
             cr = random.randint(0, (1 << 32)-1)
-        self.run_tst_program(Program(lst, bigendian), initial_cr=cr)
+        self.add_case(Program(lst, bigendian), initial_cr=cr)
 
-    def test_0_mcrf(self):
+    def case_0_mcrf(self):
         for i in range(8):
             lst = [f"mcrf 5, {i}"]
             cr = 0xfeff0001
-            self.run_tst_program(Program(lst, bigendian), initial_cr=cr)
+            self.add_case(Program(lst, bigendian), initial_cr=cr)
 
-    def test_mtcrf(self):
+    def case_mtcrf(self):
         for i in range(20):
             mask = random.randint(0, 255)
             lst = [f"mtcrf {mask}, 2"]
             cr = random.randint(0, (1 << 32)-1)
             initial_regs = [0] * 32
             initial_regs[2] = random.randint(0, (1 << 32)-1)
-            self.run_tst_program(Program(lst, bigendian), initial_regs=initial_regs,
+            self.add_case(Program(lst, bigendian), initial_regs=initial_regs,
                                  initial_cr=cr)
 
-    def test_mtocrf(self):
+    def case_mtocrf(self):
         for i in range(20):
             mask = 1 << random.randint(0, 7)
             lst = [f"mtocrf {mask}, 2"]
             cr = random.randint(0, (1 << 32)-1)
             initial_regs = [0] * 32
             initial_regs[2] = random.randint(0, (1 << 32)-1)
-            self.run_tst_program(Program(lst, bigendian), initial_regs=initial_regs,
+            self.add_case(Program(lst, bigendian), initial_regs=initial_regs,
                                  initial_cr=cr)
 
-    def test_mfcr(self):
+    def case_mfcr(self):
         for i in range(5):
             lst = ["mfcr 2"]
             cr = random.randint(0, (1 << 32)-1)
-            self.run_tst_program(Program(lst, bigendian), initial_cr=cr)
+            self.add_case(Program(lst, bigendian), initial_cr=cr)
 
-    def test_mfocrf(self):
+    def case_mfocrf(self):
         for i in range(20):
             mask = 1 << random.randint(0, 7)
             lst = [f"mfocrf 2, {mask}"]
             cr = random.randint(0, (1 << 32)-1)
-            self.run_tst_program(Program(lst, bigendian), initial_cr=cr)
+            self.add_case(Program(lst, bigendian), initial_cr=cr)
 
-    def test_isel(self):
+    def case_isel(self):
         for i in range(20):
             bc = random.randint(0, 31)
             lst = [f"isel 1, 2, 3, {bc}"]
@@ -125,22 +114,22 @@ class CRTestCase(FHDLTestCase):
             initial_regs[3] = random.randint(0, (1 << 64)-1)
             #initial_regs[2] = i*2
             #initial_regs[3] = i*2+1
-            self.run_tst_program(Program(lst, bigendian),
+            self.add_case(Program(lst, bigendian),
                                  initial_regs=initial_regs, initial_cr=cr)
 
-    def test_setb(self):
+    def case_setb(self):
         for i in range(20):
             bfa = random.randint(0, 7)
             lst = [f"setb 1, {bfa}"]
             cr = random.randint(0, (1 << 32)-1)
-            self.run_tst_program(Program(lst, bigendian), initial_cr=cr)
+            self.add_case(Program(lst, bigendian), initial_cr=cr)
 
-    def test_regression_setb(self):
+    def case_regression_setb(self):
         lst = [f"setb 1, 6"]
         cr = random.randint(0, 0x66f6b106)
-        self.run_tst_program(Program(lst, bigendian), initial_cr=cr)
+        self.add_case(Program(lst, bigendian), initial_cr=cr)
 
-    def test_ilang(self):
+    def case_ilang(self):
         pspec = CRPipeSpec(id_wid=2)
         alu = CRBasePipe(pspec)
         vl = rtlil.convert(alu, ports=alu.ports())
@@ -295,7 +284,7 @@ class TestRunner(FHDLTestCase):
 if __name__ == "__main__":
     unittest.main(exit=False)
     suite = unittest.TestSuite()
-    suite.addTest(TestRunner(CRTestCase.test_data))
+    suite.addTest(TestRunner(CRTestCase().test_data))
 
     runner = unittest.TextTestRunner()
     runner.run(suite)
index b4bceb1b43bd7adcfc66ebd45f92f7ccaa4a8f03..99dd1d5c13b38c34b23c0ffa921257c5a388b299 100644 (file)
@@ -19,9 +19,11 @@ class TestAccumulatorBase:
             if n.startswith("case_") and callable(v):
                 v(self)
 
-    def add_case(self, prog, initial_regs=None, initial_sprs=None):
+    def add_case(self, prog, initial_regs=None, initial_sprs=None,
+                        initial_cr=0):
         test_name = inspect.stack()[1][3] # name of caller of this function
-        tc = TestCase(prog, test_name, initial_regs, initial_sprs)
+        tc = TestCase(prog, test_name, 
+                      regs=initial_regs, sprs=initial_sprs, cr=initial_cr)
         self.test_data.append(tc)