Skip to content

Commit fc9fcb0

Browse files
gatk555martinwhitaker
authored andcommitted
Regression test for vvp scheduler fix.
This is for the latent bug exposed when testing the original fix for issue #1041. Contributed by gatk555 in PR #1065.
1 parent b128508 commit fc9fcb0

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

ivtest/vpi/br_gh1041b.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <vpi_user.h>
2+
3+
static void step(void);
4+
5+
static vpiHandle w;
6+
7+
static PLI_INT32 tick_cb(struct t_cb_data *cb)
8+
{
9+
static struct t_vpi_value val = { .format = vpiIntVal };
10+
static int idx;
11+
12+
(void)cb;
13+
14+
++idx;
15+
val.value.integer = idx & 1;
16+
vpi_put_value(w, &val, NULL, vpiNoDelay);
17+
step();
18+
return 0;
19+
}
20+
21+
/* Request a callback after a delay. */
22+
23+
static void step(void)
24+
{
25+
static struct t_vpi_time now = { .type = vpiSimTime, .low = 2 };
26+
static struct t_cb_data cbd =
27+
{ .reason = cbAfterDelay, .cb_rtn = tick_cb, .time = &now };
28+
29+
/* Callback after delay. */
30+
31+
vpi_register_cb(&cbd);
32+
}
33+
34+
/* Callback function - simulation is starting. */
35+
36+
static PLI_INT32 start_cb(struct t_cb_data *cb)
37+
{
38+
static struct t_vpi_value val = { .format = vpiIntVal };
39+
40+
(void)cb;
41+
42+
w = vpi_handle_by_name("test.w", NULL);
43+
if (!w)
44+
vpi_printf("No handle!\n");
45+
vpi_printf("Got handle for %s\n", vpi_get_str(vpiFullName, w));
46+
val.value.integer = 0;
47+
vpi_put_value(w, &val, NULL, vpiNoDelay);
48+
step();
49+
return 0;
50+
}
51+
52+
/* VPI initialisation. */
53+
54+
static void start(void)
55+
{
56+
static struct t_vpi_time now = { .type = vpiSimTime };
57+
static struct t_cb_data cbd = { .reason = cbStartOfSimulation,
58+
.time = &now, .cb_rtn = start_cb };
59+
60+
/* At this point VPI objects do not exist,
61+
* so request a callback once they do.
62+
*/
63+
64+
vpi_register_cb(&cbd);
65+
}
66+
67+
/* This is a table of registration functions. This table is the external
68+
* symbol that the VVP simulator looks for when loading this .vpi module.
69+
*/
70+
71+
void (*vlog_startup_routines[])(void) = {
72+
start,
73+
0
74+
};

ivtest/vpi/br_gh1041b.v

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module test(w);
2+
input wire w;
3+
wire a, b;
4+
5+
6+
initial begin
7+
#11 $finish;
8+
end
9+
10+
assign b = 0;
11+
12+
assign a = !w | b;
13+
14+
always @(a) begin
15+
$display($time, ": Wire a is now ", a);
16+
end
17+
endmodule
18+

ivtest/vpi_gold/br_gh1041b.gold

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Compiling vpi/br_gh1041b.c...
2+
Making br_gh1041b.vpi from br_gh1041b.o...
3+
Got handle for test.w
4+
0: Wire a is now 1
5+
2: Wire a is now 0
6+
4: Wire a is now 1
7+
6: Wire a is now 0
8+
8: Wire a is now 1
9+
10: Wire a is now 0
10+
vpi/br_gh1041b.v:7: $finish called at 11 (1s)

ivtest/vpi_regress.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ br_gh317 normal br_gh317.c br_gh317.gold
7272
br_gh496 normal,-g2009 br_gh496.c br_gh496.gold
7373
br_gh1037 normal,-g2009 br_gh1037.c br_gh1037.gold
7474
br_gh1041 normal br_gh1041.c br_gh1041.gold
75+
br_gh1041b normal br_gh1041b.c br_gh1041b.gold
7576
br_ml20191013 normal br_ml20191013.c br_ml20191013.gold
7677
by_index normal by_index.c by_index.gold
7778
by_name normal by_name.c by_name.log

0 commit comments

Comments
 (0)