Bug 883314 part 2: refactor mochitest chunking code to be re-used for mochitest-browser-chrome, r=jmaher
authorGavin Sharp <gavin@gavinsharp.com>
Sun, 16 Jun 2013 11:19:47 -0400
changeset 146831 a13d509adbf031f8f84de4eca798665505548ddd
parent 146830 afa0efd81288b4d8fedbc8f7e494c0a9ea1af684
child 146832 1b2f815f5f08da18aa4d23505c72de8d1473b129
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs883314
milestone24.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 883314 part 2: refactor mochitest chunking code to be re-used for mochitest-browser-chrome, r=jmaher
testing/mochitest/Makefile.in
testing/mochitest/chunkifyTests.js
testing/mochitest/jar.mn
testing/mochitest/server.js
testing/mochitest/tests/SimpleTest/setup.js
--- a/testing/mochitest/Makefile.in
+++ b/testing/mochitest/Makefile.in
@@ -43,16 +43,17 @@ include $(topsrcdir)/build/automation-bu
 		$(topsrcdir)/testing/mozbase/manifestdestiny/manifestparser/manifestparser.py \
 		$(topsrcdir)/testing/mozbase/mozdevice/mozdevice/droid.py \
 		$(topsrcdir)/testing/mozbase/mozdevice/mozdevice/Zeroconf.py \
 		$(topsrcdir)/build/automationutils.py \
 		$(topsrcdir)/build/mobile/remoteautomation.py \
 		$(topsrcdir)/build/mobile/b2gautomation.py \
 		gen_template.pl \
 		server.js \
+		chunkifyTests.js \
 		harness-overlay.xul \
 		harness.xul \
 		browser-test-overlay.xul \
 		browser-test.js \
 		cc-analyzer.js \
 		chrome-harness.js \
 		browser-harness.xul \
 		redirect.html \
new file mode 100644
--- /dev/null
+++ b/testing/mochitest/chunkifyTests.js
@@ -0,0 +1,59 @@
+/* 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/. */
+
+function chunkifyTests(tests, totalChunks, thisChunk, chunkByDir, logger) {
+  var total_chunks = parseInt(totalChunks);
+  // this_chunk is in the range [1,total_chunks]
+  var this_chunk = parseInt(thisChunk);
+  var returnTests;
+
+  // We want to split the tests up into chunks according to which directory
+  // they're in
+  if (chunkByDir) {
+    chunkByDir = parseInt(chunkByDir);
+    var tests_by_dir = {};
+    var test_dirs = []
+    for (var i = 0; i < tests.length; ++i) {
+      var test_path = tests[i];
+      if (test_path[0] == '/') {
+        test_path = test_path.substr(1);
+      }
+      var dir = test_path.split("/");
+      // We want the first chunkByDir+1 components, or everything but the
+      // last component, whichever is less.
+      // we add 1 to chunkByDir since 'tests' is always part of the path, and
+      // want to ignore the last component since it's the test filename.
+      dir = dir.slice(0, Math.min(chunkByDir+1, dir.length-1));
+      // reconstruct a directory name
+      dir = dir.join("/");
+      if (!(dir in tests_by_dir)) {
+        tests_by_dir[dir] = [tests[i]];
+        test_dirs.push(dir);
+      } else {
+        tests_by_dir[dir].push(tests[i]);
+      }
+    }
+    var tests_per_chunk = test_dirs.length / total_chunks;
+    var start = Math.round((this_chunk-1) * tests_per_chunk);
+    var end = Math.round(this_chunk * tests_per_chunk);
+    returnTests = [];
+    var dirs = []
+    for (var i = start; i < end; ++i) {
+      var dir = test_dirs[i];
+      dirs.push(dir);
+      returnTests = returnTests.concat(tests_by_dir[dir]);
+    }
+    if (logger)
+      logger.log("Running tests in " + dirs.join(", "));
+  } else {
+    var tests_per_chunk = tests.length / total_chunks;
+    var start = Math.round((this_chunk-1) * tests_per_chunk);
+    var end = Math.round(this_chunk * tests_per_chunk);
+    returnTests = tests.slice(start, end);
+    if (logger)
+      logger.log("Running tests " + (start+1) + "-" + end + "/" + tests.length);
+  }
+
+  return returnTests;
+}
--- a/testing/mochitest/jar.mn
+++ b/testing/mochitest/jar.mn
@@ -4,16 +4,17 @@ mochikit.jar:
   content/browser-test.js (browser-test.js)
   content/browser-test-overlay.xul (browser-test-overlay.xul)
   content/cc-analyzer.js (cc-analyzer.js)
   content/chrome-harness.js (chrome-harness.js)
   content/harness-overlay.xul (harness-overlay.xul)
   content/harness.xul (harness.xul)
   content/redirect.html (redirect.html)
   content/server.js (server.js)
