Skip to content

Commit 7e58313

Browse files
authored
Improve compilesim.py test coverage (#458)
* Improve compilesim.py test coverage
1 parent 7dfa485 commit 7e58313

File tree

1 file changed

+53
-4
lines changed

1 file changed

+53
-4
lines changed

tests/test_compilesim.py

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ def test_reg_to_reg_simulation(self):
132132
self.o2 <<= self.r2
133133
self.check_trace(' o 00224466\no2 02244660\n')
134134

135+
def test_less_than_cmp_simulation(self):
136+
left = self.r[0:-1]
137+
right = pyrtl.Const(1, bitwidth=1)
138+
self.r.next <<= left < right
139+
self.check_trace('o 01010101\n')
140+
141+
def test_equals_simulation(self):
142+
left = self.r[0:-1]
143+
right = pyrtl.Const(0, bitwidth=1)
144+
self.r.next <<= left == right
145+
self.check_trace('o 01010101\n')
146+
135147

136148
class PrintTraceBase(unittest.TestCase):
137149
# note: doesn't include tests for compact=True because all the tests test that
@@ -902,13 +914,13 @@ def compareIO(self, sim_trace_a, expected_output):
902914
sim_trace_a.print_trace(output, compact=True)
903915
self.assertEqual(output.getvalue(), expected_output)
904916

905-
def test_function_RomBlock(self):
917+
def rom_block_test_helper(self, bitwidth):
906918

907919
def rom_data_function(add):
908920
return int((add + 5) / 2)
909921

910922
pyrtl.reset_working_block()
911-
self.bitwidth = 4
923+
self.bitwidth = bitwidth
912924
self.addrwidth = 4
913925
self.output1 = pyrtl.Output(self.bitwidth, "o1")
914926
self.output2 = pyrtl.Output(self.bitwidth, "o2")
@@ -931,13 +943,25 @@ def rom_data_function(add):
931943
("o2", lambda x: rom_data_function(2 * x))), 6)
932944
self.compareIO(self.sim_trace, exp_out)
933945

934-
def test_function_RomBlock_with_optimization(self):
946+
def test_function_rom_block_bitwidth_4(self):
947+
self.rom_block_test_helper(4)
948+
949+
def test_function_rom_block_bitwidth_12(self):
950+
self.rom_block_test_helper(12)
951+
952+
def test_function_rom_block_bitwidth_32(self):
953+
self.rom_block_test_helper(32)
954+
955+
def test_function_rom_block_bitwidth_64(self):
956+
self.rom_block_test_helper(64)
957+
958+
def rom_block_with_optimization_helper(self, bitwidth):
935959

936960
def rom_data_function(add):
937961
return int((add + 5) / 2)
938962

939963
pyrtl.reset_working_block()
940-
self.bitwidth = 4
964+
self.bitwidth = bitwidth
941965
self.addrwidth = 4
942966
self.output1 = pyrtl.Output(self.bitwidth, "o1")
943967
self.output2 = pyrtl.Output(self.bitwidth, "o2")
@@ -966,6 +990,18 @@ def rom_data_function(add):
966990
("o2", lambda x: rom_data_function(2 * x))), 6)
967991
self.compareIO(self.sim_trace, exp_out)
968992

993+
def test_function_rom_block_with_optimization_bitwidth_4(self):
994+
self.rom_block_with_optimization_helper(4)
995+
996+
def test_function_rom_block_with_optimization_bitwidth_12(self):
997+
self.rom_block_with_optimization_helper(12)
998+
999+
def test_function_rom_block_with_optimization_bitwidth_32(self):
1000+
self.rom_block_with_optimization_helper(32)
1001+
1002+
def test_function_rom_block_with_optimization_bitwidth_64(self):
1003+
self.rom_block_with_optimization_helper(64)
1004+
9691005
def test_rom_out_of_range_error(self):
9701006
rom_data_array = [15, 13, 11, 9, 7, 5, 3]
9711007
rom1 = pyrtl.RomBlock(bitwidth=4, addrwidth=3, romdata=rom_data_array)
@@ -977,6 +1013,19 @@ def test_rom_out_of_range_error(self):
9771013
with self.assertRaises(pyrtl.PyrtlError) as ex:
9781014
self.sim(tracer=sim_trace)
9791015

1016+
def test_rom_rom_block_in_memory_value_map_error(self):
1017+
rom_data_array = [6]
1018+
rom1 = pyrtl.RomBlock(bitwidth=4, addrwidth=1, romdata=rom_data_array)
1019+
rom_addr = pyrtl.Input(1, "rom_addr")
1020+
rom_out = pyrtl.Output(4, "rom_out")
1021+
rom_out <<= rom1[rom_addr]
1022+
mem_val_map = {rom1: {0: 0}}
1023+
1024+
sim_trace = pyrtl.SimulationTrace()
1025+
with self.assertRaises(pyrtl.PyrtlError) as error:
1026+
self.sim(tracer=sim_trace, memory_value_map=mem_val_map)
1027+
self.assertIn("memory_value_map", str(error.exception))
1028+
9801029
def test_rom_val_map(self):
9811030
def rom_data_function(add):
9821031
return int((add + 5) / 2)

0 commit comments

Comments
 (0)