FAFT: Remove asynchronous reboot/wake calls..
The httplib that the XMLRPC module uses, does not seem to be threadsafe.
In particular, it was somewhat common for firmware_ECWakeSource to fail
with a ConnectionError raised by the httplib. This was because the wake
methods used by this test were being called asynchronously and were
causing collisions for the same HTTPConnection object. This commit
changes the tests to use synchronous calls instead.
BUG=chrome-os-partner:59753
BRANCH=None
TEST=Run firmware_ECWakeSource on sentry and verify it succeeds.
TEST=Run firmware_DevModeStress on sentry and verify it succeds.
Change-Id: I9c9abfd0bcec9e3c93a9068bc6c5b1af5fdf6274
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/419067
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Wai-Hong Tam <waihong@google.com>
diff --git a/server/cros/faft/firmware_test.py b/server/cros/faft/firmware_test.py
index 6de7843..0f43a8f 100644
--- a/server/cros/faft/firmware_test.py
+++ b/server/cros/faft/firmware_test.py
@@ -11,7 +11,6 @@
import time
import uuid
-from threading import Timer
from autotest_lib.client.bin import utils
from autotest_lib.client.common_lib import error
from autotest_lib.server import test
@@ -734,7 +733,7 @@
logging.info('Checking power state "%s" maximum %d times.',
power_state, retries)
while retries > 0:
- logging.info("try count: %d" % retries)
+ logging.info("try count: %d", retries)
try:
retries = retries - 1
ret = self._get_power_state(power_state)
@@ -743,41 +742,11 @@
pass
return False
- def delayed(seconds):
- def decorator(f):
- def wrapper(*args, **kargs):
- t = Timer(seconds, f, args, kargs)
- t.start()
- return wrapper
- return decorator
-
- @delayed(WAKE_DELAY)
- def wake_by_power_button(self):
- """Delay by WAKE_DELAY seconds and then wake DUT with power button."""
- self.servo.power_normal_press()
-
- @delayed(WAKE_DELAY)
- def wake_by_lid_switch(self):
- """Delay by WAKE_DELAY seconds and then wake DUT with lid switch."""
- self.servo.set('lid_open', 'no')
- time.sleep(self.LID_DELAY)
- self.servo.set('lid_open', 'yes')
-
- def suspend_as_reboot(self, wake_func):
- """
- Suspend DUT and also kill FAFT client so that this acts like a reboot.
-
- Args:
- wake_func: A function that is called to wake DUT. Note that this
- function must delay itself so that we don't wake DUT before
- suspend_as_reboot returns.
- """
+ def suspend(self):
+ """Suspends the DUT."""
cmd = '(sleep %d; powerd_dbus_suspend) &' % self.EC_SUSPEND_DELAY
self.faft_client.system.run_shell_command(cmd)
- self.faft_client.disconnect()
time.sleep(self.EC_SUSPEND_DELAY)
- logging.info("wake function disabled")
- wake_func()
def _fetch_servo_log(self):
"""Fetch the servo log."""
@@ -1092,13 +1061,14 @@
return ret
def run_shutdown_process(self, shutdown_action, pre_power_action=None,
- run_power_action=True, post_power_action=None, shutdown_timeout=None):
+ run_power_action=True, post_power_action=None,
+ shutdown_timeout=None):
"""Run shutdown_action(), which makes DUT shutdown, and power it on.
@param shutdown_action: function which makes DUT shutdown, like
pressing power key.
@param pre_power_action: function which is called before next power on.
- @param power_action: power_key press by default, set to None to skip.
+ @param run_power_action: power_key press by default, set to None to skip.
@param post_power_action: function which is called after next power on.
@param shutdown_timeout: a timeout to confirm DUT shutdown.
@raise TestFail: if the shutdown_action() failed to turn DUT off.
diff --git a/server/site_tests/firmware_DevModeStress/firmware_DevModeStress.py b/server/site_tests/firmware_DevModeStress/firmware_DevModeStress.py
index bc57ee4..72ef937 100644
--- a/server/site_tests/firmware_DevModeStress/firmware_DevModeStress.py
+++ b/server/site_tests/firmware_DevModeStress/firmware_DevModeStress.py
@@ -2,9 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-#from threading import Timer
import logging
-import time
from autotest_lib.client.common_lib import utils
from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
@@ -41,9 +39,10 @@
'devsw_boot': '1',
'mainfw_type': 'developer',
}))
- self.switcher.mode_aware_reboot(
- 'custom',
- lambda:self.suspend_as_reboot(self.wake_by_power_button))
+ self.suspend()
+ self.switcher.wait_for_client_offline()
+ self.servo.power_normal_press()
+ self.switcher.wait_for_client()
logging.info("Complete, final check for dev mode.")
self.check_state((self.checkers.crossystem_checker, {
diff --git a/server/site_tests/firmware_ECWakeSource/firmware_ECWakeSource.py b/server/site_tests/firmware_ECWakeSource/firmware_ECWakeSource.py
index ef094ed..658a07b 100644
--- a/server/site_tests/firmware_ECWakeSource/firmware_ECWakeSource.py
+++ b/server/site_tests/firmware_ECWakeSource/firmware_ECWakeSource.py
@@ -27,6 +27,7 @@
"""Shutdown and hibernate EC. Then wake by power button."""
self.faft_client.system.run_shell_command("shutdown -P now")
time.sleep(self.SHUTDOWN_DELAY)
+ self.switcher.wait_for_client_offline()
self.ec.send_command("hibernate 1000")
time.sleep(self.WAKE_DELAY)
self.servo.power_short_press()
@@ -37,16 +38,19 @@
raise error.TestNAError("Nothing needs to be tested on this device")
logging.info("Suspend and wake by power button.")
- self.switcher.mode_aware_reboot(
- 'custom',
- lambda:self.suspend_as_reboot(self.wake_by_power_button))
+ self.suspend()
+ self.switcher.wait_for_client_offline()
+ self.servo.power_normal_press()
+ self.switcher.wait_for_client()
logging.info("Suspend and wake by lid switch.")
- self.switcher.mode_aware_reboot(
- 'custom',
- lambda:self.suspend_as_reboot(self.wake_by_lid_switch))
+ self.suspend()
+ self.switcher.wait_for_client_offline()
+ self.servo.set('lid_open', 'no')
+ time.sleep(self.LID_DELAY)
+ self.servo.set('lid_open', 'yes')
+ self.switcher.wait_for_client()
logging.info("EC hibernate and wake by power button.")
- self.switcher.mode_aware_reboot(
- 'custom',
- lambda:self.hibernate_and_wake_by_power_button())
+ self.hibernate_and_wake_by_power_button()
+ self.switcher.wait_for_client()