OpenCores
URL https://opencores.org/ocsvn/btc_dsha256/btc_dsha256/trunk

Subversion Repositories btc_dsha256

[/] [btc_dsha256/] [trunk/] [rtl/] [vhdl/] [TestBench/] [sha_256_chunk_TB.vhd] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 nuxi1209
library hotan;
2
use hotan.sha_256_pkg.all;
3
library ieee;
4
use ieee.NUMERIC_STD.all;
5
use ieee.std_logic_1164.all;
6
use IEEE.std_logic_arith.all;
7
use IEEE.NUMERIC_STD.ALL;
8
 
9
        -- Add your library and packages declaration here ...
10
 
11
entity sha_256_chunk_tb is
12
end sha_256_chunk_tb;
13
 
14
architecture TB_ARCHITECTURE of sha_256_chunk_tb is
15
        -- Component declaration of the tested unit
16
        component sha_256_chunk
17
        generic(
18
                gMSG_IS_CONSTANT : std_logic_vector(0 to 15) := (others=>'1');
19
                gH_IS_CONST : std_logic_vector(0 to 7) := (others=>'1');
20
                gBASE_DELAY : integer := 3;
21
                gOUT_VALID_GEN : boolean := false;
22
                gUSE_BRAM_AS_LARGE_SHIFTREG : boolean := false
23
        );
24
        port(
25
                iClk : in STD_LOGIC;
26
                iRst_async : in STD_LOGIC;
27
                iValid : in STD_LOGIC;
28
                ivMsgDword : in tDwordArray(0 to 15);
29
                ivH0 : in STD_LOGIC_VECTOR(31 downto 0);
30
                ivH1 : in STD_LOGIC_VECTOR(31 downto 0);
31
                ivH2 : in STD_LOGIC_VECTOR(31 downto 0);
32
                ivH3 : in STD_LOGIC_VECTOR(31 downto 0);
33
                ivH4 : in STD_LOGIC_VECTOR(31 downto 0);
34
                ivH5 : in STD_LOGIC_VECTOR(31 downto 0);
35
                ivH6 : in STD_LOGIC_VECTOR(31 downto 0);
36
                ivH7 : in STD_LOGIC_VECTOR(31 downto 0);
37
                ovH0 : out STD_LOGIC_VECTOR(31 downto 0);
38
                ovH1 : out STD_LOGIC_VECTOR(31 downto 0);
39
                ovH2 : out STD_LOGIC_VECTOR(31 downto 0);
40
                ovH3 : out STD_LOGIC_VECTOR(31 downto 0);
41
                ovH4 : out STD_LOGIC_VECTOR(31 downto 0);
42
                ovH5 : out STD_LOGIC_VECTOR(31 downto 0);
43
                ovH6 : out STD_LOGIC_VECTOR(31 downto 0);
44
                ovH7 : out STD_LOGIC_VECTOR(31 downto 0);
45
                oValid : out std_logic);
46
        end component;
47
 
48
        -- Stimulus signals - signals mapped to the input and inout ports of tested entity
49
        signal iClk : STD_LOGIC := '1';
50
        signal iRst_async : STD_LOGIC := '1';
51
        signal iValid : STD_LOGIC := '0';
52
        signal ivMsgDword : tDwordArray(0 to 15) := (others=>(others=>'0'));
53
        signal ivH0 : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
54
        signal ivH1 : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
55
        signal ivH2 : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
56
        signal ivH3 : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
57
        signal ivH4 : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
58
        signal ivH5 : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
59
        signal ivH6 : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
60
        signal ivH7 : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
61
        signal oValid : std_logic;
62
 
63
        -- Observed signals - signals mapped to the output ports of tested entity
64
 
65
        -- Add your code here ...
66
 
67
        constant cTEST_NUM : integer := 3;
68
        type tTEST_MSG is array(0 to cTEST_NUM - 1) of tDwordArray(0 to 15);
69
        type tTEST_RESULT is array(0 to cTEST_NUM - 1) of tDwordArray(0 to 7);
70
        -- The test string length must <= 63
71
        constant cTEST_STR_00 : string := "";
72
        constant cTEST_STR_01 : string := "The quick brown fox jumps over the lazy dog";
73
        constant cTEST_STR_02 : string := "The quick brown fox jumps over the lazy dog.";
74
 
75
        constant cTEST_MSG : tTEST_MSG := (
76
                                                                                conv_str_to_msg(cTEST_STR_00),
77
                                                                                conv_str_to_msg(cTEST_STR_01),
78
                                                                                conv_str_to_msg(cTEST_STR_02)
79
                                                                                );
80
 
81
        constant cTEST_RESULT : tTEST_RESULT := (
82
                                                                                (X"e3b0c442", X"98fc1c14", X"9afbf4c8", X"996fb924", X"27ae41e4", X"649b934c", X"a495991b", X"7852b855"),
83
                                                                                (X"D7A8FBB3", X"07D78094", X"69CA9ABC", X"B0082E4F", X"8D5651E4", X"6D3CDB76", X"2D02D0BF", X"37C9E592"),
84
                                                                                (X"EF537F25", X"C895BFA7", X"82526529", X"A9B63D97", X"AA631564", X"D5D789C2", X"B765448C", X"8635FB6C")
85
                                                                                );
86
 
87
        constant cCLK_PERIOD : time := 10 ns;
88
        constant cRESET_INTERVAL : time := 71 ns;
89
        constant cSTRAT_TEST : integer := 19;
90
 
91
 
92
        signal ovH : tDwordArray(0 to 7) := (others=>(others=>'0'));
93
 
94
        signal siTestInCnt : integer := 0;
95
        signal siTestOutCnt : integer := 0;
96
 
