Skip to content

Commit d1646ab

Browse files
authored
Drop unittest from TestCaseWithSimulator (#642)
1 parent 4ba6564 commit d1646ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+557
-545
lines changed

test/cache/test_icache.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class TestSimpleCommonBusCacheRefiller(TestCaseWithSimulator):
6767
line_size: int
6868
fetch_block: int
6969

70-
def setUp(self) -> None:
70+
def setup_method(self) -> None:
7171
self.gen_params = GenParams(
7272
test_core_config.replace(
7373
xlen=self.isa_xlen, icache_line_bytes_log=self.line_size, fetch_block_bytes_log=self.fetch_block
@@ -130,22 +130,22 @@ def refiller_process(self):
130130

131131
cur_addr = req_addr + i * self.cp.fetch_block_bytes
132132

133-
self.assertEqual(ret["addr"], cur_addr)
133+
assert ret["addr"] == cur_addr
134134

135135
if cur_addr in self.bad_fetch_blocks:
136-
self.assertEqual(ret["error"], 1)
137-
self.assertEqual(ret["last"], 1)
136+
assert ret["error"] == 1
137+
assert ret["last"] == 1
138138
break
139139

140140
fetch_block = ret["fetch_block"]
141141
for j in range(self.cp.words_in_fetch_block):
142142
word = (fetch_block >> (j * self.cp.word_width)) & (2**self.cp.word_width - 1)
143-
self.assertEqual(word, self.mem[cur_addr + j * self.cp.word_width_bytes])
143+
assert word == self.mem[cur_addr + j * self.cp.word_width_bytes]
144144

145-
self.assertEqual(ret["error"], 0)
145+
assert ret["error"] == 0
146146

147147
last = 1 if i == self.cp.fetch_blocks_in_line - 1 else 0
148-
self.assertEqual(ret["last"], last)
148+
assert ret["last"] == last
149149

150150
def test(self):
151151
with self.run_simulation(self.test_module) as sim:
@@ -190,7 +190,7 @@ class TestICacheBypass(TestCaseWithSimulator):
190190
isa_xlen: str
191191
fetch_block: int
192192

193-
def setUp(self) -> None:
193+
def setup_method(self) -> None:
194194
self.gen_params = GenParams(
195195
test_core_config.replace(xlen=self.isa_xlen, fetch_block_bytes_log=self.fetch_block, icache_enable=False)
196196
)
@@ -253,14 +253,14 @@ def user_process(self):
253253
ret = yield from self.m.accept_res.call()
254254

255255
if (req_addr & ~(self.cp.word_width_bytes - 1)) in self.bad_addrs:
256-
self.assertTrue(ret["error"])
256+
assert ret["error"]
257257
else:
258-
self.assertFalse(ret["error"])
258+
assert not ret["error"]
259259

260260
data = self.mem[req_addr]
261261
if self.gen_params.isa.xlen == 64:
262262
data |= self.mem[req_addr + 4] << 32
263-
self.assertEqual(ret["fetch_block"], data)
263+
assert ret["fetch_block"] == data
264264

265265
while random.random() < 0.5:
266266
yield
@@ -321,7 +321,7 @@ class TestICache(TestCaseWithSimulator):
321321
line_size: int
322322
fetch_block: int
323323

324-
def setUp(self) -> None:
324+
def setup_method(self) -> None:
325325
random.seed(42)
326326

327327
self.mem = dict()
@@ -405,17 +405,17 @@ def assert_resp(self, resp: RecordIntDictRet):
405405
addr = self.issued_requests.popleft() & ~(self.cp.fetch_block_bytes - 1)
406406

407407
if (addr & ~((1 << self.cp.offset_bits) - 1)) in self.bad_cache_lines:
408-
self.assertTrue(resp["error"])
408+
assert resp["error"]
409409
else:
410-
self.assertFalse(resp["error"])
410+
assert not resp["error"]
411411
fetch_block = 0
412412
for i in range(0, self.cp.fetch_block_bytes, 4):
413413
fetch_block |= self.mem[addr + i] << (8 * i)
414414

415-
self.assertEqual(resp["fetch_block"], fetch_block)
415+
assert resp["fetch_block"] == fetch_block
416416

417417
def expect_refill(self, addr: int):
418-
self.assertEqual(self.refill_requests.popleft(), addr)
418+
assert self.refill_requests.popleft() == addr
419419

420420
def call_cache(self, addr: int):
421421
yield from self.send_req(addr)
@@ -435,7 +435,7 @@ def cache_user_process():
435435
# Accesses to the same cache line shouldn't cause a cache miss
436436
for i in range(self.cp.fetch_blocks_in_line):
437437
yield from self.call_cache(0x00010000 + i * self.cp.fetch_block_bytes)
438-
self.assertEqual(len(self.refill_requests), 0)
438+
assert len(self.refill_requests) == 0
439439

440440
# Now go beyond the first cache line
441441
yield from self.call_cache(0x00010000 + self.cp.line_size_bytes)
@@ -456,7 +456,7 @@ def cache_user_process():
456456
# Now do some accesses within the cached memory
457457
for i in range(50):
458458
yield from self.call_cache(random.randrange(0, self.cp.line_size_bytes * self.cp.num_of_sets, 4))
459-
self.assertEqual(len(self.refill_requests), 0)
459+
assert len(self.refill_requests) == 0
460460

461461
with self.run_simulation(self.m) as sim:
462462
sim.add_sync_process(cache_user_process)
@@ -474,7 +474,7 @@ def cache_process():
474474
# And now both lines should be in the cache
475475
yield from self.call_cache(0x00010004)
476476
yield from self.call_cache(0x00020004)
477-
self.assertEqual(len(self.refill_requests), 0)
477+
assert len(self.refill_requests) == 0
478478

479479
with self.run_simulation(self.m) as sim:
480480
sim.add_sync_process(cache_process)
@@ -501,7 +501,7 @@ def cache_process():
501501
# Send the request
502502
yield from self.m.issue_req.call_init(addr=addr)
503503
yield Settle()
504-
self.assertTrue((yield from self.m.issue_req.done()))
504+
assert (yield from self.m.issue_req.done())
505505

506506
# After a cycle the response should be ready
507507
yield
@@ -592,7 +592,7 @@ def cache_process():
592592
addr = w * 0x00010000 + s * self.cp.line_size_bytes
593593
yield from self.call_cache(addr)
594594

595-
self.assertEqual(len(self.refill_requests), 0)
595+
assert len(self.refill_requests) == 0
596596

597597
yield from self.m.flush_cache.call()
598598

@@ -620,8 +620,8 @@ def cache_process():
620620
self.issued_requests.append(0x00010000)
621621
yield from self.m.flush_cache.call_init()
622622
yield Settle()
623-
self.assertFalse((yield from self.m.issue_req.done()))
624-
self.assertTrue((yield from self.m.flush_cache.done()))
623+
assert not (yield from self.m.issue_req.done())
624+
assert (yield from self.m.flush_cache.done())
625625
yield
626626
yield from self.m.flush_cache.call_do()
627627
yield from self.m.issue_req.call_do()
@@ -637,7 +637,7 @@ def cache_process():
637637
yield from self.m.flush_cache.call_init()
638638
yield
639639
# We cannot flush until there are two pending requests
640-
self.assertFalse((yield from self.m.flush_cache.done()))
640+
assert not (yield from self.m.flush_cache.done())
641641
yield
642642
yield from self.m.flush_cache.disable()
643643
yield

test/frontend/test_decode_stage.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
from transactron.lib import AdapterTrans, FIFO
23

34
from transactron.testing import TestCaseWithSimulator, TestbenchIO, SimpleTestCircuit, ModuleConnector
@@ -10,7 +11,8 @@
1011

1112

1213
class TestDecode(TestCaseWithSimulator):
13-
def setUp(self) -> None:
14+
@pytest.fixture(autouse=True)
15+
def setup(self, configure_dependency_context):
1416
self.gen_params = GenParams(test_core_config.replace(start_pc=24))
1517

1618
fifo_in = FIFO(self.gen_params.get(FetchLayouts).raw_instr, depth=2)
@@ -35,45 +37,45 @@ def decode_test_proc(self):
3537
yield from self.fifo_in_write.call(instr=0x02A28213)
3638
decoded = yield from self.fifo_out_read.call()
3739

38-
self.assertEqual(decoded["exec_fn"]["op_type"], OpType.ARITHMETIC)
39-
self.assertEqual(decoded["exec_fn"]["funct3"], Funct3.ADD)
40-
self.assertEqual(decoded["exec_fn"]["funct7"], 0)
41-
self.assertEqual(decoded["regs_l"]["rl_dst"], 4)
42-
self.assertEqual(decoded["regs_l"]["rl_s1"], 5)
43-
self.assertEqual(decoded["regs_l"]["rl_s2"], 0)
44-
self.assertEqual(decoded["imm"], 42)
40+
assert decoded["exec_fn"]["op_type"] == OpType.ARITHMETIC
41+
assert decoded["exec_fn"]["funct3"] == Funct3.ADD
42+
assert decoded["exec_fn"]["funct7"] == 0
43+
assert decoded["regs_l"]["rl_dst"] == 4
44+
assert decoded["regs_l"]["rl_s1"] == 5
45+
assert decoded["regs_l"]["rl_s2"] == 0
46+
assert decoded["imm"] == 42
4547

4648
# testing an OP instruction (test copied from test_decoder.py)
4749
yield from self.fifo_in_write.call(instr=0x003100B3)
4850
decoded = yield from self.fifo_out_read.call()
4951

50-
self.assertEqual(decoded["exec_fn"]["op_type"], OpType.ARITHMETIC)
51-
self.assertEqual(decoded["exec_fn"]["funct3"], Funct3.ADD)
52-
self.assertEqual(decoded["exec_fn"]["funct7"], Funct7.ADD)
53-
self.assertEqual(decoded["regs_l"]["rl_dst"], 1)
54-
self.assertEqual(decoded["regs_l"]["rl_s1"], 2)
55-
self.assertEqual(decoded["regs_l"]["rl_s2"], 3)
52+
assert decoded["exec_fn"]["op_type"] == OpType.ARITHMETIC
53+
assert decoded["exec_fn"]["funct3"] == Funct3.ADD
54+
assert decoded["exec_fn"]["funct7"] == Funct7.ADD
55+
assert decoded["regs_l"]["rl_dst"] == 1
56+
assert decoded["regs_l"]["rl_s1"] == 2
57+
assert decoded["regs_l"]["rl_s2"] == 3
5658

5759
# testing an illegal
5860
yield from self.fifo_in_write.call(instr=0x0)
5961
decoded = yield from self.fifo_out_read.call()
6062

61-
self.assertEqual(decoded["exec_fn"]["op_type"], OpType.EXCEPTION)
62-
self.assertEqual(decoded["exec_fn"]["funct3"], Funct3._EILLEGALINSTR)
63-
self.assertEqual(decoded["exec_fn"]["funct7"], 0)
64-
self.assertEqual(decoded["regs_l"]["rl_dst"], 0)
65-
self.assertEqual(decoded["regs_l"]["rl_s1"], 0)
66-
self.assertEqual(decoded["regs_l"]["rl_s2"], 0)
63+
assert decoded["exec_fn"]["op_type"] == OpType.EXCEPTION
64+
assert decoded["exec_fn"]["funct3"] == Funct3._EILLEGALINSTR
65+
assert decoded["exec_fn"]["funct7"] == 0
66+
assert decoded["regs_l"]["rl_dst"] == 0
67+
assert decoded["regs_l"]["rl_s1"] == 0
68+
assert decoded["regs_l"]["rl_s2"] == 0
6769

6870
yield from self.fifo_in_write.call(instr=0x0, access_fault=1)
6971
decoded = yield from self.fifo_out_read.call()
7072

71-
self.assertEqual(decoded["exec_fn"]["op_type"], OpType.EXCEPTION)
72-
self.assertEqual(decoded["exec_fn"]["funct3"], Funct3._EINSTRACCESSFAULT)
73-
self.assertEqual(decoded["exec_fn"]["funct7"], 0)
74-
self.assertEqual(decoded["regs_l"]["rl_dst"], 0)
75-
self.assertEqual(decoded["regs_l"]["rl_s1"], 0)
76-
self.assertEqual(decoded["regs_l"]["rl_s2"], 0)
73+
assert decoded["exec_fn"]["op_type"] == OpType.EXCEPTION
74+
assert decoded["exec_fn"]["funct3"] == Funct3._EINSTRACCESSFAULT
75+
assert decoded["exec_fn"]["funct7"] == 0
76+
assert decoded["regs_l"]["rl_dst"] == 0
77+
assert decoded["regs_l"]["rl_s1"] == 0
78+
assert decoded["regs_l"]["rl_s2"] == 0
7779

7880
def test(self):
7981
with self.run_simulation(self.m) as sim:

test/frontend/test_fetch.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
from collections import deque
23

34
import random
@@ -37,7 +38,7 @@ def elaborate(self, platform):
3738

3839

3940
class TestFetch(TestCaseWithSimulator):
40-
def setUp(self) -> None:
41+
def setup_method(self) -> None:
4142
self.gen_params = GenParams(test_core_config.replace(start_pc=0x18))
4243

4344
self.icache = MockedICache(self.gen_params)
@@ -125,8 +126,8 @@ def fetch_out_check(self):
125126
yield
126127

127128
instr = self.instr_queue.popleft()
128-
self.assertEqual(v["pc"], instr["pc"])
129-
self.assertEqual(v["instr"], instr["instr"])
129+
assert v["pc"] == instr["pc"]
130+
assert v["instr"] == instr["instr"]
130131

131132
if instr["is_branch"]:
132133
# branches on mispredict will stall fetch because of exception and then resume with new pc
@@ -145,7 +146,8 @@ def test(self):
145146

146147

147148
class TestUnalignedFetch(TestCaseWithSimulator):
148-
def setUp(self) -> None:
149+
@pytest.fixture(autouse=True)
150+
def setup(self, configure_dependency_context):
149151
self.gen_params = GenParams(test_core_config.replace(start_pc=0x18, compressed=True))
150152
self.instr_queue = deque()
151153
self.instructions = 500
@@ -256,8 +258,8 @@ def fetch_out_check(self):
256258
v = yield from self.io_out.call()
257259
discard_mispredict = False
258260

259-
self.assertEqual(v["pc"], instr["pc"])
260-
self.assertEqual(v["access_fault"], instr_error)
261+
assert v["pc"] == instr["pc"]
262+
assert v["access_fault"] == instr_error
261263

262264
if instr["is_branch"] or instr_error:
263265
yield from self.random_wait(5)

test/frontend/test_instr_decoder.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def __init__(
171171
),
172172
]
173173

174-
def setUp(self):
174+
def setup_method(self):
175175
self.gen_params = GenParams(
176176
test_core_config.replace(
177177
_implied_extensions=Extension.G | Extension.XINTMACHINEMODE | Extension.XINTSUPERVISOR | Extension.ZBB
@@ -186,52 +186,52 @@ def process():
186186
yield self.decoder.instr.eq(test.encoding)
187187
yield Settle()
188188

189-
self.assertEqual((yield self.decoder.illegal), test.illegal)
189+
assert (yield self.decoder.illegal) == test.illegal
190190
if test.illegal:
191191
return
192192

193-
self.assertEqual((yield self.decoder.opcode), test.opcode)
193+
assert (yield self.decoder.opcode) == test.opcode
194194

195195
if test.funct3 is not None:
196-
self.assertEqual((yield self.decoder.funct3), test.funct3)
197-
self.assertEqual((yield self.decoder.funct3_v), test.funct3 is not None)
196+
assert (yield self.decoder.funct3) == test.funct3
197+
assert (yield self.decoder.funct3_v) == (test.funct3 is not None)
198198

199199
if test.funct7 is not None:
200-
self.assertEqual((yield self.decoder.funct7), test.funct7)
201-
self.assertEqual((yield self.decoder.funct7_v), test.funct7 is not None)
200+
assert (yield self.decoder.funct7) == test.funct7
201+
assert (yield self.decoder.funct7_v) == (test.funct7 is not None)
202202

203203
if test.funct12 is not None:
204-
self.assertEqual((yield self.decoder.funct12), test.funct12)
205-
self.assertEqual((yield self.decoder.funct12_v), test.funct12 is not None)
204+
assert (yield self.decoder.funct12) == test.funct12
205+
assert (yield self.decoder.funct12_v) == (test.funct12 is not None)
206206

207207
if test.rd is not None:
208-
self.assertEqual((yield self.decoder.rd), test.rd)
209-
self.assertEqual((yield self.decoder.rd_v), test.rd is not None)
208+
assert (yield self.decoder.rd) == test.rd
209+
assert (yield self.decoder.rd_v) == (test.rd is not None)
210210

211211
if test.rs1 is not None:
212-
self.assertEqual((yield self.decoder.rs1), test.rs1)
213-
self.assertEqual((yield self.decoder.rs1_v), test.rs1 is not None)
212+
assert (yield self.decoder.rs1) == test.rs1
213+
assert (yield self.decoder.rs1_v) == (test.rs1 is not None)
214214

215215
if test.rs2 is not None:
216-
self.assertEqual((yield self.decoder.rs2), test.rs2)
217-
self.assertEqual((yield self.decoder.rs2_v), test.rs2 is not None)
216+
assert (yield self.decoder.rs2) == test.rs2
217+
assert (yield self.decoder.rs2_v) == (test.rs2 is not None)
218218

219219
if test.imm is not None:
220-
self.assertEqual((yield self.decoder.imm.as_signed()), test.imm)
220+
assert (yield self.decoder.imm.as_signed()) == test.imm
221221

222222
if test.succ is not None:
223-
self.assertEqual((yield self.decoder.succ), test.succ)
223+
assert (yield self.decoder.succ) == test.succ
224224

225225
if test.pred is not None:
226-
self.assertEqual((yield self.decoder.pred), test.pred)
226+
assert (yield self.decoder.pred) == test.pred
227227

228228
if test.fm is not None:
229-
self.assertEqual((yield self.decoder.fm), test.fm)
229+
assert (yield self.decoder.fm) == test.fm
230230

231231
if test.csr is not None:
232-
self.assertEqual((yield self.decoder.csr), test.csr)
232+
assert (yield self.decoder.csr) == test.csr
233233

234-
self.assertEqual((yield self.decoder.optype), test.op)
234+
assert (yield self.decoder.optype) == test.op
235235

236236
with self.run_simulation(self.decoder) as sim:
237237
sim.add_process(process)
@@ -280,7 +280,7 @@ def process():
280280
for encoding, illegal in self.E_TEST:
281281
yield self.decoder.instr.eq(encoding)
282282
yield Settle()
283-
self.assertEqual((yield self.decoder.illegal), illegal)
283+
assert (yield self.decoder.illegal) == illegal
284284

285285
with self.run_simulation(self.decoder) as sim:
286286
sim.add_process(process)
@@ -329,7 +329,7 @@ def code_prefixes(code: code_type) -> list[code_type]:
329329
encoding = known_codes[prefix]
330330

331331
# prefix of instruction can not be equal to code of any other isntruction
332-
self.assertIsNone(encoding, f"Instruction is not unique: I1 = {encoding} I2 = {instruction}")
332+
assert encoding is None, f"Instruction is not unique: I1 = {encoding} I2 = {instruction}"
333333

334334
known_codes[prefix] = None
335335

@@ -398,4 +398,4 @@ def instruction_code(instr: Encoding) -> code_type:
398398

399399
for instruction in ext_collisions:
400400
code = instruction_code(instruction)
401-
self.assertIn(code, known_codes, f"Instruction is not colliding: OpType={ext} I={instruction}")
401+
assert code in known_codes, f"Instruction is not colliding: OpType={ext} I={instruction}"

0 commit comments

Comments
 (0)