added factory function for test class creation
authorklehman <klehman9@comcast.net>
Sun, 12 Sep 2021 00:53:31 +0000 (20:53 -0400)
committerklehman <klehman9@comcast.net>
Sun, 12 Sep 2021 00:53:31 +0000 (20:53 -0400)
src/soc/simple/test/teststate.py

index 8d6c32bd8ec2ce1f9e9170a685947a05eef85004..c51107ed77157622956cb6905798c16bfca419b1 100644 (file)
@@ -1,27 +1,14 @@
 from openpower.decoder.power_enums import XER_bits
 
-class State:
-    def __init__(self):
-        pass
-
-    def get_intregs(self):
-        pass
-
-    def get_crregs(self):
-        pass
-
-    def get_xregs(self):
-        pass
-
-    def get_pc(self):
-        pass
 
+class State:
     def get_state(self):
         yield from self.get_intregs()
         yield from self.get_crregs()
         yield from self.get_xregs()
         yield from self.get_pc()
 
+
 class SimState(State):
     def __init__(self, sim):
         self.sim = sim
@@ -103,3 +90,13 @@ class HDLState(State):
         self.pc = yield self.state.r_ports['cia'].o_data
         self.pcl.append(self.pc)
         print("class hdl pc", hex(self.pc))
+
+
+def TestState(state_type, dut, state_dic):
+    state_factory = {'sim': SimState, 'hdl': HDLState}
+    state_class = state_factory[state_type]
+    state = state_class(state_dic[state_type])
+    state.dut = dut
+    state.state_type = state_type
+    yield from state.get_state()
+    return state