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

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [comps/] [uvm_in_order_comparator.svh] - Blame information for rev 16

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 HanySalah
//
2
//------------------------------------------------------------------------------
3
//   Copyright 2007-2011 Mentor Graphics Corporation
4
//   Copyright 2007-2011 Cadence Design Systems, Inc.
5
//   Copyright 2010-2011 Synopsys, Inc.
6
//   All Rights Reserved Worldwide
7
//
8
//   Licensed under the Apache License, Version 2.0 (the
9
//   "License"); you may not use this file except in
10
//   compliance with the License.  You may obtain a copy of
11
//   the License at
12
//
13
//       http://www.apache.org/licenses/LICENSE-2.0
14
//
15
//   Unless required by applicable law or agreed to in
16
//   writing, software distributed under the License is
17
//   distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
18
//   CONDITIONS OF ANY KIND, either express or implied.  See
19
//   the License for the specific language governing
20
//   permissions and limitations under the License.
21
//------------------------------------------------------------------------------
22
 
23
//------------------------------------------------------------------------------
24
// Title: Comparators
25
//
26
// The following classes define comparators for objects and built-in types.
27
//------------------------------------------------------------------------------
28
 
29
//------------------------------------------------------------------------------
30
//
31
// CLASS: uvm_in_order_comparator #(T,comp_type,convert,pair_type)
32
//
33
// Compares two streams of data objects of the type parameter, T.
34
// These transactions may either be classes or built-in types. To be
35
// successfully compared, the two streams of data must be in the same order.
36
// Apart from that, there are no assumptions made about the relative timing of
37
// the two streams of data.
38
//
39
// Type parameters
40
//
41
//   T       - Specifies the type of transactions to be compared.
42
//
43
//   comp_type - A policy class to compare the two
44
//               transaction streams. It must provide the static method
45
//               "function bit comp(T a, T b)" which returns ~TRUE~
46
//               if ~a~ and ~b~ are the same.
47
//
48
//   convert - A policy class to convert the transactions being compared
49
//             to a string. It must provide the static method
50
//             "function string convert2string(T a)".
51
//
52
//  pair_type - A policy class to allow pairs of transactions to be handled as
53
//              a single  type.
54
//
55
// Built in types (such as ints, bits, logic, and structs) can be compared using
56
// the default values for comp_type, convert, and pair_type. For convenience,
57
// you can use the subtype, 
58
// for built-in types.
59
//
60
// When T is a , you can use the convenience subtype
61
// .
62
//
63
// Comparisons are commutative, meaning it does not matter which data stream is
64
// connected to which export, before_export or after_export.
65
//
66
// Comparisons are done in order and as soon as a transaction is received from
67
// both streams. Internal fifos are used to buffer incoming transactions on one
68
// stream until a transaction to compare arrives on the other stream.
69
//
70
//------------------------------------------------------------------------------
71
 
72
class uvm_in_order_comparator
73
  #( type T = int ,
74
     type comp_type = uvm_built_in_comp #( T ) ,
75
     type convert = uvm_built_in_converter #( T ) ,
76
     type pair_type = uvm_built_in_pair #( T ) )
77
    extends uvm_component;
78
 
79
  typedef uvm_in_order_comparator #(T,comp_type,convert,pair_type) this_type;
