How can we write a test bench for a design in Vivado-HLS? Here, I am going to explain the structure of
a test bench in Vivado-HLS and how to use that to perform design simulation and debugging.
The C top-level function, called main(), is also the test bench top-function.
That means a testbench should start with the main() function.
The test bench functions won’t be synthesised. Therefore, it can call any types of function in C or
use any features in C language. It can accept a few arguments, and it should return an integer value.
While the name of the design top-function should be defined in the Vivado-HLS project settings, the name of
the test bench top-function is always main().
Any function under the design top function should be synthesisable.
The test bench should call the design top function along with its execution.
Self-checking is one of the test bench requirements. The test bench should check the design correctness
and report that through the main function return statement.
If the results are correct, the test bench should return the value of 0.
Otherwise, the test bench should return any non-zero values.
Let’s consider this simple design which transfers an 8-bit date from its input to its output without
any changes.
The test bench of this design consists of five stages:
1-The C main() function is the top function and should return an integer value.
2-Then the design inputs should be generated. As it receives an 8-bit input which can have
256 different cases. We use a for-loop to generate all the possible values for the input.
3- Then the test bench should call the design top-function, pass the input and receive the output.
4- The received output should be compared against the golden model (or known good results) which in this
case is very simple, and it is the original input value.
In the case of any discrepancy, a non-zero value should be written into the return variable, which
is status in this code.
5- Then a proper message can be written to the output to report the status of the design.
In addition, the function returns the success of the design verification by the return status.
You are responsible for ensuring that the test bench checks the results. If the test bench does not check
the results but returns zero, Vivado HLS indicates that the simulation test has been successful
even though the results were not actually checked. Even if the output data is correct and valid,
Vivado HLS reports a simulation failure if the test bench does not return the value
zero in function main().
The Vivado HLS GUI does not have a command console and cannot accept user inputs during the test bench execution.
So, using scanf C-function and similar functions are not allowed.
After getting familiar with the testbench concept and its coding style, we should explore its development
in the Vivado-HLS IDE.
The next lecture will cope with this challenge.
This is our takeaway message. A test bench top-function of a design consists of four main parts: Generating
the design inputs. Calling the design top-function using the generated inputs. Comparing the design
outputs with the golden model outputs. Returning the success of the design verification.
Now the quiz of this lecture. Write a testbench function for the following design.