From 245ea26bc595881a552113f36c1be9955c7cd5ec Mon Sep 17 00:00:00 2001 From: Gabor Szita Date: Fri, 3 Jan 2025 02:00:03 +0100 Subject: [PATCH 1/5] Improve compilesim.py test coverage --- tests/test_compilesim.py | 57 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/tests/test_compilesim.py b/tests/test_compilesim.py index 68920e56..c9b4398b 100644 --- a/tests/test_compilesim.py +++ b/tests/test_compilesim.py @@ -132,6 +132,18 @@ def test_reg_to_reg_simulation(self): self.o2 <<= self.r2 self.check_trace(' o 00224466\no2 02244660\n') + def test_less_than_cmp_simulation(self): + left = self.r[0:-1] + right = pyrtl.Const(1, bitwidth=1) + self.r.next <<= left < right + self.check_trace('o 01010101\n') + + def test_equals_simulation(self): + left = self.r[0:-1] + right = pyrtl.Const(0, bitwidth=1) + self.r.next <<= left == right + self.check_trace('o 01010101\n') + class PrintTraceBase(unittest.TestCase): # 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): sim_trace_a.print_trace(output, compact=True) self.assertEqual(output.getvalue(), expected_output) - def test_function_RomBlock(self): + def romBlock_test_helper(self, bidwidth): def rom_data_function(add): return int((add + 5) / 2) pyrtl.reset_working_block() - self.bitwidth = 4 + self.bitwidth = bidwidth self.addrwidth = 4 self.output1 = pyrtl.Output(self.bitwidth, "o1") self.output2 = pyrtl.Output(self.bitwidth, "o2") @@ -931,13 +943,25 @@ def rom_data_function(add): ("o2", lambda x: rom_data_function(2 * x))), 6) self.compareIO(self.sim_trace, exp_out) - def test_function_RomBlock_with_optimization(self): + def test_function_RomBlock_bitwidth_4(self): + self.romBlock_test_helper(4) + + def test_function_RomBlock_bitwidth_12(self): + self.romBlock_test_helper(12) + + def test_function_RomBlock_bitwidth_32(self): + self.romBlock_test_helper(32) + + def test_function_RomBlock_bitwidth_64(self): + self.romBlock_test_helper(64) + + def romBlock_with_optimization_helper(self, bidwidth): def rom_data_function(add): return int((add + 5) / 2) pyrtl.reset_working_block() - self.bitwidth = 4 + self.bitwidth = bidwidth self.addrwidth = 4 self.output1 = pyrtl.Output(self.bitwidth, "o1") self.output2 = pyrtl.Output(self.bitwidth, "o2") @@ -966,6 +990,18 @@ def rom_data_function(add): ("o2", lambda x: rom_data_function(2 * x))), 6) self.compareIO(self.sim_trace, exp_out) + def test_function_RomBlock_with_optimization_bidwidth_4(self): + self.romBlock_with_optimization_helper(4) + + def test_function_RomBlock_with_optimization_bidwidth_12(self): + self.romBlock_with_optimization_helper(12) + + def test_function_RomBlock_with_optimization_bidwidth_32(self): + self.romBlock_with_optimization_helper(32) + + def test_function_RomBlock_with_optimization_bidwidth_64(self): + self.romBlock_with_optimization_helper(64) + def test_rom_out_of_range_error(self): rom_data_array = [15, 13, 11, 9, 7, 5, 3] rom1 = pyrtl.RomBlock(bitwidth=4, addrwidth=3, romdata=rom_data_array) @@ -977,6 +1013,19 @@ def test_rom_out_of_range_error(self): with self.assertRaises(pyrtl.PyrtlError) as ex: self.sim(tracer=sim_trace) + def test_rom_romblock_in_memory_value_map_error(self): + rom_data_array = [1, 2, 3, 4, 5, 6, 7, 8] + rom1 = pyrtl.RomBlock(bitwidth=4, addrwidth=3, romdata=rom_data_array) + rom_add = pyrtl.Input(3, "rom_in_2") + rom_out = pyrtl.Output(4, "rom_out_2") + rom_out <<= rom1[rom_add] + mem_val_map = {rom1: {0: 0, 1: 1, 2: 2, 3: 3}} + + sim_trace = pyrtl.SimulationTrace() + with self.assertRaises(pyrtl.PyrtlError) as error: + self.sim(tracer=sim_trace, memory_value_map=mem_val_map) + self.assertEqual(str(error.exception), "RomBlock in memory_value_map") + def test_rom_val_map(self): def rom_data_function(add): return int((add + 5) / 2) From 4c2c112099e10f227623dfdd50beab0529b5dcd2 Mon Sep 17 00:00:00 2001 From: Gabor Szita Date: Sat, 4 Jan 2025 13:53:06 +0100 Subject: [PATCH 2/5] Fix capitalization, bitwidth typo, and pycodestyle errors --- tests/test_compilesim.py | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/tests/test_compilesim.py b/tests/test_compilesim.py index c9b4398b..7407fcea 100644 --- a/tests/test_compilesim.py +++ b/tests/test_compilesim.py @@ -914,13 +914,13 @@ def compareIO(self, sim_trace_a, expected_output): sim_trace_a.print_trace(output, compact=True) self.assertEqual(output.getvalue(), expected_output) - def romBlock_test_helper(self, bidwidth): + def rom_block_test_helper(self, bitwidth): def rom_data_function(add): return int((add + 5) / 2) pyrtl.reset_working_block() - self.bitwidth = bidwidth + self.bitwidth = bitwidth self.addrwidth = 4 self.output1 = pyrtl.Output(self.bitwidth, "o1") self.output2 = pyrtl.Output(self.bitwidth, "o2") @@ -943,25 +943,25 @@ def rom_data_function(add): ("o2", lambda x: rom_data_function(2 * x))), 6) self.compareIO(self.sim_trace, exp_out) - def test_function_RomBlock_bitwidth_4(self): - self.romBlock_test_helper(4) - - def test_function_RomBlock_bitwidth_12(self): - self.romBlock_test_helper(12) - - def test_function_RomBlock_bitwidth_32(self): - self.romBlock_test_helper(32) + def test_function_rom_block_bitwidth_4(self): + self.rom_block_test_helper(4) - def test_function_RomBlock_bitwidth_64(self): - self.romBlock_test_helper(64) + def test_function_rom_block_bitwidth_12(self): + self.rom_block_test_helper(12) - def romBlock_with_optimization_helper(self, bidwidth): + def test_function_rom_block_bitwidth_32(self): + self.rom_block_test_helper(32) + + def test_function_rom_block_bitwidth_64(self): + self.rom_block_test_helper(64) + + def rom_block_with_optimization_helper(self, bitwidth): def rom_data_function(add): return int((add + 5) / 2) pyrtl.reset_working_block() - self.bitwidth = bidwidth + self.bitwidth = bitwidth self.addrwidth = 4 self.output1 = pyrtl.Output(self.bitwidth, "o1") self.output2 = pyrtl.Output(self.bitwidth, "o2") @@ -990,17 +990,17 @@ def rom_data_function(add): ("o2", lambda x: rom_data_function(2 * x))), 6) self.compareIO(self.sim_trace, exp_out) - def test_function_RomBlock_with_optimization_bidwidth_4(self): - self.romBlock_with_optimization_helper(4) + def test_function_rom_block_with_optimization_bidwidth_4(self): + self.rom_block_with_optimization_helper(4) - def test_function_RomBlock_with_optimization_bidwidth_12(self): - self.romBlock_with_optimization_helper(12) + def test_function_rom_block_with_optimization_bidwidth_12(self): + self.rom_block_with_optimization_helper(12) - def test_function_RomBlock_with_optimization_bidwidth_32(self): - self.romBlock_with_optimization_helper(32) + def test_function_rom_block_with_optimization_bidwidth_32(self): + self.rom_block_with_optimization_helper(32) - def test_function_RomBlock_with_optimization_bidwidth_64(self): - self.romBlock_with_optimization_helper(64) + def test_function_rom_block_with_optimization_bidwidth_64(self): + self.rom_block_with_optimization_helper(64) def test_rom_out_of_range_error(self): rom_data_array = [15, 13, 11, 9, 7, 5, 3] @@ -1013,7 +1013,7 @@ def test_rom_out_of_range_error(self): with self.assertRaises(pyrtl.PyrtlError) as ex: self.sim(tracer=sim_trace) - def test_rom_romblock_in_memory_value_map_error(self): + def test_rom_rom_block_in_memory_value_map_error(self): rom_data_array = [1, 2, 3, 4, 5, 6, 7, 8] rom1 = pyrtl.RomBlock(bitwidth=4, addrwidth=3, romdata=rom_data_array) rom_add = pyrtl.Input(3, "rom_in_2") From 71c1e5128c85daa78fae1a2bfa697d1511760773 Mon Sep 17 00:00:00 2001 From: Gabor Szita Date: Sat, 4 Jan 2025 14:16:30 +0100 Subject: [PATCH 3/5] Reduce addrwidth to 1 and fix the naming of Input and Ouput --- tests/test_compilesim.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_compilesim.py b/tests/test_compilesim.py index 7407fcea..0ad9651e 100644 --- a/tests/test_compilesim.py +++ b/tests/test_compilesim.py @@ -1014,12 +1014,12 @@ def test_rom_out_of_range_error(self): self.sim(tracer=sim_trace) def test_rom_rom_block_in_memory_value_map_error(self): - rom_data_array = [1, 2, 3, 4, 5, 6, 7, 8] - rom1 = pyrtl.RomBlock(bitwidth=4, addrwidth=3, romdata=rom_data_array) - rom_add = pyrtl.Input(3, "rom_in_2") - rom_out = pyrtl.Output(4, "rom_out_2") - rom_out <<= rom1[rom_add] - mem_val_map = {rom1: {0: 0, 1: 1, 2: 2, 3: 3}} + rom_data_array = [6] + rom1 = pyrtl.RomBlock(bitwidth=4, addrwidth=1, romdata=rom_data_array) + rom_addr = pyrtl.Input(1, "rom_addr") + rom_out = pyrtl.Output(4, "rom_out") + rom_out <<= rom1[rom_addr] + mem_val_map = {rom1: {0: 0}} sim_trace = pyrtl.SimulationTrace() with self.assertRaises(pyrtl.PyrtlError) as error: From 9c2b4937aa7c70678724ada386b538a3deff9905 Mon Sep 17 00:00:00 2001 From: Gabor Szita Date: Sat, 4 Jan 2025 14:20:29 +0100 Subject: [PATCH 4/5] Only check if error message contains memory_value_map --- tests/test_compilesim.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_compilesim.py b/tests/test_compilesim.py index 0ad9651e..5084fff8 100644 --- a/tests/test_compilesim.py +++ b/tests/test_compilesim.py @@ -1024,7 +1024,7 @@ def test_rom_rom_block_in_memory_value_map_error(self): sim_trace = pyrtl.SimulationTrace() with self.assertRaises(pyrtl.PyrtlError) as error: self.sim(tracer=sim_trace, memory_value_map=mem_val_map) - self.assertEqual(str(error.exception), "RomBlock in memory_value_map") + self.assertIn("memory_value_map", str(error.exception)) def test_rom_val_map(self): def rom_data_function(add): From 5a0799d75e871e76fba57adeafc0448efa2d92c2 Mon Sep 17 00:00:00 2001 From: Gabor Szita Date: Wed, 8 Jan 2025 12:00:27 -0800 Subject: [PATCH 5/5] Fix more bitwidth typos --- tests/test_compilesim.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_compilesim.py b/tests/test_compilesim.py index 5084fff8..993d9d55 100644 --- a/tests/test_compilesim.py +++ b/tests/test_compilesim.py @@ -990,16 +990,16 @@ def rom_data_function(add): ("o2", lambda x: rom_data_function(2 * x))), 6) self.compareIO(self.sim_trace, exp_out) - def test_function_rom_block_with_optimization_bidwidth_4(self): + def test_function_rom_block_with_optimization_bitwidth_4(self): self.rom_block_with_optimization_helper(4) - def test_function_rom_block_with_optimization_bidwidth_12(self): + def test_function_rom_block_with_optimization_bitwidth_12(self): self.rom_block_with_optimization_helper(12) - def test_function_rom_block_with_optimization_bidwidth_32(self): + def test_function_rom_block_with_optimization_bitwidth_32(self): self.rom_block_with_optimization_helper(32) - def test_function_rom_block_with_optimization_bidwidth_64(self): + def test_function_rom_block_with_optimization_bitwidth_64(self): self.rom_block_with_optimization_helper(64) def test_rom_out_of_range_error(self):