2013-07-26 19:04:31 +04:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
# Integrates Talos mozharness with mach
|
|
|
|
|
2015-06-22 03:39:09 +03:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2013-07-26 19:04:31 +04:00
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import json
|
2013-10-15 22:05:39 +04:00
|
|
|
import socket
|
2013-07-26 19:04:31 +04:00
|
|
|
|
2015-11-21 14:47:30 +03:00
|
|
|
from mozbuild.base import MozbuildObject, MachCommandBase
|
|
|
|
from mach.decorators import CommandProvider, Command
|
2013-07-26 19:04:31 +04:00
|
|
|
|
2015-09-19 13:25:04 +03:00
|
|
|
HERE = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
|
|
|
|
2013-07-26 19:04:31 +04:00
|
|
|
class TalosRunner(MozbuildObject):
|
2015-09-19 13:25:04 +03:00
|
|
|
def run_test(self, talos_args):
|
2013-07-26 19:04:31 +04:00
|
|
|
"""
|
|
|
|
We want to do couple of things before running Talos
|
|
|
|
1. Clone mozharness
|
|
|
|
2. Make config for Talos Mozharness
|
|
|
|
3. Run mozharness
|
|
|
|
"""
|
|
|
|
|
2015-09-19 13:25:04 +03:00
|
|
|
self.init_variables(talos_args)
|
2013-07-26 19:04:31 +04:00
|
|
|
self.make_config()
|
|
|
|
self.write_config()
|
|
|
|
self.make_args()
|
|
|
|
return self.run_mozharness()
|
|
|
|
|
2015-09-19 13:25:04 +03:00
|
|
|
def init_variables(self, talos_args):
|
2013-07-26 19:04:31 +04:00
|
|
|
self.talos_dir = os.path.join(self.topsrcdir, 'testing', 'talos')
|
2015-07-22 17:59:01 +03:00
|
|
|
self.mozharness_dir = os.path.join(self.topsrcdir, 'testing',
|
|
|
|
'mozharness')
|
2013-07-26 19:04:31 +04:00
|
|
|
self.talos_json = os.path.join(self.talos_dir, 'talos.json')
|
2015-12-16 02:05:23 +03:00
|
|
|
self.config_file_path = os.path.join(self._topobjdir, 'testing',
|
|
|
|
'talos-in_tree_conf.json')
|
2013-07-26 19:04:31 +04:00
|
|
|
self.binary_path = self.get_binary_path()
|
2017-05-25 18:48:03 +03:00
|
|
|
self.virtualenv_script = os.path.join(self.topsrcdir, 'third_party', 'python',
|
2013-07-26 19:04:31 +04:00
|
|
|
'virtualenv', 'virtualenv.py')
|
2015-12-16 02:05:23 +03:00
|
|
|
self.virtualenv_path = os.path.join(self._topobjdir, 'testing',
|
|
|
|
'talos-venv')
|
2013-07-26 19:04:31 +04:00
|
|
|
self.python_interp = sys.executable
|
2015-09-19 13:25:04 +03:00
|
|
|
self.talos_args = talos_args
|
2013-07-26 19:04:31 +04:00
|
|
|
|
|
|
|
def make_config(self):
|
2018-01-10 12:59:53 +03:00
|
|
|
default_actions = ['populate-webroot']
|
|
|
|
default_actions.extend([
|
2018-02-27 00:43:09 +03:00
|
|
|
'create-virtualenv',
|
2018-01-10 12:59:53 +03:00
|
|
|
'run-tests',
|
|
|
|
])
|
2013-07-26 19:04:31 +04:00
|
|
|
self.config = {
|
2015-08-31 23:41:49 +03:00
|
|
|
'run_local': True,
|
2013-07-26 19:04:31 +04:00
|
|
|
'talos_json': self.talos_json,
|
|
|
|
'binary_path': self.binary_path,
|
2017-07-13 03:05:29 +03:00
|
|
|
'repo_path': self.topsrcdir,
|
|
|
|
'obj_path': self.topobjdir,
|
2013-07-26 19:04:31 +04:00
|
|
|
'log_name': 'talos',
|
|
|
|
'virtualenv_path': self.virtualenv_path,
|
|
|
|
'pypi_url': 'http://pypi.python.org/simple',
|
|
|
|
'base_work_dir': self.mozharness_dir,
|
|
|
|
'exes': {
|
|
|
|
'python': self.python_interp,
|
|
|
|
'virtualenv': [self.python_interp, self.virtualenv_script]
|
|
|
|
},
|
2013-10-15 22:05:39 +04:00
|
|
|
'title': socket.gethostname(),
|
2018-01-10 12:59:53 +03:00
|
|
|
'default_actions': default_actions,
|
2015-09-19 13:25:04 +03:00
|
|
|
'talos_extra_options': ['--develop'] + self.talos_args,
|
2017-06-05 21:51:06 +03:00
|
|
|
'python3_manifest': {
|
|
|
|
'win32': 'python3.manifest',
|
|
|
|
'win64': 'python3_x64.manifest',
|
|
|
|
}
|
2013-07-26 19:04:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
def make_args(self):
|
|
|
|
self.args = {
|
2015-09-25 23:39:03 +03:00
|
|
|
'config': {},
|
|
|
|
'initial_config_file': self.config_file_path,
|
2015-11-21 14:47:30 +03:00
|
|
|
}
|
2013-07-26 19:04:31 +04:00
|
|
|
|
|
|
|
def write_config(self):
|
|
|
|
try:
|
|
|
|
config_file = open(self.config_file_path, 'wb')
|
|
|
|
config_file.write(json.dumps(self.config))
|
|
|
|
except IOError as e:
|
|
|
|
err_str = "Error writing to Talos Mozharness config file {0}:{1}"
|
|
|
|
print(err_str.format(self.config_file_path, str(e)))
|
|
|
|
raise e
|
|
|
|
|
|
|
|
def run_mozharness(self):
|
2013-08-01 17:19:40 +04:00
|
|
|
sys.path.insert(0, self.mozharness_dir)
|
2013-07-26 19:04:31 +04:00
|
|
|
from mozharness.mozilla.testing.talos import Talos
|
|
|
|
talos_mh = Talos(config=self.args['config'],
|
|
|
|
initial_config_file=self.args['initial_config_file'])
|
|
|
|
return talos_mh.run()
|
|
|
|
|
2015-11-21 14:47:30 +03:00
|
|
|
|
|
|
|
def create_parser():
|
|
|
|
sys.path.insert(0, HERE) # allow to import the talos package
|
|
|
|
from talos.cmdline import create_parser
|
|
|
|
return create_parser(mach_interface=True)
|
|
|
|
|
|
|
|
|
2013-07-26 19:04:31 +04:00
|
|
|
@CommandProvider
|
|
|
|
class MachCommands(MachCommandBase):
|
|
|
|
@Command('talos-test', category='testing',
|
2015-09-19 13:25:04 +03:00
|
|
|
description='Run talos tests (performance testing).',
|
2015-11-21 14:47:30 +03:00
|
|
|
parser=create_parser)
|
2015-09-19 13:25:04 +03:00
|
|
|
def run_talos_test(self, **kwargs):
|
2013-07-26 19:04:31 +04:00
|
|
|
talos = self._spawn(TalosRunner)
|
|
|
|
|
|
|
|
try:
|
2015-09-19 13:25:04 +03:00
|
|
|
return talos.run_test(sys.argv[2:])
|
2013-07-26 19:04:31 +04:00
|
|
|
except Exception as e:
|
|
|
|
print(str(e))
|
|
|
|
return 1
|