1*** Settings ***
2Documentation   This suite tests Platform Event Log (PEL) functionality of OpenBMC.
3
4Library         ../../lib/pel_utils.py
5Variables       ../../data/pel_variables.py
6Resource        ../../lib/list_utils.robot
7Resource        ../../lib/openbmc_ffdc.robot
8
9Test Setup      Redfish.Login
10Test Teardown   Run Keywords  Redfish.Logout  AND  FFDC On Test Case Fail
11
12
13*** Variables ***
14
15${CMD_INTERNAL_FAILURE}  busctl call xyz.openbmc_project.Logging /xyz/openbmc_project/logging
16...  xyz.openbmc_project.Logging.Create Create ssa{ss} xyz.openbmc_project.Common.Error.InternalFailure
17...  xyz.openbmc_project.Logging.Entry.Level.Error 0
18
19
20*** Test Cases ***
21
22Create Test PEL Log And Verify
23    [Documentation]  Create PEL log using busctl command and verify via peltool.
24    [Tags]  Create_Test_PEL_Log_And_Verify
25
26    Redfish Purge Event Log
27    Create Test PEL Log
28    ${pel_id}=  Get PEL Log Via BMC CLI
29    Should Not Be Empty  ${pel_id}  msg=System PEL log entry is empty.
30
31
32Verify PEL Log Details
33    [Documentation]  Verify PEL log details via peltool.
34    [Tags]  Verify_PEL_Log_Details
35
36    Redfish Purge Event Log
37
38    ${bmc_time1}=  CLI Get BMC DateTime
39    Create Test PEL Log
40    ${bmc_time2}=  CLI Get BMC DateTime
41
42    ${pel_records}=  Peltool  -l
43
44    # Example output from 'Peltool  -l':
45    # pel_records:
46    # [0x50000012]:
47    #   [CreatorID]:                  BMC
48    #   [CompID]:                     0x1000
49    #   [PLID]:                       0x50000012
50    #   [Subsystem]:                  BMC Firmware
51    #   [Message]:                    An application had an internal failure
52    #   [SRC]:                        BD8D1002
53    #   [Commit Time]:                03/02/2020  09:35:15
54    #   [Sev]:                        Unrecoverable Error
55
56    ${ids}=  Get Dictionary Keys  ${pel_records}
57    ${id}=  Get From List  ${ids}  0
58
59    @{pel_fields}=  Create List  CreatorID  Subsystem  Message  Sev
60    FOR  ${field}  IN  @{pel_fields}
61      Valid Value  pel_records['${id}']['${field}']  ['${PEL_DETAILS['${field}']}']
62    END
63
64    Valid Value  pel_records['${id}']['PLID']  ['${id}']
65
66    # Verify if "CompID" and "SRC" fields of PEL has alphanumeric value.
67    Should Match Regexp  ${pel_records['${id}']['CompID']}  [a-zA-Z0-9]
68    Should Match Regexp  ${pel_records['${id}']['SRC']}  [a-zA-Z0-9]
69
70    ${pel_date_time}=  Convert Date  ${pel_records['${id}']['Commit Time']}
71    ...  date_format=%m/%d/%Y %H:%M:%S  exclude_millis=yes
72
73    # Convert BMC and PEL time to epoch time before comparing.
74    ${bmc_time1_epoch}=  Convert Date  ${bmc_time1}  epoch
75    ${pel_time_epoch}=  Convert Date  ${pel_date_time}  epoch
76    ${bmc_time2_epoch}=  Convert Date  ${bmc_time2}  epoch
77
78    Should Be True  ${bmc_time1_epoch} <= ${pel_time_epoch} <= ${bmc_time2_epoch}
79
80
81Verify PEL Log Persistence After BMC Reboot
82    [Documentation]  Verify PEL log persistence after BMC reboot.
83    [Tags]  Verify_PEL_Log_Persistence_After_BMC_Reboot
84
85    Create Test PEL Log
86    ${pel_before_reboot}=  Get PEL Log Via BMC CLI
87
88    Redfish OBMC Reboot (off)
89    ${pel_after_reboot}=  Get PEL Log Via BMC CLI
90
91    List Should Contain Sub List  ${pel_after_reboot}  ${pel_before_reboot}
92
93
94Verify PEL ID Numbering
95    [Documentation]  Verify PEL ID numbering.
96    [Tags]  Verify_PEL_ID_Numbering
97
98    Redfish Purge Event Log
99    Create Test PEL Log
100    Create Test PEL Log
101
102    ${pel_ids}=  Get PEL Log Via BMC CLI
103
104    # Example of PEL IDs from PEL logs.
105    #  [0x50000012]:             <--- First PEL ID
106    #    [CreatorID]:                  BMC
107    #    [CompID]:                     0x1000
108    #    [PLID]:                       0x50000012
109    #    [Subsystem]:                  BMC Firmware
110    #    [Message]:                    An application had an internal failure
111    #    [SRC]:                        BD8D1002
112    #    [Commit Time]:                03/02/2020  09:35:15
113    #    [Sev]:                        Unrecoverable Error
114    #
115    #  [0x50000013]:             <--- Second PEL ID
116    #    [CreatorID]:                  BMC
117    #    [CompID]:                     0x1000
118    #    [PLID]:                       0x50000013
119    #    [Subsystem]:                  BMC Firmware
120    #    [Message]:                    An application had an internal failure
121    #    [SRC]:                        BD8D1002
122    #    [Commit Time]:                03/02/2020  09:35:15
123    #    [Sev]:                        Unrecoverable Error
124
125    Should Be True  ${pel_ids[1]} == ${pel_ids[0]}+1
126
127Verify Machine Type Model And Serial Number
128    [Documentation]  Verify machine type model and serial number from PEL.
129    [Tags]  Verify_Machine_Type_Model_And_Serial_Number
130
131    Create Test PEL Log
132
133    ${pel_ids}=  Get PEL Log Via BMC CLI
134    ${id}=  Get From List  ${pel_ids}  -1
135    ${pel_serial_number}=  Get PEL Field Value  ${id}  Failing MTMS  Serial Number
136    ${pel_machine_type_model}=  Get PEL Field Value  ${id}  Failing MTMS  Machine Type Model
137
138    # Example of "Machine Type Model" and "Serial Number" fields value from "Failing MTMS" section of PEL.
139    #  [Failing MTMS]:
140    #    [Created by]:                                 0x2000
141    #    [Machine Type Model]:                         1234-ABC   <---- Machine type
142    #    [Section Version]:                            1
143    #    [Serial Number]:                              ABCDEFG    <---- Serial number
144    #    [Sub-section type]:                           0
145
146    ${redfish_machine_model}=  Redfish.Get Attribute  /redfish/v1/Systems/system/  Model
147    ${redfish_serial_number}=  Redfish.Get Attribute  /redfish/v1/Systems/system/  SerialNumber
148
149    Valid Value  pel_machine_type_model  ['${redfish_machine_model}']
150    Valid Value  pel_serial_number  ['${redfish_serial_number}']
151
152    # Check "Machine Type Model" and "Serial Number" fields value from "Extended User Header" section of PEL.
153    ${pel_machine_type_model}=  Get PEL Field Value  ${id}  Extended User Header  Reporting Machine Type
154    ${pel_serial_number}=  Get PEL Field Value  ${id}  Extended User Header  Reporting Serial Number
155
156    Valid Value  pel_machine_type_model  ['${redfish_machine_model}']
157    Valid Value  pel_serial_number  ['${redfish_serial_number}']
158
159
160Verify Host Off State From PEL
161    [Documentation]  Verify Host off state from PEL.
162    [Tags]  Verify_Host_Off_State_From_PEL
163
164    Redfish Power Off  stack_mode=skip
165    Create Test PEL Log
166
167    ${pel_ids}=  Get PEL Log Via BMC CLI
168    ${id}=  Get From List  ${pel_ids}  -1
169    ${pel_host_state}=  Get PEL Field Value  ${id}  User Data  HostState
170
171    Valid Value  pel_host_state  ['Off']
172
173
174Verify BMC Version From PEL
175    [Documentation]  Verify BMC Version from PEL.
176    [Tags]  Verify_BMC_Version_From_PEL
177
178    Create Test PEL Log
179
180    ${pel_ids}=  Get PEL Log Via BMC CLI
181    ${id}=  Get From List  ${pel_ids}  -1
182    ${pel_bmc_version}=  Get PEL Field Value  ${id}  User Data  BMC Version ID
183
184    ${bmc_version}=  Get BMC Version
185    Valid Value  bmc_version  ['${bmc_version}']
186
187
188Verify PEL Log After Host Poweron
189    [Documentation]  Verify PEL log generation while booting host.
190    [Tags]  Verify_PEL_Log_After_Host_Poweron
191
192    Redfish Power Off  stack_mode=skip
193    Redfish Purge Event Log
194    Redfish Power On  stack_mode=skip
195
196    ${pel_informational_error}=  Get PEL Log IDs  User Header  Event Severity  Informational Event
197    ${pel_bmc_created_error}=  Get PEL Log IDs  Private Header  Creator Subsystem  BMC
198
199    # Get BMC created non-infomational error.
200    ${pel_bmc_error}=  Subtract Lists  ${pel_bmc_created_error}  ${pel_informational_error}
201
202    Should Be Empty  ${pel_bmc_error}  msg=Unexpected error log generated during Host poweron.
203
204
205Verify BMC Event Log ID
206    [Documentation]  Verify BMC Event Log ID from PEL.
207    [Tags]  Verify_BMC_Event_Log_ID
208
209    Redfish Purge Event Log
210    Create Test PEL Log
211
212    ${pel_ids}=  Get PEL Log Via BMC CLI
213    ${pel_bmc_event_log_id}=  Get PEL Field Value  ${pel_ids[0]}  Private Header  BMC Event Log Id
214
215    # Example "BMC Event Log Id" field value from "Private Header" section of PEL.
216    #  [Private Header]:
217    #    [Created at]:                 08/24/1928 12:04:06
218    #    [Created by]:                 0x584D
219    #    [Sub-section type]:           0
220    #    [Entry Id]:                   0x50000BB7
221    #    [Platform Log Id]:            0x8200061D
222    #    [CSSVER]:
223    #    [Section Version]:            1
224    #    [Creator Subsystem]:          PHYP
225    #    [BMC Event Log Id]:           341      <---- BMC event log id value
226    #    [Committed at]:               03/25/1920 12:06:22
227
228    ${redfish_event_logs}=  Redfish.Get Properties  /redfish/v1/Systems/system/LogServices/EventLog/Entries
229
230    # Example of redfish_event_logs output:
231    # redfish_event_logs:
232    #  [@odata.id]:                    /redfish/v1/Systems/system/LogServices/EventLog/Entries
233    #  [Name]:                         System Event Log Entries
234    #  [Members@odata.count]:          1
235    #  [@odata.type]:                  #LogEntryCollection.LogEntryCollection
236    #  [Description]:                  Collection of System Event Log Entries
237    #  [Members]:
238    #    [0]:
239    #      [@odata.id]:                /redfish/v1/Systems/system/LogServices/EventLog/Entries/235
240    #      [Name]:                     System Event Log Entry
241    #      [Severity]:                 Critical
242    #      [EntryType]:                Event
243    #      [Created]:                  2020-04-02T07:25:13+00:00
244    #      [@odata.type]:              #LogEntry.v1_5_1.LogEntry
245    #      [Id]:                       235          <----- Event log ID
246    #      [Message]:                  xyz.openbmc_project.Common.Error.InternalFailure
247
248    Valid Value  pel_bmc_event_log_id  ['${redfish_event_logs['Members'][0]['Id']}']
249
250
251Verify Delete All PEL
252    [Documentation]  Verify deleting all PEL logs.
253    [Tags]  Verify_Delete_All_PEL
254
255    Create Test PEL Log
256    Create Test PEL Log
257    Peltool  --delete-all  False
258
259    ${pel_ids}=  Get PEL Log Via BMC CLI
260    Should Be Empty  ${pel_ids}
261
262
263*** Keywords ***
264
265Create Test PEL Log
266    [Documentation]  Generate test PEL log.
267
268    # Test PEL log entry example:
269    # {
270    #    "0x5000002D": {
271    #            "SRC": "BD8D1002",
272    #            "Message": "An application had an internal failure",
273    #            "PLID": "0x5000002D",
274    #            "CreatorID": "BMC",
275    #            "Subsystem": "BMC Firmware",
276    #            "Commit Time": "02/25/2020  04:47:09",
277    #            "Sev": "Unrecoverable Error",
278    #            "CompID": "0x1000"
279    #    }
280    # }
281
282    BMC Execute Command  ${CMD_INTERNAL_FAILURE}
283
284
285Get PEL Log IDs
286    [Documentation]  Returns the list of PEL log IDs which contains given field's value.
287    [Arguments]  ${pel_section}  ${pel_field}  @{pel_field_value}
288
289    # Description of argument(s):
290    # pel_section      The section of PEL (e.g. Private Header, User Header).
291    # pel_field        The PEL field (e.g. Event Severity, Event Type).
292    # pel_field_value  The list of PEL's field value (e.g. Unrecoverable Error).
293
294    ${pel_ids}=  Get PEL Log Via BMC CLI
295    @{pel_id_list}=  Create List
296
297    FOR  ${id}  IN  @{pel_ids}
298      ${pel_output}=  Peltool  -i ${id}
299      # Example of PEL output from "peltool -i <id>" command.
300      #  [Private Header]:
301      #    [Created at]:                                 08/24/1928 12:04:06
302      #    [Created by]:                                 0x584D
303      #    [Sub-section type]:                           0
304      #    [Entry Id]:                                   0x50000BB7
305      #    [Platform Log Id]:                            0x8200061D
306      #    [CSSVER]:
307      #    [Section Version]:                            1
308      #    [Creator Subsystem]:                          PHYP
309      #    [BMC Event Log Id]:                           341
310      #    [Committed at]:                               03/25/1920 12:06:22
311      #  [User Header]:
312      #    [Log Committed by]:                           0x4552
313      #    [Action Flags]:
314      #      [0]:                                        Report Externally
315      #    [Subsystem]:                                  I/O Subsystem
316      #    [Event Type]:                                 Miscellaneous, Informational Only
317      #    [Sub-section type]:                           0
318      #    [Event Scope]:                                Entire Platform
319      #    [Event Severity]:                             Informational Event
320      #    [Host Transmission]:                          Not Sent
321      #    [Section Version]:                            1
322
323      ${pel_section_output}=  Get From Dictionary  ${pel_output}  ${pel_section}
324      ${pel_field_output}=  Get From Dictionary  ${pel_section_output}  ${pel_field}
325      Run Keyword If  '${pel_field_output}' in @{pel_field_value}  Append To List  ${pel_id_list}  ${id}
326    END
327    Sort List  ${pel_id_list}
328
329    [Return]  ${pel_id_list}
330
331
332Get PEL Log Via BMC CLI
333    [Documentation]  Returns the list of PEL IDs using BMC CLI.
334
335    ${pel_records}=  Peltool  -l
336    ${ids}=  Get Dictionary Keys  ${pel_records}
337    Sort List  ${ids}
338
339    [Return]  ${ids}
340
341
342Get PEL Field Value
343    [Documentation]  Returns the value of given PEL's field.
344    [Arguments]  ${pel_id}  ${pel_section}  ${pel_field}
345
346    # Description of argument(s):
347    # pel_id           The ID of PEL (e.g. 0x5000002D, 0x5000002E).
348    # pel_section      The section of PEL (e.g. Private Header, User Header)
349    # pel_field        The PEL field (e.g. Event Severity, Event Type).
350
351    ${pel_output}=  Peltool  -i ${pel_id}
352
353    # Example of PEL output from "peltool -i <id>" command.
354    #  [Private Header]:
355    #    [Created at]:                                 08/24/1928 12:04:06
356    #    [Created by]:                                 0x584D
357    #    [Sub-section type]:                           0
358    #    [Entry Id]:                                   0x50000BB7
359    #    [Platform Log Id]:                            0x8200061D
360    #    [CSSVER]:
361    #    [Section Version]:                            1
362    #    [Creator Subsystem]:                          PHYP
363    #    [BMC Event Log Id]:                           341
364    #    [Committed at]:                               03/25/1920 12:06:22
365    #  [User Header]:
366    #    [Log Committed by]:                           0x4552
367    #    [Action Flags]:
368    #      [0]:                                        Report Externally
369    #    [Subsystem]:                                  I/O Subsystem
370    #    [Event Type]:                                 Miscellaneous, Informational Only
371    #    [Sub-section type]:                           0
372    #    [Event Scope]:                                Entire Platform
373    #    [Event Severity]:                             Informational Event
374    #    [Host Transmission]:                          Not Sent
375    #    [Section Version]:                            1
376
377    ${pel_section_output}=  Get From Dictionary  ${pel_output}  ${pel_section}
378    ${pel_field_output}=  Get From Dictionary  ${pel_section_output}  ${pel_field}
379
380    [Return]  ${pel_field_output}
381