Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/42723 )

Change subject: base: Stop using testing::internal:: in tests.
......................................................................

base: Stop using testing::internal:: in tests.

The name strongly suggests that this namespace isn't for our use.
Instead, use the new gtestLogOutput string stream, or in the debug test
add an optional parameter to debugDumpFlags which lets us direct the
output to a string stream we can inspect.

Change-Id: I51d3c0ec42981b70736e7b3bbedfb49f82dc7f95
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/42723
Reviewed-by: Gabe Black <[email protected]>
Reviewed-by: Daniel Carvalho <[email protected]>
Maintainer: Gabe Black <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/base/debug.cc
M src/base/debug.hh
M src/base/debug.test.cc
M src/base/socket.test.cc
M src/base/stats/storage.test.cc
5 files changed, 18 insertions(+), 32 deletions(-)

Approvals:
  Daniel Carvalho: Looks good to me, approved
  Gabe Black: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/base/debug.cc b/src/base/debug.cc
index 925c16f..38eb25f 100644
--- a/src/base/debug.cc
+++ b/src/base/debug.cc
@@ -181,7 +181,7 @@
 }

 void
-dumpDebugFlags()
+dumpDebugFlags(std::ostream &os)
 {
     using namespace Debug;
     FlagsMap::iterator i = allFlags().begin();
@@ -189,6 +189,6 @@
     for (; i != end; ++i) {
         SimpleFlag *f = dynamic_cast<SimpleFlag *>(i->second);
         if (f && f->enabled())
-            cprintf("%s\n", f->name());
+            ccprintf(os, "%s\n", f->name());
     }
 }
diff --git a/src/base/debug.hh b/src/base/debug.hh
index be5fa36..38d92f9 100644
--- a/src/base/debug.hh
+++ b/src/base/debug.hh
@@ -43,6 +43,7 @@
 #define __BASE_DEBUG_HH__

 #include <initializer_list>
+#include <iostream>
 #include <map>
 #include <string>
 #include <vector>
@@ -142,7 +143,7 @@

 void clearDebugFlag(const char *string);

-void dumpDebugFlags();
+void dumpDebugFlags(std::ostream &os=std::cout);

 /**
  * \def DTRACE(x)
diff --git a/src/base/debug.test.cc b/src/base/debug.test.cc
index f995a33..22320d1 100644
--- a/src/base/debug.test.cc
+++ b/src/base/debug.test.cc
@@ -29,6 +29,7 @@
 #include <gtest/gtest.h>

 #include "base/debug.hh"
+#include "base/gtest/logging.hh"

 /** Test assignment of names and descriptions. */
 TEST(DebugFlagTest, NameDesc)
@@ -51,12 +52,11 @@
 TEST(DebugFlagDeathTest, UniqueNames)
 {
     Debug::SimpleFlag flag("FlagUniqueNamesTest", "A");
-    testing::internal::CaptureStderr();
+    gtestLogOutput.str("");
     EXPECT_ANY_THROW(Debug::SimpleFlag("FlagUniqueNamesTest", "B"));
     const std::string expected = "panic: panic condition !result.second "
         "occurred: Flag FlagUniqueNamesTest already defined!\n";
-    std::string actual = testing::internal::GetCapturedStderr().substr();
-    actual = actual.substr(actual.find(":", actual.find(":") + 1) + 2);
+    std::string actual = gtestLogOutput.str();
     EXPECT_EQ(expected, actual);
 }

@@ -266,9 +266,9 @@
     Debug::SimpleFlag flag("FlagDumpDebugFlagTest", "");

     // Verify that the names of the enabled flags are printed
-    testing::internal::CaptureStdout();
+    gtestLogOutput.str("");
     dumpDebugFlags();
-    std::string output = testing::internal::GetCapturedStdout();
+    std::string output = gtestLogOutput.str();
     EXPECT_EQ(output, "");
     ASSERT_FALSE(flag.enabled());
 }
@@ -298,9 +298,9 @@
     compound_flag_b.enable();

     // Verify that the names of the enabled flags are printed
