[gem5-dev] Change in gem5/gem5[develop]: base: Add unit test for base/trace.hh

2021-06-16 Thread Daniel Carvalho (Gerrit) via gem5-dev
Daniel Carvalho has submitted this change. (  
https://gem5-review.googlesource.com/c/public/gem5/+/41336 )


Change subject: base: Add unit test for base/trace.hh
..

base: Add unit test for base/trace.hh

Add an unit test for base/trace.hh.

Marked the source files needed for tracing with a 'gem5 trace'
tag.

Change-Id: Ib1e17de3c772146596a26a2ce5aa7a6310bf7938
Signed-off-by: Daniel R. Carvalho 
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/41336
Tested-by: kokoro 
Reviewed-by: Bobby R. Bruce 
Maintainer: Bobby R. Bruce 
---
M src/SConscript
M src/base/SConscript
A src/base/trace.test.cc
M src/sim/SConscript
4 files changed, 613 insertions(+), 8 deletions(-)

Approvals:
  Bobby R. Bruce: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/SConscript b/src/SConscript
index cc51b9f..923aef8 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -1261,7 +1261,7 @@

 env.Command('debug/flags.cc', Value(debug_flags),
 MakeAction(makeDebugFlagCC, Transform("TRACING", 0)))
-Source('debug/flags.cc')
+Source('debug/flags.cc', add_tags='gem5 trace')

 # version tags
 tags = \
diff --git a/src/base/SConscript b/src/base/SConscript
index 94f8398..b30dbf4 100644
--- a/src/base/SConscript
+++ b/src/base/SConscript
@@ -30,7 +30,7 @@

 SimObject('Graphics.py')
 GTest('amo.test', 'amo.test.cc')
-Source('atomicio.cc')
+Source('atomicio.cc', add_tags='gem5 trace')
 GTest('atomicio.test', 'atomicio.test.cc', 'atomicio.cc')
 Source('bitfield.cc')
 GTest('bitfield.test', 'bitfield.test.cc', 'bitfield.cc')
@@ -40,7 +40,7 @@
 Source('cprintf.cc', add_tags='gtest lib')
 GTest('cprintf.test', 'cprintf.test.cc')
 Executable('cprintftime', 'cprintftime.cc', 'cprintf.cc')
-Source('debug.cc')
+Source('debug.cc', add_tags='gem5 trace')
 GTest('debug.test', 'debug.test.cc', 'debug.cc')
 if env['HAVE_FENV']:
 Source('fenv.cc')
@@ -63,7 +63,7 @@
 Source('logging.cc')
 GTest('logging.test', 'logging.test.cc', 'logging.cc', 'hostinfo.cc',
 'cprintf.cc', 'gtest/logging.cc', skip_lib=True)
-Source('match.cc')
+Source('match.cc', add_tags='gem5 trace')
 GTest('match.test', 'match.test.cc', 'match.cc', 'str.cc')
 Source('output.cc')
 Source('pixel.cc')
@@ -75,13 +75,14 @@
 Source('socket.cc')
 GTest('socket.test', 'socket.test.cc', 'socket.cc')
 Source('statistics.cc')
-Source('str.cc')
+Source('str.cc', add_tags='gem5 trace')
 GTest('str.test', 'str.test.cc', 'str.cc')
 Source('time.cc')
 Source('version.cc')
 Source('temperature.cc')
 GTest('temperature.test', 'temperature.test.cc', 'temperature.cc')
-Source('trace.cc')
+Source('trace.cc', add_tags='gem5 trace')
+GTest('trace.test', 'trace.test.cc', with_tag('gem5 trace'))
 GTest('trie.test', 'trie.test.cc')
 Source('types.cc')
 GTest('types.test', 'types.test.cc', 'types.cc')
diff --git a/src/base/trace.test.cc b/src/base/trace.test.cc
new file mode 100644
index 000..beefbe4
--- /dev/null
+++ b/src/base/trace.test.cc
@@ -0,0 +1,604 @@
+/*
+ * Copyright (c) 2021 Daniel R. Carvalho
+ * All rights reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+
+#include 
+#include 
+
+#include "base/gtest/cur_tick_fake.hh"
+#include "base/gtest/logging.hh"
+#include "base/named.hh"
+#include "base/trace.hh"
+
+// In test SetGetLogger this logger will be assigned to be the one returned
+// by Tracer::getDebugLogger(). All tests before that test should assume
+// that getDebugLogger() returns a 

[gem5-dev] Change in gem5/gem5[develop]: base: Add unit test for base/trace.hh

2021-02-12 Thread Daniel Carvalho (Gerrit) via gem5-dev
Daniel Carvalho has uploaded this change for review. (  
https://gem5-review.googlesource.com/c/public/gem5/+/41336 )



Change subject: base: Add unit test for base/trace.hh
..

base: Add unit test for base/trace.hh

Add an unit test for base/trace.hh.

Marked the source files needed for tracing with a 'gem5 trace'
tag.

Change-Id: Ib1e17de3c772146596a26a2ce5aa7a6310bf7938
Signed-off-by: Daniel R. Carvalho 
---
M src/SConscript
M src/base/SConscript
A src/base/trace.test.cc
M src/sim/SConscript
4 files changed, 612 insertions(+), 8 deletions(-)



diff --git a/src/SConscript b/src/SConscript
index aeb7038..ef0aa6d 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -1171,7 +1171,7 @@

 env.Command('debug/flags.cc', Value(debug_flags),
 MakeAction(makeDebugFlagCC, Transform("TRACING", 0)))
-Source('debug/flags.cc')
+Source('debug/flags.cc', add_tags='gem5 trace')

 # version tags
 tags = \
diff --git a/src/base/SConscript b/src/base/SConscript
index 1190b93..323a018 100644
--- a/src/base/SConscript
+++ b/src/base/SConscript
@@ -30,7 +30,7 @@

 SimObject('Graphics.py')
 GTest('amo.test', 'amo.test.cc')
-Source('atomicio.cc')
+Source('atomicio.cc', add_tags='gem5 trace')
 GTest('atomicio.test', 'atomicio.test.cc', 'atomicio.cc')
 Source('bitfield.cc')
 GTest('bitfield.test', 'bitfield.test.cc', 'bitfield.cc')
@@ -40,7 +40,7 @@
 Source('cprintf.cc', add_tags='gtest lib')
 GTest('cprintf.test', 'cprintf.test.cc')
 Executable('cprintftime', 'cprintftime.cc', 'cprintf.cc')
-Source('debug.cc')
+Source('debug.cc', add_tags='gem5 trace')
 GTest('debug.test', 'debug.test.cc', 'debug.cc')
 if env['USE_FENV']:
 Source('fenv.c')
@@ -57,7 +57,7 @@
 GTest('inifile.test', 'inifile.test.cc', 'inifile.cc', 'str.cc')
 GTest('intmath.test', 'intmath.test.cc')
 Source('logging.cc')
-Source('match.cc')
+Source('match.cc', add_tags='gem5 trace')
 GTest('match.test', 'match.test.cc', 'match.cc', 'str.cc')
 Source('output.cc')
 Source('pixel.cc')
@@ -69,13 +69,14 @@
 Source('socket.cc')
 GTest('socket.test', 'socket.test.cc', 'socket.cc')
 Source('statistics.cc')
-Source('str.cc')
+Source('str.cc', add_tags='gem5 trace')
 GTest('str.test', 'str.test.cc', 'str.cc')
 Source('time.cc')
 Source('version.cc')
 Source('temperature.cc')
 GTest('temperature.test', 'temperature.test.cc', 'temperature.cc')
-Source('trace.cc')
+Source('trace.cc', add_tags='gem5 trace')
+GTest('trace.test', 'trace.test.cc', with_tag('gem5 trace'))
 GTest('trie.test', 'trie.test.cc')
 Source('types.cc')
 GTest('types.test', 'types.test.cc', 'types.cc')
diff --git a/src/base/trace.test.cc b/src/base/trace.test.cc
new file mode 100644
index 000..73e9bf2
--- /dev/null
+++ b/src/base/trace.test.cc
@@ -0,0 +1,603 @@
+/*
+ * Copyright (c) 2021 Daniel R. Carvalho
+ * All rights reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+
+#include 
+#include 
+
+#include "base/gtest/cur_tick_fake.hh"
+#include "base/trace.hh"
+
+// In test SetGetLogger this logger will be assigned to be the one returned
+// by Tracer::getDebugLogger(). All tests before that test should assume
+// that getDebugLogger() returns a cerr-based logger, and all tests after
+// that test should assume that this logger is returned
+std::stringstream ss;
+Trace::OstreamLogger main_logger(ss);
+
+// Instantiate the mock class to have a valid curTick of 0
+GTestTickHandler tickHandler;
+
+namespace Debug {
+/** Debug flag used for the tests in this file. */