Created
January 26, 2015 13:07
-
-
Save luser/c1e948eb16d43e6863bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# ***** BEGIN LICENSE BLOCK ***** | |
# 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/. | |
# ***** END LICENSE BLOCK ***** | |
import copy | |
import os | |
import re | |
import sys | |
# load modules from mozharness dir | |
sys.path.insert(1, os.path.join(os.path.dirname(sys.argv[0]), | |
'mozharness')) | |
from mozharness.base.errors import BaseErrorList, TarErrorList | |
from mozharness.base.log import ERROR, WARNING, FATAL | |
from mozharness.base.script import ( | |
BaseScript, | |
PreScriptAction, | |
) | |
from mozharness.base.vcs.vcsbase import VCSMixin | |
from mozharness.mozilla.testing.testbase import TestingMixin, testing_config_options | |
from mozharness.mozilla.mozbase import MozbaseMixin | |
from mozharness.mozilla.buildbot import TBPL_SUCCESS | |
from mozharness.mozilla.structuredlog import StructuredOutputParser | |
class LuciddreamTest(TestingMixin, VCSMixin, MozbaseMixin, BaseScript): | |
config_options = [[ | |
["--emulator-url"], | |
{"action": "store", | |
"dest": "emulator_url", | |
"default": None, | |
"help": "URL to the emulator zip", | |
} | |
], [ | |
["--luciddream-repo"], | |
{"action": "store", | |
"dest": "luciddream_repo", | |
"default": "", | |
"help": "Luciddream repository to use", | |
} | |
], [ | |
["--luciddream-rev"], | |
{"action": "store", | |
"dest": "luciddream_rev", | |
"default": "master", | |
"help": "Revision of Luciddream to check out", | |
} | |
], [ | |
["--tools-repo"], | |
{"action": "store", | |
"dest": "tools_repo", | |
"default": 'https://hg.mozilla.org/build/tools', | |
"help": "Build tools repo", | |
} | |
]] + copy.deepcopy(testing_config_options) | |
def __init__(self, require_config_file=False): | |
super(LuciddreamTest, self).__init__( | |
config_options=self.config_options, | |
all_actions=['clobber', | |
'download-and-extract', | |
'create-virtualenv', | |
'install', | |
'run-tests'], | |
default_actions=['clobber', | |
'download-and-extract', | |
'create-virtualenv', | |
'install', | |
'run-tests'], | |
require_config_file=require_config_file, | |
config={ | |
'require_test_zip': False, | |
'emulator': 'arm', | |
"exes": { | |
'gittool.py': '%(abs_tools_dir)s/buildfarm/utils/gittool.py', | |
}, | |
'virtualenv_modules': [ | |
'mozinstall', | |
], | |
} | |
) | |
# these are necessary since self.config is read only | |
c = self.config | |
self.installer_url = c.get('installer_url') | |
self.installer_path = c.get('installer_path') | |
self.emulator_url = c.get('emulator_url') | |
self.binary_path = c.get('binary_path') | |
def query_abs_dirs(self): | |
if self.abs_dirs: | |
return self.abs_dirs | |
abs_dirs = super(LuciddreamTest, self).query_abs_dirs() | |
dirs = {} | |
dirs['abs_emulator_dir'] = os.path.join( | |
abs_dirs['abs_work_dir'], 'emulator') | |
dirs['abs_b2g-distro_dir'] = os.path.join( | |
dirs['abs_emulator_dir'], 'b2g-distro') | |
dirs['abs_luciddream_dir'] = os.path.join( | |
abs_dirs['abs_work_dir'], 'luciddream') | |
dirs['abs_tools_dir'] = os.path.join( | |
abs_dirs['abs_work_dir'], 'tools') | |
abs_dirs.update(dirs) | |
self.abs_dirs = abs_dirs | |
return self.abs_dirs | |
def checkout_tools(self): | |
dirs = self.query_abs_dirs() | |
# We need hg.m.o/build/tools checked out | |
self.info("Checking out tools") | |
repos = [{ | |
'repo': self.config['tools_repo'], | |
'vcs': "hg", # May not have hgtool yet | |
'dest': dirs['abs_tools_dir'], | |
}] | |
rev = self.vcs_checkout(**repos[0]) | |
self.set_buildbot_property("tools_revision", rev, write_to_file=True) | |
def clone_luciddream(self): | |
self.info("Checking out luciddream harness") | |
luciddream_dir = self.query_abs_dirs()['abs_luciddream_dir'] | |
luciddream_repo = self.config['luciddream_repo'] | |
luciddream_rev = self.config['luciddream_rev'] | |
repos = [ | |
{'vcs': 'gittool', 'repo': luciddream_repo, 'dest': luciddream_dir, 'revision': luciddream_rev}, | |
] | |
# self.vcs_checkout already retries, so no need to wrap it in | |
# self.retry. We set the error_level to ERROR to prevent it going fatal | |
# so we can do our own handling here. | |
retval = self.vcs_checkout_repos(repos, error_level=ERROR) | |
if not retval: | |
self.rmtree(luciddream_dir) | |
self.fatal("Automation Error: couldn't clone luciddream", exit_code=4) | |
return retval | |
def install_emulator(self): | |
dirs = self.query_abs_dirs() | |
self.mkdir_p(dirs['abs_emulator_dir']) | |
tarfile = self.download_proxied_file(self.emulator_url, | |
parent_dir=dirs['abs_work_dir'], | |
error_level=FATAL) | |
self.emulator_path = tarfile | |
tar = self.query_exe('tar', return_type='list') | |
self.run_command(tar + ['zxf', self.emulator_path], | |
cwd=dirs['abs_emulator_dir'], | |
error_list=TarErrorList, | |
halt_on_failure=True, fatal_exit_code=3) | |
def download_and_extract(self): | |
super(LuciddreamTest, self).download_and_extract() | |
self.checkout_tools() | |
self.install_emulator() | |
self.clone_luciddream() | |
@PreScriptAction('create-virtualenv') | |
def _pre_create_virtualenv(self, action): | |
luciddream_dir = self.query_abs_dirs()['abs_luciddream_dir'] | |
self.register_virtualenv_module( | |
'luciddream', | |
url=luciddream_dir, | |
requirements=[os.path.join(luciddream_dir, 'requirements.txt')], | |
) | |
def run_tests(self): | |
""" | |
Run the tests | |
""" | |
dirs = self.query_abs_dirs() | |
env = {} | |
env = self.query_env(partial_env=env) | |
cwd = dirs['abs_luciddream_dir'] | |
# parser = StructuredOutputParser( | |
# suite_category='luciddream', | |
# strict=True, | |
# config=self.config, | |
# error_list=BaseErrorList, | |
# log_obj=self.log_obj, | |
# ) | |
raw_log = os.path.join(dirs['abs_work_dir'], 'luciddream_raw.log') | |
cmd = [ | |
self.query_python_path('python'), | |
'luciddream/runluciddream.py', | |
'--b2gpath', dirs['abs_b2g-distro_dir'], | |
'--browser-path', self.binary_path, | |
'--log-raw=%s' % raw_log, | |
'example-tests/luciddream.ini', | |
] | |
return_code = self.run_command(cmd, cwd=cwd, env=env, | |
output_timeout=1000, | |
output_parser=None, | |
success_codes=[0]) | |
if __name__ == '__main__': | |
luciddreamTest = LuciddreamTest() | |
luciddreamTest.run_and_exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment