Enable basic infrastructure for PLDM testing

What infrastructure support is enabled
     - Added keywords to run pldm command.
     - Added basic test cases for base PLDM commands.

Change-Id: Ic821415c2bb29cee231093db614f0787c9faee57
Signed-off-by: Rahul Maheshwari <rahulmaheshwari@in.ibm.com>
diff --git a/data/pldm_variables.py b/data/pldm_variables.py
index ab51392..b2e9e6e 100755
--- a/data/pldm_variables.py
+++ b/data/pldm_variables.py
@@ -4,6 +4,7 @@
 Contains PLDM-related constants.
 """
 
+
 # PLDM types.
 PLDM_TYPE_BASE = {'VALUE': '00', 'STRING': 'base'}
 PLDM_TYPE_PLATFORM = {'VALUE': '02', 'STRING': 'platform'}
@@ -82,7 +83,7 @@
 
 # PLDM command format.
 
-CMD_GETPLDMTYPES = 'pldmtool base GetPLDMTypes'
+CMD_GETPLDMTYPES = 'base GetPLDMTypes'
 
 '''
 e.g. : GetPLDMVersion usage
@@ -94,7 +95,7 @@
 base->0,platform->2,bios->3,fru->4
 
 '''
-CMD_GETPLDMVERSION = 'pldmtool base GetPLDMVersion -t %s'
+CMD_GETPLDMVERSION = 'base GetPLDMVersion -t %s'
 
 '''
 e.g. : PLDM raw command usage
@@ -104,10 +105,13 @@
 pldm raw -d 0x<header> 0x<pldm_type> 0x<pldm_cmd_type> 0x<payload_data>
 '''
 
-CMD_PLDMTOOL_RAW = 'pldmtool raw -d 0x80' + '0x%s' + ' ' + '0x%s'
+CMD_PLDMTOOL_RAW = 'raw -d 0x80' + '0x%s' + ' ' + '0x%s'
 
 
 # PLDM command payload data.
 
 PAYLOAD_GetPLDMVersion = \
     ' 0x00 0x00 0x00 0x00 0x%s 0x%s'    # %(TransferOperationFlag, PLDMType)
+
+
+PLDM_SUPPORTED_TYPES = ['base', 'platform', 'bios']
diff --git a/lib/pldm_utils.py b/lib/pldm_utils.py
new file mode 100644
index 0000000..a6a8aee
--- /dev/null
+++ b/lib/pldm_utils.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+
+r"""
+PLDM functions.
+"""
+
+import re
+import var_funcs as vf
+import func_args as fa
+import bmc_ssh_utils as bsu
+
+
+def pldmtool(option_string, parse_results=1, **bsu_options):
+    r"""
+    Run pldmtool on the BMC with the caller's option string and return the result.
+
+    Example:
+
+    ${pldm_results}=  Pldmtool  base GetPLDMTypes
+    Rprint Vars  pldm_results
+
+    pldm_results:
+      [request_message]:                              08 01 80 00 04
+      [success_in_creating_the_socket]:               RC = 3
+      [success_in_connecting_to_socket]:              RC = 0
+      [success_in_sending_message_type_as_pldm_to_mctp]:RC = 0
+      [write_to_socket_successful]:                   RC = 5
+      [total_length]:                                 14
+      [loopback_response_message]:                    08 01 80 00 04
+      [on_first_recv(),response_==_request]:          RC = 0
+      [shutdown_socket_successful]:                   RC = 0
+      [response_message]:                             08 01 00 00 04 00 0d 00 00 00 00 00 00 00
+      [supported_types]:
+        [raw]:
+          [0]:                                        0
+          [1]:                                        2
+          [2]:                                        3
+        [text]:
+          [0]:                                        base
+          [1]:                                        platform
+          [2]:                                        bios
+
+    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
+                                    pldmtool output.
+    bsu_options                     Options to be passed directly to bmc_execute_command.  See its prolog for
+                                    details.
+    """
+
+    # This allows callers to specify arguments in python style (e.g. print_out=1 vs. print_out=${1}).
+    bsu_options = fa.args_to_objects(bsu_options)
+
+    stdout, stderr, rc = bsu.bmc_execute_command('pldmtool ' + option_string, **bsu_options)
+
+    if parse_results:
+        # Remove linefeeds following colons.
+        stdout = re.sub(":\n", ":", stdout)
+        # Remove first line (e.g. "Encode request successfully").
+        stdout = re.sub("^.*\\n", "", stdout)
+        result = vf.key_value_outbuf_to_dict(stdout)
+        if 'supported_types' in result:
+            # 'supported types' begins like this:
+            # 0(base) 2(platform) 3(bios)
+            # Parsing it to look like it does in the example above.
+            supported_types = {'raw': [], 'text': []}
+            for entry in result['supported_types'].split(" "):
+                record = entry.split("(")
+                supported_types['raw'].append(record[0])
+                supported_types['text'].append(record[1].rstrip(")"))
+            result['supported_types'] = supported_types
+        return result
+
+    return stdout
diff --git a/pldm/test_pldm_base.robot b/pldm/test_pldm_base.robot
new file mode 100644
index 0000000..77bfae7
--- /dev/null
+++ b/pldm/test_pldm_base.robot
@@ -0,0 +1,55 @@
+*** Settings ***
+
+Documentation    Module to test PLDM base commands.
+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
+
+
+*** Test Cases ***
+
+Verify Get PLDM Types
+    [Documentation]  Verify supported PLDM types.
+    [Tags]  Verify_Get_PLDM_Types
+
+    ${pldm_output}=  Pldmtool  base GetPLDMTypes
+    Valid List  pldm_output['supported_types']['text']  required_values=${PLDM_SUPPORTED_TYPES}
+
+
+Verify Get PLDM Version For Base
+    [Documentation]  Verify supported PLDM version for base type.
+    [Tags]  Verify_Get_PLDM_Version_For_Base
+
+    ${pldm_cmd}=  Evaluate  $CMD_GETPLDMVERSION % 'base'
+    ${pldm_output}=  Pldmtool  ${pldm_cmd}
+    Valid Value  pldm_output['type_0(base)']  ${VERSION_BASE['STRING']}
+
+
+Verify Get PLDM Version For Platform
+    [Documentation]  Verify supported PLDM version for platform type.
+    [Tags]  Verify_Get_PLDM_Version_For_Platform
+
+    ${pldm_cmd}=  Evaluate  $CMD_GETPLDMVERSION % 'platform'
+    ${pldm_output}=  Pldmtool  ${pldm_cmd}
+    Valid Value  pldm_output['type_2(platform)']  ${VERSION_PLATFORM['STRING']}
+
+
+Verify Get PLDM Version For BIOS
+    [Documentation]  Verify supported PLDM version for BIOS type.
+    [Tags]  Verify_Get_PLDM_Version_For_BIOS
+
+    ${pldm_cmd}=  Evaluate  $CMD_GETPLDMVERSION % 'bios'
+    ${pldm_output}=  Pldmtool  ${pldm_cmd}
+    Valid Value  pldm_output['type_3(bios)']  ${VERSION_BIOS['STRING']}
+
+
+Verify Get PLDM Version For FRU
+    [Documentation]  Verify supported PLDM version for FRU type.
+    [Tags]  Verify_Get_PLDM_Version_For_FRU
+
+    ${pldm_cmd}=  Evaluate  $CMD_GETPLDMVERSION % 'fru'
+    ${pldm_output}=  Pldmtool  ${pldm_cmd}
+    Valid Value  pldm_output['type_4(fru)']  ${VERSION_FRU['STRING']}