1*** Settings ***
2Documentation       This module is for OS checkstop opertions.
3Resource            ../../lib/rest_client.robot
4Resource            ../../lib/utils.robot
5Variables           ../../lib/ras/variables.py
6Library             ../../lib/bmc_ssh_utils.py
7Library             OperatingSystem
8
9*** Keywords ***
10
11Getscom Operations On OS
12    [Documentation]  Executes getscom command on OS with the given
13    ...              input command.
14    [Arguments]      ${input_cmd}
15    # Description of arguments:
16    # input_cmd      -l|--list-chips
17    #                -c|--chip <chip-id> <addr>
18
19    ${output}  ${stderr}  ${rc}=  OS Execute Command  getscom ${input_cmd}
20    Should Be Empty  ${stderr}
21    [Return]  ${output}
22
23Gard Operations On OS
24    [Documentation]  Executes opal-gard command on OS with the given
25    ...              input command.
26    [Arguments]      ${input_cmd}
27    # Description of arguments:
28    # input_cmd      list/clear all/show <gard_record_id>
29
30    ${output}  ${stderr}  ${rc}=  OS Execute Command  opal-gard ${input_cmd}
31    Should Be Empty  ${stderr}
32    [Return]  ${output}
33
34Putscom Operations On OS
35    [Documentation]  Executes putscom command on OS with the given
36    ...              input arguments.
37    [Arguments]      ${proc_chip_id}  ${fru}  ${address}
38    # Description of arguments:
39    # proc_chip_id        Processor ID (e.g '0', '8').
40    # fru            FRU value (e.g. 2011400).
41    # address        Chip address (e.g 4000000000000000).
42
43    ${cmd}=  Catenate  putscom -c 0x${proc_chip_id} 0x${fru} 0x${address}
44    Start Command  ${cmd}
45
46Get ProcChipId From OS
47    [Documentation]  Get processor chip ID values based on the input.
48    [Arguments]      ${chip_type}  ${master_proc_chip}
49    # Description of arguments:
50    # chip_type         The chip type (Processor/Centaur).
51    # master_proc_chip  Processor chip type ('True' or 'False').
52
53    ${cmd}=  Catenate  -l | grep -i ${chip_type} | cut -c1-8
54    ${proc_chip_id}=  Getscom Operations On OS  ${cmd}
55    # Example output:
56    # getscom -l | grep processor | cut -c1-8
57    # 00000008     - False
58    # 00000000     - True
59
60    ${proc_ids}=  Split String  ${proc_chip_id}
61    ${proc_id}=  Run Keyword If  '${master_proc_chip}' == 'True'
62    \  ...  Get From List  ${proc_ids}  1
63    \  ...  ELSE  Get From List  ${proc_ids}  0
64
65    # Example output:
66    # 00000008
67    [Return]  ${proc_id}
68
69Get Core IDs From OS
70    [Documentation]  Get Core IDs corresponding to the input processor chip ID.
71    [Arguments]      ${proc_chip_id}
72    # Description of argument(s):
73    # proc_chip_id        Processor ID (e.g '0', '8').
74
75    ${cmd}=  Catenate  set -o pipefail ; ${probe_cpu_file_path}
76    ...    | grep -i 'CHIP ID: ${proc_chip_id}' | cut -c21-22
77    ${output}  ${stderr}  ${rc}=  OS Execute Command  ${cmd}
78    Should Be Empty  ${stderr}
79    ${core_ids}=  Split String  ${output}
80    # Example output:
81    # ['2', '3', '4', '5', '6']
82    [Return]  ${core_ids}
83
84FIR Address Translation Through HOST
85    [Documentation]  Do FIR address translation through host for given FIR,
86    ...              core value & target type.
87    [Arguments]  ${fir}  ${core_id}  ${target_type}
88    # Description of argument(s):
89    # fir          FIR (Fault isolation register) value (e.g. 2011400).
90    # core_id      Core ID (e.g. 9).
91    # target_type  Target type (e.g. 'EQ', 'EX', 'C').
92
93    ${cmd}=  Catenate  set -o pipefail ; ${addr_translation_file_path} ${fir}
94    ...  ${core_id} | grep -i ${target_type}
95    ${output}  ${stderr}  ${rc}=  OS Execute Command  ${cmd}
96    Should Be Empty  ${stderr}
97    ${translated_addr}=  Split String  ${output}  :${SPACE}0x
98    # Example output:
99    # 0x10010c00
100    [Return]  ${translated_addr[1]}
101
102Inject Error Through HOST
103    [Documentation]  Inject checkstop on processor through HOST.
104    ...              Test sequence:
105    ...              1. Boot To HOST
106    ...              2. Clear any existing gard records
107    ...              3. Inject Error on processor/centaur
108    [Arguments]      ${fir}  ${chip_address}  ${threshold_limit}
109    ...  ${master_proc_chip}=True
110    # Description of argument(s):
111    # fir                 FIR (Fault isolation register) value (e.g. 2011400).
112    # chip_address        chip address (e.g 2000000000000000).
113    # threshold_limit     Threshold limit (e.g 1, 5, 32).
114    # master_proc_chip    Processor chip type (True' or 'False').
115
116    Delete Error Logs
117    Login To OS Host
118    Gard Operations On OS  clear all
119
120    # Fetch processor chip IDs.
121    ${proc_chip_id}=  Get ProcChipId From OS  Processor  ${master_proc_chip}
122
123    ${threshold_limit}=  Convert To Integer  ${threshold_limit}
124    :FOR  ${i}  IN RANGE  ${threshold_limit}
125    \  Run Keyword  Putscom Operations On OS  ${proc_chip_id}  ${fir}
126    ...  ${chip_address}
127    # Adding delay after each error injection.
128    \  Sleep  10s
129    # Adding delay to get error log after error injection.
130    Sleep  120s
131
132Code Update Unrecoverable Error Inject
133    [Documentation]  Inject UE MCACALFIR checkstop on processor through
134    ...   host during PNOR code update.
135
136    Inject Error Through HOST  05010800  4000000000000000  1
137