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