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/.
5 from __future__
import absolute_import
, unicode_literals
14 from mozbuild
.base
import (
15 MachCommandConditions
as conditions
,
16 BinaryNotFoundException
,
19 from mach
.decorators
import (
28 def setup_awsy_argument_parser():
29 from marionette_harness
.runtests
import MarionetteArguments
30 from mozlog
.structured
import commandline
32 parser
= MarionetteArguments()
33 commandline
.add_logging_group(parser
)
38 from awsy
import ITERATIONS
, PER_TAB_PAUSE
, SETTLE_WAIT_TIME
, MAX_TABS
41 def run_awsy(command_context
, tests
, binary
=None, **kwargs
):
43 from mozlog
.structured
import commandline
45 from marionette_harness
.runtests
import MarionetteTestRunner
, MarionetteHarness
47 parser
= setup_awsy_argument_parser()
49 awsy_source_dir
= os
.path
.join(command_context
.topsrcdir
, "testing", "awsy")
51 tests
= [os
.path
.join(awsy_source_dir
, "awsy", "test_memory_usage.py")]
53 args
= argparse
.Namespace(tests
=tests
)
58 kwargs
["entities"] = 3
59 kwargs
["iterations"] = 1
60 kwargs
["perTabPause"] = 1
61 kwargs
["settleWaitTime"] = 1
63 if "single_stylo_traversal" in kwargs
and kwargs
["single_stylo_traversal"]:
64 os
.environ
["STYLO_THREADS"] = "1"
66 os
.environ
["STYLO_THREADS"] = "4"
81 if arg
in kwargs
and kwargs
[arg
] is not None:
82 runtime_testvars
[arg
] = kwargs
[arg
]
84 if "webRootDir" not in runtime_testvars
:
85 awsy_tests_dir
= os
.path
.join(command_context
.topobjdir
, "_tests", "awsy")
86 web_root_dir
= os
.path
.join(awsy_tests_dir
, "html")
87 runtime_testvars
["webRootDir"] = web_root_dir
89 web_root_dir
= runtime_testvars
["webRootDir"]
90 awsy_tests_dir
= os
.path
.dirname(web_root_dir
)
92 if "resultsDir" not in runtime_testvars
:
93 runtime_testvars
["resultsDir"] = os
.path
.join(awsy_tests_dir
, "results")
95 runtime_testvars
["bin"] = binary
96 runtime_testvars
["run_local"] = True
98 page_load_test_dir
= os
.path
.join(web_root_dir
, "page_load_test")
99 if not os
.path
.isdir(page_load_test_dir
):
100 os
.makedirs(page_load_test_dir
)
102 if not os
.path
.isdir(runtime_testvars
["resultsDir"]):
103 os
.makedirs(runtime_testvars
["resultsDir"])
105 runtime_testvars_path
= os
.path
.join(awsy_tests_dir
, "runtime-testvars.json")
106 if kwargs
["testvars"]:
107 kwargs
["testvars"].append(runtime_testvars_path
)
109 kwargs
["testvars"] = [runtime_testvars_path
]
111 runtime_testvars_file
= open(runtime_testvars_path
, "wb" if six
.PY2
else "w")
112 runtime_testvars_file
.write(json
.dumps(runtime_testvars
, indent
=2))
113 runtime_testvars_file
.close()
115 manifest_file
= os
.path
.join(awsy_source_dir
, "tp5n-pageset.manifest")
119 os
.path
.join(command_context
.topsrcdir
, "mach"),
123 "--tooltool-manifest=%s" % manifest_file
,
125 % os
.path
.join(command_context
.topsrcdir
, "tooltool-cache"),
128 command_context
.run_process(cwd
=page_load_test_dir
, **tooltool_args
)
129 tp5nzip
= os
.path
.join(page_load_test_dir
, "tp5n.zip")
130 tp5nmanifest
= os
.path
.join(page_load_test_dir
, "tp5n", "tp5n.manifest")
131 if not os
.path
.exists(tp5nmanifest
):
132 unzip_args
= {"args": ["unzip", "-q", "-o", tp5nzip
, "-d", page_load_test_dir
]}
134 command_context
.run_process(**unzip_args
)
135 except Exception as exc
:
137 if mozinfo
.os
== "win":
139 " Try using --web-root to specify a "
140 "directory closer to the drive root."
146 {"directory": page_load_test_dir
, "exception": exc
},
147 "Failed to unzip `tp5n.zip` into "
148 "`{directory}` with `{exception}`." + troubleshoot
,
152 # If '--preferences' was not specified supply our default set.
153 if not kwargs
["prefs_files"]:
154 kwargs
["prefs_files"] = [os
.path
.join(awsy_source_dir
, "conf", "prefs.json")]
156 # Setup DMD env vars if necessary.
158 bin_dir
= os
.path
.dirname(binary
)
160 if "DMD" not in os
.environ
:
161 os
.environ
["DMD"] = "1"
163 # Work around a startup crash with DMD on windows
164 if mozinfo
.os
== "win":
165 kwargs
["pref"] = "security.sandbox.content.level:0"
170 "Forcing 'security.sandbox.content.level' = 0 because DMD is enabled.",
172 elif mozinfo
.os
== "mac":
173 # On mac binary is in MacOS and dmd.py is in Resources, ie:
174 # Name.app/Contents/MacOS/libdmd.dylib
175 # Name.app/Contents/Resources/dmd.py
176 bin_dir
= os
.path
.join(bin_dir
, "../Resources/")
178 # Also add the bin dir to the python path so we can use dmd.py
179 if bin_dir
not in sys
.path
:
180 sys
.path
.append(bin_dir
)
182 for k
, v
in six
.iteritems(kwargs
):
185 parser
.verify_usage(args
)
187 args
.logger
= commandline
.setup_logging(
188 "Are We Slim Yet Tests", args
, {"mach": sys
.stdout
}
190 failed
= MarionetteHarness(MarionetteTestRunner
, args
=vars(args
)).run()
200 description
="Run Are We Slim Yet (AWSY) memory usage testing using marionette.",
201 parser
=setup_awsy_argument_parser
,
203 @CommandArgumentGroup("AWSY")
210 help="Path to web server root directory. If not specified, "
211 "defaults to topobjdir/_tests/awsy/html.",
219 help="Path to page manifest text file containing a list "
220 "of urls to test. The urls must be served from localhost. If not "
221 "specified, defaults to page_load_test/tp5n/tp5n.manifest under "
230 help="Path to results directory. If not specified, defaults "
231 "to the parent directory of the web root.",
239 help="Set --entities=3, --iterations=1, --per-tab-pause=1, "
240 "--settle-wait-time=1 for a quick test. Overrides any explicit "
241 "argument settings.",
249 help="Number of urls to load. Defaults to the total number of urls.",
257 help="Maximum number of tabs to open. Defaults to %s." % MAX_TABS
,
265 help="Number of times to run through the test suite. "
266 "Defaults to %s." % ITERATIONS
,
274 help="Seconds to wait in between opening tabs. Defaults to %s." % PER_TAB_PAUSE
,
277 "--settle-wait-time",
281 dest
="settleWaitTime",
282 help="Seconds to wait for things to settled down. "
283 "Defaults to %s." % SETTLE_WAIT_TIME
,
291 help="Enable DMD during testing. Requires a DMD-enabled build.",
299 help="Use the tp6 pageset during testing.",
301 def run_awsy_test(command_context
, tests
, **kwargs
):
302 """mach awsy-test runs the in-tree version of the Are We Slim Yet
305 awsy-test is implemented as a marionette test and marionette
306 test arguments also apply although they are not necessary
307 since reasonable defaults will be chosen.
309 The AWSY specific arguments can be found in the Command
310 Arguments for AWSY section below.
312 awsy-test will automatically download the tp5n.zip talos
313 pageset from tooltool and install it under
314 topobjdir/_tests/awsy/html. You can specify your own page set
315 by specifying --web-root and --page-manifest.
317 The results of the test will be placed in the results
318 directory specified by the --results argument.
320 On Windows, you may experience problems due to path length
321 errors when extracting the tp5n.zip file containing the
322 test pages or when attempting to write checkpoints to the
323 results directory. In that case, you should specify both
324 the --web-root and --results arguments pointing to a location
325 with a short path. For example:
327 --web-root=c:\\\\tmp\\\\html --results=c:\\\\tmp\\\\results
329 Note that the double backslashes are required.
331 kwargs
["logger_name"] = "Awsy Tests"
332 if "test_objects" in kwargs
:
334 for obj
in kwargs
["test_objects"]:
335 tests
.append(obj
["file_relpath"])
336 del kwargs
["test_objects"]
338 if not kwargs
.get("binary") and conditions
.is_firefox(command_context
):
340 kwargs
["binary"] = command_context
.get_binary_path("app")
341 except BinaryNotFoundException
as e
:
343 logging
.ERROR
, "awsy", {"error": str(e
)}, "ERROR: {error}"
345 command_context
.log(logging
.INFO
, "awsy", {"help": e
.help()}, "{help}")
347 return run_awsy(command_context
, tests
, **kwargs
)