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 3

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

Line No. Rev Author Line
1 3 nuxi1209
------------------------------------------------------------------- 
2
--                                                               --
3
--  Copyright (C) 2013 Author and VariStream Studio              --
4
--  Author : Yu Peng                                             --
5
--                                                               -- 
6
--  This source file may be used and distributed without         -- 
7
--  restriction provided that this copyright statement is not    -- 
8
--  removed from the file and that any derivative work contains  -- 
9
--  the original copyright notice and the associated disclaimer. -- 
10
--                                                               -- 
11
--  This source file is free software; you can redistribute it   -- 
12
--  and/or modify it under the terms of the GNU Lesser General   -- 
13
--  Public License as published by the Free Software Foundation; -- 
14
--  either version 2.1 of the License, or (at your option) any   -- 
15
--  later version.                                               -- 
16
--                                                               -- 
17
--  This source is distributed in the hope that it will be       -- 
18
--  useful, but WITHOUT ANY WARRANTY; without even the implied   -- 
19
--  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      -- 
20
--  PURPOSE.  See the GNU Lesser General Public License for more -- 
21
--  details.                                                     -- 
22
--                                                               -- 
23
--  You should have received a copy of the GNU Lesser General    -- 
24
--  Public License along with this source; if not, download it   -- 
25
--  from http://www.opencores.org/lgpl.shtml                     -- 
26
--                                                               -- 
27
-------------------------------------------------------------------
28
 
29 2 nuxi1209
library hotan;
30
use hotan.sha_256_pkg.all;
31
library ieee;
32
use ieee.NUMERIC_STD.all;
33
use ieee.std_logic_1164.all;
34
use IEEE.std_logic_arith.all;
35
use IEEE.NUMERIC_STD.ALL;
36
 
37
        -- Add your library and packages declaration here ...
38
 
39
entity sha_256_chunk_tb is
40
end sha_256_chunk_tb;
41
 
42
architecture TB_ARCHITECTURE of sha_256_chunk_tb is
43
        -- Component declaration of the tested unit
44
        component sha_256_chunk
45
        generic(
46
                gMSG_IS_CONSTANT : std_logic_vector(0 to 15) := (others=>'1');
47
                gH_IS_CONST : std_logic_vector(0 to 7) := (others=>'1');
48
                gBASE_DELAY : integer := 3;
49
                gOUT_VALID_GEN : boolean := false;
50
                gUSE_BRAM_AS_LARGE_SHIFTREG : boolean := false
51
        );
52
        port(
53
                iClk : in STD_LOGIC;
54
                iRst_async : in STD_LOGIC;
55
                iValid : in STD_LOGIC;
56
                ivMsgDword : in tDwordArray(0 to 15);
57
                ivH0 : in STD_LOGIC_VECTOR(31 downto 0);
58
                ivH1 : in STD_LOGIC_VECTOR(31 downto 0);
59
                ivH2 : in STD_LOGIC_VECTOR(31 downto 0);
60
                ivH3 : in STD_LOGIC_VECTOR(31 downto 0);
61
                ivH4 : in STD_LOGIC_VECTOR(31 downto 0);
62
                ivH5 : in STD_LOGIC_VECTOR(31 downto 0);
63
                ivH6 : in STD_LOGIC_VECTOR(31 downto 0);
64
                ivH7 : in STD_LOGIC_VECTOR(31 downto 0);
65
                ovH0 : out STD_LOGIC_VECTOR(31 downto 0);
66
                ovH1 : out STD_LOGIC_VECTOR(31 downto 0);
67
                ovH2 : out STD_LOGIC_VECTOR(31 downto 0);
68
                ovH3 : out STD_LOGIC_VECTOR(31 downto 0);
69
                ovH4 : out STD_LOGIC_VECTOR(31 downto 0);
70
                ovH5 : out STD_LOGIC_VECTOR(31 downto 0);
71
                ovH6 : out STD_LOGIC_VECTOR(31 downto 0);
72
                ovH7 : out STD_LOGIC_VECTOR(31 downto 0);
73
                oValid : out std_logic);
74
        end component;
75
 
76
        -- Stimulus signals - signals mapped to the input and inout ports of tested entity
77
        signal iClk : STD_LOGIC := '1';
78
        signal iRst_async : STD_LOGIC := '1';
