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

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [base/] [uvm_comparer.svh] - Blame information for rev 16

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 HanySalah
//-----------------------------------------------------------------------------
2
//   Copyright 2007-2010 Mentor Graphics Corporation
3
//   Copyright 2007-2011 Cadence Design Systems, Inc.
4
//   Copyright 2010 Synopsys, Inc.
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
// CLASS: uvm_comparer
25
//
26
// The uvm_comparer class provides a policy object for doing comparisons. The
27
// policies determine how miscompares are treated and counted. Results of a
28
// comparison are stored in the comparer object. The 
29
// and  methods are passed a uvm_comparer policy
30
// object.
31
//
32
//------------------------------------------------------------------------------
33
 
34
class uvm_comparer;
35
 
36
  // Variable: policy
37
  //
38
  // Determines whether comparison is UVM_DEEP, UVM_REFERENCE, or UVM_SHALLOW.
39
 
40
  uvm_recursion_policy_enum policy = UVM_DEFAULT_POLICY;
41
 
42
 
43
  // Variable: show_max
44
  //
45
  // Sets the maximum number of messages to send to the printer for miscompares
46
  // of an object.
47
 
48
  int unsigned show_max = 1;
49
 
50
 
51
  // Variable: verbosity
52
  //
53
  // Sets the verbosity for printed messages.
54
  //
55
  // The verbosity setting is used by the messaging mechanism to determine
56
  // whether messages should be suppressed or shown.
57
 
58
  int unsigned verbosity = UVM_LOW;
59
 
60
 
61
  // Variable: sev
62
  //
63
  // Sets the severity for printed messages.
64
  //
65
  // The severity setting is used by the messaging mechanism for printing and
66
  // filtering messages.
67
 
68
  uvm_severity sev = UVM_INFO;
69
 
70
 
71
  // Variable: miscompares
72
  //
73
  // This string is reset to an empty string when a comparison is started.
74
  //
75
  // The string holds the last set of miscompares that occurred during a
76
  // comparison.
77
 
78
  string miscompares = "";
79
 
80
 
81
  // Variable: physical
82
  //
83
  // This bit provides a filtering mechanism for fields.
84
  //
85
  // The abstract and physical settings allow an object to distinguish between
86
  // two different classes of fields.
87
  //
88
  // It is up to you, in the  method, to test the
89
  // setting of this field if you want to use the physical trait as a filter.
90
 
91
  bit physical = 1;
92
 
93
 
94
  // Variable: abstract
95
  //
96
  // This bit provides a filtering mechanism for fields.
97
  //
98
  // The abstract and physical settings allow an object to distinguish between
99
  // two different classes of fields.
100
  //
101
  // It is up to you, in the  method, to test the
102
  // setting of this field if you want to use the abstract trait as a filter.
103
 
104
  bit abstract = 1;
105
 
106
 
107
  // Variable: check_type
108
  //
109
  // This bit determines whether the type, given by ,
110
  // is used to verify that the types of two objects are the same.
111
  //
112
  // This bit is used by the  method. In some cases it is useful
113
  // to set this to 0 when the two operands are related by inheritance but are
114
  // different types.
115
 
116
  bit check_type = 1;
117
 
118
 
119
  // Variable: result
120
  //
121
  // This bit stores the number of miscompares for a given compare operation.
122
  // You can use the result to determine the number of miscompares that
123
  // were found.
124
 
125
  int unsigned result = 0;
126
 
127
 
128
  // Function: compare_field
129
  //
130
  // Compares two integral values.
131
  //
132
  // The ~name~ input is used for purposes of storing and printing a miscompare.
133
  //
134
  // The left-hand-side ~lhs~ and right-hand-side ~rhs~ objects are the two
135
  // objects used for comparison.
136
  //
137
  // The size variable indicates the number of bits to compare; size must be
138
  // less than or equal to 4096.
139
  //
140
  // The radix is used for reporting purposes, the default radix is hex.
141
 
142
  virtual function bit compare_field (string name,
143
                                      uvm_bitstream_t lhs,
144
                                      uvm_bitstream_t rhs,
145
                                      int size,
146
                                      uvm_radix_enum radix=UVM_NORADIX);
147
    uvm_bitstream_t mask;
148
    string msg;
149
 
150
    if(size <= 64)
151
      return compare_field_int(name, lhs, rhs, size, radix);
152
 
153
    mask = -1;
154
    mask >>= (UVM_STREAMBITS-size);
155
    if((lhs & mask) !== (rhs & mask)) begin
156
      uvm_object::__m_uvm_status_container.scope.set_arg(name);
157
      case (radix)
158
        UVM_BIN: begin
159
              $swrite(msg, "lhs = 'b%0b : rhs = 'b%0b",
160
                       lhs&mask, rhs&mask);
161
             end
162
        UVM_OCT: begin
163
              $swrite(msg, "lhs = 'o%0o : rhs = 'o%0o",
164
                       lhs&mask, rhs&mask);
