adding OP_MTMSR test
[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
10 from soc.regfile.util import fast_reg_to_spr # HACK!
11
12 """
13 def assert_outputs(self, branch, dec2, sim, prev_nia, code):
14 """
15
16
17 class BranchTestRunner(TestRunner):
18 def __init__(self, test_data):
19 super().__init__(test_data, BranchFunctionUnit, self,
20 Function.BRANCH)
21
22 def get_cu_inputs(self, dec2, sim):
23 """naming (res) must conform to BranchFunctionUnit input regspec
24 """
25 res = yield from get_cu_inputs(dec2, sim)
26 return res
27
28 def check_cu_outputs(self, res, dec2, sim, code):
29 """naming (res) must conform to BranchFunctionUnit output regspec
30 """
31
32 print ("check extra output", repr(code), res)
33
34 # NIA (next instruction address aka PC)
35 branch_taken = 'nia' in res
36 # TODO - get the old PC, use it to check if the branch was taken
37 # sim_branch_taken = prev_nia != sim.pc.CIA
38 # self.assertEqual(branch_taken, sim_branch_taken, code)
39 if branch_taken:
40 branch_addr = res['nia']
41 self.assertEqual(branch_addr, sim.pc.CIA.value, code)
42
43 # Link SPR
44 lk = yield dec2.e.do.lk
45 branch_lk = 'fast2' in res
46 self.assertEqual(lk, branch_lk, code)
47 if lk:
48 branch_lr = res['fast2']
49 self.assertEqual(sim.spr['LR'], branch_lr, code)
50
51 # CTR SPR
52 ctr_ok = 'fast1' in res
53 if ctr_ok:
54 ctr = res['fast1']
55 self.assertEqual(sim.spr['CTR'], ctr, code)
56
57
58 if __name__ == "__main__":
59 unittest.main(exit=False)
60 suite = unittest.TestSuite()
61 suite.addTest(BranchTestRunner(BranchTestCase.test_data))
62
63 runner = unittest.TextTestRunner()
64 runner.run(suite)