OpenCores
URL https://opencores.org/ocsvn/uart2bus_testbench/uart2bus_testbench/trunk

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [reg/] [sequences/] [uvm_mem_walk_seq.svh] - Blame information for rev 16

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 HanySalah
//
2
// -------------------------------------------------------------
3
//    Copyright 2004-2008 Synopsys, Inc.
4
//    Copyright 2010 Mentor Graphics Corporation
5
//    All Rights Reserved Worldwide
6
//
7
//    Licensed under the Apache License, Version 2.0 (the
8
//    "License"); you may not use this file except in
9
//    compliance with the License.  You may obtain a copy of
10
//    the License at
11
//
12
//        http://www.apache.org/licenses/LICENSE-2.0
13
//
14
//    Unless required by applicable law or agreed to in
15
//    writing, software distributed under the License is
16
//    distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17
//    CONDITIONS OF ANY KIND, either express or implied.  See
18
//    the License for the specific language governing
19
//    permissions and limitations under the License.
20
// -------------------------------------------------------------
21
//
22
 
23
 
24
//------------------------------------------------------------------------------
25
// Title: Memory Walking-Ones Test Sequences
26
//
27
// This section defines sequences for applying a "walking-ones"
28
// algorithm on one or more memories.
29
//------------------------------------------------------------------------------
30
 
31
 
32
//------------------------------------------------------------------------------
33
// Class: uvm_mem_single_walk_seq
34
//
35
// Runs the walking-ones algorithm on the memory given by the  property,
36
// which must be assigned prior to starting this sequence.
37
//
38
// If bit-type resource named
39
// "NO_REG_TESTS", "NO_MEM_TESTS", or "NO_MEM_WALK_TEST"
40
// in the "REG::" namespace
41
// matches the full name of the memory,
42
// the memory is not tested.
43
//
44
//| uvm_resource_db#(bit)::set({"REG::",regmodel.blk.mem0.get_full_name()},
45
//|                            "NO_MEM_TESTS", 1, this);
46
//
47
// The walking ones algorithm is performed for each map in which the memory
48
// is defined.
49
//
50
//| for (k = 0 thru memsize-1)
51
//|   write addr=k data=~k
52
//|   if (k > 0) {
53
//|     read addr=k-1, expect data=~(k-1)
54
//|     write addr=k-1 data=k-1
55
//|   if (k == last addr)
56
//|     read addr=k, expect data=~k
57
//
58
//------------------------------------------------------------------------------
59
 
60
class uvm_mem_single_walk_seq extends uvm_reg_sequence #(uvm_sequence #(uvm_reg_item));
61
 
62
   `uvm_object_utils(uvm_mem_single_walk_seq)
63
 
64
 
65
   // Variable: mem
66
   //
67
   // The memory to test; must be assigned prior to starting sequence.
68
 
69
   uvm_mem mem;
70
 
71
 
72
   // Function: new
73
   //
74
   // Creates a new instance of the class with the given name.
75
 
76
   function new(string name="uvm_mem_walk_seq");
77
     super.new(name);
78
   endfunction
79
 
80
 
81
   // Task: body
82
   //
83
   // Performs the walking-ones algorithm on each map of the memory
84
   // specified in .
85
 
86
   virtual task body();
87
      uvm_reg_map maps[$];
88
      int n_bits;
89
 
90
      if (mem == null) begin
91
         `uvm_error("uvm_mem_walk_seq", "No memory specified to run sequence on");
92
         return;
93
      end
94
 
95
      // Memories with some attributes are not to be tested
96
      if (uvm_resource_db#(bit)::get_by_name({"REG::",mem.get_full_name()},
97
                                             "NO_REG_TESTS", 0) != null ||
98
          uvm_resource_db#(bit)::get_by_name({"REG::",mem.get_full_name()},
99
                                             "NO_MEM_TESTS", 0) != null ||
100
          uvm_resource_db#(bit)::get_by_name({"REG::",mem.get_full_name()},
101
                                             "NO_MEM_WALK_TEST", 0) != null )
102
         return;
103
 
