Update SBE side switch test execution flow

Resolves  openbmc/openbmc-test-automation#1148

Change-Id: I5579124dbca9afc64f51fbb57c754abd85fb50d8
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/tests/test_sbe_side_switch.robot b/tests/test_sbe_side_switch.robot
index e501079..fd777f5 100644
--- a/tests/test_sbe_side_switch.robot
+++ b/tests/test_sbe_side_switch.robot
@@ -6,6 +6,13 @@
 Variables           ../data/variables.py
 Resource            ../lib/boot_utils.robot
 
+Test Setup          Test Setup Execution
+Test Teardown       Test Teardown Execution
+
+*** Variables ***
+
+${sbe_side_bit_mask}  ${0x00004000}
+
 *** Test Cases ***
 
 Test SBE Side Switch
@@ -13,37 +20,85 @@
     ...  switches.
     [Tags]  Test_SBE_Side_Switch
 
-    Delete All Error Logs
-    Set Auto Reboot  ${1}
     REST Power On
 
-    Start Journal Log
+    ${attempts_left}=  Read Attribute  /xyz/openbmc_project/state/host0
+    ...  AttemptsLeft
+    Should Be Equal As Strings  ${attempts_left}  3
+    ...  msg=Expects boot attempts left 3, but got ${attempts_left}.
 
-    ${attempts_left}=  Read Attribute  /xyz/openbmc_project/state/host0
-    ...  AttemptsLeft
-    Should Be Equal As Strings  ${attempts_left}  2
-    Trigger Host Watchdog Error
-    Wait For Host Reboot
-    ${attempts_left}=  Read Attribute  /xyz/openbmc_project/state/host0
-    ...  AttemptsLeft
-    Should Be Equal As Strings  ${attempts_left}  1
-    Trigger Host Watchdog Error
-    Wait For Host Reboot
-    ${attempts_left}=  Read Attribute  /xyz/openbmc_project/state/host0
-    ...  AttemptsLeft
-    Should Be Equal As Strings  ${attempts_left}  0
+    # Get which side the SBE is booted with. By default 0.
+    ${sbe_val} =  Get SBE
+    ${sbe_cur_side} =  Evaluate  ${sbe_side_bit_mask} & ${sbe_val}
 
-    # Verify the side switched
-    ${journal_text}=  Stop Journal Log
-    Should Contain  ${journal_text}  Setting SBE seeprom side to 1
+    Trigger Watchdog Error To Switch SBE Boot Side
+
+    # Next Power on check if host booting is in progress.
+    Wait Until Keyword Succeeds  2 min  30 sec  Watchdog Object Should Exist
+
+    # Verify that the side has switched.
+    ${sbe_val} =  Get SBE
+    ${sbe_orig_side} =  Evaluate  ${sbe_side_bit_mask} & ${sbe_val}
+
+    Run Keyword If  ${sbe_orig_side} == ${0}
+    ...      Should Be True  ${sbe_cur_side} == ${sbe_side_bit_mask}
+    ...      msg=SBE seeprom side is 1.
+    ...  ELSE
+    ...      Should Be True  ${sbe_cur_side} == ${0}
+    ...      msg=SBE seeprom side is 0.
+
+    # Verify that host booted on the current SBE side.
+    Wait Until Keyword Succeeds  10 min  10 sec  Is Host Running
 
 
 *** Keywords ***
 
-Wait For Host Reboot
-    [Documentation]  Wait for the host to reboot.
+Test Setup Execution
+    [Documentation]  Do the test setup execution.
 
-    ${match_state}=  Create Dictionary  host=^Off$
-    Wait State  ${match_state}  wait_time=5 min
-    ${match_state}=  Create Dictionary  host=^Running$
-    Wait State  ${match_state}  wait_time=5 min
+    Delete All Error Logs
+    Set Auto Reboot  ${1}
+    Smart Power Off
+
+
+Test Teardown Execution
+    [Documentation]  Do the test teardown execution.
+    FFDC On Test Case Fail
+    Smart Power Off
+
+
+Watchdog Object Should Exist
+    [Documentation]  Watchdog object should exist.
+
+    ${resp}=  OpenBMC Get Request  ${WATCHDOG_URI}  quiet=${1}
+    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
+    ...  msg=Failed to get ${WATCHDOC_URI}, response = ${resp.status_code}.
+
+
+Trigger Watchdog Error To Switch SBE Boot Side
+    [Documentation]  Trigger watchdog error to force SBE boot side switch.
+
+    # 20 second wait is introduced to ensure host boot progress at least
+    # crossed the initial istep booting sequence.
+
+    Trigger Host Watchdog Error
+    ${attempts_left}=  Read Attribute  /xyz/openbmc_project/state/host0
+    ...  AttemptsLeft
+    Should Be Equal As Strings  ${attempts_left}  2
+    ...  msg=Expects boot attempts left 2, but got ${attempts_left}.
+
+    Wait Until Keyword Succeeds  2 min  30 sec  Watchdog Object Should Exist
+    Sleep  20 s
+    Trigger Host Watchdog Error
+    ${attempts_left}=  Read Attribute  /xyz/openbmc_project/state/host0
+    ...  AttemptsLeft
+    Should Be Equal As Strings  ${attempts_left}  1
+    ...  msg=Expects boot attempts left 1, but got ${attempts_left}.
+
+    Wait Until Keyword Succeeds  2 min  30 sec  Watchdog Object Should Exist
+    Sleep  20 s
+    Trigger Host Watchdog Error
+    ${attempts_left}=  Read Attribute  /xyz/openbmc_project/state/host0
+    ...  AttemptsLeft
+    Should Be Equal As Strings  ${attempts_left}  0
+    ...  msg=Expects boot attempts left 0, but got ${attempts_left}.