summaryrefslogtreecommitdiff
path: root/src/systemc/tests/systemc/utils/sc_report/cached
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-05-24 01:37:55 -0700
committerGabe Black <gabeblack@google.com>2018-08-08 10:09:54 +0000
commit16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f (patch)
tree7b6faaacb4574a555e561534aa4a8508c0624c32 /src/systemc/tests/systemc/utils/sc_report/cached
parent7235d3b5211d0ba8f528d930a4c1e7ad62eec51a (diff)
downloadgem5-16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f.tar.xz
systemc: Import tests from the Accellera systemc distribution.
Change-Id: Iad76b398949a55d768a34d027a2d8e3739953da6 Reviewed-on: https://gem5-review.googlesource.com/10845 Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com> Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/systemc/tests/systemc/utils/sc_report/cached')
-rw-r--r--src/systemc/tests/systemc/utils/sc_report/cached/cached.cpp227
-rw-r--r--src/systemc/tests/systemc/utils/sc_report/cached/golden/cached.log62
2 files changed, 289 insertions, 0 deletions
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>