Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | function parseTestManifest(testManifest, params, callback) { |
michael@0 | 8 | var links = {}; |
michael@0 | 9 | var paths = []; |
michael@0 | 10 | |
michael@0 | 11 | // Support --test-manifest format for mobile/b2g |
michael@0 | 12 | if ("runtests" in testManifest || "excludetests" in testManifest) { |
michael@0 | 13 | callback(testManifest); |
michael@0 | 14 | return; |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | // For mochitest-chrome and mochitest-browser-chrome harnesses, we |
michael@0 | 18 | // define tests as links[testname] = true. |
michael@0 | 19 | // For mochitest-plain, we define lists as an array of testnames. |
michael@0 | 20 | for (var obj of testManifest['tests']) { |
michael@0 | 21 | var path = obj['path']; |
michael@0 | 22 | // Note that obj.disabled may be "". We still want to skip in that case. |
michael@0 | 23 | if ("disabled" in obj) { |
michael@0 | 24 | dump("TEST-SKIPPED | " + path + " | " + obj.disabled + "\n"); |
michael@0 | 25 | continue; |
michael@0 | 26 | } |
michael@0 | 27 | if (params.testRoot != 'tests' && params.testRoot !== undefined) { |
michael@0 | 28 | links[params.baseurl + '/' + params.testRoot + '/' + path] = true |
michael@0 | 29 | } else { |
michael@0 | 30 | paths.push(params.testPrefix + path); |
michael@0 | 31 | } |
michael@0 | 32 | } |
michael@0 | 33 | if (paths.length > 0) { |
michael@0 | 34 | callback(paths); |
michael@0 | 35 | } else { |
michael@0 | 36 | callback(links); |
michael@0 | 37 | } |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | function getTestManifest(url, params, callback) { |
michael@0 | 41 | var req = new XMLHttpRequest(); |
michael@0 | 42 | req.open("GET", url); |
michael@0 | 43 | req.onload = function() { |
michael@0 | 44 | if (req.readyState == 4) { |
michael@0 | 45 | if (req.status == 200) { |
michael@0 | 46 | try { |
michael@0 | 47 | parseTestManifest(JSON.parse(req.responseText), params, callback); |
michael@0 | 48 | } catch (e) { |
michael@0 | 49 | dump("TEST-UNEXPECTED-FAIL: setup.js | error parsing " + url + " (" + e + ")\n"); |
michael@0 | 50 | throw e; |
michael@0 | 51 | } |
michael@0 | 52 | } else { |
michael@0 | 53 | dump("TEST-UNEXPECTED-FAIL: setup.js | error loading " + url + "\n"); |
michael@0 | 54 | callback({}); |
michael@0 | 55 | } |
michael@0 | 56 | } |
michael@0 | 57 | } |
michael@0 | 58 | req.send(); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | // Test Filtering Code |
michael@0 | 62 | |
michael@0 | 63 | /* |
michael@0 | 64 | Open the file referenced by runOnly|exclude and use that to compare against |
michael@0 | 65 | testList |
michael@0 | 66 | parameters: |
michael@0 | 67 | filter = json object of runtests | excludetests |
michael@0 | 68 | testList = array of test names to run |
michael@0 | 69 | runOnly = use runtests vs excludetests in case both are defined |
michael@0 | 70 | returns: |
michael@0 | 71 | filtered version of testList |
michael@0 | 72 | */ |
michael@0 | 73 | function filterTests(filter, testList, runOnly) { |
michael@0 | 74 | |
michael@0 | 75 | var filteredTests = []; |
michael@0 | 76 | var removedTests = []; |
michael@0 | 77 | var runtests = {}; |
michael@0 | 78 | var excludetests = {}; |
michael@0 | 79 | |
michael@0 | 80 | if (filter == null) { |
michael@0 | 81 | return testList; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | if ('runtests' in filter) { |
michael@0 | 85 | runtests = filter.runtests; |
michael@0 | 86 | } |
michael@0 | 87 | if ('excludetests' in filter) { |
michael@0 | 88 | excludetests = filter.excludetests; |
michael@0 | 89 | } |
michael@0 | 90 | if (!('runtests' in filter) && !('excludetests' in filter)) { |
michael@0 | 91 | if (runOnly == 'true') { |
michael@0 | 92 | runtests = filter; |
michael@0 | 93 | } else { |
michael@0 | 94 | excludetests = filter; |
michael@0 | 95 | } |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | var testRoot = config.testRoot || "tests"; |
michael@0 | 99 | // Start with testList, and put everything that's in 'runtests' in |
michael@0 | 100 | // filteredTests. |
michael@0 | 101 | if (Object.keys(runtests).length) { |
michael@0 | 102 | for (var i = 0; i < testList.length; i++) { |
michael@0 | 103 | var testpath = testList[i]; |
michael@0 | 104 | var tmppath = testpath.replace(/^\//, ''); |
michael@0 | 105 | for (var f in runtests) { |
michael@0 | 106 | // Remove leading /tests/ if exists |
michael@0 | 107 | file = f.replace(/^\//, '') |
michael@0 | 108 | file = file.replace(/^tests\//, '') |
michael@0 | 109 | |
michael@0 | 110 | // Match directory or filename, testList has <testroot>/<path> |
michael@0 | 111 | if (tmppath.match(testRoot + "/" + file) != null) { |
michael@0 | 112 | filteredTests.push(testpath); |
michael@0 | 113 | break; |
michael@0 | 114 | } |
michael@0 | 115 | } |
michael@0 | 116 | } |
michael@0 | 117 | } else { |
michael@0 | 118 | filteredTests = testList.slice(0); |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | // Continue with filteredTests, and deselect everything that's in |
michael@0 | 122 | // excludedtests. |
michael@0 | 123 | if (!Object.keys(excludetests).length) { |
michael@0 | 124 | return filteredTests; |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | var refilteredTests = []; |
michael@0 | 128 | for (var i = 0; i < filteredTests.length; i++) { |
michael@0 | 129 | var found = false; |
michael@0 | 130 | var testpath = filteredTests[i]; |
michael@0 | 131 | var tmppath = testpath.replace(/^\//, ''); |
michael@0 | 132 | for (var f in excludetests) { |
michael@0 | 133 | // Remove leading /tests/ if exists |
michael@0 | 134 | file = f.replace(/^\//, '') |
michael@0 | 135 | file = file.replace(/^tests\//, '') |
michael@0 | 136 | |
michael@0 | 137 | // Match directory or filename, testList has <testroot>/<path> |
michael@0 | 138 | if (tmppath.match(testRoot + "/" + file) != null) { |
michael@0 | 139 | found = true; |
michael@0 | 140 | break; |
michael@0 | 141 | } |
michael@0 | 142 | } |
michael@0 | 143 | if (!found) { |
michael@0 | 144 | refilteredTests.push(testpath); |
michael@0 | 145 | } |
michael@0 | 146 | } |
michael@0 | 147 | return refilteredTests; |
michael@0 | 148 | } |