firmware_ECWakeSource: Wait for G3 state when hibernating

Method run_shutdown_cmd() sends 'shutdown' command to DUT and
waits until DUT goes offline. Actually not responding for a ping
doesn't mean DUT is powered off.

This was found by running ECWakeSource test against EC ToT on casta.
Power button was pressed when DUT was in S0 state, so test was
unable to wake up DUT.

This was working before, because after sending shutdown command test was
issuing 'hibernate 1000' on EC console. Hibernating EC causes
chipset_force_shutdown() to be called if chipset is not in shutdown
state. Starting from CL:2442037 PSL hibernating with timeout is disabled
for NPCX.

Above situation was fixed by checking if 'shutdown' command sent to DUT
actually causes power state change to G3 (though EC hibernating needs to
be fixed too).

BUG=b:161775827
BRANCH=none
TEST=Flash EC ToT on Casta. Run ECWakeSource test. Make sure that power
     button is pressed after DUT enters G3 state.

Change-Id: I5f578acf042bce28cb34a86e1de4921230943f4d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/2582039
Tested-by: Patryk Duda <pdk@semihalf.com>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
diff --git a/server/site_tests/firmware_ECWakeSource/firmware_ECWakeSource.py b/server/site_tests/firmware_ECWakeSource/firmware_ECWakeSource.py
index 145e312..cd804d1 100644
--- a/server/site_tests/firmware_ECWakeSource/firmware_ECWakeSource.py
+++ b/server/site_tests/firmware_ECWakeSource/firmware_ECWakeSource.py
@@ -44,6 +44,10 @@
         """Shutdown to G3/S5, hibernate EC, and then wake by power button."""
         is_ac = host.is_ac_connected()
         self.run_shutdown_cmd()
+        if not self.wait_power_state(self.POWER_STATE_G3,
+                                     self.POWER_STATE_RETRY_COUNT):
+            raise error.TestFail('Platform failed to reach G3 state.')
+
         self.ec.send_command('hibernate 1000')
         time.sleep(self.WAKE_DELAY)