-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestbench.v
More file actions
59 lines (42 loc) · 1.1 KB
/
testbench.v
File metadata and controls
59 lines (42 loc) · 1.1 KB
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
`timescale 1ns / 1ps
module testbench();
// Inputs
reg [15:0] A, B;
reg Cin;
// Outputs
wire [15:0] Sum;
wire Cout;
// Variables for the self-verifying logic
reg [15:0] expected_sum;
reg expected_cout;
integer i;
integer error_count = 0;
localparam N = 1000000;
Sklanksy DUT(
.A(A),
.B(B),
.Cin(Cin),
.Sum(Sum),
.Cout(Cout)
);
initial begin
// Loop to run N random test cases
for (i = 0; i < N; i = i + 1) begin
A = $random;
B = $random;
Cin = $random % 2;
{expected_cout, expected_sum} = A + B + Cin;
#10;
if ({Cout, Sum} !== {expected_cout, expected_sum}) begin
error_count = error_count + 1;
end
end
#10;
if (error_count == 0) begin
$display("SUCCESS: All %0d random tests passed!", i);
end else begin
$display("FAILURE: %0d out of %0d tests failed.", error_count, i);
end
$finish;
end
endmodule