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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
|
# 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/.
import re
from itertools import combinations
import pytest
from mozunit import main
from gecko_taskgraph.util import chunking
pytestmark = pytest.mark.slow
@pytest.fixture(scope="module")
def mock_manifest_runtimes():
"""Deterministically produce a list of simulated manifest runtimes.
Args:
manifests (list): list of manifests against which simulated manifest
runtimes would be paired up to.
Returns:
dict of manifest data paired with a float value representing runtime.
"""
def inner(manifests):
manifests = sorted(manifests)
# Generate deterministic runtime data.
runtimes = [(i / 10) ** (i / 10) for i in range(len(manifests))]
return dict(zip(manifests, runtimes))
return inner
@pytest.fixture(scope="module")
def unchunked_manifests():
"""Produce a list of unchunked manifests to be consumed by test method.
Args:
length (int, optional): number of path elements to keep.
cutoff (int, optional): number of generated test paths to remove
from the test set if user wants to limit the number of paths.
Returns:
list: list of test paths.
"""
data = ["blueberry", "nashi", "peach", "watermelon"]
def inner(suite, length=2, cutoff=0):
if "web-platform" in suite:
suffix = ""
prefix = "/"
elif "reftest" in suite:
suffix = ".list"
prefix = ""
else:
suffix = ".ini"
prefix = ""
return [prefix + "/".join(p) + suffix for p in combinations(data, length)][
cutoff:
]
return inner
@pytest.fixture(scope="module")
def mock_task_definition():
"""Builds a mock task definition for use in testing.
Args:
os_name (str): represents the os.
os_version (str): represents the os version
bits (int): software bits.
build_type (str): opt or debug.
build_attrs (list, optional): specify build attribute(s)
variants (list, optional): specify runtime variant(s)
Returns:
dict: mocked task definition.
"""
def inner(os_name, os_version, bits, build_type, build_attrs=None, variants=None):
setting = {
"platform": {
"arch": str(bits),
"os": {
"name": os_name,
"version": os_version,
},
},
"build": {
"type": build_type,
},
"runtime": {},
}
# Optionally set build attributes and runtime variants.
if build_attrs:
if isinstance(build_attrs, str):
build_attrs = [build_attrs]
for attr in build_attrs:
setting["build"][attr] = True
if variants:
if isinstance(variants, str):
variants = [variants]
for variant in variants:
setting["runtime"][variant] = True
return {"test-name": "foo", "test-setting": setting}
return inner
@pytest.fixture(scope="module")
def mock_mozinfo():
"""Returns a mocked mozinfo object, similar to guess_mozinfo_from_task().
Args:
os (str): typically one of 'win, linux, mac, android'.
processor (str): processor architecture.
asan (bool, optional): addressanitizer build.
bits (int, optional): defaults to 64.
ccov (bool, optional): code coverage build.
debug (bool, optional): debug type build.
fission (bool, optional): process fission.
headless (bool, optional): headless browser testing without displays.
tsan (bool, optional): threadsanitizer build.
Returns:
dict: Dictionary mimickign the results from guess_mozinfo_from_task.
"""
def inner(
os,
processor,
asan=False,
bits=64,
ccov=False,
debug=False,
fission=False,
headless=False,
tsan=False,
):
return {
"os": os,
"processor": processor,
"toolkit": "",
"asan": asan,
"bits": bits,
"ccov": ccov,
"debug": debug,
"e10s": True,
"fission": fission,
"headless": headless,
"tsan": tsan,
"appname": "firefox",
"condprof": False,
}
return inner
@pytest.mark.parametrize(
"params,exception",
[
[("win", "7", 32, "opt"), None],
[("win", "10", 64, "opt"), None],
[("linux", "1804", 64, "debug"), None],
[("macosx", "1015", 64, "debug"), None],
[("macosx", "1100", 64, "opt"), None],
[("android", "", 64, "debug"), None],
[("and", "", 64, "debug"), ValueError],
[("", "", 64, "opt"), ValueError],
[("linux", "1804", 64, "opt", ["ccov"]), None],
[("linux", "1804", 64, "opt", ["asan"]), None],
[("win", "10", 64, "opt", ["tsan"]), None],
[("mac", "1100", 64, "opt", ["ccov"]), None],
[("android", "", 64, "opt", None, ["fission"]), None],
[("win", "10", "aarch64", "opt"), None],
],
)
def test_guess_mozinfo_from_task(params, exception, mock_task_definition):
"""Tests the mozinfo guessing process."""
# Set up a mocked task object.
task = mock_task_definition(*params)
if exception:
with pytest.raises(exception):
result = chunking.guess_mozinfo_from_task(task)
else:
expected_toolkits = {
"android": "android",
"linux": "gtk",
"mac": "cocoa",
"win": "windows",
}
result = chunking.guess_mozinfo_from_task(task)
setting = task["test-setting"]
assert str(result["bits"]) in setting["platform"]["arch"]
assert result["os"] in ("android", "linux", "mac", "win")
assert result["os"] in setting["platform"]["os"]["name"]
assert result["toolkit"] == expected_toolkits[result["os"]]
# Ensure the outcome of special build variants being present match what
# guess_mozinfo_from_task method returns for these attributes.
assert ("asan" in setting["build"]) == result["asan"]
assert ("tsan" in setting["build"]) == result["tsan"]
assert ("ccov" in setting["build"]) == result["ccov"]
# Ensure runtime variants match
assert ("fission" in setting["runtime"]) == result["fission"]
assert ("1proc" in setting["runtime"]) != result["e10s"]
@pytest.mark.parametrize("platform", ["unix", "windows", "android"])
@pytest.mark.parametrize(
"suite", ["crashtest", "reftest", "web-platform-tests", "xpcshell"]
)
def test_get_runtimes(platform, suite):
"""Tests that runtime information is returned for known good configurations."""
assert chunking.get_runtimes(platform, suite)
@pytest.mark.parametrize(
"platform,suite,exception",
[
("nonexistent_platform", "nonexistent_suite", KeyError),
("unix", "nonexistent_suite", KeyError),
("unix", "", TypeError),
("", "", TypeError),
("", "nonexistent_suite", TypeError),
],
)
def test_get_runtimes_invalid(platform, suite, exception):
"""Ensure get_runtimes() method raises an exception if improper request is made."""
with pytest.raises(exception):
chunking.get_runtimes(platform, suite)
@pytest.mark.parametrize(
"suite",
[
"web-platform-tests",
"web-platform-tests-reftest",
"web-platform-tests-wdspec",
"web-platform-tests-crashtest",
],
)
@pytest.mark.parametrize("chunks", [1, 3, 6, 20])
def test_mock_chunk_manifests_wpt(unchunked_manifests, suite, chunks):
"""Tests web-platform-tests and its subsuites chunking process."""
# Setup.
manifests = unchunked_manifests(suite)
# Generate the expected results, by generating list of indices that each
# manifest should go into and then appending each item to that index.
# This method is intentionally different from the way chunking.py performs
# chunking for cross-checking.
expected = [[] for _ in range(chunks)]
indexed = zip(manifests, list(range(0, chunks)) * len(manifests))
for i in indexed:
expected[i[1]].append(i[0])
# Call the method under test on unchunked manifests.
chunked_manifests = chunking.chunk_manifests(suite, "unix", chunks, manifests)
# Assertions and end test.
assert chunked_manifests
if chunks > len(manifests):
# If chunk count exceeds number of manifests, not all chunks will have
# manifests.
with pytest.raises(AssertionError):
assert all(chunked_manifests)
else:
assert all(chunked_manifests)
minimum = min(len(c) for c in chunked_manifests)
maximum = max(len(c) for c in chunked_manifests)
assert maximum - minimum <= 1
assert expected == chunked_manifests
@pytest.mark.parametrize(
"suite",
[
"mochitest-devtools-chrome",
"mochitest-browser-chrome",
"mochitest-plain",
"mochitest-chrome",
"xpcshell",
],
)
@pytest.mark.parametrize("chunks", [1, 3, 6, 20])
def test_mock_chunk_manifests(
mock_manifest_runtimes, unchunked_manifests, suite, chunks
):
"""Tests non-WPT tests and its subsuites chunking process."""
# Setup.
manifests = unchunked_manifests(suite)
# Call the method under test on unchunked manifests.
chunked_manifests = chunking.chunk_manifests(suite, "unix", chunks, manifests)
# Assertions and end test.
assert chunked_manifests
if chunks > len(manifests):
# If chunk count exceeds number of manifests, not all chunks will have
# manifests.
with pytest.raises(AssertionError):
assert all(chunked_manifests)
else:
assert all(chunked_manifests)
@pytest.mark.parametrize(
"suite",
[
"web-platform-tests",
"web-platform-tests-reftest",
"xpcshell",
"mochitest-plain",
"mochitest-devtools-chrome",
"mochitest-browser-chrome",
"mochitest-chrome",
],
)
@pytest.mark.parametrize(
"platform",
[
("mac", "x86_64"),
("win", "x86_64"),
("win", "x86"),
("win", "aarch64"),
("linux", "x86_64"),
("linux", "x86"),
],
)
def test_get_manifests(suite, platform, mock_mozinfo):
"""Tests the DefaultLoader class' ability to load manifests."""
mozinfo = mock_mozinfo(*platform)
loader = chunking.DefaultLoader([])
manifests = loader.get_manifests(suite, frozenset(mozinfo.items()))
assert manifests
assert manifests["active"]
if "web-platform" in suite:
assert manifests["skipped"] == []
else:
assert manifests["skipped"]
items = manifests["active"]
if suite == "xpcshell":
assert all([re.search(r"xpcshell(.*)?.ini", m) for m in items])
if "mochitest" in suite:
assert all([re.search(r"(mochitest|chrome|browser).*.ini", m) for m in items])
if "web-platform" in suite:
assert all([m.startswith("/") and m.count("/") <= 4 for m in items])
@pytest.mark.parametrize(
"suite",
[
"mochitest-devtools-chrome",
"mochitest-browser-chrome",
"mochitest-plain",
"mochitest-chrome",
"web-platform-tests",
"web-platform-tests-reftest",
"xpcshell",
],
)
@pytest.mark.parametrize(
"platform",
[
("mac", "x86_64"),
("win", "x86_64"),
("linux", "x86_64"),
],
)
@pytest.mark.parametrize("chunks", [1, 3, 6, 20])
def test_chunk_manifests(suite, platform, chunks, mock_mozinfo):
"""Tests chunking with real manifests."""
mozinfo = mock_mozinfo(*platform)
loader = chunking.DefaultLoader([])
manifests = loader.get_manifests(suite, frozenset(mozinfo.items()))
chunked_manifests = chunking.chunk_manifests(
suite, platform, chunks, manifests["active"]
)
# Assertions and end test.
assert chunked_manifests
assert len(chunked_manifests) == chunks
assert all(chunked_manifests)
if __name__ == "__main__":
main()
|