Skip to content

Commit 350f643

Browse files
committed
Change: Update source code to correct lint messages from Icarus Verilog
Change: Move to latest SVUT version
1 parent 281d1f1 commit 350f643

File tree

5 files changed

+331
-186
lines changed

5 files changed

+331
-186
lines changed

sim/test/async_fifo_unit_test.sv

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ module async_fifo_unit_test;
2323
wire rempty;
2424
wire arempty;
2525

26-
async_fifo
26+
async_fifo
2727
#(
2828
DSIZE,
2929
ASIZE
3030
)
31-
dut
31+
dut
3232
(
3333
wclk,
3434
wrst_n,
@@ -59,7 +59,7 @@ module async_fifo_unit_test;
5959
end
6060
`endif
6161

62-
task setup();
62+
task setup(msg="Setup testcase");
6363
begin
6464

6565
wrst_n = 1'b0;
@@ -70,34 +70,29 @@ module async_fifo_unit_test;
7070
#100;
7171
wrst_n = 1;
7272
rrst_n = 1;
73-
#200;
73+
#50;
7474
@(posedge wclk);
7575

7676
end
7777
endtask
7878

79-
task teardown();
79+
task teardown(msg="Tearing down");
8080
begin
81-
82-
#200;
83-
81+
#50;
8482
end
8583
endtask
8684

87-
`UNIT_TESTS
85+
`TEST_SUITE("ASYNCFIFO")
86+
87+
`UNIT_TEST("IDLE")
8888

89-
`UNIT_TEST(IDLE)
90-
91-
`INFO("Test: IDLE");
9289
`FAIL_IF(wfull);
9390
`FAIL_IF(!rempty);
94-
91+
9592
`UNIT_TEST_END
9693

97-
`UNIT_TEST(SIMPLE_WRITE_AND_READ)
94+
`UNIT_TEST("SINGLE_WRITE_THEN_READ")
9895

99-
`INFO("Test: Simple write then read");
100-
10196
@(posedge wclk)
10297

10398
winc = 1;
@@ -111,23 +106,24 @@ module async_fifo_unit_test;
111106

112107
wait (rempty == 1'b0);
113108

109+
rinc = 1;
110+
@(negedge rclk)
111+
114112
`FAIL_IF_NOT_EQUAL(rdata, 32'hA);
115113

116114
`UNIT_TEST_END
117115

118-
`UNIT_TEST(MULTIPLE_WRITE_AND_READ)
116+
`UNIT_TEST("MULTIPLE_WRITE_AND_READ")
119117

120-
`INFO("Test: Multiple write then read");
121-
122118
for (i=0; i<10; i=i+1) begin
123119
@(negedge wclk);
124120
winc = 1;
125121
wdata = i;
126-
// $display("DEBUG: [%g]: %x", $time, i);
122+
$display("DEBUG: [%g]: %x", $time, i);
127123
end
128124
@(negedge wclk);
129125
winc = 0;
130-
126+
131127
#100;
132128

133129
@(posedge rclk);
@@ -136,15 +132,13 @@ module async_fifo_unit_test;
136132
for (i=0; i<10; i=i+1) begin
137133
@(posedge rclk);
138134
`FAIL_IF_NOT_EQUAL(rdata, i);
139-
// $display("DEBUG: [%g]: %x", $time, rdata);
135+
$display("DEBUG: [%g]: %x", $time, rdata);
140136
end
141137

142138
`UNIT_TEST_END
143139

144-
`UNIT_TEST(TEST_FULL_FLAG)
140+
`UNIT_TEST("TEST_FULL_FLAG")
145141

146-
`INFO("Test: full flag test");
147-
148142
winc = 1;
149143

150144
for (i=0; i<2**ASIZE; i=i+1) begin
@@ -160,12 +154,10 @@ module async_fifo_unit_test;
160154

161155
`UNIT_TEST_END
162156

163-
`UNIT_TEST(TEST_EMPTY_FLAG)
164-
165-
`INFO("Test: empty flag test");
157+
`UNIT_TEST("TEST_EMPTY_FLAG")
166158

167159
`FAIL_IF_NOT_EQUAL(rempty, 1);
168-
160+
169161
for (i=0; i<2**ASIZE; i=i+1) begin
170162
@(posedge wclk)
171163
winc = 1;
@@ -176,10 +168,8 @@ module async_fifo_unit_test;
176168

177169
`UNIT_TEST_END
178170

179-
`UNIT_TEST(TEST_SIMPLE_ALMOST_EMPTY_FLAG)
180-
181-
`INFO("Test: almost empty flag simple test");
182-
171+
`UNIT_TEST("TEST_SIMPLE_ALMOST_EMPTY_FLAG")
172+
183173
`FAIL_IF_NOT_EQUAL(arempty, 0);
184174

185175
@(posedge wclk)
@@ -193,10 +183,8 @@ module async_fifo_unit_test;
193183

194184
`UNIT_TEST_END
195185

196-
`UNIT_TEST(TEST_SIMPLE_ALMOST_FULL_FLAG)
186+
`UNIT_TEST("TEST_SIMPLE_ALMOST_FULL_FLAG")
197187

198-
`INFO("Test: Almost full flag simple test");
199-
200188
winc = 1;
201189
for (i=0; i<2**ASIZE; i=i+1) begin
202190

@@ -210,13 +198,11 @@ module async_fifo_unit_test;
210198

211199
@(posedge wclk)
212200
`FAIL_IF_NOT_EQUAL(wfull, 1);
213-
201+
214202
`UNIT_TEST_END
215203

216-
`UNIT_TEST(TEST_CONSECUTIVE_ALMOST_EMPTY_FULL)
204+
`UNIT_TEST("TEST_CONSECUTIVE_ALMOST_EMPTY_FULL")
217205

218-
`INFO("Test: Consecutive empty/full flags test");
219-
220206
winc = 1;
221207
for (i=0; i<2**ASIZE; i=i+1) begin
222208

@@ -230,9 +216,9 @@ module async_fifo_unit_test;
230216

231217
@(posedge wclk)
232218
`FAIL_IF_NOT_EQUAL(wfull, 1);
233-
219+
234220
`UNIT_TEST_END
235-
`UNIT_TESTS_END
221+
`TEST_SUITE_END
236222

237223
endmodule
238224

sim/test/svut_h.sv

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
/// Copyright 2020 The SVUT Authors
2+
///
3+
/// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
/// of this software and associated documentation files (the "Software"), to
5+
/// deal in the Software without restriction, including without limitation the
6+
/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7+
/// sell copies of the Software, and to permit persons to whom the Software is
8+
/// furnished to do so, subject to the following conditions:
9+
///
10+
/// The above copyright notice and this permission notice shall be included in
11+
/// all copies or substantial portions of the Software.
12+
///
13+
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18+
/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19+
/// IN THE SOFTWARE.
20+
21+
22+
`ifndef SVUT_DEFINES
23+
`define SVUT_DEFINES
24+
25+
/// Define colors for $display
26+
27+
`define BLUE "\033[0;34m"
28+
`define GREEN "\033[0;32m"
29+
`define ORANGE "\033[1;33m"
30+
`define PINK "\033[1;35m"
31+
`define RED "\033[1;31m"
32+
`define NC "\033[0m"
33+
34+
35+
/// Follows a set of ready to use function to print status
36+
/// and information with an appropriate color.
37+
38+
`define INFO(msg) \
39+
$display("\033[0;34mINFO: %s (@ %0t)\033[0m", msg, $time)
40+
41+
`define SUCCESS(msg) \
42+
$display("\033[0;32mSUCCESS: %s (@ %0t)\033[0m", msg, $time)
43+
44+
`define WARNING(msg) \
45+
$display("\033[1;33mWARNING: %s (@ %0t)\033[0m", msg, $time); \
46+
svut_warning += 1
47+
48+
`define CRITICAL(msg) \
49+
$display("\033[1;35mCRITICAL: %s (@ %0t)\033[0m", msg, $time); \
50+
svut_critical += 1
51+
52+
`define ERROR(msg)\
53+
$display("\033[1;31mERROR: %s (@ %0t)\033[0m", msg, $time); \
54+
svut_error += 1
55+
56+
/// SVUT_SETUP is the code portion initializing all the needed
57+
/// variables. To call once before or after the module instance
58+
59+
`define SVUT_SETUP \
60+
integer svut_status = 0; \
61+
integer svut_warning = 0; \
62+
integer svut_critical = 0; \
63+
integer svut_error = 0; \
64+
integer svut_error_total = 0; \
65+
integer svut_nb_test = 0; \
66+
integer svut_nb_test_success = 0; \
67+
string svut_test_name = ""; \
68+
string svut_suite_name = ""; \
69+
string svut_msg = "";
70+
71+
72+
/// LAST_STATUS is a flag asserted if check the last
73+
/// check function failed
74+
`define LAST_STATUS svut_status
75+
76+
/// Follows a set of macros to check an expression
77+
/// or a signal. All use the same syntax:
78+
/// - a signal or an expression to evaluate
79+
/// - an optional message to print if case the
80+
/// evaluation fails.
81+
82+
/// This function is shared between assertions to format messages
83+
function string create_msg(input string assertion, message);
84+
if (message != "")
85+
create_msg = {message, " (", assertion, ")"};
86+
else
87+
create_msg = assertion;
88+
endfunction
89+
90+
91+
/// This check will fails if expression is not = 0
92+
`define FAIL_IF(exp, message="") \
93+
svut_status = 0; \
94+
svut_msg = create_msg("FAIL_IF", message); \
95+
if (exp) begin \
96+
`ERROR(svut_msg); \
97+
svut_status = 1; \
98+
end
99+
100+
/// This check will fails if expression is not > 0
101+
`define FAIL_IF_NOT(exp, message="") \
102+
svut_status = 0; \
103+
svut_msg = create_msg("FAIL_IF_NOT", message); \
104+
if (!exp) begin \
105+
`ERROR(svut_msg); \
106+
svut_status = 1; \
107+
end
108+
109+
/// This check will fails if both input are equal
110+
`define FAIL_IF_EQUAL(a,b, message="") \
111+
svut_status = 0; \
112+
svut_msg = create_msg("FAIL_IF_EQUAL", message); \
113+
if (a === b) begin \
114+
`ERROR(svut_msg); \
115+
svut_status = 1; \
116+
end
117+
118+
/// This check will fails if both input are not equal
119+
`define FAIL_IF_NOT_EQUAL(a,b, message="") \
120+
svut_status = 0; \
121+
svut_msg = create_msg("FAIL_IF_NOT_EQUAL", message); \
122+
if (a !== b) begin \
123+
`ERROR(svut_msg); \
124+
svut_status = 1; \
125+
end
126+
127+
/// This check will fails if expression is not = 0
128+
`define ASSERT(exp, message="") \
129+
svut_status = 0; \
130+
svut_msg = create_msg("ASSERT", message); \
131+
if (!exp) begin \
132+
`ERROR(svut_msg); \
133+
svut_status = 1; \
134+
end
135+
136+
137+
/// This header must be placed to start a test suite execution
138+
`define TEST_SUITE(name="") \
139+
task run(msg=""); \
140+
begin \
141+
svut_suite_name = name; \
142+
svut_msg = {"Start testsuite ", name}; \
143+
`INFO(svut_msg);
144+
145+
/// This header must be placed to start a test execution
146+
`define UNIT_TEST(name="") \
147+
begin \
148+
svut_msg = {"Start test ", name}; \
149+
`INFO(svut_msg); \
150+
setup(); \
151+
svut_test_name = name; \
152+
svut_error = 0; \
153+
svut_nb_test = svut_nb_test + 1;
154+
155+
/// This header must be placed to close a test
156+
`define UNIT_TEST_END \
157+
teardown(); \
158+
if (svut_error == 0) begin \
159+
svut_nb_test_success = svut_nb_test_success + 1; \
160+
`SUCCESS("Test successful"); \
161+
end else begin \
162+
`ERROR("Test failed"); \
163+
svut_error_total += svut_error; \
164+
end \
165+
end
166+
167+
/// This header must be placed to close a test suite
168+
`define TEST_SUITE_END \
169+
end \
170+
endtask \
171+
initial begin\
172+
run(); \
173+
svut_msg = {"Stop testsuite ", svut_suite_name}; \
174+
`INFO(svut_msg); \
175+
if (svut_warning > 0) begin \
176+
$display("\t\033[1;33m- Warning number: %0d\033[0m", svut_warning); \
177+
end \
178+
if (svut_critical > 0) begin \
179+
$display("\t\033[1;35m- Critical number: %0d\033[0m", svut_critical); \
180+
end \
181+
if (svut_error_total > 0) begin \
182+
$display("\t\033[1;31m- Error number: %0d\033[0m", svut_error_total); \
183+
end \
184+
if (svut_nb_test_success != svut_nb_test) begin \
185+
$display("\t\033[1;31m- STATUS: %0d/%0d test(s) passed\033[0m\n", svut_nb_test_success, svut_nb_test); \
186+
end else begin \
187+
$display("\t\033[0;32m- STATUS: %0d/%0d test(s) passed\033[0m\n", svut_nb_test_success, svut_nb_test); \
188+
end \
189+
$finish(); \
190+
end
191+
192+
`endif

0 commit comments

Comments
 (0)