testing/mochitest/chunkifyTests.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 function chunkifyTests(tests, totalChunks, thisChunk, chunkByDir, logger) {
michael@0 6 var total_chunks = parseInt(totalChunks);
michael@0 7 // this_chunk is in the range [1,total_chunks]
michael@0 8 var this_chunk = parseInt(thisChunk);
michael@0 9 var returnTests;
michael@0 10
michael@0 11 // We want to split the tests up into chunks according to which directory
michael@0 12 // they're in
michael@0 13 if (chunkByDir) {
michael@0 14 chunkByDir = parseInt(chunkByDir);
michael@0 15 var tests_by_dir = {};
michael@0 16 var test_dirs = []
michael@0 17 for (var i = 0; i < tests.length; ++i) {
michael@0 18 var test_path = tests[i];
michael@0 19 if (test_path[0] == '/') {
michael@0 20 test_path = test_path.substr(1);
michael@0 21 }
michael@0 22 // mochitest-chrome and mochitest-browser-chrome pass an array of chrome://
michael@0 23 // URIs
michael@0 24 var protocolRegexp = /^[a-zA-Z]+:\/\//;
michael@0 25 if (protocolRegexp.test(test_path)) {
michael@0 26 test_path = test_path.replace(protocolRegexp, "");
michael@0 27 }
michael@0 28 var dir = test_path.split("/");
michael@0 29 // We want the first chunkByDir+1 components, or everything but the
michael@0 30 // last component, whichever is less.
michael@0 31 // we add 1 to chunkByDir since 'tests' is always part of the path, and
michael@0 32 // want to ignore the last component since it's the test filename.
michael@0 33 dir = dir.slice(0, Math.min(chunkByDir+1, dir.length-1));
michael@0 34 // reconstruct a directory name
michael@0 35 dir = dir.join("/");
michael@0 36 if (!(dir in tests_by_dir)) {
michael@0 37 tests_by_dir[dir] = [tests[i]];
michael@0 38 test_dirs.push(dir);
michael@0 39 } else {
michael@0 40 tests_by_dir[dir].push(tests[i]);
michael@0 41 }
michael@0 42 }
michael@0 43 var tests_per_chunk = test_dirs.length / total_chunks;
michael@0 44 var start = Math.round((this_chunk-1) * tests_per_chunk);
michael@0 45 var end = Math.round(this_chunk * tests_per_chunk);
michael@0 46 returnTests = [];
michael@0 47 var dirs = []
michael@0 48 for (var i = start; i < end; ++i) {
michael@0 49 var dir = test_dirs[i];
michael@0 50 dirs.push(dir);
michael@0 51 returnTests = returnTests.concat(tests_by_dir[dir]);
michael@0 52 }
michael@0 53 if (logger)
michael@0 54 logger.log("Running tests in " + dirs.join(", "));
michael@0 55 } else {
michael@0 56 var tests_per_chunk = tests.length / total_chunks;
michael@0 57 var start = Math.round((this_chunk-1) * tests_per_chunk);
michael@0 58 var end = Math.round(this_chunk * tests_per_chunk);
michael@0 59 returnTests = tests.slice(start, end);
michael@0 60 if (logger)
michael@0 61 logger.log("Running tests " + (start+1) + "-" + end + "/" + tests.length);
michael@0 62 }
michael@0 63
michael@0 64 return returnTests;
michael@0 65 }
michael@0 66
michael@0 67 function skipTests(tests, startTestPattern, endTestPattern) {
michael@0 68 var startIndex = 0, endIndex = tests.length - 1;
michael@0 69 for (var i = 0; i < tests.length; ++i) {
michael@0 70 var test_path = tests[i];
michael@0 71 if (startTestPattern && test_path.endsWith(startTestPattern)) {
michael@0 72 startIndex = i;
michael@0 73 }
michael@0 74
michael@0 75 if (endTestPattern && test_path.endsWith(endTestPattern)) {
michael@0 76 endIndex = i;
michael@0 77 }
michael@0 78 }
michael@0 79
michael@0 80 return tests.slice(startIndex, endIndex + 1);
michael@0 81 }

mercurial