summaryrefslogtreecommitdiffstats
path: root/src/usr/fapi2/test/fapi2PlatGetVpdOcmbChipTest.C
blob: 49f0384580f8d82e1b4c0fbec619ab25c0661902 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/fapi2/test/fapi2PlatGetVpdOcmbChipTest.C $            */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

#include <fapi2PlatGetVpdOcmbChipTest.H>
#include <plat_vpd_access.H>

// The maximum size of a the EFD buffer
// Ony used if failed to get buffer size
const size_t DEFAULT_MAX_BYTES_BUFFER_SIZE = 128;


void fapi2PlatGetVpdOcmbChipTest::testPlatGetVPD_EFD()
{
    FAPI_INF(">>testGetVPD_EFD");

    if(TARGETING::MODEL_AXONE != TARGETING::targetService().getProcessorModel())
    {
        FAPI_INF("<<testGetVPD_EFD: This is not AXONE. Skipping AXONE tests.");
        return;
    }

    // Find a valid target of type OCMB_CHIP
    TARGETING::TargetHandleList l_ocmbTargetList;
    TARGETING::getAllChips(l_ocmbTargetList, TARGETING::TYPE_OCMB_CHIP, true);
    if (!l_ocmbTargetList.size())
    {
        TS_FAIL("<<testGetVPD_EFD: No valid TYPE_OCMB_CHIP target found. "
                "Can not execute test cases.");
        return;
    }

    // Some useful variables
    size_t l_numTests(0);
    size_t l_numFails(0);
    fapi2::ReturnCode l_rc;
    fapi2::VPDInfo<fapi2::TARGET_TYPE_OCMB_CHIP> l_vpdInfo(fapi2::EFD);


    /// Test case 1
    // Test with a "bad" target
    ++l_numTests;
    do
    {
        fapi2::Target<fapi2::TARGET_TYPE_OCMB_CHIP> l_ocmbChipTarget;
        uint8_t* o_efdBuffer(nullptr);

        l_rc = platGetVPD(l_ocmbChipTarget, l_vpdInfo, o_efdBuffer);

        if (l_rc == fapi2::FAPI2_RC_SUCCESS)
        {
            TS_FAIL("testGetVPD_EFD: Test case 1 failed: OCMB_CHIP target is a "
                    "nullptr but platGetVPD returned SUCCESS.");

            ++l_numFails;
            break;
        }

    } while(0);


    /// Test case 2
    // Test with an invalid target.  If no invalid target is found, then move
    // on - do not fail the test.  This test is an unlikely scenario and not
    // so critical that it needs to fail if unable to perform.
    do
    {
        // Get a list of targets
        TARGETING::TargetRangeFilter l_targetList(
                                     TARGETING::targetService().begin(),
                                     TARGETING::targetService().end(),
                                     NULL);

        // Iterate thru the list looking for the first NON OCMB_CHIP target
        for ( ; l_targetList; ++l_targetList)
        {
            if ( TARGETING::TYPE_OCMB_CHIP !=
                 (*l_targetList)->getAttr<TARGETING::ATTR_TYPE>() )
            {
                // Found first non OCMB_CHIP target, break out and use it
                break;
            }
        }

        // l_targetList is just an iterator that gets advanced in a container.
        // If that iterator is still valid then we can safely assume that
        // it points to a non OCMB_CHIP target
        if (l_targetList)
        {
            ++l_numTests;
            fapi2::Target<fapi2::TARGET_TYPE_OCMB_CHIP> l_ocmbChipTarget =
                                                                 *l_targetList;
            uint8_t* o_efdBuffer(nullptr);

            l_rc = platGetVPD(l_ocmbChipTarget, l_vpdInfo, o_efdBuffer);

            if (l_rc == fapi2::FAPI2_RC_SUCCESS)
            {
                TS_FAIL("testGetVPD_EFD: Test case 2 failed: OCMB_CHIP target "
                        "is invalid (the target is being spoofed with a "
                        "different type) but platGetVPD returned SUCCESS.");

                ++l_numFails;
                break;
            } // end if (l_rc == fapi2::FAPI2_RC_SUCCESS)
        }  // end if (l_targetList)
    } while (0);


    // Initialize input data
    fapi2::Target<fapi2::TARGET_TYPE_OCMB_CHIP> l_ocmbChipTarget =
                                                          l_ocmbTargetList[0];
    uint8_t* o_efdBuffer{nullptr};


    /// Test case 3
    // Test with NULL buffer
    ++l_numTests;
    do
    {
        // Initialize the essential input variables
        l_vpdInfo.iv_size = 0;

        // Make the platGetVPD call with buffer size 0 and buffer set at nullptr
        l_rc = platGetVPD(l_ocmbChipTarget, l_vpdInfo, o_efdBuffer);

        // Error if call not successful and size is 0
        if (l_rc != fapi2::FAPI2_RC_SUCCESS || !l_vpdInfo.iv_size)
        {
            TS_FAIL("testGetVPD_EFD: Test case 3 failed: Failed to return a "
                     "buffer size.");

            ++l_numFails;
            break;
        }
    } while(0);

    // If no buffer size returned from previous call then set size to default
    if (!l_vpdInfo.iv_size)
    {
        l_vpdInfo.iv_size = DEFAULT_MAX_BYTES_BUFFER_SIZE;
    }

    // Create the memory for the buffer
    o_efdBuffer = new uint8_t[l_vpdInfo.iv_size];

    /// Test case 4
    // Test with data that will not find a match on frequency
    // and enable ffdc set to false.
    ++l_numTests;
    do
    {
        // Initialize the other input variables
        l_vpdInfo.iv_omi_freq_mhz = 19200;
        l_vpdInfo.iv_rank = 0;
        l_vpdInfo.iv_is_config_ffdc_enabled = false;

        // Make the platGetVPD call
        l_rc = platGetVPD(l_ocmbChipTarget, l_vpdInfo, o_efdBuffer);

        if (l_rc == fapi2::FAPI2_RC_SUCCESS)
        {
            TS_FAIL("testGetVPD_EFD: Test case 4 failed: Request for EFD with "
                    "frequency %d and rank %d should have failed.",
                    l_vpdInfo.iv_omi_freq_mhz, l_vpdInfo.iv_rank);

            ++l_numFails;
            break;
        }
    } while(0);


    /// Test case 5
    // Test with data that will not find a match on frequency
    // and enable ffdc set to true.
    ++l_numTests;
    do
    {
        // Initialize the other input variables
        l_vpdInfo.iv_omi_freq_mhz = 25600;
        l_vpdInfo.iv_rank = 2;
        l_vpdInfo.iv_is_config_ffdc_enabled = true;

        // Make the platGetVPD call
        l_rc = platGetVPD(l_ocmbChipTarget, l_vpdInfo, o_efdBuffer);

        if (l_rc == fapi2::FAPI2_RC_SUCCESS)
        {
            TS_FAIL("testGetVPD_EFD: Test case 5 failed: Request for EFD with "
                    "frequency %d and rank %d should have failed.",
                    l_vpdInfo.iv_omi_freq_mhz, l_vpdInfo.iv_rank);

            ++l_numFails;
            break;
        }
    } while(0);


    /// Test case 6
    // Test when the size of the output buffer is insufficient to hold
    // the found EFD block data
    ++l_numTests;
    do
    {
        // Initialize the other input variables
        l_vpdInfo.iv_omi_freq_mhz = 21330;
        l_vpdInfo.iv_rank = 0;
        l_vpdInfo.iv_is_config_ffdc_enabled = false;

        // Shrink the buffer size to be less than size of returning data
        --l_vpdInfo.iv_size;

        // Make the platGetVPD call
        l_rc = platGetVPD(l_ocmbChipTarget, l_vpdInfo, o_efdBuffer);

        if (l_rc == fapi2::FAPI2_RC_SUCCESS)
        {
            TS_FAIL("testGetVPD_EFD: Test case 6 failed: Size of buffer (%d) "
                    "is inadequate to hold returning data, size (%d).",
                    l_vpdInfo.iv_size, (l_vpdInfo.iv_size + 1));

            ++l_numFails;
            break;
        }
    } while(0);


    /// Test case 7
    // Test when the size of the output buffer is greater than
    // the size of the found EFD block data
    ++l_numTests;
    do
    {
        // Initialize the other input variables
        l_vpdInfo.iv_omi_freq_mhz = 21330;
        l_vpdInfo.iv_rank = 0;
        l_vpdInfo.iv_is_config_ffdc_enabled = false;

        // Increase the buffer size to be greater than size of returning data
        ++l_vpdInfo.iv_size;

        // Make the platGetVPD call
        l_rc = platGetVPD(l_ocmbChipTarget, l_vpdInfo, o_efdBuffer);

        if (l_rc != fapi2::FAPI2_RC_SUCCESS)
        {
            TS_FAIL("testGetVPD_EFD: Test case 7 failed: Failed with known "
                     "good data - frequency(%d), master rank(%d) "
                     "and buffer size(%d)",
                     l_vpdInfo.iv_omi_freq_mhz,
                     l_vpdInfo.iv_rank,
                     l_vpdInfo.iv_size);

            ++l_numFails;
            break;
        }
    } while(0);


    /// Test case 8
    // Test with data that is guaranteed to find a match 1
    ++l_numTests;
    do
    {
        // Initialize the other input variables
        l_vpdInfo.iv_omi_freq_mhz = 25600;
        l_vpdInfo.iv_rank = 0;
        l_vpdInfo.iv_is_config_ffdc_enabled = true;

        // Make the platGetVPD call to find the EFD data block that matches
        // given data
        l_rc = platGetVPD(l_ocmbChipTarget, l_vpdInfo, o_efdBuffer);

        if (l_rc != fapi2::FAPI2_RC_SUCCESS)
        {
            TS_FAIL("testGetVPD_EFD: Test case 8 failed: Failed with known "
                     "good data - frequency(%d), master rank(%d) "
                     "and buffer size(%d)",
                     l_vpdInfo.iv_omi_freq_mhz,
                     l_vpdInfo.iv_rank,
                     l_vpdInfo.iv_size);

            ++l_numFails;
            break;
        }
    } while(0);


    /// Test case 9
    // Test with data that is guaranteed to find a match 2
    ++l_numTests;
    do
    {
        // Initialize the other input variables
        l_vpdInfo.iv_omi_freq_mhz = 23460;
        l_vpdInfo.iv_rank = 0;
        l_vpdInfo.iv_is_config_ffdc_enabled = true;

        // Make the platGetVPD call to find the EFD data block that matches
        // given data
        l_rc = platGetVPD(l_ocmbChipTarget, l_vpdInfo, o_efdBuffer);


        if (l_rc != fapi2::FAPI2_RC_SUCCESS)
        {
            TS_FAIL("testGetVPD_EFD: Test case 9 failed: Failed with known "
                     "good data - frequency(%d), master rank(%d) "
                     "and buffer size(%d)",
                     l_vpdInfo.iv_omi_freq_mhz,
                     l_vpdInfo.iv_rank,
                     l_vpdInfo.iv_size);

            ++l_numFails;
            break;
        }
    } while(0);


    /// Test case 10
    // Test with data that is guaranteed to find a match 3
    ++l_numTests;
    do
    {
        // Initialize the other input variables
        l_vpdInfo.iv_omi_freq_mhz = 21330;
        l_vpdInfo.iv_rank = 0;
        l_vpdInfo.iv_is_config_ffdc_enabled = true;

        // Make the platGetVPD call to find the EFD data block that matches
        // given data
        l_rc = platGetVPD(l_ocmbChipTarget, l_vpdInfo, o_efdBuffer);

        if (l_rc != fapi2::FAPI2_RC_SUCCESS)
        {
            TS_FAIL("testGetVPD_EFD: Test case 10 failed: Failed with known "
                     "good data - frequency(%d), master rank(%d) "
                     "and buffer size(%d)",
                     l_vpdInfo.iv_omi_freq_mhz,
                     l_vpdInfo.iv_rank,
                     l_vpdInfo.iv_size);

            ++l_numFails;
            break;
        }
    } while(0);


    // Clean up memory
    delete []o_efdBuffer;
    o_efdBuffer = nullptr;

    FAPI_INF("<<testGetVPD_EFD: Test Complete. %d/%d fails",
             l_numFails, l_numTests);
};  // end void fapi2PlatGetVpdOcmbChipTest::testPlatGetVPD_EFD()


OpenPOWER on IntegriCloud