How can I create a test bench file from main m.file?

1 view (last 30 days)
Hi,
How can I convert from main m.file to test bench file?
I need to implement with HDL coder and FPGA in the loop. I did construct an algorithm for a smith waterman sequencing.
Need assist.
Thanks

Answers (1)

Tim McBrayer
Tim McBrayer on 17 Dec 2013
A testbench is just MATLAB code that provides input stimulus to your design, and also reads and verifies the outputs. A good testbench should exercise your design with enough input data so that you are confident that your implementation is correct.
For example, assume your design is a new way to add 2 8-bit numbers. Your inputs A and B are 8-bit values, and you have a single 9-bit output. A poor testbench would make a single call to your function:
result = myAdd(int8(2), int8(3));
if result ~= 5
<report error>
end
A better testbench for this case, since the inputs are small, could run loops across both inputs and test each possible pair of inputs.
for aa = 0:255
for bb = 0:255
result = myAdd(int8(aa), int8(bb));
if result ~= aa + bb
<report error>
end
end
end
With a more complicated design you cannot do exhaustive testing like this in a reasonable time. You can design your testbench to test expected problem areas, extreme values, corner cases, use random data, etc. It's up to you on what to do.
The idea is to run your code in MATLAB and make sure that it performs as you expect it to. HDL Coder can use your testbench and verify that the HDL you generate behaves identically to the original MATLAB code in a 3rd party HDL simulator or even when implemented on a target FPGA board.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!