-    testing::internal::CaptureStdout();
-    dumpDebugFlags();
-    std::string output = testing::internal::GetCapturedStdout();
+    std::ostringstream os;
+    dumpDebugFlags(os);
+    std::string output = os.str();
     EXPECT_EQ(output, "FlagDumpDebugFlagTestA\nFlagDumpDebugFlagTestC\n" \
         "FlagDumpDebugFlagTestE\n");
 }
diff --git a/src/base/socket.test.cc b/src/base/socket.test.cc
index 7262a02..7372911 100644
--- a/src/base/socket.test.cc
+++ b/src/base/socket.test.cc
@@ -28,6 +28,7 @@

 #include <gtest/gtest.h>

+#include "base/gtest/logging.hh"
 #include "base/socket.hh"

 #define TEST_PORT_1 7893
@@ -103,20 +104,10 @@
     /*
* You cannot listen to another port if you are already listening to one.
      */
-    testing::internal::CaptureStderr();
+    gtestLogOutput.str("");
     EXPECT_ANY_THROW(listen_socket.listen(TEST_PORT_1));
     std::string expected = "panic: Socket already listening!\n";
-    std::string actual = testing::internal::GetCapturedStderr().substr();
-
-    /*
-     * The GoogleExitLogger will output using the following:
-     * `std::cerr << loc.file << ":" << loc.line << ": " << s;`
-     * As we do not care about the file and line where the error originated
- * (this may change, and it shouldn't break the test when this happens), - * we strip out the leading `<file>:<line>: ` (we simply remove everything
-     * prior to two characters after the second colon in the string).
-     */
-    actual = actual.substr(actual.find(":", actual.find(":") + 1) + 2);
+    std::string actual = gtestLogOutput.str();
     EXPECT_EQ(expected, actual);
 }

@@ -128,12 +119,11 @@
     /*
* You cannot listen to another port if you are already listening to one.
      */
-    testing::internal::CaptureStderr();
+    gtestLogOutput.str("");
     EXPECT_ANY_THROW(listen_socket.listen(TEST_PORT_2));

     std::string expected = "panic: Socket already listening!\n";
-    std::string actual = testing::internal::GetCapturedStderr().substr();
-    actual = actual.substr(actual.find(":", actual.find(":") + 1) + 2);
+    std::string actual = gtestLogOutput.str();
     EXPECT_EQ(expected, actual);
 }

diff --git a/src/base/stats/storage.test.cc b/src/base/stats/storage.test.cc
index 3218438..36f73a6 100644
--- a/src/base/stats/storage.test.cc
+++ b/src/base/stats/storage.test.cc
@@ -32,6 +32,7 @@
 #include <cmath>

 #include "base/gtest/cur_tick_fake.hh"
+#include "base/gtest/logging.hh"
 #include "base/stats/storage.hh"

 // Instantiate the fake class to have a valid curTick of 0
@@ -272,9 +273,7 @@
 /** Test that an assertion is thrown when bucket size is 0. */
 TEST(StatsDistStorDeathTest, BucketSize0)
 {
-    testing::internal::CaptureStderr();
     EXPECT_ANY_THROW(Stats::DistStor::Params params(0, 5, 0));
-    testing::internal::GetCapturedStderr();
 }
 #endif

@@ -500,17 +499,13 @@
/** Test that an assertion is thrown when not enough buckets are provided. */
 TEST(StatsHistStorDeathTest, NotEnoughBuckets0)
 {
-    testing::internal::CaptureStderr();
     EXPECT_ANY_THROW(Stats::HistStor::Params params(0));
-    testing::internal::GetCapturedStderr();
 }

/** Test that an assertion is thrown when not enough buckets are provided. */
 TEST(StatsHistStorDeathTest, NotEnoughBuckets1)
 {
-    testing::internal::CaptureStderr();
     EXPECT_ANY_THROW(Stats::HistStor::Params params(1));
-    testing::internal::GetCapturedStderr();
 }
 #endif


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/42723
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I51d3c0ec42981b70736e7b3bbedfb49f82dc7f95
Gerrit-Change-Number: 42723
Gerrit-PatchSet: 3
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to