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