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, re, shutil, stat, subprocess, tempfile | 5 import logging, os, re, shutil, stat, subprocess, tempfile |
| 6 import common | 6 import common |
| 7 import constants, cros_ui, login | 7 import constants, cros_ui, login |
| 8 from autotest_lib.client.bin import test, utils | 8 from autotest_lib.client.bin import test, utils |
| 9 from autotest_lib.client.common_lib import error, global_config | 9 from autotest_lib.client.common_lib import error, global_config |
| 10 | 10 |
| 11 class ChromeTestBase(test.test): | 11 class ChromeTestBase(test.test): |
| 12 home_dir = None | 12 home_dir = None |
| 13 chrome_restart_disabled = False | |
| 13 | 14 |
| 14 def setup(self): | 15 def setup(self): |
| 15 self.job.setup_dep(['chrome_test']) | 16 self.job.setup_dep(['chrome_test']) |
| 16 # create a empty srcdir to prevent the error that checks .version file | 17 # create a empty srcdir to prevent the error that checks .version file |
| 17 if not os.path.exists(self.srcdir): | 18 if not os.path.exists(self.srcdir): |
| 18 os.mkdir(self.srcdir) | 19 os.mkdir(self.srcdir) |
| 19 | 20 |
| 21 def nuke_chrome(self): | |
| 22 try: | |
| 23 open(constants.DISABLE_BROWSER_RESTART_MAGIC_FILE, 'w').close() | |
| 24 self.chrome_restart_disabled = True | |
| 25 except IOError, e: | |
| 26 logging.debug(e) | |
| 27 raise error.TestError('Failed to disable browser restarting.') | |
| 28 login.nuke_process_by_name(name=constants.BROWSER, with_prejudice=True) | |
| 20 | 29 |
| 21 def initialize(self): | 30 |
| 31 def initialize(self, nuke_browser_norestart = True): | |
|
Nirnimesh
2011/04/05 22:45:50
remove space around =
| |
| 22 self.home_dir = tempfile.mkdtemp() | 32 self.home_dir = tempfile.mkdtemp() |
| 23 os.chmod(self.home_dir, stat.S_IROTH | stat.S_IWOTH |stat.S_IXOTH) | 33 os.chmod(self.home_dir, stat.S_IROTH | stat.S_IWOTH |stat.S_IXOTH) |
| 24 dep = 'chrome_test' | 34 dep = 'chrome_test' |
| 25 dep_dir = os.path.join(self.autodir, 'deps', dep) | 35 dep_dir = os.path.join(self.autodir, 'deps', dep) |
| 26 self.job.install_pkg(dep, 'dep', dep_dir) | 36 self.job.install_pkg(dep, 'dep', dep_dir) |
| 27 self.cr_source_dir = '%s/test_src' % dep_dir | 37 self.cr_source_dir = '%s/test_src' % dep_dir |
| 28 self.test_binary_dir = '%s/out/Release' % self.cr_source_dir | 38 self.test_binary_dir = '%s/out/Release' % self.cr_source_dir |
| 29 try: | 39 if (nuke_browser_norestart): |
| 30 open(constants.DISABLE_BROWSER_RESTART_MAGIC_FILE, 'w').close() | 40 self.nuke_chrome() |
| 31 except IOError, e: | |
| 32 logging.debug(e) | |
| 33 raise error.TestError('Failed to disable browser restarting.') | |
| 34 login.nuke_process_by_name(name=constants.BROWSER, with_prejudice=True) | |
| 35 try: | 41 try: |
| 36 setup_cmd = '/bin/sh %s/%s' % (self.test_binary_dir, | 42 setup_cmd = '/bin/sh %s/%s' % (self.test_binary_dir, |
| 37 'setup_test_links.sh') | 43 'setup_test_links.sh') |
| 38 utils.system(setup_cmd) # this might raise an exception | 44 utils.system(setup_cmd) # this might raise an exception |
| 39 except error.CmdError, e: | 45 except error.CmdError, e: |
| 40 raise error.TestError(e) | 46 raise error.TestError(e) |
| 41 | 47 |
| 42 | 48 |
| 43 def filter_bad_tests(self, tests): | 49 def filter_bad_tests(self, tests): |
| 44 matcher = re.compile(".+\.(FLAKY|FAILS|DISABLED).+") | 50 matcher = re.compile(".+\.(FLAKY|FAILS|DISABLED).+") |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 raise error.TestFail('%s failed!' % test_to_run) | 92 raise error.TestFail('%s failed!' % test_to_run) |
| 87 | 93 |
| 88 | 94 |
| 89 def generate_test_list(self, binary, group, total_groups): | 95 def generate_test_list(self, binary, group, total_groups): |
| 90 all_tests = self.list_chrome_tests(self.binary_to_run) | 96 all_tests = self.list_chrome_tests(self.binary_to_run) |
| 91 group_size = len(all_tests)/total_groups + 1 # to be safe | 97 group_size = len(all_tests)/total_groups + 1 # to be safe |
| 92 return all_tests[group*group_size:group*group_size+group_size] | 98 return all_tests[group*group_size:group*group_size+group_size] |
| 93 | 99 |
| 94 | 100 |
| 95 def cleanup(self): | 101 def cleanup(self): |
| 96 # Allow chrome to be restarted again. | 102 if self.chrome_restart_disabled: |
| 97 os.unlink(constants.DISABLE_BROWSER_RESTART_MAGIC_FILE) | 103 # Allow chrome to be restarted again. |
| 104 os.unlink(constants.DISABLE_BROWSER_RESTART_MAGIC_FILE) | |
| 98 # Reset the UI. | 105 # Reset the UI. |
| 99 login.nuke_login_manager() | 106 login.nuke_login_manager() |
| 100 login.refresh_login_screen() | 107 login.refresh_login_screen() |
| 101 if self.home_dir: | 108 if self.home_dir: |
| 102 shutil.rmtree(self.home_dir, ignore_errors=True) | 109 shutil.rmtree(self.home_dir, ignore_errors=True) |
| 103 test.test.cleanup(self) | 110 test.test.cleanup(self) |
| OLD | NEW |