big reorg on PowerDecoder2, actually Decode2Execute1Type
[soc.git] / src / soc / fu / compunits / test / test_alu_compunit.py
1 import unittest
2 from soc.decoder.power_enums import (XER_bits, Function)
3
4 from soc.fu.alu.test.test_pipe_caller import get_cu_inputs
5 from soc.fu.alu.test.test_pipe_caller import ALUTestCase # creates the tests
6
7 from soc.fu.test.common import ALUHelpers
8 from soc.fu.compunits.compunits import ALUFunctionUnit
9 from soc.fu.compunits.test.test_compunit import TestRunner
10
11
12 class ALUTestRunner(TestRunner):
13 def __init__(self, test_data):
14 super().__init__(test_data, ALUFunctionUnit, self,
15 Function.ALU)
16
17 def get_cu_inputs(self, dec2, sim):
18 """naming (res) must conform to ALUFunctionUnit input regspec
19 """
20 res = yield from get_cu_inputs(dec2, sim)
21 return res
22
23 def check_cu_outputs(self, res, dec2, sim, code):
24 """naming (res) must conform to ALUFunctionUnit output regspec
25 """
26
27 rc = yield dec2.e.do.rc.data
28 op = yield dec2.e.do.insn_type
29 cridx_ok = yield dec2.e.write_cr.ok
30 cridx = yield dec2.e.write_cr.data
31
32 print ("check extra output", repr(code), cridx_ok, cridx)
33
34 if rc:
35 self.assertEqual(cridx_ok, 1, code)
36 self.assertEqual(cridx, 0, code)
37
38 sim_o = {}
39
40 yield from ALUHelpers.get_sim_int_o(sim_o, sim, dec2)
41 yield from ALUHelpers.get_wr_sim_cr_a(sim_o, sim, dec2)
42 yield from ALUHelpers.get_sim_xer_ov(sim_o, sim, dec2)
43 yield from ALUHelpers.get_wr_sim_xer_ca(sim_o, sim, dec2)
44 yield from ALUHelpers.get_sim_xer_so(sim_o, sim, dec2)
45
46 ALUHelpers.check_cr_a(self, res, sim_o, "CR%d %s" % (cridx, code))
47 ALUHelpers.check_xer_ov(self, res, sim_o, code)
48 ALUHelpers.check_xer_ca(self, res, sim_o, code)
49 ALUHelpers.check_int_o(self, res, sim_o, code)
50 ALUHelpers.check_xer_so(self, res, sim_o, code)
51
52
53 if __name__ == "__main__":
54 unittest.main(exit=False)
55 suite = unittest.TestSuite()
56 suite.addTest(ALUTestRunner(ALUTestCase.test_data))
57
58 runner = unittest.TextTestRunner()
59 runner.run(suite)