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/.
10 from mozfile
import load_source
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")
60 "scripts." + name
, os
.path
.join(scriptdir
, "scripts", name
+ ".py")
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 parent
, name
= os
.path
.split(path
)
86 name
= os
.path
.splitext(name
)[0]
88 configdir
= os
.path
.join(
89 build
.topsrcdir
, "testing", "mozharness", "configs", parent
92 mod
= load_source(name
, os
.path
.join(configdir
, name
+ ".py"))
96 for category
in sorted(config
["suite_definitions"]):
97 key
= "all_{}_suites".format(category
)
102 for suite
in sorted(config
["all_{}_suites".format(category
)]):
103 yield category
, suite
106 def generate_suites():
107 for name
, script
in MOZHARNESS_SCRIPTS
.items():
110 for path
in script
["configs"]:
111 for suite
in generate_suites_from_config(path
):
118 if suite
[-1] in script
["xfail"]:
119 item
= pytest
.param(item
, marks
=pytest
.mark
.xfail
)
126 return "{}/{}".format(name
, suite
[-1])
129 @pytest.mark
.parametrize("item", generate_suites(), ids
=idfn
)
130 def test_suites(item
, patch_resolver
, all_suites
):
131 """An integration test to make sure the suites returned by
132 `tasks.resolve_tests_by_suite` match up with the names defined in
135 patch_resolver([], all_suites
)
136 suites
= resolve_tests_by_suite(["test"])
137 os
.environ
["MOZHARNESS_TEST_PATHS"] = json
.dumps(suites
)
140 func
= get_mozharness_test_paths(name
)
144 if __name__
== "__main__":