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
This commit is contained in:
Gavin Sharp 2013-06-16 11:19:47 -04:00
parent ec13bb0752
commit 03583a2fa5
5 changed files with 65 additions and 48 deletions

View File

@ -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 \

View File

@ -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;
}

View File

@ -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)

View File

@ -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"},

View File

@ -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);