Bug 949708 - Dump RLogRingBuffer on test failures in ice_unittest. r=ekr
authorByron Campen [:bwc] <docfaraday@gmail.com>
Fri, 03 Jan 2014 13:36:37 -0800
changeset 178376 ea1cb546306339528ca00268de37769278402d17
parent 178375 403ab3213879eed64e81fcd4fc93e40bc4d7b92b
child 178377 e281ab880710a237530b709cc716e16f04461347
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersekr
bugs949708
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 949708 - Dump RLogRingBuffer on test failures in ice_unittest. r=ekr
media/mtransport/test/gtest_ringbuffer_dumper.h
media/mtransport/test/ice_unittest.cpp
media/webrtc/signaling/test/signaling_unittests.cpp
new file mode 100644
--- /dev/null
+++ b/media/mtransport/test/gtest_ringbuffer_dumper.h
@@ -0,0 +1,83 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// Original author: bcampen@mozilla.com
+
+#ifndef gtest_ringbuffer_dumper_h__
+#define gtest_ringbuffer_dumper_h__
+
+#include "mozilla/SyncRunnable.h"
+
+#define GTEST_HAS_RTTI 0
+#include "gtest/gtest.h"
+#include "gtest_utils.h"
+
+#include "runnable_utils.h"
+#include "rlogringbuffer.h"
+
+using mozilla::RLogRingBuffer;
+using mozilla::WrapRunnable;
+
+namespace test {
+class RingbufferDumper : public ::testing::EmptyTestEventListener {
+  public:
+    explicit RingbufferDumper(MtransportTestUtils* test_utils) :
+      test_utils_(test_utils)
+    {}
+
+    void ClearRingBuffer_s() {
+      RLogRingBuffer::CreateInstance();
+      // Set limit to zero to clear the ringbuffer
+      RLogRingBuffer::GetInstance()->SetLogLimit(0);
+      RLogRingBuffer::GetInstance()->SetLogLimit(UINT32_MAX);
+    }
+
+    void DestroyRingBuffer_s() {
+      RLogRingBuffer::DestroyInstance();
+    }
+
+    void DumpRingBuffer_s() {
+      std::deque<std::string> logs;
+      // Get an unlimited number of log lines, with no filter
+      RLogRingBuffer::GetInstance()->GetAny(0, &logs);
+      for (auto l = logs.begin(); l != logs.end(); ++l) {
+        std::cout << *l << std::endl;
+      }
+      ClearRingBuffer_s();
+    }
+
+    virtual void OnTestStart(const ::testing::TestInfo& testInfo) {
+      mozilla::SyncRunnable::DispatchToThread(
+          test_utils_->sts_target(),
+          WrapRunnable(this, &RingbufferDumper::ClearRingBuffer_s));
+    }
+
+    virtual void OnTestEnd(const ::testing::TestInfo& testInfo) {
+      mozilla::SyncRunnable::DispatchToThread(
+          test_utils_->sts_target(),
+          WrapRunnable(this, &RingbufferDumper::DestroyRingBuffer_s));
+    }
+
+    // Called after a failed assertion or a SUCCEED() invocation.
+    virtual void OnTestPartResult(const ::testing::TestPartResult& testResult) {
+      if (testResult.failed()) {
+        // Dump (and empty) the RLogRingBuffer
+        mozilla::SyncRunnable::DispatchToThread(
+            test_utils_->sts_target(),
+            WrapRunnable(this, &RingbufferDumper::DumpRingBuffer_s));
+      }
+    }
+
+  private:
+    MtransportTestUtils *test_utils_;
+};
+
+} // namespace test
+
+#endif // gtest_ringbuffer_dumper_h__
+
+
+
--- a/media/mtransport/test/ice_unittest.cpp
+++ b/media/mtransport/test/ice_unittest.cpp
@@ -26,16 +26,17 @@
 #include "nsXPCOM.h"
 
 #include "nricectx.h"
 #include "nricemediastream.h"
 #include "nriceresolverfake.h"
 #include "nriceresolver.h"
 #include "nrinterfaceprioritizer.h"
 #include "mtransport_test_utils.h"
+#include "gtest_ringbuffer_dumper.h"
 #include "rlogringbuffer.h"
 #include "runnable_utils.h"
 #include "stunserver.h"
 // TODO(bcampen@mozilla.com): Big fat hack since the build system doesn't give
 // us a clean way to add object files to a single executable.
 #include "stunserver.cpp"
 #include "stun_udp_socket_filter.h"
 #include "mozilla/net/DNS.h"
@@ -1621,16 +1622,21 @@ int main(int argc, char **argv)
 
   test_utils = new MtransportTestUtils();
   NSS_NoDB_Init(nullptr);
   NSS_SetDomesticPolicy();
 
   // Start the tests
   ::testing::InitGoogleTest(&argc, argv);
 
