-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage_test.sv
More file actions
116 lines (94 loc) · 2.49 KB
/
package_test.sv
File metadata and controls
116 lines (94 loc) · 2.49 KB
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
114
115
116
package package_test;
import packet_pkg::*;
import scoreboard_pkg::*;
`define SV_RAND_CHECK(r)\
do begin \
if (!(r)) begin\
$display("%s:%0d Randomization failed \"%s\"", \
`__FILE__, `__LINE__, `"r`"); \
end \
end while(0)
virtual class Driver_cbs;
virtual task pre_tx(ref packet pkt);
//Callback does nothing
endtask // pre_tx
virtual task post_tx(ref packet pkt);
endtask // post_tx
endclass // Driver_cbs
class Driver_cbs_scoreboard extends Driver_cbs;
Scoreboard scb;
function new();
this.scb = new();
endfunction
virtual task post_tx(ref packet pkt);
scb.compare_expected(pkt);
endtask // post_tx
endclass
class Driver_cbs_v3 extends Driver_cbs;
int corruption_cnt;
function new ();
corruption_cnt = 0;
endfunction // new
virtual task pre_tx(ref packet pkt);
int rval = $urandom_range(0,99);
if(rval == 0) begin
pkt.header.version = 3;
corruption_cnt++;
end
endtask
endclass
class Driver;
mailbox #(packet) gen2drv;
packet p;
Driver_cbs cbs[$];
function new(input mailbox #(packet) gen2drv);
this.gen2drv = gen2drv;
endfunction // new
task run(input int count);
repeat(count) begin
gen2drv.get(p);
foreach (cbs[i]) cbs[i].pre_tx(p);
transmit(p);
foreach (cbs[i]) cbs[i].post_tx(p);
end
endtask // run
task transmit(base_packet pkt);
#10ns;
endtask
endclass
class Generator;
mailbox #(packet) gen2drv;
packet blueprint;
function new(input mailbox #(packet) gen2drv);
this.gen2drv = gen2drv;
blueprint = new();
endfunction
task run(input int count);
repeat(count) begin
`SV_RAND_CHECK(blueprint.randomize());
blueprint.calc_header_checksum();
gen2drv.put(blueprint.copy()); // requires base_packet class copy to have been implemented by a child class or will not compile!
end
endtask
endclass
class Environment;
Generator gen;
Driver drv;
mailbox #(packet) gen2drv;
int count;
function new(int count);
this.count = count;
endfunction;
function void build();
gen2drv = new();
gen = new(gen2drv);
drv = new(gen2drv);
endfunction
task run();
fork
gen.run(count);
drv.run(count);
join
endtask
endclass
endpackage