add quick test and loooong test of pysvp64dis - branches split out
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 20 Sep 2022 16:43:32 +0000 (17:43 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 20 Sep 2022 16:43:32 +0000 (17:43 +0100)
src/openpower/sv/trans/test_pysvp64dis.py
src/openpower/sv/trans/test_pysvp64dis_branch.py [new file with mode: 0644]

index 874efac17b16dd29e19be5f0271f583ab91dc721..1ffc775e3269da214e391ce63810c60e39d30d87 100644 (file)
@@ -257,26 +257,8 @@ class SVSTATETestCase(unittest.TestCase):
         self._do_tst(expected)
 
     def test_16_bc(self):
-        # hilarious. this should be autogenerated from a sequence
-        # of lists of options. it's a lot of frickin options.
-        lists = [[None, 'all'],
-                 [None, 'm=r3/sz', 'm=r3/snz'],
-                 #[None, 'vs', 'vsi', 'vsb', 'vsbi'],
-                 [None, 'ctr', 'cti'],
-                 #[None, 'sl'],
-                 #[None, 'slu'],
-                 #[None, 'lru'],
-                ]
-        expected = []
-        for options in itertools.product(*lists):
-            options = list(filter(lambda x:x, options))
-            options.sort() # otherwise chaos!
-            if len(options) != 0:
-                options = [''] + options # trick to make a "/" at the front
-            print ("option", options)
-            option = "sv.bc%s 12,*1,0xc" % "/".join(options)
-            expected.append(option)
-        #_old_handcrafted_expected = [
+        """bigger list in test_pysvp64dis_branch.py, this one's "quick"
+        """
         expected = [
                     "sv.bc/all 12,*1,0xc",
                     "sv.bc/snz 12,*1,0xc",
diff --git a/src/openpower/sv/trans/test_pysvp64dis_branch.py b/src/openpower/sv/trans/test_pysvp64dis_branch.py
new file mode 100644 (file)
index 0000000..104330c
--- /dev/null
@@ -0,0 +1,62 @@
+from openpower.simulator.program import Program
+from openpower.sv.trans.pysvp64dis import load, dump
+from openpower.sv.trans.svp64 import SVP64Asm
+from openpower.decoder.power_insn import Database, Verbosity
+from openpower.decoder.power_enums import find_wiki_dir
+from openpower.sv import sv_binutils_fptrans
+import unittest
+import itertools
+import sys
+
+class SVSTATETestCase(unittest.TestCase):
+
+    def _do_tst(self, expected):
+        isa = SVP64Asm(expected)
+        lst = list(isa)
+        with Program(lst, bigendian=False) as program:
+            print ("ops", program._instructions)
+            program.binfile.seek(0)
+            insns = load(program.binfile)
+            #for insn in insns:
+                #print ("insn", insn)
+            insns = list(insns)
+            print ("insns", insns)
+            for i, line in enumerate(dump(insns, verbosity=Verbosity.SHORT)):
+                name = expected[i].split(" ")[0]
+                with self.subTest("%d:%s" % (i, name)):
+                    print("instruction", repr(line), repr(expected[i]))
+                    self.assertEqual(expected[i], line,
+                                     "instruction does not match "
+                                     "'%s' expected '%s'" % (line, expected[i]))
+
+
+    def test_0_bc(self):
+        # hilarious. this should be autogenerated from a sequence
+        # of lists of options. it's a lot of frickin options.
+        lists = [[None, 'all'],
+                 [None, 'm=r3', 'sz', 'snz'], # see below on this one...
+                 [None, 'vs', 'vsi', 'vsb', 'vsbi'],
+                 [None, 'ctr', 'cti'],
+                 [None, 'sl'],
+                 [None, 'slu'],
+                 [None, 'lru'],
+                ]
+        expected = []
+        for options in itertools.product(*lists): # permutations of list-options
+            options = list(filter(lambda x:x, options)) # filter Nones
+            # /sz or /snz must have /m=r3 added but then sorted
+            if 'sz' in options or 'snz' in options:
+                options.append("m=r3")
+            options.sort() # otherwise chaos!
+            if len(options) != 0:
+                options = [''] + options # trick to make a "/" at the front
+            print ("option", options)
+            # ahhhhhahahaha and sv.bcctr and sv.bcl ahahahahaah....
+            option = "sv.bc%s 12,*1,0xc" % "/".join(options)
+            expected.append(option)
+
+        self._do_tst(expected)
+
+if __name__ == "__main__":
+    unittest.main()
+