aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/gna/issue1817/full_adder_tb.vhdl
blob: 0e49c4f1852523e675335c91cd78332365d418d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
-------------------------------------------------------------------------------
-- Title      : Full-Adder Test Bench
-- Project    :
-------------------------------------------------------------------------------
--! \file     full_adder_tb.vhd
--! \author   Jose Correcher <jose.correcher@gmail.com>
--! \date     Created    : 2021-07-02
--            Last update: 2021-07-02
-- Platform   :
-- Standard   : VHDL'08
-------------------------------------------------------------------------------
-- Description:
--! \class    full_adder
--! \details
--!            This is the test bench for full-adder design.
-------------------------------------------------------------------------------
-- Copyright (c) 2021
-------------------------------------------------------------------------------
-- Revisions  :
-- Date        Version  Author  Description
-- 2021-07-02  1.0      jcorrecher  Created
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
-- * libraries
-------------------------------------------------------------------------------

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

-------------------------------------------------------------------------------
-- * entity
-------------------------------------------------------------------------------

entity full_adder_tb is

end entity full_adder_tb;

-------------------------------------------------------------------------------
-- * architecture body
-------------------------------------------------------------------------------

architecture sim of full_adder_tb is

-- ** record declaration
  type rc_data is record
    a    : std_logic;
    b    : std_logic;
    cin  : std_logic;
    s    : std_logic;
    cout : std_logic;
  end record rc_data;

-- ** truth table declaration
  type fa_array is array (natural range <>) of rc_data;
  constant fa_table : fa_array :=
    (('0', '0', '0', '0', '0'),
     ('0', '0', '1', '1', '0'),
     ('0', '1', '0', '1', '0'),
     ('0', '1', '1', '0', '1'),
     ('1', '0', '0', '1', '0'),
     ('1', '0', '1', '0', '1'),
     ('1', '1', '0', '0', '1'),
     ('1', '1', '1', '1', '1'));

-- ** signal declaration
  signal a, b, cin, s, cout : std_logic;

begin

-------------------------------------------------------------------------------
-- * TB0 : Test
-------------------------------------------------------------------------------

  process
  begin
    --  Check each pattern.
    for i in fa_table'range loop
      --  Set the inputs.
      a   <= fa_table(i).a;
      b   <= fa_table(i).b;
      cin <= fa_table(i).cin;
      --  Wait for the results.
      wait for 1 ns;
      --  Check the outputs.
      assert s = fa_table(i).s
        report "bad sum value" severity error;
      assert cout = fa_table(i).cout
        report "bad carry out value" severity error;
    end loop;
    assert false report "end of test" severity note;
    std.env.stop;
    wait;
  end process;

-------------------------------------------------------------------------------
-- * TB1 : DUV + FM
-------------------------------------------------------------------------------

-- ** instance

  DUV : entity work.full_adder
    port map (
      a    => a,
      b    => b,
      cin  => cin,
      s    => s,
      cout => cout
      );

end architecture sim;