allow tests to optionally use multiple threads

modify threaded path ops tests to check

Background: this CL came out of a conversation with Eric where I learned that 10s of machines host 100s of bots. Since the bot hosting tests may be shared with many other tasks, it seems unwise for path ops to launch multiple test threads.

The change here is to make launching multiple threads "opt-in" and by default, bots can run path ops in a single thread.
Review URL: https://codereview.chromium.org/14002007

git-svn-id: http://skia.googlecode.com/svn/trunk@8750 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/PathOpsExtendedTest.cpp b/tests/PathOpsExtendedTest.cpp
index 9b27fce..675918f 100644
--- a/tests/PathOpsExtendedTest.cpp
+++ b/tests/PathOpsExtendedTest.cpp
@@ -43,12 +43,6 @@
 static bool gComparePathsAssert = true;
 static bool gPathStrAssert = true;
 
-#if FORCE_RELEASE
-static bool gRunTestsInOneThread = true;
-#else
-static bool gRunTestsInOneThread = true;
-#endif
-
 static void showPathContour(SkPath::Iter& iter) {
     uint8_t verb;
     SkPoint pts[4];
@@ -522,14 +516,14 @@
 const int maxThreadsAllocated = 64;
 static int maxThreads = 1;
 
-int initializeTests(const char* test) {
+int initializeTests(skiatest::Reporter* reporter, const char* test) {
 #ifdef SK_DEBUG
     gDebugMaxWindSum = 4;
     gDebugMaxWindValue = 4;
 #endif
     testName = test;
     size_t testNameSize = strlen(test);
-    if (!gRunTestsInOneThread) {
+    if (reporter->allowThreaded()) {
         int threads = -1;
 #ifdef SK_BUILD_FOR_MAC
         size_t size = sizeof(threads);
diff --git a/tests/PathOpsExtendedTest.h b/tests/PathOpsExtendedTest.h
index ece1c86..5644c94 100644
--- a/tests/PathOpsExtendedTest.h
+++ b/tests/PathOpsExtendedTest.h
@@ -35,7 +35,7 @@
                          const char* pathStr);
 extern bool testSimplify(skiatest::Reporter* reporter, const SkPath& path);
 
-int initializeTests(const char* testName);
+int initializeTests(skiatest::Reporter* reporter, const char* testName);
 void outputProgress(char* ramStr, const char* pathStr, SkPath::FillType );
 void outputProgress(char* ramStr, const char* pathStr, SkPathOp op);
 
diff --git a/tests/PathOpsOpCubicThreadedTest.cpp b/tests/PathOpsOpCubicThreadedTest.cpp
index 4197d76..3448ee9 100644
--- a/tests/PathOpsOpCubicThreadedTest.cpp
+++ b/tests/PathOpsOpCubicThreadedTest.cpp
@@ -59,7 +59,7 @@
 
 static void PathOpsOpCubicsThreadedTest(skiatest::Reporter* reporter)
 {
-    int threadCount = initializeTests("cubicOp");
+    int threadCount = initializeTests(reporter, "cubicOp");
     PathOpsThreadedTestRunner testRunner(reporter, threadCount);
     for (int a = 0; a < 6; ++a) {  // outermost
         for (int b = a + 1; b < 7; ++b) {
diff --git a/tests/PathOpsOpRectThreadedTest.cpp b/tests/PathOpsOpRectThreadedTest.cpp
index e7aec8a..58e4707 100644
--- a/tests/PathOpsOpRectThreadedTest.cpp
+++ b/tests/PathOpsOpRectThreadedTest.cpp
@@ -67,7 +67,7 @@
 }
 
 static void PathOpsRectsThreadedTest(skiatest::Reporter* reporter) {
-    int threadCount = initializeTests("testOp");
+    int threadCount = initializeTests(reporter, "testOp");
     PathOpsThreadedTestRunner testRunner(reporter, threadCount);
     for (int a = 0; a < 6; ++a) {  // outermost
         for (int b = a + 1; b < 7; ++b) {
diff --git a/tests/PathOpsQuadLineIntersectionThreadedTest.cpp b/tests/PathOpsQuadLineIntersectionThreadedTest.cpp
index 23adaf9..7d1b133 100644
--- a/tests/PathOpsQuadLineIntersectionThreadedTest.cpp
+++ b/tests/PathOpsQuadLineIntersectionThreadedTest.cpp
@@ -113,7 +113,7 @@
 
 static void PathOpsQuadLineIntersectionThreadedTest(skiatest::Reporter* reporter)
 {
-    int threadCount = initializeTests("testQuadLineIntersect");
+    int threadCount = initializeTests(reporter, "testQuadLineIntersect");
     PathOpsThreadedTestRunner testRunner(reporter, threadCount);
     for (int a = 0; a < 16; ++a) {
         for (int b = 0 ; b < 16; ++b) {
diff --git a/tests/PathOpsSimplifyDegenerateThreadedTest.cpp b/tests/PathOpsSimplifyDegenerateThreadedTest.cpp
index 1c1f9ca..22997e7 100755
--- a/tests/PathOpsSimplifyDegenerateThreadedTest.cpp
+++ b/tests/PathOpsSimplifyDegenerateThreadedTest.cpp
@@ -61,7 +61,7 @@
 }
 
 static void PathOpsSimplifyDegeneratesThreadedTest(skiatest::Reporter* reporter) {
-    int threadCount = initializeTests("testDegenerates");
+    int threadCount = initializeTests(reporter, "testDegenerates");
     PathOpsThreadedTestRunner testRunner(reporter, threadCount);
     for (int a = 0; a < 16; ++a) {
         int ax = a & 0x03;
diff --git a/tests/PathOpsSimplifyQuadThreadedTest.cpp b/tests/PathOpsSimplifyQuadThreadedTest.cpp
index 0290602..8dea049 100644
--- a/tests/PathOpsSimplifyQuadThreadedTest.cpp
+++ b/tests/PathOpsSimplifyQuadThreadedTest.cpp
@@ -68,7 +68,7 @@
 
 static void PathOpsSimplifyQuadsThreadedTest(skiatest::Reporter* reporter)
 {
-    int threadCount = initializeTests("testQuads");
+    int threadCount = initializeTests(reporter, "testQuads");
     PathOpsThreadedTestRunner testRunner(reporter, threadCount);
     int a = 0;
     for (; a < 16; ++a) {
diff --git a/tests/PathOpsSimplifyQuadralateralsThreadedTest.cpp b/tests/PathOpsSimplifyQuadralateralsThreadedTest.cpp
index 99cd79e..5afadbe 100755
--- a/tests/PathOpsSimplifyQuadralateralsThreadedTest.cpp
+++ b/tests/PathOpsSimplifyQuadralateralsThreadedTest.cpp
@@ -69,7 +69,7 @@
 }
 
 static void PathOpsSimplifyQuadralateralsThreadedTest(skiatest::Reporter* reporter) {
-    int threadCount = initializeTests("testQuadralaterals");
+    int threadCount = initializeTests(reporter, "testQuadralaterals");
     PathOpsThreadedTestRunner testRunner(reporter, threadCount);
     for (int a = 0; a < 16; ++a) {
         for (int b = a ; b < 16; ++b) {
diff --git a/tests/PathOpsSimplifyRectThreadedTest.cpp b/tests/PathOpsSimplifyRectThreadedTest.cpp
index 33863cf..66b70d3 100644
--- a/tests/PathOpsSimplifyRectThreadedTest.cpp
+++ b/tests/PathOpsSimplifyRectThreadedTest.cpp
@@ -173,7 +173,7 @@
 
 static void PathOpsSimplifyRectsThreadedTest(skiatest::Reporter* reporter)
 {
-    int threadCount = initializeTests("testLine");
+    int threadCount = initializeTests(reporter, "testLine");
     PathOpsThreadedTestRunner testRunner(reporter, threadCount);
     for (int a = 0; a < 8; ++a) {  // outermost
         for (int b = a ; b < 8; ++b) {
diff --git a/tests/PathOpsSimplifyTrianglesThreadedTest.cpp b/tests/PathOpsSimplifyTrianglesThreadedTest.cpp
index 42aad38..8d1e8db 100755
--- a/tests/PathOpsSimplifyTrianglesThreadedTest.cpp
+++ b/tests/PathOpsSimplifyTrianglesThreadedTest.cpp
@@ -66,7 +66,7 @@
 }
 
 static void PathOpsSimplifyTrianglesThreadedTest(skiatest::Reporter* reporter) {
-    int threadCount = initializeTests("testTriangles");
+    int threadCount = initializeTests(reporter, "testTriangles");
     PathOpsThreadedTestRunner testRunner(reporter, threadCount);
     for (int a = 0; a < 15; ++a) {
         int ax = a & 0x03;
diff --git a/tests/Test.h b/tests/Test.h
index bfb4d60..6b0b901 100644
--- a/tests/Test.h
+++ b/tests/Test.h
@@ -43,7 +43,7 @@
         void report(const char testDesc[], Result);
         void endTest(Test*);
         virtual bool allowExtendedTest() const { return false; }
-
+        virtual bool allowThreaded() const { return false; }
         // helpers for tests
         void assertTrue(bool cond, const char desc[]) {
             if (!cond) {
diff --git a/tests/skia_test.cpp b/tests/skia_test.cpp
index 0851f8e..fd56cc7 100644
--- a/tests/skia_test.cpp
+++ b/tests/skia_test.cpp
@@ -62,10 +62,11 @@
 
 class DebugfReporter : public Reporter {
 public:
-    DebugfReporter(bool allowExtendedTest)
+    DebugfReporter(bool allowExtendedTest, bool allowThreaded)
         : fIndex(0)
         , fTotal(0)
-        , fAllowExtendedTest(allowExtendedTest) {
+        , fAllowExtendedTest(allowExtendedTest)
+        , fAllowThreaded(allowThreaded) {
     }
 
     void setIndexOfTotal(int index, int total) {
@@ -77,6 +78,10 @@
         return fAllowExtendedTest;
     }
 
+    virtual bool allowThreaded() const {
+        return fAllowThreaded;
+    }
+
 protected:
     virtual void onStart(Test* test) {
         SkDebugf("[%d/%d] %s...\n", fIndex+1, fTotal, test->getName());
@@ -92,6 +97,7 @@
 private:
     int fIndex, fTotal;
     bool fAllowExtendedTest;
+    bool fAllowThreaded;
 };
 
 static const char* make_canonical_dir_path(const char* path, SkString* storage) {
@@ -126,6 +132,7 @@
 DEFINE_string2(tmpDir, t, NULL, "tmp directory for tests to use.");
 DEFINE_string2(resourcePath, i, NULL, "directory for test resources.");
 DEFINE_bool2(extendedTest, x, false, "run extended tests for pathOps.");
+DEFINE_bool2(threaded, z, false, "allow tests to use multiple threads.");
 DEFINE_bool2(verbose, v, false, "enable verbose output.");
 
 int tool_main(int argc, char** argv);
@@ -170,7 +177,7 @@
         SkDebugf("%s\n", header.c_str());
     }
 
-    DebugfReporter reporter(FLAGS_extendedTest);
+    DebugfReporter reporter(FLAGS_extendedTest, FLAGS_threaded);
     Iter iter(&reporter);
     Test* test;