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, 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 dep_dir = '/usr/local/chrome' | |
11 | 12 |
12 def setup(self): | 13 def setup(self): |
13 self.job.setup_dep(['chrome_test']) | |
ericli
2010/11/05 21:40:30
why you want to remove this? I am not sure if it w
Chris Masone
2010/11/09 23:08:24
I undid that now
| |
14 # create a empty srcdir to prevent the error that checks .version file | |
15 if not os.path.exists(self.srcdir): | 14 if not os.path.exists(self.srcdir): |
16 os.mkdir(self.srcdir) | 15 os.mkdir(self.srcdir) |
17 | 16 |
18 | 17 |
19 def run_chrome_test(self, test_to_run, extra_params = ''): | 18 def initialize(self): |
20 dep = 'chrome_test' | |
21 dep_dir = os.path.join(self.autodir, 'deps', dep) | |
22 self.job.install_pkg(dep, 'dep', dep_dir) | |
23 | |
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() | 19 self.home_dir = tempfile.mkdtemp() |
28 | 20 |
21 | |
22 def _generate_prefix(self): | |
23 chrome_dir = '/opt/google/chrome' | |
24 test_binary_dir = '%s/out/Release' % self.dep_dir | |
29 try: | 25 try: |
30 setup_cmd = '%s/%s' % (test_binary_dir, | 26 setup_cmd = '%s/%s' % (test_binary_dir, |
31 'setup_test_links.sh') | 27 'setup_test_links.sh') |
32 utils.system(setup_cmd) | 28 utils.system(setup_cmd) # this might raise an exception |
29 except error.CmdError, e: | |
30 raise error.TestError(e) | |
31 return (self.dep_dir, test_binary_dir) | |
33 | 32 |
33 | |
34 def list_chrome_tests(self, test_binary): | |
35 cr_source_dir,test_binary_dir = self._generate_prefix() | |
36 all_tests = [] | |
37 try: | |
38 cmd = '%s/%s --gtest_list_tests' % (test_binary_dir, test_binary) | |
39 cmd = 'HOME=%s CR_SOURCE_ROOT=%s %s' % (self.home_dir, | |
40 cr_source_dir, | |
41 site_ui.xcommand(cmd)) | |
42 logging.debug("Running %s" % cmd) | |
43 test_proc = subprocess.Popen(cmd, | |
44 shell=True, | |
45 stdout=subprocess.PIPE) | |
46 last_suite = None | |
47 for line in test_proc.stdout: | |
48 stripped = line.lstrip() | |
49 if (stripped == line): | |
50 last_suite = stripped.rstrip() | |
51 else: | |
52 all_tests.append(last_suite+stripped.rstrip()) | |
53 except OSError, e: | |
54 logging.debug(e) | |
55 raise error.TestFail('Failed to list tests in %s!' % test_binary) | |
56 return all_tests | |
57 | |
58 | |
59 def run_chrome_test(self, test_to_run, extra_params = ''): | |
60 cr_source_dir,test_binary_dir = self._generate_prefix() | |
61 try: | |
34 cmd = '%s/%s %s' % (test_binary_dir, test_to_run, extra_params) | 62 cmd = '%s/%s %s' % (test_binary_dir, test_to_run, extra_params) |
35 cmd = 'HOME=%s CR_SOURCE_ROOT=%s %s' % (self.home_dir, | 63 cmd = 'HOME=%s CR_SOURCE_ROOT=%s %s' % (self.home_dir, |
36 cr_source_dir, | 64 cr_source_dir, |
37 site_ui.xcommand(cmd)) | 65 site_ui.xcommand(cmd)) |
38 logging.info("Running %s" % cmd) | 66 logging.info("Running %s" % cmd) |
39 utils.system(cmd) | 67 utils.system(cmd) |
40 except error.CmdError, e: | 68 except error.CmdError, e: |
41 logging.debug(e) | 69 logging.debug(e) |
42 raise error.TestFail('%s failed!' % test_to_run) | 70 raise error.TestFail('%s failed!' % test_to_run) |
43 | 71 |
44 | 72 |
45 def cleanup(self): | 73 def cleanup(self): |
46 if self.home_dir: | 74 if self.home_dir: |
47 shutil.rmtree(self.home_dir, ignore_errors=True) | 75 shutil.rmtree(self.home_dir, ignore_errors=True) |
48 test.test.cleanup(self) | 76 test.test.cleanup(self) |
OLD | NEW |