From 7e1725735947b7dbdbed08e9c8831e4f21f5c7c1 Mon Sep 17 00:00:00 2001 From: Gavin Sharp Date: Sun, 16 Jun 2013 11:15:17 -0400 Subject: [PATCH 01/75] Bug 883314 part 1: simplify code, r=jmaher --HG-- extra : transplant_source : J%AA%8D%F0%3B%AFi%00%18i%ABY%A0%24E%C6Ok%E4T --- testing/mochitest/browser-harness.xul | 2 +- testing/mochitest/chrome-harness.js | 25 +++++++++++-------------- testing/mochitest/harness-overlay.xul | 2 +- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/testing/mochitest/browser-harness.xul b/testing/mochitest/browser-harness.xul index 0583cf33cb0a..6948cc43d016 100644 --- a/testing/mochitest/browser-harness.xul +++ b/testing/mochitest/browser-harness.xul @@ -164,7 +164,7 @@ // Returns an array of browserTest objects for all the selected tests function listTests() { - [links, singleTestPath] = getTestList(); + var links = getTestList(); if (!links) return []; diff --git a/testing/mochitest/chrome-harness.js b/testing/mochitest/chrome-harness.js index 11cc61928fe9..6e94b7bbd48e 100644 --- a/testing/mochitest/chrome-harness.js +++ b/testing/mochitest/chrome-harness.js @@ -82,7 +82,6 @@ function getMochitestJarListing(aBasePath, aTestPath, aDir) var base = "content/" + aDir + "/"; - var singleTestPath; if (aTestPath) { var extraPath = aTestPath; var pathToCheck = base + aTestPath; @@ -91,21 +90,21 @@ function getMochitestJarListing(aBasePath, aTestPath, aDir) if (pathEntry.isDirectory) { base = pathToCheck; } else { - singleTestPath = basePath + '/' + base + aTestPath; + var singleTestPath = basePath + '/' + base + aTestPath; var singleObject = {}; singleObject[singleTestPath] = true; - return [singleObject, singleTestPath]; + return singleObject; } } else if (zReader.hasEntry(pathToCheck + "/")) { base = pathToCheck + "/"; } else { - return []; + return null; } } var [links, count] = zList(base, zReader, basePath, true); - return [links, null]; + return links; } /* @@ -172,7 +171,6 @@ function getFileListing(basePath, testPath, dir, srvScope) var testsDir = ioSvc.newURI(testPath, null, testsDirURI) .QueryInterface(Components.interfaces.nsIFileURL).file; - var singleTestPath; if (testPath != undefined) { var extraPath = testPath; @@ -180,24 +178,24 @@ function getFileListing(basePath, testPath, dir, srvScope) // Invalid testPath... if (!testsDir.exists()) - return []; + return null; if (testsDir.isFile()) { if (fileNameRegexp.test(testsDir.leafName)) var singlePath = basePath + '/' + testPath; var links = {}; links[singlePath] = true; - return [links, null]; + return links; // We were passed a file that's not a test... - return []; + return null; } // otherwise, we were passed a directory of tests basePath += "/" + testPath; } var [links, count] = srvScope.list(basePath, testsDir, true); - return [links, null]; + return links; } @@ -379,13 +377,12 @@ function getTestList() { var srvScope = {}; scriptLoader.loadSubScript('chrome://mochikit/content/server.js', srvScope); - var singleTestPath; var links; if (getResolvedURI(baseurl).JARFile) { - [links, singleTestPath] = getMochitestJarListing(baseurl, params.testPath, params.testRoot); + links = getMochitestJarListing(baseurl, params.testPath, params.testRoot); } else { - [links, singleTestPath] = getFileListing(baseurl, params.testPath, params.testRoot, srvScope); + links = getFileListing(baseurl, params.testPath, params.testRoot, srvScope); } - return [links, singleTestPath]; + return links; } diff --git a/testing/mochitest/harness-overlay.xul b/testing/mochitest/harness-overlay.xul index d2c7e20ec21b..dce17443c31d 100644 --- a/testing/mochitest/harness-overlay.xul +++ b/testing/mochitest/harness-overlay.xul @@ -35,7 +35,7 @@ if (Cc === undefined) { function loadTests() { window.removeEventListener("load", loadTests, false); - [links, singleTestPath] = getTestList(); + links = getTestList(); // load server.js in so we can share template functions var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"]. From 30fa51a97b50cf91ac2f935f4fd2497970cc5195 Mon Sep 17 00:00:00 2001 From: Gavin Sharp Date: Sun, 16 Jun 2013 11:19:47 -0400 Subject: [PATCH 02/75] Bug 883314 part 2: refactor mochitest chunking code to be re-used for mochitest-browser-chrome, r=jmaher --HG-- extra : transplant_source : %0A%C3%7F%B7%CFL%AD%2C%A2Y%5D51%AF%19%C1%C8%C5%5B%07 --- testing/mochitest/Makefile.in | 1 + testing/mochitest/chunkifyTests.js | 59 +++++++++++++++++++++ testing/mochitest/jar.mn | 1 + testing/mochitest/server.js | 2 + testing/mochitest/tests/SimpleTest/setup.js | 50 +---------------- 5 files changed, 65 insertions(+), 48 deletions(-) create mode 100644 testing/mochitest/chunkifyTests.js 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); From 102d8be2b6a0dfed109d29f75e8a9debeb55cc74 Mon Sep 17 00:00:00 2001 From: Gavin Sharp Date: Sun, 16 Jun 2013 11:22:48 -0400 Subject: [PATCH 03/75] Bug 883314 part 3: adjust refactored chunking code to deal with mochitest-browser-chrome and mochitest-chrome file paths, r=jmaher --HG-- extra : transplant_source : %ED%E7%ED%EEs%C5.%A0%FE%3ECEI60%A4h%C2%11Y --- testing/mochitest/chunkifyTests.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/testing/mochitest/chunkifyTests.js b/testing/mochitest/chunkifyTests.js index ad1171a5ed68..5a36a068a8bf 100644 --- a/testing/mochitest/chunkifyTests.js +++ b/testing/mochitest/chunkifyTests.js @@ -19,6 +19,12 @@ function chunkifyTests(tests, totalChunks, thisChunk, chunkByDir, logger) { if (test_path[0] == '/') { test_path = test_path.substr(1); } + // mochitest-chrome and mochitest-browser-chrome pass an array of chrome:// + // URIs + var protocolRegexp = /^[a-zA-Z]+:\/\//; + if (protocolRegexp.test(test_path)) { + test_path = test_path.replace(protocolRegexp, ""); + } var dir = test_path.split("/"); // We want the first chunkByDir+1 components, or everything but the // last component, whichever is less. From 8495f67a0d7e4c88a13aeeda0c66a32f4410e7ad Mon Sep 17 00:00:00 2001 From: Gavin Sharp Date: Sun, 16 Jun 2013 11:26:31 -0400 Subject: [PATCH 04/75] Bug 883314 part 4: use the chunking code for mochitest-browser-chrome, r=jmaher --HG-- extra : transplant_source : E%26%86p%E0%14%99Jb%19%A8%A8%D9%23%7E%9EiH%DBf --- testing/mochitest/browser-harness.xul | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/testing/mochitest/browser-harness.xul b/testing/mochitest/browser-harness.xul index 6948cc43d016..7ad1a3f7bd4f 100644 --- a/testing/mochitest/browser-harness.xul +++ b/testing/mochitest/browser-harness.xul @@ -12,6 +12,7 @@ - - -