Bug 1313489 - Part 2: Convert DeadlockDetectorScalability to a gtest. r=froydnj
☠☠ backed out by 2e21f3a89751 ☠ ☠
authorEric Rahm <erahm@mozilla.com>
Wed, 09 Nov 2016 10:25:17 -0800
changeset 351982 54098e53a5841ce10c1f3fc2bb507b77587e7d7c
parent 351981 7b0acef284ad19804d1d3d681cba2f5ba6622377
child 351983 d6a0b28b04e4b35494d15155f79e43cdc5244835
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1313489
milestone52.0a1
Bug 1313489 - Part 2: Convert DeadlockDetectorScalability to a gtest. r=froydnj This converts the tests to gtests. Most of them are just runtime tests and just hava dummy assertion that everything ran. One test remains disabled, although it's still built-in. You can run the disabled test with the following command: > GTEST_ALSO_RUN_DISABLED_TESTS=1 ./mach gtest DeadlockDetectorScalability.* MozReview-Commit-ID: 57rxjiZKjQ6
testing/cppunittest.ini
xpcom/tests/TestDeadlockDetectorScalability.cpp
xpcom/tests/gtest/TestDeadlockDetectorScalability.cpp
xpcom/tests/gtest/moz.build
xpcom/tests/moz.build
--- a/testing/cppunittest.ini
+++ b/testing/cppunittest.ini
@@ -10,17 +10,16 @@
 skip-if = os != 'win'
 [TestCasting]
 [TestCeilingFloor]
 [TestCertDB]
 [TestCheckedInt]
 [TestCookie]
 [TestCountPopulation]
 [TestCountZeroes]
-[TestDeadlockDetectorScalability]
 [TestDllInterceptor]
 skip-if = os != 'win'
 [TestEndian]
 [TestEnumeratedArray]
 [TestEnumSet]
 [TestEnumTypeTraits]
 [TestFastBernoulliTrial]
 [TestFloatingPoint]
rename from xpcom/tests/TestDeadlockDetectorScalability.cpp
rename to xpcom/tests/gtest/TestDeadlockDetectorScalability.cpp
--- a/xpcom/tests/TestDeadlockDetectorScalability.cpp
+++ b/xpcom/tests/gtest/TestDeadlockDetectorScalability.cpp
@@ -2,78 +2,58 @@
  * vim: sw=4 ts=4 et :
  * 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/. */
 
 // Avoid DMD-specific parts of MOZ_DEFINE_MALLOC_SIZE_OF
 #undef MOZ_DMD
 
-#include "TestHarness.h"
 #include "nsIMemoryReporter.h"
-
 #include "mozilla/Mutex.h"
 
-#define PASS()                                  \
-    do {                                        \
-        passed(__FUNCTION__);                   \
-        return NS_OK;                           \
-    } while (0)
-
-#define FAIL(why)                               \
-    do {                                        \
-        fail("%s | %s - %s", __FILE__, __FUNCTION__, why); \
-        return NS_ERROR_FAILURE;                \
-    } while (0)
-
-
-// def/undef these to run particular tests.
-#undef DD_TEST1
-#undef DD_TEST2
-#undef DD_TEST3
-#undef DD_TEST4
+#include "gtest/gtest.h"
 
 //-----------------------------------------------------------------------------
 
-#ifdef DD_TEST1
-
 static void
 AllocLockRecurseUnlockFree(int i)
 {
     if (0 == i)
         return;
 
     mozilla::Mutex* lock = new mozilla::Mutex("deadlockDetector.scalability.t1");
     {
         mozilla::MutexAutoLock _(*lock);
         AllocLockRecurseUnlockFree(i - 1);
     }
     delete lock;
 }
 
 // This test creates a resource dependency chain N elements long, then
 // frees all the resources in the chain.
-static nsresult
-LengthNDepChain(int N)
+TEST(DeadlockDetectorScalability, LengthNDepChain)
 {
+    const int N = 1 << 14; // 16K
     AllocLockRecurseUnlockFree(N);
-    PASS();
+    ASSERT_TRUE(true);
 }
 
