| 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 common, fnmatch, logging, os, re, string, threading, time | 5 import common, fnmatch, logging, os, re, string, threading, time |
| 6 | 6 |
| 7 from autotest_lib.server import autotest, hosts, subcommand | 7 from autotest_lib.server import autotest, hosts, subcommand |
| 8 from autotest_lib.server import site_bsd_router | 8 from autotest_lib.server import site_bsd_router |
| 9 from autotest_lib.server import site_linux_router | 9 from autotest_lib.server import site_linux_router |
| 10 from autotest_lib.server import site_host_attributes | 10 from autotest_lib.server import site_host_attributes |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 def client_netdump_stop(self, params): | 744 def client_netdump_stop(self, params): |
| 745 if self.client_netdump_thread is not None: | 745 if self.client_netdump_thread is not None: |
| 746 self.__destroy_netdump_dev() | 746 self.__destroy_netdump_dev() |
| 747 self.client.run("pkill %s" % self.client_cmd_netdump) | 747 self.client.run("pkill %s" % self.client_cmd_netdump) |
| 748 self.client.get_file(self.client_netdump_file, '.') | 748 self.client.get_file(self.client_netdump_file, '.') |
| 749 self.client.delete_tmp_dir(self.client_netdump_dir) | 749 self.client.delete_tmp_dir(self.client_netdump_dir) |
| 750 self.client_netdump_thread.join() | 750 self.client_netdump_thread.join() |
| 751 self.client_netdump_thread = None | 751 self.client_netdump_thread = None |
| 752 | 752 |
| 753 | 753 |
| 754 def client_suspend(self, params): |
| 755 """ Suspend the system """ |
| 756 |
| 757 script_client_file = self.install_script('site_system_suspend.py', |
| 758 '../client/common_lib/rtc.py', |
| 759 '../client/common_lib/' |
| 760 'sys_power.py') |
| 761 result = self.client.run('python "%s" %d' % |
| 762 (script_client_file, int(params.get("suspend_time", 5)))) |
| 763 |
| 764 |
| 765 def client_suspend_bg(self, params): |
| 766 """ Suspend the system in the background """ |
| 767 |
| 768 script_client_file = self.install_script('site_system_suspend.py', |
| 769 '../client/common_lib/rtc.py', |
| 770 '../client/common_lib/' |
| 771 'sys_power.py') |
| 772 cmd = ('python "%s" %d' % |
| 773 (script_client_file, int(params.get("suspend_time", 5)))) |
| 774 self.client_suspend_thread = HelperThread(self.client, cmd) |
| 775 self.client_suspend_thread.start() |
| 776 |
| 777 |
| 778 def client_suspend_end(self, params): |
| 779 """ Join the backgrounded suspend thread """ |
| 780 |
| 781 self.client_suspend_thread.join() |
| 782 if self.client_suspend_thread.result.exit_status: |
| 783 raise error.TestError('suspend failed') |
| 784 |
| 754 class HelperThread(threading.Thread): | 785 class HelperThread(threading.Thread): |
| 755 # Class that wraps a ping command in a thread so it can run in the bg. | 786 # Class that wraps a ping command in a thread so it can run in the bg. |
| 756 def __init__(self, client, cmd): | 787 def __init__(self, client, cmd): |
| 757 threading.Thread.__init__(self) | 788 threading.Thread.__init__(self) |
| 758 self.client = client | 789 self.client = client |
| 759 self.cmd = cmd | 790 self.cmd = cmd |
| 760 | 791 |
| 761 def run(self): | 792 def run(self): |
| 762 # NB: set ignore_status as we're always terminated w/ pkill | 793 # NB: set ignore_status as we're always terminated w/ pkill |
| 763 self.client.run(self.cmd, ignore_status=True) | 794 self.result = self.client.run(self.cmd, ignore_status=True) |
| 764 | |
| 765 | 795 |
| 766 def __byfile(a, b): | 796 def __byfile(a, b): |
| 767 if a['file'] < b['file']: | 797 if a['file'] < b['file']: |
| 768 return -1 | 798 return -1 |
| 769 elif a['file'] > b['file']: | 799 elif a['file'] > b['file']: |
| 770 return 1 | 800 return 1 |
| 771 else: | 801 else: |
| 772 return 0 | 802 return 0 |
| 773 | 803 |
| 774 | 804 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 except error.TestFail: | 909 except error.TestFail: |
| 880 if 'expect_failure' in testcase: | 910 if 'expect_failure' in testcase: |
| 881 self.expect_failure(name, testcase['expect_failure']) | 911 self.expect_failure(name, testcase['expect_failure']) |
| 882 else: | 912 else: |
| 883 raise | 913 raise |
| 884 except Exception, e: | 914 except Exception, e: |
| 885 if 'expect_failure' in testcase: | 915 if 'expect_failure' in testcase: |
| 886 self.expect_failure(name, testcase['expect_failure']) | 916 self.expect_failure(name, testcase['expect_failure']) |
| 887 else: | 917 else: |
| 888 raise error.TestFail(e) | 918 raise error.TestFail(e) |
| OLD | NEW |