Add a test of EC dropping X86 power into G3 after S5

This test checks if EC correctly drop X86 into G3 after S5 for 10
seconds.

BUG=chrome-os-partner:10256
TEST=Test passed.

Change-Id: I1b0669219af1420c4fe7a6b4174f9337122d8740
Reviewed-on: https://gerrit.chromium.org/gerrit/25388
Reviewed-by: Tom Wai-Hong Tam <waihong@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
Commit-Ready: Vic Yang <victoryang@chromium.org>
diff --git a/server/site_tests/firmware_ECPowerG3/control b/server/site_tests/firmware_ECPowerG3/control
new file mode 100644
index 0000000..5c49958
--- /dev/null
+++ b/server/site_tests/firmware_ECPowerG3/control
@@ -0,0 +1,23 @@
+# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+AUTHOR = "Chrome OS Team"
+NAME = "firmware_ECPowerG3"
+PURPOSE = "Servo based EC X86 power G3 drop test"
+CRITERIA = "This test will fail if EC fails to drop to G3 correctly."
+TIME = "LONG"
+TEST_CATEGORY = "Functional"
+TEST_CLASS = "firmware"
+TEST_TYPE = "server"
+
+DOC = """
+This test check EC drop X86 into G3 after S5 for 10 seconds.
+"""
+
+def run_ecpowerg3(machine):
+    host = hosts.create_host(machine)
+    job.run_test("firmware_ECPowerG3", host=host, cmdline_args=args,
+                 use_faft=True, disable_sysinfo=True)
+
+parallel_simple(run_ecpowerg3, machines)
diff --git a/server/site_tests/firmware_ECPowerG3/firmware_ECPowerG3.py b/server/site_tests/firmware_ECPowerG3/firmware_ECPowerG3.py
new file mode 100644
index 0000000..4f4f1da
--- /dev/null
+++ b/server/site_tests/firmware_ECPowerG3/firmware_ECPowerG3.py
@@ -0,0 +1,47 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from autotest_lib.client.common_lib import error
+from autotest_lib.server.cros.faftsequence import FAFTSequence
+
+class firmware_ECPowerG3(FAFTSequence):
+    """
+    Servo based EC X86 power G3 drop test.
+    """
+    version = 1
+
+    # Time out range for waiting system drop into G3.
+    G3_DELAY = 13
+
+    # Record failure event
+    _failed = False
+
+    def check_G3(self):
+        """Shutdown the system and check if X86 drop into G3 correctly."""
+        self.faft_client.run_shell_command("shutdown -P now")
+        self.send_uart_command_get_output("", "x86 power state 1 = S5")
+        try:
+                self.send_uart_command_get_output("", "x86 power state 0 = G3",
+                                                   timeout=self.G3_DELAY)
+        except:
+                # Catch failure here to gracefully terminate test
+                logging.error("EC fails to drop into G3")
+                self._failed = True
+        self.servo.power_short_press()
+
+
+    def check_failure(self):
+        return not self._failed
+
+
+    def run_once(self, host=None):
+        self.register_faft_sequence((
+            {   # Step 1, power off and check if system drop into G3 correctly
+                'reboot_action': self.check_G3,
+            },
+            {   # Step 2, check if failure occurred
+                'state_checker': self.check_failure,
+            }
+        ))
+        self.run_faft_sequence()