165
             end
166
        UVM_DEC: begin
167
              $swrite(msg, "lhs = %0d : rhs = %0d",
168
                       lhs&mask, rhs&mask);
169
             end
170
        UVM_TIME: begin
171
            $swrite(msg, "lhs = %0t : rhs = %0t",
172
               lhs&mask, rhs&mask);
173
        end
174
        UVM_STRING: begin
175
              $swrite(msg, "lhs = %0s : rhs = %0s",
176
                       lhs&mask, rhs&mask);
177
             end
178
        UVM_ENUM: begin
179
              //Printed as decimal, user should cuse compare string for enum val
180
              $swrite(msg, "lhs = %0d : rhs = %0d",
181
                       lhs&mask, rhs&mask);
182
              end
183
        default: begin
184
              $swrite(msg, "lhs = 'h%0x : rhs = 'h%0x",
185
                       lhs&mask, rhs&mask);
186
             end
187
      endcase
188
      print_msg(msg);
189
      return 0;
190
    end
191
    return 1;
192
  endfunction
193
 
194
 
195
 
196
  // Function: compare_field_int
197
  //
198
  // This method is the same as  except that the arguments are
199
  // small integers, less than or equal to 64 bits. It is automatically called
200
  // by  if the operand size is less than or equal to 64.
201
 
202
  virtual function bit compare_field_int (string name,
203
                                          uvm_integral_t lhs,
204
                                          uvm_integral_t rhs,
205
                                          int size,
206
                                          uvm_radix_enum radix=UVM_NORADIX);
207
    logic [63:0] mask;
208
    string msg;
209
 
210
    mask = -1;
211
    mask >>= (64-size);
212
    if((lhs & mask) !== (rhs & mask)) begin
213
      uvm_object::__m_uvm_status_container.scope.set_arg(name);
214
      case (radix)
215
        UVM_BIN: begin
216
              $swrite(msg, "lhs = 'b%0b : rhs = 'b%0b",
217
                       lhs&mask, rhs&mask);
218
             end
219
        UVM_OCT: begin
220
              $swrite(msg, "lhs = 'o%0o : rhs = 'o%0o",
221
                       lhs&mask, rhs&mask);
222
             end
223
        UVM_DEC: begin
224
              $swrite(msg, "lhs = %0d : rhs = %0d",
225
                       lhs&mask, rhs&mask);
226
             end
227
        UVM_TIME: begin
228
            $swrite(msg, "lhs = %0t : rhs = %0t",
229
               lhs&mask, rhs&mask);
230
        end
231
        UVM_STRING: begin
232
              $swrite(msg, "lhs = %0s : rhs = %0s",
233
                       lhs&mask, rhs&mask);
234
             end
235
        UVM_ENUM: begin
236
              //Printed as decimal, user should cuse compare string for enum val
237
              $swrite(msg, "lhs = %0d : rhs = %0d",
238
                       lhs&mask, rhs&mask);
239
              end
240
        default: begin
241
              $swrite(msg, "lhs = 'h%0x : rhs = 'h%0x",
242
                       lhs&mask, rhs&mask);
243
             end
244
      endcase
245
      print_msg(msg);
246
      return 0;
247
    end
248
    return 1;
249
  endfunction
250
 
251
 
252
  // Function: compare_field_real
253
  //
254
  // This method is the same as  except that the arguments are
255
  // real numbers.
256
 
257
  virtual function bit compare_field_real (string name,
258
                                          real lhs,
259
                                          real rhs);
260
    string msg;
261
 
262
    if(lhs != rhs) begin
263
      uvm_object::__m_uvm_status_container.scope.set_arg(name);
264
      $swrite(msg, "lhs = ", lhs, " : rhs = ", rhs);
265
      print_msg(msg);
266
      return 0;
267
    end
268
    return 1;
269
  endfunction
270
 
271
 
272
  // Function: compare_object
273
  //
274
  // Compares two class objects using the  knob to determine whether the
275
  // comparison should be deep, shallow, or reference.
276
  //
277
  // The name input is used for purposes of storing and printing a miscompare.
278
  //
279
  // The ~lhs~ and ~rhs~ objects are the two objects used for comparison.
280
  //
281
  // The ~check_type~ determines whether or not to verify the object
282
  // types match (the return from ~lhs.get_type_name()~ matches
283
  // ~rhs.get_type_name()~).
284
 
285
  virtual function bit compare_object (string name,
286
                                       uvm_object lhs,
287
                                       uvm_object rhs);
288
    if (rhs == lhs)
289
      return 1;
290
 
291
    if (policy == UVM_REFERENCE && lhs != rhs) begin
292
      uvm_object::__m_uvm_status_container.scope.set_arg(name);
293
      print_msg_object(lhs, rhs);
294
      return 0;
295
    end
296
 
297
    if (rhs == null || lhs == null) begin
