Bug 1773567 - remove fission variant making the labels fission by default. r=ahal
[gecko.git] / taskcluster / gecko_taskgraph / test / test_transforms_test.py
blob141e9217aa5d9ee006f55dc9fd16e503d3019eb3
1 # Any copyright is dedicated to the Public Domain.
2 # https://creativecommons.org/publicdomain/zero/1.0/
3 """
4 Tests for the 'tests.py' transforms
5 """
7 import hashlib
8 import json
9 from functools import partial
10 from pprint import pprint
12 import mozunit
13 import pytest
15 from gecko_taskgraph.transforms import test as test_transforms
18 @pytest.fixture
19 def make_test_task():
20 """Create a test task definition with required default values."""
22 def inner(**extra):
23 task = {
24 "attributes": {},
25 "build-platform": "linux64",
26 "mozharness": {"extra-options": []},
27 "test-platform": "linux64",
28 "treeherder-symbol": "g(t)",
29 "try-name": "task",
31 task.update(extra)
32 return task
34 return inner
37 def test_split_variants(monkeypatch, run_transform, make_test_task):
38 # mock out variant definitions
39 monkeypatch.setattr(
40 test_transforms.variant,
41 "TEST_VARIANTS",
43 "foo": {
44 "description": "foo variant",
45 "suffix": "foo",
46 "component": "foo bar",
47 "merge": {
48 "mozharness": {
49 "extra-options": [
50 "--setpref=foo=1",
55 "bar": {
56 "description": "bar variant",
57 "suffix": "bar",
58 "component": "foo bar",
59 "when": {
60 "$eval": "task['test-platform'][:5] == 'linux'",
62 "merge": {
63 "mozharness": {
64 "extra-options": [
65 "--setpref=bar=1",
69 "replace": {"tier": 2},
74 def make_expected(variant):
75 """Helper to generate expected tasks."""
76 return make_test_task(
77 **{
78 "attributes": {"unittest_variant": variant},
79 "description": f"{variant} variant",
80 "mozharness": {
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)
90 # test no variants
91 input_task = make_test_task(
92 **{
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")
113 expected["tier"] = 2
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"] == [
127 "--setpref=foo=1",
128 "--setpref=bar=1",
130 assert tasks[1]["treeherder-symbol"] == "g-foo-bar(t)"
132 # test 'when' filter
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,
150 "variants": ["foo"],
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(
159 "task,expected",
161 pytest.param(
163 "attributes": {"unittest_variant": "webrender-sw+wayland+1proc"},
164 "test-platform": "linux1804-64-clang-trunk-qr/opt",
167 "platform": {
168 "arch": "64",
169 "os": {
170 "name": "linux",
171 "version": "1804",
174 "build": {
175 "type": "opt",
176 "clang-trunk": True,
178 "runtime": {
179 "1proc": True,
180 "wayland": True,
181 "webrender-sw": True,
184 id="linux",
186 pytest.param(
188 "attributes": {},
189 "test-platform": "android-hw-a51-11-0-arm7-shippable-qr/opt",
192 "platform": {
193 "arch": "arm7",
194 "device": "a51",
195 "os": {
196 "name": "android",
197 "version": "11.0",
200 "build": {
201 "type": "opt",
202 "shippable": True,
204 "runtime": {},
206 id="android",
208 pytest.param(
210 "attributes": {},
211 "test-platform": "windows10-64-2004-ref-hw-2017-ccov/debug",
214 "platform": {
215 "arch": "64",
216 "machine": "ref-hw-2017",
217 "os": {
218 "build": "2004",
219 "name": "windows",
220 "version": "10",
223 "build": {
224 "type": "debug",
225 "ccov": True,
227 "runtime": {},
229 id="windows",
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")
237 ).hexdigest()[:12]
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.
248 assert (
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(
263 "task,callback",
265 pytest.param(
266 {"attributes": {"unittest_variant": "socketprocess"}},
267 assert_spi_not_disabled,
268 id="socketprocess",
270 pytest.param(
272 "attributes": {"unittest_variant": "socketprocess_networking"},
274 assert_spi_not_disabled,
275 id="socketprocess_networking",
277 pytest.param({}, assert_spi_disabled, id="no variant"),
278 pytest.param(
279 {"suite": "cppunit", "attributes": {"unittest_variant": "socketprocess"}},
280 assert_spi_not_disabled,
281 id="excluded suite",
283 pytest.param(
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)
295 task = list(
296 run_transform(test_transforms.other.ensure_spi_disabled_on_all_but_spi, task)
297 )[0]
298 pprint(task)
299 callback(task)
302 if __name__ == "__main__":
303 mozunit.main()