From 16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Thu, 24 May 2018 01:37:55 -0700 Subject: systemc: Import tests from the Accellera systemc distribution. Change-Id: Iad76b398949a55d768a34d027a2d8e3739953da6 Reviewed-on: https://gem5-review.googlesource.com/10845 Reviewed-by: Giacomo Travaglini Maintainer: Gabe Black --- .../action_selection/action_selection.cpp | 245 +++++++++++++++++++++ .../action_selection/golden/action_selection.log | 97 ++++++++ .../systemc/utils/sc_report/cached/cached.cpp | 227 +++++++++++++++++++ .../utils/sc_report/cached/golden/cached.log | 62 ++++++ .../utils/sc_report/log_file/golden/log_file.log | 85 +++++++ .../systemc/utils/sc_report/log_file/log_file.cpp | 126 +++++++++++ .../utils/sc_report/test01/golden/test01.log | 45 ++++ .../systemc/utils/sc_report/test01/test01.cpp | 109 +++++++++ .../utils/sc_report/test02/golden/test02.log | 27 +++ .../systemc/utils/sc_report/test02/test02.cpp | 80 +++++++ .../utils/sc_report/test03/golden/test03.log | 10 + .../systemc/utils/sc_report/test03/test03.cpp | 76 +++++++ .../utils/sc_report/test04/empty_msg_id.cpp | 57 +++++ .../utils/sc_report/test04/golden/empty_msg_id.log | 13 ++ .../utils/sc_report/test05/catch_actions.cpp | 93 ++++++++ .../sc_report/test05/golden/catch_actions.log | 10 + 16 files changed, 1362 insertions(+) create mode 100644 src/systemc/tests/systemc/utils/sc_report/action_selection/action_selection.cpp create mode 100644 src/systemc/tests/systemc/utils/sc_report/action_selection/golden/action_selection.log create mode 100644 src/systemc/tests/systemc/utils/sc_report/cached/cached.cpp create mode 100644 src/systemc/tests/systemc/utils/sc_report/cached/golden/cached.log create mode 100644 src/systemc/tests/systemc/utils/sc_report/log_file/golden/log_file.log create mode 100644 src/systemc/tests/systemc/utils/sc_report/log_file/log_file.cpp create mode 100644 src/systemc/tests/systemc/utils/sc_report/test01/golden/test01.log create mode 100644 src/systemc/tests/systemc/utils/sc_report/test01/test01.cpp create mode 100644 src/systemc/tests/systemc/utils/sc_report/test02/golden/test02.log create mode 100644 src/systemc/tests/systemc/utils/sc_report/test02/test02.cpp create mode 100644 src/systemc/tests/systemc/utils/sc_report/test03/golden/test03.log create mode 100644 src/systemc/tests/systemc/utils/sc_report/test03/test03.cpp create mode 100644 src/systemc/tests/systemc/utils/sc_report/test04/empty_msg_id.cpp create mode 100644 src/systemc/tests/systemc/utils/sc_report/test04/golden/empty_msg_id.log create mode 100644 src/systemc/tests/systemc/utils/sc_report/test05/catch_actions.cpp create mode 100644 src/systemc/tests/systemc/utils/sc_report/test05/golden/catch_actions.log (limited to 'src/systemc/tests/systemc/utils/sc_report') diff --git a/src/systemc/tests/systemc/utils/sc_report/action_selection/action_selection.cpp b/src/systemc/tests/systemc/utils/sc_report/action_selection/action_selection.cpp new file mode 100644 index 000000000..75951037b --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_report/action_selection/action_selection.cpp @@ -0,0 +1,245 @@ +/***************************************************************************** + + 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 which actions are selected + + An important part of the sc_report functionality is to translate + an reported tupel (id,severity) into a set of actions. This test + is dedicated to this functionality. It uses user-defined actions and + user-defined handler. + + 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 + + +/* + Allocate user-defined action: + + Allocate as many user-defined actions as possible. + Note: We need to have at least usr1..usr6 action which are used in + subsequent tests. + +*/ + +const unsigned num_usr_actions = 6; +sc_actions usr_actions[num_usr_actions]; + +sc_actions& usr1 = usr_actions[0]; +sc_actions& usr2 = usr_actions[1]; +sc_actions& usr3 = usr_actions[2]; +sc_actions& usr4 = usr_actions[3]; +sc_actions& usr5 = usr_actions[4]; +sc_actions& usr6 = usr_actions[5]; + +const char* id1 = "ID1"; +const char* id2 = "ID2"; +const char* id3 = "ID3"; +const char* id4 = "ID4"; + + +void allocate_user_actions( ) +{ + sc_actions usr; + for (unsigned int n=0; n<1000; n++) { + usr = sc_report_handler::get_new_action_id(); + if ( usr == SC_UNSPECIFIED ) { + cout << "We got " << n << " user-defined actions\n"; + break; + } + // make sure we don't get the same usr action again and that it + // is really new + sc_assert (usr!=SC_UNSPECIFIED && usr!=SC_DO_NOTHING && usr!=SC_THROW && + usr!=SC_LOG && usr!=SC_DISPLAY && usr!=SC_CACHE_REPORT && + usr!=SC_STOP && usr!=SC_ABORT ); + if ( n < num_usr_actions ) { + // save for later use + usr_actions[n] = usr; + for (unsigned int i=0; i "; + for (int n=0; n<32; n++) { + sc_actions action = actions & 1<") << endl; +} + + +/* + Test selection schema id x severity : + + ID + Severity 1 2 3 + + info usr2 usr1 usr5* + warning usr3 usr1 usr3 + error usr4 usr1 usr1* + fatal usr5 usr1 usr5 + + usr1..usr5 are user-defined actions + + ID 1 selects by severity rule which has lowest priority, + ID 2 selects by ID rule, + ID 3 selects by individual severity x ID rules (highest priority) + +*/ +void set_rules() +{ + // set rule 1: by severity + sc_report_handler::set_actions( SC_INFO, usr2 ); + sc_report_handler::set_actions( SC_WARNING, usr3 ); + sc_report_handler::set_actions( SC_ERROR, usr4 ); + sc_report_handler::set_actions( SC_FATAL, usr5 ); + + // set rule 2: by id + sc_report_handler::set_actions( id2, usr1 ); + + // set rule 3: by (id,severity) + sc_report_handler::set_actions ( id3, SC_INFO, usr5 ); + sc_report_handler::set_actions ( id3, SC_ERROR, usr1 ); +} +void query_rules( const char* id ) +{ + sc_report_handler::report( SC_INFO, id, "extra_msg_for_info", "no_specific_file", 0); + sc_report_handler::report( SC_WARNING, id, "extra_msg_for_warning","no_specific_file", 1); + sc_report_handler::report( SC_ERROR, id, "extra_msg_for_error", "no_specific_file", 2); + sc_report_handler::report( SC_FATAL, id, "extra_msg_for_fatal", "no_specific_file", 3); + cout << endl; +} +void query_rules() +{ + query_rules( id1 ); + query_rules( id2 ); + query_rules( id3 ); +} + + +int sc_main(int,char**) +{ + allocate_user_actions(); + sc_report_handler::set_handler( &dump_all_handler ); + + // disable automatic stop + sc_report_handler::stop_after( SC_ERROR, 0 ); + sc_report_handler::stop_after( SC_FATAL, 0 ); + + // Don't emit error|fatal for ID4 because this would + // terminate the simulation. + cout << "Default settings for ID4\n"; + query_rules( id4 ); + + // check default setting of rules + cout << "Specific settings for ID1..ID3\n"; + set_rules(); + query_rules(); + + // temporarily suppress usr4: + // - check which actions are emitted + // - check that suppress() restores old state + // - check return value of suppress(.) + cout << "temporarily suppress usr4\n"; + sc_start( 1,SC_NS ); + sc_report_handler::suppress( usr3 ); + sc_assert( sc_report_handler::suppress( usr4 ) == usr3 ); + query_rules( id1 ); + sc_assert( sc_report_handler::suppress() == usr4 ); + query_rules( id1 ); + + // temporarily force usr1: same checking as with suppress + cout << "temporarily force usr1\n"; + sc_start( 1,SC_NS ); + sc_report_handler::force( usr2 ); + sc_assert( sc_report_handler::force( usr1 ) == usr2 ); + query_rules( id1 ); + sc_assert( sc_report_handler::force() == usr1 ); + query_rules( id1 ); + + // temporarily force usr1: same checking as with suppress + cout << "temporarily suppress {usr3,usr4} and force {usr1,usr3}\n"; + sc_start( 1,SC_NS ); + sc_report_handler::force ( usr1|usr3 ); + sc_report_handler::suppress( usr3|usr4 ); + query_rules( id1 ); + sc_report_handler::force(); + sc_report_handler::suppress(); + query_rules( id1 ); + + return 0; +} diff --git a/src/systemc/tests/systemc/utils/sc_report/action_selection/golden/action_selection.log b/src/systemc/tests/systemc/utils/sc_report/action_selection/golden/action_selection.log new file mode 100644 index 000000000..e24a895b4 --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_report/action_selection/golden/action_selection.log @@ -0,0 +1,97 @@ +SystemC Simulation +We got 24 user-defined actions +Default settings for ID4 +report: ID4 INFO --> log display + msg=extra_msg_for_info file=no_specific_file line 0 time=0 s process= +report: ID4 WARNING --> log display + msg=extra_msg_for_warning file=no_specific_file line 1 time=0 s process= +report: ID4 ERROR --> throw log cache-report + msg=extra_msg_for_error file=no_specific_file line 2 time=0 s process= +report: ID4 FATAL --> log display cache-report abort + msg=extra_msg_for_fatal file=no_specific_file line 3 time=0 s process= + +Specific settings for ID1..ID3 +report: ID1 INFO --> usr2 + msg=extra_msg_for_info file=no_specific_file line 0 time=0 s process= +report: ID1 WARNING --> usr3 + msg=extra_msg_for_warning file=no_specific_file line 1 time=0 s process= +report: ID1 ERROR --> usr4 + msg=extra_msg_for_error file=no_specific_file line 2 time=0 s process= +report: ID1 FATAL --> usr5 + msg=extra_msg_for_fatal file=no_specific_file line 3 time=0 s process= + +report: ID2 INFO --> usr1 + msg=extra_msg_for_info file=no_specific_file line 0 time=0 s process= +report: ID2 WARNING --> usr1 + msg=extra_msg_for_warning file=no_specific_file line 1 time=0 s process= +report: ID2 ERROR --> usr1 + msg=extra_msg_for_error file=no_specific_file line 2 time=0 s process= +report: ID2 FATAL --> usr1 + msg=extra_msg_for_fatal file=no_specific_file line 3 time=0 s process= + +report: ID3 INFO --> usr5 + msg=extra_msg_for_info file=no_specific_file line 0 time=0 s process= +report: ID3 WARNING --> usr3 + msg=extra_msg_for_warning file=no_specific_file line 1 time=0 s process= +report: ID3 ERROR --> usr1 + msg=extra_msg_for_error file=no_specific_file line 2 time=0 s process= +report: ID3 FATAL --> usr5 + msg=extra_msg_for_fatal file=no_specific_file line 3 time=0 s process= + +temporarily suppress usr4 +report: ID1 INFO --> usr2 + msg=extra_msg_for_info file=no_specific_file line 0 time=1 ns process= +report: ID1 WARNING --> usr3 + msg=extra_msg_for_warning file=no_specific_file line 1 time=1 ns process= +report: ID1 ERROR --> + msg=extra_msg_for_error file=no_specific_file line 2 time=1 ns process= +report: ID1 FATAL --> usr5 + msg=extra_msg_for_fatal file=no_specific_file line 3 time=1 ns process= + +report: ID1 INFO --> usr2 + msg=extra_msg_for_info file=no_specific_file line 0 time=1 ns process= +report: ID1 WARNING --> usr3 + msg=extra_msg_for_warning file=no_specific_file line 1 time=1 ns process= +report: ID1 ERROR --> usr4 + msg=extra_msg_for_error file=no_specific_file line 2 time=1 ns process= +report: ID1 FATAL --> usr5 + msg=extra_msg_for_fatal file=no_specific_file line 3 time=1 ns process= + +temporarily force usr1 +report: ID1 INFO --> usr1 usr2 + msg=extra_msg_for_info file=no_specific_file line 0 time=2 ns process= +report: ID1 WARNING --> usr1 usr3 + msg=extra_msg_for_warning file=no_specific_file line 1 time=2 ns process= +report: ID1 ERROR --> usr1 usr4 + msg=extra_msg_for_error file=no_specific_file line 2 time=2 ns process= +report: ID1 FATAL --> usr1 usr5 + msg=extra_msg_for_fatal file=no_specific_file line 3 time=2 ns process= + +report: ID1 INFO --> usr2 + msg=extra_msg_for_info file=no_specific_file line 0 time=2 ns process= +report: ID1 WARNING --> usr3 + msg=extra_msg_for_warning file=no_specific_file line 1 time=2 ns process= +report: ID1 ERROR --> usr4 + msg=extra_msg_for_error file=no_specific_file line 2 time=2 ns process= +report: ID1 FATAL --> usr5 + msg=extra_msg_for_fatal file=no_specific_file line 3 time=2 ns process= + +temporarily suppress {usr3,usr4} and force {usr1,usr3} +report: ID1 INFO --> usr1 usr2 usr3 + msg=extra_msg_for_info file=no_specific_file line 0 time=3 ns process= +report: ID1 WARNING --> usr1 usr3 + msg=extra_msg_for_warning file=no_specific_file line 1 time=3 ns process= +report: ID1 ERROR --> usr1 usr3 + msg=extra_msg_for_error file=no_specific_file line 2 time=3 ns process= +report: ID1 FATAL --> usr1 usr3 usr5 + msg=extra_msg_for_fatal file=no_specific_file line 3 time=3 ns process= + +report: ID1 INFO --> usr2 + msg=extra_msg_for_info file=no_specific_file line 0 time=3 ns process= +report: ID1 WARNING --> usr3 + msg=extra_msg_for_warning file=no_specific_file line 1 time=3 ns process= +report: ID1 ERROR --> usr4 + msg=extra_msg_for_error file=no_specific_file line 2 time=3 ns process= +report: ID1 FATAL --> usr5 + msg=extra_msg_for_fatal file=no_specific_file line 3 time=3 ns process= + diff --git a/src/systemc/tests/systemc/utils/sc_report/cached/cached.cpp b/src/systemc/tests/systemc/utils/sc_report/cached/cached.cpp new file mode 100644 index 000000000..8bddd9001 --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_report/cached/cached.cpp @@ -0,0 +1,227 @@ +/***************************************************************************** + + 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 -- caching of report in process context + + 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 + + +/* + + id1 has actions: display, cache + id2 has actions: display + + Issue report in this order in the following contextes: + + retrieve report from thread1 -> no report + retrieve report from method1 -> no report + retrieve report from global -> no report + + info/id1/a -> thread1 + warning/id1/b -> method1 + info/id1/c -> global + warning/id1/d -> thread2 + info/id1/e -> method2 + + info/id2/f -> thread1 + warning/id2/g -> method1 + info/id2/h -> global + warning/id2/i -> thread2 + info/id2/j -> method2 + + retrieve report from thread1 -> info/id1/a + retrieve report from method1 -> warning/id1/b + retrieve report from global -> info/id1/c + retrieve report from thread2 -> no report + retrieve report from method2 -> no report +*/ + + +static const char* severity2str[] = { + "INFO", "WARNING", "ERROR", "FATAL", "UNKNOWN_SEVERITY" +}; + +void dump_cached_report(const char* ctx) +{ + sc_report* report = sc_report_handler::get_cached_report(); + cout << sc_time_stamp() + << " from context '" << ctx << "' "; + if (report) { + cout << report->get_msg_type() + << " " << severity2str[ report->get_severity() ] << endl + << " msg=" << report->get_msg() + << " file=" << report->get_file_name() + << " line " << report->get_line_number() + << " time=" << report->get_time(); + const char* name = report->get_process_name(); + cout << " process=" << (name ? name : "") << endl; + } else { + cout << "\n"; + } + sc_report_handler::clear_cached_report(); +} + +SC_MODULE( M ) +{ + sc_in emit; // 1: emit, 0: dump cahced report + sc_in id; + sc_in ofs; + sc_event t1, t2, m1, m2; + + SC_CTOR( M ) { + SC_THREAD( thread1 ); + sensitive << t1; + dont_initialize(); + + SC_THREAD( thread2 ); + sensitive << t2; + dont_initialize(); + + SC_METHOD( method1 ); + sensitive << m1; + dont_initialize(); + + SC_METHOD( method2 ); + sensitive << m2; + dont_initialize(); + } + void thread1() { + while(1) { + if (emit) + sc_report_handler::report(SC_INFO, id.read(), "aa"+ofs, "file_t1", 110+ofs); + else + dump_cached_report("t1"); + wait(); + } + } + void method1() { + if (emit) + sc_report_handler::report(SC_WARNING, id.read(), "bb"+ofs, "file_m1", 210+ofs); + else + dump_cached_report("m1"); + } + void thread2() { + while(1) { + if (emit) + sc_report_handler::report(SC_WARNING, id.read(), "dd"+ofs, "file_t2", 120+ofs); + else + dump_cached_report("t2"); + wait(); + } + } + void method2() { + if (emit) + sc_report_handler::report(SC_INFO, id.read(), "ee"+ofs, "file_m2", 220+ofs); + else + dump_cached_report("m2"); + } +}; + + +int sc_main(int,char**) +{ + sc_report_handler::set_actions( "ID1", SC_DISPLAY | SC_CACHE_REPORT ); + sc_report_handler::set_actions( "ID2", SC_DISPLAY ); + + sc_signal emit; + sc_signal ID; + sc_signal ofs; + M uut("M"); + uut( emit,ID,ofs ); + + emit = 0; + ID="ID3"; + ofs=0; + sc_start( 1,SC_NS ); + + // dump initial cached reports + cout << "Initial status:\n"; + uut.t1.notify(); + uut.m1.notify(); + uut.t2.notify(); + uut.m2.notify(); + dump_cached_report("global"); + sc_start( 1, SC_NS ); + + // emit report ID1 everywhere + emit = 1; + ID="ID1"; + sc_start( 1,SC_NS ); + cout << "\n\nEmit ID1\n"; + uut.t1.notify(); + uut.m1.notify(); + sc_start( 1, SC_NS ); + sc_report_handler::report(SC_INFO, ID.read(), "cc", "file_g", 300); + uut.t2.notify(); + uut.m2.notify(); + sc_start( 1, SC_NS ); + + // emit report ID2 everywhere + cout << "\n\nEmit ID2\n"; + emit = 1; + ID="ID2"; + ofs=1; + sc_start( 1,SC_NS ); + uut.t1.notify(); + uut.m1.notify(); + sc_start( 1, SC_NS ); + sc_report_handler::report(SC_INFO, ID.read(), "c", "file_g", 310); + uut.t2.notify(); + uut.m2.notify(); + sc_start( 1, SC_NS ); + + // dump cached reports: should be all ID1 + emit = 0; + sc_start( 1,SC_NS ); + cout << "\n\nStatus:\n"; + uut.t1.notify(); + uut.t2.notify(); + uut.m1.notify(); + uut.m2.notify(); + dump_cached_report("global"); + sc_start( 1, SC_NS ); + + // dump cached reports again + // (should be all empty because dump clears cached report) + cout << "\n\nStatus:\n"; + uut.t1.notify(); + uut.t2.notify(); + uut.m1.notify(); + uut.m2.notify(); + dump_cached_report("global"); + sc_start( 1, SC_NS ); + + return 0; +} diff --git a/src/systemc/tests/systemc/utils/sc_report/cached/golden/cached.log b/src/systemc/tests/systemc/utils/sc_report/cached/golden/cached.log new file mode 100644 index 000000000..7b0aa9b80 --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_report/cached/golden/cached.log @@ -0,0 +1,62 @@ +SystemC Simulation +Initial status: +1 ns from context 'global' +1 ns from context 'm1' +1 ns from context 'm2' +1 ns from context 't1' +1 ns from context 't2' + + +Emit ID1 + +Warning: ID1: bb +In file: +In process: M.method1 @ 3 ns + +Info: ID1: aa + +Info: ID1: cc + +Info: ID1: ee + +Warning: ID1: dd +In file: +In process: M.thread2 @ 4 ns + + +Emit ID2 + +Warning: ID2: b +In file: +In process: M.method1 @ 6 ns + +Info: ID2: a + +Info: ID2: c + +Info: ID2: e + +Warning: ID2: d +In file: +In process: M.thread2 @ 7 ns + + +Status: +9 ns from context 'global' ID1 INFO + msg=cc file=file_g line 300 time=4 ns process= +9 ns from context 'm1' ID1 WARNING + msg=bb file=file_m1 line 210 time=3 ns process=M.method1 +9 ns from context 'm2' ID1 INFO + msg=ee file=file_m2 line 220 time=4 ns process=M.method2 +9 ns from context 't1' ID1 INFO + msg=aa file=file_t1 line 110 time=3 ns process=M.thread1 +9 ns from context 't2' ID1 WARNING + msg=dd file=file_t2 line 120 time=4 ns process=M.thread2 + + +Status: +10 ns from context 'global' +10 ns from context 'm1' +10 ns from context 'm2' +10 ns from context 't1' +10 ns from context 't2' 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: + +Info: ID1: after log is opened + +Warning: ID2: after log is opened +In file: + +Error: ID1: after log is opened +In file: + +Fatal: ID2: after log is opened +In file: + +Error: ID1: after log is opened +In file: + +Info: ID1: after log is opened + +Warning: ID2: after log is opened +In file: +In process: uut.method1 @ 20 ns + +Error: ID1: after log is opened +In file: +In process: uut.method1 @ 20 ns + +Fatal: ID2: after log is opened +In file: +In process: uut.method1 @ 20 ns + +Info: ID2: after log is opened + +Warning: ID1: after log is opened +In file: +In process: uut.thread1 @ 30 ns + +Error: ID2: after log is opened +In file: +In process: uut.thread1 @ 30 ns + +Fatal: ID1: after log is opened +In file: +In process: uut.thread1 @ 30 ns + +Info: ID1: after log is closed + +Warning: ID1: after log is closed +In file: + + +Dump the logfile +0 s: Info: ID1: after log is opened +0 s: Warning: ID2: after log is opened +In file: +0 s: Error: ID1: after log is opened +In file: +0 s: Fatal: ID2: after log is opened +In file: +10 ns: Error: ID1: after log is opened +In file: +20 ns: Info: ID1: after log is opened +20 ns: Warning: ID2: after log is opened +In file: +In process: uut.method1 @ 20 ns +20 ns: Error: ID1: after log is opened +In file: +In process: uut.method1 @ 20 ns +20 ns: Fatal: ID2: after log is opened +In file: +In process: uut.method1 @ 20 ns +30 ns: Info: ID2: after log is opened +30 ns: Warning: ID1: after log is opened +In file: +In process: uut.thread1 @ 30 ns +30 ns: Error: ID2: after log is opened +In file: +In process: uut.thread1 @ 30 ns +30 ns: Fatal: ID1: after log is opened +In file: +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 + +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(c); + } + fclose( log) ; + + return 0; +} diff --git a/src/systemc/tests/systemc/utils/sc_report/test01/golden/test01.log b/src/systemc/tests/systemc/utils/sc_report/test01/golden/test01.log new file mode 100644 index 000000000..e42609dd4 --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_report/test01/golden/test01.log @@ -0,0 +1,45 @@ +SystemC Simulation + +Info: (I804) /IEEE_Std_1666/deprecated: integer report ids are deprecated, use string values: sc_report::register_id() +bogus message +0 +1 +0 + +Info: (I9999) bogus message: infos ... + +Info: (I9999) bogus message: infos not suppressed + +Info: (I9999) bogus message: not suppressed + +Warning: (W9999) bogus message: warnings ... +In file: + +Warning: (W9999) bogus message: warnings not suppressed +In file: + +Warning: (W9999) bogus message: not suppressed +In file: + +caught exception +Error: (E9999) bogus message: do make warnings errors +In file: + +Warning: (W9999) bogus message: do not make warnings errors +In file: + +caught exception +Error: (E9999) bogus message: errors ... +In file: + +caught exception +Error: (E9999) bogus message: cannot be suppressed +In file: + +Info: (I804) /IEEE_Std_1666/deprecated: You can turn off warnings about + IEEE 1666 deprecated features by placing this method call + as the first statement in your sc_main() function: + + sc_core::sc_report_handler::set_actions( "/IEEE_Std_1666/deprecated", + sc_core::SC_DO_NOTHING ); + diff --git a/src/systemc/tests/systemc/utils/sc_report/test01/test01.cpp b/src/systemc/tests/systemc/utils/sc_report/test01/test01.cpp new file mode 100644 index 000000000..88f5a76af --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_report/test01/test01.cpp @@ -0,0 +1,109 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + test01.cpp -- + + Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +// test of reporting -- API + +#include "systemc.h" + +int +sc_main( int, char*[] ) +{ + const int MY_ID = 9999; + + sc_report::register_id( MY_ID, "bogus message" ); + cout << sc_report::get_message( MY_ID ) << endl; + cout << sc_report::is_suppressed( MY_ID ) << endl; + sc_report::suppress_id( MY_ID, true ); + cout << sc_report::is_suppressed( MY_ID ) << endl; + sc_report::suppress_id( MY_ID, false ); + cout << sc_report::is_suppressed( MY_ID ) << endl; + + SC_REPORT_INFO( MY_ID, "infos ..." ); + sc_report::suppress_infos( true ); + SC_REPORT_INFO( MY_ID, "infos suppressed" ); + sc_report::suppress_infos( false ); + SC_REPORT_INFO( MY_ID, "infos not suppressed" ); + sc_report::suppress_id( MY_ID, true ); + SC_REPORT_INFO( MY_ID, "suppressed" ); + sc_report::suppress_id( MY_ID, false ); + SC_REPORT_INFO( MY_ID, "not suppressed" ); + + SC_REPORT_WARNING( MY_ID, "warnings ..." ); + sc_report::suppress_warnings( true ); + SC_REPORT_WARNING( MY_ID, "warnings suppressed" ); + sc_report::suppress_warnings( false ); + SC_REPORT_WARNING( MY_ID, "warnings not suppressed" ); + sc_report::suppress_id( MY_ID, true ); + SC_REPORT_WARNING( MY_ID, "suppressed" ); + sc_report::suppress_id( MY_ID, false ); + SC_REPORT_WARNING( MY_ID, "not suppressed" ); + + sc_report::make_warnings_errors( true ); + try { + SC_REPORT_WARNING( MY_ID, "do make warnings errors" ); + } + catch( sc_report x ) { + cout << "\ncaught exception" << endl; + cout << x.what() << endl; + } + sc_report::make_warnings_errors( false ); + try { + SC_REPORT_WARNING( MY_ID, "do not make warnings errors" ); + } + catch( sc_report x ) { + cout << "\ncaught exception" << endl; + cout << x.what() << endl; + } + + try { + SC_REPORT_ERROR( MY_ID, "errors ..." ); + } + catch( sc_report x ) { + cout << "\ncaught exception" << endl; + cout << x.what() << endl; + } + sc_report::suppress_id( MY_ID, true ); + try { + SC_REPORT_ERROR( MY_ID, "cannot be suppressed" ); + } + catch( sc_report x ) { + cout << "\ncaught exception" << endl; + cout << x.what() << endl; + } + + return 0; +} diff --git a/src/systemc/tests/systemc/utils/sc_report/test02/golden/test02.log b/src/systemc/tests/systemc/utils/sc_report/test02/golden/test02.log new file mode 100644 index 000000000..a4a3c22b1 --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_report/test02/golden/test02.log @@ -0,0 +1,27 @@ +SystemC Simulation + +Info: (I804) /IEEE_Std_1666/deprecated: integer report ids are deprecated, use string values: sc_report::register_id() + +caught exception +Error: (E800) register_id failed: invalid report id +In file: + +caught exception +Error: (E800) register_id failed: invalid report message +In file: + +caught exception +Error: (E800) register_id failed: report id already exists +In file: + +unknown id + +0 + +Info: (I804) /IEEE_Std_1666/deprecated: You can turn off warnings about + IEEE 1666 deprecated features by placing this method call + as the first statement in your sc_main() function: + + sc_core::sc_report_handler::set_actions( "/IEEE_Std_1666/deprecated", + sc_core::SC_DO_NOTHING ); + diff --git a/src/systemc/tests/systemc/utils/sc_report/test02/test02.cpp b/src/systemc/tests/systemc/utils/sc_report/test02/test02.cpp new file mode 100644 index 000000000..c72871006 --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_report/test02/test02.cpp @@ -0,0 +1,80 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + test02.cpp -- + + Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +// test of reporting -- implementation + +#include "systemc.h" + +int +sc_main( int, char*[] ) +{ + const int MY_ID = 9999; + + try { + sc_report::register_id( -1, "first try" ); + } + catch( sc_report x ) { + cout << "\ncaught exception" << endl; + cout << x.what() << endl; + } + + try { + sc_report::register_id( MY_ID, 0 ); + } + catch( sc_report x ) { + cout << "\ncaught exception" << endl; + cout << x.what() << endl; + } + + try { + sc_report::register_id( MY_ID, "bogus message" ); + sc_report::register_id( MY_ID, "another bogus message" ); + } + catch( sc_report x ) { + cout << "\ncaught exception" << endl; + cout << x.what() << endl; + } + + cout << endl; + cout << sc_report::get_message( 1234 ) << endl; + + sc_report::suppress_id( 4321, true ); + cout << endl; + cout << sc_report::is_suppressed( 4321 ) << endl; + + return 0; +} diff --git a/src/systemc/tests/systemc/utils/sc_report/test03/golden/test03.log b/src/systemc/tests/systemc/utils/sc_report/test03/golden/test03.log new file mode 100644 index 000000000..f2e6178c3 --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_report/test03/golden/test03.log @@ -0,0 +1,10 @@ +SystemC Simulation + +Fatal: Oh no!: A bad thing has happened +In file: +In process: dut.thread @ 1 ns + +Fatal: Oh no!: A bad thing has happened +In file: +In process: dut.thread @ 2 ns +Program completed diff --git a/src/systemc/tests/systemc/utils/sc_report/test03/test03.cpp b/src/systemc/tests/systemc/utils/sc_report/test03/test03.cpp new file mode 100644 index 000000000..79aafea54 --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_report/test03/test03.cpp @@ -0,0 +1,76 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + test03.cpp -- Test of disabling of SC_FATAL + + Original Author: Andy Goodrich, Forte Design Systems, Inc., 2005-12-12 + + *****************************************************************************/ + +/***************************************************************************** + + 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(DUT) +{ + SC_CTOR(DUT) + { + SC_CTHREAD(thread,m_clk.pos()); + reset_signal_is(m_reset, true); + } + void thread() + { + sc_report_handler::set_actions(SC_FATAL,SC_DISPLAY); + sc_report_handler::stop_after(SC_FATAL,-1); + for (;;) + { + wait(); + SC_REPORT_FATAL("Oh no!","A bad thing has happened"); + } + } + sc_in m_clk; + sc_in m_reset; +}; +int sc_main(int argc, char* argv[]) +{ + sc_clock clock; + DUT dut("dut"); + sc_signal reset; + + dut.m_clk(clock); + dut.m_reset(reset); + + reset = true; + sc_start(1, SC_NS); + reset = false; + sc_start(2, SC_NS); + + cout << "Program completed" << endl; + return 0; +} diff --git a/src/systemc/tests/systemc/utils/sc_report/test04/empty_msg_id.cpp b/src/systemc/tests/systemc/utils/sc_report/test04/empty_msg_id.cpp new file mode 100644 index 000000000..4fd0a9d94 --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_report/test04/empty_msg_id.cpp @@ -0,0 +1,57 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + empty_msg_id.cpp -- Test for empty message IDs + + Original Author: Philipp A. Hartmann, OFFIS, 2013-09-17 + + *****************************************************************************/ + +#include + +using std::cout; +using std::endl; +using sc_core::sc_report_handler; + +static const char * null_msg = NULL; +static const char * empty_msg = ""; + +int sc_main(int,char*[]) +{ + SC_REPORT_INFO( empty_msg, "empty msg id" ); + cout << sc_report_handler::get_count(empty_msg) << endl; + sc_assert( sc_report_handler::get_count(empty_msg) == 1 ); + + SC_REPORT_INFO( 1, "empty msg id" ); // integer ID + cout << sc_report_handler::get_count("") << endl; + sc_assert( sc_report_handler::get_count(empty_msg) == 2 ); + + + SC_REPORT_INFO( null_msg, "null msg id" ); + cout << sc_report_handler::get_count(null_msg) << endl; + sc_assert( sc_report_handler::get_count(null_msg) == 1 ); + + SC_REPORT_INFO( 0, "another (integer) null msg id" ); + cout << sc_report_handler::get_count(null_msg) << endl; + sc_assert( sc_report_handler::get_count(null_msg) == 2 ); + + return 0; +} diff --git a/src/systemc/tests/systemc/utils/sc_report/test04/golden/empty_msg_id.log b/src/systemc/tests/systemc/utils/sc_report/test04/golden/empty_msg_id.log new file mode 100644 index 000000000..20a630dec --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_report/test04/golden/empty_msg_id.log @@ -0,0 +1,13 @@ +SystemC Simulation + +Info: (I1) : empty msg id +1 + +Info: (I1) : empty msg id +2 + +Info: (I0) unknown error: null msg id +1 + +Info: (I0) unknown error: another (integer) null msg id +2 diff --git a/src/systemc/tests/systemc/utils/sc_report/test05/catch_actions.cpp b/src/systemc/tests/systemc/utils/sc_report/test05/catch_actions.cpp new file mode 100644 index 000000000..cdc94543b --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_report/test05/catch_actions.cpp @@ -0,0 +1,93 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + catch_actions.cpp -- Test for catch actions used with a custom report handler + + Original Author: Philipp A. Hartmann, Intel, 2017-01-22 + + *****************************************************************************/ + +#include + +using std::cout; +using std::endl; +using sc_core::sc_actions; +using sc_core::SC_DISPLAY; +using sc_core::SC_ERROR; +using sc_core::SC_LOG; +using sc_core::SC_THROW; +using sc_core::sc_report; +using sc_core::sc_report_handler; + +/* anonymous */ namespace { +bool last_report_thrown = false; +void custom_handler(const sc_report& rep, const sc_actions& actions) +{ + if ( actions & SC_DISPLAY ) { + cout << endl + // if last_report_thrown is set, we're in a catch action + << (last_report_thrown ? "[caught] " : "[normal] ") + << sc_core::sc_report_compose_message(rep) + << endl; + } + + // only log errors from catch actions + if (rep.get_severity() == SC_ERROR) { + if (actions & SC_LOG) { + sc_assert( !(actions & SC_THROW) ); + } else { + sc_assert( actions & SC_THROW ); + } + } + + // cache SC_THROW state of current report + last_report_thrown = (actions & SC_THROW); + + // delegate other actions to default handler + sc_report_handler::default_handler(rep, actions & ~SC_DISPLAY); + +} /* custom_handler */ +} /* anonymous namespace */ + +int sc_main(int,char*[]) +{ + // extended report logging, currently not checked in verify.pl + sc_report_handler::set_log_file_name("catch_actions.ext.log"); + + sc_report_handler::set_handler(custom_handler); + SC_REPORT_INFO("catch_actions", "prepared custom handler"); + sc_assert(last_report_thrown == false); + + SC_REPORT_INFO("catch_actions", "preparing catch actions"); + sc_actions act = sc_report_handler::set_catch_actions(SC_DISPLAY | SC_LOG); + sc_assert(act == SC_DISPLAY); + sc_assert(sc_report_handler::get_catch_actions() == (SC_DISPLAY | SC_LOG)); + + SC_REPORT_INFO("catch_actions", "only log errors from catch actions"); + act = sc_report_handler::set_actions + (SC_ERROR, (sc_core::SC_DEFAULT_ERROR_ACTIONS & ~SC_LOG)); + + // real test + SC_REPORT_ERROR("catch_actions", "throwing an exception"); + + // not reached + return 0; +} diff --git a/src/systemc/tests/systemc/utils/sc_report/test05/golden/catch_actions.log b/src/systemc/tests/systemc/utils/sc_report/test05/golden/catch_actions.log new file mode 100644 index 000000000..868e965f2 --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_report/test05/golden/catch_actions.log @@ -0,0 +1,10 @@ +SystemC Simulation + +[normal] Info: catch_actions: prepared custom handler + +[normal] Info: catch_actions: preparing catch actions + +[normal] Info: catch_actions: only log errors from catch actions + +[caught] Error: catch_actions: throwing an exception +In file: -- cgit v1.2.3