summaryrefslogtreecommitdiff
path: root/src/systemc/tests/systemc/utils/sc_report/log_file
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-05-24 01:37:55 -0700
committerGabe Black <gabeblack@google.com>2018-08-08 10:09:54 +0000
commit16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f (patch)
tree7b6faaacb4574a555e561534aa4a8508c0624c32 /src/systemc/tests/systemc/utils/sc_report/log_file
parent7235d3b5211d0ba8f528d930a4c1e7ad62eec51a (diff)
downloadgem5-16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f.tar.xz
systemc: Import tests from the Accellera systemc distribution.
Change-Id: Iad76b398949a55d768a34d027a2d8e3739953da6 Reviewed-on: https://gem5-review.googlesource.com/10845 Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com> Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/systemc/tests/systemc/utils/sc_report/log_file')
-rw-r--r--src/systemc/tests/systemc/utils/sc_report/log_file/golden/log_file.log85
-rw-r--r--src/systemc/tests/systemc/utils/sc_report/log_file/log_file.cpp126
2 files changed, 211 insertions, 0 deletions
diff --git a/src/systemc/tests/systemc/utils/sc_report/log_file/golden/log_file.log b/src/systemc/tests/systemc/utils/sc_report/log_file/golden/log_file.log
new file mode 100644
index 000000000..2b1399285
--- /dev/null
+++ b/src/systemc/tests/systemc/utils/sc_report/log_file/golden/log_file.log
@@ -0,0 +1,85 @@
+SystemC Simulation
+
+Info: ID1: before log is opened
+
+Warning: ID1: before log is opened
+In file: <removed by verify.pl>
+
+Info: ID1: after log is opened
+
+Warning: ID2: after log is opened
+In file: <removed by verify.pl>
+
+Error: ID1: after log is opened
+In file: <removed by verify.pl>
+
+Fatal: ID2: after log is opened
+In file: <removed by verify.pl>
+
+Error: ID1: after log is opened
+In file: <removed by verify.pl>
+
+Info: ID1: after log is opened
+
+Warning: ID2: after log is opened
+In file: <removed by verify.pl>
+In process: uut.method1 @ 20 ns
+
+Error: ID1: after log is opened
+In file: <removed by verify.pl>
+In process: uut.method1 @ 20 ns
+
+Fatal: ID2: after log is opened
+In file: <removed by verify.pl>
+In process: uut.method1 @ 20 ns
+
+Info: ID2: after log is opened
+
+Warning: ID1: after log is opened
+In file: <removed by verify.pl>
+In process: uut.thread1 @ 30 ns
+
+Error: ID2: after log is opened
+In file: <removed by verify.pl>
+In process: uut.thread1 @ 30 ns
+
+Fatal: ID1: after log is opened
+In file: <removed by verify.pl>
+In process: uut.thread1 @ 30 ns
+
+Info: ID1: after log is closed
+
+Warning: ID1: after log is closed
+In file: <removed by verify.pl>
+
+
+Dump the logfile
+0 s: Info: ID1: after log is opened
+0 s: Warning: ID2: after log is opened
+In file: <removed by verify.pl>
+0 s: Error: ID1: after log is opened
+In file: <removed by verify.pl>
+0 s: Fatal: ID2: after log is opened
+In file: <removed by verify.pl>
+10 ns: Error: ID1: after log is opened
+In file: <removed by verify.pl>
+20 ns: Info: ID1: after log is opened
+20 ns: Warning: ID2: after log is opened
+In file: <removed by verify.pl>
+In process: uut.method1 @ 20 ns
+20 ns: Error: ID1: after log is opened
+In file: <removed by verify.pl>
+In process: uut.method1 @ 20 ns
+20 ns: Fatal: ID2: after log is opened
+In file: <removed by verify.pl>
+In process: uut.method1 @ 20 ns
+30 ns: Info: ID2: after log is opened
+30 ns: Warning: ID1: after log is opened
+In file: <removed by verify.pl>
+In process: uut.thread1 @ 30 ns
+30 ns: Error: ID2: after log is opened
+In file: <removed by verify.pl>
+In process: uut.thread1 @ 30 ns
+30 ns: Fatal: ID1: after log is opened
+In file: <removed by verify.pl>
+In process: uut.thread1 @ 30 ns
diff --git a/src/systemc/tests/systemc/utils/sc_report/log_file/log_file.cpp b/src/systemc/tests/systemc/utils/sc_report/log_file/log_file.cpp
new file mode 100644
index 000000000..7df9cb497
--- /dev/null
+++ b/src/systemc/tests/systemc/utils/sc_report/log_file/log_file.cpp
@@ -0,0 +1,126 @@
+/*****************************************************************************
+
+ Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
+ more contributor license agreements. See the NOTICE file distributed
+ with this work for additional information regarding copyright ownership.
+ Accellera licenses this file to you under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with the
+ License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied. See the License for the specific language governing
+ permissions and limitations under the License.
+
+ *****************************************************************************/
+
+/*****************************************************************************
+
+ sc_report -- test error reporting, sepcifically log file
+
+ That that messages are printed into the log file.
+
+ Original Author: Ulli Holtmann, Synopsys, Inc., Jan 2003
+
+ *****************************************************************************/
+
+/*****************************************************************************
+
+ MODIFICATION LOG - modifiers, enter your name, affiliation, date and
+ changes you are making here.
+
+ Name, Affiliation, Date:
+ Description of Modification:
+
+ *****************************************************************************/
+
+#include <systemc.h>
+
+SC_MODULE( M )
+{
+ sc_event trigger_t, trigger_m;
+ SC_CTOR( M ) {
+ SC_THREAD( thread1 );
+ sensitive << trigger_t;
+ dont_initialize();
+
+ SC_METHOD( method1 );
+ sensitive << trigger_m;
+ dont_initialize();
+ }
+ void method1() {
+ sc_report_handler::report( SC_INFO, "ID1", "after log is opened", "method", 101);
+ sc_report_handler::report( SC_WARNING, "ID2", "after log is opened", "method", 102);
+ sc_report_handler::report( SC_ERROR, "ID1", "after log is opened", "method", 103);
+ sc_report_handler::report( SC_FATAL, "ID2", "after log is opened", "method", 104);
+ }
+ void thread1() {
+ while(1) {
+ sc_report_handler::report( SC_INFO, "ID2", "after log is opened", "thread", 201);
+ sc_report_handler::report( SC_WARNING, "ID1", "after log is opened", "thread", 202);
+ sc_report_handler::report( SC_ERROR, "ID2", "after log is opened", "thread", 203);
+ sc_report_handler::report( SC_FATAL, "ID1", "after log is opened", "thread", 204);
+ wait();
+ }
+ }
+};
+
+int sc_main(int,char**)
+{
+ const char fname[] = "./sc_report.log";
+ M uut("uut");
+
+ // do not abort when on error, fatal
+ sc_report_handler::stop_after( SC_ERROR, 0 );
+ sc_report_handler::stop_after( SC_FATAL, 0 );
+ sc_report_handler::suppress( SC_STOP | SC_ABORT );
+ sc_report_handler::set_actions( "ID1", SC_LOG | SC_DISPLAY );
+ sc_report_handler::set_actions( "ID2", SC_LOG | SC_DISPLAY );
+
+ // produces messages before the log file is opened
+ sc_report_handler::report( SC_INFO, "ID1", "before log is opened", "no_file", 0);
+ sc_report_handler::report( SC_WARNING, "ID1", "before log is opened", "no_file", 0);
+
+ // open log file
+ sc_report_handler::set_log_file_name( fname );
+ sc_assert( strcmp(fname,sc_report_handler::get_log_file_name()) == 0 );
+
+ // emit report from global context at t=0
+ sc_report_handler::report( SC_INFO, "ID1", "after log is opened", "file1", 1);
+ sc_report_handler::report( SC_WARNING, "ID2", "after log is opened", "file2", 2);
+ sc_report_handler::report( SC_ERROR, "ID1", "after log is opened", "file3", 3);
+ sc_report_handler::report( SC_FATAL, "ID2", "after log is opened", "file4", 4);
+
+ // emit report from global context at 10ns, method at 20ns, thread at 30ns
+ uut.trigger_m.notify( 20, SC_NS );
+ uut.trigger_t.notify( 30, SC_NS );
+ sc_start( 10,SC_NS );
+ sc_report_handler::report( SC_ERROR, "ID1", "after log is opened", "file3", 5);
+ sc_start( 100, SC_NS );
+
+ // close log file and more messages
+ sc_report_close_default_log();
+
+ sc_report_handler::report( SC_INFO, "ID1", "after log is closed", "no_file", 0);
+ sc_report_handler::report( SC_WARNING, "ID1", "after log is closed", "no_file", 0);
+
+ // open file again and dump into cout so we cover it by regression
+ cout << "\n\nDump the logfile\n";
+ FILE* log = fopen( fname,"r" );
+ if ( !log ) {
+ SC_REPORT_FATAL( "Can not open the sc_report log file: ", fname );
+ return 1;
+ }
+ while ( 1 ) {
+ int c = fgetc(log);
+ if (c==EOF)
+ break;
+ cout << static_cast<char>(c);
+ }
+ fclose( log) ;
+
+ return 0;
+}