forked from sam-keamy/ece2300-sec02
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PairTripleDetector_test.v
114 lines (84 loc) · 2.85 KB
/
PairTripleDetector_test.v
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//========================================================================
// PairTripleDetector_test
//========================================================================
`include "ece2300-stdlib.v"
module Top();
//----------------------------------------------------------------------
// Setup
//----------------------------------------------------------------------
logic clk;
logic reset;
ece2300_TestUtils t( .* );
//----------------------------------------------------------------------
// Instantiate design under test
//----------------------------------------------------------------------
logic dut_in0;
logic dut_in1;
logic dut_in2;
logic dut_out;
PairTripleDetector dut
(
.in0 (dut_in0),
.in1 (dut_in1),
.in2 (dut_in2),
.out (dut_out)
);
//----------------------------------------------------------------------
// check
//----------------------------------------------------------------------
// All tasks start at #1 after the rising edge of the clock. So we
// write the inputs #1 after the rising edge, and check the outputs #1
// before the next rising edge.
task check
(
input logic in0,
input logic in1,
input logic in2,
input logic out
);
dut_in0 = in0;
dut_in1 = in1;
dut_in2 = in2;
#8;
if ( t.n != 0 )
$display( "%3d: %x %x %x > %x", t.cycles,
dut_in0, dut_in1, dut_in2, dut_out );
`ECE2300_CHECK_EQ( dut_out, out );
#2;
endtask
//----------------------------------------------------------------------
// test_case_1_basic
//----------------------------------------------------------------------
task test_case_1_basic();
$display( "\ntest_case_1_basic" );
t.reset_sequence();
check( 0, 0, 0, 0 );
check( 0, 1, 1, 1 );
check( 0, 1, 0, 0 );
check( 1, 1, 1, 1 );
endtask
//----------------------------------------------------------------------
// test_case_2_exhaustive
//----------------------------------------------------------------------
task test_case_2_exhaustive();
$display( "\ntest_case_2_exhaustive" );
t.reset_sequence();
// '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
// Discussion Section Task
// '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
// Add checks for exhaustive testing (i.e., check all possible
// inputs).
endtask
//----------------------------------------------------------------------
// main
//----------------------------------------------------------------------
// We start with a #1 delay so that all tasks will essentially start at
// #1 after the rising edge of the clock.
initial begin
#1;
if ((t.n <= 0) || (t.n == 1)) test_case_1_basic();
if ((t.n <= 0) || (t.n == 2)) test_case_2_exhaustive();
$display(t.pass_fail);
$finish;
end
endmodule