1
+ library vunit_lib;
2
+ context vunit_lib.vunit_context;
3
+
4
+ -- A testbench has no ports.
5
+ entity tb_adder is
6
+ generic (runner_cfg : string );
7
+ end tb_adder ;
8
+
9
+ architecture behav of tb_adder is
10
+ -- Declaration of the component that will be instantiated.
11
+ component adder
12
+ port (i0, i1 : in bit ; ci : in bit ; s : out bit ; co : out bit );
13
+ end component ;
14
+
15
+ -- Specifies which entity is bound with the component.
16
+ for adder_0: adder use entity work.adder;
17
+ signal i0, i1, ci, s, co : bit ;
18
+ begin
19
+ -- Component instantiation.
20
+ adder_0 : adder port map (i0 => i0, i1 => i1, ci => ci, s => s, co => co);
21
+
22
+ -- This process does the real job.
23
+ process
24
+ type pattern_type is record
25
+ -- The inputs of the adder.
26
+ i0, i1, ci : bit ;
27
+ -- The expected outputs of the adder.
28
+ s, co : bit ;
29
+ end record ;
30
+ -- The patterns to apply.
31
+ type pattern_array is array (natural range <> ) of pattern_type;
32
+ constant patterns : pattern_array :=
33
+ (('0' , '0' , '0' , '0' , '0' ),
34
+ ('0' , '0' , '1' , '1' , '0' ),
35
+ ('0' , '1' , '0' , '1' , '0' ),
36
+ ('0' , '1' , '1' , '0' , '1' ),
37
+ ('1' , '0' , '0' , '1' , '0' ),
38
+ ('1' , '0' , '1' , '0' , '1' ),
39
+ ('1' , '1' , '0' , '0' , '1' ),
40
+ ('1' , '1' , '1' , '1' , '1' ));
41
+ begin
42
+ test_runner_setup(runner, runner_cfg);
43
+ -- Check each pattern.
44
+ for i in patterns'range loop
45
+ -- Set the inputs.
46
+ i0 <= patterns(i).i0;
47
+ i1 <= patterns(i).i1;
48
+ ci <= patterns(i).ci;
49
+ -- Wait for the results.
50
+ wait for 1 ns ;
51
+ -- Check the outputs.
52
+ assert s = patterns(i).s
53
+ report " bad sum value" severity error ;
54
+ assert co = patterns(i).co
55
+ report " bad carry out value" severity error ;
56
+ end loop ;
57
+ assert false report " end of test" severity note ;
58
+ -- Wait forever; this will finish the simulation.
59
+ -- wait;
60
+ test_runner_cleanup(runner); -- Simulation ends here
61
+ end process ;
62
+
63
+ end behav ;
0 commit comments