-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwinLogic_tb.sv
57 lines (50 loc) · 1.75 KB
/
winLogic_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
49
50
51
52
53
54
55
56
57
// Set delay unit to 1 ns and simulation precision to 0.1 ns (100 ps)
`timescale 1ns / 100ps
module winLogic_tb();
logic clk, reset;
logic [17:0]gBoard;
logic gameIsDone, gameIsDoneExp;
logic [1:0] winner, winnerExp;
logic [31:0] vectornum, errors;
logic [20:0] testvectors[1000:0];
// instantiate device under test
winLogic dut(.gBoard, .gameIsDone, .winner);
// generate clock
always
begin
clk=1; #5; clk=0; #5;
end
// at start of test, load test vectors
// and pulse reset
initial
begin
//$dumpfile("winLogic_tb.vcd"); // where to dump the results
//$dumpvars(1, clk, reset, gBoard, gameIsDone, winner);
$readmemb("winLogic.tv", testvectors);
vectornum=0; errors=0;
reset=1; #27; reset=0;
end
// apply test vectors on rising edge of clk
always @(posedge clk)
begin
#1; {gBoard, gameIsDoneExp, winnerExp} = testvectors[vectornum];
end
// check results on falling edge of clk
always @(negedge clk)
if(~reset) begin // skip during reset
//$display("Testing: gameIsDoneExp=%b , winnerExp=%b...", gameIsDoneExp, winnerExp);
if ((gameIsDone !== gameIsDoneExp)|(winner !== winnerExp)) begin // check result
$display("Error: on testvector number:%d, input=%b", vectornum, gBoard);
$display("output done: %b, (%b expected)", gameIsDone, gameIsDoneExp);
$display("output winner: %b, (%b expected)", winner, winnerExp);
errors = errors + 1;
end
vectornum = vectornum + 1;
//$display("testing we want %b, we see %b..", 21'bx, testvectors[vectornum]);
if(testvectors[vectornum] === 21'bx) begin
$display("%d tests completed with %d errors", vectornum, errors);
//$dumpflush;
$finish;
end
end
endmodule