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

Subversion Repositories sha3

[/] [sha3/] [trunk/] [low_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 [31:0] in;
26
    reg in_ready;
27
    reg is_last;
28
    reg [1: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; is_last = 0;
96
        byte_num = 3; /* should have no effect */
97
        for (i=0; i<8; i=i+1)
98
          begin
99
            in = 32'h12345678; #(`P);
100
            in = 32'h90ABCDEF; #(`P);
101
          end
102
        in = 32'h12345678; #(`P);
103
        in = 32'h90ABCDEF; is_last = 1; #(`P);
104
        in_ready = 0;
105
        is_last = 0;
106
        check({ {8{64'h1234567890ABCDEF}}, 64'h1234567890ABCD81 });
107
 
108
        // pad an (576-64) bit string
109
        reset = 1; #(`P); reset = 0;
110
        // don't wait any cycle
111
        in_ready = 1; is_last = 0;
112
        byte_num = 1; /* should have no effect */
113
        for (i=0; i<8; i=i+1)
114
          begin
115
            in = 32'h12345678; #(`P);
116
            in = 32'h90ABCDEF; #(`P);
117
          end
118
        is_last = 1;
119
        byte_num = 0;
120
        #(`P);
121
        in_ready = 0;
122
        is_last = 0;
123
        #(`P);
124
        check({ {8{64'h1234567890ABCDEF}}, 64'h0100000000000080 });
125
 
126
        // pad an (576*2-16) bit string
127
        reset = 1; #(`P); reset = 0;
128
        in_ready = 1;
129
        byte_num = 7; /* should have no effect */
130
        is_last = 0;
131
        for (i=0; i<9; i=i+1)
132
          begin
133
            in = 32'h12345678; #(`P);
134
            in = 32'h90ABCDEF; #(`P);
135
          end
136
        if (out_ready !== 1) error;
137
        check({9{64'h1234567890ABCDEF}});
138
        #(`P/2);
139
        if (buffer_full !== 1) error; // should not eat
140
        #(`P/2);
141
        in = 64'h999; // should not eat this
142
        #(`P/2);
143
        if (buffer_full !== 1) error; // should not eat
144
        #(`P/2);
145
        f_ack = 1; #(`P); f_ack = 0;
146
        if (out_ready !== 0) error;
147
        // feed next (576-16) bit
148
        for (i=0; i<8; i=i+1)
149
          begin
150
            in = 32'h12345678; #(`P);
151
            in = 32'h90ABCDEF; #(`P);
152
          end
153
        in = 32'h12345678; #(`P);
154
        byte_num = 2;
155
        is_last = 1;
156
        in = 32'h90ABCDEF; #(`P);
157
        if (out_ready !== 1) error;
158
        check({ {8{64'h1234567890ABCDEF}}, 64'h1234567890AB0180 });
159
        is_last = 0;
160
        // eat these bits
161
        f_ack = 1; #(`P); f_ack = 0;
162
        // should not provide any more bits, if user provides nothing
163
        in_ready = 0;
164
        is_last = 0;
165
        for (i=0; i<10; i=i+1)
166
          begin
167
            if (out_ready === 1) error;
168
            #(`P);
169
          end
170
        in_ready = 0;
171
 
172
        $display("Good!");
173
        $finish;
174
    end
175
 
176
    always #(`P/2) clk = ~ clk;
177
 
178
    task error;
179
        begin
180
              $display("E");
181
              $finish;
182
        end
183
    endtask
184
 
185
    task check;
186
        input [575:0] wish;
187
        begin
188
          if (out !== wish)
189
            begin
190
              $display("out:%h wish:%h", out, wish);
191
              error;
192
            end
193
        end
194
    endtask
195
endmodule
196
 
197
`undef P

powered by: WebSVN 2.1.0

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