Bug 1700051: part 31.2) Move `mSoftBegin` to `SoftText`. r=smaug
[gecko.git] / testing / talos / mach_commands.py
blob3ac68f11f8632469f70341fbffc12ea144d25827
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 from __future__ import absolute_import, print_function, unicode_literals
9 import logging
10 import os
11 import six
12 import sys
13 import json
14 import socket
16 from mozbuild.base import (
17 MozbuildObject,
18 MachCommandBase,
19 BinaryNotFoundException,
21 from mach.decorators import CommandProvider, Command
23 HERE = os.path.dirname(os.path.realpath(__file__))
26 class TalosRunner(MozbuildObject):
27 def run_test(self, talos_args):
28 """
29 We want to do couple of things before running Talos
30 1. Clone mozharness
31 2. Make config for Talos Mozharness
32 3. Run mozharness
33 """
35 try:
36 self.init_variables(talos_args)
37 except BinaryNotFoundException as e:
38 self.log(logging.ERROR, "talos", {"error": str(e)}, "ERROR: {error}")
39 self.log(logging.INFO, "raptor", {"help": e.help()}, "{help}")
40 return 1
42 self.make_config()
43 self.write_config()
44 self.make_args()
45 return self.run_mozharness()
47 def init_variables(self, talos_args):
48 self.talos_dir = os.path.join(self.topsrcdir, "testing", "talos")
49 self.mozharness_dir = os.path.join(self.topsrcdir, "testing", "mozharness")
50 self.talos_json = os.path.join(self.talos_dir, "talos.json")
51 self.config_file_path = os.path.join(
52 self._topobjdir, "testing", "talos-in_tree_conf.json"
54 self.binary_path = self.get_binary_path()
55 self.virtualenv_script = os.path.join(
56 self.topsrcdir, "third_party", "python", "virtualenv", "virtualenv.py"
58 self.virtualenv_path = os.path.join(self._topobjdir, "testing", "talos-venv")
59 self.python_interp = sys.executable
60 self.talos_args = talos_args
62 def make_config(self):
63 default_actions = ["populate-webroot"]
64 default_actions.extend(
66 "create-virtualenv",
67 "run-tests",
70 self.config = {
71 "run_local": True,
72 "talos_json": self.talos_json,
73 "binary_path": self.binary_path,
74 "repo_path": self.topsrcdir,
75 "obj_path": self.topobjdir,
76 "log_name": "talos",
77 "virtualenv_path": self.virtualenv_path,
78 "pypi_url": "http://pypi.python.org/simple",
79 "base_work_dir": self.mozharness_dir,
80 "exes": {
81 "python": self.python_interp,
82 "virtualenv": [self.python_interp, self.virtualenv_script],
84 "title": socket.gethostname(),
85 "default_actions": default_actions,
86 "talos_extra_options": ["--develop"] + self.talos_args,
87 "python3_manifest": {
88 "win32": "python3.manifest",
89 "win64": "python3_x64.manifest",
93 def make_args(self):
94 self.args = {
95 "config": {},
96 "initial_config_file": self.config_file_path,
99 def write_config(self):
100 try:
101 config_file = open(self.config_file_path, "wb")
102 config_file.write(six.ensure_binary(json.dumps(self.config)))
103 except IOError as e:
104 err_str = "Error writing to Talos Mozharness config file {0}:{1}"
105 print(err_str.format(self.config_file_path, str(e)))
106 raise e
108 def run_mozharness(self):
109 sys.path.insert(0, self.mozharness_dir)
110 from mozharness.mozilla.testing.talos import Talos
112 talos_mh = Talos(
113 config=self.args["config"],
114 initial_config_file=self.args["initial_config_file"],
116 return talos_mh.run()
119 def create_parser():
120 sys.path.insert(0, HERE) # allow to import the talos package
121 from talos.cmdline import create_parser
123 return create_parser(mach_interface=True)
126 @CommandProvider
127 class MachCommands(MachCommandBase):
128 @Command(
129 "talos-test",
130 category="testing",
131 description="Run talos tests (performance testing).",
132 parser=create_parser,
134 def run_talos_test(self, **kwargs):
135 talos = self._spawn(TalosRunner)
137 try:
138 return talos.run_test(sys.argv[2:])
139 except Exception as e:
140 print(str(e))
141 return 1