Code update reboots check

Fixes:
   - boot count set to zero in utils.robot
   - add boot count check in code update path
   - add check for kernel reboot btime persistency

Resolves openbmc/openbmc-test-automation#311

Change-Id: I35f11c28d4f162f9440ef426ee3da6c70b80985c
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/extended/code_update/update_bmc.robot b/extended/code_update/update_bmc.robot
index 205264f..40bad5b 100644
--- a/extended/code_update/update_bmc.robot
+++ b/extended/code_update/update_bmc.robot
@@ -26,10 +26,14 @@
 Resource          code_update_utils.robot
 Resource          ../../lib/boot/boot_resource_master.robot
 Resource          ../../lib/state_manager.robot
+Resource          ../../lib/utils.robot
 
 *** Variables ***
 
-${FILE_PATH}      ${EMPTY}
+${FILE_PATH}       ${EMPTY}
+
+# There are two reboots issued by code update.
+${MAX_BOOT_COUNT}  ${2}
 
 *** Test Cases ***
 
@@ -54,6 +58,7 @@
     Run Keyword if  '${status}' == '${False}'
     ...     Pass Execution   Same Driver version installed
 
+    Check Boot Count And Time
     Prune Journal Log
     Power Off Request
     Run Keyword And Ignore Error
@@ -63,6 +68,7 @@
     # Wait time is increased temporary to 10 mins due
     # to openbmc/openbmc#673
     Check If BMC is Up    10 min   10 sec
+    Check Boot Count And Time
 
     Wait For BMC Ready
 
@@ -83,6 +89,7 @@
     ...    Trigger Warm Reset via Reboot
 
     Check If BMC is Up    30 min   10 sec
+    Check Boot Count And Time
     Sleep  1 min
     Validate BMC Version
 
@@ -90,6 +97,9 @@
     # interface while checking for BMC ready state.
     Set State Interface Version
     Wait For BMC Ready
+    Check Boot Count And Time
+    Run Keyword If  ${BOOT_COUNT} == ${1}
+    ...  Log  Boot Time not Updated by Kernel!!!  level=WARN
 
 
 Test Basic BMC Performance At Ready State
@@ -100,3 +110,13 @@
     Check BMC Mem Performance
     Check BMC File System Performance
 
+*** Keywords ***
+
+Check Boot Count And Time
+    [Documentation]  Check for unexpected reboots.
+    Set BMC Reset Reference Time
+    Log To Console  \n Boot Count: ${BOOT_COUNT}
+    Log To Console  \n Boot Time: ${BOOT_TIME}
+    Run Keyword If  ${BOOT_COUNT} > ${MAX_BOOT_COUNT}
+    ...  Log  Phantom Reboot!!! Unexpected reboot detected  level=WARN
+
diff --git a/lib/utils.robot b/lib/utils.robot
index e616a7d..b012450 100755
--- a/lib/utils.robot
+++ b/lib/utils.robot
@@ -596,16 +596,16 @@
 
 Set BMC Reset Reference Time
     [Documentation]  Set current boot time as a reference and increment
-    ...               boot count.
+    ...              boot count.
 
     ${cur_btime}=  Get BMC Boot Time
-    Run Keyword If  ${cur_btime} > ${BOOT_TIME}
-    ...  Run Keywords
+    Run Keyword If  ${BOOT_TIME} == ${0} and ${BOOT_COUNT} == ${0}
     ...  Set Global Variable  ${BOOT_TIME}  ${cur_btime}
+    ...  ELSE IF  ${cur_btime} > ${BOOT_TIME}
+    ...  Run Keywords  Set Global Variable  ${BOOT_TIME}  ${cur_btime}
     ...  AND
     ...  Set Global Variable  ${BOOT_COUNT}  ${BOOT_COUNT + 1}
 
-
 Get BMC Boot Time
     [Documentation]  Get boot time from /proc/stat.