Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import logging, os, shutil, tempfile, utils | 5 import logging, os, re, shutil, subprocess, tempfile, utils |
| 6 from autotest_lib.client.bin import test | 6 from autotest_lib.client.bin import test |
| 7 from autotest_lib.client.common_lib import error, site_ui | 7 from autotest_lib.client.common_lib import error, site_ui |
| 8 | 8 |
| 9 class ChromeTestBase(test.test): | 9 class ChromeTestBase(test.test): |
| 10 home_dir = None | 10 home_dir = None |
| 11 | 11 |
| 12 def setup(self): | 12 def setup(self): |
| 13 self.job.setup_dep(['chrome_test']) | 13 self.job.setup_dep(['chrome_test']) |
| 14 # create a empty srcdir to prevent the error that checks .version file | 14 # create a empty srcdir to prevent the error that checks .version file |
| 15 if not os.path.exists(self.srcdir): | 15 if not os.path.exists(self.srcdir): |
| 16 os.mkdir(self.srcdir) | 16 os.mkdir(self.srcdir) |
| 17 | 17 |
| 18 | 18 |
| 19 def run_chrome_test(self, test_to_run, extra_params = ''): | 19 def initialize(self): |
| 20 self.home_dir = tempfile.mkdtemp() | |
| 20 dep = 'chrome_test' | 21 dep = 'chrome_test' |
| 21 dep_dir = os.path.join(self.autodir, 'deps', dep) | 22 dep_dir = os.path.join(self.autodir, 'deps', dep) |
| 23 self.job.add_repository(['/usr/local/autotest-pkgs']) | |
|
ericli
2010/11/12 22:16:26
get this value from globle_config.ini.
from autot
Chris Masone
2010/11/15 23:46:23
Done.
| |
| 22 self.job.install_pkg(dep, 'dep', dep_dir) | 24 self.job.install_pkg(dep, 'dep', dep_dir) |
| 25 self.cr_source_dir = '%s/test_src' % dep_dir | |
| 26 self.test_binary_dir = '%s/out/Release' % self.cr_source_dir | |
| 27 try: | |
| 28 setup_cmd = '/bin/sh %s/%s' % (self.test_binary_dir, | |
| 29 'setup_test_links.sh') | |
| 30 utils.system(setup_cmd) # this might raise an exception | |
| 31 except error.CmdError, e: | |
| 32 raise error.TestError(e) | |
| 23 | 33 |
| 24 chrome_dir = '/opt/google/chrome' | |
| 25 cr_source_dir = '%s/test_src' % dep_dir | |
| 26 test_binary_dir = '%s/test_src/out/Release' % dep_dir | |
| 27 self.home_dir = tempfile.mkdtemp() | |
| 28 | 34 |
| 35 def filter_bad_tests(self, tests): | |
| 36 matcher = re.compile(".+\.(FLAKY|FAILS|DISABLED).+") | |
| 37 return filter(lambda(x): not matcher.match(x), tests) | |
| 38 | |
| 39 | |
| 40 def list_chrome_tests(self, test_binary): | |
| 41 all_tests = [] | |
| 29 try: | 42 try: |
| 30 setup_cmd = '%s/%s' % (test_binary_dir, | 43 cmd = '%s/%s --gtest_list_tests' % (self.test_binary_dir, |
| 31 'setup_test_links.sh') | 44 test_binary) |
| 32 utils.system(setup_cmd) | 45 cmd = 'HOME=%s CR_SOURCE_ROOT=%s %s' % (self.home_dir, |
| 46 self.cr_source_dir, | |
| 47 site_ui.xcommand(cmd)) | |
| 48 logging.debug("Running %s" % cmd) | |
| 49 test_proc = subprocess.Popen(cmd, | |
| 50 shell=True, | |
| 51 stdout=subprocess.PIPE) | |
| 52 last_suite = None | |
| 53 skipper = re.compile('YOU HAVE') | |
| 54 for line in test_proc.stdout: | |
| 55 stripped = line.lstrip() | |
| 56 if stripped == '' or skipper.match(stripped): | |
| 57 continue | |
| 58 elif (stripped == line): | |
| 59 last_suite = stripped.rstrip() | |
| 60 else: | |
| 61 all_tests.append(last_suite+stripped.rstrip()) | |
| 62 except OSError, e: | |
| 63 logging.debug(e) | |
| 64 raise error.TestFail('Failed to list tests in %s!' % test_binary) | |
| 65 return all_tests | |
| 33 | 66 |
| 34 cmd = '%s/%s %s' % (test_binary_dir, test_to_run, extra_params) | 67 |
| 68 def run_chrome_test(self, test_to_run, extra_params = ''): | |
|
ericli
2010/11/12 22:16:26
no space for cmd arg default value.
extra_params='
Chris Masone
2010/11/15 23:46:23
Done.
| |
| 69 try: | |
| 70 cmd = '%s/%s %s' % (self.test_binary_dir, test_to_run, extra_params) | |
| 35 cmd = 'HOME=%s CR_SOURCE_ROOT=%s %s' % (self.home_dir, | 71 cmd = 'HOME=%s CR_SOURCE_ROOT=%s %s' % (self.home_dir, |
| 36 cr_source_dir, | 72 self.cr_source_dir, |
| 37 site_ui.xcommand(cmd)) | 73 site_ui.xcommand(cmd)) |
| 38 logging.info("Running %s" % cmd) | |
| 39 utils.system(cmd) | 74 utils.system(cmd) |
| 40 except error.CmdError, e: | 75 except error.CmdError, e: |
| 41 logging.debug(e) | 76 logging.debug(e) |
| 42 raise error.TestFail('%s failed!' % test_to_run) | 77 raise error.TestFail('%s failed!' % test_to_run) |
| 43 | 78 |
| 44 | 79 |
| 80 def generate_test_list(self, binary, group, total_groups): | |
| 81 all_tests = self.list_chrome_tests(self.binary_to_run) | |
| 82 group_size = len(all_tests)/total_groups + 1 # to be safe | |
| 83 return all_tests[group*group_size:group*group_size+group_size] | |
| 84 | |
| 85 | |
| 45 def cleanup(self): | 86 def cleanup(self): |
| 46 if self.home_dir: | 87 if self.home_dir: |
| 47 shutil.rmtree(self.home_dir, ignore_errors=True) | 88 shutil.rmtree(self.home_dir, ignore_errors=True) |
| 48 test.test.cleanup(self) | 89 test.test.cleanup(self) |
| OLD | NEW |