Automate 9 TC to verify BIOS Attribute Types using pldmtool

      - Verify Set BIOS Integer Attribute Type
      - Verify Set BIOS String Attribute Type
      - Verify Restore BIOS Attribute Values
      - Verify Get BIOS Attribute With Invalid Attribute Name
      - Verify Set BIOS Attribute With Invalid Attribute Name
      - Verify Set Invalid Optional Value For BIOS Enumeration Attribute Type
      - Verify Set Out Of Range Integer Value For BIOS Integer Attribute Type
      - Verify Set Out Of Range String Value For BIOS String Attribute Type

Change-Id: I2db9fea8acd097a33a52f6cd5d03ed8427c12a4f
Signed-off-by: Sridevi Ramesh <sridevra@in.ibm.com>
diff --git a/lib/pldm_utils.py b/lib/pldm_utils.py
old mode 100644
new mode 100755
index e22af25..661e8ab
--- a/lib/pldm_utils.py
+++ b/lib/pldm_utils.py
@@ -9,9 +9,12 @@
 import func_args as fa
 import bmc_ssh_utils as bsu
 import json
+import random
+import string
 
 
 def pldmtool(option_string, **bsu_options):
+
     r"""
     Run pldmtool on the BMC with the caller's option string and return the result.
 
@@ -26,11 +29,6 @@
           "Response": "1.0.0"
       }
 
-     pldmtool base GetTID
-     {
-         "Response": 1
-     }
-
     Description of argument(s):
     option_string                   A string of options which are to be processed by the pldmtool command.
     parse_results                   Parse the pldmtool results and return a dictionary rather than the raw
@@ -43,17 +41,23 @@
     bsu_options = fa.args_to_objects(bsu_options)
 
     stdout, stderr, rc = bsu.bmc_execute_command('pldmtool ' + option_string, **bsu_options)
-    return json.loads(stdout)
+    if stderr:
+        return stderr
+    try:
+        return json.loads(stdout)
+    except ValueError:
+        return stdout
 
 
-def GenerateBIOSAttrHandleValueDict(attr_val_table_data):
+def GetBIOSEnumAttributeOptionalValues(attr_val_table_data):
+
     """
-    From pldmtool bios GetBIOSTable of AttributeValueTable generate dictionary of
-    for BIOS attribute and its value.
+    From pldmtool GetBIOSTable of type AttributeValueTable get the dict of
+    attribute handle and its optional values for BIOS Enumeration type.
 
     Description of argument(s):
     attr_val_table_data     pldmtool output from GetBIOSTable table type AttributeValueTable
-                             e.g.
+                            e.g.
                             [{
                                   "AttributeHandle": 20,
                                   "AttributeNameHandle": "23(pvm-pcie-error-inject)",
@@ -64,24 +68,9 @@
                                   "NumberOfDefaultValues": 1,
                                   "DefaultValueStringHandleIndex[0]": 1,
                                   "StringHandle": "4(Enabled)"
-                             },
-                             {
-                                  "AttributeHandle": 26,
-                                  "AttributeNameHandle": "28(pvm_fw_boot_side)",
-                                  "AttributeType": "BIOSEnumeration",
-                                  "NumberOfPossibleValues": 2,
-                                  "PossibleValueStringHandle[0]": "11(Perm)",
-                                  "PossibleValueStringHandle[1]": "15(Temp)",
-                                  "NumberOfDefaultValues": 1,
-                                  "DefaultValueStringHandleIndex[0]": 1,
-                                  "StringHandle": "15(Temp)"
                              }]
-
     @return                  Dictionary of BIOS attribute and its value.
