ovm_report_handler.svh

Go to the documentation of this file.
00001 // $Id: ovm_report_handler.svh 19 2009-12-28 21:40:27Z seanoboyle $
00002 //------------------------------------------------------------------------------
00003 //   Copyright 2007-2009 Mentor Graphics Corporation
00004 //   Copyright 2007-2009 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 `ifndef OVM_REPORT_HANDLER_SVH
00023 `define OVM_REPORT_HANDLER_SVH
00024 
00025 typedef class ovm_report_object;
00026 typedef class ovm_report_server;
00027 typedef class ovm_report_global_server;
00028 
00029 `ifdef INCA
00030     class ovm_hash #(type T=int, I1=int, I2=int);
00031       local T d[string];
00032       function void set(I1 i1, I2 i2, T t);
00033         string s;
00034         $swrite(s,i1,":",i2);
00035         d[s] = t;
00036       endfunction
00037       function T get(I1 i1,I2 i2);
00038         string s;
00039         $swrite(s,i1,":",i2);
00040         return d[s];
00041       endfunction
00042       function int exists(I1 i1, I2 i2);
00043         string s;
00044         if(d.num() == 0) return 0;
00045         $swrite(s,i1,":",i2);
00046         return d.exists(s);
00047       endfunction
00048       function int first(string index);
00049         return d.first(index);
00050       endfunction
00051       function int next(string index);
00052         return d.next(index);
00053       endfunction
00054       function T fetch(string index);
00055         return d[index];
00056       endfunction
00057     endclass : ovm_hash
00058 `endif
00059    
00060 
00061 //------------------------------------------------------------------------------
00062 //
00063 // CLASS: ovm_report_handler
00064 //
00065 // The ovm_report_handler is the class to which most methods in
00066 // <ovm_report_object> delegate. It stores the maximum verbosity, actions,
00067 // and files that affect the way reports are handled. 
00068 //
00069 // The report handler is not intended for direct use. See <ovm_report_object>
00070 // for information on the OVM reporting mechanism.
00071 //
00072 // The relationship between <ovm_report_object> (a base class for ovm_component)
00073 // and ovm_report_handler is typically one to one, but it can be many to one
00074 // if several ovm_report_objects are configured to use the same
00075 // ovm_report_handler_object. See <ovm_report_object::set_report_handler>.
00076 //
00077 // The relationship between ovm_report_handler and <ovm_report_server> is many
00078 // to one. 
00079 //
00080 //------------------------------------------------------------------------------
00081 
00082 class ovm_report_handler;
00083 
00084   ovm_report_global_server m_glob;
00085 
00086   int m_max_verbosity_level;
00087 
00088   // internal variables
00089 
00090   ovm_action severity_actions[ovm_severity];
00091 
00092   `ifndef INCA
00093   id_actions_array id_actions;
00094   id_actions_array severity_id_actions[ovm_severity];
00095 
00096   // file handles : default, severity, action, (severity,id)
00097   OVM_FILE default_file_handle;
00098   OVM_FILE severity_file_handles[ovm_severity];
00099   id_file_array id_file_handles;
00100   id_file_array severity_id_file_handles[ovm_severity];
00101   `endif
00102 
00103   `ifdef INCA
00104   ovm_action id_actions[string];
00105   ovm_hash #(ovm_action,ovm_severity,string) severity_id_actions = new;
00106 
00107   OVM_FILE default_file_handle;
00108   OVM_FILE severity_file_handles[ovm_severity];
00109   OVM_FILE id_file_handles[string];
00110   ovm_hash #(OVM_FILE,ovm_severity,string) severity_id_file_handles = new;
00111   `endif
00112 
00113 
00114   // Function: new
00115   // 
00116   // Creates and initializes a new ovm_report_handler object.
00117 
00118   function new();
00119     m_glob = new();
00120     initialize;
00121   endfunction
00122 
00123 
00124   // Function- get_server
00125   //
00126   // Internal method called by <ovm_report_object::get_report_server>.
00127 
00128   function ovm_report_server get_server();
00129     return m_glob.get_server();
00130   endfunction
00131 
00132 
00133   // Function- set_max_quit_count
00134   //
00135   // Internal method called by <ovm_report_object::set_report_max_quit_count>.
00136 
00137   function void set_max_quit_count(int max_count);
00138     ovm_report_server srvr;
00139     srvr = m_glob.get_server();
00140     srvr.set_max_quit_count(max_count);
00141   endfunction
00142 
00143 
00144   // Function- summarize
00145   //
00146   // Internal method called by <ovm_report_object::report_summarize>.
00147 
00148   function void summarize(OVM_FILE file = 0);
00149     ovm_report_server srvr;
00150     srvr = m_glob.get_server();
00151     srvr.summarize(file);
00152   endfunction
00153 
00154 
00155   // Function- report_header
00156   //
00157   // Internal method called by <ovm_report_object::report_header>
00158 
00159   function void report_header(OVM_FILE file = 0);
00160 
00161     ovm_report_server srvr;
00162 
00163     srvr = m_glob.get_server();
00164     srvr.f_display(file,
00165       "----------------------------------------------------------------");
00166     srvr.f_display(file, ovm_revision_string());
00167     srvr.f_display(file, ovm_mgc_copyright);
00168     srvr.f_display(file, ovm_cdn_copyright);
00169     srvr.f_display(file,
00170       "----------------------------------------------------------------");
00171   endfunction
00172 
00173 
00174   // Function- initialize
00175   // 
00176   // This method is called by the constructor to initialize the arrays and
00177   // other variables described above to their default values.
00178 
00179   function void initialize();
00180     set_default_file(0);
00181     m_max_verbosity_level = OVM_MEDIUM;
00182     set_defaults();
00183   endfunction
00184 
00185 
00186   // Function: run_hooks
00187   //
00188   // The run_hooks method is called if the <OVM_CALL_HOOK> action is set for a
00189   // report. It first calls the client's <report_hook> method, followed by the
00190   // appropriate severity-specific hook method. If either returns 0, then the
00191   // report is not processed.
00192 
00193   virtual function bit run_hooks(ovm_report_object client,
00194                                  ovm_severity severity,
00195                                  string id,
00196                                  string message,
00197                                  int verbosity,
00198                                  string filename,
00199                                  int line);
00200 
00201     bit ok;
00202 
00203     ok = client.report_hook(id, message, verbosity, filename, line);
00204 
00205     case(severity)
00206       OVM_INFO:
00207        ok &= client.report_info_hook   (id, message, verbosity, filename, line);
00208       OVM_WARNING:
00209        ok &= client.report_warning_hook(id, message, verbosity, filename, line);
00210       OVM_ERROR:
00211        ok &= client.report_error_hook  (id, message, verbosity, filename, line);
00212       OVM_FATAL:
00213        ok &= client.report_fatal_hook  (id, message, verbosity, filename, line);
00214     endcase
00215 
00216     return ok;
00217 
00218   endfunction
00219 
00220   
00221   // Function- get_severity_id_file
00222   //
00223   // Return the file id based on the severity and the id
00224 
00225   local function OVM_FILE get_severity_id_file(ovm_severity severity, string id);
00226 
00227    `ifndef INCA
00228     id_file_array array;
00229 
00230     if(severity_id_file_handles.exists(severity)) begin
00231       array = severity_id_file_handles[severity];      
00232       if(array.exists(id))
00233         return array[id];
00234     end
00235    `else
00236     if (severity_id_file_handles.exists(severity,id))
00237       return severity_id_file_handles.get(severity,id);
00238    `endif
00239 
00240 
00241     if(id_file_handles.exists(id))
00242       return id_file_handles[id];
00243 
00244     if(severity_file_handles.exists(severity))
00245       return severity_file_handles[severity];
00246 
00247     return default_file_handle;
00248 
00249   endfunction
00250 
00251 
00252   // Function- set_verbosity_level
00253   //
00254   // Internal method called by ovm_report_object.
00255 
00256   function void set_verbosity_level(int verbosity_level);
00257     m_max_verbosity_level = verbosity_level;
00258   endfunction
00259 
00260 
00261   // Function: get_verbosity_level
00262   //
00263   // Returns the configured maximum verbosity level.
00264 
00265   function int get_verbosity_level();
00266     return m_max_verbosity_level;
00267   endfunction
00268 
00269 
00270   // Function: get_action
00271   //
00272   // Returns the action associated with the given ~severity~ and ~id~.
00273   // 
00274   // First, if there is an action associated with the ~(severity,id)~ pair,
00275   // return that.  Else, if there is an action associated with the ~id~, return
00276   // that.  Else, if there is an action associated with the ~severity~, return
00277   // that. Else, return the default action associated with the ~severity~.
00278 
00279   function ovm_action get_action(ovm_severity severity, string id);
00280 
00281    `ifndef INCA
00282     id_actions_array array;
00283 
00284     if(severity_id_actions.exists(severity)) begin
00285       array = severity_id_actions[severity];
00286       if(array.exists(id))
00287         return array[id];
00288     end
00289    `else
00290     if (severity_id_actions.exists(severity,id))
00291       return severity_id_actions.get(severity,id);
00292    `endif
00293 
00294     if(id_actions.exists(id))
00295       return id_actions[id];
00296 
00297     return severity_actions[severity];
00298 
00299   endfunction
00300 
00301 
00302   // Function: get_file_handle
00303   //
00304   // Returns the file descriptor associated with the given ~severity~ and ~id~.
00305   //
00306   // First, if there is a file handle associated with the ~(severity,id)~ pair,
00307   // return that. Else, if there is a file handle associated with the ~id~, return
00308   // that. Else, if there is an file handle associated with the ~severity~, return
00309   // that. Else, return the default file handle.
00310 
00311   function OVM_FILE get_file_handle(ovm_severity severity, string id);
00312     OVM_FILE file;
00313   
00314     file = get_severity_id_file(severity, id);
00315     if (file != 0)
00316       return file;
00317   
00318     if (id_file_handles.exists(id)) begin
00319       file = id_file_handles[id];
00320       if (file != 0)
00321         return file;
00322     end
00323 
00324     if (severity_file_handles.exists(severity)) begin
00325       file = severity_file_handles[severity];
00326       if(file != 0)
00327         return file;
00328     end
00329 
00330     return default_file_handle;
00331   endfunction
00332 
00333 
00334   // Function: report
00335   //
00336   // This is the common handler method used by the four core reporting methods
00337   // (e.g., ovm_report_error) in <ovm_report_object>.
00338 
00339   virtual function void report(
00340       ovm_severity severity,
00341       string name,
00342       string id,
00343       string message,
00344       int verbosity_level,
00345       string filename,
00346       int line,
00347       ovm_report_object client
00348       );
00349  
00350     ovm_report_server srvr;
00351     srvr = m_glob.get_server();
00352     srvr.report(severity,name,id,message,verbosity_level,filename,line,client);
00353     
00354   endfunction
00355 
00356 
00357   // Function: format_action
00358   //
00359   // Returns a string representation of the ~action~, e.g., "DISPLAY".
00360 
00361   function string format_action(ovm_action action);
00362     string s;
00363 
00364     if(ovm_action_type'(action) == OVM_NO_ACTION) begin
00365       s = "NO ACTION";
00366     end
00367     else begin
00368       s = "";
00369       if(action & OVM_DISPLAY)   s = {s, "DISPLAY "};
00370       if(action & OVM_LOG)       s = {s, "LOG "};
00371       if(action & OVM_COUNT)     s = {s, "COUNT "};
00372       if(action & OVM_EXIT)      s = {s, "EXIT "};
00373       if(action & OVM_CALL_HOOK) s = {s, "CALL_HOOK "};
00374       if(action & OVM_STOP)      s = {s, "STOP "};
00375     end
00376 
00377     return s;
00378   endfunction
00379 
00380 
00381   // Function- set_default
00382   //
00383   // Internal method for initializing report handler.
00384 
00385   function void set_defaults();
00386     set_severity_action(OVM_INFO,    OVM_DISPLAY);
00387     set_severity_action(OVM_WARNING, OVM_DISPLAY);
00388     set_severity_action(OVM_ERROR,   OVM_DISPLAY | OVM_COUNT);
00389     set_severity_action(OVM_FATAL,   OVM_DISPLAY | OVM_EXIT);
00390 
00391     set_severity_file(OVM_INFO, default_file_handle);
00392     set_severity_file(OVM_WARNING, default_file_handle);
00393     set_severity_file(OVM_ERROR,   default_file_handle);
00394     set_severity_file(OVM_FATAL,   default_file_handle);
00395   endfunction
00396 
00397 
00398   // Function- set_severity_action
00399   // Function- set_id_action
00400   // Function- set_severity_id_action
00401   //
00402   // Internal methods called by ovm_report_object.
00403 
00404   function void set_severity_action(input ovm_severity severity,
00405                                     input ovm_action action);
00406     severity_actions[severity] = action;
00407   endfunction
00408 
00409   function void set_id_action(input string id, input ovm_action action);
00410     id_actions[id] = action;
00411   endfunction
00412 
00413   function void set_severity_id_action(ovm_severity severity,
00414                                        string id,
00415                                        ovm_action action);
00416     `ifndef INCA
00417     severity_id_actions[severity][id] = action;
00418     `else
00419     severity_id_actions.set(severity,id,action);
00420     `endif
00421   endfunction
00422   
00423 
00424   // Function- set_default_file
00425   // Function- set_severity_file
00426   // Function- set_id_file
00427   // Function- set_severity_id_file
00428   //
00429   // Internal methods called by ovm_report_object.
00430 
00431   function void set_default_file (OVM_FILE file);
00432     default_file_handle = file;
00433   endfunction
00434 
00435   function void set_severity_file (ovm_severity severity, OVM_FILE file);
00436     severity_file_handles[severity] = file;
00437   endfunction
00438 
00439   function void set_id_file (string id, OVM_FILE file);
00440     id_file_handles[id] = file;
00441   endfunction
00442 
00443   function void set_severity_id_file(ovm_severity severity,
00444                                      string id, OVM_FILE file);
00445   
00446     `ifndef INCA
00447     severity_id_file_handles[severity][id] = file;
00448     `else
00449     severity_id_file_handles.set(severity,id,file);
00450     `endif
00451   endfunction
00452 
00453   
00454   // Function- dump_state
00455   //
00456   // Internal method for debug.
00457 
00458   function void dump_state();
00459 
00460     string s;
00461     ovm_severity_type severity;
00462     ovm_action a;
00463     string idx;
00464     OVM_FILE file;
00465     ovm_report_server srvr;
00466  
00467    `ifndef INCA
00468      id_actions_array id_a_ary;
00469      id_file_array id_f_ary;
00470    `else
00471      OVM_FILE id_f_ary[string];
00472    `endif
00473 
00474     srvr = m_glob.get_server();
00475 
00476     srvr.f_display(0,
00477       "----------------------------------------------------------------------");
00478     srvr.f_display(0, "report handler state dump");
00479     srvr.f_display(0, "");
00480 
00481     $sformat(s, "max verbosity level = %d", m_max_verbosity_level);
00482     srvr.f_display(0, s);
00483 
00484     // actions
00485 
00486     srvr.f_display(0, "");   
00487     srvr.f_display(0, "+-------------+");
00488     srvr.f_display(0, "|   actions   |");
00489     srvr.f_display(0, "+-------------+");
00490     srvr.f_display(0, "");   
00491 
00492     srvr.f_display(0, "*** actions by severity");
00493     foreach( severity_actions[severity] ) begin
00494       $sformat(s, "%s = %s",
00495        ovm_severity_type'(severity), format_action(severity_actions[severity]));
00496       srvr.f_display(0, s);
00497     end
00498 
00499     srvr.f_display(0, "");
00500     srvr.f_display(0, "*** actions by id");
00501 
00502     foreach( id_actions[idx] ) begin
00503       $sformat(s, "[%s] --> %s", idx, format_action(id_actions[idx]));
00504       srvr.f_display(0, s);
00505     end
00506 
00507     // actions by id
00508 
00509     srvr.f_display(0, "");
00510     srvr.f_display(0, "*** actions by id and severity");
00511 
00512     `ifndef INCA
00513     foreach( severity_id_actions[severity] ) begin
00514       // ADAM: is id_a_ary __copied__?
00515       id_a_ary = severity_id_actions[severity];
00516       foreach( id_a_ary[idx] ) begin
00517         $sformat(s, "%s:%s --> %s",
00518            ovm_severity_type'(severity), idx, format_action(id_a_ary[idx]));
00519         srvr.f_display(0, s);        
00520       end
00521     end
00522     `else
00523     begin
00524       string idx;
00525       if ( severity_id_actions.first( idx ) )
00526         do begin
00527             $sformat(s, "%s --> %s", idx,
00528               format_action(severity_id_actions.fetch(idx)));
00529             srvr.f_display(0, s);        
00530         end
00531         while ( severity_id_actions.next( idx ) );
00532     end
00533     `endif
00534 
00535     // Files
00536 
00537     srvr.f_display(0, "");
00538     srvr.f_display(0, "+-------------+");
00539     srvr.f_display(0, "|    files    |");
00540     srvr.f_display(0, "+-------------+");
00541     srvr.f_display(0, "");   
00542 
00543     $sformat(s, "default file handle = %d", default_file_handle);
00544     srvr.f_display(0, s);
00545 
00546     srvr.f_display(0, "");
00547     srvr.f_display(0, "*** files by severity");
00548     foreach( severity_file_handles[severity] ) begin
00549       file = severity_file_handles[severity];
00550       $sformat(s, "%s = %d", ovm_severity_type'(severity), file);
00551       srvr.f_display(0, s);
00552     end
00553 
00554     srvr.f_display(0, "");
00555     srvr.f_display(0, "*** files by id");
00556 
00557     foreach ( id_file_handles[idx] ) begin
00558       file = id_file_handles[idx];
00559       $sformat(s, "id %s --> %d", idx, file);
00560       srvr.f_display(0, s);
00561     end
00562 
00563     srvr.f_display(0, "");
00564     srvr.f_display(0, "*** files by id and severity");
00565 
00566     `ifndef INCA
00567     foreach( severity_id_file_handles[severity] ) begin
00568       id_f_ary = severity_id_file_handles[severity];
00569       foreach ( id_f_ary[idx] ) begin
00570         $sformat(s, "%s:%s --> %d", ovm_severity_type'(severity), idx, id_f_ary[idx]);
00571         srvr.f_display(0, s);
00572       end
00573     end
00574     `else
00575     begin
00576       string idx;
00577       if ( severity_id_file_handles.first( idx ) )
00578         do begin
00579             $sformat(s, "%s --> %s", idx,
00580               format_action(severity_id_file_handles.fetch(idx)));
00581             srvr.f_display(0, s);        
00582         end
00583         while ( severity_id_file_handles.next( idx ) );
00584     end
00585     `endif
00586 
00587     srvr.dump_server_state();
00588     
00589     srvr.f_display(0,
00590       "----------------------------------------------------------------------");
00591   endfunction
00592 
00593 endclass : ovm_report_handler
00594 
00595 
00596 //------------------------------------------------------------------------------
00597 
00598 class default_report_server;
00599 
00600   ovm_report_global_server glob;
00601 
00602   function new();
00603     glob = new;
00604   endfunction
00605 
00606   function ovm_report_server get_server();
00607     return glob.get_server();
00608   endfunction
00609   
00610 endclass
00611 
00612 `endif // OVM_REPORT_HANDLER_SVH
00613 

Intelligent Design Verification
Intelligent Design Verification
Project: OVM, Revision: 2.1.0
Copyright (c) 2008-2010 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.6.3
IDV SV Filter Version: 2.6.3
Sat Jun 19 11:51:29 2010
Find a documentation bug? Report bugs to: bugs.intelligentdv.com Project: DoxygenFilterSV