开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

Testbenches


 

Is there any documentation / examples on how to write testbenches in BSV? I would like to have tests that run (maybe constrained) random inputs through my modules and then compares it to a reference model. In Verilog I would have a bunch of tasks that run in an initial block that fill up arrays with inputs and expected outputs, and then always blocks that feed the inputs into the module and retrieve outputs and compare them and then emit @PASS or @FAIL at the end. I could probably hack something together using StmtFSM but it seems like it would maybe be a little clumsy, and maybe there's a better way I'm not thinking of.
?
- Emily


 

There are various ways to write testbenches, and it probably depends on the kind of design or interface.? The BSC testsuite might be a source of examples -- sorry, I'm not sure which directories are good examples, offhand.? I have certainly written many testbenches like the Verilog you describe: a rule that provides input and then a rule that receives outputs and checks them, perhaps with a FIFO between them if the input rule needs to pass the expected output values etc.

I don't know that there's a good ecosystem of testbench features, yet, if that's what you're asking.? There is a Randomizable library, which has some simple constrained randomization -- it was written before the Generics feature was available (for querying the fields of a type) so probably a more sophisticated randomizer could be written now.? There is also "$random" and the LFSR library.

You can also import Verilog submodules to produce values (or to check values, or to implement assertions).? Or import C functions.? And in the worst case, you can write the entire testbench in Verilog or C/C++ and connect it to the BH/BSV design.

J


On Thu, Mar 6, 2025 at 10:11?AM Emily Schmidt via <aiju=[email protected]> wrote:
Is there any documentation / examples on how to write testbenches in BSV? I would like to have tests that run (maybe constrained) random inputs through my modules and then compares it to a reference model. In Verilog I would have a bunch of tasks that run in an initial block that fill up arrays with inputs and expected outputs, and then always blocks that feed the inputs into the module and retrieve outputs and compare them and then emit @PASS or @FAIL at the end. I could probably hack something together using StmtFSM but it seems like it would maybe be a little clumsy, and maybe there's a better way I'm not thinking of.
?
- Emily


 

I have written some helper modules for testbenches, depending on what you're doing they may also be helpful for you.
?
1) A "scoreboard" where you can put reference data as well as "dut" data. The module will then compare and can provide some stats at the end.
2) Randomizer modules for generating (input) data, similar to the Randomizable libary which Julie mentioned above. They have two advantages: You can use it with a "user-provided" seed, which allows to replicate specific test runs which failed earlier. And they work with enums and tagged unions (the Randomizable library can produce invalid values there, e.g. for enum with 3 values with bit represenation 00,01,10 it also generates 11; my implementation prevents this, however the distribution is not uniform in those cases).
?
You can find them here in our small library (or to be more precise my fork of it, as it is not yet merged):
?
I also have some documentation here:
?
Johannes


 

That's awesome, thank you.? I would love for the BSC repo to have a list of links to all the useful code that's out there -- perhaps a new section of the README under "Community" can be a list of libraries, projects, tools, etc.? We could include the TU Darmstadt repos?

Julie

On Tue, Mar 11, 2025 at 7:40?AM johannes-wirth via <johannes-wirth=[email protected]> wrote:
I have written some helper modules for testbenches, depending on what you're doing they may also be helpful for you.
?
1) A "scoreboard" where you can put reference data as well as "dut" data. The module will then compare and can provide some stats at the end.
2) Randomizer modules for generating (input) data, similar to the Randomizable libary which Julie mentioned above. They have two advantages: You can use it with a "user-provided" seed, which allows to replicate specific test runs which failed earlier. And they work with enums and tagged unions (the Randomizable library can produce invalid values there, e.g. for enum with 3 values with bit represenation 00,01,10 it also generates 11; my implementation prevents this, however the distribution is not uniform in those cases).
?
You can find them here in our small library (or to be more precise my fork of it, as it is not yet merged):
?
I also have some documentation here:
?
Johannes


 

I like that idea a lot. There are a few popular AXI/AHB repos that I think people would like to know about when they first start using Bluespec.

Michael

On Fri, Mar 14, 2025 at 5:11?PM Julie Schwartz via <quark=[email protected]> wrote:
That's awesome, thank you.? I would love for the BSC repo to have a list of links to all the useful code that's out there -- perhaps a new section of the README under "Community" can be a list of libraries, projects, tools, etc.? We could include the TU Darmstadt repos?

Julie

On Tue, Mar 11, 2025 at 7:40?AM johannes-wirth via <johannes-wirth=[email protected]> wrote:
I have written some helper modules for testbenches, depending on what you're doing they may also be helpful for you.
?
1) A "scoreboard" where you can put reference data as well as "dut" data. The module will then compare and can provide some stats at the end.
2) Randomizer modules for generating (input) data, similar to the Randomizable libary which Julie mentioned above. They have two advantages: You can use it with a "user-provided" seed, which allows to replicate specific test runs which failed earlier. And they work with enums and tagged unions (the Randomizable library can produce invalid values there, e.g. for enum with 3 values with bit represenation 00,01,10 it also generates 11; my implementation prevents this, however the distribution is not uniform in those cases).
?
You can find them here in our small library (or to be more precise my fork of it, as it is not yet merged):
?
I also have some documentation here:
?
Johannes


 

I also like the idea. Always found such lists really useful in other languages/frameworks.
?
Johannes