-                             e.g. {
-                                   'pvm_pcie_error_inject': ['Disabled', 'Enabled'],
-                                   'pvm-fw-boot-side': ['Perm', 'Temp']
-                                  }
+                             e.g. {'pvm_pcie_error_inject': ['Disabled', 'Enabled']}
     """
 
     attr_val_data_dict = {}
@@ -104,3 +93,132 @@
                 attr_handle = re.findall(r'\(.*?\)', item["AttributeNameHandle"])
                 attr_val_data_dict[attr_handle[0][1:-1]] = value_list
     return attr_val_data_dict
+
+
+def GetBIOSStrAndIntAttributeHandles(attr_type, attr_val_table_data):
+
+    """
+    From pldmtool GetBIOSTable of type AttributeValueTable get the dict of
+    attribute handle and its values based on the attribute type.
+
+    Description of argument(s):
+    attr_type               "BIOSInteger" or "BIOSString".
+    attr_val_table_data     pldmtool output from GetBIOSTable table type AttributeValueTable.
+
+    @return                 Dict of BIOS attribute and its value based on attribute type.
+
+    """
+    attr_val_int_dict = {}
+    attr_val_str_dict = {}
+    for item in attr_val_table_data:
+        value_dict = {}
+        attr_handle = re.findall(r'\(.*?\)', item["AttributeNameHandle"])
+        # Example:
+        # {'vmi_if0_ipv4_prefix_length': {'UpperBound': 32, 'LowerBound': 0}
+        if (item["AttributeType"] == "BIOSInteger"):
+            value_dict["LowerBound"] = item["LowerBound"]
+            value_dict["UpperBound"] = item["UpperBound"]
+            attr_val_int_dict[attr_handle[0][1:-1]] = value_dict
+        # Example:
+        # {'vmi_if1_ipv4_ipaddr': {'MaximumStringLength': 15, 'MinimumStringLength': 7}}
+        elif (item["AttributeType"] == "BIOSString"):
+            value_dict["MinimumStringLength"] = item["MinimumStringLength"]
+            value_dict["MaximumStringLength"] = item["MaximumStringLength"]
+            attr_val_str_dict[attr_handle[0][1:-1]] = value_dict
+
+    if (attr_type == "BIOSInteger"):
+        return attr_val_int_dict
+    elif (attr_type == "BIOSString"):
+        return attr_val_str_dict
+
+
+def GetRandomBIOSIntAndStrValues(attr_name, count):
+
+    """
+    Get random integer or string values for BIOS attribute values based on the count.
+
+    Description of argument(s):
+    attr_name               Attribute name of BIOS attribute type Integer or string.
+    count                   Max length for BIOS attribute type Integer or string.
+
+    @return                 Random attribute value based on BIOS attribute type Integer
+                            or string.
+
+    """
+    attr_random_value = ''
+
+    # Example
+    # 12.13.14.15
+    if 'gateway' in attr_name:
+        attr_random_value = ".".join(map(str, (random.randint(0, 255) for _ in range(4))))
+    # Example
+    # 11.11.11.11
+    elif 'ipaddr' in attr_name:
+        attr_random_value = ".".join(map(str, (random.randint(0, 255) for _ in range(4))))
+    # Example
+    # E5YWEDWJJ
+    elif 'name' in attr_name:
+        data = string.ascii_uppercase + string.digits
+        attr_random_value = ''.join(random.choice(data) for _ in range(int(count)))
+
+    else:
+        attr_random_value = random.randint(0, int(count))
+    return attr_random_value
+
+
+def GetBIOSAttrOriginalValues(attr_val_table_data):
+
+    """
+    From pldmtool GetBIOSTable of type AttributeValueTable get the dict of
+    attribute handle and its values.
+
+    Description of argument(s):
+    attr_val_table_data     pldmtool output from GetBIOSTable table type AttributeValueTable.
+
+    @return                 Dict of BIOS attribute and its value.
+
+    """
+    attr_val_data_dict = {}
+    for item in attr_val_table_data:
+        attr_handle = re.findall(r'\(.*?\)', item["AttributeNameHandle"])
+        attr_name = attr_handle[0][1:-1]
+
+        command = "bios GetBIOSAttributeCurrentValueByHandle -a " + attr_name
+        value = pldmtool(command)
+        attr_val_data_dict[attr_name] = value["CurrentValue"]
+        if not value["CurrentValue"]:
+            if 'name' in attr_name:
+                attr_val_data_dict[attr_name] = '""'
+
+    return attr_val_data_dict
+
+
+def GetBIOSAttrDefaultValues(attr_val_table_data):
+
+    """
+    From pldmtool GetBIOSTable of type AttributeValueTable get the dict of
+    attribute handle and its default attribute values.
+
+    Description of argument(s):
+    attr_val_table_data     pldmtool output from GetBIOSTable table type AttributeValueTable.
+
+    @return                 Dict of BIOS attribute and its default attribute value.
+
+    """
+    attr_val_data_dict = {}
+    for item in attr_val_table_data:
+        attr_handle = re.findall(r'\(.*?\)', item["AttributeNameHandle"])
+        attr_name = attr_handle[0][1:-1]
+
+        if "DefaultString" in item:
+            attr_val_data_dict[attr_name] = item["DefaultString"]
+            if not item["DefaultString"]:
+                if 'name' in attr_name:
+                    attr_val_data_dict[attr_name] = '""'
+        elif "DefaultValue" in item:
+            attr_val_data_dict[attr_name] = item["DefaultValue"]
+        elif "StringHandle" in item:
+            attr_default_value = re.findall(r'\(.*?\)', item["StringHandle"])
+            attr_val_data_dict[attr_name] = attr_default_value[0][1:-1]
+
+    return attr_val_data_dict
diff --git a/pldm/test_pldm_bios.robot b/pldm/test_pldm_bios.robot
old mode 100644
new mode 100755
index 0fc9aca..f3b5788
--- a/pldm/test_pldm_bios.robot
+++ b/pldm/test_pldm_bios.robot
@@ -10,11 +10,13 @@
 
 Test Setup       Printn
 Test Teardown    FFDC On Test Case Fail
+Suite Setup      PLDM BIOS Suite Setup
 Suite Teardown   PLDM BIOS Suite Cleanup
 
 *** Test Cases ***
 
 Verify GetDateTime
+
     [Documentation]  Verify host date & time.
     [Tags]  Verify_GetDateTime
 
@@ -37,7 +39,9 @@
 
     Should Contain  ${current_dmy[0]}  ${date_time[0]}
 
+
 Verify SetDateTime
+
     [Documentation]  Verify set date & time for the host.
     [Tags]  Verify_SetDateTime
 
@@ -65,7 +69,9 @@
     ${cmd_set_time}=  Evaluate  $CMD_SETDATETIME % '${upgrade_time}'
     ${pldm_output}=  Pldmtool  ${cmd_set_time}
 
+
 Verify GetBIOSTable For StringTable
+
     [Documentation]  Verify GetBIOSTable for table type string table.
     [Tags]  Verify_GetBIOSTable_For_StringTable
 
@@ -95,6 +101,7 @@
 
 
 Verify GetBIOSTable For AttributeTable
+
     [Documentation]  Verify if attribute table content exist for
     ...            GetBIOSTable with table type attribute table.
     [Tags]  Verify_GetBIOSTable_For_AttributeTable
@@ -109,17 +116,18 @@
     # [     maximumstringlength]:                      100
     # [     defaultstringlength]:                      15
 
-    ${pldm_output}=  Pldmtool  bios GetBIOSTable --type AttributeTable
-    ${count}=  Get Length  ${pldm_output}
+    ${count}=  Get Length  ${attr_table_data}
     ${attr_list}=  Create List
     FOR  ${i}  IN RANGE  ${count}
-        ${data}=  Set Variable  ${pldm_output}[${i}][AttributeNameHandle]
+        ${data}=  Set Variable  ${attr_table_data}[${i}][AttributeNameHandle]
         ${sub_string}=  Get Substring  ${data}  3  -1
         Append To List  ${attr_list}  ${sub_string}
     END
     Valid List  attr_list  required_values=${RESPONSE_LIST_GETBIOSTABLE_ATTRTABLE}
 
+
 Verify GetBIOSTable For AttributeValueTable
+
     [Documentation]  Verify if attribute value table content exist for
     ...              GetBIOSTable with table type attribute value table.
     [Tags]  Verify_GetBIOSTable_For_AttributeValueTable
@@ -130,38 +138,14 @@
     # [     attributetype]:                           BIOSStringReadOnly
     # [     currentstringlength]:                     15
 
-    ${pldm_output}=  Pldmtool  bios GetBIOSTable --type AttributeValueTable
-    ${count}=  Get Length  ${pldm_output}
+    ${count}=  Get Length  ${attr_table_data} 
     ${attr_val_list}=  Create List
     FOR  ${i}  IN RANGE  ${count}
-        Append To List  ${attr_val_list}  ${pldm_output}[${i}][AttributeType]
+        Append To List  ${attr_val_list}  ${attr_table_data}[${i}][AttributeType]
     END
     Valid List  attr_val_list  required_values=${RESPONSE_LIST_GETBIOSTABLE_ATTRVALTABLE}
 
 
-Verify SetBIOSAttributeCurrentValue
-
-    [Documentation]  Verify SetBIOSAttributeCurrentValue with the
-    ...              various BIOS attribute handle and its values.
-    [Tags]  Verify_SetBIOSAttributeCurrentValue
-
-    # Example output:
-    #
-    # pldmtool bios SetBIOSAttributeCurrentValue -a vmi_hostname -d BMC
-    # {
-    #     "Response": "SUCCESS"
-    # }
-
-    ${pldm_output}=  Pldmtool  bios GetBIOSTable --type AttributeTable
-    Log  ${pldm_output}
-    ${attr_val_data}=  GenerateBIOSAttrHandleValueDict  ${pldm_output}
-    Log  ${attr_val_data}
-    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
-    FOR  ${i}  IN  @{attr_handles}
-        @{attr_val_list}=  Set Variable  ${attr_val_data}[${i}]
-        Validate SetBIOSAttributeCurrentValue  ${i}  @{attr_val_list}
-    END
-
 Verify GetBIOSAttributeCurrentValueByHandle
 
     [Documentation]  Verify GetBIOSAttributeCurrentValueByHandle with the
@@ -175,8 +159,7 @@
     #     "CurrentValue": "Temp"
     # }
 
-    ${pldm_output}=  Pldmtool  bios GetBIOSTable --type AttributeTable
-    ${attr_val_data}=  GenerateBIOSAttrHandleValueDict  ${pldm_output}
+    ${attr_val_data}=  GetBIOSEnumAttributeOptionalValues  ${attr_table_data}
     @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
     FOR  ${i}  IN  @{attr_handles}
         ${cur_attr}=  Pldmtool  bios GetBIOSAttributeCurrentValueByHandle -a ${i}
@@ -185,33 +168,23 @@
         ...  Fail  Invalid GetBIOSAttributeCurrentValueByHandle value found.
     END
 
+
 *** Keywords ***
 
+PLDM BIOS Suite Setup
+
+    [Documentation]  Perform PLDM BIOS suite setup.
+
+    ${pldm_output}=  Pldmtool  bios GetBIOSTable --type AttributeTable
+    Set Global Variable  ${attr_table_data}  ${pldm_output}
+
+
 PLDM BIOS Suite Cleanup
 
-    [Documentation]  Perform pldm BIOS suite cleanup.
+    [Documentation]  Perform PLDM BIOS suite cleanup.
 
     ${result}=  Get Current Date  UTC  exclude_millis=True
     ${current_date_time}=  Evaluate  re.sub(r'-* *:*', "", '${result}')  modules=re
     ${cmd_set_date_time}=  Evaluate  $CMD_SETDATETIME % '${current_date_time}'
     ${pldm_output}=  Pldmtool  ${cmd_set_date_time}
     Valid Value  pldm_output['Response']  ['SUCCESS']
-
-Validate SetBIOSAttributeCurrentValue
-
-    [Documentation]  Set BIOS attribute with the available attribute handle
-    ...              values and revert back to original attribute handle value.
-    [Arguments]  ${attr_handle}  @{attr_val_list}
-
-    # Description of argument(s):
-    # attr_handle    BIOS attribute handle (e.g. pvm_system_power_off_policy).
-    # attr_val_list  List of the attribute values for the given attribute handle
-    #                (e.g. ['"Power Off"', '"Stay On"', 'Automatic']).
-
-    ${cur_attr}=  Pldmtool  bios GetBIOSAttributeCurrentValueByHandle -a ${attr_handle}
-    FOR  ${j}  IN  @{attr_val_list}
-        ${pldm_resp}=  pldmtool  bios SetBIOSAttributeCurrentValue -a ${attr_handle} -d ${j}
-        Valid Value  pldm_resp['Response']  ['SUCCESS']
-    END
-    ${pldm_resp}=  pldmtool  bios SetBIOSAttributeCurrentValue -a ${attr_handle} -d ${cur_attr['CurrentValue']}
-    Valid Value  pldm_resp['Response']  ['SUCCESS']
diff --git a/pldm/test_pldm_bios_attributes.robot b/pldm/test_pldm_bios_attributes.robot
new file mode 100755
index 0000000..74626a6
--- /dev/null
+++ b/pldm/test_pldm_bios_attributes.robot
@@ -0,0 +1,265 @@
+*** Settings ***
+
+Documentation    Module to test PLDM BIOS attribute types.
+
+Library          Collections
+Library          String
+Library          ../lib/pldm_utils.py
+Variables        ../data/pldm_variables.py
+Resource         ../lib/openbmc_ffdc.robot
+
+Test Setup       Printn
+Test Teardown    FFDC On Test Case Fail
+Suite Setup      PLDM BIOS Attribute Suite Setup
+Suite Teardown   PLDM BIOS Attribute Suite Cleanup
+
+
+*** Variables ***
+
+${bios_original_data}       ${EMPTY}
+${attr_table_data}     ${EMPTY}
+
+
+*** Test Cases ***
+
+Verify Get BIOS Attribute With Invalid Attribute Name
+
+    [Documentation]  Verify get BIOS attribute with invalid attribute name.
+    [Tags]  Verify_Get_BIOS_Attribute_With_Invalid_Attribute_Name
+
+    ${random_attr}=  Generate Random String  8  [LETTERS][NUMBERS]
+    ${pldm_output}=  pldmtool  bios GetBIOSAttributeCurrentValueByHandle -a ${random_attr}
+
+    # Example output:
+    #
+    # pldmtool bios GetBIOSAttributeCurrentValueByHandle -a hjkhkj
+    # Can not find the attribute hjkhkj
+    #
+
+    Should Contain  ${pldm_output}  Can not find the attribute
+
+
+Verify Set BIOS Attribute With Invalid Attribute Name
+
+    [Documentation]  Verify set BIOS attribute with invalid attribute name.
+    [Tags]  Verify_Set_BIOS_Attribute_With_Invalid_Attribute_Name
+
+    ${random_str}=  Generate Random String  8  [LETTERS][NUMBERS]
+    ${pldm_output}=  pldmtool  bios SetBIOSAttributeCurrentValue -a ${random_str} -d ${random_str}
+
+    # Example output:
+    #
+    # pldmtool bios SetBIOSAttributeCurrentValue -a hjkhkj -d 0
+    # Could not find attribute :hjkhkj
+    #
+
+    Should Contain  ${pldm_output}  Could not find attribute
+
+
+Verify Set Invalid Optional Value For BIOS Enumeration Attribute Type
+
+    [Documentation]  Verify set invalid optional value for BIOS enumeration attribute type.
+    [Tags]  Verify_Set_Invalid_Optional_Value_For_BIOS_Enumeration_Attribute_Type
+
+    ${attr_val_data}=  GetBIOSEnumAttributeOptionalValues  ${attr_table_data}
+    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
+    ${enum_attr}=  Evaluate  random.choice(${attr_handles})  modules=random
+
+    # Example output:
+    #
+    # pldmtool bios SetBIOSAttributeCurrentValue -a pvm_os_boot_side -d hhhhhj
+    # Set Attribute Error: It's not a possible value
+    #
+
+    ${pldm_output}=  pldmtool  bios SetBIOSAttributeCurrentValue -a ${enum_attr} -d 0
+    Should Contain  ${pldm_output}  Set Attribute Error
+
+
+Verify Set Out Of Range Integer Value For BIOS Integer Attribute Type
+
+    [Documentation]  Verify set out of range integer value for BIOS integer attribute type.
+    [Tags]  Verify_Set_Out_Of_Range_Integer_Value_For_BIOS_Integer_Attribute_Type
+
+    ${attr_val_data}=  GetBIOSStrAndIntAttributeHandles  BIOSInteger  ${attr_table_data}
+    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
+    ${int_attr}=  Evaluate  random.choice(${attr_handles})  modules=random
+    ${count}=  Evaluate  ${attr_val_data['${int_attr}']["UpperBound"]} + 5
+
+    # Example output:
+    #
+    # pldmtool bios SetBIOSAttributeCurrentValue -a vmi_if_count -d 12
+    # Response Message Error: rc=0,cc=2
+    #
+
+    ${pldm_output}=  pldmtool  bios SetBIOSAttributeCurrentValue -a ${int_attr} -d ${count}
+    Should Contain  ${pldm_output}  Response Message Error
+
+
+Verify Set Out Of Range String Value For BIOS String Attribute Type
+
+    [Documentation]  Verify set out of range string value for BIOS string attribute type.
+    [Tags]  Verify_Set_Out_Of_Range_String_Value_For_BIOS_String_Attribute_Type
+
+    ${attr_val_data}=  GetBIOSStrAndIntAttributeHandles  BIOSString  ${attr_table_data}
+    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
+    ${str_attr}=  Evaluate  random.choice(${attr_handles})  modules=random
+    ${count}=  Evaluate  ${attr_val_data['${str_attr}']["MaximumStringLength"]} + 5
+    ${random_value}=  Generate Random String  ${count}  [LETTERS][NUMBERS]
+
+    # Example output:
+    #
+    # pldmtool bios SetBIOSAttributeCurrentValue -a vmi_if0_ipv4_ipaddr -d 1234566788999
+    # Response Message Error: rc=0,cc=2
+    #
+
+    ${pldm_output}=  pldmtool  bios SetBIOSAttributeCurrentValue -a ${str_attr} -d ${random_value}
+    Should Contain  ${pldm_output}  Response Message Error
+
+
+Verify Set BIOS String Attribute Type
+
+    [Documentation]  Verify set BIOS string attribute type for various BIOS
+    ...              attribute handle with random values with in the range.
+    [Tags]  Verify_Set_BIOS_String_Attribute_Type
+
+    ${attr_val_data}=  GetBIOSStrAndIntAttributeHandles  BIOSString  ${attr_table_data}
+
+    # Example output:
+    #
+    # pldmtool bios SetBIOSAttributeCurrentValue -a vmi_hostname -d BMC
+    # {
+    #     "Response": "SUCCESS"
+    # }
+
+    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
+    FOR  ${i}  IN  @{attr_handles}
+        ${random_value}=  GetRandomBIOSIntAndStrValues  ${i}  ${attr_val_data['${i}']["MaximumStringLength"]}
+        ${attr_val_list}=  Create List
+        Append To List  ${attr_val_list}  ${random_value}
+        Validate Set BIOS Attributes With Optional Values  ${i}  @{attr_val_list}
+    END
+
+
+Verify Set BIOS Integer Attribute Type
+
+    [Documentation]  Verify set BIOS integer attribute type for various BIOS
+    ...              attribute handle with random values with in the range.
+    [Tags]  Verify_Set_BIOS_Integer_Attribute_Type
+
+    ${attr_val_data}=  GetBIOSStrAndIntAttributeHandles  BIOSInteger  ${attr_table_data}
+
+    # Example output:
+    #
+    # pldmtool bios SetBIOSAttributeCurrentValue -a vmi_if_count -d 1
+    # {
+    #     "Response": "SUCCESS"
+    # }
+
+    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
+
+    FOR  ${i}  IN  @{attr_handles}
+        ${random_value}=  GetRandomBIOSIntAndStrValues  ${i}  ${attr_val_data['${i}']["UpperBound"]}
+        ${attr_val_list}=  Create List
+        Append To List  ${attr_val_list}  ${random_value}
+        Validate Set BIOS Attributes With Optional Values  ${i}  @{attr_val_list}
+    END
+
+
+Verify Set BIOS Enumeration Attribute Type
+
+    [Documentation]  Verify set BIOS enumeration attribute type for various BIOS
+    ...              attribute handle with random values with in the range of
+    ...              default optional values.
+    [Tags]  Verify_BIOS_Enumeration_Attribute_Type
+
+    ${attr_val_data}=  GetBIOSEnumAttributeOptionalValues  ${attr_table_data}
+
+    # Example output:
+    #
+    # pldmtool bios SetBIOSAttributeCurrentValue -a pvm_default_os_type -d AIX
+    # {
+    #     "Response": "SUCCESS"
+    # }
+
+    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
+    FOR  ${i}  IN  @{attr_handles}
+        @{attr_val_list}=  Set Variable  ${attr_val_data}[${i}]
+        Validate Set BIOS Attributes With Optional Values  ${i}  @{attr_val_list}
+    END
+
+
+Verify Restore BIOS Attribute Values
+
+    [Documentation]  Restore all BIOS attribute values with its default values and verify.
+    [Tags]  Verify_Restore_BIOS_Attribute_Values
+
+    ${bios_default_data}=  GetBIOSAttrDefaultValues  ${attr_table_data}
+    Validate Set All BIOS Attributes Values  ${bios_default_data}
+
+
+*** Keywords ***
+
+PLDM BIOS Attribute Suite Setup
+
+    [Documentation]  Perform PLDM BIOS attribute suite setup.
+
+    ${pldm_output}=  Pldmtool  bios GetBIOSTable --type AttributeTable
+    Set Global Variable  ${attr_table_data}  ${pldm_output}
+
+    ${data}=  GetBIOSAttrOriginalValues  ${pldm_output}
+    Set Global Variable  ${bios_original_data}  ${data}
+
+
+PLDM BIOS Attribute Suite Cleanup
+
+    [Documentation]  Perform PLDM BIOS attribute suite cleanup.
+
+    Validate Set All BIOS Attributes Values  ${bios_original_data}
+
+
+Validate Set BIOS Attributes With Optional Values
+
+    [Documentation]  Set BIOS attribute with the available attribute handle
+    ...              values and revert back to original attribute handle value.
+    [Arguments]      ${attr_handle}  @{attr_val_list}
+
+    # Description of argument(s):
+    # attr_handle    BIOS attribute handle (e.g. pvm_system_power_off_policy).
+    # attr_val_list  List of the attribute values for the given attribute handle
+    #                (e.g. ['"Power Off"', '"Stay On"', 'Automatic']).
+
+    FOR  ${j}  IN  @{attr_val_list}
+        ${pldm_resp}=  pldmtool  bios SetBIOSAttributeCurrentValue -a ${attr_handle} -d ${j}
+        Valid Value  pldm_resp['Response']  ['SUCCESS']
+
+        # Compare BIOS attribute values after set operation.
+        ${output}=  pldmtool  bios GetBIOSAttributeCurrentValueByHandle -a ${attr_handle}
+        ${value1}=  Convert To String  ${output["CurrentValue"]}
+        ${value2}=  Convert To String  ${j}
+        ${value2}=  Replace String  ${value2}  "  ${EMPTY}
+        Should Be Equal  ${value1.strip()}  ${value2.strip()}
+
+    END
+
+
+Validate Set All BIOS Attributes Values
+
+    [Documentation]  Validate Set BIOS Attributes Values.
+    [Arguments]      ${bios_attr_data}
+
+    # Description of argument(s):
+    # bios_attr_data  Dictionary containing BIOS attribute name and values.
+
+    @{keys}=  Get Dictionary Keys  ${bios_attr_data}
+
+    FOR  ${key}  IN  @{keys}
+        ${pldm_resp}=  pldmtool  bios SetBIOSAttributeCurrentValue -a ${key} -d ${bios_attr_data['${key}']}
+        Valid Value  pldm_resp['Response']  ['SUCCESS']
+
+        # Compare BIOS attribute values after set operation.
+        ${output}=  pldmtool  bios GetBIOSAttributeCurrentValueByHandle -a ${key}
+        ${value1}=  Convert To String  ${output["CurrentValue"]}
+        ${value2}=  Convert To String  ${bios_attr_data['${key}']}
+        ${value2}=  Replace String  ${value2}  "  ${EMPTY}
+        Should Be Equal  ${value1.strip()}  ${value2.strip()}
+    END