diff --git a/fpgalib/test/test_dac.py b/fpgalib/test/test_dac.py index b4ead8d5..ba67b8af 100644 --- a/fpgalib/test/test_dac.py +++ b/fpgalib/test/test_dac.py @@ -37,59 +37,67 @@ def test_make_jump_table(self): self.dac.make_jump_table(entries) # we made it this far and we're feeling pretty good about it - def test_catch_bad_jump_table(self): - """Test jump table commands that are executed too frequently""" - - # from_addr of 16 followed by 20 are too close together - bad_jump_args = [ + def test_catch_nop_nop_too_close(self): + entries = self.make_entries([ ('NOP', [16]), ('NOP', [20]), ('END', [400]) - ] + ]) + with pytest.raises(ValueError): + self.dac.make_jump_table(entries) + + def test_catch_jump_iterated_nop_too_close(self): - # from addr of 16 is followed by from addr of 20 - bad_jump_args_2 = [ + entries = self.make_entries([ ('JUMP', [32, 16, 1]), ('NOP', [20]), ('END', [400]) - ] + ]) + with pytest.raises(ValueError): + self.dac.make_jump_table(entries) + + def test_catch_jump_back_too_close(self): + + entries = self.make_entries([ + ('NOP', [32]), + ('JUMP', [100, 28, 0]), + ('END', [400]) + ]) + with pytest.raises(ValueError): + self.dac.make_jump_table(entries) + + def test_catch_idle_end_too_close(self): # from addr of 32 is followed by from addr of 36 (even though IDLE?) - bad_jump_args_3 = [ + entries = self.make_entries([ ('IDLE', [32, 200]), ('END', [36]) - ] - - for args in [bad_jump_args, bad_jump_args_2, bad_jump_args_3]: - entries = self.make_entries(args) - with pytest.raises(ValueError): - self.dac.make_jump_table(entries) + ]) + with pytest.raises(ValueError): + self.dac.make_jump_table(entries) - def test_catch_bad_jump_table_edge(self): + def test_nop_nop_1_clk_too_close(self): """Test a table that executes commands 1 clock cycle too frequently""" from_addr = self.dac.JT_MIN_FROM_ADDR * 4 - bad_jump_args = [ + entries = self.make_entries([ ('NOP', [from_addr]), ('NOP', [from_addr + (self.dac.JT_MIN_CLK_CYCLES_BETWEEN_OPCODES - 1) * 4]), ('END', [400]) - ] + ]) - entries = self.make_entries(bad_jump_args) with pytest.raises(ValueError): - self.dac.make_jump_table(entries) + self.dac.make_jump_table(entries) + def test_nop_nop_min_clk_ok(self): from_addr = self.dac.JT_MIN_FROM_ADDR * 4 - bad_jump_args = [ + _ = self.make_entries([ ('NOP', [from_addr]), ('NOP', [from_addr + self.dac.JT_MIN_CLK_CYCLES_BETWEEN_OPCODES * 4]), ('END', [400]) - ] - - _ = self.make_entries(bad_jump_args) - + ]) if __name__ == '__main__': pytest.main(['-v', __file__])