97
        signal svResultMatch : std_logic_vector(0 to cTEST_NUM - 1) := (others=>'0');
98
 
99
begin
100
 
101
        -- Unit Under Test port map
102
        UUT : sha_256_chunk
103
                generic map(
104
                        gMSG_IS_CONSTANT => (others=>'0'),
105
                        gH_IS_CONST => (others=>'0'),
106
                        gBASE_DELAY => 1,
107
                        gOUT_VALID_GEN => true
108
                )
109
                port map (
110
                        iClk => iClk,
111
                        iRst_async => iRst_async,
112
                        iValid => iValid,
113
                        ivMsgDword => ivMsgDword,
114
                        ivH0 => ivH0,
115
                        ivH1 => ivH1,
116
                        ivH2 => ivH2,
117
                        ivH3 => ivH3,
118
                        ivH4 => ivH4,
119
                        ivH5 => ivH5,
120
                        ivH6 => ivH6,
121
                        ivH7 => ivH7,
122
                        ovH0 => ovH(0),
123
                        ovH1 => ovH(1),
124
                        ovH2 => ovH(2),
125
                        ovH3 => ovH(3),
126
                        ovH4 => ovH(4),
127
                        ovH5 => ovH(5),
128
                        ovH6 => ovH(6),
129
                        ovH7 => ovH(7),
130
                        oValid => oValid
131
                );
132
 
133
        -- Add your stimulus here ...
134
        iClk <= not iClk after (cCLK_PERIOD / 2);
135
        iRst_async <= '0' after cRESET_INTERVAL;
136
 
137
        iValid <= '1' after (cSTRAT_TEST * cCLK_PERIOD + 1 ns), '0' after ((cSTRAT_TEST * cCLK_PERIOD + 1 ns) + cTEST_NUM * cCLK_PERIOD);
138
        ivH0 <= X"6a09e667" after (cSTRAT_TEST * cCLK_PERIOD + 1 ns), (others=>'0') after ((cSTRAT_TEST * cCLK_PERIOD + 1 ns) + cTEST_NUM * cCLK_PERIOD);
139
        ivH1 <= X"bb67ae85" after (cSTRAT_TEST * cCLK_PERIOD + 1 ns), (others=>'0') after ((cSTRAT_TEST * cCLK_PERIOD + 1 ns) + cTEST_NUM * cCLK_PERIOD);
140
        ivH2 <= X"3c6ef372" after (cSTRAT_TEST * cCLK_PERIOD + 1 ns), (others=>'0') after ((cSTRAT_TEST * cCLK_PERIOD + 1 ns) + cTEST_NUM * cCLK_PERIOD);
141
        ivH3 <= X"a54ff53a" after (cSTRAT_TEST * cCLK_PERIOD + 1 ns), (others=>'0') after ((cSTRAT_TEST * cCLK_PERIOD + 1 ns) + cTEST_NUM * cCLK_PERIOD);
142
        ivH4 <= X"510e527f" after (cSTRAT_TEST * cCLK_PERIOD + 1 ns), (others=>'0') after ((cSTRAT_TEST * cCLK_PERIOD + 1 ns) + cTEST_NUM * cCLK_PERIOD);
143
        ivH5 <= X"9b05688c" after (cSTRAT_TEST * cCLK_PERIOD + 1 ns), (others=>'0') after ((cSTRAT_TEST * cCLK_PERIOD + 1 ns) + cTEST_NUM * cCLK_PERIOD);
144
        ivH6 <= X"1f83d9ab" after (cSTRAT_TEST * cCLK_PERIOD + 1 ns), (others=>'0') after ((cSTRAT_TEST * cCLK_PERIOD + 1 ns) + cTEST_NUM * cCLK_PERIOD);
145
        ivH7 <= X"5be0cd19" after (cSTRAT_TEST * cCLK_PERIOD + 1 ns), (others=>'0') after ((cSTRAT_TEST * cCLK_PERIOD + 1 ns) + cTEST_NUM * cCLK_PERIOD);
146
 
147
        process(iClk, iRst_async)
148
        begin
149
                if iRst_async = '1' then
150
                        siTestInCnt <= 0;
151
                        siTestOutCnt <= 0;
152
                        svResultMatch <= (others=>'0');
153
                elsif rising_edge(iClk) then
154
                        if iValid = '1' then
155
                                siTestInCnt <= siTestInCnt + 1 after 1 ns;
156
                        end if;
157
 
158
                        if oValid = '1' then
159
                                siTestOutCnt <= siTestOutCnt + 1;
160
                        end if;
161
 
162
                        if oValid = '1' then
163
                                for i in 0 to cTEST_NUM - 1 loop
164
                                        if i = siTestOutCnt then
165
                                                if ovH = cTEST_RESULT(i) then
166
                                                        svResultMatch(i) <= '1';
167
                                                else
168
                                                        svResultMatch(i) <= '0';
169
                                                end if;
170
                                        end if;
171
                                end loop;
172
                        end if;
173
                end if;
174
        end process;
175
 
176
        process(iValid, siTestInCnt)
177
        begin
178
                if iValid = '0' or siTestInCnt >= cTEST_NUM then
179
                        ivMsgDword <= (others=>(others=>'0'));
180
                else
181
                        ivMsgDword <= cTEST_MSG(siTestInCnt);
182
                end if;
183
        end process;
184
 
185
end TB_ARCHITECTURE;
186
 
187
configuration TESTBENCH_FOR_sha_256_chunk of sha_256_chunk_tb is
188
        for TB_ARCHITECTURE
189
                for UUT : sha_256_chunk
190
                        use entity work.sha_256_chunk(behavioral);
191
                end for;
192
        end for;
193
end TESTBENCH_FOR_sha_256_chunk;
194
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.