diff options
author | Gabe Black <gabeblack@google.com> | 2018-05-24 01:37:55 -0700 |
---|---|---|
committer | Gabe Black <gabeblack@google.com> | 2018-08-08 10:09:54 +0000 |
commit | 16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f (patch) | |
tree | 7b6faaacb4574a555e561534aa4a8508c0624c32 /src/systemc/tests/systemc/utils | |
parent | 7235d3b5211d0ba8f528d930a4c1e7ad62eec51a (diff) | |
download | gem5-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')
34 files changed, 2458 insertions, 0 deletions
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 <systemc.h> + + +/* + 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<n; i++) { + // lso check that is is new + sc_assert( usr!=usr_actions[i]); + } + } + } +} + + +static const char* severity2str[] = { + "INFO", "WARNING", "ERROR", "FATAL", "UNKNOWN_SEVERITY" +}; + +// custom handler which is used to dump out reports and actions +void dump_all_handler( const sc_report& report, const sc_actions& actions) +{ + // dump out report + cout << "report: " << report.get_msg_type() + << " " << severity2str[ report.get_severity() ]; + cout << " --> "; + for (int n=0; n<32; n++) { + sc_actions action = actions & 1<<n; + if (action) { + cout << " "; + switch(action) { + case SC_UNSPECIFIED: cout << "unspecified"; break; + case SC_DO_NOTHING: cout << "do-nothing"; break; + case SC_THROW: cout << "throw"; break; + case SC_LOG: cout << "log"; break; + case SC_DISPLAY: cout << "display"; break; + case SC_CACHE_REPORT: cout << "cache-report"; break; + case SC_INTERRUPT: cout << "interrupt"; break; + case SC_STOP: cout << "stop"; break; + case SC_ABORT: cout << "abort"; break; + default: + bool found=false; + for (unsigned int u=0; u<num_usr_actions; u++) + if (action == usr_actions[u]) { + cout << "usr" << u+1; + found=true; + break; + } + if (!found) + cout << "UNKNOWN"; + } + } + } + cout << endl; + cout << " 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 : "<none>") << 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=<none> +report: ID4 WARNING --> log display + msg=extra_msg_for_warning file=no_specific_file line 1 time=0 s process=<none> +report: ID4 ERROR --> throw log cache-report + msg=extra_msg_for_error file=no_specific_file line 2 time=0 s process=<none> +report: ID4 FATAL --> log display cache-report abort + msg=extra_msg_for_fatal file=no_specific_file line 3 time=0 s process=<none> + +Specific settings for ID1..ID3 +report: ID1 INFO --> usr2 + msg=extra_msg_for_info file=no_specific_file line 0 time=0 s process=<none> +report: ID1 WARNING --> usr3 + msg=extra_msg_for_warning file=no_specific_file line 1 time=0 s process=<none> +report: ID1 ERROR --> usr4 + msg=extra_msg_for_error file=no_specific_file line 2 time=0 s process=<none> +report: ID1 FATAL --> usr5 + msg=extra_msg_for_fatal file=no_specific_file line 3 time=0 s process=<none> + +report: ID2 INFO --> usr1 + msg=extra_msg_for_info file=no_specific_file line 0 time=0 s process=<none> +report: ID2 WARNING --> usr1 + msg=extra_msg_for_warning file=no_specific_file line 1 time=0 s process=<none> +report: ID2 ERROR --> usr1 + msg=extra_msg_for_error file=no_specific_file line 2 time=0 s process=<none> +report: ID2 FATAL --> usr1 + msg=extra_msg_for_fatal file=no_specific_file line 3 time=0 s process=<none> + +report: ID3 INFO --> usr5 + msg=extra_msg_for_info file=no_specific_file line 0 time=0 s process=<none> +report: ID3 WARNING --> usr3 + msg=extra_msg_for_warning file=no_specific_file line 1 time=0 s process=<none> +report: ID3 ERROR --> usr1 + msg=extra_msg_for_error file=no_specific_file line 2 time=0 s process=<none> +report: ID3 FATAL --> usr5 + msg=extra_msg_for_fatal file=no_specific_file line 3 time=0 s process=<none> + +temporarily suppress usr4 +report: ID1 INFO --> usr2 + msg=extra_msg_for_info file=no_specific_file line 0 time=1 ns process=<none> +report: ID1 WARNING --> usr3 + msg=extra_msg_for_warning file=no_specific_file line 1 time=1 ns process=<none> +report: ID1 ERROR --> + msg=extra_msg_for_error file=no_specific_file line 2 time=1 ns process=<none> +report: ID1 FATAL --> usr5 + msg=extra_msg_for_fatal file=no_specific_file line 3 time=1 ns process=<none> + +report: ID1 INFO --> usr2 + msg=extra_msg_for_info file=no_specific_file line 0 time=1 ns process=<none> +report: ID1 WARNING --> usr3 + msg=extra_msg_for_warning file=no_specific_file line 1 time=1 ns process=<none> +report: ID1 ERROR --> usr4 + msg=extra_msg_for_error file=no_specific_file line 2 time=1 ns process=<none> +report: ID1 FATAL --> usr5 + msg=extra_msg_for_fatal file=no_specific_file line 3 time=1 ns process=<none> + +temporarily force usr1 +report: ID1 INFO --> usr1 usr2 + msg=extra_msg_for_info file=no_specific_file line 0 time=2 ns process=<none> +report: ID1 WARNING --> usr1 usr3 + msg=extra_msg_for_warning file=no_specific_file line 1 time=2 ns process=<none> +report: ID1 ERROR --> usr1 usr4 + msg=extra_msg_for_error file=no_specific_file line 2 time=2 ns process=<none> +report: ID1 FATAL --> usr1 usr5 + msg=extra_msg_for_fatal file=no_specific_file line 3 time=2 ns process=<none> + +report: ID1 INFO --> usr2 + msg=extra_msg_for_info file=no_specific_file line 0 time=2 ns process=<none> +report: ID1 WARNING --> usr3 + msg=extra_msg_for_warning file=no_specific_file line 1 time=2 ns process=<none> +report: ID1 ERROR --> usr4 + msg=extra_msg_for_error file=no_specific_file line 2 time=2 ns process=<none> +report: ID1 FATAL --> usr5 + msg=extra_msg_for_fatal file=no_specific_file line 3 time=2 ns process=<none> + +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=<none> +report: ID1 WARNING --> usr1 usr3 + msg=extra_msg_for_warning file=no_specific_file line 1 time=3 ns process=<none> +report: ID1 ERROR --> usr1 usr3 + msg=extra_msg_for_error file=no_specific_file line 2 time=3 ns process=<none> +report: ID1 FATAL --> usr1 usr3 usr5 + msg=extra_msg_for_fatal file=no_specific_file line 3 time=3 ns process=<none> + +report: ID1 INFO --> usr2 + msg=extra_msg_for_info file=no_specific_file line 0 time=3 ns process=<none> +report: ID1 WARNING --> usr3 + msg=extra_msg_for_warning file=no_specific_file line 1 time=3 ns process=<none> +report: ID1 ERROR --> usr4 + msg=extra_msg_for_error file=no_specific_file line 2 time=3 ns process=<none> +report: ID1 FATAL --> usr5 + msg=extra_msg_for_fatal file=no_specific_file line 3 time=3 ns process=<none> + 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 <systemc.h> + + +/* + + 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 : "<none>") << endl; + } else { + cout << "<no cached report>\n"; + } + sc_report_handler::clear_cached_report(); +} + +SC_MODULE( M ) +{ + sc_in<bool> emit; // 1: emit, 0: dump cahced report + sc_in<const char*> id; + sc_in<bool> 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<bool> emit; + sc_signal<const char*> ID; + sc_signal<bool> 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' <no cached report> +1 ns from context 'm1' <no cached report> +1 ns from context 'm2' <no cached report> +1 ns from context 't1' <no cached report> +1 ns from context 't2' <no cached report> + + +Emit ID1 + +Warning: ID1: bb +In file: <removed by verify.pl> +In process: M.method1 @ 3 ns + +Info: ID1: aa + +Info: ID1: cc + +Info: ID1: ee + +Warning: ID1: dd +In file: <removed by verify.pl> +In process: M.thread2 @ 4 ns + + +Emit ID2 + +Warning: ID2: b +In file: <removed by verify.pl> +In process: M.method1 @ 6 ns + +Info: ID2: a + +Info: ID2: c + +Info: ID2: e + +Warning: ID2: d +In file: <removed by verify.pl> +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=<none> +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' <no cached report> +10 ns from context 'm1' <no cached report> +10 ns from context 'm2' <no cached report> +10 ns from context 't1' <no cached report> +10 ns from context 't2' <no cached report> 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; +} 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: <removed by verify.pl> + +Warning: (W9999) bogus message: warnings not suppressed +In file: <removed by verify.pl> + +Warning: (W9999) bogus message: not suppressed +In file: <removed by verify.pl> + +caught exception +Error: (E9999) bogus message: do make warnings errors +In file: <removed by verify.pl> + +Warning: (W9999) bogus message: do not make warnings errors +In file: <removed by verify.pl> + +caught exception +Error: (E9999) bogus message: errors ... +In file: <removed by verify.pl> + +caught exception +Error: (E9999) bogus message: cannot be suppressed +In file: <removed by verify.pl> + +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: <removed by verify.pl> + +caught exception +Error: (E800) register_id failed: invalid report message +In file: <removed by verify.pl> + +caught exception +Error: (E800) register_id failed: report id already exists +In file: <removed by verify.pl> + +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: <removed by verify.pl> +In process: dut.thread @ 1 ns + +Fatal: Oh no!: A bad thing has happened +In file: <removed by verify.pl> +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<bool> m_clk; + sc_in<bool> m_reset; +}; +int sc_main(int argc, char* argv[]) +{ + sc_clock clock; + DUT dut("dut"); + sc_signal<bool> 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 <systemc> + +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 <systemc> + +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: <removed by verify.pl> diff --git a/src/systemc/tests/systemc/utils/sc_vector/test01/golden/test01.log b/src/systemc/tests/systemc/utils/sc_vector/test01/golden/test01.log new file mode 100644 index 000000000..c05a2fb7c --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_vector/test01/golden/test01.log @@ -0,0 +1,12 @@ +SystemC Simulation +dut.sub_modules - sc_vector +dut.sub_modules_0 - sc_module +dut.sub_modules_1 - sc_module +dut.sub_modules_2 - sc_module +dut.sub_modules_3 - sc_module +dut.vector_0 - sc_vector +dut.vector_0_0 - sc_in +dut.vector_0_1 - sc_in +dut.vector_0_2 - sc_in +dut.vector_0_3 - sc_in +Program completed diff --git a/src/systemc/tests/systemc/utils/sc_vector/test01/test01.cpp b/src/systemc/tests/systemc/utils/sc_vector/test01/test01.cpp new file mode 100644 index 000000000..47cc9d45a --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_vector/test01/test01.cpp @@ -0,0 +1,84 @@ +/***************************************************************************** + + 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 -- Test sc_vector + + Original Author: Philipp A. Hartmann, OFFIS, 2010-01-10 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +#include "systemc.h" + +#include "sysc/utils/sc_vector.h" +using sc_core::sc_vector; + +SC_MODULE( sub_module ) +{ + sc_in<bool> in; + SC_CTOR(sub_module) {} +}; + +SC_MODULE( module ) +{ + // vector of sub-modules + sc_vector< sub_module > m_sub_vec; + + // vector of ports + sc_vector< sc_in<bool> > in_vec; + + module( sc_core::sc_module_name, unsigned n_sub ) + : m_sub_vec( "sub_modules", n_sub ) // set name prefix, and create sub-modules + // , in_vec() // use default constructor + // , in_vec( "in_vec" ) // set name prefix + { + // delayed initialisation of port vector + // here with default prefix sc_core::sc_gen_unique_name("vector") + in_vec.init( n_sub ); + + // bind ports of sub-modules -- sc_assemble_vector + sc_assemble_vector( m_sub_vec, &sub_module::in ).bind( in_vec ); + } +}; + +int sc_main(int , char* []) +{ + module m("dut", 4); + + std::vector<sc_object*> children = m.get_child_objects(); + + for (size_t i=0; i<children.size(); ++i ) + cout << children[i]->name() << " - " + << children[i]->kind() + << endl; + + cout << "Program completed" << endl; + return 0; +} diff --git a/src/systemc/tests/systemc/utils/sc_vector/test02/golden/test02.log b/src/systemc/tests/systemc/utils/sc_vector/test02/golden/test02.log new file mode 100644 index 000000000..6140c1e6a --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_vector/test02/golden/test02.log @@ -0,0 +1,18 @@ +SystemC Simulation +dut.array - sc_vector +dut.inps - sc_vector +dut.inps_0 - sc_in +dut.inps_1 - sc_in +dut.inps_2 - sc_in +dut.inps_3 - sc_in +dut.inps_4 - sc_in +dut.sigs - sc_vector +dut.array_0 - derived_0 +dut.array_1 - derived_1 +dut.array_2 - derived_0 +dut.sigs_0 - sc_signal +dut.sigs_1 - sc_signal +dut.sigs_2 - sc_signal +dut.sigs_3 - sc_signal +dut.sigs_4 - sc_signal +Program completed diff --git a/src/systemc/tests/systemc/utils/sc_vector/test02/test02.cpp b/src/systemc/tests/systemc/utils/sc_vector/test02/test02.cpp new file mode 100644 index 000000000..7b827dd3a --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_vector/test02/test02.cpp @@ -0,0 +1,127 @@ +/***************************************************************************** + + 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 -- Test sc_vector + + Original Author: Philipp A. Hartmann, OFFIS, 2010-01-10 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +//#define USE_BOOST + +#ifndef USE_BOOST +# define SC_INCLUDE_DYNAMIC_PROCESSES +#endif + +#include "systemc.h" + +#include "sysc/utils/sc_vector.h" +using sc_core::sc_vector; + +#ifdef USE_BOOST +#include <boost/bind.hpp> +#include <boost/bind/placeholders.hpp> +#endif + +// ---- some classes +// +struct base : sc_object +{ + base( const char* n ) : sc_object(n) {} +}; + +struct derived_0 : base +{ + derived_0(const char* name) : base(name) {} + const char* kind() const { return "derived_0"; } +}; + +struct derived_1 : public base +{ + derived_1(const char* name) : base(name) {} + const char* kind() const { return "derived_1"; } +}; + +// plain function pointer +base* fill_array( const char* n, size_t i ) +{ + if( i%2 ) return new derived_1( n ); + return new derived_0( n ); +} + +SC_MODULE(DUT) +{ + sc_vector< base > arr; + sc_vector< sc_in<bool> > inps; + sc_vector< sc_signal<bool> > sigs; + + SC_CTOR(DUT); + + // member function as creator (use with sc_bind()) + sc_signal<bool>* init_sig_bind( const char* n, unsigned i ) + { + sc_signal<bool>* sig = new sc_signal<bool>(n); + inps[i]( *sig ); + return sig; + } +}; + + +DUT::DUT( sc_module_name ) + : arr("array") + , inps("inps", 5) + , sigs("sigs") +{ + arr.init( 3, fill_array ); + + sigs.init( inps.size() +#if defined( SC_INCLUDE_DYNAMIC_PROCESSES ) + , sc_bind( &DUT::init_sig_bind, this, sc_unnamed::_1, sc_unnamed::_2 ) +#elif defined( USE_BOOST ) + , boost::bind( &DUT::init_sig_bind, this, _1, _2 ) +#endif + ); +} + +int sc_main(int , char* []) +{ + DUT dut("dut"); + + std::vector<sc_object*> children = dut.get_child_objects(); + + for (size_t i=0; i<children.size(); ++i ) + cout << children[i]->name() << " - " + << children[i]->kind() + << endl; + + cout << "Program completed" << endl; + return 0; +} diff --git a/src/systemc/tests/systemc/utils/sc_vector/test03/golden/test03.log b/src/systemc/tests/systemc/utils/sc_vector/test03/golden/test03.log new file mode 100644 index 000000000..a982c7ab8 --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_vector/test03/golden/test03.log @@ -0,0 +1,12 @@ +SystemC Simulation +dut.sub_modules_0 - sc_module +dut.sub_modules_1 - sc_module +dut.sub_modules_2 - sc_module +dut.sub_modules_3 - sc_module +dut.sub_modules_4 - sc_module +sub_modules_0 - dut +sub_modules_1 - dut +sub_modules_2 - dut +sub_modules_3 - dut +sub_modules_4 - dut +Program completed diff --git a/src/systemc/tests/systemc/utils/sc_vector/test03/test03.cpp b/src/systemc/tests/systemc/utils/sc_vector/test03/test03.cpp new file mode 100644 index 000000000..9feebdc64 --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_vector/test03/test03.cpp @@ -0,0 +1,101 @@ +/***************************************************************************** + + 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 sc_vector + + Original Author: Philipp A. Hartmann, OFFIS, 2010-03-05 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +#include "systemc.h" + +#include "sysc/utils/sc_vector.h" +using sc_core::sc_vector; + +SC_MODULE( sub_module ) +{ + // constructor with additional parameters + sub_module( sc_core::sc_module_name, int param ); + // ... +}; + +SC_MODULE( module ) +{ + sc_core::sc_vector< sub_module > m_sub_vec; // vector of sub-modules + + module( sc_core::sc_module_name, unsigned n_sub ); // constructor + + struct mod_creator // Creator struct + { + mod_creator( int p ) : param(p) {} // store parameter to forward + + sub_module* operator()( const char* name, size_t ) // actual creator function + { + return new sub_module( name, param ); // forward param to sub-module + } + int param; + }; + +}; + +sub_module::sub_module( sc_core::sc_module_name, int ) + { /* empty */ } + +module::module( sc_core::sc_module_name, unsigned n_sub ) + : m_sub_vec( "sub_modules" ) // set name prefix +{ + m_sub_vec.init( n_sub, mod_creator(42) ); // init with custom creator + // ... +} + +int sc_main(int , char* []) +{ + module dut( "dut", 5 ); + + typedef sc_core::sc_vector<sub_module> vec_type; + vec_type const & children = dut.m_sub_vec; + + for( vec_type::const_iterator it = children.begin(); + it != children.end(); ++it ) + { + cout << it->name() << " - " + << (*it).kind() + << endl; + } + + for (size_t i=0; i < children.size(); ++i ) + cout << children[i].basename() << " - " + << children[i].get_parent_object()->name() + << endl; + + cout << "Program completed" << endl; + return 0; +} diff --git a/src/systemc/tests/systemc/utils/sc_vector/test04/golden/test04.log b/src/systemc/tests/systemc/utils/sc_vector/test04/golden/test04.log new file mode 100644 index 000000000..a7dfafcea --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_vector/test04/golden/test04.log @@ -0,0 +1,42 @@ +SystemC Simulation +dut.nodes_0_0 created @ 0x0 +dut.nodes_0_1 created @ 0x1 +dut.nodes_0_2 created @ 0x2 +dut.nodes_0_3 created @ 0x3 +dut.nodes_0_4 created @ 0x4 +dut.nodes_1_0 created @ 1x0 +dut.nodes_1_1 created @ 1x1 +dut.nodes_1_2 created @ 1x2 +dut.nodes_1_3 created @ 1x3 +dut.nodes_1_4 created @ 1x4 +dut.nodes_2_0 created @ 2x0 +dut.nodes_2_1 created @ 2x1 +dut.nodes_2_2 created @ 2x2 +dut.nodes_2_3 created @ 2x3 +dut.nodes_2_4 created @ 2x4 +dut.nodes_3_0 created @ 3x0 +dut.nodes_3_1 created @ 3x1 +dut.nodes_3_2 created @ 3x2 +dut.nodes_3_3 created @ 3x3 +dut.nodes_3_4 created @ 3x4 +dut.nodes_0_0 - sc_module +dut.nodes_1_0 - sc_module +dut.nodes_2_0 - sc_module +dut.nodes_3_0 - sc_module +dut.nodes_0_1 - sc_module +dut.nodes_1_1 - sc_module +dut.nodes_2_1 - sc_module +dut.nodes_3_1 - sc_module +dut.nodes_0_2 - sc_module +dut.nodes_1_2 - sc_module +dut.nodes_2_2 - sc_module +dut.nodes_3_2 - sc_module +dut.nodes_0_3 - sc_module +dut.nodes_1_3 - sc_module +dut.nodes_2_3 - sc_module +dut.nodes_3_3 - sc_module +dut.nodes_0_4 - sc_module +dut.nodes_1_4 - sc_module +dut.nodes_2_4 - sc_module +dut.nodes_3_4 - sc_module +Program completed diff --git a/src/systemc/tests/systemc/utils/sc_vector/test04/test04.cpp b/src/systemc/tests/systemc/utils/sc_vector/test04/test04.cpp new file mode 100644 index 000000000..e8aa4df8b --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_vector/test04/test04.cpp @@ -0,0 +1,110 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + test04.cpp -- Test sc_vector -- build a two dimensional mesh + + Original Author: Philipp A. Hartmann, OFFIS, 2010-03-01 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +#include "systemc.h" +#include "sysc/utils/sc_vector.h" + + +SC_MODULE( mesh_node ) +{ + // constructor with additional parameters + mesh_node( sc_core::sc_module_name, int x, int y ); +}; + +typedef sc_vector< mesh_node > row_type; +typedef sc_vector< row_type > mesh_type; + +SC_MODULE(mesh) +{ + mesh_type nodes; + + mesh( sc_module_name, int n, int m ); + + struct node_creator + { + node_creator( int row ) : x(row) {} + + mesh_node* operator()(const char * name, size_t idx ) + { + return new mesh_node( name, x, idx ); + } + int x; + }; + + struct row_creator + { + row_creator( int n_cols ) : cols_( n_cols ) {} + + row_type* operator()( const char* name, size_t idx ) + { + return new row_type( name, cols_, node_creator(idx) ); + } + int cols_; + }; + + const unsigned rows; + const unsigned cols; + +}; + +mesh_node::mesh_node( sc_module_name, int x, int y ) +{ + std::cout << name() << " created @ " + << x << "x" << y << std::endl; +} + +mesh::mesh( sc_module_name, int n, int m ) + : nodes("nodes") + , rows( n ) + , cols( m ) +{ + nodes.init( n, row_creator(m) ); +} + +int sc_main(int argc, char* argv[]) +{ + mesh dut("dut", 4, 5); + + for (size_t j=0; j<dut.cols; ++j ) + for (size_t i=0; i<dut.rows; ++i ) + cout << dut.nodes[i][j].name() << " - " + << dut.nodes[i][j].kind() + << endl; + + cout << "Program completed" << endl; + return 0; +} diff --git a/src/systemc/tests/systemc/utils/sc_vector/test05/golden/test05.log b/src/systemc/tests/systemc/utils/sc_vector/test05/golden/test05.log new file mode 100644 index 000000000..17786de25 --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_vector/test05/golden/test05.log @@ -0,0 +1,25 @@ +SystemC Simulation + +module::before_end_of_elaboration + top.in_0.size() == 1 - src_1_0 @ 0 + top.in_1.size() == 1 - src_1_1 @ 0 + top.in_2.size() == 1 - src_2_0 @ 0 + top.in_3.size() == 1 - src_2_1 @ 0 + +sub_module::before_end_of_elaboration + top.sub.in_0.size() == 0 + top.sub.in_1.size() == 0 + top.sub.in_2.size() == 0 + top.sub.in_3.size() == 0 + +module::end_of_elaboration + top.in_0.size() == 1 - src_1_0 @ 0 + top.in_1.size() == 1 - src_1_1 @ 0 + top.in_2.size() == 1 - src_2_0 @ 0 + top.in_3.size() == 1 - src_2_1 @ 0 + +sub_module::end_of_elaboration + top.sub.in_0.size() == 2 - src_1_0 @ 0 - fifo_0 @ 1 + top.sub.in_1.size() == 2 - src_1_1 @ 0 - fifo_1 @ 1 + top.sub.in_2.size() == 1 - src_2_0 @ 0 + top.sub.in_3.size() == 1 - src_2_1 @ 0 diff --git a/src/systemc/tests/systemc/utils/sc_vector/test05/test05.cpp b/src/systemc/tests/systemc/utils/sc_vector/test05/test05.cpp new file mode 100644 index 000000000..551b4fad1 --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_vector/test05/test05.cpp @@ -0,0 +1,127 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + test05.cpp -- Test sc_vector (and its binding functions) + + Original Author: Philipp A. Hartmann, OFFIS, 2010-03-05 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +#include <systemc.h> + +#include "sysc/utils/sc_vector.h" +using sc_core::sc_vector; + +typedef sc_vector< sc_fifo_out<int> > port_vec; + +static void +dump_port_array( const char* from, const port_vec& in ) +{ + std::cout << "\n" << from << "\n"; + for( unsigned i=0; i<in.size(); ++i ) + { + std::cout + << " " + << in[i].name() + << ".size() == " << in[i].size(); + + for( int j=0; j<in[i].size(); ++j) + { + std::cout + << " - " + << dynamic_cast<const sc_core::sc_object*>(in[i][j])->name() + << " @ " << j; + } + std::cout << std::endl; + } +} + +SC_MODULE(sub_module) +{ + port_vec in; + + sub_module( sc_core::sc_module_name, unsigned n_sub ) + : in("in", n_sub ) {} + + void before_end_of_elaboration() + { dump_port_array( "sub_module::before_end_of_elaboration", in ); } + void end_of_elaboration() + { dump_port_array( "sub_module::end_of_elaboration", in ); } +}; + + +SC_MODULE(module) +{ + sub_module sub; + port_vec in; + + SC_CTOR(module) + : sub("sub", 4), in("in",4) + { + // vector to vector binding + sub.in( in ); + } + + void before_end_of_elaboration() + { dump_port_array( "module::before_end_of_elaboration", in ); } + void end_of_elaboration() + { dump_port_array( "module::end_of_elaboration", in ); } +}; + +int sc_main( int, char*[] ) +{ + + module top("top"); + + const unsigned size = 4; + const unsigned half = 2; + + sc_assert( top.in.size() == size ); + + sc_vector< sc_fifo<int> > + fifo_1( "src_1", half ), + fifo_2( "src_2", size ); + + // bind full vector (smaller than target) + port_vec::iterator mid = top.in( fifo_1 ); + sc_assert( ( mid - top.in.begin() ) - half == 0 ); + + // bind range, starting from last position + mid = top.in.bind( fifo_2.begin(), fifo_2.end(), mid ); + sc_assert( mid == top.in.end() ); + + // bind a plain C array of channels + sc_fifo<int> fifo_a[ half ]; + top.sub.in( fifo_a, fifo_a + half ); + + sc_start(); + return 0; +} diff --git a/src/systemc/tests/systemc/utils/sc_vector/test06/golden/test06.log b/src/systemc/tests/systemc/utils/sc_vector/test06/golden/test06.log new file mode 100644 index 000000000..d46c54a94 --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_vector/test06/golden/test06.log @@ -0,0 +1,37 @@ +SystemC Simulation + +-->-- m.get_child_objects() -->-- + - size: 10 + - dut.sub_modules - sc_vector + - dut.in_vec - sc_vector + - dut.sub_modules_0 - sc_module + - dut.sub_modules_1 - sc_module + - dut.sub_modules_2 - sc_module + - dut.sub_modules_3 - sc_module + - dut.in_vec_0 - sc_in + - dut.in_vec_1 - sc_in + - dut.in_vec_2 - sc_in + - dut.in_vec_3 - sc_in +--<-- m.get_child_objects() --<-- + +-->-- m.sub_vec.get_child_objects() -->-- + - size: 0 +--<-- m.sub_vec.get_child_objects() --<-- + +-->-- m.sub_vec.get_elements() -->-- + - size: 4 + - dut.sub_modules_0 - sc_module + - dut.sub_modules_1 - sc_module + - dut.sub_modules_2 - sc_module + - dut.sub_modules_3 - sc_module +--<-- m.sub_vec.get_elements() --<-- + +-->-- sc_assemble_vector( m.sub_vec, &sub_module::in ).get_elements() -->-- + - size: 4 + - dut.sub_modules_0.port_0 - sc_in + - dut.sub_modules_1.port_0 - sc_in + - dut.sub_modules_2.port_0 - sc_in + - dut.sub_modules_3.port_0 - sc_in +--<-- sc_assemble_vector( m.sub_vec, &sub_module::in ).get_elements() --<-- + +Program completed diff --git a/src/systemc/tests/systemc/utils/sc_vector/test06/test06.cpp b/src/systemc/tests/systemc/utils/sc_vector/test06/test06.cpp new file mode 100644 index 000000000..051d49c31 --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_vector/test06/test06.cpp @@ -0,0 +1,113 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + test06.cpp -- Test sc_vector::get_elements + + Original Author: Philipp A. Hartmann, OFFIS, 2010-11-04 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +#include "systemc" + +#include "sysc/utils/sc_vector.h" + +using sc_core::sc_object; +using sc_core::sc_vector; +using sc_core::sc_mutex; +using sc_core::sc_in; + +void print_vector( const char * header, + const std::vector<sc_object*> & vec ) +{ + std::cout << "\n-->-- " << header << " -->--\n"; + + std::cout << " - size: " << vec.size() << "\n"; + + for (size_t i=0; i<vec.size(); ++i ) + std::cout << " - " + << vec[i]->name() << " - " + << vec[i]->kind() << "\n"; + + std::cout << "--<-- " << header << " --<--" + << std::endl; +} + +#define PRINT_VECTOR( Vector ) \ + print_vector( #Vector, Vector ) + +SC_MODULE( sub_module ) +{ + sc_in<bool> in; + SC_CTOR(sub_module) {} +}; + + +SC_MODULE( module ) +{ + // vector of sub-modules + sc_vector< sub_module > sub_vec; + + // vector of ports + sc_vector< sc_in<bool> > in_vec; + + SC_CTOR(module) + : sub_vec( "sub_modules" ) + , in_vec( "in_vec" ) + {} + + void init( unsigned n_sub ) + { + sub_vec.init(n_sub); + in_vec.init(n_sub); + // in_vec.init(n_sub); // second call fails + + // bind ports of sub-modules -- no dereference + sc_assemble_vector( sub_vec, &sub_module::in ).bind( in_vec ); + } + +}; + +int sc_main(int, char* []) +{ + module m("dut"); + m.init(4); // calls from external context + + PRINT_VECTOR( m.get_child_objects() ); + + PRINT_VECTOR( m.sub_vec.get_child_objects() ); + + PRINT_VECTOR( m.sub_vec.get_elements() ); + + PRINT_VECTOR( sc_assemble_vector( m.sub_vec, &sub_module::in ).get_elements() ); + + std::cout << "\nProgram completed" << std::endl; + return 0; +} diff --git a/src/systemc/tests/systemc/utils/sc_vector/test07/golden/test07.log b/src/systemc/tests/systemc/utils/sc_vector/test07/golden/test07.log new file mode 100644 index 000000000..da00cd389 --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_vector/test07/golden/test07.log @@ -0,0 +1,14 @@ +SystemC Simulation + +Warning: (W807) sc_vector::bind called with empty range: target `dut.sub_modules' (sc_vector_assembly) not initialised yet +In file: <removed by verify.pl> + +Warning: (W807) sc_vector::bind called with empty range: target `dut.sub_modules' (sc_vector_assembly) empty destination range given +In file: <removed by verify.pl> + +Warning: (W807) sc_vector::bind called with empty range: target `dut.in_vec' (sc_vector) empty destination range given +In file: <removed by verify.pl> + +Warning: (W807) sc_vector::bind called with empty range: target `dut.in_vec' (sc_vector) empty destination range given +In file: <removed by verify.pl> +Success diff --git a/src/systemc/tests/systemc/utils/sc_vector/test07/test07.cpp b/src/systemc/tests/systemc/utils/sc_vector/test07/test07.cpp new file mode 100644 index 000000000..beed04b1f --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_vector/test07/test07.cpp @@ -0,0 +1,105 @@ +/***************************************************************************** + + 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 -- Test sc_vector -- empty bindings + + Original Author: Philipp A. Hartmann, OFFIS, 2011-02-14 + + *****************************************************************************/ + +/***************************************************************************** + + 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( sub_module ) +{ + sc_in<bool> in; + SC_CTOR(sub_module) {} +}; + +SC_MODULE( module ) +{ + // vector of sub-modules + sc_vector< sub_module > m_sub_vec; + + // vector of ports + sc_vector< sc_in<bool> > in_vec; + + module( sc_core::sc_module_name, unsigned n_sub ) + : m_sub_vec( "sub_modules" ) + , in_vec( "in_vec" ) + { + // bind ports of submodules (before initialisation of module vector) + do_bind(); + + // initialise module vector + m_sub_vec.init( n_sub ); + + // bind ports of submodules (before initialisation of port vector) + do_bind(); + + // delayed initialisation of port vector + in_vec.init( n_sub ); + + // bind ports of submodules (should be fine now) + do_bind(); + } + + void do_bind() + { + try { + // bind ports of sub-modules -- sc_assemble_vector + sc_assemble_vector( m_sub_vec, &sub_module::in ).bind( in_vec ); + } catch( sc_report const & rpt ) { + std::cout << rpt.what() << std::endl; + } + } +}; + +int sc_main(int , char* []) +{ + module m("dut", 4); + sc_vector< sc_signal<bool> > s("sig"); + + // bind ports to signals -- before initialisation of signal vector + m.in_vec( s ); + + s.init(4); + + // bind empty range + m.in_vec( s.begin(), s.begin() ); + + // bind with full range + m.in_vec( s ); + + sc_start( SC_ZERO_TIME ); + + cout << "Success" << endl; + return 0; +} diff --git a/src/systemc/tests/systemc/utils/sc_vector/test08/golden/test08.log b/src/systemc/tests/systemc/utils/sc_vector/test08/golden/test08.log new file mode 100644 index 000000000..4e18b8169 --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_vector/test08/golden/test08.log @@ -0,0 +1,9 @@ +SystemC Simulation + +Error: (E808) sc_vector::get_elements called for element type not derived from sc_object: evs +In file: <removed by verify.pl> + +Error: (E808) sc_vector::get_elements called for element type not derived from sc_object: foo +In file: <removed by verify.pl> + +Success diff --git a/src/systemc/tests/systemc/utils/sc_vector/test08/test08.cpp b/src/systemc/tests/systemc/utils/sc_vector/test08/test08.cpp new file mode 100644 index 000000000..d08a0d7fb --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_vector/test08/test08.cpp @@ -0,0 +1,60 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + test08.cpp -- sc_vector of objects not derived from sc_object + (OSCI extension to IEEE 1666-2011) + + Original Author: Philipp A. Hartmann, OFFIS, 2011-10-01 + + *****************************************************************************/ + +#include "systemc.h" + +struct foo +{ + explicit + foo( const char* nm ) + : name(nm) + {} + std::string name; +}; + +int sc_main( int, char*[] ) +{ + sc_report_handler::set_actions( SC_ERROR, SC_DISPLAY ); + + sc_vector< sc_event > ev_vec ( "evs", 1 ); + + sc_assert( ev_vec.size() == 1 ); + // should print an error + sc_assert( ev_vec.get_elements().size() == 0 ); + + sc_vector< foo > foo_vec( "foo", 1 ); + + sc_assert( foo_vec.size() == 1 ); + sc_assert( sc_assemble_vector( foo_vec, &foo::name ).size() == 1 ); + // should print an error + sc_assert( sc_assemble_vector( foo_vec, &foo::name ) + .get_elements().size() == 0 ); + + cout << "\nSuccess" << endl; + return 0; +} diff --git a/src/systemc/tests/systemc/utils/sc_vector/test09/golden/iter_test.log b/src/systemc/tests/systemc/utils/sc_vector/test09/golden/iter_test.log new file mode 100644 index 000000000..7ced375b0 --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_vector/test09/golden/iter_test.log @@ -0,0 +1,3 @@ +SystemC Simulation + +Success diff --git a/src/systemc/tests/systemc/utils/sc_vector/test09/iter_test.cpp b/src/systemc/tests/systemc/utils/sc_vector/test09/iter_test.cpp new file mode 100644 index 000000000..4a4599afa --- /dev/null +++ b/src/systemc/tests/systemc/utils/sc_vector/test09/iter_test.cpp @@ -0,0 +1,97 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + iter_test.cpp -- sc_vector iterator comparisons + + Original Author: Philipp A. Hartmann, OFFIS, 2014-08-21 + + *****************************************************************************/ +#include <systemc.h> + +SC_MODULE(mod) +{ + sc_in<bool> p; + SC_CTOR(mod){} +}; + +int sc_main(int,char*[]) +{ + typedef sc_vector<mod> module_vec; + typedef sc_vector_assembly<mod,sc_in<bool> > module_port_vec; + + module_vec mv("sigs",5); + module_vec::const_iterator citr = mv.begin(); + module_vec::iterator itr = mv.begin(); + + module_port_vec mpv = sc_assemble_vector(mv, &mod::p); + module_port_vec::const_iterator cpitr = mpv.cbegin(); + module_port_vec::iterator pitr = mpv.begin(); + + sc_assert(itr == citr); + sc_assert(citr == itr); + sc_assert(!(itr != citr)); + sc_assert(!(citr != itr)); + + sc_assert(itr == cpitr); + sc_assert(citr == pitr); + sc_assert(cpitr == itr); + sc_assert(pitr == citr); + sc_assert(!(itr != cpitr)); + sc_assert(!(citr != pitr)); + sc_assert(!(cpitr != pitr)); + sc_assert(!(pitr != itr)); + + sc_assert(itr < mv.end()); + sc_assert(!(itr > mv.cend())); + sc_assert(citr < mv.end()); + sc_assert(!(citr > mv.cend())); + + ++citr; + sc_assert(itr != citr); + sc_assert(citr != itr); + sc_assert(!(itr == citr)); + sc_assert(!(citr == itr)); + + sc_assert(!(itr < itr)); + sc_assert(!(itr > itr)); + sc_assert(itr < citr); + sc_assert(citr > itr); + + sc_assert(1 == citr - mv.begin()); + sc_assert(0 == pitr - mv.cbegin()); + itr += citr - mpv.begin(); + sc_assert(1 == itr - mpv.cbegin()); + + sc_assert(citr == itr); + sc_assert(itr <= citr); + sc_assert(citr <= itr); + sc_assert(cpitr <= itr); + sc_assert(!(itr <= cpitr)); + + itr++; + cpitr = pitr += itr - mv.begin(); + sc_assert(itr == pitr); + sc_assert(itr >= citr); + sc_assert(!(citr >= pitr)); + + cout << "\nSuccess" << endl; + return 0; +} |