-#endif
-
 //-----------------------------------------------------------------------------
 
-#ifdef DD_TEST2
-
 // This test creates a single lock that is ordered < N resources, then
 // repeatedly exercises this order k times.
-static nsresult
-OneLockNDeps(const int N, const int K)
+//
+// NB: It takes a minute or two to run so it is disabled by default.
+TEST(DeadlockDetectorScalability, DISABLED_OneLockNDeps)
 {
+    // NB: Using a larger test size to stress our traversal logic.
+    const int N = 1 << 17; // 131k
+    const int K = 100;
+
     mozilla::Mutex* lock = new mozilla::Mutex("deadlockDetector.scalability.t2.master");
     mozilla::Mutex** locks = new mozilla::Mutex*[N];
     if (!locks)
         NS_RUNTIMEABORT("couldn't allocate lock array");
 
     for (int i = 0; i < N; ++i)
         locks[i] =
             new mozilla::Mutex("deadlockDetector.scalability.t2.dep");
@@ -90,35 +70,33 @@ OneLockNDeps(const int N, const int K)
             for (int j = 0; j < N; ++j)
                 mozilla::MutexAutoLock s(*locks[i]);
     }
 
     for (int i = 0; i < N; ++i)
         delete locks[i];
     delete[] locks;
 
-    PASS();
+    ASSERT_TRUE(true);
 }
 
-#endif
-
 //-----------------------------------------------------------------------------
 
-#ifdef DD_TEST3
-
 // This test creates N resources and adds the theoretical maximum number
 // of dependencies, O(N^2).  It then repeats that sequence of
 // acquisitions k times.  Finally, all resources are freed.
 //
 // It's very difficult to perform well on this test.  It's put forth as a
 // challenge problem.
 
-static nsresult
-MaxDepsNsq(const int N, const int K)
+TEST(DeadlockDetectorScalability, MaxDepsNsq)
 {
+    const int N = 1 << 10; // 1k
+    const int K = 10;
+
     mozilla::Mutex** locks = new mozilla::Mutex*[N];
     if (!locks)
         NS_RUNTIMEABORT("couldn't allocate lock array");
 
     for (int i = 0; i < N; ++i)
         locks[i] = new mozilla::Mutex("deadlockDetector.scalability.t3");
 
     for (int i = 0; i < N; ++i) {
@@ -134,32 +112,30 @@ MaxDepsNsq(const int N, const int K)
                 mozilla::MutexAutoLock al2(*locks[k]);
         }
     }
 
     for (int i = 0; i < N; ++i)
         delete locks[i];
     delete[] locks;
 
-    PASS();
+    ASSERT_TRUE(true);
 }
 
-#endif
-
 //-----------------------------------------------------------------------------
 
-#ifdef DD_TEST4
-
 // This test creates a single lock that is ordered < N resources. The
 // resources are allocated, exercised K times, and deallocated one at
 // a time.
 
