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
16 from mozbuild
.base
import (
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
):
29 We want to do couple of things before running Talos
31 2. Make config for Talos Mozharness
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}")
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(
72 "talos_json": self
.talos_json
,
73 "binary_path": self
.binary_path
,
74 "repo_path": self
.topsrcdir
,
75 "obj_path": self
.topobjdir
,
77 "virtualenv_path": self
.virtualenv_path
,
78 "pypi_url": "http://pypi.python.org/simple",
79 "base_work_dir": self
.mozharness_dir
,
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
,
88 "win32": "python3.manifest",
89 "win64": "python3_x64.manifest",
96 "initial_config_file": self
.config_file_path
,
99 def write_config(self
):
101 config_file
= open(self
.config_file_path
, "wb")
102 config_file
.write(six
.ensure_binary(json
.dumps(self
.config
)))
104 err_str
= "Error writing to Talos Mozharness config file {0}:{1}"
105 print(err_str
.format(self
.config_file_path
, str(e
)))
108 def run_mozharness(self
):
109 sys
.path
.insert(0, self
.mozharness_dir
)
110 from mozharness
.mozilla
.testing
.talos
import Talos
113 config
=self
.args
["config"],
114 initial_config_file
=self
.args
["initial_config_file"],
116 return talos_mh
.run()
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)
127 class MachCommands(MachCommandBase
):
131 description
="Run talos tests (performance testing).",
132 parser
=create_parser
,
134 def run_talos_test(self
, **kwargs
):
135 talos
= self
._spawn
(TalosRunner
)
138 return talos
.run_test(sys
.argv
[2:])
139 except Exception as e
: