BMC boot time and count

The algorithm here to determine boot time and incrementing boot
count is simple reasoning logic. The /proc/stat btime gives the
time at which the system booted, in seconds since the Unix epoch.

By default Boot time and count is set to 0. When the first instance
of call is made to set the boot time, both the boot time and count
is updated. Subsequent calls to update is done if the global boot
time is less than the current boot time from the BMC.

Resolves openbmc/openbmc-test-automation#294

Change-Id: Iab5778af1d928ed583572b99ce2257d8df6c5238
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/lib/utils.robot b/lib/utils.robot
index c309fc0..418f2c6 100755
--- a/lib/utils.robot
+++ b/lib/utils.robot
@@ -28,6 +28,9 @@
 ${bmc_file_system_usage_cmd}=
 ...  df -h | grep -v /dev/mtdblock5 | cut -c 52-54 | grep 100 | wc -l
 
+${BOOT_TIME}     ${0}
+${BOOT_COUNT}    ${0}
+
 *** Keywords ***
 
 Wait For Host To Ping
@@ -560,3 +563,27 @@
     Write Attribute    ${HOST_SETTING}    power_policy   data=${valueDict}
     ${currentPolicy}=  Read Attribute     ${HOST_SETTING}   power_policy
     Should Be Equal    ${currentPolicy}   ${policy}
+
+
+Set BMC Reset Reference Time
+    [Documentation]  Set current boot time as a reference and increment
+    ...               boot count.
+
+    ${cur_btime}=  Get BMC Boot Time
+    Run Keyword 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.
+
+    Open Connection And Log In
+    ${output}  ${stderr}=
+    ...  Execute Command  egrep '^btime ' /proc/stat | cut -f 2 -d ' '
+    ...  return_stderr=True
+    Should Be Empty  ${stderr}
+    ${btime}=  Convert To Integer  ${output}
+    [Return]  ${btime}