create new function teststate_check_regs which is called by check_regs
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 12 Sep 2021 13:21:23 +0000 (14:21 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 12 Sep 2021 13:21:23 +0000 (14:21 +0100)
teststate_checkregs does not care how many pieces of state it is asked
to compare. could be 2, could be 3, could be 30

src/soc/simple/test/test_core.py
src/soc/simple/test/teststate.py

index 608c442c3d70c748c9110c9384cb8ef00084f45c..0be2a292e8b0c7ab29e11474c24f764913d1fba0 100644 (file)
@@ -149,12 +149,23 @@ def setup_regs(pdecode2, core, test):
     print("oe:", oe, oe_ok)
 
 
+def teststate_check_regs(dut, states, test, code):
+    """teststate_check_regs: compares a set of Power ISA objects
+    to check if they have the same "state" (registers only, at the moment)
+    """
+    slist = []
+    for stype, totest in states.items():
+        state = yield from TestState(stype, totest, dut, code)
+        slist.append(state)
+    for i in range(len(slist)-1):
+        state, against = slist[i], slist[i+1]
+        state.compare(against)
+
+
 def check_regs(dut, sim, core, test, code):
     # create the two states and compare
     testdic = {'sim': sim, 'hdl': core}
-    simstate = yield from TestState('sim', testdic, dut, code)
-    corestate = yield from TestState('hdl', testdic, dut, code)
-    simstate.compare(corestate)
+    yield from teststate_check_regs(dut, testdic, test, code)
 
 
 def wait_for_busy_hi(cu):
index 9b45f50654168701fe19f496f0cb824eafff8b05..f10d2462338d461c2c2c218d6c8bac91d738928f 100644 (file)
@@ -124,10 +124,14 @@ class HDLState(State):
         print("class hdl pc", hex(self.pc))
 
 
-def TestState(state_type, state_dic, dut, code):
-    state_factory = {'sim': SimState, 'hdl': HDLState}
+global state_factory
+state_factory = {'sim': SimState, 'hdl': HDLState}
+
+
+def TestState(state_type, to_test, dut, code):
     state_class = state_factory[state_type]
-    state = state_class(state_dic[state_type])
+    state = state_class(to_test)
+    state.to_test = to_test
     state.dut = dut
     state.state_type = state_type
     state.code = code