3 This module tests the functionality of the state class by manually
4 loading various registers and memory with values to be compared
5 between different states.
8 * https://bugs.libre-soc.org/show_bug.cgi?id=686
14 from openpower
.test
.state
import SimState
, state_factory
17 class TestStates(unittest
.TestCase
):
18 def test_basic_regs(self
):
19 initial_regs
= [0] * 32
21 initial_regs
[i
] = random
.randint(0, (1 << 64) - 1)
22 sim
= self
.empty_state('sim')
23 sim
.intregs
= initial_regs
24 hdl
= self
.empty_state('hdl')
25 hdl
.intregs
= initial_regs
27 sim
= self
.empty_state('sim')
28 sim
.intregs
= initial_regs
29 hdl
= self
.empty_state('hdl')
30 hdl
.intregs
= initial_regs
33 @unittest.expectedFailure
34 def test_basic_regs_fail(self
):
35 initial_regs
= [0] * 32
37 initial_regs
[i
] = random
.randint(0, (1 << 64) - 1)
38 fail_regs
[i
] = random
.randint(0, (1 << 64) - 1)
39 sim
= self
.empty_state('sim')
40 sim
.intregs
= initial_regs
41 hdl
= self
.empty_state('hdl')
42 hdl
.intregs
= fail_regs
44 sim
= self
.empty_state('sim')
45 sim
.intregs
= initial_regs
46 hdl
= self
.empty_state('hdl')
47 hdl
.intregs
= fail_regs
50 def test_basic_mem(self
):
53 initial_mem
[i
*8] = random
.randint(0, (1 << 64) - 1)
54 sim
= self
.empty_state('sim')
56 hdl
= self
.empty_state('hdl')
61 def test_basic_mem_size_0_diff(self
):
62 sim_mem
= {0: 8, 16: 24, 240: 32}
63 hdl_mem
= {0: 8, 16: 24, 224: 0, 232: 0, 240: 32}
64 sim
= self
.empty_state('sim')
66 hdl
= self
.empty_state('hdl')
71 @unittest.expectedFailure
72 def test_basic_mem_size_fail(self
):
75 initial_mem
[i
] = random
.randint(0, (1 << 64) - 1)
76 sim
= self
.empty_state('sim')
78 hdl
= self
.empty_state('hdl')
80 hdl
.mem
[i
] = initial_mem
[i
]
84 @unittest.expectedFailure
85 def test_basic_mem_off_by_one(self
):
86 sim_mem
= {0: 8, 16: 24, 24: 0}
87 hdl_mem
= {0: 8, 8: 24, 24: 0}
88 sim
= self
.empty_state('sim')
90 hdl
= self
.empty_state('hdl')
95 @unittest.expectedFailure
96 def test_basic_mem_one_word_fail(self
):
99 sim
= self
.empty_state('sim')
101 hdl
= self
.empty_state('hdl')
106 @unittest.expectedFailure
107 def test_basic_no_mem_fail(self
):
109 sim
= self
.empty_state('sim')
110 hdl
= self
.empty_state('hdl')
115 def empty_state(self
, state_type
):
116 state_class
= state_factory
[state_type
]
117 state
= state_class(None)
121 state
.so
, state
.sv
, state
.ov
, state
.ca
= 0, 0, 0, 0
125 state
.state_type
= state_type
129 if __name__
== '__main__':