Backed out changeset 54098e53a584 (bug 1313489)
authorSebastian Hengst <archaeopteryx@coole-files.de>
Wed, 09 Nov 2016 21:10:02 +0100
changeset 348637 2e21f3a89751b5bf85d8c10b983dfcc845452cf8
parent 348636 ea14d2a7c5dc3893ed6d42d94cbe36c45d7fd975
child 348638 3aa99c2ab46d92ca0f1480d36aed87b49c575efd
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1313489
milestone52.0a1
backs out54098e53a5841ce10c1f3fc2bb507b77587e7d7c
Backed out changeset 54098e53a584 (bug 1313489)
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,16 +10,17 @@
 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/gtest/TestDeadlockDetectorScalability.cpp
rename to xpcom/tests/TestDeadlockDetectorScalability.cpp
--- a/xpcom/tests/gtest/TestDeadlockDetectorScalability.cpp
+++ b/xpcom/tests/TestDeadlockDetectorScalability.cpp
@@ -2,58 +2,78 @@
  * 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"
 
-#include "gtest/gtest.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
 
 //-----------------------------------------------------------------------------
 
+#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.
-TEST(DeadlockDetectorScalability, LengthNDepChain)
+static nsresult
+LengthNDepChain(int N)
 {
-    const int N = 1 << 14; // 16K
     AllocLockRecurseUnlockFree(N);
-    ASSERT_TRUE(true);
+    PASS();
 }
 
+#endif
+
 //-----------------------------------------------------------------------------
 
+#ifdef DD_TEST2
+
 // This test creates a single lock that is ordered < N resources, then
 // repeatedly exercises this order k times.
-//
-// NB: It takes a minute or two to run so it is disabled by default.
-TEST(DeadlockDetectorScalability, DISABLED_OneLockNDeps)
+static nsresult
+OneLockNDeps(const int N, const int K)
 {
-    // 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");
@@ -70,33 +90,35 @@ TEST(DeadlockDetectorScalability, DISABL
             for (int j = 0; j < N; ++j)
                 mozilla::MutexAutoLock s(*locks[i]);
     }
 
     for (int i = 0; i < N; ++i)
         delete locks[i];
     delete[] locks;
 
-    ASSERT_TRUE(true);
+    PASS();
 }
 
+#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.
 
-TEST(DeadlockDetectorScalability, MaxDepsNsq)
+static nsresult
+MaxDepsNsq(const int N, const int K)
 {
-    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) {
@@ -112,30 +134,32 @@ TEST(DeadlockDetectorScalability, MaxDep
                 mozilla::MutexAutoLock al2(*locks[k]);
         }
     }
 
     for (int i = 0; i < N; ++i)
         delete locks[i];
     delete[] locks;
 
-    ASSERT_TRUE(true);
+    PASS();
 }
 
+#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.
 
-TEST(DeadlockDetectorScalability, OneLockNDepsUsedSeveralTimes)
+static nsresult
+OneLockNDepsUsedSeveralTimes(const size_t N, const size_t K)
 {
-    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);
@@ -147,24 +171,63 @@ TEST(DeadlockDetectorScalability, OneLoc
 
         // Destroy the child lock.
         delete lock_2;
     }
 
     // Cleanup the master lock.
     delete lock_1;
 
-    ASSERT_TRUE(true);
+    PASS();
 }
 
+#endif
+
 //-----------------------------------------------------------------------------
 
 MOZ_DEFINE_MALLOC_SIZE_OF(DeadlockDetectorMallocSizeOf)
 
-// This is a simple test that exercises the deadlock detector memory reporting
-// functionality.
-TEST(DeadlockDetectorScalability, SizeOf)
+int
+main(int argc, char** argv)
 {
+    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);
 
-    ASSERT_GT(memory_used, size_t(0));
+    return rv;
 }
--- a/xpcom/tests/gtest/moz.build
+++ b/xpcom/tests/gtest/moz.build
@@ -44,17 +44,16 @@ 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
@@ -47,16 +47,23 @@ 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',