1*** Settings ***
2
3Documentation    Module to test PLDM BIOS attribute types.
4
5Library          Collections
6Library          String
7Library          ../lib/pldm_utils.py
8Variables        ../data/pldm_variables.py
9Resource         ../lib/openbmc_ffdc.robot
10
11Test Setup       Printn
12Test Teardown    FFDC On Test Case Fail
13Suite Setup      PLDM BIOS Attribute Suite Setup
14Suite Teardown   PLDM BIOS Attribute Suite Cleanup
15
16
17*** Variables ***
18
19${bios_original_data}       ${EMPTY}
20${attr_table_data}     ${EMPTY}
21
22
23*** Test Cases ***
24
25Verify Get BIOS Attribute With Invalid Attribute Name
26
27    [Documentation]  Verify get BIOS attribute with invalid attribute name.
28    [Tags]  Verify_Get_BIOS_Attribute_With_Invalid_Attribute_Name
29
30    ${random_attr}=  Generate Random String  8  [LETTERS][NUMBERS]
31    ${pldm_output}=  pldmtool  bios GetBIOSAttributeCurrentValueByHandle -a ${random_attr}
32
33    # Example output:
34    #
35    # pldmtool bios GetBIOSAttributeCurrentValueByHandle -a hjkhkj
36    # Can not find the attribute hjkhkj
37    #
38
39    Should Contain  ${pldm_output}  Can not find the attribute
40
41
42Verify Set BIOS Attribute With Invalid Attribute Name
43
44    [Documentation]  Verify set BIOS attribute with invalid attribute name.
45    [Tags]  Verify_Set_BIOS_Attribute_With_Invalid_Attribute_Name
46
47    ${random_str}=  Generate Random String  8  [LETTERS][NUMBERS]
48    ${pldm_output}=  pldmtool  bios SetBIOSAttributeCurrentValue -a ${random_str} -d ${random_str}
49
50    # Example output:
51    #
52    # pldmtool bios SetBIOSAttributeCurrentValue -a hjkhkj -d 0
53    # Could not find attribute :hjkhkj
54    #
55
56    Should Contain  ${pldm_output}  Could not find attribute
57
58
59Verify Set Invalid Optional Value For BIOS Enumeration Attribute Type
60
61    [Documentation]  Verify set invalid optional value for BIOS enumeration attribute type.
62    [Tags]  Verify_Set_Invalid_Optional_Value_For_BIOS_Enumeration_Attribute_Type
63
64    ${attr_val_data}=  GetBIOSEnumAttributeOptionalValues  ${attr_table_data}
65    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
66    ${enum_attr}=  Evaluate  random.choice(${attr_handles})  modules=random
67
68    # Example output:
69    #
70    # pldmtool bios SetBIOSAttributeCurrentValue -a pvm_os_boot_side -d hhhhhj
71    # Set Attribute Error: It's not a possible value
72    #
73
74    ${pldm_output}=  pldmtool  bios SetBIOSAttributeCurrentValue -a ${enum_attr} -d 0
75    Should Contain  ${pldm_output}  Set Attribute Error
76
77
78Verify Set Out Of Range Integer Value For BIOS Integer Attribute Type
79
80    [Documentation]  Verify set out of range integer value for BIOS integer attribute type.
81    [Tags]  Verify_Set_Out_Of_Range_Integer_Value_For_BIOS_Integer_Attribute_Type
82
83    ${attr_val_data}=  GetBIOSStrAndIntAttributeHandles  BIOSInteger  ${attr_table_data}
84    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
85    ${int_attr}=  Evaluate  random.choice(${attr_handles})  modules=random
86    ${count}=  Evaluate  ${attr_val_data['${int_attr}']["UpperBound"]} + 5
87
88    # Example output:
89    #
90    # pldmtool bios SetBIOSAttributeCurrentValue -a vmi_if_count -d 12
91    # Response Message Error: rc=0,cc=2
92    #
93
94    ${pldm_output}=  pldmtool  bios SetBIOSAttributeCurrentValue -a ${int_attr} -d ${count}
95    Should Contain  ${pldm_output}  Response Message Error
96
97
98Verify Set Out Of Range String Value For BIOS String Attribute Type
99
100    [Documentation]  Verify set out of range string value for BIOS string attribute type.
101    [Tags]  Verify_Set_Out_Of_Range_String_Value_For_BIOS_String_Attribute_Type
102
103    ${attr_val_data}=  GetBIOSStrAndIntAttributeHandles  BIOSString  ${attr_table_data}
104    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
105    ${str_attr}=  Evaluate  random.choice(${attr_handles})  modules=random
106    ${count}=  Evaluate  ${attr_val_data['${str_attr}']["MaximumStringLength"]} + 5
107    ${random_value}=  Generate Random String  ${count}  [LETTERS][NUMBERS]
108
109    # Example output:
110    #
111    # pldmtool bios SetBIOSAttributeCurrentValue -a vmi_if0_ipv4_ipaddr -d 1234566788999
112    # Response Message Error: rc=0,cc=2
113    #
114
115    ${pldm_output}=  pldmtool  bios SetBIOSAttributeCurrentValue -a ${str_attr} -d ${random_value}
116    Should Contain  ${pldm_output}  Response Message Error
117
118
119Verify Set BIOS String Attribute Type
120
121    [Documentation]  Verify set BIOS string attribute type for various BIOS
122    ...              attribute handle with random values with in the range.
123    [Tags]  Verify_Set_BIOS_String_Attribute_Type
124
125    ${attr_val_data}=  GetBIOSStrAndIntAttributeHandles  BIOSString  ${attr_table_data}
126
127    # Example output:
128    #
129    # pldmtool bios SetBIOSAttributeCurrentValue -a vmi_hostname -d BMC
130    # {
131    #     "Response": "SUCCESS"
132    # }
133
134    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
135    FOR  ${i}  IN  @{attr_handles}
136        ${random_value}=  GetRandomBIOSIntAndStrValues  ${i}  ${attr_val_data['${i}']["MaximumStringLength"]}
137        ${attr_val_list}=  Create List
138        Append To List  ${attr_val_list}  ${random_value}
139        Validate Set BIOS Attributes With Optional Values  ${i}  @{attr_val_list}
140    END
141
142
143Verify Set BIOS Integer Attribute Type
144
145    [Documentation]  Verify set BIOS integer attribute type for various BIOS
146    ...              attribute handle with random values with in the range.
147    [Tags]  Verify_Set_BIOS_Integer_Attribute_Type
148
149    ${attr_val_data}=  GetBIOSStrAndIntAttributeHandles  BIOSInteger  ${attr_table_data}
150
151    # Example output:
152    #
153    # pldmtool bios SetBIOSAttributeCurrentValue -a vmi_if_count -d 1
154    # {
155    #     "Response": "SUCCESS"
156    # }
157
158    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
159
160    FOR  ${i}  IN  @{attr_handles}
161        ${random_value}=  GetRandomBIOSIntAndStrValues  ${i}  ${attr_val_data['${i}']["UpperBound"]}
162        ${attr_val_list}=  Create List
163        Append To List  ${attr_val_list}  ${random_value}
164        Validate Set BIOS Attributes With Optional Values  ${i}  @{attr_val_list}
165    END
166
167
168Verify Set BIOS Enumeration Attribute Type
169
170    [Documentation]  Verify set BIOS enumeration attribute type for various BIOS
171    ...              attribute handle with random values with in the range of
172    ...              default optional values.
173    [Tags]  Verify_BIOS_Enumeration_Attribute_Type
174
175    ${attr_val_data}=  GetBIOSEnumAttributeOptionalValues  ${attr_table_data}
176
177    # Example output:
178    #
179    # pldmtool bios SetBIOSAttributeCurrentValue -a pvm_default_os_type -d AIX
180    # {
181    #     "Response": "SUCCESS"
182    # }
183
184    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
185    FOR  ${i}  IN  @{attr_handles}
186        @{attr_val_list}=  Set Variable  ${attr_val_data}[${i}]
187        Validate Set BIOS Attributes With Optional Values  ${i}  @{attr_val_list}
188    END
189
190
191Verify Restore BIOS Attribute Values
192
193    [Documentation]  Restore all BIOS attribute values with its default values and verify.
194    [Tags]  Verify_Restore_BIOS_Attribute_Values
195
196    ${bios_default_data}=  GetBIOSAttrDefaultValues  ${attr_table_data}
197    Validate Set All BIOS Attributes Values  ${bios_default_data}
198
199
200*** Keywords ***
201
202PLDM BIOS Attribute Suite Setup
203
204    [Documentation]  Perform PLDM BIOS attribute suite setup.
205
206    ${pldm_output}=  Pldmtool  bios GetBIOSTable --type AttributeTable
207    Set Global Variable  ${attr_table_data}  ${pldm_output}
208
209    ${data}=  GetBIOSAttrOriginalValues  ${pldm_output}
210    Set Global Variable  ${bios_original_data}  ${data}
211
212
213PLDM BIOS Attribute Suite Cleanup
214
215    [Documentation]  Perform PLDM BIOS attribute suite cleanup.
216
217    Validate Set All BIOS Attributes Values  ${bios_original_data}
218
219
220Validate Set BIOS Attributes With Optional Values
221
222    [Documentation]  Set BIOS attribute with the available attribute handle
223    ...              values and revert back to original attribute handle value.
224    [Arguments]      ${attr_handle}  @{attr_val_list}
225
226    # Description of argument(s):
227    # attr_handle    BIOS attribute handle (e.g. pvm_system_power_off_policy).
228    # attr_val_list  List of the attribute values for the given attribute handle
229    #                (e.g. ['"Power Off"', '"Stay On"', 'Automatic']).
230
231    FOR  ${j}  IN  @{attr_val_list}
232        ${pldm_resp}=  pldmtool  bios SetBIOSAttributeCurrentValue -a ${attr_handle} -d ${j}
233        Valid Value  pldm_resp['Response']  ['SUCCESS']
234
235        # Compare BIOS attribute values after set operation.
236        ${output}=  pldmtool  bios GetBIOSAttributeCurrentValueByHandle -a ${attr_handle}
237        ${value1}=  Convert To String  ${output["CurrentValue"]}
238        ${value2}=  Convert To String  ${j}
239        ${value2}=  Replace String  ${value2}  "  ${EMPTY}
240        Should Be Equal  ${value1.strip()}  ${value2.strip()}
241
242    END
243
244
245Validate Set All BIOS Attributes Values
246
247    [Documentation]  Validate Set BIOS Attributes Values.
248    [Arguments]      ${bios_attr_data}
249
250    # Description of argument(s):
251    # bios_attr_data  Dictionary containing BIOS attribute name and values.
252
253    @{keys}=  Get Dictionary Keys  ${bios_attr_data}
254
255    FOR  ${key}  IN  @{keys}
256        ${pldm_resp}=  pldmtool  bios SetBIOSAttributeCurrentValue -a ${key} -d ${bios_attr_data['${key}']}
257        Valid Value  pldm_resp['Response']  ['SUCCESS']
258
259        # Compare BIOS attribute values after set operation.
260        ${output}=  pldmtool  bios GetBIOSAttributeCurrentValueByHandle -a ${key}
261        ${value1}=  Convert To String  ${output["CurrentValue"]}
262        ${value2}=  Convert To String  ${bios_attr_data['${key}']}
263        ${value2}=  Replace String  ${value2}  "  ${EMPTY}
264        Should Be Equal  ${value1.strip()}  ${value2.strip()}
265    END
266