log_file.cpp revision 12855:588919e0e4aa
12207SN/A/***************************************************************************** 25254Sksewell@umich.edu 35254Sksewell@umich.edu Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 42207SN/A more contributor license agreements. See the NOTICE file distributed 55254Sksewell@umich.edu with this work for additional information regarding copyright ownership. 65254Sksewell@umich.edu Accellera licenses this file to you under the Apache License, Version 2.0 75254Sksewell@umich.edu (the "License"); you may not use this file except in compliance with the 85254Sksewell@umich.edu License. You may obtain a copy of the License at 95254Sksewell@umich.edu 105254Sksewell@umich.edu http://www.apache.org/licenses/LICENSE-2.0 115254Sksewell@umich.edu 125254Sksewell@umich.edu Unless required by applicable law or agreed to in writing, software 135254Sksewell@umich.edu distributed under the License is distributed on an "AS IS" BASIS, 145254Sksewell@umich.edu WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 152207SN/A implied. See the License for the specific language governing 165254Sksewell@umich.edu permissions and limitations under the License. 175254Sksewell@umich.edu 185254Sksewell@umich.edu *****************************************************************************/ 195254Sksewell@umich.edu 205254Sksewell@umich.edu/***************************************************************************** 215254Sksewell@umich.edu 225254Sksewell@umich.edu sc_report -- test error reporting, sepcifically log file 235254Sksewell@umich.edu 245254Sksewell@umich.edu That that messages are printed into the log file. 255254Sksewell@umich.edu 265254Sksewell@umich.edu Original Author: Ulli Holtmann, Synopsys, Inc., Jan 2003 272665Ssaidi@eecs.umich.edu 285254Sksewell@umich.edu *****************************************************************************/ 295254Sksewell@umich.edu 305254Sksewell@umich.edu/***************************************************************************** 312207SN/A 322207SN/A MODIFICATION LOG - modifiers, enter your name, affiliation, date and 332474SN/A changes you are making here. 342207SN/A 358229Snate@binkert.org Name, Affiliation, Date: 362454SN/A Description of Modification: 372454SN/A 382680Sktlim@umich.edu *****************************************************************************/ 398232Snate@binkert.org 406650Sksewell@umich.edu#include <systemc.h> 416650Sksewell@umich.edu 426650Sksewell@umich.eduSC_MODULE( M ) 432474SN/A{ 442207SN/A sc_event trigger_t, trigger_m; 452447SN/A SC_CTOR( M ) { 462474SN/A SC_THREAD( thread1 ); 472447SN/A sensitive << trigger_t; 485154Sgblack@eecs.umich.edu dont_initialize(); 495154Sgblack@eecs.umich.edu 505154Sgblack@eecs.umich.edu SC_METHOD( method1 ); 512474SN/A sensitive << trigger_m; 522686Sksewell@umich.edu dont_initialize(); 532686Sksewell@umich.edu } 542935Sksewell@umich.edu void method1() { 552474SN/A sc_report_handler::report( SC_INFO, "ID1", "after log is opened", "method", 101); 562474SN/A sc_report_handler::report( SC_WARNING, "ID2", "after log is opened", "method", 102); 572474SN/A sc_report_handler::report( SC_ERROR, "ID1", "after log is opened", "method", 103); 582474SN/A sc_report_handler::report( SC_FATAL, "ID2", "after log is opened", "method", 104); 592686Sksewell@umich.edu } 602686Sksewell@umich.edu void thread1() { 6110318Sandreas.hansson@arm.com while(1) { 622686Sksewell@umich.edu sc_report_handler::report( SC_INFO, "ID2", "after log is opened", "thread", 201); 636811SMatt DeVuyst sc_report_handler::report( SC_WARNING, "ID1", "after log is opened", "thread", 202); 6411386Ssteve.reinhardt@amd.com sc_report_handler::report( SC_ERROR, "ID2", "after log is opened", "thread", 203); 652474SN/A sc_report_handler::report( SC_FATAL, "ID1", "after log is opened", "thread", 204); 662474SN/A wait(); 672474SN/A } 687532Ssteve.reinhardt@amd.com } 692474SN/A}; 707532Ssteve.reinhardt@amd.com 716650Sksewell@umich.eduint sc_main(int,char**) 7210318Sandreas.hansson@arm.com{ 732474SN/A const char fname[] = "./sc_report.log"; 745958Sgblack@eecs.umich.edu M uut("uut"); 756811SMatt DeVuyst 766650Sksewell@umich.edu // do not abort when on error, fatal 776811SMatt DeVuyst sc_report_handler::stop_after( SC_ERROR, 0 ); 786650Sksewell@umich.edu sc_report_handler::stop_after( SC_FATAL, 0 ); 796811SMatt DeVuyst sc_report_handler::suppress( SC_STOP | SC_ABORT ); 806811SMatt DeVuyst sc_report_handler::set_actions( "ID1", SC_LOG | SC_DISPLAY ); 8111389Sbrandon.potter@amd.com sc_report_handler::set_actions( "ID2", SC_LOG | SC_DISPLAY ); 8211389Sbrandon.potter@amd.com 8311389Sbrandon.potter@amd.com // produces messages before the log file is opened 846650Sksewell@umich.edu sc_report_handler::report( SC_INFO, "ID1", "before log is opened", "no_file", 0); 856650Sksewell@umich.edu sc_report_handler::report( SC_WARNING, "ID1", "before log is opened", "no_file", 0); 866650Sksewell@umich.edu 876811SMatt DeVuyst // open log file 886811SMatt DeVuyst sc_report_handler::set_log_file_name( fname ); 896811SMatt DeVuyst sc_assert( strcmp(fname,sc_report_handler::get_log_file_name()) == 0 ); 906811SMatt DeVuyst 916811SMatt DeVuyst // emit report from global context at t=0 926811SMatt DeVuyst sc_report_handler::report( SC_INFO, "ID1", "after log is opened", "file1", 1); 936811SMatt DeVuyst sc_report_handler::report( SC_WARNING, "ID2", "after log is opened", "file2", 2); 9410318Sandreas.hansson@arm.com sc_report_handler::report( SC_ERROR, "ID1", "after log is opened", "file3", 3); 956811SMatt DeVuyst sc_report_handler::report( SC_FATAL, "ID2", "after log is opened", "file4", 4); 966811SMatt DeVuyst 976811SMatt DeVuyst // emit report from global context at 10ns, method at 20ns, thread at 30ns 986811SMatt DeVuyst uut.trigger_m.notify( 20, SC_NS ); 996811SMatt DeVuyst uut.trigger_t.notify( 30, SC_NS ); 1006811SMatt DeVuyst sc_start( 10,SC_NS ); 1016811SMatt DeVuyst sc_report_handler::report( SC_ERROR, "ID1", "after log is opened", "file3", 5); 1026811SMatt DeVuyst sc_start( 100, SC_NS ); 1036811SMatt DeVuyst 1046811SMatt DeVuyst // close log file and more messages 1056811SMatt DeVuyst sc_report_close_default_log(); 10611389Sbrandon.potter@amd.com 10711389Sbrandon.potter@amd.com sc_report_handler::report( SC_INFO, "ID1", "after log is closed", "no_file", 0); 10811389Sbrandon.potter@amd.com sc_report_handler::report( SC_WARNING, "ID1", "after log is closed", "no_file", 0); 10911389Sbrandon.potter@amd.com 1106811SMatt DeVuyst // open file again and dump into cout so we cover it by regression 1116811SMatt DeVuyst cout << "\n\nDump the logfile\n"; 1126811SMatt DeVuyst FILE* log = fopen( fname,"r" ); 1136811SMatt DeVuyst if ( !log ) { 1146811SMatt DeVuyst SC_REPORT_FATAL( "Can not open the sc_report log file: ", fname ); 1156811SMatt DeVuyst return 1; 1166811SMatt DeVuyst } 1176811SMatt DeVuyst while ( 1 ) { 1186811SMatt DeVuyst int c = fgetc(log); 1196811SMatt DeVuyst if (c==EOF) 1206650Sksewell@umich.edu break; 1216650Sksewell@umich.edu cout << static_cast<char>(c); 1226811SMatt DeVuyst } 1236811SMatt DeVuyst fclose( log) ; 1246650Sksewell@umich.edu 1256650Sksewell@umich.edu return 0; 1266650Sksewell@umich.edu} 1276650Sksewell@umich.edu