+  content/chunkifyTests.js (chunkifyTests.js)
   content/dynamic/getMyDirectory.sjs (dynamic/getMyDirectory.sjs)
   content/static/harness.css (static/harness.css)
   content/tests/SimpleTest/ChromePowers.js (tests/SimpleTest/ChromePowers.js)
   content/tests/SimpleTest/EventUtils.js (tests/SimpleTest/EventUtils.js)
   content/tests/SimpleTest/ChromeUtils.js (tests/SimpleTest/ChromeUtils.js)
   content/tests/SimpleTest/LogController.js (tests/SimpleTest/LogController.js)
   content/tests/SimpleTest/MozillaLogger.js (../specialpowers/content/MozillaLogger.js)
   content/tests/SimpleTest/SpecialPowersObserverAPI.js (../specialpowers/content/SpecialPowersObserverAPI.js)
--- a/testing/mochitest/server.js
+++ b/testing/mochitest/server.js
@@ -600,16 +600,18 @@ function testListing(metadata, response)
         ),
         SCRIPT({type: "text/javascript",
                  src: "/tests/SimpleTest/LogController.js"}),
         SCRIPT({type: "text/javascript",
                  src: "/tests/SimpleTest/TestRunner.js"}),
         SCRIPT({type: "text/javascript",
                  src: "/tests/SimpleTest/MozillaLogger.js"}),
         SCRIPT({type: "text/javascript",
+                 src: "/chunkifyTests.js"}),
+        SCRIPT({type: "text/javascript",
                  src: "/tests/SimpleTest/setup.js"}),
         SCRIPT({type: "text/javascript"},
                "window.onload =  hookup; gTestList=" + tests + ";"
         )
       ),
       BODY(
         DIV({class: "container"},
           H2("--> ", A({href: "#", id: "runtests"}, "Run Tests"), " <--"),
--- a/testing/mochitest/tests/SimpleTest/setup.js
+++ b/testing/mochitest/tests/SimpleTest/setup.js
@@ -120,65 +120,19 @@ RunSet.runall = function(e) {
   // Filter tests to include|exclude tests based on data in params.filter.
   // This allows for including or excluding tests from the gTestList
   gTestList = filterTests(params.testManifest, params.runOnly);
 
   // Which tests we're going to run
   var my_tests = gTestList;
 
   if (params.totalChunks && params.thisChunk) {
-    var total_chunks = parseInt(params.totalChunks);
-    // this_chunk is in the range [1,total_chunks]
-    var this_chunk = parseInt(params.thisChunk);
+    my_tests = chunkifyTests(my_tests, params.totalChunks, params.thisChunk, params.chunkByDir, TestRunner.logger);
+  }
 
-    // We want to split the tests up into chunks according to which directory
-    // they're in
-    if (params.chunkByDir) {
-      var chunkByDir = parseInt(params.chunkByDir);
-      var tests_by_dir = {};
-      var test_dirs = []
-      for (var i = 0; i < gTestList.length; ++i) {
-        var test_path = gTestList[i];
-        if (test_path[0] == '/') {
-          test_path = test_path.substr(1);
-        }
-        var dir = test_path.split("/");
-        // We want the first chunkByDir+1 components, or everything but the
-        // last component, whichever is less.
-        // we add 1 to chunkByDir since 'tests' is always part of the path, and
-        // want to ignore the last component since it's the test filename.
-        dir = dir.slice(0, Math.min(chunkByDir+1, dir.length-1));
-        // reconstruct a directory name
-        dir = dir.join("/");
-        if (!(dir in tests_by_dir)) {
-          tests_by_dir[dir] = [gTestList[i]];
-          test_dirs.push(dir);
-        } else {
-          tests_by_dir[dir].push(gTestList[i]);
-        }
-      }
-      var tests_per_chunk = test_dirs.length / total_chunks;
-      var start = Math.round((this_chunk-1) * tests_per_chunk);
-      var end = Math.round(this_chunk * tests_per_chunk);
-      my_tests = [];
-      var dirs = []
-      for (var i = start; i < end; ++i) {
-        var dir = test_dirs[i];
-        dirs.push(dir);
-        my_tests = my_tests.concat(tests_by_dir[dir]);
-      }
-      TestRunner.logger.log("Running tests in " + dirs.join(", "));
-    } else {
-      var tests_per_chunk = gTestList.length / total_chunks;
-      var start = Math.round((this_chunk-1) * tests_per_chunk);
-      var end = Math.round(this_chunk * tests_per_chunk);
-      my_tests = gTestList.slice(start, end);
-      TestRunner.logger.log("Running tests " + (start+1) + "-" + end + "/" + gTestList.length);
-    }
-  }
   if (params.shuffle) {
     for (var i = my_tests.length-1; i > 0; --i) {
       var j = Math.floor(Math.random() * i);
       var tmp = my_tests[j];
       my_tests[j] = my_tests[i];
       my_tests[i] = tmp;
     }
   }