80
  `uvm_component_param_utils(this_type)
81
 
82
  const static string type_name =
83
    "uvm_in_order_comparator #(T,comp_type,convert,pair_type)";
84
 
85
  // Port: before_export
86
  //
87
  // The export to which one stream of data is written. The port must be
88
  // connected to an analysis port that will provide such data.
89
 
90
  uvm_analysis_export #(T) before_export;
91
 
92
 
93
  // Port: after_export
94
  //
95
  // The export to which the other stream of data is written. The port must be
96
  // connected to an analysis port that will provide such data.
97
 
98
  uvm_analysis_export #(T) after_export;
99
 
100
 
101
  // Port: pair_ap
102
  //
103
  // The comparator sends out pairs of transactions across this analysis port.
104
  // Both matched and unmatched pairs are published via a pair_type objects.
105
  // Any connected analysis export(s) will receive these transaction pairs.
106
 
107
  uvm_analysis_port   #(pair_type) pair_ap;
108
 
109
  local uvm_tlm_analysis_fifo #(T) m_before_fifo;
110
  local uvm_tlm_analysis_fifo #(T) m_after_fifo;
111
 
112
  int m_matches, m_mismatches;
113
 
114
  function new(string name, uvm_component parent);
115
 
116
    super.new(name, parent);
117
 
118
    before_export = new("before_export", this);
119
    after_export  = new("after_export", this);
120
    pair_ap       = new("pair_ap", this);
121
 
122
    m_before_fifo = new("before", this);
123
    m_after_fifo  = new("after", this);
124
    m_matches = 0;
125
    m_mismatches = 0;
126
 
127
  endfunction
128
 
129
  virtual function string get_type_name();
130
    return type_name;
131
  endfunction
132
 
133
  virtual function void connect_phase(uvm_phase phase);
134
    before_export.connect(m_before_fifo.analysis_export);
135
    after_export.connect(m_after_fifo.analysis_export);
136
  endfunction
137
 
138
 
139
  // Task- run_phase
140
  //
141
  // Internal method.
142
  //
143
  // Takes pairs of before and after transactions and compares them.
144
  // Status information is updated according to the results of the comparison.
145
  // Each pair is published to the pair_ap analysis port.
146
 
147
  virtual task run_phase(uvm_phase phase);
148
 
149
    pair_type pair;
150
    T b;
151
    T a;
152
 
153
    string s;
154
    super.run_phase(phase);
155
    forever begin
156
 
157
      m_before_fifo.get(b);
158
      m_after_fifo.get(a);
159
 
160
      if(!comp_type::comp(b, a)) begin
161
 
162
        $sformat(s, "%s differs from %s", convert::convert2string(a),
163
                                          convert::convert2string(b));
164
 
165
        uvm_report_warning("Comparator Mismatch", s);
166
 
167
        m_mismatches++;
168
 
169
      end
170
      else begin
171
        s = convert::convert2string(b);
172
        uvm_report_info("Comparator Match", s);
173
        m_matches++;
174
      end
175
 
176
      // we make the assumption here that a transaction "sent for
177
      // analysis" is safe from being edited by another process.
178
      // Hence, it is safe not to clone a and b.
179
 
180
      pair = new("after/before");
181
      pair.first = a;
182
      pair.second = b;
183
      pair_ap.write(pair);
184
    end
185
 
186
  endtask
187
 
188
 
189
  // Function: flush
190
  //
191
  // This method sets m_matches and m_mismatches back to zero. The
192
  //  takes care of flushing the FIFOs.
193
 
194
  virtual function void flush();
195
    m_matches = 0;
196
    m_mismatches = 0;
197
  endfunction
198
 
199
endclass
200
 
201
 
202
//------------------------------------------------------------------------------
203
//
204
// CLASS: uvm_in_order_built_in_comparator #(T)
205
//
206
// This class uses the uvm_built_in_* comparison, converter, and pair classes.
207
// Use this class for built-in types (int, bit, string, etc.)
208
//
209
//------------------------------------------------------------------------------
210
 
211
class uvm_in_order_built_in_comparator #(type T=int)
212
  extends uvm_in_order_comparator #(T);
213
 
214
  typedef uvm_in_order_built_in_comparator #(T) this_type;
215
  `uvm_component_param_utils(this_type)
216
 
217
  const static string type_name = "uvm_in_order_built_in_comparator #(T)";
218
 
219
  function new(string name, uvm_component parent);
220
    super.new(name, parent);
221
  endfunction
222
 
223
  virtual function string get_type_name ();
224
    return type_name;
225
  endfunction
226
 
227
endclass
228
 
229
 
230
//------------------------------------------------------------------------------
231
//
232
// CLASS: uvm_in_order_class_comparator #(T)
233
//
234
// This class uses the uvm_class_* comparison, converter, and pair classes.
235
// Use this class for comparing user-defined objects of type T, which must
236
// provide compare() and convert2string() method.
237
//
238
//------------------------------------------------------------------------------
239
 
240
class uvm_in_order_class_comparator #( type T = int )
241
  extends uvm_in_order_comparator #( T ,
242
                                     uvm_class_comp #( T ) ,
243
                                     uvm_class_converter #( T ) ,
244
                                     uvm_class_pair #( T, T ) );
245
 
246
  typedef uvm_in_order_class_comparator #(T) this_type;
247
  `uvm_component_param_utils(this_type)
248
 
249
  const static string type_name = "uvm_in_order_class_comparator #(T)";
250
 
251
  function new( string name  , uvm_component parent);
252
    super.new( name, parent );
253
  endfunction
254
 
255
  virtual function string get_type_name ();
256
    return type_name;
257
  endfunction
258
 
259
endclass

powered by: WebSVN 2.1.0

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