Testbench#

The testbench helper functions and classes provide usability features when writing testbenches. If you want to learn how to test one of your component make sure to read the cocotb-wrapper User Guide guide.

Creating a testbench#

The Testbench class provides a convenient wrapper around the cocotb API to define tests. Inside a test we use standard cocotb. However, tests are not registered using the cocotb.test decorator, but rather by creating a Testbench instance and use the register_test() decorator method. This provides several advantages over the traditional approach.

Beside the register_test() decorator method, the Testbench class also provides the register_setup() and register_teardown() decorator methods, to register setup and teardown functions. The setup and teardown functions get executed before and after each test. Additionally, the Testbench automatically sets the integer signal test_id inside the DUT to an incrementing number. So each test has its own ID and can be identified when looking at the wave file.

Finally, the Testbench class provides the start_clock() and reset() methods to start the clock and reset the component. Those methods are usually called within a setup and teardown function.

testbench.Testbench(name[, clk, rst, ...])

A cocotb testbench.

testbench._Test(test_function[, test_id, ...])

A single test of a testbench.