104
      n_bits = mem.get_n_bits();
105
 
106
      // Memories may be accessible from multiple physical interfaces (maps)
107
      mem.get_maps(maps);
108
 
109
      // Walk the memory via each map
110
      foreach (maps[j]) begin
111
         uvm_status_e status;
112
         uvm_reg_data_t  val, exp, v;
113
 
114
         // Only deal with RW memories
115
         if (mem.get_access(maps[j]) != "RW") continue;
116
 
117
         `uvm_info("uvm_mem_walk_seq", $sformatf("Walking memory %s in map \"%s\"...",
118
                                    mem.get_full_name(), maps[j].get_full_name()), UVM_LOW);
119
 
120
         // The walking process is, for address k:
121
         // - Write ~k
122
         // - Read k-1 and expect ~(k-1) if k > 0
123
         // - Write k-1 at k-1
124
         // - Read k and expect ~k if k == last address
125
         for (int k = 0; k < mem.get_size(); k++) begin
126
 
127
            mem.write(status, k, ~k, UVM_FRONTDOOR, maps[j], this);
128
 
129
            if (status != UVM_IS_OK) begin
130
               `uvm_error("uvm_mem_walk_seq", $sformatf("Status was %s when writing \"%s[%0d]\" through map \"%s\".",
131
                                           status.name(), mem.get_full_name(), k, maps[j].get_full_name()));
132
            end
133
 
134
            if (k > 0) begin
135
               mem.read(status, k-1, val, UVM_FRONTDOOR, maps[j], this);
136
               if (status != UVM_IS_OK) begin
137
                  `uvm_error("uvm_mem_walk_seq", $sformatf("Status was %s when reading \"%s[%0d]\" through map \"%s\".",
138
                                              status.name(), mem.get_full_name(), k, maps[j].get_full_name()));
139
               end
140
               else begin
141
                  exp = ~(k-1) & ((1'b1<
142
                  if (val !== exp) begin
143
                     `uvm_error("uvm_mem_walk_seq", $sformatf("\"%s[%0d-1]\" read back as 'h%h instead of 'h%h.",
144
                                                 mem.get_full_name(), k, val, exp));
145
 
146
                  end
147
               end
148
 
149
               mem.write(status, k-1, k-1, UVM_FRONTDOOR, maps[j], this);
150
               if (status != UVM_IS_OK) begin
151
                  `uvm_error("uvm_mem_walk_seq", $sformatf("Status was %s when writing \"%s[%0d-1]\" through map \"%s\".",
152
                                              status.name(), mem.get_full_name(), k, maps[j].get_full_name()));
153
               end
154
            end
155
 
156
            if (k == mem.get_size() - 1) begin
157
               mem.read(status, k, val, UVM_FRONTDOOR, maps[j], this);
158
               if (status != UVM_IS_OK) begin
159
                  `uvm_error("uvm_mem_walk_seq", $sformatf("Status was %s when reading \"%s[%0d]\" through map \"%s\".",
160
                                              status.name(), mem.get_full_name(), k, maps[j].get_full_name()));
161
               end
162
               else begin
