Verify PEL log details

Change-Id: I653eae10350663a119a2f6776c85766c90b49ebe
Signed-off-by: Rahul Maheshwari <rahulmaheshwari@in.ibm.com>
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/data/pel_variables.py b/data/pel_variables.py
new file mode 100644
index 0000000..1a14803
--- /dev/null
+++ b/data/pel_variables.py
@@ -0,0 +1,13 @@
+#!/usr/bin/python
+
+r"""
+Contains PEL related constants.
+"""
+
+PEL_DETAILS = {
+    'CreatorID': 'BMC',
+    'CompID': '0x1000',
+    'Subsystem': 'BMC Firmware',
+    'Message': 'An application had an internal failure',
+    'SRC': 'BD8D1002',
+    'Sev': 'Unrecoverable Error'}
diff --git a/openpower/pel/test_bmc_pel.robot b/openpower/pel/test_bmc_pel.robot
index e31243f..f8d0d50 100644
--- a/openpower/pel/test_bmc_pel.robot
+++ b/openpower/pel/test_bmc_pel.robot
@@ -2,6 +2,7 @@
 Documentation   This suite tests Platform Event Log (PEL) functionality of OpenBMC.
 
 Library         ../../lib/pel_utils.py
+Variables       ../../data/pel_variables.py
 Resource        ../../lib/openbmc_ffdc.robot
 
 Test Setup      Redfish.Login
@@ -27,6 +28,55 @@
     Should Not Be Empty  ${pel_id}  msg=System PEL log entry is empty.
 
 
+Verify PEL Log Details
+    [Documentation]  Verify PEL log details via peltool.
+    [Tags]  Verify_PEL_Log_Details
+
+    Redfish Purge Event Log
+
+    ${bmc_time1}=  CLI Get BMC DateTime
+    Create Test PEL Log
+    ${bmc_time2}=  CLI Get BMC DateTime
+
+    ${pel_records}=  Peltool  -l
+
+    # Example output from 'Peltool  -l':
+    # pel_records:
+    # [0x50000012]:
+    #   [CreatorID]:                  BMC
+    #   [CompID]:                     0x1000
+    #   [PLID]:                       0x50000012
+    #   [Subsystem]:                  BMC Firmware
+    #   [Message]:                    An application had an internal failure
+    #   [SRC]:                        BD8D1002
+    #   [Commit Time]:                03/02/2020  09:35:15
+    #   [Sev]:                        Unrecoverable Error
+
+    ${ids}=  Get Dictionary Keys  ${pel_records}
+    ${id}=  Get From List  ${ids}  0
+
+    @{pel_fields}=  Create List  CreatorID  Subsystem  Message  Sev
+    FOR  ${field}  IN  @{pel_fields}
+      Valid Value  pel_records['${id}']['${field}']  ['${PEL_DETAILS['${field}']}']
+    END
+
+    Valid Value  pel_records['${id}']['PLID']  ['${id}']
+
+    # Verify if "CompID" and "SRC" fields of PEL has alphanumeric value.
+    Should Match Regexp  ${pel_records['${id}']['CompID']}  [a-zA-Z0-9]
+    Should Match Regexp  ${pel_records['${id}']['SRC']}  [a-zA-Z0-9]
+
+    ${pel_date_time}=  Convert Date  ${pel_records['${id}']['Commit Time']}
+    ...  date_format=%m/%d/%Y %H:%M:%S  exclude_millis=yes
+
+    # Convert BMC and PEL time to epoch time before comparing.
+    ${bmc_time1_epoch}=  Convert Date  ${bmc_time1}  epoch
+    ${pel_time_epoch}=  Convert Date  ${pel_date_time}  epoch
+    ${bmc_time2_epoch}=  Convert Date  ${bmc_time2}  epoch
+
+    Should Be True  ${bmc_time1_epoch} <= ${pel_time_epoch} <= ${bmc_time2_epoch}
+
+
 Verify PEL Log Persistence After BMC Reboot
     [Documentation]  Verify PEL log persistence after BMC reboot.
     [Tags]  Verify_PEL_Log_Persistence_After_BMC_Reboot