1 # Any copyright is dedicated to the Public Domain.
2 # https://creativecommons.org/publicdomain/zero/1.0/
4 Tests for the 'tests.py' transforms
9 from functools
import partial
10 from pprint
import pprint
15 from gecko_taskgraph
.transforms
import test
as test_transforms
20 """Create a test task definition with required default values."""
25 "build-platform": "linux64",
26 "mozharness": {"extra-options": []},
27 "test-platform": "linux64",
28 "treeherder-symbol": "g(t)",
37 def test_split_variants(monkeypatch
, run_transform
, make_test_task
):
38 # mock out variant definitions
40 test_transforms
.variant
,
44 "description": "foo variant",
46 "component": "foo bar",
56 "description": "bar variant",
58 "component": "foo bar",
60 "$eval": "task['test-platform'][:5] == 'linux'",
69 "replace": {"tier": 2},
74 def make_expected(variant
):
75 """Helper to generate expected tasks."""
76 return make_test_task(
78 "attributes": {"unittest_variant": variant
},
79 "description": f
"{variant} variant",
81 "extra-options": [f
"--setpref={variant}=1"],
83 "treeherder-symbol": f
"g-{variant}(t)",
84 "variant-suffix": f
"-{variant}",
88 run_split_variants
= partial(run_transform
, test_transforms
.variant
.split_variants
)
91 input_task
= make_test_task(
93 "run-without-variant": True,
96 tasks
= list(run_split_variants(input_task
))
97 assert len(tasks
) == 1
98 assert tasks
[0] == input_task
100 # test variants are split into expected tasks
101 input_task
= make_test_task(
103 "run-without-variant": True,
104 "variants": ["foo", "bar"],
107 tasks
= list(run_split_variants(input_task
))
108 assert len(tasks
) == 3
109 assert tasks
[0] == make_test_task()
110 assert tasks
[1] == make_expected("foo")
112 expected
= make_expected("bar")
114 assert tasks
[2] == expected
116 # test composite variants
117 input_task
= make_test_task(
119 "run-without-variant": True,
120 "variants": ["foo+bar"],
123 tasks
= list(run_split_variants(input_task
))
124 assert len(tasks
) == 2
125 assert tasks
[1]["attributes"]["unittest_variant"] == "foo+bar"
126 assert tasks
[1]["mozharness"]["extra-options"] == [
130 assert tasks
[1]["treeherder-symbol"] == "g-foo-bar(t)"
133 input_task
= make_test_task(
135 "run-without-variant": True,
136 # this should cause task to be filtered out of 'bar' and 'foo+bar' variants
137 "test-platform": "windows",
138 "variants": ["foo", "bar", "foo+bar"],
141 tasks
= list(run_split_variants(input_task
))
142 assert len(tasks
) == 2
143 assert "unittest_variant" not in tasks
[0]["attributes"]
144 assert tasks
[1]["attributes"]["unittest_variant"] == "foo"
146 # test 'run-without-variants=False'
147 input_task
= make_test_task(
149 "run-without-variant": False,
153 tasks
= list(run_split_variants(input_task
))
154 assert len(tasks
) == 1
155 assert tasks
[0]["attributes"]["unittest_variant"] == "foo"
158 @pytest.mark
.parametrize(
163 "attributes": {"unittest_variant": "webrender-sw+wayland+1proc"},
164 "test-platform": "linux1804-64-clang-trunk-qr/opt",
181 "webrender-sw": True,
189 "test-platform": "android-hw-a51-11-0-arm7-shippable-qr/opt",
211 "test-platform": "windows10-64-2004-ref-hw-2017-ccov/debug",
216 "machine": "ref-hw-2017",
233 def test_set_test_setting(run_transform
, task
, expected
):
234 # add hash to 'expected'
235 expected
["_hash"] = hashlib
.sha256(
236 json
.dumps(expected
, sort_keys
=True).encode("utf-8")
239 task
= list(run_transform(test_transforms
.other
.set_test_setting
, task
))[0]
240 assert "test-setting" in task
241 assert task
["test-setting"] == expected
244 def assert_spi_not_disabled(task
):
245 extra_options
= task
["mozharness"]["extra-options"]
246 # The pref to enable this gets set outside of this transform, so only
247 # bother asserting that the pref to disable does not exist.
249 "--setpref=media.peerconnection.mtransport_process=false" not in extra_options
251 assert "--setpref=network.process.enabled=false" not in extra_options
254 def assert_spi_disabled(task
):
255 extra_options
= task
["mozharness"]["extra-options"]
256 assert "--setpref=media.peerconnection.mtransport_process=false" in extra_options
257 assert "--setpref=media.peerconnection.mtransport_process=true" not in extra_options
258 assert "--setpref=network.process.enabled=false" in extra_options
259 assert "--setpref=network.process.enabled=true" not in extra_options
262 @pytest.mark
.parametrize(
266 {"attributes": {"unittest_variant": "socketprocess"}},
267 assert_spi_not_disabled
,
272 "attributes": {"unittest_variant": "socketprocess_networking"},
274 assert_spi_not_disabled
,
275 id="socketprocess_networking",
277 pytest
.param({}, assert_spi_disabled
, id="no variant"),
279 {"suite": "cppunit", "attributes": {"unittest_variant": "socketprocess"}},
280 assert_spi_not_disabled
,
284 {"attributes": {"unittest_variant": "no-fission+socketprocess"}},
285 assert_spi_not_disabled
,
286 id="composite variant",
290 def test_ensure_spi_disabled_on_all_but_spi(
291 make_test_task
, run_transform
, task
, callback
293 task
.setdefault("suite", "mochitest-plain")
294 task
= make_test_task(**task
)
296 run_transform(test_transforms
.other
.ensure_spi_disabled_on_all_but_spi
, task
)
302 if __name__
== "__main__":