1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 from tryselect
.tasks
import build
, resolve_tests_by_suite
13 MOZHARNESS_SCRIPTS
= {
14 "android_emulator_unittest": {
15 "class_name": "AndroidEmulatorTest",
17 "android/android_common.py",
30 "class_name": "DesktopUnittest",
32 "unittests/linux_unittest.py",
33 "unittests/mac_unittest.py",
34 "unittests/win_unittest.py",
44 "mochitest-valgrind-plain",
51 """A suite being listed in a script's `xfail` list means it won't work
52 properly with MOZHARNESS_TEST_PATHS (the mechanism |mach try fuzzy <path>|
57 def get_mozharness_test_paths(name
):
58 scriptdir
= os
.path
.join(build
.topsrcdir
, "testing", "mozharness", "scripts")
60 files
= imp
.find_module(name
, [scriptdir
])
61 mod
= imp
.load_module("scripts.{}".format(name
), *files
)
63 class_name
= MOZHARNESS_SCRIPTS
[name
]["class_name"]
64 cls
= getattr(mod
, class_name
)
65 return cls(require_config_file
=False)._get
_mozharness
_test
_paths
68 @pytest.fixture(scope
="module")
70 from moztest
.resolve
import _test_flavors
, _test_subsuites
73 for flavor
in _test_flavors
:
74 all_suites
.append({"flavor": flavor
, "srcdir_relpath": "test"})
76 for flavor
, subsuite
in _test_subsuites
:
78 {"flavor": flavor
, "subsuite": subsuite
, "srcdir_relpath": "test"}
84 def generate_suites_from_config(path
):
85 configdir
= os
.path
.join(build
.topsrcdir
, "testing", "mozharness", "configs")
87 parent
, name
= os
.path
.split(path
)
88 name
= os
.path
.splitext(name
)[0]
90 files
= imp
.find_module("{}".format(name
), [os
.path
.join(configdir
, parent
)])
91 mod
= imp
.load_module("config.{}".format(name
), *files
)
94 for category
in sorted(config
["suite_definitions"]):
95 key
= "all_{}_suites".format(category
)
100 for suite
in sorted(config
["all_{}_suites".format(category
)]):
101 yield category
, suite
104 def generate_suites():
105 for name
, script
in MOZHARNESS_SCRIPTS
.items():
108 for path
in script
["configs"]:
109 for suite
in generate_suites_from_config(path
):
116 if suite
[-1] in script
["xfail"]:
117 item
= pytest
.param(item
, marks
=pytest
.mark
.xfail
)
124 return "{}/{}".format(name
, suite
[-1])
127 @pytest.mark
.parametrize("item", generate_suites(), ids
=idfn
)
128 def test_suites(item
, patch_resolver
, all_suites
):
129 """An integration test to make sure the suites returned by
130 `tasks.resolve_tests_by_suite` match up with the names defined in
133 patch_resolver([], all_suites
)
134 suites
= resolve_tests_by_suite(["test"])
135 os
.environ
["MOZHARNESS_TEST_PATHS"] = json
.dumps(suites
)
138 func
= get_mozharness_test_paths(name
)
142 if __name__
== "__main__":