-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcounter_unit_test.sv
78 lines (64 loc) · 1.72 KB
/
counter_unit_test.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
`include "svunit_defines.svh"
`include "counter.sv"
`include "sv_waveterm.sv"
module counter_unit_test;
import svunit_pkg::svunit_testcase;
string name = "counter_ut";
svunit_testcase svunit_ut;
logic clk = 0;
always #5 clk <= !clk;
logic reset_b;
logic [3:0] counter;
`sv_waveterm_begin(counter_waves, clk)
`sv_waveterm_int(reset_b)
`sv_waveterm_int(counter)
`sv_waveterm_end
//===================================
// This is the UUT that we're
// running the Unit Tests on
//===================================
counter my_counter(.*);
//===================================
// Build
//===================================
function void build();
svunit_ut = new(name);
endfunction
//===================================
// Setup for running the Unit Tests
//===================================
task setup();
svunit_ut.setup();
/* Place Setup Code Here */
reset_b = '0;
#17;
reset_b = '1;
endtask
//===================================
// Here we deconstruct anything we
// need after running the Unit Tests
//===================================
task teardown();
svunit_ut.teardown();
/* Place Teardown Code Here */
endtask
//===================================
// All tests are defined between the
// SVUNIT_TESTS_BEGIN/END macros
//
// Each individual test must be
// defined between `SVTEST(_NAME_)
// `SVTEST_END
//
// i.e.
// `SVTEST(mytest)
// <test code>
// `SVTEST_END
//===================================
`SVUNIT_TESTS_BEGIN
`SVTEST(not_5)
repeat (6) @(posedge clk);
`FAIL_IF_LOG(counter == 5, {"Unexpected 5 in counter:\n", counter_waves.sprint()})
`SVTEST_END
`SVUNIT_TESTS_END
endmodule