298
      uvm_object::__m_uvm_status_container.scope.set_arg(name);
299
      print_msg_object(lhs, rhs);
300
      return 0;  //miscompare
301
    end
302
 
303
    uvm_object::__m_uvm_status_container.scope.down(name);
304
    compare_object = lhs.compare(rhs, this);
305
    uvm_object::__m_uvm_status_container.scope.up();
306
 
307
  endfunction
308
 
309
 
310
  // Function: compare_string
311
  //
312
  // Compares two string variables.
313
  //
314
  // The ~name~ input is used for purposes of storing and printing a miscompare.
315
  //
316
  // The ~lhs~ and ~rhs~ objects are the two objects used for comparison.
317
 
318
  virtual function bit compare_string (string name,
319
                                       string lhs,
320
                                       string rhs);
321
    string msg;
322
    if(lhs != rhs) begin
323
      uvm_object::__m_uvm_status_container.scope.set_arg(name);
324
      msg = { "lhs = \"", lhs, "\" : rhs = \"", rhs, "\""};
325
      print_msg(msg);
326
      return 0;
327
    end
328
    return 1;
329
  endfunction
330
 
331
 
332
  // Function: print_msg
333
  //
334
  // Causes the error count to be incremented and the message, ~msg~, to be
335
  // appended to the  string (a newline is used to separate
336
  // messages).
337
  //
338
  // If the message count is less than the  setting, then the message
339
  // is printed to standard-out using the current verbosity and severity
340
  // settings. See the  and  variables for more information.
341
 
342
  function void print_msg (string msg);
343
    uvm_root root;
344
    uvm_coreservice_t cs;
345
    cs = uvm_coreservice_t::get();
346
    root = cs.get_root();
347
 
348
    result++;
349
    if(result <= show_max) begin
350
       msg = {"Miscompare for ", uvm_object::__m_uvm_status_container.scope.get(), ": ", msg};
351
       root.uvm_report(sev, "MISCMP", msg, verbosity, `uvm_file, `uvm_line);
352
    end
353
    miscompares = { miscompares, uvm_object::__m_uvm_status_container.scope.get(), ": ", msg, "\n" };
354
  endfunction
355
 
356
 
357
 
358
  // Internal methods - do not call directly
359
 
360
  // print_rollup
361
  // ------------
362
 
363
  //Need this function because sformat doesn't support objects
364
  function void print_rollup(uvm_object rhs, uvm_object lhs);
365
    uvm_root root;
366
    uvm_coreservice_t cs;
367
 
368
    string msg;
369
    cs = uvm_coreservice_t::get();
370
    root = cs.get_root();
371
    if(uvm_object::__m_uvm_status_container.scope.depth() == 0) begin
372
      if(result && (show_max || (uvm_severity'(sev) != UVM_INFO))) begin
373
        if(show_max < result)
374
           $swrite(msg, "%0d Miscompare(s) (%0d shown) for object ",
375
             result, show_max);
376
        else begin
377
           $swrite(msg, "%0d Miscompare(s) for object ", result);
378
        end
379
 
380
        root.uvm_report(sev, "MISCMP", $sformatf("%s%s@%0d vs. %s@%0d", msg,
381
                        lhs.get_name(), lhs.get_inst_id(), rhs.get_name(), rhs.get_inst_id()),
382
                        verbosity, `uvm_file, `uvm_line);
383
      end
384
    end
385
  endfunction
386
 
387
 
388
  // print_msg_object
389
  // ----------------
390
 
391
  function void print_msg_object(uvm_object lhs, uvm_object rhs);
392
      uvm_root root;
393
  uvm_coreservice_t cs;
394
  cs = uvm_coreservice_t::get();
395
  root = cs.get_root();
396
 
397
    result++;
398
    if(result <= show_max) begin
399
       root.uvm_report(sev, "MISCMP",
400
         $sformatf("Miscompare for %0s: lhs = @%0d : rhs = @%0d",
401
         uvm_object::__m_uvm_status_container.scope.get(), (lhs!=null ? lhs.get_inst_id() : 0),         (rhs != null ? rhs.get_inst_id() : 0)), verbosity, `uvm_file, `uvm_line);
402
    end
403
    $swrite(miscompares, "%s%s: lhs = @%0d : rhs = @%0d",
404
        miscompares, uvm_object::__m_uvm_status_container.scope.get(), (lhs != null ? lhs.get_inst_id() : 0), (rhs != null ? rhs.get_inst_id() : 0));
405
  endfunction
406
 
407
 
408
 
409
  // init ??
410
 
411
  static function uvm_comparer init();
412
    if(uvm_default_comparer==null) uvm_default_comparer=new;
413
    return uvm_default_comparer;
414
  endfunction
415
 
416
 
417
  int depth;                      //current depth of objects
418
  uvm_object compare_map[uvm_object];
419
  uvm_scope_stack scope    = new;
420
 
421
endclass
422
 

powered by: WebSVN 2.1.0

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