-static nsresult
-OneLockNDepsUsedSeveralTimes(const size_t N, const size_t K)
+TEST(DeadlockDetectorScalability, OneLockNDepsUsedSeveralTimes)
 {
+    const size_t N = 1 << 17; // 131k
+    const size_t K = 3;
+
     // Create master lock.
     mozilla::Mutex* lock_1 = new mozilla::Mutex("deadlockDetector.scalability.t4.master");
     for (size_t n = 0; n < N; n++) {
         // Create child lock.
         mozilla::Mutex* lock_2 = new mozilla::Mutex("deadlockDetector.scalability.t4.child");
 
         // First lock the master.
         mozilla::MutexAutoLock m(*lock_1);
@@ -171,63 +147,24 @@ OneLockNDepsUsedSeveralTimes(const size_
 
         // Destroy the child lock.
         delete lock_2;
     }
 
     // Cleanup the master lock.
     delete lock_1;
 
-    PASS();
+    ASSERT_TRUE(true);
 }
 
-#endif
-
 //-----------------------------------------------------------------------------
 
 MOZ_DEFINE_MALLOC_SIZE_OF(DeadlockDetectorMallocSizeOf)
 
-int
-main(int argc, char** argv)
+// This is a simple test that exercises the deadlock detector memory reporting
+// functionality.
+TEST(DeadlockDetectorScalability, SizeOf)
 {
-    ScopedXPCOM xpcom("Deadlock detector scalability (" __FILE__ ")");
-    if (xpcom.failed())
-        return 1;
-
-    int rv = 0;
-
-    // Uncomment these tests to run them.  Not expected to be common.
-
-#ifndef DD_TEST1
-    puts("Skipping not-requested LengthNDepChain() test");
-#else
-    if (NS_FAILED(LengthNDepChain(1 << 14))) // 16K
-        rv = 1;
-#endif
-
-#ifndef DD_TEST2
-    puts("Skipping not-requested OneLockNDeps() test");
-#else
-    // NB: Using a larger test size to stress our traversal logic.
-    if (NS_FAILED(OneLockNDeps(1 << 17, 100))) // 131k
-        rv = 1;
-#endif
-
-#ifndef DD_TEST3
-    puts("Skipping not-requested MaxDepsNsq() test");
-#else
-    if (NS_FAILED(MaxDepsNsq(1 << 10, 10))) // 1k
-        rv = 1;
-#endif
-
-#ifndef DD_TEST4
-    puts("Skipping not-requested OneLockNDepsUsedSeveralTimes() test");
-#else
-    if (NS_FAILED(OneLockNDepsUsedSeveralTimes(1 << 17, 3))) // 131k
-        rv = 1;
-#endif
-
     size_t memory_used = mozilla::BlockingResourceBase::SizeOfDeadlockDetector(
         DeadlockDetectorMallocSizeOf);
-    printf_stderr("Used %d bytes\n", (int)memory_used);
 
-    return rv;
+    ASSERT_GT(memory_used, size_t(0));
 }
--- a/xpcom/tests/gtest/moz.build
+++ b/xpcom/tests/gtest/moz.build
@@ -44,16 +44,17 @@ UNIFIED_SOURCES += [
     'TestXPIDLString.cpp',
 ]
 
 if CONFIG['MOZ_DEBUG'] and CONFIG['OS_ARCH'] not in ('WINNT') and CONFIG['OS_TARGET'] != 'Android':
     # FIXME bug 523392: TestDeadlockDetector doesn't like Windows
     # Bug 1054249: Doesn't work on Android
     UNIFIED_SOURCES += [
         'TestDeadlockDetector.cpp',
+        'TestDeadlockDetectorScalability.cpp',
     ]
 
 # Compile TestAllocReplacement separately so Windows headers don't pollute
 # the global namespace for other files.
 SOURCES += [
     'TestAllocReplacement.cpp',
     'TestCOMPtr.cpp', # Redefines IFoo and IBar
     'TestHashtables.cpp', # Redefines IFoo
--- a/xpcom/tests/moz.build
+++ b/xpcom/tests/moz.build
@@ -48,23 +48,16 @@ if CONFIG['WRAP_STL_INCLUDES'] and not C
 
 XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
 
 # FIXME: bug 577500 TestStaticAtoms fails when run in dist/bin
 #CPP_UNIT_TESTS += [
 #    'TestStaticAtoms',
 #]
 
-if CONFIG['MOZ_DEBUG'] and CONFIG['OS_ARCH'] not in ('WINNT'):
-    # FIXME bug 523392: TestDeadlockDetector doesn't like Windows
-    # FIXME bug 523378: also fails on OS X
-    GeckoCppUnitTests([
-        'TestDeadlockDetectorScalability',
-    ])
-
 if CONFIG['COMPILE_ENVIRONMENT']:
     TEST_HARNESS_FILES.xpcshell.xpcom.tests.unit += [
         '!/dist/bin/components/xpcomtest.xpt',
     ]
 
 XPIDL_MODULE = 'xpcomtest'
 XPIDL_SOURCES += [
     'NotXPCOMTest.idl',