summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/test/fapiwinkletest.H
blob: 36503293296a0b4dd71269746545185b82df1535 (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
/*  IBM_PROLOG_BEGIN_TAG
 *  This is an automatically generated prolog.
 *
 *  $Source: src/usr/hwpf/test/fapiwinkletest.H $
 *
 *  IBM CONFIDENTIAL
 *
 *  COPYRIGHT International Business Machines Corp. 2012
 *
 *  p1
 *
 *  Object Code Only (OCO) source materials
 *  Licensed Internal Code Source Materials
 *  IBM HostBoot Licensed Internal Code
 *
 *  The source code for this program is not published or other-
 *  wise divested of its trade secrets, irrespective of what has
 *  been deposited with the U.S. Copyright Office.
 *
 *  Origin: 30
 *
 *  IBM_PROLOG_END_TAG
 */

#ifndef __FAPIWINKLETEST_H
#define __FAPIWINKLETEST_H

/**
 *  @file fapiwinkletest.H
 *
 *  @brief Test cases for winkle HWP utilities.
*/

#include <cxxtest/TestSuite.H>

#include    <fapi.H>
#include    <fapiPlatHwpInvoker.H>
#include    <hwpf/fapi/fapiMvpdAccess.H>

#include    <targeting/common/commontargeting.H>
#include    <targeting/common/utilFilter.H>

#include    <RepairRingFunc.H>

using namespace     fapi;
using   namespace   TARGETING;

class FapiWinkleTest: public CxxTest::TestSuite
{
public:

    /**
     * @brief   call fapiGetMvpdPdr to fetch a #R record.
     *
     */
    void    testGetMvpdPdr()
    {
        fapi::ReturnCode    l_fapirc( fapi::FAPI_RC_SUCCESS );
        uint8_t             *l_pdRRecord            =   NULL;
        uint32_t            l_pdRLen                =   0;

        // test value, coreesponds to procmvpd.dat:e23067dae839f5b434ec12b5c86d2ae4fbb51259
        //  @todo change test when we get valid data in procpore.dat
        const   uint32_t    MVPD_PDR_TEST_SIZE      =   0x5f74;


        TS_TRACE( "testGetMvpdPdr entry" );

        TARGETING::TargetHandleList l_cpuTargetList;
        getAllChips(l_cpuTargetList, TYPE_PROC);

        // loop thru all the cpu's
        for ( uint8_t l_cpuNum=0; l_cpuNum < l_cpuTargetList.size(); l_cpuNum++ )
        {
            //  make a local copy of the CPU target
            TARGETING::Target*  l_cpu_target = l_cpuTargetList[l_cpuNum];

            //  dump physical path to target
            EntityPath l_path;
            l_path  =   l_cpu_target->getAttr<ATTR_PHYS_PATH>();
            l_path.dump();

            // cast OUR type of target to a FAPI type of target.
            fapi::Target l_fapi_cpu_target(
                                          TARGET_TYPE_PROC_CHIP,
                                          reinterpret_cast<void *>
                                          (const_cast<TARGETING::Target*>(l_cpu_target)) );

            TS_TRACE( "call fapiGetMvpdPdr with NULL pointer" );

            //  call fapiGetMvpdPdr once with a NULL pointer to get the buffer size
            //  should return no error now.
            l_fapirc = fapiGetMvpdPdr(  l_fapi_cpu_target,
                                        NULL,
                                        l_pdRLen );
            if ( l_fapirc != fapi::FAPI_RC_SUCCESS )
            {
                TS_FAIL( "testGetMvpdPdr:  expected FAPI_RC_SUCCESS" );
                return;
            }

            //  this will change when MVPD is changed, and will need to be changed
            //  above.
            if ( l_pdRLen   !=  MVPD_PDR_TEST_SIZE )
            {
                TS_FAIL( "testGetMvpdPdr: expected size = 0x%x, received 0x%x",
                         MVPD_PDR_TEST_SIZE,
                         l_pdRLen );
                return;
            }

            //  do a malloc instead of a new just for variety
            l_pdRRecord =   reinterpret_cast<uint8_t *>(malloc(l_pdRLen) );

            //  call fapiGetMvpdPdr once with a NULL pointer to get the buffer size
            l_fapirc = fapiGetMvpdPdr(  l_fapi_cpu_target,
                                        l_pdRRecord,
                                        l_pdRLen );
            if ( l_fapirc != fapi::FAPI_RC_SUCCESS )
            {
                TS_FAIL( "testGetMvpdPdr:  expected FAPI_RC_SUCCESS" );
                return;
            }


            //  clean up memory
            free( l_pdRRecord );
        }

        TS_TRACE( "testGetMvpdPdr exit" );
    }


    //  @note:
    //  ring modifiers are from  MVPD #R record, 2012-05-22.
    //  This will change and the unit test will need to be changed...

    /**
     * @brief Fetch Repair Rings
     */
    void testRepairRings()
    {
        fapi::ReturnCode    l_fapirc        =   fapi::FAPI_RC_SUCCESS;
        uint8_t             *l_pRingBuf     =   NULL;
        uint32_t            l_ringBufsize   =   0;
        uint32_t            l_ringModifier  =   0;
        struct _testRRstr {
            uint32_t val;
            uint32_t size;
        }  l_ringModifiers[] = {
            { 0x8036006, 0x20,  },
            { 0x11033006, 0x20, },
            { 0x12033006, 0x20, },
            { 0x13033006, 0x20, },
            { 0x14033006, 0x20, },
            { 0x15033006, 0x20, },
            { 0x18033006, 0x20, },
            { 0x19033006, 0x20, },
            { 0x1a033006, 0x20, },
            { 0x1b033006, 0x20, },
            { 0x1c033006, 0x20, },
            { 0x1d033006, 0x20, },
            { 0x1e033006, 0x20, },
            { 0x11034f86, 0x20, },
            { 0x12034f86, 0x20, },
            { 0x13034f86, 0x20, },
            { 0x14034f86, 0x20, },
            { 0x15034f86, 0x20, },
            { 0x18034f86, 0x20, },
            { 0x19034f86, 0x20, },
            { 0x1a034f86, 0x20, },
            { 0x1b034f86, 0x20, },
            { 0x1c034f86, 0x20, },
            { 0x1d034f86, 0x20, },
            { 0x1e034f86, 0x20, },
            { 0x2036e06,  0x20, },
            { 0x2031006,  0x20, },
            { 0x9037d06,  0x20, },
            { 0x1034806,  0x20, },
            { 0x3034806,  0x20, },
        };

        TS_TRACE( "testRepairRings entry" );

        TARGETING::TargetHandleList l_cpuTargetList;
        getAllChips(l_cpuTargetList, TYPE_PROC);

        // loop thru all the cpu's
        for ( uint8_t l_cpuNum=0; l_cpuNum < l_cpuTargetList.size(); l_cpuNum++ )
        {
            //  make a local copy of the CPU target
            TARGETING::Target*  l_cpu_target = l_cpuTargetList[l_cpuNum];

            TS_TRACE( "testRepairRings: cpuNum = 0x%x ", l_cpuNum );

            //  dump physical path to target
            EntityPath l_path;
            l_path  =   l_cpu_target->getAttr<ATTR_PHYS_PATH>();
            l_path.dump();

            // cast OUR type of target to a FAPI type of target.
            fapi::Target l_fapi_cpu_target(
                                TARGET_TYPE_PROC_CHIP,
                                reinterpret_cast<void *>
                                (const_cast<TARGETING::Target*>(l_cpu_target)) );

            //  allocate some space to put the record(s)
            l_pRingBuf      =    new uint8_t[ 0x200];

            //  ----------------------------------------------------------------
            //  Pass in a NULL pointer for the ring buffer, should get an error.
            //  ----------------------------------------------------------------
            TS_TRACE( "testRepairRings: pass in NULL ptr" );
            l_ringBufsize   =   0x0;
            l_ringModifier  =   0;
            l_fapirc    =   getRepairRing(  l_fapi_cpu_target,
                                            l_ringModifier,
                                            NULL,
                                            l_ringBufsize );
            TS_TRACE( "testRepairRings: ring modifier=0x%x: l_ringBufsize=0x%x",
                      l_ringModifier, l_ringBufsize );
            if ( l_fapirc != fapi::RC_REPAIR_RING_INVALID_RINGBUF_PTR )
            {
                //  note:  "uint32_t" below is an _operator_ of fapi::ReturnCode
                TS_FAIL( "testRepairRings: rc FAIL: 0x%x, 0x%x",
                         fapi::RC_REPAIR_RING_INVALID_RINGBUF_PTR,
                         static_cast<uint32_t>(l_fapirc) );
                return;
            }
            //  ----------------------------------------------------------------
            //  Pass in 0 for the ring modifier, should return with "not found"
            //  error
            //  ----------------------------------------------------------------
            TS_TRACE( "testRepairRings: pass in invalid ringModifier" );
            l_ringBufsize   =   0x100;
            l_ringModifier  =   0;     // ringModifier picked at random
            l_fapirc    =   getRepairRing(  l_fapi_cpu_target,
                                            l_ringModifier,
                                            l_pRingBuf,
                                            l_ringBufsize );
            TS_TRACE( "testRepairRings: ring modifier=0x%x: l_ringBufsize=0x%x",
                      l_ringModifier,
                      l_ringBufsize );
            if ( l_fapirc != fapi::RC_REPAIR_RING_NOT_FOUND )
            {
                //  note:  "uint32_t" below is an _operator_ of fapi::ReturnCode
                TS_FAIL( "testRepairRings:  rc FAIL: 0x%x, 0x%x",
                         fapi::RC_REPAIR_RING_NOT_FOUND,
                         static_cast<uint32_t>(l_fapirc) );
                return;
            }

            //  loop takes too long, test ring 5
            uint8_t i   =   5;
            //  ----------------------------------------------------------------
            //  Pass in 0 length with a valid ringModifier, should return with
            //  correct length and no buffer.
            //  ----------------------------------------------------------------
            TS_TRACE( "testRepairRings: get size of ring %d ", i );
            l_ringBufsize   =   0x0;
            l_ringModifier  =   l_ringModifiers[i].val;
            l_fapirc    =   getRepairRing(  l_fapi_cpu_target,
                                            l_ringModifier,
                                            l_pRingBuf,
                                            l_ringBufsize );
            TS_TRACE( "testRepairRings: ring modifier=0x%x: l_ringBufsize=0x%x",
                      l_ringModifier,
                      l_ringBufsize );
            if ( l_fapirc != fapi::RC_REPAIR_RING_INVALID_SIZE )
            {
                //  note:  "uint32_t" below is an _operator_ of fapi::ReturnCode
                TS_FAIL( "testRepairRings: rc FAIL: 0x%x, 0x%x",
                         fapi::RC_REPAIR_RING_INVALID_SIZE,
                         static_cast<uint32_t>(l_fapirc) );
                return;
            }
            if ( l_ringBufsize != l_ringModifiers[i].size )
            {
                TS_FAIL( "testRepairRings:  size FAIL: 0x%x, 0x%x",
                         l_ringModifiers[i].size,
                         l_ringBufsize  );
                return;
            }


            //  ----------------------------------------------------------------
            //  RingBufsize should now have the correct size, fetch ring 5.
            //  ----------------------------------------------------------------
            TS_TRACE( "testRepairRings: get ring %d", i );

            // l_ringBufsize set from above...
            l_ringModifier  =   l_ringModifiers[i].val;
            l_fapirc    =   getRepairRing(  l_fapi_cpu_target,
                                            l_ringModifier,
                                            l_pRingBuf,
                                            l_ringBufsize );
            TS_TRACE( "testRepairRings: ring modifier=0x%x: l_ringBufsize=0x%x",
                      l_ringModifier, l_ringBufsize );

            if ( l_fapirc != fapi::FAPI_RC_SUCCESS )
            {
                //  note:  "uint32_t" below is an _operator_ of fapi::ReturnCode
                TS_FAIL( "testRepairRings:  rc FAIL: 0x%x, 0x%x",
                         fapi::FAPI_RC_SUCCESS,
                         static_cast<uint32_t>(l_fapirc) );
                return;
            }
            if ( l_ringBufsize != l_ringModifiers[i].size )
            {
                TS_FAIL( "testRepairRings:  size FAIL: 0x%x, 0x%x",
                         l_ringModifiers[i].size,
                         l_ringBufsize  );
                return;
            }

            // @todo dump ring buffer here.
            TRACDBIN( g_trac_test, "testRepairRings: Dump Repair Ring Buffer:",
                      l_pRingBuf,
                      l_ringBufsize );

            //  delete allocated space
            delete[]    l_pRingBuf;
        }

        TS_TRACE( "testRepairRings exit" );
    }

};

#endif
OpenPOWER on IntegriCloud