-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisSame_tb.sv
48 lines (42 loc) · 1.13 KB
/
isSame_tb.sv
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
// Set delay unit to 1 ns and simulation precision to 0.1 ns (100 ps)
`timescale 1ns / 100ps
module isSame_tb();
logic clk;
logic a,b,c;
logic y, yExpected;
logic [31:0] vectornum, errors;
logic [3:0] testvectors[1000:0];
// instantiate device under test
isSame dut(.a, .b, .c, .y);
// generate clock
always
begin
clk=1; #5; clk=0; #5;
end
// at start of test, load test vectors
// and pulse reset
initial
begin
$readmemb("isSame.tv", testvectors);
vectornum=0; errors=0;
end
// apply test vectors on rising edge of clk
always @(posedge clk)
begin
#1; {a, b, c, yExpected} = testvectors[vectornum];
end
// check results on falling edge of clk
always @(negedge clk) begin
if (y !== yExpected) begin // check result
$display("Error: inputs=%b", {a, b, c});
$display("outputs=%b (%b expected)", y, yExpected);
errors = errors + 1;
end
vectornum = vectornum + 1;
if(testvectors[vectornum] === 4'bx) begin
$display("%d tests completed with %d errors", vectornum, errors);
//$dumpflush;
$finish;
end
end
endmodule