From: Luke Kenneth Casson Leighton Date: Thu, 4 Jun 2020 19:10:37 +0000 (+0100) Subject: no global variables in test suites X-Git-Tag: div_pipeline~584 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=13a34c6f0ff446b7bf61897950366f29694268c8;p=soc.git no global variables in test suites --- diff --git a/src/soc/fu/compunits/test/test_shiftrot_compunit.py b/src/soc/fu/compunits/test/test_shiftrot_compunit.py index 890d743f..81f7b862 100644 --- a/src/soc/fu/compunits/test/test_shiftrot_compunit.py +++ b/src/soc/fu/compunits/test/test_shiftrot_compunit.py @@ -4,7 +4,6 @@ from soc.decoder.power_enums import (XER_bits, Function) # XXX bad practice: use of global variables from soc.fu.shift_rot.test.test_pipe_caller import get_cu_inputs from soc.fu.shift_rot.test.test_pipe_caller import ShiftRotTestCase -from soc.fu.shift_rot.test.test_pipe_caller import test_data from soc.fu.compunits.compunits import ShiftRotFunctionUnit from soc.fu.compunits.test.test_compunit import TestRunner @@ -69,7 +68,7 @@ class ShiftRotTestRunner(TestRunner): if __name__ == "__main__": unittest.main(exit=False) suite = unittest.TestSuite() - suite.addTest(ShiftRotTestRunner(test_data)) + suite.addTest(ShiftRotTestRunner(ShiftRotTestCase.test_data)) runner = unittest.TextTestRunner() runner.run(suite) diff --git a/src/soc/fu/shift_rot/test/test_pipe_caller.py b/src/soc/fu/shift_rot/test/test_pipe_caller.py index cab58845..c8e3153e 100644 --- a/src/soc/fu/shift_rot/test/test_pipe_caller.py +++ b/src/soc/fu/shift_rot/test/test_pipe_caller.py @@ -84,7 +84,7 @@ def set_alu_inputs(alu, dec2, sim): print ("extra inputs: CA/32", bin(inp['xer_ca'])) else: yield alu.p.data_i.xer_ca.eq(0) - + # This test bench is a bit different than is usual. Initially when I # was writing it, I had all of the tests call a function to create a @@ -104,17 +104,16 @@ def set_alu_inputs(alu, dec2, sim): # massively. Before, it took around 1 minute on my computer, now it # takes around 3 seconds -test_data = [] - class ShiftRotTestCase(FHDLTestCase): + test_data = [] def __init__(self, name): super().__init__(name) self.test_name = name + def run_tst_program(self, prog, initial_regs=None, initial_sprs=None): tc = TestCase(prog, self.test_name, initial_regs, initial_sprs) - test_data.append(tc) - + self.test_data.append(tc) def test_shift(self): insns = ["slw", "sld", "srw", "srd", "sraw", "srad"] @@ -127,7 +126,6 @@ class ShiftRotTestCase(FHDLTestCase): print(initial_regs[1], initial_regs[2]) self.run_tst_program(Program(lst), initial_regs) - def test_shift_arith(self): lst = ["sraw 3, 1, 2"] initial_regs = [0] * 32 @@ -249,7 +247,7 @@ class TestRunner(FHDLTestCase): fn_unit = yield pdecode2.e.fn_unit self.assertEqual(fn_unit, Function.SHIFT_ROT.value) yield from set_alu_inputs(alu, pdecode2, simulator) - yield + yield opname = code.split(' ')[0] yield from simulator.call(opname) index = simulator.pc.CIA.value//4 @@ -286,7 +284,7 @@ class TestRunner(FHDLTestCase): if __name__ == "__main__": unittest.main(exit=False) suite = unittest.TestSuite() - suite.addTest(TestRunner(test_data)) + suite.addTest(TestRunner(ShiftRotTestCase.test_data)) runner = unittest.TextTestRunner() runner.run(suite)