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

Subversion Repositories sha3

[/] [sha3/] [trunk/] [high_throughput_core/] [testbench/] [test_padder.v] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 homer.hsin
/*
2
 * Copyright 2013, Homer Hsing <homer.hsing@gmail.com>
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
 
17
`timescale 1ns / 1ps
18
`define P 20
19
 
20
module test_padder;
21
 
22
    // Inputs
23
    reg clk;
24
    reg reset;
25
    reg [63:0] in;
26
    reg in_ready;
27
    reg is_last;
28
    reg [2:0] byte_num;
29
    reg f_ack;
30
 
31
    // Outputs
32
    wire buffer_full;
33
    wire [575:0] out;
34
    wire out_ready;
35
 
36
    // Var
37
    integer i;
38
 
39
    // Instantiate the Unit Under Test (UUT)
40
    padder uut (
41
        .clk(clk),
42
        .reset(reset),
43
        .in(in),
44
        .in_ready(in_ready),
45
        .is_last(is_last),
46
        .byte_num(byte_num),
47
        .buffer_full(buffer_full),
48
        .out(out),
49
        .out_ready(out_ready),
50
        .f_ack(f_ack)
51
    );
52
 
53
    initial begin
54
        // Initialize Inputs
55
        clk = 0;
56
        reset = 1;
57
        in = 0;
58
        in_ready = 0;
59
        is_last = 0;
60
        byte_num = 0;
61
        f_ack = 0;
62
 
63
        // Wait 100 ns for global reset to finish
64
        #100;
65
 
66
        // Add stimulus here
67
        @ (negedge clk);
68
 
69
        // pad an empty string, should not eat next input
70
        reset = 1; #(`P); reset = 0;
71
        #(7*`P); // wait some cycles
72
        if (buffer_full !== 0) error;
73
        in_ready = 1;
74
        is_last = 1;
75
        #(`P);
76
        in_ready = 1; // next input
77
        is_last = 1;
78
        #(`P);
79
        in_ready = 0;
80
        is_last = 0;
81
 
82
        while (out_ready !== 1)
83
            #(`P);
84
        check({8'h1, 560'h0, 8'h80});
85
        f_ack = 1; #(`P); f_ack = 0;
86
        for(i=0; i<5; i=i+1)
87
          begin
88
            #(`P);
89
            if (buffer_full !== 0) error; // should be 0
90
          end
91
 
92
        // pad an (576-8) bit string
93
        reset = 1; #(`P); reset = 0;
94
        #(4*`P); // wait some cycles
95
        in_ready = 1;
96
        byte_num = 7; /* should have no effect */
97
        is_last = 0;
98
        for (i=0; i<8; i=i+1)
99
          begin
100
            in = 64'h1234567890ABCDEF;
101
            #(`P);
102
          end
103
        is_last = 1;
104
        #(`P);
105
        in_ready = 0;
106
        is_last = 0;
107
        check({ {8{64'h1234567890ABCDEF}}, 64'h1234567890ABCD81 });
108
 
109
        // pad an (576-64) bit string
110
        reset = 1; #(`P); reset = 0;
111
        // don't wait any cycle
112
        in_ready = 1;
113
        byte_num = 7; /* should have no effect */
114
        is_last = 0;
115
        for (i=0; i<8; i=i+1)
116
          begin
117
            in = 64'h1234567890ABCDEF;
118
            #(`P);
119
          end
120
        is_last = 1;
121
        byte_num = 0;
122
        #(`P);
123
        in_ready = 0;
124
        is_last = 0;
125
        check({ {8{64'h1234567890ABCDEF}}, 64'h0100000000000080 });
126
 
127
        // pad an (576*2-16) bit string
128
        reset = 1; #(`P); reset = 0;
129
        in_ready = 1;
130
        byte_num = 7; /* should have no effect */
131
        is_last = 0;
132
        for (i=0; i<9; i=i+1)
133
          begin
134
            in = 64'h1234567890ABCDEF;
135
            #(`P);
136
          end
137
        if (out_ready !== 1) error;
138
        check({9{64'h1234567890ABCDEF}});
139
        #(`P/2);
140
        if (buffer_full !== 1) error; // should not eat
141
        #(`P/2);
142
        in = 64'h999; // should not eat this
143
        #(`P/2);
144
        if (buffer_full !== 1) error; // should not eat
145
        #(`P/2);
146
        f_ack = 1; #(`P); f_ack = 0;
147
        if (out_ready !== 0) error;
148
        // feed next (576-16) bit
149
        for (i=0; i<8; i=i+1)
150
          begin
151
            in = 64'h1234567890ABCDEF; #(`P);
152
          end
153
        byte_num = 6;
154
        is_last = 1;
155
        in = 64'h1234567890ABCDEF; #(`P);
156
        if (out_ready !== 1) error;
157
        check({ {8{64'h1234567890ABCDEF}}, 64'h1234567890AB0180 });
158
        is_last = 0;
159
        // eat these bits
160
        f_ack = 1; #(`P); f_ack = 0;
161
        // should not provide any more bits, if user provides nothing
162
        in_ready = 0;
163
        is_last = 0;
164
        for (i=0; i<10; i=i+1)
165
          begin
166
            if (out_ready === 1) error;
167
            #(`P);
168
          end
169
        in_ready = 0;
170
 
171
        $display("Good!");
172
        $finish;
173
    end
174
 
175
    always #(`P/2) clk = ~ clk;
176
 
177
    task error;
178
        begin
179
              $display("E");
180
              $finish;
181
        end
182
    endtask
183
 
184
    task check;
185
        input [575:0] wish;
186
        begin
187
          if (out !== wish)
188
            begin
189
              $display("out:%h wish:%h", out, wish);
190
              error;
191
            end
192
        end
193
    endtask
194
endmodule
195
 
196
`undef P

powered by: WebSVN 2.1.0

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