|
|
- Randomize the test configuration : Randomize various testbench configuration, Example, how many ports of ethernet switch is enabled, How many BFM's needed to connected, What is depth of packet memory.
- Create various components of testbench :In this stage, various testbench class's constructor is called, vmm_channel are connected. Basically memory allocation of various components of testbench is done.
- Reset the DUT : In this stage DUT is reset.
- configure the DUT : In this state various DUT configuration is performed.
- start various components of testbench:In this state various components are started, like packet generator is started to generate packets, checkers, bfm and monitors are started.
- wait for testbench to complete :Wait for the testbench to complete the generation, collection and checking.
- stop all components of testbench :In this stage all the components are stoped. This is not a must have state
- report final statics of testbench :In this stage scoreboard, error and warning counters are checked.
|
|
|
1 `include "vmm.sv"
2
3 // Note : This is not exact representation of AHB data class
4 // All data class needs to extend from vmm_data
5 class ahb_data extends vmm_data;
6 vmm_log log;
7 // Declare all the fields
8 rand bit [31:0] addr;
9 rand bit [31:0] data [16];
10 rand bit [3:0] beats;
11
12 // Make sure all variables have init value
13 function new(vmm_log log = null);
14 int i;
15 super.new(log);
16 this.log = log;
17 this.addr = 0;
18 for (i = 0; i < 16; i ++) begin
19 this.data[1] = 0;
20 end
21 this.beats = 1;
22 endfunction
23 virtual function vmm_data copy(vmm_data to = null);
24 ahb_data cpy;
25 int i;
26 if (to == null) begin
27 cpy = new (log);
28 end else begin
29 if ( ! ($cast(cpy,to))) begin
30 `vmm_fatal(log,"Object is not of type ahb_data");
31 end
32 end
33 cpy.addr = this.addr;
34 for (i = 0; i < 16; i ++) begin
35 cpy.data[i] = this.data[1];
36 end
37 copy = cpy;
38 endfunction
39
40
41 // Print message
42 function void display(string prefix = "");
43 if (is_valid()) begin
44 `vmm_debug(log,$psprintf("%s",psdisplay(prefix)));
45 end else begin
46 `vmm_error(log,$psprintf("%s",psdisplay(prefix)));
47 end
48 endfunction
49
50 // Return the string members and their values
51 virtual function string psdisplay(string prefix = "");
52 string msg;
53 int i;
54 msg = $psprintf(" %s\n", prefix);
55 msg = $psprintf("%s ADDRESS : 32'h%x\n",msg,addr);
56 msg = $psprintf("%s BEATS : %0d\n",msg,beats);
57
58 for (i = 0; i < beats; i++) begin
59 msg = $psprintf("%s DATA[%2d] : 32'h%x\n",msg,i,data[i]);
60 end
61 psdisplay = msg;
62 endfunction
63 endclass
64
65 // We need to add below line to construct vmm_channel for object ahb_data
66 `vmm_channel(ahb_data)
67 `vmm_atomic_gen(ahb_data,"ATOMIC GEN")
68
69 // This class sinks transactions
70 class sink extends vmm_xactor;
71 ahb_data_channel fifo;
72 vmm_log log;
73
74 function new(vmm_log log, string name, ahb_data_channel fifo);
75 super.new(name,name);
76 this.log = log;
77 this.fifo = fifo;
78 endfunction
79
80 virtual task main();
81 ahb_data d;
82 super.main();
83 while (1) begin
84 wait_if_stopped_or_empty(fifo);
85 fifo.get(d);
86 // Indicate we are processing the object
87 d.notify.indicate(vmm_data::STARTED);
88 #10 ;
89 // Indicate we done with processing the object
90 $display("Indicating done processing");
91 d.notify.indicate(vmm_data::ENDED);
92 end
93 endtask
94 endclass
95
96 class my_env extends vmm_env;
97 vmm_log log ;
98 ahb_data_channel fifo;
99 ahb_data_atomic_gen src ;
100 sink snk ;
101
102 function new();
103 super.new("my_env");
104 log = new("my_env","env");
105 endfunction
106
107 virtual function void gen_cfg();
108 super.gen_cfg();
109 `vmm_warning(this.log,"gen_cfg not implemented for this example");
110 endfunction
111
112 virtual function void build();
113 super.build();
114 fifo = new ("CHANNEL","FIFO");
115 src = new("SOURCE",-1,fifo);
116 snk = new(log,"SINK",fifo);
117 endfunction
118
119 virtual task reset_dut();
120 super.reset_dut();
121 `vmm_warning(this.log,"reset_dut not implemented for this example");
122 endtask
123
124 virtual task cfg_dut();
125 super.cfg_dut();
126 `vmm_warning(this.log,"cfg_dut not implemented for this example");
127 endtask
128
129 virtual task start();
130 super.start();
131 src.stop_after_n_insts = 2;
132 snk.start_xactor();
133 src.start_xactor();
134 endtask
135
136 virtual task wait_for_end();
137 super.wait_for_end();
138 // Wait for source to end
139 src.notify.wait_for(ahb_data_atomic_gen::DONE);
140 `vmm_note(this.log,"Generator is done with generation");
141 endtask
142
143 virtual task stop();
144 super.stop();
145 #100 ;
146 snk.stop_xactor();
147 src.stop_xactor();
148 endtask
149
150 virtual task report();
151 super.report();
152 `vmm_note(this.log,"Generator is done with generation");
153 endtask
154
155 endclass
156
157 program test();
158
159 my_env env = new();
160
161 initial begin
162 env.run();
163 #100 ;
164 end
165
166 endprogram
You could download file vmm_env_ex.sv here
|