Debian Codegraph @

testing/mozharness/scripts/firefox_ui_tests.py

raw
1 #!/usr/bin/env python
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 # You can obtain one at http://mozilla.org/MPL/2.0/.
5
6
7 import copy
8 import os
9 import sys
10
11 # load modules from parent dir
12 sys.path.insert(1, os.path.dirname(sys.path[0]))
13
14 from mozharness.base.python import PreScriptAction
15 from mozharness.mozilla.structuredlog import StructuredOutputParser
16 from mozharness.mozilla.testing.codecoverage import (
17 CodeCoverageMixin,
18 code_coverage_config_options,
19 )
20 from mozharness.mozilla.testing.testbase import TestingMixin, testing_config_options
21 from mozharness.mozilla.vcstools import VCSToolsScript
22
23 # General command line arguments for Firefox ui tests
24 firefox_ui_tests_config_options = (
25 [
26 [
27 ["--allow-software-gl-layers"],
28 {
29 "action": "store_true",
30 "dest": "allow_software_gl_layers",
31 "default": False,
32 "help": "Permits a software GL implementation (such as LLVMPipe) to use the GL "
33 "compositor.",
34 },
35 ],
36 [
37 ["--dry-run"],
38 {
39 "dest": "dry_run",
40 "default": False,
41 "help": "Only show what was going to be tested.",
42 },
43 ],
44 [
45 ["--disable-e10s"],
46 {
47 "dest": "e10s",
48 "action": "store_false",
49 "default": True,
50 "help": "Disable multi-process (e10s) mode when running tests.",
51 },
52 ],
53 [
54 ["--disable-fission"],
55 {
56 "dest": "disable_fission",
57 "action": "store_true",
58 "default": False,
59 "help": "Disable fission mode when running tests.",
60 },
61 ],
62 [
63 ["--setpref"],
64 {
65 "dest": "extra_prefs",
66 "action": "append",
67 "default": [],
68 "help": "Extra user prefs.",
69 },
70 ],
71 [
72 ["--symbols-path=SYMBOLS_PATH"],
73 {
74 "dest": "symbols_path",
75 "help": "absolute path to directory containing breakpad "
76 "symbols, or the url of a zip file containing symbols.",
77 },
78 ],
79 ]
80 + copy.deepcopy(testing_config_options)
81 + copy.deepcopy(code_coverage_config_options)
82 )
83
84
85 class FirefoxUIFunctionalTests(TestingMixin, VCSToolsScript, CodeCoverageMixin):
86 def __init__(
87 self,
88 config_options=None,
89 all_actions=None,
90 default_actions=None,
91 *args,
92 **kwargs,
93 ):
94 config_options = config_options or firefox_ui_tests_config_options
95 actions = [
96 "clobber",
97 "download-and-extract",
98 "create-virtualenv",
99 "install",
100 "run-tests",
101 "uninstall",
102 ]
103
104 super(FirefoxUIFunctionalTests, self).__init__(
105 config_options=config_options,
106 all_actions=all_actions or actions,
107 default_actions=default_actions or actions,
108 *args,
109 **kwargs,
110 )
111
112 # Code which runs in automation has to include the following properties
113 self.binary_path = self.config.get("binary_path")
114 self.installer_path = self.config.get("installer_path")
115 self.installer_url = self.config.get("installer_url")
116 self.test_packages_url = self.config.get("test_packages_url")
117 self.test_url = self.config.get("test_url")
118
119 if not self.test_url and not self.test_packages_url:
120 self.fatal("You must use --test-url, or --test-packages-url")
121
122 @PreScriptAction("create-virtualenv")
123 def _pre_create_virtualenv(self, action):
124 dirs = self.query_abs_dirs()
125
126 requirements = os.path.join(
127 dirs["abs_test_install_dir"], "config", "firefox_ui_requirements.txt"
128 )
129 self.register_virtualenv_module(requirements=[requirements])
130
131 def download_and_extract(self):
132 """Override method from TestingMixin for more specific behavior."""
133 extract_dirs = [
134 "config/*",
135 "firefox-ui/*",
136 "marionette/*",
137 "mozbase/*",
138 "tools/mozterm/*",
139 "tools/wptserve/*",
140 "tools/wpt_third_party/*",
141 "mozpack/*",
142 "mozbuild/*",
143 ]
144 super(FirefoxUIFunctionalTests, self).download_and_extract(
145 extract_dirs=extract_dirs
146 )
147
148 def query_abs_dirs(self):
149 if self.abs_dirs:
150 return self.abs_dirs
151
152 abs_dirs = super(FirefoxUIFunctionalTests, self).query_abs_dirs()
153 abs_tests_install_dir = os.path.join(abs_dirs["abs_work_dir"], "tests")
154
155 dirs = {
156 "abs_blob_upload_dir": os.path.join(
157 abs_dirs["abs_work_dir"], "blobber_upload_dir"
158 ),
159 "abs_fxui_dir": os.path.join(abs_tests_install_dir, "firefox-ui"),
160 "abs_fxui_manifest_dir": os.path.join(
161 abs_tests_install_dir,
162 "firefox-ui",
163 "tests",
164 "testing",
165 "firefox-ui",
166 "tests",
167 ),
168 "abs_test_install_dir": abs_tests_install_dir,
169 }
170
171 for key in dirs:
172 if key not in abs_dirs:
173 abs_dirs[key] = dirs[key]
174 self.abs_dirs = abs_dirs
175
176 return self.abs_dirs
177
178 def query_harness_args(self, extra_harness_config_options=None):
179 """Collects specific test related command line arguments.
180
181 Sub classes should override this method for their own specific arguments.
182 """
183 config_options = extra_harness_config_options or []
184
185 args = []
186 for option in config_options:
187 dest = option[1]["dest"]
188 name = self.config.get(dest)
189
190 if name:
191 if type(name) is bool:
192 args.append(option[0][0])
193 else:
194 args.extend([option[0][0], self.config[dest]])
195
196 return args
197
198 def run_test(self, binary_path, env=None, marionette_port=2828):
199 """All required steps for running the tests against an installer."""
200 dirs = self.query_abs_dirs()
201
202 # Import the harness to retrieve the location of the cli scripts
203 import firefox_ui_harness
204
205 cmd = [
206 self.query_python_path(),
207 os.path.join(
208 os.path.dirname(firefox_ui_harness.__file__), "cli_functional.py"
209 ),
210 "--binary",
211 binary_path,
212 "--address",
213 f"localhost:{marionette_port}",
214 # Resource files to serve via local webserver
215 "--server-root",
216 os.path.join(dirs["abs_fxui_dir"], "resources"),
217 # Use the work dir to get temporary data stored
218 "--workspace",
219 dirs["abs_work_dir"],
220 # logging options
221 "--gecko-log=-", # output from the gecko process redirected to stdout
222 "--log-raw=-", # structured log for output parser redirected to stdout
223 # Enable tracing output to log transmission protocol
224 "-vv",
225 ]
226
227 # Collect all pass-through harness options to the script
228 cmd.extend(self.query_harness_args())
229
230 if not self.config.get("e10s"):
231 cmd.append("--disable-e10s")
232
233 if self.config.get("disable_fission"):
234 cmd.append("--disable-fission")
235
236 cmd.extend([f"--setpref={p}" for p in self.config.get("extra_prefs")])
237
238 if self.symbols_url:
239 cmd.extend(["--symbols-path", self.symbols_url])
240
241 parser = StructuredOutputParser(
242 config=self.config, log_obj=self.log_obj, strict=False
243 )
244
245 # Add the tests to run
246 cmd.append(
247 os.path.join(dirs["abs_fxui_manifest_dir"], "functional", "manifest.toml")
248 )
249
250 # Set further environment settings
251 env = env or self.query_env()
252 env.update({"MINIDUMP_SAVE_PATH": dirs["abs_blob_upload_dir"]})
253 if self.query_minidump_stackwalk():
254 env.update({"MINIDUMP_STACKWALK": self.minidump_stackwalk_path})
255 env["RUST_BACKTRACE"] = "full"
256
257 # If code coverage is enabled, set GCOV_PREFIX and JS_CODE_COVERAGE_OUTPUT_DIR
258 # env variables
259 if self.config.get("code_coverage"):
260 env["GCOV_PREFIX"] = self.gcov_dir
261 env["JS_CODE_COVERAGE_OUTPUT_DIR"] = self.jsvm_dir
262
263 if self.config["allow_software_gl_layers"]:
264 env["MOZ_LAYERS_ALLOW_SOFTWARE_GL"] = "1"
265
266 return_code = self.run_command(
267 cmd,
268 cwd=dirs["abs_fxui_dir"],
269 output_timeout=1000,
270 output_parser=parser,
271 env=env,
272 )
273
274 tbpl_status, log_level, summary = parser.evaluate_parser(return_code)
275 self.record_status(tbpl_status, level=log_level)
276
277 return return_code
278
279 @PreScriptAction("run-tests")
280 def _pre_run_tests(self, action):
281 if not self.installer_path and not self.installer_url:
282 self.critical(
283 "Please specify an installer via --installer-path or --installer-url."
284 )
285 sys.exit(1)
286
287 def run_tests(self):
288 """Run all the tests"""
289 return self.run_test(
290 binary_path=self.binary_path,
291 env=self.query_env(),
292 )
293
294
295 if __name__ == "__main__":
296 myScript = FirefoxUIFunctionalTests()
297 myScript.run_and_exit()