diff --git a/testing/mochitest/Makefile.in b/testing/mochitest/Makefile.in index 5eae31211809..6a8f7690a96c 100644 --- a/testing/mochitest/Makefile.in +++ b/testing/mochitest/Makefile.in @@ -48,6 +48,7 @@ _SERV_FILES = \ $(topsrcdir)/build/mobile/b2gautomation.py \ gen_template.pl \ server.js \ + chunkifyTests.js \ harness-overlay.xul \ harness.xul \ browser-test-overlay.xul \ diff --git a/testing/mochitest/chunkifyTests.js b/testing/mochitest/chunkifyTests.js new file mode 100644 index 000000000000..ad1171a5ed68 --- /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; +} diff --git a/testing/mochitest/jar.mn b/testing/mochitest/jar.mn index 742c04d483da..794762eb1c8c 100644 --- a/testing/mochitest/jar.mn +++ b/testing/mochitest/jar.mn @@ -9,6 +9,7 @@ mochikit.jar: 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) diff --git a/testing/mochitest/server.js b/testing/mochitest/server.js index c935a7b8c2b1..2f2b33e8dcf7 100644 --- a/testing/mochitest/server.js +++ b/testing/mochitest/server.js @@ -604,6 +604,8 @@ function testListing(metadata, response) 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"}, diff --git a/testing/mochitest/tests/SimpleTest/setup.js b/testing/mochitest/tests/SimpleTest/setup.js index 2057c3900f08..543f36a30622 100644 --- a/testing/mochitest/tests/SimpleTest/setup.js +++ b/testing/mochitest/tests/SimpleTest/setup.js @@ -125,55 +125,9 @@ RunSet.runall = function(e) { 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); - - // 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); - } + my_tests = chunkifyTests(my_tests, params.totalChunks, params.thisChunk, params.chunkByDir, TestRunner.logger); } + if (params.shuffle) { for (var i = my_tests.length-1; i > 0; --i) { var j = Math.floor(Math.random() * i);