1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
# 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/.
from __future__ import unicode_literals
import cPickle as pickle
import os
import shutil
import tempfile
import unittest
import mozpack.path as mozpath
from mozfile import NamedTemporaryFile
from mozunit import main
from mozbuild.base import MozbuildObject
from mozbuild.testing import (
TestMetadata,
TestResolver,
)
ALL_TESTS = {
"accessible/tests/mochitest/actions/test_anchors.html": [
{
"dir_relpath": "accessible/tests/mochitest/actions",
"expected": "pass",
"file_relpath": "accessible/tests/mochitest/actions/test_anchors.html",
"flavor": "a11y",
"here": "/Users/gps/src/firefox/accessible/tests/mochitest/actions",
"manifest": "/Users/gps/src/firefox/accessible/tests/mochitest/actions/a11y.ini",
"name": "test_anchors.html",
"path": "/Users/gps/src/firefox/accessible/tests/mochitest/actions/test_anchors.html",
"relpath": "test_anchors.html"
}
],
"services/common/tests/unit/test_async_chain.js": [
{
"dir_relpath": "services/common/tests/unit",
"file_relpath": "services/common/tests/unit/test_async_chain.js",
"firefox-appdir": "browser",
"flavor": "xpcshell",
"head": "head_global.js head_helpers.js head_http.js",
"here": "/Users/gps/src/firefox/services/common/tests/unit",
"manifest": "/Users/gps/src/firefox/services/common/tests/unit/xpcshell.ini",
"name": "test_async_chain.js",
"path": "/Users/gps/src/firefox/services/common/tests/unit/test_async_chain.js",
"relpath": "test_async_chain.js",
"tail": ""
}
],
"services/common/tests/unit/test_async_querySpinningly.js": [
{
"dir_relpath": "services/common/tests/unit",
"file_relpath": "services/common/tests/unit/test_async_querySpinningly.js",
"firefox-appdir": "browser",
"flavor": "xpcshell",
"head": "head_global.js head_helpers.js head_http.js",
"here": "/Users/gps/src/firefox/services/common/tests/unit",
"manifest": "/Users/gps/src/firefox/services/common/tests/unit/xpcshell.ini",
"name": "test_async_querySpinningly.js",
"path": "/Users/gps/src/firefox/services/common/tests/unit/test_async_querySpinningly.js",
"relpath": "test_async_querySpinningly.js",
"tail": ""
}
],
"toolkit/mozapps/update/test/unit/test_0201_app_launch_apply_update.js": [
{
"dir_relpath": "toolkit/mozapps/update/test/unit",
"file_relpath": "toolkit/mozapps/update/test/unit/test_0201_app_launch_apply_update.js",
"flavor": "xpcshell",
"generated-files": "head_update.js",
"head": "head_update.js",
"here": "/Users/gps/src/firefox/toolkit/mozapps/update/test/unit",
"manifest": "/Users/gps/src/firefox/toolkit/mozapps/update/test/unit/xpcshell_updater.ini",
"name": "test_0201_app_launch_apply_update.js",
"path": "/Users/gps/src/firefox/toolkit/mozapps/update/test/unit/test_0201_app_launch_apply_update.js",
"reason": "bug 820380",
"relpath": "test_0201_app_launch_apply_update.js",
"run-sequentially": "Launches application.",
"skip-if": os == 'android'",
"tail": ""
},
{
"dir_relpath": "toolkit/mozapps/update/test/unit",
"file_relpath": "toolkit/mozapps/update/test/unit/test_0201_app_launch_apply_update.js",
"flavor": "xpcshell",
"generated-files": "head_update.js",
"head": "head_update.js head2.js",
"here": "/Users/gps/src/firefox/toolkit/mozapps/update/test/unit",
"manifest": "/Users/gps/src/firefox/toolkit/mozapps/update/test/unit/xpcshell_updater.ini",
"name": "test_0201_app_launch_apply_update.js",
"path": "/Users/gps/src/firefox/toolkit/mozapps/update/test/unit/test_0201_app_launch_apply_update.js",
"reason": "bug 820380",
"relpath": "test_0201_app_launch_apply_update.js",
"run-sequentially": "Launches application.",
"skip-if": os == 'android'",
"tail": ""
}
],
"mobile/android/tests/background/junit3/src/common/TestAndroidLogWriters.java": [
{
"dir_relpath": "mobile/android/tests/background/junit3/src/common",
"file_relpath": "mobile/android/tests/background/junit3/src/common/TestAndroidLogWriters.java",
"flavor": "instrumentation",
"here": "/Users/nalexander/Mozilla/gecko-dev/mobile/android/tests/background/junit3",
"manifest": "/Users/nalexander/Mozilla/gecko-dev/mobile/android/tests/background/junit3/instrumentation.ini",
"name": "src/common/TestAndroidLogWriters.java",
"path": "/Users/nalexander/Mozilla/gecko-dev/mobile/android/tests/background/junit3/src/common/TestAndroidLogWriters.java",
"relpath": "src/common/TestAndroidLogWriters.java",
"subsuite": "background"
}
],
"mobile/android/tests/browser/junit3/src/TestDistribution.java": [
{
"dir_relpath": "mobile/android/tests/browser/junit3/src",
"file_relpath": "mobile/android/tests/browser/junit3/src/TestDistribution.java",
"flavor": "instrumentation",
"here": "/Users/nalexander/Mozilla/gecko-dev/mobile/android/tests/browser/junit3",
"manifest": "/Users/nalexander/Mozilla/gecko-dev/mobile/android/tests/browser/junit3/instrumentation.ini",
"name": "src/TestDistribution.java",
"path": "/Users/nalexander/Mozilla/gecko-dev/mobile/android/tests/browser/junit3/src/TestDistribution.java",
"relpath": "src/TestDistribution.java",
"subsuite": "browser"
}
],
"image/test/browser/browser_bug666317.js": [
{
"dir_relpath": "image/test/browser",
"file_relpath": "image/test/browser/browser_bug666317.js",
"flavor": "browser-chrome",
"here": "/home/chris/m-c/obj-dbg/_tests/testing/mochitest/browser/image/test/browser",
"manifest": "/home/chris/m-c/image/test/browser/browser.ini",
"name": "browser_bug666317.js",
"path": "/home/chris/m-c/obj-dbg/_tests/testing/mochitest/browser/image/test/browser/browser_bug666317.js",
"relpath": "image/test/browser/browser_bug666317.js",
"skip-if": "e10s # Bug 948194 - Decoded Images seem to not be discarded on memory-pressure notification with e10s enabled",
"subsuite": ""
}
],
"devtools/client/markupview/test/browser_markupview_copy_image_data.js": [
{
"dir_relpath": "devtools/client/markupview/test",
"file_relpath": "devtools/client/markupview/test/browser_markupview_copy_image_data.js",
"flavor": "browser-chrome",
"here": "/home/chris/m-c/obj-dbg/_tests/testing/mochitest/browser/devtools/client/markupview/test",
"manifest": "/home/chris/m-c/devtools/client/markupview/test/browser.ini",
"name": "browser_markupview_copy_image_data.js",
"path": "/home/chris/m-c/obj-dbg/_tests/testing/mochitest/browser/devtools/client/markupview/test/browser_markupview_copy_image_data.js",
"relpath": "devtools/client/markupview/test/browser_markupview_copy_image_data.js",
"subsuite": "devtools",
"tags": "devtools"
}
]
}
TEST_DEFAULTS = {
"/Users/gps/src/firefox/toolkit/mozapps/update/test/unit/xpcshell_updater.ini": {"support-files": "\ndata/**\nxpcshell_updater.ini"}
}
class Base(unittest.TestCase):
def setUp(self):
self._temp_files = []
def tearDown(self):
for f in self._temp_files:
del f
self._temp_files = []
def _get_test_metadata(self):
all_tests = NamedTemporaryFile(mode='wb')
pickle.dump(ALL_TESTS, all_tests)
all_tests.flush()
self._temp_files.append(all_tests)
test_defaults = NamedTemporaryFile(mode='wb')
pickle.dump(TEST_DEFAULTS, test_defaults)
test_defaults.flush()
self._temp_files.append(test_defaults)
return TestMetadata(all_tests.name, test_defaults=test_defaults.name)
class TestTestMetadata(Base):
def test_load(self):
t = self._get_test_metadata()
self.assertEqual(len(t._tests_by_path), 8)
self.assertEqual(len(list(t.tests_with_flavor('xpcshell'))), 3)
self.assertEqual(len(list(t.tests_with_flavor('mochitest-plain'))), 0)
def test_resolve_all(self):
t = self._get_test_metadata()
self.assertEqual(len(list(t.resolve_tests())), 9)
def test_resolve_filter_flavor(self):
t = self._get_test_metadata()
self.assertEqual(len(list(t.resolve_tests(flavor='xpcshell'))), 4)
def test_resolve_by_dir(self):
t = self._get_test_metadata()
self.assertEqual(len(list(t.resolve_tests(paths=['services/common']))), 2)
def test_resolve_under_path(self):
t = self._get_test_metadata()
self.assertEqual(len(list(t.resolve_tests(under_path='services'))), 2)
self.assertEqual(len(list(t.resolve_tests(flavor='xpcshell',
under_path='services'))), 2)
def test_resolve_multiple_paths(self):
t = self._get_test_metadata()
result = list(t.resolve_tests(paths=['services', 'toolkit']))
self.assertEqual(len(result), 4)
def test_resolve_support_files(self):
expected_support_files = "\ndata/**\nxpcshell_updater.ini"
t = self._get_test_metadata()
result = list(t.resolve_tests(paths=['toolkit']))
self.assertEqual(len(result), 2)
for test in result:
self.assertEqual(test['support-files'],
expected_support_files)
def test_resolve_path_prefix(self):
t = self._get_test_metadata()
result = list(t.resolve_tests(paths=['image']))
self.assertEqual(len(result), 1)
class TestTestResolver(Base):
FAKE_TOPSRCDIR = '/Users/gps/src/firefox'
def setUp(self):
Base.setUp(self)
self._temp_dirs = []
def tearDown(self):
Base.tearDown(self)
for d in self._temp_dirs:
shutil.rmtree(d)
def _get_resolver(self):
topobjdir = tempfile.mkdtemp()
self._temp_dirs.append(topobjdir)
with open(os.path.join(topobjdir, 'all-tests.pkl'), 'wb') as fh:
pickle.dump(ALL_TESTS, fh)
with open(os.path.join(topobjdir, 'test-defaults.pkl'), 'wb') as fh:
pickle.dump(TEST_DEFAULTS, fh)
o = MozbuildObject(self.FAKE_TOPSRCDIR, None, None, topobjdir=topobjdir)
# Monkey patch the test resolver to avoid tests failing to find make
# due to our fake topscrdir.
TestResolver._run_make = lambda *a, **b: None
return o._spawn(TestResolver)
def test_cwd_children_only(self):
"""If cwd is defined, only resolve tests under the specified cwd."""
r = self._get_resolver()
# Pretend we're under '/services' and ask for 'common'. This should
# pick up all tests from '/services/common'
tests = list(r.resolve_tests(paths=['common'], cwd=os.path.join(r.topsrcdir,
'services')))
self.assertEqual(len(tests), 2)
# Tests should be rewritten to objdir.
for t in tests:
self.assertEqual(t['here'], mozpath.join(r.topobjdir,
'_tests/xpcshell/services/common/tests/unit'))
def test_various_cwd(self):
"""Test various cwd conditions are all equal."""
r = self._get_resolver()
expected = list(r.resolve_tests(paths=['services']))
actual = list(r.resolve_tests(paths=['services'], cwd='/'))
self.assertEqual(actual, expected)
actual = list(r.resolve_tests(paths=['services'], cwd=r.topsrcdir))
self.assertEqual(actual, expected)
actual = list(r.resolve_tests(paths=['services'], cwd=r.topobjdir))
self.assertEqual(actual, expected)
def test_subsuites(self):
"""Test filtering by subsuite."""
r = self._get_resolver()
tests = list(r.resolve_tests(paths=['mobile']))
self.assertEqual(len(tests), 2)
tests = list(r.resolve_tests(paths=['mobile'], subsuite='browser'))
self.assertEqual(len(tests), 1)
self.assertEqual(tests[0]['name'], 'src/TestDistribution.java')
tests = list(r.resolve_tests(paths=['mobile'], subsuite='background'))
self.assertEqual(len(tests), 1)
self.assertEqual(tests[0]['name'], 'src/common/TestAndroidLogWriters.java')
def test_wildcard_patterns(self):
"""Test matching paths by wildcard."""
r = self._get_resolver()
tests = list(r.resolve_tests(paths=['mobile/**']))
self.assertEqual(len(tests), 2)
for t in tests:
self.assertTrue(t['file_relpath'].startswith('mobile'))
tests = list(r.resolve_tests(paths=['**/**.js', 'accessible/**']))
self.assertEqual(len(tests), 7)
for t in tests:
path = t['file_relpath']
self.assertTrue(path.startswith('accessible') or path.endswith('.js'))
if __name__ == '__main__':
main()
|