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, re, shutil, subprocess, tempfile, utils | 5 import logging, os, re, shutil, subprocess, tempfile, utils |
6 import common | |
kmixter1
2010/12/16 03:12:57
style is to put these all on one line. Should you
ericli
2010/12/17 21:48:39
common is a very special hack by autotest design,
| |
7 import ui | |
6 from autotest_lib.client.bin import test | 8 from autotest_lib.client.bin import test |
7 from autotest_lib.client.common_lib import error, global_config, site_ui | 9 from autotest_lib.client.common_lib import error, global_config |
8 | 10 |
9 class ChromeTestBase(test.test): | 11 class ChromeTestBase(test.test): |
10 home_dir = None | 12 home_dir = None |
11 | 13 |
12 def setup(self): | 14 def setup(self): |
13 self.job.setup_dep(['chrome_test']) | 15 self.job.setup_dep(['chrome_test']) |
14 # create a empty srcdir to prevent the error that checks .version file | 16 # create a empty srcdir to prevent the error that checks .version file |
15 if not os.path.exists(self.srcdir): | 17 if not os.path.exists(self.srcdir): |
16 os.mkdir(self.srcdir) | 18 os.mkdir(self.srcdir) |
17 | 19 |
(...skipping 23 matching lines...) Expand all Loading... | |
41 return filter(lambda(x): not matcher.match(x), tests) | 43 return filter(lambda(x): not matcher.match(x), tests) |
42 | 44 |
43 | 45 |
44 def list_chrome_tests(self, test_binary): | 46 def list_chrome_tests(self, test_binary): |
45 all_tests = [] | 47 all_tests = [] |
46 try: | 48 try: |
47 cmd = '%s/%s --gtest_list_tests' % (self.test_binary_dir, | 49 cmd = '%s/%s --gtest_list_tests' % (self.test_binary_dir, |
48 test_binary) | 50 test_binary) |
49 cmd = 'HOME=%s CR_SOURCE_ROOT=%s %s' % (self.home_dir, | 51 cmd = 'HOME=%s CR_SOURCE_ROOT=%s %s' % (self.home_dir, |
50 self.cr_source_dir, | 52 self.cr_source_dir, |
51 site_ui.xcommand(cmd)) | 53 ui.xcommand(cmd)) |
52 logging.debug("Running %s" % cmd) | 54 logging.debug("Running %s" % cmd) |
53 test_proc = subprocess.Popen(cmd, | 55 test_proc = subprocess.Popen(cmd, |
54 shell=True, | 56 shell=True, |
55 stdout=subprocess.PIPE) | 57 stdout=subprocess.PIPE) |
56 last_suite = None | 58 last_suite = None |
57 skipper = re.compile('YOU HAVE') | 59 skipper = re.compile('YOU HAVE') |
58 for line in test_proc.stdout: | 60 for line in test_proc.stdout: |
59 stripped = line.lstrip() | 61 stripped = line.lstrip() |
60 if stripped == '' or skipper.match(stripped): | 62 if stripped == '' or skipper.match(stripped): |
61 continue | 63 continue |
62 elif (stripped == line): | 64 elif (stripped == line): |
63 last_suite = stripped.rstrip() | 65 last_suite = stripped.rstrip() |
64 else: | 66 else: |
65 all_tests.append(last_suite+stripped.rstrip()) | 67 all_tests.append(last_suite+stripped.rstrip()) |
66 except OSError, e: | 68 except OSError, e: |
67 logging.debug(e) | 69 logging.debug(e) |
68 raise error.TestFail('Failed to list tests in %s!' % test_binary) | 70 raise error.TestFail('Failed to list tests in %s!' % test_binary) |
69 return all_tests | 71 return all_tests |
70 | 72 |
71 | 73 |
72 def run_chrome_test(self, test_to_run, extra_params=''): | 74 def run_chrome_test(self, test_to_run, extra_params=''): |
73 try: | 75 try: |
74 cmd = '%s/%s %s' % (self.test_binary_dir, test_to_run, extra_params) | 76 cmd = '%s/%s %s' % (self.test_binary_dir, test_to_run, extra_params) |
75 cmd = 'HOME=%s CR_SOURCE_ROOT=%s %s' % (self.home_dir, | 77 cmd = 'HOME=%s CR_SOURCE_ROOT=%s %s' % (self.home_dir, |
76 self.cr_source_dir, | 78 self.cr_source_dir, |
77 site_ui.xcommand(cmd)) | 79 ui.xcommand(cmd)) |
78 utils.system(cmd) | 80 utils.system(cmd) |
79 except error.CmdError, e: | 81 except error.CmdError, e: |
80 logging.debug(e) | 82 logging.debug(e) |
81 raise error.TestFail('%s failed!' % test_to_run) | 83 raise error.TestFail('%s failed!' % test_to_run) |
82 | 84 |
83 | 85 |
84 def generate_test_list(self, binary, group, total_groups): | 86 def generate_test_list(self, binary, group, total_groups): |
85 all_tests = self.list_chrome_tests(self.binary_to_run) | 87 all_tests = self.list_chrome_tests(self.binary_to_run) |
86 group_size = len(all_tests)/total_groups + 1 # to be safe | 88 group_size = len(all_tests)/total_groups + 1 # to be safe |
87 return all_tests[group*group_size:group*group_size+group_size] | 89 return all_tests[group*group_size:group*group_size+group_size] |
88 | 90 |
89 | 91 |
90 def cleanup(self): | 92 def cleanup(self): |
91 if self.home_dir: | 93 if self.home_dir: |
92 shutil.rmtree(self.home_dir, ignore_errors=True) | 94 shutil.rmtree(self.home_dir, ignore_errors=True) |
93 test.test.cleanup(self) | 95 test.test.cleanup(self) |
OLD | NEW |