How to manage large VHDL testbenches
testing, vhdl
Solution
Separating test bench code in manageable procedures is possible, but maybe the compiler complained because a procedure tries to access signals that were not in scope ? If a procedure is to controls a signal that is not in scope, then the signal can be given as argument to the procedure, as shown for the `procReset` example below.
A test bench structure, with multiple levels for easier maintenance, is shown below:
--==========================================================
-- Reusable procedures
-- Reset generation
procedure procReset(signal rst : out std_logic; ...) is
...
--==========================================================
-- Main test control procedure in test bench
process is
------------------------------------------------------------
-- General control and status
-- Reset device under test and related test bench modules
procedure genReset is
begin
procReset(rst, 100 ns); -- procReset declared elsewhere
-- Other code as required for complete reset
end procedure;
------------------------------------------------------------
-- Test cases
procedure testClockSignals is
begin
genReset; -- Apply reset to avoid test case interdependency
-- Test code here, and call genErr if mismatch detected
end procedure;
procedure testDigitialIO is
begin
genReset; -- Apply reset to avoid test case interdependency
-- Test code here, and call genErr if mismatch detected
end procedure;
procedure testDACSignals is
begin
genReset; -- Apply reset to avoid test case interdependency
-- Test code here, and call genErr if mismatch detected
end procedure;
begin
------------------------------------------------------------
-- Run test cases
testClockSignals;
testDigitialIO;
testDACSignals;
-- End of simulation
std.env.stop(0);
wait;
end process;
There are several levels in the structure:
Run test cases: Where the procedures for each test case is called. It is thereby possible to comment out one or more of the test cases during development and debugging.
Test cases: Test test case code itself, which is written as separate and independent procedures. Interdependence between run of the different test cases is avoided by reset (using `genReset` procedure) of the device under test and related test bench support modules.
General control and status: Reusable test bench specific procedure, for example reset of device under test and test bench support modules.
Reusable procedures: Does not control or use test bench signals directly, but only through procedure arguments. These procedures may be located in packages (other files) for reuse in other test benches.
The test bench file may still be quite a number of lines, since all the test case code still have to be in the same file with the above approach, if this test bench code need direct access to test bench signals in order to control or check the signals values. If signal values can be passed to test case procedures through arguments, as done for the `procReset` call, then it is possible to move the test case code to another package.
Problem
One problem I've seen again and again on different VHDL projects is that the top-level testbenches are always large and difficult to keep organized. There is basically a main test process where EVERY test signal is controlled or validated from, which becomes HUGE over time. I know that you can make testbenches for the lower-level components, but this question mainly applies to top-level input/output tests. I'd like to have some kind of hierarchy structure to keep things organized. I've tried implementing VHDL procedures, but the compiler was very unhappy because it thought I was trying to assign signals from different sections of code... Is there anything available in VHDL to achieve the behavior of c programming's inline-function or #define preprocessor replacement macros? If not, what can you suggest? It would make me happy to be able to have my top-level test bench look like this: ``` testClockSignals(); testDigitialIO(); testDACSignals(); ... ``` Having the implementation of these functions in a separate file would be icing on the cake. Haha...I'd just like to write and simulate the test benches in C.