ovm_in_order_comparator.svh

Go to the documentation of this file.
00001 // $Id: a00235.html,v 1.1 2009/01/07 19:29:52 alex.marin Exp $
00002 //----------------------------------------------------------------------
00003 //   Copyright 2007-2008 Mentor Graphics Corporation
00004 //   Copyright 2007-2008 Cadence Design Systems, Inc.
00005 //   All Rights Reserved Worldwide
00006 //
00007 //   Licensed under the Apache License, Version 2.0 (the
00008 //   "License"); you may not use this file except in
00009 //   compliance with the License.  You may obtain a copy of
00010 //   the License at
00011 //
00012 //       http://www.apache.org/licenses/LICENSE-2.0
00013 //
00014 //   Unless required by applicable law or agreed to in
00015 //   writing, software distributed under the License is
00016 //   distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
00017 //   CONDITIONS OF ANY KIND, either express or implied.  See
00018 //   the License for the specific language governing
00019 //   permissions and limitations under the License.
00020 //----------------------------------------------------------------------
00021 
00022 //----------------------------------------------------------------------
00023 // CLASS in_order_comparator
00024 //
00025 // in_order_comparator : compares two streams of data
00026 //
00027 // makes no assumptions about the relative ordering of the two streams
00028 //
00029 // T is the type of the two streams of data.
00030 //
00031 // comp and convert are functors which describe how to do
00032 // comparison and printing for T.
00033 //
00034 // These parameters can be changed for different T's :
00035 // however, we expect that the two pairs of classes above
00036 // will be OK for most cases. Built in types ( such as ints,
00037 // bits, logic, and structs ) are dealt with by using the
00038 // default functors built_in_comp and built_in_converter, while
00039 // classes should be dealt with by class_comp and
00040 // class_converter, which in turn assume the existence of comp
00041 // and convert2string functions in the class itself.
00042 //----------------------------------------------------------------------
00043 
00044 class ovm_in_order_comparator 
00045   #( type T = int ,
00046      type comp_type = ovm_built_in_comp #( T ) ,
00047      type convert = ovm_built_in_converter #( T ) , 
00048      type pair_type = ovm_built_in_pair #( T ) )
00049     extends ovm_component;
00050 
00051   typedef ovm_in_order_comparator #(T,comp_type,convert,pair_type) this_type;
00052   `ovm_component_param_utils(this_type)
00053 
00054   const static string type_name = 
00055     "ovm_in_order_comparator #(T,comp_type,convert,pair_type)";
00056 
00057   //  The two exports. Actually, there are no assumptions made about
00058   // ordering, so it doesn't matter which way around you make the 
00059   // connections
00060 
00061   ovm_analysis_export #( T ) before_export , after_export;
00062   ovm_analysis_port #( pair_type ) pair_ap;
00063   
00064   local tlm_analysis_fifo #( T ) before_fifo , after_fifo;
00065   int m_matches , m_mismatches;
00066 
00067 
00068   function new( string name ,
00069       ovm_component parent ) ;
00070 
00071     super.new( name, parent );
00072 
00073     before_export = new("before_export" , this );
00074     after_export = new("after_export" , this );
00075 
00076     pair_ap = new("pair_ap" , this );
00077     
00078     before_fifo = new("before" , this );
00079     after_fifo = new("after" , this );
00080     
00081     m_matches = 0;
00082     m_mismatches = 0;
00083   endfunction
00084   
00085   virtual function string get_type_name();
00086     return type_name;
00087   endfunction
00088 
00089   virtual function void connect();
00090     before_export.connect( before_fifo.analysis_export );
00091     after_export.connect( after_fifo.analysis_export );
00092   endfunction
00093 
00094 
00095   // run is not a user visible task. It gets pairs of befores and
00096   // afters, and compares them. Status info is updated according to the
00097   // results of this comparison.
00098 
00099   virtual task run();
00100  
00101     pair_type pair;
00102     T b;
00103     T a;
00104   
00105     string s;
00106    
00107     forever begin
00108       
00109       before_fifo.get( b );
00110       after_fifo.get( a );
00111       
00112       if( !comp_type::comp( b , a ) ) begin
00113 
00114       $sformat( s , "%s differs from %s" ,
00115           convert::convert2string( a ) ,
00116           convert::convert2string( b ) );
00117     
00118         ovm_report_warning("Comparator Mismatch" , s );
00119         m_mismatches++;
00120       end
00121       else begin
00122         s = convert::convert2string( b );
00123         ovm_report_info("Comparator Match" , s );
00124         m_matches++;
00125       end
00126 
00127       //
00128       // we make the assumption here that a transaction "sent for
00129       // analysis" is safe from being edited by another process
00130       //
00131       // hence, it is safe not to clone a and b.
00132       
00133       pair = new( a , b );
00134       pair_ap.write( pair );
00135     end
00136   
00137   endtask
00138 
00139   virtual function void flush();
00140     m_matches = 0;
00141     m_mismatches = 0;
00142   endfunction
00143   
00144 endclass : ovm_in_order_comparator
00145 
00146 //----------------------------------------------------------------------
00147 // CLASS in_order_built_in_comparator
00148 //----------------------------------------------------------------------
00149 
00150 // in_order_built_in_comparator uses the default ( ie,
00151 // built_in ) comparison and printing policy classes.
00152 
00153 class ovm_in_order_built_in_comparator #( type T = int )
00154   extends ovm_in_order_comparator #( T );
00155 
00156   typedef ovm_in_order_built_in_comparator #(T) this_type;
00157   `ovm_component_param_utils(this_type)
00158 
00159   const static string type_name = "ovm_in_order_built_in_comparator #(T)";
00160 
00161   function new( string name , ovm_component parent );
00162     super.new( name, parent );
00163   endfunction
00164   
00165   virtual function string get_type_name ();
00166     return type_name;
00167   endfunction
00168 
00169 endclass : ovm_in_order_built_in_comparator 
00170 
00171 //----------------------------------------------------------------------
00172 // CLASS in_order_class_comparator
00173 //----------------------------------------------------------------------
00174 
00175 // in_order_class_comparator uses the class comparison and
00176 // printing policy classes. This ultimately relies on the
00177 // existence of comp and convert2string methods in the
00178 // transaction type T
00179 
00180 class ovm_in_order_class_comparator #( type T = int )
00181   extends ovm_in_order_comparator #( T , 
00182                                      ovm_class_comp #( T ) , 
00183                                      ovm_class_converter #( T ) , 
00184                                      ovm_class_pair #( T, T ) );
00185 
00186   typedef ovm_in_order_class_comparator #(T) this_type;
00187   `ovm_component_param_utils(this_type)
00188 
00189   const static string type_name = "ovm_in_order_class_comparator #(T)";
00190 
00191   function new( string name  , ovm_component parent);
00192     super.new( name, parent );
00193   endfunction
00194   
00195   virtual function string get_type_name ();
00196     return type_name;
00197   endfunction
00198 
00199 endclass : ovm_in_order_class_comparator

Intelligent Design Verification
Intelligent Design Verification
Project: OVM, Revision: 2.0.1
Copyright (c) 2008 Intelligent Design Verification.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included here:
http://www.intelligentdv.com/licenses/fdl.txt
doxygen
Doxygen Version: 1.5.5
Wed Jan 7 19:27:17 2009
Find a documentation bug? Report bugs to: bugs.intelligentdv.com Project: DoxygenFilterSV