Skip to content

Commit f3ddba5

Browse files
Merge pull request #22 from eyck/main
Splits reporting into frontend and backend implementation
2 parents 5e537b1 + 4a10d46 commit f3ddba5

File tree

11 files changed

+934
-660
lines changed

11 files changed

+934
-660
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
/_build/
33
/.cproject
44
/.project
5+
/.venv
6+
/.vscode

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ endmacro()
1010

1111
run_test(smoke)
1212
run_test(smoke_report)
13+
run_test(smoke_logger)

examples/smoke.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ SC_MODULE (test) {
4141
uint64_t myint = mid + mid;
4242
myint += mid;
4343
if (mid == 0x450) {
44-
SC_REPORT_INFO("ext test", "Success");
44+
SCP_INFO("ext test") << "Success";
4545
} else {
46-
SC_REPORT_INFO("ext test", "Failour");
46+
SCP_INFO("ext test") << "Failure";
4747
}
4848
}
4949
};

examples/smoke_logger.cc

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
/*****************************************************************************
2+
Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
3+
more contributor license agreements. See the NOTICE file distributed
4+
with this work for additional information regarding copyright ownership.
5+
Accellera licenses this file to you under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with the
7+
License. You may obtain a copy of the License at
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12+
implied. See the License for the specific language governing
13+
permissions and limitations under the License.
14+
****************************************************************************/
15+
16+
#include <scp/tlm_extensions/initiator_id.h>
17+
#include <scp/tlm_extensions/path_trace.h>
18+
#include <scp/logger.h>
19+
20+
#include <systemc>
21+
#include <tlm>
22+
#include <cci_configuration>
23+
24+
#include <cstdio>
25+
#include <string>
26+
#include <fstream>
27+
#include <unistd.h>
28+
29+
SC_MODULE (test4) {
30+
SC_CTOR (test4) {
31+
SCP_INFO(()) << " . T4 Logger() 1";
32+
SCP_WARN(()) << " . T4 Logger() 1";
33+
SCP_INFO(()) << " . T4 Logger() 2";
34+
SCP_WARN(()) << " . T4 Logger() 2";
35+
}
36+
SCP_LOGGER();
37+
};
38+
39+
SC_MODULE (test3) {
40+
SC_CTOR (test3) {
41+
SCP_INFO((D)) << " . T3 D Logger \"other\" \"feature.one\"";
42+
SCP_WARN((D)) << " . T3 D Logger \"other\" \"feature.one\"";
43+
SCP_INFO(()) << " . T3 Logger ()";
44+
SCP_WARN(()) << " . T3 Logger ()";
45+
}
46+
SCP_LOGGER((D), "other", "feature.one");
47+
SCP_LOGGER(());
48+
};
49+
50+
SC_MODULE (test2) {
51+
SC_CTOR (test2) : t31("t3_1"), t32("t3_2"), t4("t4") {
52+
SCP_INFO(()) << " T2 Logger()";
53+
SCP_WARN(()) << " T2 Logger()";
54+
}
55+
SCP_LOGGER();
56+
test3 t31, t32;
57+
test4 t4;
58+
};
59+
60+
SC_MODULE (test1) {
61+
SC_CTOR (test1) : t2("t2") {
62+
SCP_WARN((), "My.Name") << " T1 My.Name typed log";
63+
SCP_INFO(()) << " T1 Logger()";
64+
SCP_WARN(()) << " T1 Logger()";
65+
66+
SCP_LOGGER_VECTOR_PUSH_BACK(vec, "some", "thing1");
67+
SCP_LOGGER_VECTOR_PUSH_BACK(vec, "some", "thing2");
68+
69+
SCP_INFO((vec[0])) << "Thing1?";
70+
SCP_WARN((vec[0])) << "Thing1?";
71+
SCP_INFO((vec[1])) << "Thing2?";
72+
SCP_WARN((vec[1])) << "Thing2?";
73+
}
74+
SCP_LOGGER("something", "else");
75+
SCP_LOGGER_VECTOR(vec);
76+
test2 t2;
77+
};
78+
79+
class outside_class
80+
{
81+
SCP_LOGGER("out.class", "thing1");
82+
83+
public:
84+
outside_class() {
85+
SCP_INFO(())("constructor");
86+
SCP_WARN(())("constructor");
87+
}
88+
};
89+
90+
SC_MODULE (test) {
91+
outside_class oc;
92+
SC_CTOR (test) {
93+
SCP_DEBUG(SCMOD) << "First part";
94+
scp::tlm_extensions::path_trace ext;
95+
ext.stamp(this);
96+
SCP_INFO(SCMOD) << ext.to_string();
97+
ext.reset();
98+
99+
ext.stamp(this);
100+
ext.stamp(this);
101+
ext.stamp(this);
102+
103+
SCP_INFO(SCMOD) << ext.to_string();
104+
ext.reset();
105+
106+
SCP_DEBUG(SCMOD) << "Second part";
107+
scp::tlm_extensions::initiator_id mid(0x1234);
108+
mid = 0x2345;
109+
mid &= 0xff;
110+
mid <<= 4;
111+
uint64_t myint = mid + mid;
112+
myint += mid;
113+
if (mid == 0x450) {
114+
SC_REPORT_INFO("ext test", "Success");
115+
} else {
116+
SC_REPORT_INFO("ext test", "Failour");
117+
}
118+
119+
SCP_INFO() << "Globally cached version empty";
120+
SCP_INFO(())("FMT String : Locally cached version default");
121+
SCP_INFO(SCMOD) << "Globally cached version feature using SCMOD macro";
122+
SCP_INFO((m_my_logger))
123+
<< "Locally cached version using (m_my_logger)";
124+
SCP_INFO((D)) << "Locally cached version with D";
125+
}
126+
127+
SCP_LOGGER((m_my_logger));
128+
SCP_LOGGER(());
129+
SCP_LOGGER((1), "other");
130+
SCP_LOGGER((D), "other", "feature.one");
131+
};
132+
133+
int sc_main(int argc, char** argv) {
134+
cci_utils::consuming_broker broker("global_broker");
135+
cci_register_broker(broker);
136+
cci::cci_originator orig("config");
137+
broker.set_preset_cci_value("log_level", cci::cci_value(1), orig);
138+
broker.set_preset_cci_value("top.log_level", cci::cci_value(5), orig);
139+
broker.set_preset_cci_value("*.t3_1.log_level", cci::cci_value(5), orig);
140+
broker.set_preset_cci_value("feature.log_level", cci::cci_value(5), orig);
141+
142+
broker.set_preset_cci_value("test4.log_level", cci::cci_value(4), orig);
143+
broker.set_preset_cci_value("thing1.log_level", cci::cci_value(5), orig);
144+
145+
std::string logfile = "/tmp/scp_smoke_report_test." +
146+
std::to_string(getpid());
147+
scp::init_logging(
148+
scp::LogConfig()
149+
.logLevel(scp::log::DEBUG) // set log level to debug
150+
.msgTypeFieldWidth(20)
151+
.fileInfoFrom(5)
152+
.logAsync(false)
153+
.printSimTime(false)
154+
.logFileName(logfile)); // make the msg type column a bit tighter
155+
SCP_INFO() << "Constructing design";
156+
test toptest("top");
157+
test1 t1("t1");
158+
159+
SCP_INFO() << "Starting simulation";
160+
sc_core::sc_start();
161+
SCP_WARN() << "Ending simulation";
162+
163+
#ifdef FMT_SHARED
164+
std::string fmtstr = "FMT String : Locally cached version default";
165+
#else
166+
std::string fmtstr = "Please add FMT library for FMT support.";
167+
#endif
168+
169+
std::string expected =
170+
R"([ info] [ 0 s ]SystemC : Constructing design
171+
[ info] [ 0 s ]out.class : constructor
172+
[ warning] [ 0 s ]out.class : constructor
173+
[ debug] [ 0 s ]top : First part
174+
[ info] [ 0 s ]top : top
175+
[ info] [ 0 s ]top : top->top->top
176+
[ debug] [ 0 s ]top : Second part
177+
[ info] [ 0 s ]ext test : Success
178+
[ info] [ 0 s ]SystemC : Globally cached version empty
179+
[ info] [ 0 s ]top : )" +
180+
fmtstr + R"(
181+
[ info] [ 0 s ]top : Globally cached version feature using SCMOD macro
182+
[ info] [ 0 s ]top : Locally cached version using (m_my_logger)
183+
[ info] [ 0 s ]top : Locally cached version with D
184+
[ info] [ 0 s ]t1.t2.t3_1 : . T3 D Logger "other" "feature.one"
185+
[ warning] [ 0 s ]t1.t2.t3_1 : . T3 D Logger "other" "feature.one"
186+
[ info] [ 0 s ]t1.t2.t3_1 : . T3 Logger ()
187+
[ warning] [ 0 s ]t1.t2.t3_1 : . T3 Logger ()
188+
[ info] [ 0 s ]t1.t2.t3_2 : . T3 D Logger "other" "feature.one"
189+
[ warning] [ 0 s ]t1.t2.t3_2 : . T3 D Logger "other" "feature.one"
190+
[ warning] [ 0 s ]t1.t2.t3_2 : . T3 Logger ()
191+
[ info] [ 0 s ]t1.t2.t4 : . T4 Logger() 1
192+
[ warning] [ 0 s ]t1.t2.t4 : . T4 Logger() 1
193+
[ info] [ 0 s ]t1.t2.t4 : . T4 Logger() 2
194+
[ warning] [ 0 s ]t1.t2.t4 : . T4 Logger() 2
195+
[ warning] [ 0 s ]t1.t2 : T2 Logger()
196+
[ warning] [ 0 s ]My.Name : T1 My.Name typed log
197+
[ warning] [ 0 s ]t1 : T1 Logger()
198+
[ info] [ 0 s ]t1 : Thing1?
199+
[ warning] [ 0 s ]t1 : Thing1?
200+
[ warning] [ 0 s ]t1 : Thing2?
201+
[ info] [ 0 s ]SystemC : Starting simulation
202+
[ warning] [ 0 s ]SystemC : Ending simulation
203+
)";
204+
205+
std::ifstream lf(logfile);
206+
std::string out((std::istreambuf_iterator<char>(lf)),
207+
std::istreambuf_iterator<char>());
208+
209+
std::cout << "out file\n" << out << "\n";
210+
std::cout << "expected\n" << expected << "\n";
211+
std::cout << "Number of difference: " << out.compare(expected) << "\n";
212+
213+
std::remove(logfile.c_str());
214+
return out.compare(expected);
215+
}

