1*** Settings ***
2Documentation    Test suite to verify BIOS POST code log entries.
3
4Resource         ../../../lib/resource.robot
5Resource         ../../../lib/bmc_redfish_resource.robot
6Resource         ../../../lib/openbmc_ffdc.robot
7Resource         ../../../lib/logging_utils.robot
8
9Suite Setup      Suite Setup Execution
10Test Setup       Test Setup Execution
11Test Teardown    Test Teardown Execution
12Suite Teardown   Suite Teardown Execution
13
14Force Tags       Post_Codes
15
16*** Variables ***
17${max_view_count}    1000
18
19
20*** Test Cases ***
21
22Test PostCodes When Host Boots
23    [Documentation]  Boot the system and verify PostCodes from host are logged.
24    [Tags]  Test_PostCodes_When_Host_Boots
25
26    Redfish Power On
27    ${post_code_list}=  Redfish Get PostCodes
28    Rprint Vars  post_code_list
29
30    ${post_codes}=  Redfish.Get Properties
31    ...  /redfish/v1/Systems/${SYSTEM_ID}/LogServices/PostCodes/Entries
32    Log To Console  BIOS POST Codes count: ${post_codes['Members@odata.count']}
33    Should Be True  ${post_codes['Members@odata.count']} >= 1  msg=No BIOS POST Codes populated.
34
35
36Test PostCodes When Host Reboot
37    [Documentation]  Initiate Host reboot the system and verify PostCodes from host are logged.
38    [Tags]  Test_PostCodes_When_Host_Reboot
39
40    # Boot to runtime and clear post codes.
41    Redfish Power On  stack_mode=skip
42    Redfish Clear PostCodes
43
44    RF SYS GracefulRestart
45    ${post_code_list}=  Redfish Get PostCodes
46    Rprint Vars  post_code_list
47
48    ${post_codes}=  Redfish.Get Properties
49    ...  /redfish/v1/Systems/${SYSTEM_ID}/LogServices/PostCodes/Entries
50    Log To Console  BIOS POST Codes count: ${post_codes['Members@odata.count']}
51    Should Be True  ${post_codes['Members@odata.count']} >= 1  msg=No BIOS POST Codes populated.
52
53
54Test PostCodes When Host Powered Off
55    [Documentation]  Power off the system and verify PostCodes from host are logged.
56    [Tags]  Test_PostCodes_When_Host_Powered_Off
57
58    # Boot to runtime and clear post codes.
59    Redfish Power On  stack_mode=skip
60    Redfish Clear PostCodes
61
62    Redfish Power Off
63    ${post_code_list}=  Redfish Get PostCodes
64    Rprint Vars  post_code_list
65
66    ${post_codes}=  Redfish.Get Properties
67    ...  /redfish/v1/Systems/${SYSTEM_ID}/LogServices/PostCodes/Entries
68    Log To Console  BIOS POST Codes count: ${post_codes['Members@odata.count']}
69    Should Be True  ${post_codes['Members@odata.count']} == 0
70    ...  msg=BIOS POST Codes populated.
71
72
73Test PostCode Id Value Incremented On Host Reboot
74    [Documentation]  Verify the value of ID in postcode entry is incremented
75    ...  on host reboot. In the ID value 'B2-49', '2' represents
76    ...  the boot cycle count of the host system.
77    [Tags]  Test_PostCode_Id_Value_Incremented_On_Host_Reboot
78    [Setup]  Populate PostCode Logs Incase No Prior Entries Available
79
80    # Get boot count of current postcode logs.
81    ${initial_boot_count}=  Get Boot Count For Last PostCode Entry
82    ${expected_boot_count}=  Evaluate  ${initial_boot_count} + 1
83
84    # Perform host reboot and verify boot count incremented in ID value.
85    RF SYS GracefulRestart
86    ${current_boot_count}=  Get Boot Count For Last PostCode Entry
87    Should Be True  ${current_boot_count} == ${expected_boot_count}
88
89
90Test PostCode Log Perisistency After BMC Reboot
91    [Documentation]  Verify the post code log entries persist after BMC reboot.
92    [Tags]  Test_PostCode_Log_Perisistency_After_BMC_Reboot
93    [Setup]  Populate PostCode Logs Incase No Prior Entries Available
94
95    Redfish Power On  stack_mode=skip
96
97    # Get log count before BMC reboot.
98    ${post_codes}=  Redfish.Get Properties
99    ...  /redfish/v1/Systems/${SYSTEM_ID}/LogServices/PostCodes/Entries
100    ${initial_log_count}=  Set Variable  ${post_codes['Members@odata.count']}
101
102    # Reboot BMC.
103    OBMC Reboot (run)
104
105    # Get log count after BMC reboot and compare with initial log count.
106    ${post_codes}=  Redfish.Get Properties
107    ...  /redfish/v1/Systems/${SYSTEM_ID}/LogServices/PostCodes/Entries
108    ${current_log_count}=  Set Variable  ${post_codes['Members@odata.count']}
109    Should Be True  ${current_log_count} == ${initial_log_count}
110
111
112Test Clear Post Code Log Action
113    [Documentation]  Verify clear log action for post code entries.
114    [Tags]  Test_Clear_Post_Code_Log_Action
115    [Setup]  Populate PostCode Logs Incase No Prior Entries Available
116
117    # Perform clear postcode log action.
118    Redfish Clear PostCodes
119    ${post_codes}=  Redfish.Get Properties
120    ...  /redfish/v1/Systems/${SYSTEM_ID}/LogServices/PostCodes/Entries
121
122    # Verify if log count becomes zero.
123    Should Be True  ${post_codes['Members@odata.count']} == 0
124    ...  msg=BIOS POST code logs not cleared.
125
126
127*** Keywords ***
128
129Test Setup Execution
130    [Documentation]  Do test setup operation.
131
132    Redfish.Login
133    Redfish Clear PostCodes
134
135
136Test Teardown Execution
137    [Documentation]  Do test teardown operation.
138
139    FFDC On Test Case Fail
140
141
142Suite Setup Execution
143    [Documentation]  Do suite setup operation.
144
145    Redfish.Login
146    Redfish Power Off  stack_mode=skip
147
148    Run Keyword And Ignore Error  Redfish Delete All BMC Dumps
149    Run Keyword And Ignore Error  Redfish Purge Event Log
150    Run Keyword And Ignore Error  Delete All Redfish Sessions
151
152
153Suite Teardown Execution
154    [Documentation]  Do suite teardown operation.
155
156    Run Keyword And Ignore Error  Redfish Delete All BMC Dumps
157    Run Keyword And Ignore Error  Redfish Purge Event Log
158    Run Keyword And Ignore Error  Delete All Redfish Sessions
159
160
161Get Boot Count For Last PostCode Entry
162    [Documentation]  Get the latest boot count from post code log entry.
163    ...  log entry has ID "B2-1000", latest boot count "2" is returned.
164
165    # {
166    #     "@odata.id": "/redfish/v1/Systems/system/LogServices/PostCodes/Entries",
167    #     "@odata.type": "#LogEntryCollection.LogEntryCollection",
168    #     "Description": "Collection of POST Code Log Entries",
169    #     "Members": [
170    #         {
171    #             "@odata.id": "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/B1-1000",
172    #             "@odata.type": "#LogEntry.v1_8_0.LogEntry",
173    #             "Created": "1970-01-01T00:16:40+00:00",
174    #             "EntryType": "Event",
175    #             "Id": "B2-1000",
176    #             "Message": "Boot Count: 2; Time Stamp Offset: 117.4928 seconds; POST Code: 0xac10",
177    #             "MessageArgs": [
178    #                 "2",
179    #                 "117.4928",
180    #                 "0xac10"
181    #             ],
182    #             "MessageId": "OpenBMC.0.2.BIOSPOSTCode",
183    #             "Name": "POST Code Log Entry",
184    #             "Severity": "OK"
185    #         }
186    #     ],
187    #     "Members@odata.count": 2240,
188    #     "Members@odata.nextLink": "/redfish/v1/Systems/system/LogServices/PostCodes/Entries?$skip=1000",
189    #     "Name": "BIOS POST Code Log Entries"
190    # }
191    ${post_codes}=  Redfish.Get Properties
192    ...  /redfish/v1/Systems/${SYSTEM_ID}/LogServices/PostCodes/Entries
193    ${total_log_count}=  Set Variable  ${post_codes['Members@odata.count']}
194
195    IF  ${total_log_count} > ${max_view_count}
196        ${skip_count}=  Evaluate  (${total_log_count}//${max_view_count})*${max_view_count}
197        ${uri}=  Set Variable
198        ...  /redfish/v1/Systems/${SYSTEM_ID}/LogServices/PostCodes/Entries?$skip=${skip_count}
199        ${post_codes}=  Redfish.Get Properties  ${uri}
200    END
201
202    ${last_id}=  Set Variable  ${post_codes['Members'][-1]['Id']}
203    ${last_id}=  Split String  ${last_id}  -
204    ${boot_count}=  Set Variable  ${last_id[0][1]}
205
206    Return From Keyword  ${boot_count}
207
208
209Populate PostCode Logs Incase No Prior Entries Available
210    [Documentation]  Trigger Redfish graceful restart action on host system
211    ...  to populate postcode logs if there are no prior log entries.
212
213    ${post_codes}=  Redfish.Get Properties
214    ...  /redfish/v1/Systems/${SYSTEM_ID}/LogServices/PostCodes/Entries
215    Run Keyword If  ${post_codes['Members@odata.count']} == 0
216    ...  RF SYS GracefulRestart
217
218