Bug 1851451 [wpt PR 41799] - Update wpt metadata, a=testonly
[gecko.git] / testing / talos / mach_commands.py
blobc68521942230c5f5189dc7fed2eb02ab3af3bfe1
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 # Integrates Talos mozharness with mach
7 import json
8 import logging
9 import os
10 import socket
11 import sys
13 import six
14 from mach.decorators import Command
15 from mozbuild.base import BinaryNotFoundException, MozbuildObject
17 HERE = os.path.dirname(os.path.realpath(__file__))
20 class TalosRunner(MozbuildObject):
21 def run_test(self, talos_args):
22 """
23 We want to do couple of things before running Talos
24 1. Clone mozharness
25 2. Make config for Talos Mozharness
26 3. Run mozharness
27 """
29 try:
30 self.init_variables(talos_args)
31 except BinaryNotFoundException as e:
32 self.log(logging.ERROR, "talos", {"error": str(e)}, "ERROR: {error}")
33 self.log(logging.INFO, "raptor", {"help": e.help()}, "{help}")
34 return 1
36 self.make_config()
37 self.write_config()
38 self.make_args()
39 return self.run_mozharness()
41 def init_variables(self, talos_args):
42 self.talos_dir = os.path.join(self.topsrcdir, "testing", "talos")
43 self.mozharness_dir = os.path.join(self.topsrcdir, "testing", "mozharness")
44 self.talos_json = os.path.join(self.talos_dir, "talos.json")
45 self.config_file_path = os.path.join(
46 self._topobjdir, "testing", "talos-in_tree_conf.json"
48 self.binary_path = self.get_binary_path()
49 self.virtualenv_script = os.path.join(
50 self.topsrcdir, "third_party", "python", "virtualenv", "virtualenv.py"
52 self.virtualenv_path = os.path.join(self._topobjdir, "testing", "talos-venv")
53 self.python_interp = sys.executable
54 self.talos_args = talos_args
56 def make_config(self):
57 default_actions = ["populate-webroot"]
58 default_actions.extend(
60 "create-virtualenv",
61 "run-tests",
64 self.config = {
65 "run_local": True,
66 "talos_json": self.talos_json,
67 "binary_path": self.binary_path,
68 "repo_path": self.topsrcdir,
69 "obj_path": self.topobjdir,
70 "log_name": "talos",
71 "virtualenv_path": self.virtualenv_path,
72 "pypi_url": "http://pypi.python.org/simple",
73 "base_work_dir": self.mozharness_dir,
74 "exes": {
75 "python": self.python_interp,
76 "virtualenv": [self.python_interp, self.virtualenv_script],
78 "title": socket.gethostname(),
79 "default_actions": default_actions,
80 "talos_extra_options": ["--develop"] + self.talos_args,
81 "python3_manifest": {
82 "win32": "python3.manifest",
83 "win64": "python3_x64.manifest",
87 def make_args(self):
88 self.args = {
89 "config": {},
90 "initial_config_file": self.config_file_path,
93 def write_config(self):
94 try:
95 config_file = open(self.config_file_path, "wb")
96 config_file.write(six.ensure_binary(json.dumps(self.config)))
97 except IOError as e:
98 err_str = "Error writing to Talos Mozharness config file {0}:{1}"
99 print(err_str.format(self.config_file_path, str(e)))
100 raise e
102 def run_mozharness(self):
103 sys.path.insert(0, self.mozharness_dir)
104 from mozharness.mozilla.testing.talos import Talos
106 talos_mh = Talos(
107 config=self.args["config"],
108 initial_config_file=self.args["initial_config_file"],
110 return talos_mh.run()
113 def create_parser():
114 sys.path.insert(0, HERE) # allow to import the talos package
115 from talos.cmdline import create_parser
117 return create_parser(mach_interface=True)
120 @Command(
121 "talos-test",
122 category="testing",
123 description="Run talos tests (performance testing).",
124 parser=create_parser,
126 def run_talos_test(command_context, **kwargs):
127 talos = command_context._spawn(TalosRunner)
129 try:
130 return talos.run_test(sys.argv[2:])
131 except Exception as e:
132 print(str(e))
133 return 1