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
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
):
23 We want to do couple of things before running Talos
25 2. Make config for Talos Mozharness
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}")
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(
66 "talos_json": self
.talos_json
,
67 "binary_path": self
.binary_path
,
68 "repo_path": self
.topsrcdir
,
69 "obj_path": self
.topobjdir
,
71 "virtualenv_path": self
.virtualenv_path
,
72 "pypi_url": "http://pypi.python.org/simple",
73 "base_work_dir": self
.mozharness_dir
,
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
,
82 "win32": "python3.manifest",
83 "win64": "python3_x64.manifest",
90 "initial_config_file": self
.config_file_path
,
93 def write_config(self
):
95 config_file
= open(self
.config_file_path
, "wb")
96 config_file
.write(six
.ensure_binary(json
.dumps(self
.config
)))
98 err_str
= "Error writing to Talos Mozharness config file {0}:{1}"
99 print(err_str
.format(self
.config_file_path
, str(e
)))
102 def run_mozharness(self
):
103 sys
.path
.insert(0, self
.mozharness_dir
)
104 from mozharness
.mozilla
.testing
.talos
import Talos
107 config
=self
.args
["config"],
108 initial_config_file
=self
.args
["initial_config_file"],
110 return talos_mh
.run()
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)
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
)
130 return talos
.run_test(sys
.argv
[2:])
131 except Exception as e
: