Automation of Sanity scenarios

Change-Id: I73b585c292aa53fcb64c1778b2264652ba619501
Signed-off-by: Sridevi Ramesh <sridevra@in.ibm.com>
diff --git a/lib/ras/host_utils.robot b/lib/ras/host_utils.robot
index a4f2cee..8e58869 100755
--- a/lib/ras/host_utils.robot
+++ b/lib/ras/host_utils.robot
@@ -36,13 +36,13 @@
 Putscom Operations On OS
     [Documentation]  Executes putscom command on OS with the given
     ...              input arguments.
-    [Arguments]      ${proc_chip_id}  ${fru}  ${address}
+    [Arguments]      ${proc_chip_id}  ${fir_address}  ${value}
     # Description of arguments:
     # proc_chip_id        Processor ID (e.g '0', '8').
-    # fru            FRU value (e.g. 2011400).
-    # address        Chip address (e.g 4000000000000000).
+    # fir_address         FIR (Fault isolation register) value (e.g. 2011400).
+    # value               (e.g 4000000000000000).
 
-    ${cmd}=  Catenate  putscom -c 0x${proc_chip_id} 0x${fru} 0x${address}
+    ${cmd}=  Catenate  putscom -c 0x${proc_chip_id} 0x${fir_address} 0x${value}
     Start Command  ${cmd}
 
 Get ProcChipId From OS
@@ -85,13 +85,13 @@
 FIR Address Translation Through HOST
     [Documentation]  Do FIR address translation through host for given FIR,
     ...              core value & target type.
-    [Arguments]  ${fir}  ${core_id}  ${target_type}
+    [Arguments]  ${fir_address}  ${core_id}  ${target_type}
     # Description of argument(s):
-    # fir          FIR (Fault isolation register) value (e.g. 2011400).
-    # core_id      Core ID (e.g. 9).
-    # target_type  Target type (e.g. 'EQ', 'EX', 'C').
+    # fir_address     FIR (Fault isolation register) value (e.g. 2011400).
+    # core_id         Core ID (e.g. 9).
+    # target_type     Target type (e.g. 'EQ', 'EX', 'C').
 
-    ${cmd}=  Catenate  set -o pipefail ; ${addr_translation_file_path} ${fir}
+    ${cmd}=  Catenate  set -o pipefail ; ${addr_translation_file_path} ${fir_address}
     ...  ${core_id} | grep -i ${target_type}
     ${output}  ${stderr}  ${rc}=  OS Execute Command  ${cmd}
     ${translated_addr}=  Split String  ${output}  :${SPACE}0x
@@ -106,11 +106,11 @@
     ...              1. Boot To HOST.
     ...              2. Clear any existing gard records.
     ...              3. Inject Error on processor.
-    [Arguments]      ${fir}  ${chip_address}  ${threshold_limit}
+    [Arguments]      ${fir_address}  ${value}  ${threshold_limit}
     ...  ${master_proc_chip}=True
     # Description of argument(s):
-    # fir                 FIR (Fault isolation register) value (e.g. 2011400).
-    # chip_address        chip address (e.g 2000000000000000).
+    # fir_address         FIR (Fault isolation register) value (e.g. 2011400).
+    # value               (e.g 2000000000000000).
     # threshold_limit     Threshold limit (e.g 1, 5, 32).
     # master_proc_chip    Processor chip type (True' or 'False').
 
@@ -124,8 +124,8 @@
 
     ${threshold_limit}=  Convert To Integer  ${threshold_limit}
     :FOR  ${count}  IN RANGE  ${threshold_limit}
-    \  Run Keyword  Putscom Operations On OS  ${proc_chip_id}  ${fir}
-    ...  ${chip_address}
+    \  Run Keyword  Putscom Operations On OS  ${proc_chip_id}  ${fir_address}
+    ...  ${value}
     # Adding delay after each error injection.
     \  Sleep  10s
     # Adding delay to get error log after error injection.
@@ -171,19 +171,6 @@
     ${opal_prd_state}=  Is Opal-PRD Service Enabled
     Should Contain  ${opal_prd_state}  enabled
 
-BMC Putscom
-    [Documentation]  Executes putscom command through BMC.
-
-    [Arguments]      ${proc_chip_id}  ${fru}  ${chip_address}
-
-    # Description of argument(s):
-    # proc_chip_id        Processor ID (e.g '0', '8').
-    # fru                 FRU (field replaceable unit) (e.g. '2011400').
-    # chip_address        Chip address (e.g. '4000000000000000').
-
-    ${cmd}=  Catenate  pdbg -d p9w -p${proc_chip_id} putscom 0x${fru} 0x${chip_address}
-
-    BMC Execute Command  ${cmd}
 
 Inject Error Through BMC
     [Documentation]  Inject checkstop on multiple targets like
@@ -192,11 +179,11 @@
     ...              1. Boot To HOST.
     ...              2. Clear any existing gard records.
     ...              3. Inject Error on processor.
-    [Arguments]      ${fir}  ${chip_address}  ${threshold_limit}
+    [Arguments]      ${fir_address}  ${value}  ${threshold_limit}
     ...  ${master_proc_chip}=True
     # Description of argument(s):
-    # fir                 FIR (Fault isolation register) value (e.g. '2011400').
-    # chip_address        Chip address (e.g. '2000000000000000').
+    # fir_address         FIR (Fault isolation register) value (e.g. '2011400').
+    # value               (e.g. '2000000000000000').
     # threshold_limit     Recoverable error threshold limit (e.g. '1', '5', '32').
 
     Delete Error Logs
@@ -207,8 +194,7 @@
 
     ${threshold_limit}=  Convert To Integer  ${threshold_limit}
     :FOR  ${count}  IN RANGE  ${threshold_limit}
-    \  BMC Putscom  0  ${fir}
-    ...  ${chip_address}
+    \  Pdbg  -p0 putscom 0x${fir_address} 0x${value}
     # Adding delay after each error injection.
     \  Sleep  10s
     # Adding delay to get error log after error injection.
@@ -223,10 +209,10 @@
     ...              2. Clear any existing gard records.
     ...              3. Power off HOST and Boot.
     ...              4. Inject Error on processor through BMC.
-    [Arguments]      ${fir}  ${chip_address}
+    [Arguments]      ${fir_address}  ${value}
     # Description of argument(s):
-    # fir                 FIR (Fault isolation register) value (e.g. '2011400').
-    # chip_address        Chip address (e.g. '2000000000000000').
+    # fir_address    FIR (Fault isolation register) value (e.g. '2011400').
+    # value          (e.g. '2000000000000000').
 
     Delete Error Logs
 
@@ -244,7 +230,7 @@
     ...  Shell Cmd  grep 'ISTEP *14' ${EXECDIR}/esol.log  quiet=1
     ...  print_output=0  show_err=0  ignore_err=0
 
-    BMC Putscom  0  ${fir}  ${chip_address}
+    Pdbg  -p0 putscom 0x${fir_address} 0x${value}
     # Adding delay to get error log after error injection.
     Sleep  10s
 
diff --git a/lib/ras/variables.py b/lib/ras/variables.py
index 538403f..4525ef3 100644
--- a/lib/ras/variables.py
+++ b/lib/ras/variables.py
@@ -83,3 +83,6 @@
 # Address translation files
 probe_cpu_file_path = '/root/probe_cpus.sh'
 addr_translation_file_path = '/root/scom_addr_p9.sh'
+
+cfam_address = "2801"
+mem_address = "8208000"
diff --git a/lib/utils.py b/lib/utils.py
index 2443bdd..0049cca 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -360,3 +360,21 @@
 
     out_buf, stderr, rc = bsu.os_execute_command('cat /etc/os-release')
     return vf.key_value_outbuf_to_dict(out_buf, delim="=", strip='"')
+
+
+def pdbg(option_string, **bsu_options):
+    r"""
+    Run pdbg on the BMC with the caller's option string and return the output.
+
+    Description of argument(s):
+    option_string                   A string of options which are to be processed by the pdbg command.
+    bsu_options                     Options to be passed directly to bmc_execute_command.  See its prolog for
+                                    details.
+    """
+
+    # Default print_out to 1.
+    if 'print_out' not in bsu_options:
+        bsu_options['print_out'] = 1
+
+    stdout, stderr, rc = bsu.bmc_execute_command('pdbg ' + option_string, **bsu_options)
+    return stdout
diff --git a/openpower/ras/ras_utils.robot b/openpower/ras/ras_utils.robot
index d092106..3113b3f 100755
--- a/openpower/ras/ras_utils.robot
+++ b/openpower/ras/ras_utils.robot
@@ -53,18 +53,18 @@
     ...              2. Check If HOST is running.
     ...              3. Verify error log entry & signature description.
     ...              4. Verify & clear gard records.
-    [Arguments]      ${interface_type}  ${fir}  ${chip_address}  ${threshold_limit}
+    [Arguments]      ${interface_type}  ${fir_address}  ${value}  ${threshold_limit}
     ...              ${signature_desc}  ${log_prefix}
     # Description of argument(s):
     # interface_type      Inject error through 'BMC' or 'HOST'.
-    # fir                 FIR (Fault isolation register) value (e.g. 2011400).
-    # chip_address        Chip address (e.g 2000000000000000).
+    # fir_address         FIR (Fault isolation register) value (e.g. 2011400).
+    # value               (e.g 2000000000000000).
     # threshold_limit     Threshold limit (e.g 1, 5, 32).
     # signature_desc      Error log signature description.
     # log_prefix          Log path prefix.
 
     Run Keyword  Inject Error Through ${interface_type}
-    ...  ${fir}  ${chip_address}  ${threshold_limit}  ${master_proc_chip}
+    ...  ${fir_address}  ${value}  ${threshold_limit}  ${master_proc_chip}
 
     Is Host Running
     ${output}=  Gard Operations On OS  list
@@ -83,12 +83,12 @@
     ...              3. Verify & clear gard records.
     ...              4. Verify error log entry & signature description.
     ...              5. Verify & clear dump entry.
-    [Arguments]      ${interface_type}  ${fir}  ${chip_address}  ${threshold_limit}
+    [Arguments]      ${interface_type}  ${fir_address}  ${value}  ${threshold_limit}
     ...              ${signature_desc}  ${log_prefix}  ${bmc_reboot}=${0}
     # Description of argument(s):
     # interface_type      Inject error through 'BMC' or 'HOST'.
-    # fir                 FIR (Fault isolation register) value (e.g. 2011400).
-    # chip_address        Chip address (e.g 2000000000000000).
+    # fir_address         FIR (Fault isolation register) value (e.g. 2011400).
+    # value               (e.g 2000000000000000).
     # threshold_limit     Threshold limit (e.g 1, 5, 32).
     # signature_desc      Error Log signature description.
     #                     (e.g 'mcs(n0p0c0) (MCFIR[0]) mc internal recoverable')
@@ -96,7 +96,7 @@
     # bmc_reboot          Do bmc reboot If bmc_reboot is set.
 
     Run Keyword  Inject Error Through ${interface_type}
-    ...  ${fir}  ${chip_address}  ${threshold_limit}  ${master_proc_chip}
+    ...  ${fir_address}  ${value}  ${threshold_limit}  ${master_proc_chip}
 
     # Do BMC Reboot after error injection.
     Run Keyword If  ${bmc_reboot}  Run Keywords
@@ -115,9 +115,9 @@
 
 Fetch FIR Address Translation Value
     [Documentation]  Fetch FIR address translation value through HOST.
-    [Arguments]  ${fir}  ${target_type}
+    [Arguments]  ${fir_address}  ${target_type}
     # Description of argument(s):
-    # fir                  FIR (Fault isolation register) value (e.g. '2011400').
+    # fir_address          FIR (Fault isolation register) value (e.g. '2011400').
     # core_id              Core ID (e.g. '9').
     # target_type          Target type (e.g. 'EX', 'EQ', 'C').
 
@@ -140,7 +140,7 @@
     ${core_ids_sub_list}=   Evaluate  random.sample(${core_ids}, 1)  random
     ${core_id}=  Get From List  ${core_ids_sub_list}  0
     ${translated_fir_addr}=  FIR Address Translation Through HOST
-    ...  ${fir}  ${core_id}  ${target_type}
+    ...  ${fir_address}  ${core_id}  ${target_type}
 
     [Return]  ${translated_fir_addr}
 
@@ -204,14 +204,14 @@
     ...              2. Check If HOST is rebooted and running.
     ...              3. Verify error log entry & signature description.
     ...              4. Verify & clear gard records.
-    [Arguments]      ${fir}  ${chip_address}  ${signature_desc}  ${log_prefix}
+    [Arguments]      ${fir_address}  ${value}  ${signature_desc}  ${log_prefix}
     # Description of argument(s):
-    # fir                 FIR (Fault isolation register) value (e.g. 2011400).
-    # chip_address        Chip address (e.g 2000000000000000).
+    # fir_address         FIR (Fault isolation register) value (e.g. 2011400).
+    # value               (e.g 2000000000000000).
     # signature_desc      Error log signature description.
     # log_prefix          Log path prefix.
 
-    Inject Error Through BMC At HOST Boot  ${fir}  ${chip_address}
+    Inject Error Through BMC At HOST Boot  ${fir_address}  ${value}
 
     Wait Until Keyword Succeeds  500 sec  20 sec  Is Host Rebooted
     Wait for OS
diff --git a/openpower/ras/test_sanity.robot b/openpower/ras/test_sanity.robot
new file mode 100644
index 0000000..dbbaa77
--- /dev/null
+++ b/openpower/ras/test_sanity.robot
@@ -0,0 +1,34 @@
+*** Settings ***
+Documentation    Test RAS sanity scenarios.
+
+Resource        ../../lib/openbmc_ffdc.robot
+Resource        ../../lib/openbmc_ffdc_utils.robot
+Resource        ../../lib/openbmc_ffdc_methods.robot
+Resource        ../../lib/ras/host_utils.robot
+Resource        ../../lib/utils.py
+Resource        ../../openpower/ras/ras_utils.robot
+Variables       ../../lib/ras/variables.py
+Variables       ../../data/variables.py
+
+Suite Setup      REST Power On
+Test Setup       Printn
+Test Teardown    FFDC On Test Case Fail
+
+
+*** Variables ***
+${proc_chip_id}    0
+
+# mention count to read system memory.
+${count}           128
+
+*** Test Cases ***
+
+Test BMC Getscom
+    ${value}=  Get From Dictionary  ${ERROR_INJECT_DICT}  MCACALIFIR_RECV1
+    Pdbg  -p${proc_chip_id} getscom 0x${value[0]}
+
+Test BMC Getcfam
+    Pdbg  -p${proc_chip_id} getcfam 0x${cfam_address}
+
+Test BMC Getmem
+    Pdbg  -p${proc_chip_id} getmem 0x${mem_address} ${count}