+  ::testing::TestEventListeners& listeners =
+        ::testing::UnitTest::GetInstance()->listeners();
+  // Adds a listener to the end.  Google Test takes the ownership.
+
+  listeners.Append(new test::RingbufferDumper(test_utils));
   test_utils->sts_target()->Dispatch(
     WrapRunnableNM(&TestStunServer::GetInstance), NS_DISPATCH_SYNC);
 
   int rv = RUN_ALL_TESTS();
 
   test_utils->sts_target()->Dispatch(
     WrapRunnableNM(&TestStunServer::ShutdownInstance), NS_DISPATCH_SYNC);
 
--- a/media/webrtc/signaling/test/signaling_unittests.cpp
+++ b/media/webrtc/signaling/test/signaling_unittests.cpp
@@ -41,16 +41,17 @@
 #include "rlogringbuffer.h"
 #include "mozilla/SyncRunnable.h"
 #include "logging.h"
 #include "stunserver.h"
 #include "stunserver.cpp"
 #include "PeerConnectionImplEnumsBinding.cpp"
 
 #include "mtransport_test_utils.h"
+#include "gtest_ringbuffer_dumper.h"
 MtransportTestUtils *test_utils;
 nsCOMPtr<nsIThread> gThread;
 
 #ifndef USE_FAKE_MEDIA_STREAMS
 #error USE_FAKE_MEDIA_STREAMS undefined
 #endif
 #ifndef USE_FAKE_PCOBSERVER
 #error USE_FAKE_PCOBSERVER undefined
@@ -98,61 +99,16 @@ private:
   }
 };
 }
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 namespace test {
-class RingbufferDumper : public ::testing::EmptyTestEventListener {
-  void ClearRingBuffer_s() {
-    RLogRingBuffer::CreateInstance();
-    // Set limit to zero to clear the ringbuffer
-    RLogRingBuffer::GetInstance()->SetLogLimit(0);
-    RLogRingBuffer::GetInstance()->SetLogLimit(UINT32_MAX);
-  }
-
-  void DestroyRingBuffer_s() {
-    RLogRingBuffer::DestroyInstance();
-  }
-
-  void DumpRingBuffer_s() {
-      std::deque<std::string> logs;
-      // Get an unlimited number of log lines, with no filter
-      RLogRingBuffer::GetInstance()->GetAny(0, &logs);
-      for (auto l = logs.begin(); l != logs.end(); ++l) {
-        std::cout << *l << std::endl;
-      }
-      ClearRingBuffer_s();
-  }
-
-  virtual void OnTestStart(const ::testing::TestInfo& testInfo) {
-    mozilla::SyncRunnable::DispatchToThread(
-      test_utils->sts_target(),
-      WrapRunnable(this, &RingbufferDumper::ClearRingBuffer_s));
-  }
-
-  virtual void OnTestEnd(const ::testing::TestInfo& testInfo) {
-    mozilla::SyncRunnable::DispatchToThread(
-      test_utils->sts_target(),
-      WrapRunnable(this, &RingbufferDumper::DestroyRingBuffer_s));
-  }
-
-  // Called after a failed assertion or a SUCCEED() invocation.
-  virtual void OnTestPartResult(const ::testing::TestPartResult& testResult) {
-    if (testResult.failed()) {
-      // Dump (and empty) the RLogRingBuffer
-      mozilla::SyncRunnable::DispatchToThread(
-        test_utils->sts_target(),
-        WrapRunnable(this, &RingbufferDumper::DumpRingBuffer_s));
-    }
-  }
-};
-
 std::string indent(const std::string &s, int width = 4) {
   std::string prefix;
   std::string out;
   char previous = '\n';
   prefix.assign(width, ' ');
   for (std::string::const_iterator i = s.begin(); i != s.end(); i++) {
     if (previous == '\n') {
       out += prefix;
@@ -3717,17 +3673,17 @@ int main(int argc, char **argv) {
     if (!strcmp(argv[i],"-t")) {
       kDefaultTimeout = 20000;
     }
   }
 
   ::testing::TestEventListeners& listeners =
         ::testing::UnitTest::GetInstance()->listeners();
   // Adds a listener to the end.  Google Test takes the ownership.
-  listeners.Append(new test::RingbufferDumper);
+  listeners.Append(new test::RingbufferDumper(test_utils));
   test_utils->sts_target()->Dispatch(
     WrapRunnableNM(&TestStunServer::GetInstance), NS_DISPATCH_SYNC);
 
   ::testing::AddGlobalTestEnvironment(new test::SignalingEnvironment);
   int result = RUN_ALL_TESTS();
 
   test_utils->sts_target()->Dispatch(
     WrapRunnableNM(&TestStunServer::ShutdownInstance), NS_DISPATCH_SYNC);