Merge remote-tracking branch 'upstream/master' into pr
[soc.git] / src / soc / fu / compunits / test / test_branch_compunit.py
1 import unittest
2 from openpower.decoder.power_enums import (XER_bits, Function)
3
4 from soc.fu.branch.test.test_pipe_caller import BranchTestCase, get_cu_inputs
5
6 from soc.fu.compunits.compunits import BranchFunctionUnit
7 from soc.fu.compunits.test.test_compunit import TestRunner
8 from openpower.endian import bigendian
9
10
11 """
12 def assert_outputs(self, branch, dec2, sim, prev_nia, code):
13 """
14
15
16 class BranchTestRunner(TestRunner):
17 def __init__(self, test_data):
18 super().__init__(test_data, BranchFunctionUnit, self,
19 Function.BRANCH, bigendian)
20
21 def get_cu_inputs(self, dec2, sim):
22 """naming (res) must conform to BranchFunctionUnit input regspec
23 """
24 res = yield from get_cu_inputs(dec2, sim)
25 return res
26
27 def check_cu_outputs(self, res, dec2, sim, alu, code):
28 """naming (res) must conform to BranchFunctionUnit output regspec
29 """
30
31 print("check extra output", repr(code), res)
32
33 # NIA (next instruction address aka PC)
34 branch_taken = 'nia' in res
35 # TODO - get the old PC, use it to check if the branch was taken
36 # sim_branch_taken = prev_nia != sim.pc.CIA
37 # self.assertEqual(branch_taken, sim_branch_taken, code)
38 if branch_taken:
39 branch_addr = res['nia']
40 self.assertEqual(branch_addr, sim.pc.CIA.value, code)
41
42 # Link SPR
43 lk = yield dec2.e.do.lk
44 branch_lk = 'fast2' in res
45 self.assertEqual(lk, branch_lk, code)
46 if lk:
47 branch_lr = res['fast2']
48 self.assertEqual(sim.spr['LR'], branch_lr, code)
49
50 # CTR SPR
51 ctr_ok = 'fast1' in res
52 if ctr_ok:
53 ctr = res['fast1']
54 self.assertEqual(sim.spr['CTR'], ctr, code)
55
56
57 if __name__ == "__main__":
58 unittest.main(exit=False)
59 suite = unittest.TestSuite()
60 suite.addTest(BranchTestRunner(BranchTestCase().test_data))
61
62 runner = unittest.TextTestRunner()
63 runner.run(suite)