79
        signal iValid : STD_LOGIC := '0';
80
        signal ivMsgDword : tDwordArray(0 to 15) := (others=>(others=>'0'));
81
        signal ivH0 : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
82
        signal ivH1 : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
83
        signal ivH2 : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
84
        signal ivH3 : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
85
        signal ivH4 : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
86
        signal ivH5 : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
87
        signal ivH6 : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
88
        signal ivH7 : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
89
        signal oValid : std_logic;
90
 
91
        -- Observed signals - signals mapped to the output ports of tested entity
92
 
93
        -- Add your code here ...
94
 
95
        constant cTEST_NUM : integer := 3;
96
        type tTEST_MSG is array(0 to cTEST_NUM - 1) of tDwordArray(0 to 15);
97
        type tTEST_RESULT is array(0 to cTEST_NUM - 1) of tDwordArray(0 to 7);
98
        -- The test string length must <= 63
99
        constant cTEST_STR_00 : string := "";
100
        constant cTEST_STR_01 : string := "The quick brown fox jumps over the lazy dog";
101
        constant cTEST_STR_02 : string := "The quick brown fox jumps over the lazy dog.";
102
 
103
        constant cTEST_MSG : tTEST_MSG := (
104
                                                                                conv_str_to_msg(cTEST_STR_00),
105
                                                                                conv_str_to_msg(cTEST_STR_01),
106
                                                                                conv_str_to_msg(cTEST_STR_02)
107
                                                                                );
108
 
109
        constant cTEST_RESULT : tTEST_RESULT := (
110
                                                                                (X"e3b0c442", X"98fc1c14", X"9afbf4c8", X"996fb924", X"27ae41e4", X"649b934c", X"a495991b", X"7852b855"),
111
                                                                                (X"D7A8FBB3", X"07D78094", X"69CA9ABC", X"B0082E4F", X"8D5651E4", X"6D3CDB76", X"2D02D0BF", X"37C9E592"),
112
                                                                                (X"EF537F25", X"C895BFA7", X"82526529", X"A9B63D97", X"AA631564", X"D5D789C2", X"B765448C", X"8635FB6C")
113
                                                                                );
114
 
115
        constant cCLK_PERIOD : time := 10 ns;
116
        constant cRESET_INTERVAL : time := 71 ns;
117
        constant cSTRAT_TEST : integer := 19;
118
 
119
 
120
        signal ovH : tDwordArray(0 to 7) := (others=>(others=>'0'));
121
 
122
        signal siTestInCnt : integer := 0;
123
        signal siTestOutCnt : integer := 0;
124
 
125
        signal svResultMatch : std_logic_vector(0 to cTEST_NUM - 1) := (others=>'0');
126
 
127
begin
128
 
129
        -- Unit Under Test port map
130
        UUT : sha_256_chunk
131
                generic map(
132
                        gMSG_IS_CONSTANT => (others=>'0'),
133
                        gH_IS_CONST => (others=>'0'),
134
                        gBASE_DELAY => 1,
135
                        gOUT_VALID_GEN => true
136
                )
137
                port map (
138
                        iClk => iClk,
139
                        iRst_async => iRst_async,
140
                        iValid => iValid,
141
                        ivMsgDword => ivMsgDword,
142
                        ivH0 => ivH0,
143
                        ivH1 => ivH1,
144
                        ivH2 => ivH2,
145
                        ivH3 => ivH3,
146
                        ivH4 => ivH4,
147
                        ivH5 => ivH5,
148
                        ivH6 => ivH6,
149
                        ivH7 => ivH7,
150
                        ovH0 => ovH(0),
151
                        ovH1 => ovH(1),
152
                        ovH2 => ovH(2),
153
                        ovH3 => ovH(3),
154
                        ovH4 => ovH(4),
155
                        ovH5 => ovH(5),
156
                        ovH6 => ovH(6),
157
                        ovH7 => ovH(7),
158
                        oValid => oValid
159
                );
160
 
161
        -- Add your stimulus here ...
162
        iClk <= not iClk after (cCLK_PERIOD / 2);
163
        iRst_async <= '0' after cRESET_INTERVAL;
164
 
165
        iValid <= '1' after (cSTRAT_TEST * cCLK_PERIOD + 1 ns), '0' after ((cSTRAT_TEST * cCLK_PERIOD + 1 ns) + cTEST_NUM * cCLK_PERIOD);
