add randomised hazard test
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 30 Nov 2021 18:29:09 +0000 (18:29 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 30 Nov 2021 18:29:09 +0000 (18:29 +0000)
src/openpower/test/general/overlap_hazards.py

index 78fe9795a0b1f02bac335789e95a0f60dfd6d61e..24cd6903c8a75a308e7e45fb21da215354ea1cee 100644 (file)
@@ -180,3 +180,36 @@ class HazardTestCase(TestAccumulatorBase):
         e.intregs[9] = 10 # 8+2 == 10
         self.add_case(Program(lst, bigendian), initial_regs, expected=e)
 
+
+class RandomHazardTestCase(TestAccumulatorBase):
+
+    def case_random(self):
+        selection_1 = ['mulli', 'addi']
+        selection_2 = ['mullw', 'add']
+        rrange = 8
+        n_ops = 10
+        lst = []
+        for i in range(n_ops):
+            if random.randint(0, 1) == 0:
+                select = selection_1[random.randint(0, len(selection_1)-1)]
+                dst = random.randint(0, rrange)
+                reg1 = random.randint(0, rrange)
+                imm = random.randint(-20, +20)
+                insn = "%s %d, %d, %d" % (select, dst, reg1, imm)
+            else:
+                select = selection_2[random.randint(0, len(selection_2)-1)]
+                dst = random.randint(0, rrange)
+                reg1 = random.randint(0, rrange)
+                reg2 = random.randint(0, rrange)
+                insn = "%s %d, %d, %d" % (select, dst, reg1, reg2)
+            lst.append(insn)
+        initial_regs = [0] * 32
+        for i in range(rrange):
+            initial_regs[i] = random.randint(-20, +20)
+        self.add_case(Program(lst, bigendian), initial_regs)
+
+    def case_regression(self):
+        lst = ['addi 1,8,14',
+               'addi 3,0,5',
+               'mulli 1,3,-11'
+              ]