summaryrefslogtreecommitdiffstats
path: root/src/usr/runtime/test/hdatservicetest.H
blob: cfd70ddfbb3b1050d7e8c19379201f6e5463babb (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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/runtime/test/hdatservicetest.H $                      */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,2014              */
/*                                                                        */
/* 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                                                     */
#ifndef __TEST_HDATSERVICETEST_H
#define __TEST_HDATSERVICETEST_H

/**
 *  @file runtimetest.H
 *
 */

#include <cxxtest/TestSuite.H>

#include <arch/ppc.H> //for MAGIC
#include <errl/errlmanager.H>
#include <targeting/common/commontargeting.H>
#include <runtime/runtime.H>
#include <attributeenums.H>
#include "../hdatstructs.H"
#include "../errlud_hdat.H"
#include <runtime/runtime_reasoncodes.H>

/*
 * To test with a custom HDAT do the following:
 *   #define REAL_HDAT_TEST in hdatservicetest.H
 *   #define REAL_HDAT_TEST in hdatservice.C
 *   When MAGIC_BREAK hits run this in simics:
 *      system_cmp0.phys_mem.load-file hdat.bin 0x10000000
 *
 *   Note that there will be DumpTest failures.
 */
//#define REAL_HDAT_TEST

extern trace_desc_t* g_trac_runtime;

class HdatServiceTest: public CxxTest::TestSuite
{
  public:
    void testHdat(void)
    {
        TRACFCOMP( g_trac_runtime, "testHdat> start" );
        errlHndl_t errhdl = NULL;

        // Figure out if we expect to have this data or not
        TARGETING::Target * sys = NULL;
        TARGETING::targetService().getTopLevelTarget( sys );
        assert(sys != NULL);
        TARGETING::ATTR_PAYLOAD_KIND_type payload_kind =
          sys->getAttr<TARGETING::ATTR_PAYLOAD_KIND>();

#ifdef REAL_HDAT_TEST
        payload_kind = TARGETING::PAYLOAD_KIND_PHYP;
#endif

        // Verify something in the system parms
        uint64_t sys_parms_addr = 0;
        size_t sys_parms_size = 0;
        errhdl = RUNTIME::get_host_data_section(
                                    RUNTIME::IPLPARMS_SYSTEM,
                                    0,
                                    sys_parms_addr,
                                    sys_parms_size );
        if( payload_kind == TARGETING::PAYLOAD_KIND_PHYP )
        {
            if( errhdl  )
            {
                TS_FAIL("testHdat> Error trying to locate IPLPARMS_SYSTEM");
                errlCommit(errhdl,RUNTIME_COMP_ID);
            }
            else if( sys_parms_addr == 0 )
            {
                TS_FAIL("testHdat> NULL returned for get_host_data_section(IPLPARMS_SYSTEM)");
            }
            else if( (sys_parms_size < sizeof(hdatSysParms_t))
                     || (sys_parms_size == RUNTIME::DATA_SIZE_UNKNOWN) )
            {
                TS_FAIL("testHdat> Size of IPLPARMS_SYSTEM data too small");
            }
            else
            {
                hdatSysParms_t* sys_parms = reinterpret_cast<hdatSysParms_t*>(sys_parms_addr);

                uint32_t pvr = sys_parms->hdatEffectivePvr;
                TRACFCOMP( g_trac_runtime, "PVR=%.8X", pvr );

                TARGETING::Target* procmaster = NULL;
                TARGETING::targetService().masterProcChipTargetHandle( procmaster );
                assert( procmaster != NULL );
                TARGETING::ATTR_MODEL_type model =
                  procmaster->getAttr<TARGETING::ATTR_MODEL>();

                if( (model == TARGETING::MODEL_MURANO)
                    && !((pvr & 0x00FF0000) == 0x004B0000) )
                {
                    TS_FAIL("testHdat> PVR model != 4B for Murano");
                }
                else if( (model == TARGETING::MODEL_VENICE)
                         && !((pvr & 0x00FF0000) == 0x004D0000) )
                {
                    TS_FAIL("testHdat> PVR model != 4D for Venice");
                }
                else if( (model == TARGETING::MODEL_NAPLES)
                         && !((pvr & 0x00FF0000) == 0x004C0000) )
                {
                    TS_FAIL("testHdat> PVR model != 4C for Naples");
                }
            }
        }
        else
        {
            if( !errhdl )
            {
                TS_FAIL("testHdat> Did not get expected error trying to locate IPLPARMS_SYSTEM for non-PHYP Payload");
            }
            else
            {
                delete errhdl;
            }
        }



        // Verify the HostServices Node Data
        uint64_t node_data_addr = 0;
        size_t node_data_size = 0;
        errhdl = RUNTIME::get_host_data_section(
                                    RUNTIME::HSVC_NODE_DATA,
                                    0,
                                    node_data_addr,
                                    node_data_size );
        if( errhdl
            && ((payload_kind == TARGETING::PAYLOAD_KIND_PHYP) 
                || (payload_kind == TARGETING::PAYLOAD_KIND_NONE)) )
        {
            TS_FAIL("testHdat> Error trying to locate HSVC_NODE_DATA");
            errlCommit(errhdl,RUNTIME_COMP_ID);
        }
        else if( !errhdl
                 && (payload_kind != TARGETING::PAYLOAD_KIND_PHYP) 
                 && (payload_kind != TARGETING::PAYLOAD_KIND_NONE) )
        {
            TS_FAIL("testHdat> Did not get expected error trying to locate HSVC_NODE_DATA for non-PHYP/Standalone Payload");
        }
        else if( (node_data_addr == 0)
                 && (payload_kind != TARGETING::PAYLOAD_KIND_PHYP) 
                 && (payload_kind != TARGETING::PAYLOAD_KIND_NONE) )
        {
            TS_FAIL("testHdat> NULL or zero size returned for get_host_data_section(HSVC_NODE_DATA)");
        }
        else if( (node_data_size == 0)
                 || (node_data_size == RUNTIME::DATA_SIZE_UNKNOWN) )
        {
            TS_FAIL("testHdat> Size of HSVC_NODE_DATA is unexpected");
        }
        if( errhdl )
        {
            delete errhdl;
        }


        // Verify the HostServices System Data
        uint64_t sys_data_addr = 0;
        size_t sys_data_size = 0;
        errhdl = RUNTIME::get_host_data_section(
                                    RUNTIME::HSVC_SYSTEM_DATA,
                                    0,
                                    sys_data_addr,
                                    sys_data_size );
        if( errhdl
            && ((payload_kind == TARGETING::PAYLOAD_KIND_PHYP) 
                || (payload_kind == TARGETING::PAYLOAD_KIND_NONE)) )
        {
            TS_FAIL("testHdat> Error trying to locate HSVC_SYSTEM_DATA");
            errlCommit(errhdl,RUNTIME_COMP_ID);
        }
        else if( !errhdl
                 && (payload_kind != TARGETING::PAYLOAD_KIND_PHYP) 
                 && (payload_kind != TARGETING::PAYLOAD_KIND_NONE) )
        {
            TS_FAIL("testHdat> Did not get expected error trying to locate HSVC_SYSTEM_DATA for non-PHYP/Standalone Payload");
        }
        else if( ((sys_data_addr == 0) || (sys_data_size == 0))
                 && (payload_kind != TARGETING::PAYLOAD_KIND_PHYP) 
                 && (payload_kind != TARGETING::PAYLOAD_KIND_NONE) )
        {
            TS_FAIL("testHdat> NULL or zero size returned for get_host_data_section(HSVC_SYSTEM_DATA)");
        }
        else if( (sys_data_size == 0)
                 || (sys_data_size == RUNTIME::DATA_SIZE_UNKNOWN) )
        {
            TS_FAIL("testHdat> Size of HSVC_SYSTEM_DATA is unexpected");
        }
        if( errhdl )
        {
            delete errhdl;
        }

        // Verify the Dump Tables
        uint64_t dump_addr = 0;
        size_t dump_size = 0;
        errhdl = RUNTIME::get_host_data_section(
                                    RUNTIME::MS_DUMP_SRC_TBL,
                                    0,
                                    dump_addr,
                                    dump_size );

        if( errhdl
            && ((payload_kind == TARGETING::PAYLOAD_KIND_PHYP) 
                || (payload_kind == TARGETING::PAYLOAD_KIND_NONE)))
        {
            TS_FAIL("testHdat> Error trying to locate MS_DUMP_SRC_TBL");
            errlCommit(errhdl,RUNTIME_COMP_ID);
        }
        else if( !errhdl
                 && (payload_kind != TARGETING::PAYLOAD_KIND_PHYP) 
                 && (payload_kind != TARGETING::PAYLOAD_KIND_NONE) )
        {
            TS_FAIL("testHdat> Did not get expected error trying to locate MS_DUMP_SRC_TBL for non-PHYP/Standalone Payload");
        }
        else if( ((dump_addr == 0) || (dump_size < 16))
                 && (payload_kind != TARGETING::PAYLOAD_KIND_PHYP) 
                 && (payload_kind != TARGETING::PAYLOAD_KIND_NONE) )
        {
            TS_FAIL("testHdat> NULL or zero size returned for get_host_data_section(MS_DUMP_SRC_TBL)");
        }
        else if( (dump_size <16)
                 || (dump_size == RUNTIME::DATA_SIZE_UNKNOWN) )
        {
            TS_FAIL("testHdat> Size of MS_DUMP_SRC_TBL is unexpected");
        }
        if( errhdl )
        {
            delete errhdl;
        }


        errhdl = RUNTIME::get_host_data_section(
                                    RUNTIME::MS_DUMP_DST_TBL,
                                    0,
                                    dump_addr,
                                    dump_size );
        if( errhdl
            && ((payload_kind == TARGETING::PAYLOAD_KIND_PHYP) 
                || (payload_kind == TARGETING::PAYLOAD_KIND_NONE)) )
        {
            TS_FAIL("testHdat> Error trying to locate MS_DUMP_DST_TBL");
            errlCommit(errhdl,RUNTIME_COMP_ID);
        }
        else if( !errhdl
                 && (payload_kind != TARGETING::PAYLOAD_KIND_PHYP) 
                 && (payload_kind != TARGETING::PAYLOAD_KIND_NONE) )
        {
            TS_FAIL("testHdat> Did not get expected error trying to locate MS_DUMP_DST_TBL for non-PHYP/Standalone Payload");
        }
        else if( ((dump_addr == 0) || (dump_size < 16))
                 && (payload_kind != TARGETING::PAYLOAD_KIND_PHYP) 
                 && (payload_kind != TARGETING::PAYLOAD_KIND_NONE) )
        {
            TS_FAIL("testHdat> NULL or zero size returned for get_host_data_section(MS_DUMP_DST_TBL)");
        }
        else if( (dump_size <16)
                 || (dump_size == RUNTIME::DATA_SIZE_UNKNOWN) )
        {
            TS_FAIL("testHdat> Size of MS_DUMP_DST_TBL is unexpected");
        }
        if( errhdl )
        {
            delete errhdl;
        }


        errhdl = RUNTIME::get_host_data_section(
                                    RUNTIME::MS_DUMP_RESULTS_TBL,
                                    0,
                                    dump_addr,
                                    dump_size );

        if( errhdl
            && ((payload_kind == TARGETING::PAYLOAD_KIND_PHYP) 
                || (payload_kind == TARGETING::PAYLOAD_KIND_NONE)) )
        {
            TS_FAIL("testHdat> Error trying to locate MS_DUMP_SRC_TBL");
            errlCommit(errhdl,RUNTIME_COMP_ID);
        }
        else if( !errhdl
                 && (payload_kind != TARGETING::PAYLOAD_KIND_PHYP) 
                 && (payload_kind != TARGETING::PAYLOAD_KIND_NONE) )
        {
            TS_FAIL("testHdat> Did not get expected error trying to locate MS_DUMP_RESULTS_TBL for non-PHYP/Standalone Payload");
        }
        else if( ((dump_addr == 0) || (dump_size < 16))
                 && (payload_kind != TARGETING::PAYLOAD_KIND_PHYP) 
                 && (payload_kind != TARGETING::PAYLOAD_KIND_NONE) )
        {
            TS_FAIL("testHdat> NULL or zero size returned for get_host_data_section(MS_DUMP_RESULTS_TBL)");
        }
        else if( (dump_size <16)
                 || (dump_size == RUNTIME::DATA_SIZE_UNKNOWN) )
        {
            TS_FAIL("testHdat> Size of MS_DUMP_RESULTS_TBL is unexpected");
        }
        if( errhdl )
        {
            delete errhdl;
        }

        TRACFCOMP( g_trac_runtime, "testHdat> finish" );
    }

    void testSpira( void )
    {
#ifdef REAL_HDAT_TEST
        TRACFCOMP( g_trac_runtime, "testSpira> start" );
        errlHndl_t errhdl = NULL;

        uint64_t naca_addr = 0;
        size_t naca_size = 0;
        errhdl = RUNTIME::get_host_data_section(
                                    RUNTIME::NACA,
                                    0,
                                    naca_addr,
                                    naca_size );
        if( errhdl  )
        {
            TS_FAIL("testSpira> Error trying to locate NACA");
            errlCommit(errhdl,RUNTIME_COMP_ID);
        }
        else if( naca_addr == 0 )
        {
            TS_FAIL("testSpira> NULL returned for get_host_data_section(NACA)");
        }
        else if( (naca_size == 0)
                 || (naca_size == RUNTIME::DATA_SIZE_UNKNOWN) )
        {
            TS_FAIL("testSpira> Size of NACA data too small");
        }


        uint64_t spiral_addr = 0;
        size_t spiral_size = 0;
        errhdl = RUNTIME::get_host_data_section(
                                    RUNTIME::SPIRA_L,
                                    0,
                                    spiral_addr,
                                    spiral_size );
        if( errhdl  )
        {
            TS_FAIL("testSpira> Error trying to locate SPIRA_L");
            errlCommit(errhdl,RUNTIME_COMP_ID);
        }
        else if( spiral_addr == 0 )
        {
            TS_FAIL("testSpira> NULL returned for get_host_data_section(SPIRA_L)");
        }
        else if( (spiral_size == 0)
                 || (spiral_size == RUNTIME::DATA_SIZE_UNKNOWN) )
        {
            TS_FAIL("testSpira> Size of SPIRA_L data too small");
        }


        uint64_t spiras_addr = 0;
        size_t spiras_size = 0;
        errhdl = RUNTIME::get_host_data_section(
                                    RUNTIME::SPIRA_S,
                                    0,
                                    spiras_addr,
                                    spiras_size );
        if( errhdl  )
        {
            TS_FAIL("testSpira> Error trying to locate SPIRA_S");
            errlCommit(errhdl,RUNTIME_COMP_ID);
        }
        else if( spiras_addr == 0 )
        {
            TS_FAIL("testSpira> NULL returned for get_host_data_section(SPIRA_S)");
        }
        else if( (spiras_size == 0)
                 || (spiras_size == RUNTIME::DATA_SIZE_UNKNOWN) )
        {
            TS_FAIL("testSpira> Size of SPIRA-S data too small");
        }


        uint64_t spirah_addr = 0;
        size_t spirah_size = 0;
        errhdl = RUNTIME::get_host_data_section(
                                    RUNTIME::SPIRA_H,
                                    0,
                                    spirah_addr,
                                    spirah_size );
        if( errhdl  )
        {
            TS_FAIL("testSpira> Error trying to locate SPIRA_H");
            errlCommit(errhdl,RUNTIME_COMP_ID);
        }
        else if( spirah_addr == 0 )
        {
            TS_FAIL("testSpira> NULL returned for get_host_data_section(SPIRA_H)");
        }
        else if( (spirah_size == 0)
                 || (spirah_size == RUNTIME::DATA_SIZE_UNKNOWN) )
        {
            TS_FAIL("testSpira> Size of SPIRA_H data too small");
        }

        errhdl = new ERRORLOG::ErrlEntry(
                            ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                            RUNTIME::MOD_HDATSERVICE_VERIFY_HDAT_ADDRESS,
                            RUNTIME::RC_BAD_HDAT_HEADER,
                            0,0 );
        add_host_data_ffdc(RUNTIME::HSVC_NODE_DATA,errhdl);
        add_host_data_ffdc(RUNTIME::HSVC_SYSTEM_DATA,errhdl);
        add_host_data_ffdc(RUNTIME::NACA,errhdl);
        add_host_data_ffdc(RUNTIME::SPIRA_L,errhdl);
        add_host_data_ffdc(RUNTIME::SPIRA_S,errhdl);
        add_host_data_ffdc(RUNTIME::SPIRA_H,errhdl);
        errlCommit(errhdl,RUNTIME_COMP_ID);


        TRACFCOMP( g_trac_runtime, "testSpira> finish" );
#endif
    }

};


#endif

OpenPOWER on IntegriCloud