examples/smoke_report.cc

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323

2424
#include <cstdio>
2525
#include <string>
26-
#include <fstream>
27-
#include <streambuf>
2826
#include <unistd.h>
2927

3028
SC_MODULE (test4) {
@@ -144,14 +142,6 @@ int sc_main(int argc, char** argv) {
144142

145143
std::string logfile = "/tmp/scp_smoke_report_test." +
146144
std::to_string(getpid());
147-
scp::init_logging(
148-
scp::LogConfig()
149-
.logLevel(scp::log::DEBUG) // set log level to debug
150-
.msgTypeFieldWidth(20)
151-
.fileInfoFrom(5)
152-
.logAsync(false)
153-
.printSimTime(false)
154-
.logFileName(logfile)); // make the msg type column a bit tighter
155145
SCP_INFO() << "Constructing design";
156146
test toptest("top");
157147
test1 t1("t1");
@@ -160,56 +150,5 @@ int sc_main(int argc, char** argv) {
160150
sc_core::sc_start();
161151
SCP_WARN() << "Ending simulation";
162152

163-
#ifdef FMT_SHARED
164-
std::string fmtstr = "FMT String : Cached version default";
165-
#else
166-
std::string fmtstr = "Please add FMT library for FMT support.";
167-
#endif
168-
169-
std::string expected =
170-
R"([ info] [ 0 s ]SystemC : Constructing design
171-
[ info] [ 0 s ]out.class : constructor
172-
[ warning] [ 0 s ]out.class : constructor
173-
[ debug] [ 0 s ]top : First part
174-
[ info] [ 0 s ]top : top
175-
[ info] [ 0 s ]top : top->top->top
176-
[ debug] [ 0 s ]top : Second part
177-
[ info] [ 0 s ]ext test : Success
178-
[ info] [ 0 s ]SystemC : Uncached version empty
179-
[ info] [ 0 s ]top : )" +
180-
fmtstr + R"(
181-
[ info] [ 0 s ]top : UnCached version feature using SCMOD macro
182-
[ info] [ 0 s ]top : Cached version using (m_my_logger)
183-
[ info] [ 0 s ]top : Cached version with D
184-
[ info] [ 0 s ]t1.t2.t3_1 : . T3 D Logger "other" "feature.one"
185-
[ warning] [ 0 s ]t1.t2.t3_1 : . T3 D Logger "other" "feature.one"
186-
[ info] [ 0 s ]t1.t2.t3_1 : . T3 Logger ()
187-
[ warning] [ 0 s ]t1.t2.t3_1 : . T3 Logger ()
188-
[ info] [ 0 s ]t1.t2.t3_2 : . T3 D Logger "other" "feature.one"
189-
[ warning] [ 0 s ]t1.t2.t3_2 : . T3 D Logger "other" "feature.one"
190-
[ warning] [ 0 s ]t1.t2.t3_2 : . T3 Logger ()
191-
[ info] [ 0 s ]t1.t2.t4 : . T4 Logger() 1
192-
[ warning] [ 0 s ]t1.t2.t4 : . T4 Logger() 1
193-
[ info] [ 0 s ]t1.t2.t4 : . T4 Logger() 2
194-
[ warning] [ 0 s ]t1.t2.t4 : . T4 Logger() 2
195-
[ warning] [ 0 s ]t1.t2 : T2 Logger()
196-
[ warning] [ 0 s ]My.Name : T1 My.Name typed log
197-
[ warning] [ 0 s ]t1 : T1 Logger()
198-
[ info] [ 0 s ]t1 : Thing1?
199-
[ warning] [ 0 s ]t1 : Thing1?
200-
[ warning] [ 0 s ]t1 : Thing2?
201-
[ info] [ 0 s ]SystemC : Starting simulation
202-
[ warning] [ 0 s ]SystemC : Ending simulation
203-
)";
204-
205-
std::ifstream lf(logfile);
206-
std::string out((std::istreambuf_iterator<char>(lf)),
207-
std::istreambuf_iterator<char>());
208-
209-
std::cout << "out file\n" << out << "\n";
210-
std::cout << "expected\n" << expected << "\n";
211-
std::cout << "Number of difference: " << out.compare(expected) << "\n";
212-
213-
std::remove(logfile.c_str());
214-
return out.compare(expected);
153+
return 0;
215154
}

0 commit comments

Comments
 (0)