Bug 1125559 - Move TestThreadPool.cpp to gtest and enable it; r=froydnj
☠☠ backed out by c2fd55873192 ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 26 Jan 2015 17:10:09 -0500
changeset 225887 8ae4f78d7e259bdde22b41764a3c2a9a5d250d3c
parent 225886 67496f44f4617eda8f650d5c801fd9b327e5ac96
child 225888 8aa2406244bcd81ff460d2a7902ed5e73f0c596d
push id54674
push usereakhgari@mozilla.com
push dateMon, 26 Jan 2015 22:11:11 +0000
treeherdermozilla-inbound@8ae4f78d7e25 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1125559
milestone38.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 1125559 - Move TestThreadPool.cpp to gtest and enable it; r=froydnj
xpcom/tests/TestThreadPool.cpp
xpcom/tests/gtest/TestThreadPool.cpp
xpcom/tests/gtest/moz.build
xpcom/tests/moz.build
rename from xpcom/tests/TestThreadPool.cpp
rename to xpcom/tests/gtest/TestThreadPool.cpp
--- a/xpcom/tests/TestThreadPool.cpp
+++ b/xpcom/tests/gtest/TestThreadPool.cpp
@@ -7,56 +7,54 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include "nsXPCOM.h"
 #include "nsXPCOMCIDInternal.h"
 #include "nsIThreadPool.h"
 #include "nsComponentManagerUtils.h"
 #include "nsCOMPtr.h"
 #include "nsIRunnable.h"
+#include "mozilla/Atomics.h"
+#include "gtest/gtest.h"
 
-class Task : public nsIRunnable
+class Task MOZ_FINAL : public nsIRunnable
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
 
-  Task(int i) : mIndex(i) {}
+  explicit Task(int i) : mIndex(i) {}
 
   NS_IMETHOD Run()
   {
     printf("###(%d) running from thread: %p\n", mIndex, (void *) PR_GetCurrentThread());
     int r = (int) ((float) rand() * 200 / RAND_MAX);
     PR_Sleep(PR_MillisecondsToInterval(r));
     printf("###(%d) exiting from thread: %p\n", mIndex, (void *) PR_GetCurrentThread());
+    ++sCount;
     return NS_OK;
   }
 
+  static mozilla::Atomic<int> sCount;
+
 private:
+  ~Task() {}
+
   int mIndex;
 };
 NS_IMPL_ISUPPORTS(Task, nsIRunnable)
 
-static nsresult
-RunTests()
+mozilla::Atomic<int> Task::sCount;
+
+TEST(ThreadPool, Main)
 {
   nsCOMPtr<nsIThreadPool> pool = do_CreateInstance(NS_THREADPOOL_CONTRACTID);
-  NS_ENSURE_STATE(pool);
+  EXPECT_TRUE(pool);
 
   for (int i = 0; i < 100; ++i) {
     nsCOMPtr<nsIRunnable> task = new Task(i);
-    NS_ENSURE_TRUE(task, NS_ERROR_OUT_OF_MEMORY);
+    EXPECT_TRUE(task);
 
     pool->Dispatch(task, NS_DISPATCH_NORMAL);
   }
 
   pool->Shutdown();
-  return NS_OK;
+  EXPECT_EQ(Task::sCount, 100);
 }
-
-int
-main(int argc, char **argv)
-{
-  if (NS_FAILED(NS_InitXPCOM2(nullptr, nullptr, nullptr)))
-    return -1;
-  RunTests();
-  NS_ShutdownXPCOM(nullptr);
-  return 0;
-}
--- a/xpcom/tests/gtest/moz.build
+++ b/xpcom/tests/gtest/moz.build
@@ -9,14 +9,15 @@ UNIFIED_SOURCES += [
     'TestEncoding.cpp',
     'TestExpirationTracker.cpp',
     'TestPipes.cpp',
     'TestPriorityQueue.cpp',
     'TestSnappyStreams.cpp',
     'TestStorageStream.cpp',
     'TestStrings.cpp',
     'TestSynchronization.cpp',
+    'TestThreadPool.cpp',
     'TestTimeStamp.cpp',
 ]
 
 FINAL_LIBRARY = 'xul-gtest'
 
 FAIL_ON_WARNINGS = True
--- a/xpcom/tests/moz.build
+++ b/xpcom/tests/moz.build
@@ -75,17 +75,16 @@ GeckoCppUnitTests([
 
 if CONFIG['MOZ_MEMORY']:
     GeckoCppUnitTests([
         'TestJemalloc',
     ])
 
 # XXX Make these tests work in libxul builds.
 #CPP_UNIT_TESTS += [
-#    'TestThreadPool',
 #    'TestThreads',
 #    'TestXPIDLString',
 #    'TestUTF',
 #    'TestAtoms',
 #]
 
 # FIXME: bug 577500 TestStaticAtoms fails when run in dist/bin
 #CPP_UNIT_TESTS += [