1*** Settings ***
2
3Documentation    Module to test IPMI SEL functionality.
4Resource         ../lib/ipmi_client.robot
5Resource         ../lib/openbmc_ffdc.robot
6Library          ../lib/ipmi_utils.py
7Variables        ../data/ipmi_raw_cmd_table.py
8
9Test Setup       Test Setup Execution
10Test Teardown    FFDC On Test Case Fail
11
12Force Tags       IPMI_SEL
13
14*** Variables ***
15
16# Based on 13th byte of add SEL entry command as per IPMI spec
17# event_dir and event_type variable value needs to be given.
18${sel_no_entry_msg}  SEL has no entries
19${event_type}        Lower Non-critical going low
20${event_dir}         Asserted
21
22*** Test Cases ***
23
24Verify IPMI SEL Version
25    [Documentation]  Verify IPMI SEL's version info.
26    [Tags]  Verify_IPMI_SEL_Version
27    ${version_info}=  Get IPMI SEL Setting  Version
28    ${setting_status}=  Fetch From Left  ${version_info}  (
29    ${setting_status}=  Evaluate  $setting_status.replace(' ','')
30
31    Should Be True  ${setting_status} >= 1.5
32    Should Contain  ${version_info}  v2 compliant  case_insensitive=True
33
34
35Verify Empty SEL
36    [Documentation]  Verify IPMI sel clear command clears the SEL entry.
37    [Tags]  Verify_Empty_SEL
38
39    Redfish Power Off  stack_mode=skip
40
41    # Generate an error log and verify there is one at least.
42    Create Test PEL Log
43    ${resp}=  Run IPMI Standard Command  sel elist last 1
44    Log To Console  ${resp}
45
46    Should Contain Any  ${resp}  system hardware failure   Asserted
47    ...  msg=Add SEL Entry failed.
48
49    # Send SEL clear command and verify if it really clears up the SEL entry.
50    Run IPMI Standard Command  sel clear
51    Sleep  5s
52
53    ${resp}=  Run IPMI Standard Command  sel list
54    Should Contain  ${resp}  SEL has no entries  case_insensitive=True
55
56
57Verify Add SEL Entry
58    [Documentation]  Verify add SEL entry.
59    [Tags]  Verify_Add_SEL_Entry
60    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND  Run IPMI Standard Command  sel clear
61
62    # The IPMI raw command to generate Temp sensor  error is no longer working.
63    # Our aim is to check if the SEL command is listed in IPMI or not.
64    # Original keyword "Create User Defined SEL" for reference
65    Create Test PEL Log
66
67    # Get last SEL entry.
68    ${resp}=  Run IPMI Standard Command  sel elist last 1
69    #  output:
70    #  1 | 11/17/2021 | 07:49:20 | System Event #0x01 | Undetermined system hardware failure | Asserted
71    Run Keywords  Should Contain  ${resp}  system hardware failure  AND
72    ...  Should Contain  ${resp}  Asserted  msg=Add SEL Entry failed.
73
74
75Verify Add SEL Entry For Any Random Sensor
76    [Documentation]  Create SEL entry and verify for any given random sensor.
77    [Tags]  Verify_Add_SEL_Entry_For_Any_Random_Sensor
78    [Teardown]  Run Keywords  FFDC On Test Case Fail  AND  Run IPMI Standard Command  sel clear
79
80    # Get any sensor available from sensor list.
81    ${sensor_name}=  Fetch One Threshold Sensor From Sensor List
82
83    # Get Sensor ID from SDR get "sensor".
84    ${sensor_data1}=  Fetch Sensor Details From SDR  ${sensor_name}  Sensor ID
85    ${sensor_number}=  Get Bytes From SDR Sensor  ${sensor_data1}
86
87    # Get Sensor Type from SDR get "sensor".
88    ${sensor_data2}=  Fetch Sensor Details From SDR  ${sensor_name}  Sensor Type (Threshold)
89    ${sensor_type_id}=  Get Bytes From SDR Sensor  ${sensor_data2}
90
91    # Add SEL Entry.
92    # ${sel_entry_id} is the Record ID for added record (LSB First).
93    ${sel_create_resp}=  Create SEL  ${sensor_type_id}  ${sensor_number}
94    ${sel_entry_id}=  Split String  ${sel_create_resp}
95
96    # Get last SEL entry.
97    ${resp}=  Run IPMI Standard Command  sel elist
98    Should Not Contain  ${resp}  ${sel_no_entry_msg}
99
100    # Output of the Sel elist.
101    # Below example is a continuous line statement.
102    #    N | MM/DD/YYYY | HH:MM:SS | Sensor_Type Sensor_Name |
103    #    Lower Non-critical going low  | Asserted | Reading 0.
104
105    ${get_sel_entry}=  Get Lines Containing String  ${resp}  ${sensor_name}
106    ${sel_entry}=  Get Lines Containing String  ${get_sel_entry}  ${event_type}
107    Should Contain  ${sel_entry}  ${event_dir}  msg=Add SEL Entry failed.
108
109    # Get SEL Entry IPMI Raw Command.
110    ${entry}=  Get SEL Entry Via IPMI  ${sel_entry_id[0]}  ${sel_entry_id[1]}
111
112    # Compare SEL Record ID.
113    ${sel_record_id}=  Set Variable  ${entry[2:4]}
114    Should Be Equal  ${sel_record_id}  ${sel_entry_id}
115
116    # Sensor type compare.
117    Should Be Equal  ${sensor_type_id}  ${entry[12]}
118
119    # Sensor number compare.
120    Should Be Equal  ${sensor_number}  ${entry[13]}
121
122
123Verify Reserve SEL
124    [Documentation]  Verify reserve SEL.
125    [Tags]  Verify_Reserve_SEL
126
127    ${resp}=  Run IPMI Command
128    ...  ${IPMI_RAW_CMD['SEL_entry']['Reserve'][0]}
129    ${reserve_id}=  Split String  ${resp}
130
131    # Execute clear SEL raw command with Reservation ID.
132    # Command will not execute unless the correct Reservation ID value is provided.
133    Run IPMI Command
134    ...  0x0a 0x47 0x${reserve_id[0]} 0x${reserve_id[1]} 0x43 0x4c 0x52 0xaa
135
136    # Check SEL list.
137    ${resp}=  Run IPMI Standard Command  sel list
138    Should Contain  ${resp}  SEL has no entries  case_insensitive=True
139
140
141Verify IPMI SEL Most Recent Addition Timestamp
142    [Documentation]  Verify most recent addition timestamp in SEL info.
143    [Tags]  Verify_IPMI_SEL_Most_Recent_Addition_Timestamp
144
145    # Get Most Recent Addition Timestamp from SEL Info.
146    ${addition_timestamp}=  Get Most Recent Addition Timestamp From SEL Info
147
148    IF  '${addition_timestamp}' != 'ffffffff'
149        # Convert to epoch timestamp.
150        ${epoch_addition}=  Convert To Integer  ${addition_timestamp}  16
151
152        # Get SEL List last 1 entry date and time and convert to epoch timestamp.
153        ${sel_epoch_time}=  Get SEL Elist Last Entry Date In Epoch
154
155        # Compare epoch of sel entry timestamp and last addition timestamp.
156        ${diff}=  Evaluate  int(${sel_epoch_time}) - int(${epoch_addition})
157        Should Be True  ${diff}<=600
158
159    ELSE
160        # Get any Sensor available from Sensor list
161        ${sensor_name}=  Fetch One Threshold Sensor From Sensor List
162
163        # Get Sensor ID from SDR Get "sensor" and Identify Sensor ID.
164        ${sensor_data1}=  Fetch Sensor Details From SDR  ${sensor_name}  Sensor ID
165        ${sensor_number}=  Get Bytes From SDR Sensor  ${sensor_data1}
166
167        # Get Sensor Type from SDR Get "sensor" and Identify Sensor Type.
168        ${sensor_data2}=  Fetch Sensor Details From SDR  ${sensor_name}  Sensor Type (Threshold)
169        ${sensor_type_id}=  Get Bytes From SDR Sensor  ${sensor_data2}
170
171        # Add SEL Entry.
172        ${sel_create_resp}=  Create SEL  ${sensor_type_id}  ${sensor_number}
173
174        # Get SEL List last 1 entry date and time and convert to epoch timestamp.
175        ${sel_epoch_time}=  Get SEL Elist Last Entry Date In Epoch
176
177        # Get Most Recent Addition Timestamp from SEL Info.
178        ${addition}=  Get Most Recent Addition Timestamp From SEL Info
179        ${epoch_addition}=  Convert To Integer  ${addition}  16
180
181        # Compare epoch of sel entry timestamp and last addition timestamp.
182        ${diff}=  Evaluate  int(${epoch_addition}) - int(${sel_epoch_time})
183        Should Be True  ${diff}<=5
184    END
185
186
187Verify IPMI SEL Most Recent Erase Timestamp
188    [Documentation]  Verify Most Recent Erase Timestamp In SEL Info with current
189    ...              BMC epoch timestamp.
190    [Tags]  Verify_IPMI_SEL_Most_Recent_Erase_Timestamp
191
192    # Get BMC Current Time.
193    ${bmc_epoch_time}=  Get BMC Time In Epoch
194
195    # Get Most Recent Addition Timestamp from SEL Info.
196    ${addition_timestamp}=  Get Most Recent Addition Timestamp From SEL Info
197    Should Be Equal  ${addition_timestamp}  ffffffff
198
199    # Get Most Recent Erase Timestamp from SEL Info.
200    ${erase_timestamp}=  Get Most Recent Erase Timestamp From SEL Info
201    ${epoch_erase}=  Convert To Integer  ${erase_timestamp}  16
202
203    # Compare epoch of erase timestamp and current bmc timestamp.
204    ${diff}=  Evaluate  int(${epoch_erase}) - int(${bmc_epoch_time})
205    Should Be True  ${diff}<=5
206
207
208Verify Clear SEL With Invalid Reservation ID
209    [Documentation]  Verify clear SEL After generating another reserve ID.
210    [Tags]  Verify_Clear_SEL_With_Invalid_Reservation_ID
211
212    # Reserve Sel command - 1.
213    ${resp}=  Run IPMI Command
214    ...  ${IPMI_RAW_CMD['SEL_entry']['Reserve'][0]}
215    ${reserve_id}=  Split String  ${resp}
216
217    # Reserve Sel command - 2.
218    ${resp}=  Run IPMI Command
219    ...  ${IPMI_RAW_CMD['SEL_entry']['Reserve'][0]}
220
221    ${cmd}=  Catenate  ${IPMI_RAW_CMD['SEL_entry']['Clear_SEL'][0]} 0x${reserve_id[0]}
222    ...  0x${reserve_id[1]} ${IPMI_RAW_CMD['SEL_entry']['Clear_SEL'][1]}
223
224    # Clear SEL command.
225    ${clear_resp}=  Run Keyword and Expect Error  *${IPMI_RAW_CMD['SEL_entry']['Clear_SEL'][4]}*
226    ...  Run IPMI Command  ${cmd}
227    Should Contain  ${clear_resp}  ${IPMI_RAW_CMD['SEL_entry']['Clear_SEL'][5]}
228
229
230Verify Reservation ID Erasure Status
231    [Documentation]  Verify Erasure status by clearing SEL with Reserve ID and verify the response byte,
232    ...  whether erasure status is updated in clear sel command response data using new Reserve ID.
233    [Tags]  Verify_Reservation_ID_Erasure_Status
234
235    # Generate Reserve ID 1.
236    ${resp}=  Run IPMI Command
237    ...  ${IPMI_RAW_CMD['SEL_entry']['Reserve'][0]}
238    ${reserve_id}=  Split String  ${resp}
239
240    ${cmd1}=  Catenate  ${IPMI_RAW_CMD['SEL_entry']['Clear_SEL'][0]} 0x${reserve_id[0]}
241    ...  0x${reserve_id[1]} ${IPMI_RAW_CMD['SEL_entry']['Clear_SEL'][1]}
242
243    # Execute clear SEL raw command with Reservation ID.
244    # Command will not execute unless the correct Reservation ID value is provided.
245    Run IPMI Command  ${cmd1}
246
247    # Generate Reserver ID 2.
248    ${resp}=  Run IPMI Command
249    ...  ${IPMI_RAW_CMD['SEL_entry']['Reserve'][0]}
250    ${reserve_id}=  Split String  ${resp}
251
252    ${cmd2}=  Catenate  ${IPMI_RAW_CMD['SEL_entry']['Clear_SEL'][0]} 0x${reserve_id[0]}
253    ...  0x${reserve_id[1]} ${IPMI_RAW_CMD['SEL_entry']['Clear_SEL'][6]}
254
255    # Check the Erasure status of Clear SEL.
256    ${data}=  Run IPMI Command  ${cmd2}
257
258    # 00 - Erasure in Progress , 01 - Erasure Complete.
259    Should Contain Any  ${data}  00  01
260
261
262Verify Clear SEL After Cold Reset
263    [Documentation]  Verify Clear SEL for a reserve SEL ID after Cold Reset.
264    [Tags]  Verify_Clear_SEL_After_Cold_Reset
265
266    # Reserve Sel command.
267    ${resp}=  Run IPMI Command
268    ...  ${IPMI_RAW_CMD['SEL_entry']['Reserve'][0]}
269    ${reserve_id}=  Split String  ${resp}
270
271    # Run Cold Reset.
272    IPMI MC Reset Cold (off)
273
274    ${cmd}=  Catenate  ${IPMI_RAW_CMD['SEL_entry']['Clear_SEL'][0]} 0x${reserve_id[0]}
275    ...  0x${reserve_id[1]} ${IPMI_RAW_CMD['SEL_entry']['Clear_SEL'][1]}
276
277    # Clear SEL command.
278    ${clear_resp}=  Run Keyword and Expect Error  *${IPMI_RAW_CMD['SEL_entry']['Clear_SEL'][5]}*
279    ...  Run IPMI Command  ${cmd}
280
281    Should Contain  ${clear_resp}  ${IPMI_RAW_CMD['SEL_entry']['Clear_SEL'][4]}
282
283
284*** Keywords ***
285
286Create User Defined SEL
287    [Documentation]  Create a user defined tempearature sensor SEL.
288
289    # Create a SEL.
290    # Example:
291    # a | 02/14/2020 | 01:16:58 | Temperature #0x17 |  | Asserted
292    Run IPMI Command
293    ...  0x0a 0x44 0x00 0x00 0x02 0x00 0x00 0x00 0x00 0x00 0x00 0x04 0x01 ${sensor_number} 0x00 0xa0 0x04 0x07
294
295
296Get SEL Entry Via IPMI
297    [Documentation]  Get SEL Entry Via IPMI raw command.
298    [Arguments]  ${record1}  ${record2}
299
300    # Description of Argument(s):
301    # ${record1}    Record ID for added record, LS Byte
302    # ${record2}    Record ID for added record, MS Byte
303
304    # For example, when a first sel entry is added with IPMI raw command, the response will be "01 00".
305    # Here, ${record1} is 01, and ${record2} is 00.
306
307    ${cmd}=  Catenate  ${IPMI_RAW_CMD['SEL_entry']['Get_SEL_Entry'][0]} 0x${record1}
308    ...  0x${record2} ${IPMI_RAW_CMD['SEL_entry']['Get_SEL_Entry'][1]}
309
310    # Get SEL Entry Raw command.
311    ${resp}=  Run IPMI Command  ${cmd}
312    ${resp}=  Split String  ${resp}
313
314    [Return]  ${resp}
315
316
317Get Most Recent Addition Timestamp From SEL Info
318    [Documentation]  Get Most recent addition timestamp From SEL Info.
319
320    # Get SEL Info raw command.
321    ${sel_info}=  Get SEL Info Via IPMI
322
323    # Get Most Recent Addition timestamp in hex.
324    ${addition_timestamp}=  Set Variable  ${sel_info[5:9]}
325    Reverse List  ${addition_timestamp}
326    ${addition_timestamp}=  Evaluate  "".join(${addition_timestamp})
327
328    [Return]  ${addition_timestamp}
329
330
331Get Most Recent Erase Timestamp From SEL Info
332    [Documentation]  Get Most recent erase timestamp From SEL Info.
333
334    # Get SEL Info Raw command.
335    ${sel_info}=  Get SEL Info Via IPMI
336
337    # Get Most Recent Erase timestamp in hex.
338    ${erase_timestamp}=  Set Variable  ${sel_info[9:13]}
339    Reverse List  ${erase_timestamp}
340    ${erase_timestamp}=  Evaluate  "".join(${erase_timestamp})
341
342    [Return]  ${erase_timestamp}
343
344
345Get SEL Elist Last Entry Date In Epoch
346    [Documentation]  Get the time from SEL elist last entry and returns epoch time.
347
348    # Get SEL list last entry.
349    ${resp}=  Run IPMI Standard Command  sel elist last 1
350
351    # Get date from the sel entry and convert to epoch timestamp.
352    ${sel_entry_date}=  Fetch Added SEL Date  ${resp}
353    ${epoch_date}=  Convert Date  ${sel_entry_date}  epoch  exclude_millis=yes  date_format=%m/%d/%Y %H:%M:%S
354
355    [Return]  ${epoch_date}
356
357
358Get BMC Time In Epoch
359    [Documentation]  Get the current time from BMC and returns epoch time.
360
361    # Get the bmc native bmc date command response.
362    ${date}=  Get Current Date from BMC
363
364    ${epoch_date}=  Convert Date  ${date}  epoch  exclude_millis=yes  date_format=%m/%d/%Y %H:%M:%S
365
366    [Return]   ${epoch_date}
367
368
369Test Setup Execution
370    [Documentation]  Do test setup tasks.
371
372    Run IPMI Standard Command  sel clear
373    Sleep  5s
374