Cleanup testbench, add messages to assertions
authorMichael Nolan <mtnolan2640@gmail.com>
Sat, 29 Feb 2020 20:27:05 +0000 (15:27 -0500)
committerMichael Nolan <mtnolan2640@gmail.com>
Sat, 29 Feb 2020 20:27:05 +0000 (15:27 -0500)
src/decoder/test/test_power_major_decoder.py

index 7ef62b13f48848dc40ca5a228eb7734b5a2e24e7..1d0d6b17bfbc25117fc87522cbc364c7ba72dd79 100644 (file)
@@ -43,43 +43,25 @@ class DecoderTestCase(FHDLTestCase):
             for row in major_opcodes:
                 yield opcode.eq(int(row['opcode']))
                 yield Delay(1e-6)
-                result = yield function_unit
-                expected = Function[row['unit']].value
-                self.assertEqual(expected, result)
-
-                result = yield internal_op
-                expected = InternalOp[row['internal op']].value
-                self.assertEqual(expected, result)
-
-                result = yield in1_sel
-                expected = In1Sel[row['in1']].value
-                self.assertEqual(expected, result)
-
-                result = yield in2_sel
-                expected = In2Sel[row['in2']].value
-                self.assertEqual(expected, result)
-
-                result = yield in3_sel
-                expected = In3Sel[row['in3']].value
-                self.assertEqual(expected, result)
-
-                result = yield out_sel
-                expected = OutSel[row['out']].value
-                self.assertEqual(expected, result)
-
-                result = yield rc_sel
-                expected = RC[row['rc']].value
-                self.assertEqual(expected, result)
-
-                result = yield ldst_len
-                expected = LdstLen[row['ldst len']].value
-                self.assertEqual(expected, result)
-
+                signals = [(function_unit, Function, 'unit'),
+                           (internal_op, InternalOp, 'internal op'),
+                           (in1_sel, In1Sel, 'in1'),
+                           (in2_sel, In2Sel, 'in2'),
+                           (in3_sel, In3Sel, 'in3'),
+                           (out_sel, OutSel, 'out'),
+                           (rc_sel, RC, 'rc'),
+                           (ldst_len, LdstLen, 'ldst len')]
+                for sig, enm, name in signals:
+                    result = yield sig
+                    expected = enm[row[name]]
+                    msg = f"{sig.name} == {enm(result)}, expected: {expected}"
+                    self.assertEqual(enm(result), expected, msg)
                 for bit in single_bit_flags:
                     sig = getattr(dut, get_signal_name(bit))
                     result = yield sig
                     expected = int(row[bit])
-                    self.assertEqual(expected, result)
+                    msg = f"{sig.name} == {result}, expected: {expected}"
+                    self.assertEqual(expected, result, msg)
         sim.add_process(process)
         with sim.write_vcd("test.vcd", "test.gtkw", traces=[
                 opcode, function_unit, internal_op,