166
        ivH0 <= X"6a09e667" after (cSTRAT_TEST * cCLK_PERIOD + 1 ns), (others=>'0') after ((cSTRAT_TEST * cCLK_PERIOD + 1 ns) + cTEST_NUM * cCLK_PERIOD);
167
        ivH1 <= X"bb67ae85" after (cSTRAT_TEST * cCLK_PERIOD + 1 ns), (others=>'0') after ((cSTRAT_TEST * cCLK_PERIOD + 1 ns) + cTEST_NUM * cCLK_PERIOD);
168
        ivH2 <= X"3c6ef372" after (cSTRAT_TEST * cCLK_PERIOD + 1 ns), (others=>'0') after ((cSTRAT_TEST * cCLK_PERIOD + 1 ns) + cTEST_NUM * cCLK_PERIOD);
169
        ivH3 <= X"a54ff53a" after (cSTRAT_TEST * cCLK_PERIOD + 1 ns), (others=>'0') after ((cSTRAT_TEST * cCLK_PERIOD + 1 ns) + cTEST_NUM * cCLK_PERIOD);
170
        ivH4 <= X"510e527f" after (cSTRAT_TEST * cCLK_PERIOD + 1 ns), (others=>'0') after ((cSTRAT_TEST * cCLK_PERIOD + 1 ns) + cTEST_NUM * cCLK_PERIOD);
171
        ivH5 <= X"9b05688c" after (cSTRAT_TEST * cCLK_PERIOD + 1 ns), (others=>'0') after ((cSTRAT_TEST * cCLK_PERIOD + 1 ns) + cTEST_NUM * cCLK_PERIOD);
172
        ivH6 <= X"1f83d9ab" after (cSTRAT_TEST * cCLK_PERIOD + 1 ns), (others=>'0') after ((cSTRAT_TEST * cCLK_PERIOD + 1 ns) + cTEST_NUM * cCLK_PERIOD);
173
        ivH7 <= X"5be0cd19" after (cSTRAT_TEST * cCLK_PERIOD + 1 ns), (others=>'0') after ((cSTRAT_TEST * cCLK_PERIOD + 1 ns) + cTEST_NUM * cCLK_PERIOD);
174
 
175
        process(iClk, iRst_async)
176
        begin
177
                if iRst_async = '1' then
178
                        siTestInCnt <= 0;
179
                        siTestOutCnt <= 0;
180
                        svResultMatch <= (others=>'0');
181
                elsif rising_edge(iClk) then
182
                        if iValid = '1' then
183
                                siTestInCnt <= siTestInCnt + 1 after 1 ns;
184
                        end if;
185
 
186
                        if oValid = '1' then
187
                                siTestOutCnt <= siTestOutCnt + 1;
188
                        end if;
189
 
190
                        if oValid = '1' then
191
                                for i in 0 to cTEST_NUM - 1 loop
192
                                        if i = siTestOutCnt then
193
                                                if ovH = cTEST_RESULT(i) then
194
                                                        svResultMatch(i) <= '1';
195
                                                else
196
                                                        svResultMatch(i) <= '0';
197
                                                end if;
198 3 nuxi1209
 
199
                                                assert ovH = cTEST_RESULT(i)
200
                                                        report "The test " & integer'image(i) & " failed"
201
                                                        severity ERROR;
202 2 nuxi1209
                                        end if;
203
                                end loop;
204
                        end if;
205
                end if;
206
        end process;
207
 
208
        process(iValid, siTestInCnt)
209
        begin
210
                if iValid = '0' or siTestInCnt >= cTEST_NUM then
211
                        ivMsgDword <= (others=>(others=>'0'));
212
                else
213
                        ivMsgDword <= cTEST_MSG(siTestInCnt);
214
                end if;
215
        end process;
216 3 nuxi1209
 
217 2 nuxi1209
end TB_ARCHITECTURE;
218
 
219
configuration TESTBENCH_FOR_sha_256_chunk of sha_256_chunk_tb is
220
        for TB_ARCHITECTURE
221
                for UUT : sha_256_chunk
222
                        use entity work.sha_256_chunk(behavioral);
223
                end for;
224
        end for;
225
end TESTBENCH_FOR_sha_256_chunk;
226
 

powered by: WebSVN 2.1.0

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