163
                  exp = ~(k) & ((1'b1<
164
                  if (val !== exp) begin
165
                     `uvm_error("uvm_mem_walk_seq", $sformatf("\"%s[%0d]\" read back as 'h%h instead of 'h%h.",
166
                                                 mem.get_full_name(), k, val, exp));
167
 
168
                  end
169
               end
170
            end
171
         end
172
      end
173
   endtask: body
174
 
175
endclass: uvm_mem_single_walk_seq
176
 
177
 
178
 
179
//------------------------------------------------------------------------------
180
// Class: uvm_mem_walk_seq
181
//
182
// Verifies the all memories in a block
183
// by executing the  sequence on
184
// every memory within it.
185
//
186
// If bit-type resource named
187
// "NO_REG_TESTS", "NO_MEM_TESTS", or "NO_MEM_WALK_TEST"
188
// in the "REG::" namespace
189
// matches the full name of the block,
190
// the block is not tested.
191
//
192
//| uvm_resource_db#(bit)::set({"REG::",regmodel.blk.get_full_name(),".*"},
193
//|                            "NO_MEM_TESTS", 1, this);
194
//
195
//------------------------------------------------------------------------------
196
 
197
class uvm_mem_walk_seq extends uvm_reg_sequence #(uvm_sequence #(uvm_reg_item));
198
 
199
   // Variable: model
200
   //
201
   // The block to be tested. Declared in the base class.
202
   //
203
   //| uvm_reg_block model;
204
 
205
 
206
   // Variable: mem_seq
207
   //
208
   // The sequence used to test one memory
209
   //
210
   protected uvm_mem_single_walk_seq mem_seq;
211
 
212
   `uvm_object_utils(uvm_mem_walk_seq)
213
 
214
   function new(string name="uvm_mem_walk_seq");
215
     super.new(name);
216
   endfunction
217
 
218
 
219
   // Task: body
220
   //
221
   // Executes the mem walk sequence, one block at a time.
222
   // Do not call directly. Use seq.start() instead.
223
   //
224
   virtual task body();
225
 
226
      if (model == null) begin
227
         `uvm_error("uvm_mem_walk_seq", "No register model specified to run sequence on");
228
         return;
229
      end
230
 
231
      uvm_report_info("STARTING_SEQ",{"\n\nStarting ",get_name()," sequence...\n"},UVM_LOW);
232
 
233
      mem_seq = uvm_mem_single_walk_seq::type_id::create("single_mem_walk_seq");
234
 
235
      this.reset_blk(model);
236
      model.reset();
237
 
238
      do_block(model);
239
   endtask: body
240
 
241
 
242
   // Task: do_block
243
   //
244
   // Test all of the memories in a given ~block~
245
   //
246
   protected virtual task do_block(uvm_reg_block blk);
247
      uvm_mem mems[$];
248
 
249
      if (uvm_resource_db#(bit)::get_by_name({"REG::",blk.get_full_name()},
250
                                             "NO_REG_TESTS", 0) != null ||
251
          uvm_resource_db#(bit)::get_by_name({"REG::",blk.get_full_name()},
252
                                             "NO_MEM_TESTS", 0) != null ||
253
          uvm_resource_db#(bit)::get_by_name({"REG::",blk.get_full_name()},
254
                                             "NO_MEM_ACCESS_TEST", 0) != null )
255
         return;
256
 
257
      // Iterate over all memories, checking accesses
258
      blk.get_memories(mems, UVM_NO_HIER);
259
      foreach (mems[i]) begin
260
         // Memories with some attributes are not to be tested
261
         if (uvm_resource_db#(bit)::get_by_name({"REG::",mems[i].get_full_name()},
262
                                                "NO_REG_TESTS", 0) != null ||
263
             uvm_resource_db#(bit)::get_by_name({"REG::",mems[i].get_full_name()},
264
                                                "NO_MEM_TESTS", 0) != null ||
265
             uvm_resource_db#(bit)::get_by_name({"REG::",mems[i].get_full_name()},
266
                                                "NO_MEM_WALK_TEST", 0) != null )
267
           continue;
268
 
269
         mem_seq.mem = mems[i];
270
         mem_seq.start(null, this);
271
      end
272
 
273
      begin
274
         uvm_reg_block blks[$];
275
 
276
         blk.get_blocks(blks);
277
         foreach (blks[i]) begin
278
            do_block(blks[i]);
279
         end
280
      end
281
   endtask: do_block
282
 
283
 
284
   // Task: reset_blk
285
   //
286
   // Reset the DUT that corresponds to the specified block abstraction class.
287
   //
288
   // Currently empty.
289
   // Will rollback the environment's phase to the ~reset~
290
   // phase once the new phasing is available.
291
   //
292
   // In the meantime, the DUT should be reset before executing this
293
   // test sequence or this method should be implemented
294
   // in an extension to reset the DUT.
295
   //
296
   virtual task reset_blk(uvm_reg_block blk);
297
   endtask
298
 
299
endclass: uvm_mem_walk_seq

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.