summaryrefslogtreecommitdiffstats
path: root/src/usr/targeting/runtime/test/testtargeting.H
blob: c03f2fd2711a66fab1fd078fdb9be44282ae7992 (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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/targeting/runtime/test/testtargeting.H $              */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2013,2018                        */
/* [+] 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 <cxxtest/TestSuite.H>
#include <targeting/common/commontargeting.H>
#include <runtime/interface.h>
#include <runtime/rt_targeting.H>
#include <errl/errlentry.H>
#include <errl/errlmanager.H>
#include <targeting/common/trace.H>
#include <targeting/common/utilFilter.H>
#include <targeting/attrPlatOverride.H>
#include <util/runtime/util_rt.H>
#include <targeting/attrrp.H>

#define MEMCMPPTR(addr, offset) \
        reinterpret_cast<void*>(reinterpret_cast<uint64_t>(addr) + offset)

class TargetingTestSuite : public CxxTest::TestSuite
{
    public:
        void testTopLevelTarget()
        {
            using namespace TARGETING;

            TargetService& l_targetService = targetService();

            TARGETING::Target* l_pTarget = NULL;
            (void) l_targetService.getTopLevelTarget(l_pTarget);
            if (l_pTarget == NULL)
            {
                TS_FAIL("Top level target handle is NULL");
                return;
            }

            (void)l_pTarget->getAttr<ATTR_PHYS_PATH>().dump();
        }

        void testHBRT_targets()
        {
            using namespace TARGETING;
            errlHndl_t err = NULL;
            RT_TARG::rtChipId_t rt_chipid;

            TARGETING::TargetHandleList allTargets;
            TARGETING::TargetHandleList targetList;

            getAllChips(targetList, TYPE_PROC);

            allTargets.insert(allTargets.end(),
                              targetList.begin(),
                              targetList.end());

            targetList.clear();
            getAllChips(targetList,TYPE_MEMBUF);

            allTargets.insert(allTargets.end(),
                              targetList.begin(),
                              targetList.end());

            targetList.clear();
            getAllChiplets(targetList, TYPE_CORE);

            allTargets.insert(allTargets.end(),
                              targetList.begin(),
                              targetList.end());


            for(TargetHandleList::iterator pTarg = allTargets.begin();
                pTarg != allTargets.end(); ++pTarg)
            {
                err = RT_TARG::getRtTarget(*pTarg, rt_chipid);
                if( err )
                {
                    TS_FAIL("getRtTarget returned error log");
                    errlCommit( err, TARG_COMP_ID);
                    err = NULL;
                    break;
                }
                TRACDCOMP(g_trac_targeting,"chipId = %x",rt_chipid);

                TARGETING::Target * target = NULL;

                err = RT_TARG::getHbTarget(rt_chipid, target);
                if(err)
                {
                    TS_FAIL("getRtTarget_returned error log");
                    errlCommit( err, TARG_COMP_ID);
                    err = NULL;
                    break;
                }

                if(*pTarg != target)
                {
                    TS_FAIL("testHBRT_targets failed for rt_chipID %x "
                            "target_in %p, huid %x, target_out %p, huid %x",
                            rt_chipid,
                            *pTarg,
                            get_huid(*pTarg),
                            target,
                            get_huid(target));
                }
            }
        }

        // Verify HBRT is picking up the overrides from the IPL
        //  Note: must be before testApplyAttrOverrides, because that
        //        test clears out all of the overrides
        void testIplOverrides()
        {
            using namespace TARGETING;
            TRACFCOMP(g_trac_targeting,"testIplOverrides");
#if 0
// @TODO RTC 144077 - rt_get_targ_override() no longer sets attribute up

            //See rt_get_targ_override() for setup details about setting
            // SYSTEM:ATTR_SCRATCH_INT32_1 = -99

            TargetService& l_targetService = targetService();
            TARGETING::Target* l_pTarget = NULL;
            (void) l_targetService.getTopLevelTarget(l_pTarget);
            if (l_pTarget == NULL)
            {
                TS_FAIL("Top level target handle is NULL");
            }
            else
            {
                ATTR_SCRATCH_INT32_1_type l_val =
                  l_pTarget->getAttr<TARGETING::ATTR_SCRATCH_INT32_1>();
                if( l_val != -99 )
                {
                    TS_FAIL("testIplOverrides> SCRATCH_INT32_1=%d, expected %d", l_val, -99 );
                }
            }
#endif
        }


        void testApplyAttrOverrides()
        {
            using namespace TARGETING;
            TRACFCOMP(g_trac_targeting,"testApplyAttrOverrides (temporarily allow Attr Overrides)");

            // Must Temporarily Allow Attribute Overrides since secureboot is
            // now set at runtime.  Will restore later.
            bool allow_attr_overrides = false;
            TargetService& l_targetService = targetService();
            TARGETING::Target* l_pTarget = nullptr;
            (void) l_targetService.getTopLevelTarget(l_pTarget);
            if (l_pTarget == nullptr)
            {
                TS_FAIL("Top level target handle is NULL");
            }
            else
            {
                  allow_attr_overrides = l_pTarget->getAttr<
                    TARGETING::ATTR_ALLOW_ATTR_OVERRIDES_IN_SECURE_MODE>();

                  l_pTarget->setAttr<
                    TARGETING::ATTR_ALLOW_ATTR_OVERRIDES_IN_SECURE_MODE>(true);
            }

            do
            {
                // Get the address of the runtime apply overrides function
                runtimeInterfaces_t* rt_intf = getRuntimeInterfaces();
                if(rt_intf == NULL)
                {
                    TS_FAIL("runtimeIntfaces not set");
                    break;
                }
                if( rt_intf->apply_attr_override == NULL )
                {
                    TS_FAIL("runtimeInterfaces->apply_attr_override not set");
                    break;
                }

                // Get the initial value of the test attribute
                uint8_t l_attrVal =
                         l_pTarget->getAttr<TARGETING::ATTR_SCRATCH_UINT8_1>();
                uint8_t l_attrOverrideVal = l_attrVal + 1;
                TRACFCOMP(g_trac_targeting,
                      "apply_attr_override attribute value = 0x%02x",
                      l_attrVal);

                // Set up attribute override binary blob
                const uint64_t l_attrBlobSizeMax = 4096;
                uint8_t l_pAttrOverrideBlob[l_attrBlobSizeMax] = {0xff};
                AttributeTank l_TargetTank;
                l_TargetTank.setAttribute(ATTR_SCRATCH_UINT8_1,
                                      TYPE_SYS,
                                      AttributeTank::ATTR_POS_NA,
                                      AttributeTank::ATTR_UNIT_POS_NA,
                                      AttributeTank::ATTR_NODE_NA,
                                      0,
                                      sizeof(l_attrOverrideVal),
                                      &l_attrOverrideVal);
                AttributeTank::AttributeSerializedChunks_t l_attributes;
                l_TargetTank.serializeAttributes(
                             AttributeTank::ALLOC_TYPE_NEW,
                             l_attrBlobSizeMax,
                             l_attributes);
                // Copy override chunk to form attribute override section
                AttributeTank::AttributeSerializedChunk l_chunk;
                AttrOverrideSection * l_pAttrOverSec = NULL;
                uint32_t l_tmpIndex = 0;
                for (AttributeTank::AttributeSerializedChunks_t::iterator
                        chunkIter = l_attributes.begin();
                        chunkIter != l_attributes.end();
                        ++chunkIter)
                {
                    l_chunk = *chunkIter;
                    l_pAttrOverSec = reinterpret_cast<AttrOverrideSection *>
                                        (l_pAttrOverrideBlob + l_tmpIndex);
                    l_pAttrOverSec->iv_layer = AttributeTank::TANK_LAYER_TARG;
                    l_pAttrOverSec->iv_size = l_chunk.iv_size;
                    memcpy(&l_pAttrOverSec->iv_chunk, l_chunk.iv_pAttributes,
                        l_chunk.iv_size);
                    l_tmpIndex += sizeof(AttrOverrideSection)+
                                        l_pAttrOverSec->iv_size;
                }
                // Add termination section
                l_pAttrOverSec = reinterpret_cast<AttrOverrideSection *>
                                        (l_pAttrOverrideBlob + l_tmpIndex);
                l_pAttrOverSec->iv_layer = AttributeTank::TANK_LAYER_TERM;
                l_pAttrOverSec->iv_size = 0;
                l_tmpIndex += sizeof(AttrOverrideSection);
                // call runtime override attributes
                int rc = rt_intf->apply_attr_override(
                                    l_pAttrOverrideBlob,
                                    l_tmpIndex);
                if (rc)
                {
                    TS_FAIL("apply_attr_override empty list failed rc=%x",rc);
                    break;
                }
                // verify the overriden value
                uint8_t l_attrNewVal =
                         l_pTarget->getAttr<TARGETING::ATTR_SCRATCH_UINT8_1>();
                TRACFCOMP(g_trac_targeting,
                      "apply_attr_override overriden attribute value = 0x%02x",
                      l_attrNewVal);
                if (l_attrNewVal != l_attrOverrideVal)
                {
                    TS_FAIL("apply_attr_override value=0x%02x expected=0x%02x",
                       l_attrNewVal,l_attrOverrideVal);
                    break;
                }

                // verify that any previous overrides are not still there
                ATTR_SCRATCH_INT32_1_type l_val =
                  l_pTarget->getAttr<TARGETING::ATTR_SCRATCH_INT32_1>();
                if( l_val == -99 )
                {
                    TS_FAIL("testApplyAttrOverrides> SCRATCH_INT32_1=%d, expected %d", -99, 0 );
                    break;
                }

                TRACFCOMP(g_trac_targeting,"testApplyAttrOverrides SUCCESS");
            } while (0);

            // Restore allow_attr_overrides setting
            l_pTarget->setAttr<
              TARGETING::ATTR_ALLOW_ATTR_OVERRIDES_IN_SECURE_MODE>(
                allow_attr_overrides);
        }

        // Test the two internal functions used during HBRT concurrent update.
        // The first function validates the LID Structure against the Reserved
        // Memory data.  The second function saves and restores attribute
        // values from current Reserved Memory data into new LID Structure
        // data.  This testcase uses Reserved Memory data to make its LID
        // Structure, so it tests basic logic in the functions, but does not
        // test more complex handling of special data conditions.
        void _testSaveRestoreAttrs()
        {
#if 0 //@todo-RTC:188625-Turn this back on
            using namespace TARGETING;
            TRACFCOMP(g_trac_targeting,ENTER_MRK"testSaveRestoreAttrs");

            int rc = 0;
            uint64_t l_userdata2 = 0;
            void *l_lidStruct = nullptr;

            do
            {
                uint64_t l_attr_size = 0;
                uint64_t l_rsvdMem =
                    hb_get_rt_rsvd_mem(Util::HBRT_MEM_LABEL_ATTR,
                                       0,
                                       l_attr_size);
                void *l_rsvdMemPtr = reinterpret_cast<void*>(l_rsvdMem);

                // Allocate memory for new LID structure
                l_lidStruct = malloc(l_attr_size);

                // Make LID structure from current Reserved Memory data
                memcpy(l_lidStruct,
                       l_rsvdMemPtr,
                       l_attr_size);

                // Validate LID Structure against Reserved Memory
                /* Check that the TargetingHeader eyecatchers are valid, that
                   number of sections match, and that the types of each
                   TargetingSection match. */
                size_t l_lidDataSize = 0;
                rc = RT_TARG::validateData(l_lidStruct,
                                           l_rsvdMemPtr,
                                           l_lidDataSize,
                                           l_userdata2);
                if(rc)
                {
                    TS_FAIL("testSaveRestoreAttrs> unexpected return code from "
                            "validateData, received 0x%.2x",
                            rc);
                    break;
                }
                else if(l_userdata2 != 0)
                {
                    TS_FAIL("testSaveRestoreAttrs> unexpected user data from "
                            "validateData, received 0x%.16llx",
                            l_userdata2);
                    break;
                }

#if 0 //@todo-RTC:188625-Need to figure out a way to get the size of the original data
                if( l_lidDataSize != TARGETING::AttrRP::maxSize() )
                {
                    TS_FAIL("testSaveRestoreAttrs> size mismatch : cur=0x%llX vs new=0x%llX",
                            TARGETING::AttrRP::maxSize(), l_lidDataSize);
                    break;
                }
#endif

                // Save/Restore attribute values
                /* Copy attribute values from current Reserved Memory data
                   into new LID Structure data.  Leave attribute values in new
                   LID Structure data as is, if there is no value from current
                   Reserved Memory data. */
                rc = RT_TARG::saveRestoreAttrs(l_rsvdMemPtr,
                                               l_lidStruct,
                                               l_userdata2);
                if(rc)
                {
                    TS_FAIL("testSaveRestoreAttrs> unexpected return code from "
                            "saveRestoreAttrs, received 0x%.2x",
                            rc);
                    break;
                }
                else if(l_userdata2 != 0)
                {
                    TS_FAIL("testSaveRestoreAttrs> unexpected user data from "
                            "saveRestoreAttrs, received 0x%.8x",
                            l_userdata2);
                    break;
                }

                // Prepare to compare current attributes to new attributes
                TRACFCOMP(g_trac_targeting,"testSaveRestoreAttrs> comparing "
                          "data from new LID Structure at %p to current "
                          "Reserved Memory at %p",
                          MEMCMPPTR(l_lidStruct, 0),
                          MEMCMPPTR(l_rsvdMemPtr, 0));

                // Compare the complete set of memory
                if( memcmp( l_lidStruct, l_rsvdMemPtr, l_attr_size ) )
                {
                    TS_FAIL( "testSaveRestoreAttrs> Data does not match" );
                }

                uint64_t l_memcmpOffset = 0;
                uint64_t l_memcmpLimit = 0;
                uint64_t l_memcmpSize = 8;
                int l_memcmpRtn = 0;
                uint32_t l_memcmpCount = 0;
                uint32_t l_memcmpFailed = 0;

                // Access TargetingHeader in current data
                TargetingHeader* l_headerRsvd =
                    reinterpret_cast<TargetingHeader*>(l_rsvdMemPtr);

                // Verify TargetingHeader in current data
                if (l_headerRsvd->eyeCatcher != PNOR_TARG_EYE_CATCHER)
                {
                    TS_FAIL("testSaveRestoreAttrs>  bad eyecatcher 0x%.8x "
                            "found in Reserved Memory TargetingHeader",
                            l_headerRsvd->eyeCatcher);

                    break;
                }

                // First compare header and section data
                l_memcmpLimit = l_headerRsvd->headerSize; // Total header size
                for(;
                    l_memcmpOffset < l_memcmpLimit;
                    l_memcmpOffset += l_memcmpSize)
                {
                    // Increment compare count
                    l_memcmpCount += 1;

                    // Compare new LID Structure and current Reserved Memory
                    l_memcmpRtn =
                        memcmp(MEMCMPPTR(l_lidStruct, l_memcmpOffset),
                               MEMCMPPTR(l_rsvdMemPtr, l_memcmpOffset),
                               (l_memcmpOffset + l_memcmpSize <= l_memcmpLimit)
                                   ? l_memcmpSize
                                   : (l_memcmpLimit - l_memcmpOffset));
                    if(0 != l_memcmpRtn)
                    {
                        TRACFCOMP(g_trac_targeting,"miscompare offset 0x%.8x "
                                  "in header and section data, "
                                  "LID 0x%0.16llx, Rsvd 0x%0.16llx, "
                                  "memcmp return 0x%llx ",
                                  l_memcmpOffset,
                                  *static_cast<uint64_t *>(
                                      MEMCMPPTR(l_lidStruct, l_memcmpOffset)),
                                  *static_cast<uint64_t *>(
                                      MEMCMPPTR(l_rsvdMemPtr, l_memcmpOffset)),
                                  l_memcmpRtn);

                        l_memcmpFailed += 1;
                    }
                }

                // Count of attribute sections
                size_t l_sectionCount = l_headerRsvd->numSections;

                // Find start to the first section in current data:
                //      (header address + size of header + offset in header)
                TargetingSection* l_sectionRsvd =
                    reinterpret_cast<TargetingSection*>(
                        reinterpret_cast<uint64_t>(l_headerRsvd) +
                        sizeof(TargetingHeader) +
                        l_headerRsvd->offsetToSections);

                // Then compare each section
                for(size_t i = 0;
                    i < l_sectionCount;
                    ++i)
                {
                    // Compare a section
                    TRACFCOMP(g_trac_targeting,"testSaveRestoreAttrs> "
                          "comparing section type %d data from new LID "
                          "Structure at %p to current Reserved Memory at %p",
                          l_sectionRsvd[i].sectionType,
                          MEMCMPPTR(l_lidStruct, l_memcmpOffset),
                          MEMCMPPTR(l_rsvdMemPtr, l_memcmpOffset));
                    l_memcmpLimit =
                        std::min(l_memcmpOffset + l_sectionRsvd[i].sectionSize,
                                 l_attr_size);
                    for(;
                        l_memcmpOffset < l_memcmpLimit;
                        l_memcmpOffset += l_memcmpSize)
                    {
                        // Increment compare count
                        l_memcmpCount += 1;

                        // Compare new LID Structure and current Reserved Memory
                        l_memcmpRtn =
                            memcmp(MEMCMPPTR(l_lidStruct, l_memcmpOffset),
                                   MEMCMPPTR(l_rsvdMemPtr, l_memcmpOffset),
                                   (l_memcmpOffset + l_memcmpSize
                                    <= l_memcmpLimit)
                                       ? l_memcmpSize
                                       : (l_memcmpLimit - l_memcmpOffset));
                        if(0 != l_memcmpRtn)
                        {
                            TRACFCOMP(g_trac_targeting,"miscompare offset "
                                      "0x%.8x in %d type section, "
                                      "LID 0x%0.16llx, Rsvd 0x%0.16llx, "
                                      "memcmp return 0x%llx ",
                                      l_memcmpOffset,
                                      l_sectionRsvd[i].sectionType,
                                      *static_cast<uint64_t *>(
                                          MEMCMPPTR(l_lidStruct,
                                                    l_memcmpOffset)),
                                      *static_cast<uint64_t *>(
                                          MEMCMPPTR(l_rsvdMemPtr,
                                                    l_memcmpOffset)),
                                      l_memcmpRtn);

                            l_memcmpFailed += 1;
                        }
                    }
                }

                TRACFCOMP(g_trac_targeting,"testSaveRestoreAttrs> Pointers "
                          "after compare, new LID Structure %p, current "
                          "Reserved Memory %p",
                          MEMCMPPTR(l_lidStruct, l_memcmpOffset),
                          MEMCMPPTR(l_rsvdMemPtr, l_memcmpOffset));

                if(l_memcmpFailed != 0)
                {
                    TS_FAIL("testSaveRestoreAttrs FAILED memcmp %d "
                              ERR_MRK"testSaveRestoreAttrs FAILED memcmp %d "
                              "(0x%.8x) times out of %d (0x%.8x)",
                              l_memcmpFailed,
                              l_memcmpFailed,
                              l_memcmpCount,
                              l_memcmpCount);
                    break;
                }

                // Detect invalid LID Structure TargetingHeader eyecatcher
                TargetingHeader* l_headerLid =
                    reinterpret_cast<TargetingHeader*>(l_lidStruct);
                uint32_t *l_pEyeCatcher =
                    reinterpret_cast<uint32_t*>(reinterpret_cast<uint64_t>(
                        &l_headerLid->eyeCatcher));
                *l_pEyeCatcher += 0x20202020;
                rc = RT_TARG::validateData(l_lidStruct,
                                           l_rsvdMemPtr,
                                           l_lidDataSize,
                                           l_userdata2);
                if(rc != 0x11)
                {
                    TS_FAIL("testSaveRestoreAttrs> unexpected return code from "
                            "validateData, expected 0x11, received 0x%.2x",
                            rc);
                    break;
                }
                else if(l_userdata2 != l_headerLid->eyeCatcher)
                {
                    TS_FAIL("testSaveRestoreAttrs> unexpected user data from "
                            "validateData, expected 0x%.16llx, rcvd 0x%.16llx",
                            l_headerLid->eyeCatcher,
                            l_userdata2);
                    break;
                }
                else
                {
                    *l_pEyeCatcher -= 0x20202020;
                    l_userdata2 = 0;
                }

                // Detect invalid Reserved Memory TargetingHeader eyecatcher
                l_pEyeCatcher =
                    reinterpret_cast<uint32_t*>(reinterpret_cast<uint64_t>(
                        &l_headerRsvd->eyeCatcher));
                *l_pEyeCatcher += 0x00202020;
                rc = RT_TARG::validateData(l_lidStruct,
                                           l_rsvdMemPtr,
                                           l_lidDataSize,
                                           l_userdata2);
                if(rc != 0x12)
                {
                    TS_FAIL("testSaveRestoreAttrs> unexpected return code from "
                            "validateData, expected 0x12, received 0x%.2x",
                            rc);
                    break;
                }
                else if(l_userdata2 != l_headerRsvd->eyeCatcher)
                {
                    TS_FAIL("testSaveRestoreAttrs> unexpected user data from "
                            "validateData, expected 0x%.16llx, rcvd 0x%.16llx",
                            l_headerRsvd->eyeCatcher,
                            l_userdata2);
                    break;
                }
                else
                {
                    *l_pEyeCatcher -= 0x00202020;
                    l_userdata2 = 0;
                }

                // Detect TargetingHeader number of sections mismatch
                uint32_t *l_pNumSections =
                    reinterpret_cast<uint32_t*>(reinterpret_cast<uint64_t>(
                        &l_headerRsvd->numSections));
                *l_pNumSections += 2;
                uint64_t l_expected =
                    TWO_UINT32_TO_UINT64(l_headerLid->numSections,
                                         l_headerRsvd->numSections);
                rc = RT_TARG::validateData(l_lidStruct,
                                           l_rsvdMemPtr,
                                           l_lidDataSize,
                                           l_userdata2);
                if(rc != 0x13)
                {
                    TS_FAIL("testSaveRestoreAttrs> unexpected return code from "
                            "validateData, expected 0x13, received 0x%.2x",
                            rc);
                    break;
                }
                else if(l_userdata2 != l_expected)
                {
                    TS_FAIL("testSaveRestoreAttrs> unexpected user data from "
                            "validateData, expected 0x%.16llx, rcvd 0x%.16llx",
                            l_expected,
                            l_userdata2);
                    break;
                }
                else
                {
                    *l_pNumSections -= 2;
                    l_userdata2 = 0;
                }

                // Detect TargetingSection type mismatch
                TargetingSection* l_sectionLid =
                    reinterpret_cast<TargetingSection*>(
                        reinterpret_cast<uint64_t>(l_headerLid) +
                        sizeof(TargetingHeader) +
                        l_headerLid->offsetToSections);
                uint8_t l_sectionType = l_sectionLid[0].sectionType;
                uint8_t *l_pSectionType =
                    reinterpret_cast<uint8_t*>(reinterpret_cast<uint64_t>(
                        &l_sectionLid[0])); // sectionType is first field
                *l_pSectionType = l_sectionType + 0xF0;
                l_expected =
                    TWO_UINT32_TO_UINT64(l_sectionLid[0].sectionType,
                                         l_sectionRsvd[0].sectionType);
                rc = RT_TARG::validateData(l_lidStruct,
                                           l_rsvdMemPtr,
                                           l_lidDataSize,
                                           l_userdata2);
                if(rc != 0x14)
                {
                    TS_FAIL("testSaveRestoreAttrs> unexpected return code from "
                            "validateData, expected 0x14, received 0x%.2x",
                            rc);
                    break;
                }
                else if(l_userdata2 != l_expected)
                {
                    TS_FAIL("testSaveRestoreAttrs> unexpected user data from "
                            "validateData, expected 0x%.16llx, rcvd 0x%.16llx",
                            l_expected,
                            l_userdata2);
                    break;
                }
                else
                {
                    *l_pSectionType = l_sectionType;
                    l_userdata2 = 0;
                }

                // Validate LID Structure against Reserved Memory
                rc = RT_TARG::validateData(l_lidStruct,
                                           l_rsvdMemPtr,
                                           l_lidDataSize,
                                           l_userdata2);
                if(rc)
                {
                    TS_FAIL("testSaveRestoreAttrs> unexpected return code from "
                            "validateData, received 0x%.2x",
                            rc);
                    break;
                }
                else if(l_userdata2 != 0)
                {
                    TS_FAIL("testSaveRestoreAttrs> unexpected user data from "
                            "validateData, received 0x%.16llx",
                            l_userdata2);
                    break;
                }

                TRACFCOMP(g_trac_targeting,"testSaveRestoreAttrs SUCCESS");
            } while(false);

            free(l_lidStruct);
            l_lidStruct = nullptr;

            TRACFCOMP(g_trac_targeting,EXIT_MRK"testSaveRestoreAttrs");
#endif
        }

};
OpenPOWER on IntegriCloud