summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/test/hwpMvpdAccessorTest.H
blob: 111f8038878da023b2c7e9ba0a06e79ef83311c4 (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
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/test/hwpMvpdAccessorTest.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 __HWPMVPDACCESSORTEST_H
#define __HWPMVPDACCESSORTEST_H

// set to 1 for doing unit tests, set to 0 for production
#define HWPMVPDACCESSORTEST_UT 0

/**
 *  @file hwpMvpdAccessorTest.H
 *
 *  @brief Test cases for Mvpd HWP accessors.
*/

#include <cxxtest/TestSuite.H>

#include    <fapi.H>
#include    <fapiPlatHwpInvoker.H>

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

#include    <getMvpdRing.H>
#include    <setMvpdRing.H>

#include <errl/errlmanager.H>
#include <errl/errlentry.H>
#include <devicefw/driverif.H>
#include <trace/interface.H>

//      pull in CompressedScanData def from proc_slw_build HWP
#include <p8_scan_compression.H>

using namespace     fapi;
using   namespace   TARGETING;

class hwpMvpdAccessorTest: public CxxTest::TestSuite
{
public:

    /**
     * @brief   call fapiGetMvpdField to fetch a mvpd records.
     *
     */
    void    testGetMvpd()
    {
        fapi::ReturnCode    l_fapirc( fapi::FAPI_RC_SUCCESS );
        uint8_t             *l_pdRRecord            =   NULL;
        uint32_t            l_pdRLen                =   0;

        // list of MVPD records to test. Need to be in PNOR or procmvpd.dat
        // when g_usePNOR is false.
        struct _testMvpdRecords {
            fapi::MvpdRecord record;
            fapi::MvpdKeyword keyword;
        }  l_mvpdRecords[] = {
#if HWPMVPDACCESSORTEST_UT
            { MVPD_RECORD_CP00, MVPD_KEYWORD_PDG},
            { MVPD_RECORD_MER0, MVPD_KEYWORD_PDI},
//          { MVPD_RECORD_VER0, MVPD_KEYWORD_PDI}, //VER0 in spec,not supported
#endif
            { MVPD_RECORD_VWML, MVPD_KEYWORD_PDI},
        };

        TS_TRACE( "testGetMvpd entry" );

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

        TS_TRACE( "testGetMvpd l_cpuTargetList.size()= 0x%x ",
                                      l_cpuTargetList.size() );


        // loop thru all the cpu's
        for (TargetHandleList::iterator l_cpu_iter = l_cpuTargetList.begin();
                l_cpu_iter != l_cpuTargetList.end();
                ++l_cpu_iter)
        {
            //  make a local copy of the CPU target
            TARGETING::Target* l_cpu_target = *l_cpu_iter;

            TS_TRACE( "target HUID %.8X", TARGETING::get_huid(l_cpu_target));

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

            // loop through mvpd records of interest
            const uint32_t numRecords =
                    sizeof(l_mvpdRecords)/sizeof(l_mvpdRecords[0]);
            for (uint8_t i=0;i<numRecords;i++) {

                TS_TRACE( "record = 0x%x keyword = 0x%x",
                   l_mvpdRecords[i].record,
                   l_mvpdRecords[i].keyword);

                TS_TRACE( "call fapiGetMvpdField with NULL pointer" );

                //  call fapiGetMvpdField once with a NULL pointer to get the
                //  buffer size should return no error now.
                l_fapirc = fapiGetMvpdField(l_mvpdRecords[i].record,
                                        l_mvpdRecords[i].keyword,
                                        l_fapi_cpu_target,
                                        NULL,
                                        l_pdRLen );
                if ( l_fapirc != fapi::FAPI_RC_SUCCESS )
                {
                    TS_FAIL( "fapiGetMvpdField:  expected FAPI_RC_SUCCESS" );
                    fapiLogError(l_fapirc);
                    return;
                }

                TS_TRACE( "fapiGetMvpdField: size of record = 0x%x",
                      l_pdRLen );

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

                //  call fapiGetMvpdField once with a valid pointer
                l_fapirc = fapiGetMvpdField(l_mvpdRecords[i].record,
                                        l_mvpdRecords[i].keyword,
                                        l_fapi_cpu_target,
                                        l_pdRRecord,
                                        l_pdRLen );
                if ( l_fapirc != fapi::FAPI_RC_SUCCESS )
                {
                    TS_FAIL( "fapiGetMvpdField:  expected FAPI_RC_SUCCESS" );
                    fapiLogError(l_fapirc);
                    free( l_pdRRecord );
                    return;
                }

                //  clean up memory
                free( l_pdRRecord );
            }
        }

        TS_TRACE( "testGetMvpd exit" );
    }


    // Structure used to save/restore the VPD
    typedef struct saveRestoreData_t {
        TARGETING::Target* target;
        uint8_t* CP00_pdG;
        size_t CP00_pdG_size;
        uint8_t* CP00_pdR;
        size_t CP00_pdR_size;
    } saveRestoreData_t;

    /**
     * @brief Test get and set of 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_ringId        =   0;
        uint32_t            l_chipletId     =   0;
        uint32_t            l_bufsize       =   0x200;
        errlHndl_t l_errhdl = NULL;

        // This data needs to be in sync with the procmvpd.dat file
        // the setMvpdFunc tests use the last row. The test
        //  expects it to be a mid x20 byte ring in the #G keyword
        struct _testRRstr {
            fapi::MvpdKeyword keyword;
            uint32_t ringIdval;
            uint32_t chipletIdval;
            uint32_t size;
            uint32_t rc;
        }  l_ringModifiers[] = {
            { MVPD_KEYWORD_PDG, 0xa4, 0xFF, 0x20,  //last #G
                                fapi::RC_REPAIR_RING_NOT_FOUND },
            { MVPD_KEYWORD_PDR, 0xe0, 0x08, 0x20, //first #R
                                FAPI_RC_SUCCESS },
            { MVPD_KEYWORD_PDR, 0xe2, 0x16, 0x20, //big #R
                                FAPI_RC_SUCCESS },
            { MVPD_KEYWORD_PDG, 0xa2, 0x08, 0x20, //mid #G
                                FAPI_RC_SUCCESS },
            { MVPD_KEYWORD_PDR, 0xe1, 0x16, 0x20,//big #R
                                FAPI_RC_SUCCESS },
        };
        const size_t VALID_INDEX = 2;
        const size_t TEST_INDEX = 4;

        TS_TRACE( "testRepairRings entry" );

        std::list<saveRestoreData_t> l_srData;

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

        // loop thru all the cpu's
        for (TargetHandleList::iterator l_cpu_iter = l_cpuTargetList.begin();
                l_cpu_iter != l_cpuTargetList.end();
                ++l_cpu_iter)
        {
            //  make a local copy of the CPU target
            TARGETING::Target* l_cpu_target = *l_cpu_iter;

            TS_TRACE( "testRepairRings: "
                "target HUID %.8X",
                TARGETING::get_huid(l_cpu_target));

            //--  Save the entire VPD record to restore later
            saveRestoreData_t tmpsave;
            tmpsave.target = l_cpu_target;

            // do a read with NULL buffer to get the record size
            l_errhdl = deviceRead( l_cpu_target,
                                   NULL,
                                   tmpsave.CP00_pdG_size,
                                   DEVICE_MVPD_ADDRESS( MVPD_RECORD_CP00,
                                                        MVPD_KEYWORD_PDG ) );
            if( l_errhdl )
            {
                TS_FAIL("Error finding size of CP00/#G for %.8X",
                        TARGETING::get_huid(l_cpu_target));
                errlCommit( l_errhdl, VPD_COMP_ID );
                continue;
            }

            // now go get the data
            tmpsave.CP00_pdG = new uint8_t[tmpsave.CP00_pdG_size];
            l_errhdl = deviceRead( l_cpu_target,
                                   tmpsave.CP00_pdG,
                                   tmpsave.CP00_pdG_size,
                                   DEVICE_MVPD_ADDRESS( MVPD_RECORD_CP00,
                                                        MVPD_KEYWORD_PDG ) );
            if( l_errhdl )
            {
                TS_FAIL("Error reading CP00/#G from %.8X",
                        TARGETING::get_huid(l_cpu_target));
                errlCommit( l_errhdl, VPD_COMP_ID );
                delete[] tmpsave.CP00_pdG;
                continue;
            }

            // do a read with NULL buffer to get the record size
            l_errhdl = deviceRead( l_cpu_target,
                                   NULL,
                                   tmpsave.CP00_pdR_size,
                                   DEVICE_MVPD_ADDRESS( MVPD_RECORD_CP00,
                                                        MVPD_KEYWORD_PDR ) );
            if( l_errhdl )
            {
                TS_FAIL("Error finding size of CP00/#R for %.8X",
                        TARGETING::get_huid(l_cpu_target));
                errlCommit( l_errhdl, VPD_COMP_ID );
                continue;
            }

            // now go get the data
            tmpsave.CP00_pdR = new uint8_t[tmpsave.CP00_pdR_size];
            l_errhdl = deviceRead( l_cpu_target,
                                   tmpsave.CP00_pdR,
                                   tmpsave.CP00_pdR_size,
                                   DEVICE_MVPD_ADDRESS( MVPD_RECORD_CP00,
                                                        MVPD_KEYWORD_PDR ) );
            if( l_errhdl )
            {
                TS_FAIL("Error reading CP00/#R from %.8X",
                        TARGETING::get_huid(l_cpu_target));
                errlCommit( l_errhdl, VPD_COMP_ID );
                delete[] tmpsave.CP00_pdR;
                continue;
            }

            // add to the master list
            l_srData.push_back(tmpsave);

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

            //  allocate some space to put the record(s)
            if( l_pRingBuf != NULL )
            {
                delete[] l_pRingBuf;
            }
            l_pRingBuf      =    new uint8_t[l_bufsize];

            //  ----------------------------------------------------------------
            //  Pass in 0 for the ring modifier, should return with "not found"
            //  error
            //  ----------------------------------------------------------------
            TS_TRACE( "testRepairRings: pass in invalid ringId" );
            l_ringBufsize   =   l_bufsize;
            l_ringId        =   0;     // ringId
            l_chipletId     =   0;     // chipletId
            l_fapirc    =   getMvpdRing(  MVPD_RECORD_CP00,
                                          MVPD_KEYWORD_PDR,
                                          l_fapi_cpu_target,
                                          l_chipletId,
                                          l_ringId,
                                          l_pRingBuf,
                                          l_ringBufsize );
            TS_TRACE("testRepairRings:ringId=0x%x chipletId=0x%x Bufsize=0x%x",
                      l_ringId,
                      l_chipletId,
                      l_ringBufsize );
            if ( l_fapirc != fapi::RC_REPAIR_RING_NOT_FOUND )
            {
                //  note:  "uint32_t" below is an _operator_ of fapi::ReturnCode
                TS_FAIL("testRepairRings: expect not found rc FAIL: 0x%x, 0x%x",
                         fapi::RC_REPAIR_RING_NOT_FOUND,
                         static_cast<uint32_t>(l_fapirc) );
                fapiLogError(l_fapirc);
            }

            //  ----------------------------------------------------------------
            //  Pass in a buffer size that is too small with a valid
            //  ringId/chipletId, should return error with correct length
            //  and invalid size return code..
            //  ----------------------------------------------------------------
            TS_TRACE( "testRepairRings: pass buffer too small %d ",
                    VALID_INDEX );
            l_ringBufsize   =   0x0;
            l_ringId        =   l_ringModifiers[VALID_INDEX].ringIdval;
            l_chipletId     =   l_ringModifiers[VALID_INDEX].chipletIdval;
            l_fapirc    =   getMvpdRing(  MVPD_RECORD_CP00,
                                          MVPD_KEYWORD_PDR,
                                          l_fapi_cpu_target,
                                          l_chipletId,
                                          l_ringId,
                                          l_pRingBuf,
                                          l_ringBufsize );
            TS_TRACE("testRepairRings:ringId=0x%x chipletId=0x%x: Bufsize=0x%x",
                      l_ringId,
                      l_chipletId,
                      l_ringBufsize );
            if ( l_fapirc != fapi::RC_REPAIR_RING_INVALID_SIZE )
            {
                //  note:  "uint32_t" below is an _operator_ of fapi::ReturnCode
                TS_FAIL("testRepairRings: expect invalid size FAIL: exp=0x%x,"
                         " act=0x%x, ring=0x%X",
                         fapi::RC_REPAIR_RING_INVALID_SIZE,
                         static_cast<uint32_t>(l_fapirc),
                         l_ringId);

                fapiLogError(l_fapirc);
            }
            else if ( l_ringBufsize != l_ringModifiers[VALID_INDEX].size )
            {
                TS_FAIL( "testRepairRings: size mismatch FAIL1 on ring 0x%X:"
                         " exp=0x%x, act=0x%x",
                         l_ringId,
                         l_ringModifiers[VALID_INDEX].size,
                         l_ringBufsize  );
            }

            //  ----------------------------------------------------------------
            //  Pass in a NULL pointer with a valid ringId/chipletId, should
            //  return with correct length and successful return code.
            //  ----------------------------------------------------------------
            TS_TRACE( "testRepairRings: get size of ring %d ", VALID_INDEX );
            l_ringBufsize   =   0x0;
            l_ringId        =   l_ringModifiers[VALID_INDEX].ringIdval;
            l_chipletId     =   l_ringModifiers[VALID_INDEX].chipletIdval;
            l_fapirc    =   getMvpdRing(  MVPD_RECORD_CP00,
                                          MVPD_KEYWORD_PDR,
                                          l_fapi_cpu_target,
                                          l_chipletId,
                                          l_ringId,
                                          NULL,
                                          l_ringBufsize );
            TS_TRACE("testRepairRings:ringId=0x%x chipletId=0x%x: Bufsize=0x%x",
                      l_ringId,
                      l_chipletId,
                      l_ringBufsize );
            if ( l_fapirc )
            {
                //  note:  "uint32_t" below is an _operator_ of fapi::ReturnCode
                TS_FAIL( "testRepairRings: expect success rc FAIL: 0x%x, 0x%x",
                         fapi::FAPI_RC_SUCCESS,
                         static_cast<uint32_t>(l_fapirc));

                fapiLogError(l_fapirc);
            }
            else if ( l_ringBufsize != l_ringModifiers[VALID_INDEX].size )
            {
                TS_FAIL( "testRepairRings: size mismatch FAIL2 on ring 0x%X:"
                         " exp=0x%x, act=0x%x",
                         l_ringId,
                         l_ringModifiers[VALID_INDEX].size,
                         l_ringBufsize  );
            }

            //  ----------------------------------------------------------------
            //  Fetch rings
            //  ----------------------------------------------------------------
            const uint32_t numRings =
                        sizeof(l_ringModifiers)/sizeof(l_ringModifiers[0]);
            for (size_t i=0;i<numRings;i++)
            {
                TS_TRACE( "testRepairRings: get ring %d", i );
                l_ringBufsize   =   l_bufsize;
                l_ringId    =   l_ringModifiers[i].ringIdval;
                l_chipletId =   l_ringModifiers[i].chipletIdval;
                l_fapirc    =   getMvpdRing(  MVPD_RECORD_CP00,
                                          l_ringModifiers[i].keyword,
                                          l_fapi_cpu_target,
                                          l_chipletId,
                                          l_ringId,
                                          l_pRingBuf,
                                          l_ringBufsize );
                TS_TRACE("testRepairRings ringId=0x%x chipletId=0x%x size=0x%x",
                      l_ringId, l_chipletId, l_ringBufsize );

                if ( l_fapirc != l_ringModifiers[i].rc )
                {
                    // note: uint32_t below is an _operator_ of fapi::ReturnCode
                    TS_FAIL( "testRepairRings: getMvpdRing rc FAIL 1: rc=0x%x,"
                             " ring=0x%X, chiplet=0x%X, i=%d",
                             static_cast<uint32_t>(l_fapirc),
                             l_ringId,
                             l_chipletId,
                             i );
                    fapiLogError(l_fapirc);
                    continue;
                }
                else if( l_fapirc != fapi::FAPI_RC_SUCCESS )
                {
                    // not an error, but the next check isn't valid
                    continue;
                }

                if ( l_ringBufsize != l_ringModifiers[i].size )
                {
                    TS_FAIL( "testRepairRings: size mismatch FAIL3 on ring %X:"
                             " exp=0x%x, act=0x%x",
                             l_ringId,
                             l_ringModifiers[i].size,
                             l_ringBufsize  );
                }

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

            //  ----------------------------------------------------------------
            //  write different data, read it back to verify, then put the
            //     original data back.
            //  ----------------------------------------------------------------
            uint32_t  l_offset =0;
            uint8_t   l_data = 0;
            uint8_t  *l_pData = NULL;

            // use data from last fetch test case.
            TS_TRACE( "testRepairRings: update in place  ring %d", TEST_INDEX );
            l_ringId    =   l_ringModifiers[TEST_INDEX].ringIdval;
            l_chipletId =   l_ringModifiers[TEST_INDEX].chipletIdval;
            l_ringBufsize = l_ringModifiers[TEST_INDEX].size;

            // put in recognizable data for the debug data dump
            l_pData = l_pRingBuf+sizeof(CompressedScanData);
            for (l_offset = 0,l_data=0x10; l_offset <
                 l_ringBufsize-sizeof(CompressedScanData); l_offset++)
            {
               *l_pData++ = l_data++;
            }
            TRACDBIN( g_trac_test, "testRepairRings: updated ring data:",
                      l_pRingBuf,
                      l_ringBufsize );
            setMvpdRing_FP_t (l_setMvpdRing) = &setMvpdRing; //verify typedef
            l_fapirc    =   (*l_setMvpdRing)(  MVPD_RECORD_CP00,
                                          l_ringModifiers[TEST_INDEX].keyword,
                                          l_fapi_cpu_target,
                                          l_chipletId,
                                          l_ringId,
                                          l_pRingBuf,
                                          l_ringBufsize );

            if ( l_fapirc != fapi::FAPI_RC_SUCCESS )
            {
                //  note:  "uint32_t" below is an _operator_ of fapi::ReturnCode
                TS_FAIL( "testRepairRings: setMvpdRing rc FAIL 1: exp=0x%x,"
                         " rc=0x%x",
                         fapi::FAPI_RC_SUCCESS,
                         static_cast<uint32_t>(l_fapirc) );
                fapiLogError(l_fapirc);
            }

            //  ----------------------------------------------------------------
            //  write back a smaller ring to cause a shift left in the record
            //  ----------------------------------------------------------------
            TS_TRACE( "testRepairRings: shrink a  ring %d", TEST_INDEX );
            l_ringBufsize = l_ringModifiers[TEST_INDEX].size-4;
            reinterpret_cast<CompressedScanData *>(l_pRingBuf)->
                                                   iv_size = l_ringBufsize;

            // put in recognizable data for the debug data dump
            l_pData = l_pRingBuf+sizeof(CompressedScanData);
            for (l_offset = 0,l_data=0x20; l_offset <
                 l_ringBufsize-sizeof(CompressedScanData); l_offset++)
            {
               *l_pData++ = l_data++;
            }
            TRACDBIN( g_trac_test, "testRepairRings: updated ring data:",
                      l_pRingBuf,
                      l_ringBufsize );
            l_fapirc    =   setMvpdRing(  MVPD_RECORD_CP00,
                                          l_ringModifiers[TEST_INDEX].keyword,
                                          l_fapi_cpu_target,
                                          l_chipletId,
                                          l_ringId,
                                          l_pRingBuf,
                                          l_ringBufsize );

            if ( l_fapirc != fapi::FAPI_RC_SUCCESS )
            {
                //  note:  "uint32_t" below is an _operator_ of fapi::ReturnCode
                TS_FAIL( "testRepairRings: setMvpdRing rc FAIL 2:"
                         " exp=0x%x, rc=0x%x",
                         fapi::FAPI_RC_SUCCESS,
                         static_cast<uint32_t>(l_fapirc) );

                fapiLogError(l_fapirc);
            }

            //  ----------------------------------------------------------------
            //  write back a larger  ring to cause a shift right in the record
            //  ----------------------------------------------------------------
            TS_TRACE( "testRepairRings: grow a ring %d", TEST_INDEX );
            l_ringBufsize = l_ringModifiers[TEST_INDEX].size+16;
            reinterpret_cast<CompressedScanData *>(l_pRingBuf)->
                                                 iv_size = l_ringBufsize;

            // put in recognizable data for the debug data dump
            l_pData = l_pRingBuf+sizeof(CompressedScanData);
            for (l_offset = 0,l_data=0x30; l_offset <
                         l_ringBufsize-sizeof(CompressedScanData); l_offset++)
            {
               *l_pData++ = l_data++;
            }
            TRACDBIN( g_trac_test, "testRepairRings: updated ring data:",
                      l_pRingBuf,
                      l_ringBufsize );
            l_fapirc    =   setMvpdRing(  MVPD_RECORD_CP00,
                                          l_ringModifiers[TEST_INDEX].keyword,
                                          l_fapi_cpu_target,
                                          l_chipletId,
                                          l_ringId,
                                          l_pRingBuf,
                                          l_ringBufsize );

            if ( l_fapirc != fapi::FAPI_RC_SUCCESS )
            {
                //  note:  "uint32_t" below is an _operator_ of fapi::ReturnCode
                TS_FAIL( "testRepairRings: setMvpdRing rc FAIL 3: exp=0x%x,"
                         " rc=0x%x",
                         fapi::FAPI_RC_SUCCESS,
                         static_cast<uint32_t>(l_fapirc) );

                fapiLogError(l_fapirc);
            }

            //  ----------------------------------------------------------------
            //  append a ring that is not already there to the end
            //  ----------------------------------------------------------------
            TS_TRACE( "testRepairRings: append a ring" );
            l_ringId    =   0x77;
            l_chipletId =   0x88;
            l_ringBufsize = l_ringModifiers[TEST_INDEX].size;
            reinterpret_cast<CompressedScanData *>(l_pRingBuf)->
                                                   iv_size = l_ringBufsize;
            reinterpret_cast<CompressedScanData *>(l_pRingBuf)->
                                                   iv_ringId = l_ringId;
            reinterpret_cast<CompressedScanData *>(l_pRingBuf)->
                                                   iv_chipletId = l_chipletId;

            // put in recognizable data for the debug data dump
            l_pData = l_pRingBuf+sizeof(CompressedScanData);
            for (l_offset = 0,l_data=0x50; l_offset <
                        l_ringBufsize-sizeof(CompressedScanData); l_offset++)
            {
               *l_pData++ = l_data++;
            }
            TRACDBIN( g_trac_test, "testRepairRings: updated ring data:",
                      l_pRingBuf,
                      l_ringBufsize );
            l_fapirc    =   setMvpdRing(  MVPD_RECORD_CP00,
                                          l_ringModifiers[TEST_INDEX].keyword,
                                          l_fapi_cpu_target,
                                          l_chipletId,
                                          l_ringId,
                                          l_pRingBuf,
                                          l_ringBufsize );

            if ( l_fapirc != fapi::FAPI_RC_SUCCESS )
            {
                //  note:  "uint32_t" below is an _operator_ of fapi::ReturnCode
                TS_FAIL( "testRepairRings: setMvpdRing rc FAIL 4: exp=0x%x,"
                         " rc=0x%x",
                         fapi::FAPI_RC_SUCCESS,
                         static_cast<uint32_t>(l_fapirc) );

                fapiLogError(l_fapirc);
            }

            // read back data to prove the writes worked
            l_ringId    =   l_ringModifiers[TEST_INDEX].ringIdval;
            l_chipletId =   l_ringModifiers[TEST_INDEX].chipletIdval;
            l_ringBufsize = l_ringModifiers[TEST_INDEX].size+16;
            l_fapirc    =   getMvpdRing(  MVPD_RECORD_CP00,
                                          l_ringModifiers[TEST_INDEX].keyword,
                                          l_fapi_cpu_target,
                                          l_chipletId,
                                          l_ringId,
                                          l_pRingBuf,
                                          l_ringBufsize );

            if ( l_fapirc != fapi::FAPI_RC_SUCCESS )
            {
                TS_FAIL( "testRepairRings: getMvpdRing rc FAIL 2: 0x%x, 0x%x",
                         fapi::FAPI_RC_SUCCESS,
                         static_cast<uint32_t>(l_fapirc) );
                fapiLogError(l_fapirc);
            }
            else
            {
                l_pData = l_pRingBuf+sizeof(CompressedScanData);
                for( l_offset = 0,l_data=0x30;
                     l_offset < l_ringBufsize-sizeof(CompressedScanData);
                     l_offset++)
                {
                    if( l_pData[l_offset] != l_data++ )
                    {
                        TS_FAIL("Mismatch after write on ring %X",
                                l_ringId);
                        TRACFBIN(g_trac_test,
                                 "ringdata=",
                                 l_pRingBuf,l_ringBufsize);
                    }
                }
            }

            // read back data to prove the writes worked
            l_ringId    =   0x77;
            l_chipletId =   0x88;
            l_ringBufsize = l_ringModifiers[TEST_INDEX].size;
            l_fapirc    =   getMvpdRing(  MVPD_RECORD_CP00,
                                          l_ringModifiers[TEST_INDEX].keyword,
                                          l_fapi_cpu_target,
                                          l_chipletId,
                                          l_ringId,
                                          l_pRingBuf,
                                          l_ringBufsize );

            if ( l_fapirc != fapi::FAPI_RC_SUCCESS )
            {
                TS_FAIL( "testRepairRings: getMvpdRing rc FAIL 3: 0x%x, 0x%x",
                         fapi::FAPI_RC_SUCCESS,
                         static_cast<uint32_t>(l_fapirc) );
                fapiLogError(l_fapirc);
            }
            else
            {
                l_pData = l_pRingBuf+sizeof(CompressedScanData);
                for (l_offset = 0,l_data=0x50;
                     l_offset < l_ringBufsize-sizeof(CompressedScanData);
                     l_offset++)
                {
                    if( l_pData[l_offset] != l_data++ )
                    {
                        TS_FAIL("Mismatch after write on ring %X",
                                l_ringId);
                        TRACFBIN(g_trac_test,
                                 "ringdata=",
                                 l_pRingBuf,l_ringBufsize);
                    }
                }
            }


            //  ----------------------------------------------------------------
            //  Pass in a buffer size that does not match the exact size
            //  of the ringId/chipletId, should  return with correct length
            //  and invalid size return code.
            //  ----------------------------------------------------------------
            TS_TRACE("testRepairRing:bad size ring=0x%x chiplet=0x%x size=0x%x",
                      l_ringId,
                      l_chipletId,
                      l_ringBufsize );
            l_ringBufsize   =   l_bufsize;
            l_ringId        =   l_ringModifiers[TEST_INDEX].ringIdval;
            l_chipletId     =   l_ringModifiers[TEST_INDEX].chipletIdval;
            l_fapirc    =   setMvpdRing(  MVPD_RECORD_CP00,
                                          MVPD_KEYWORD_PDR,
                                          l_fapi_cpu_target,
                                          l_chipletId,
                                          l_ringId,
                                          l_pRingBuf,
                                          l_ringBufsize );

            if ( l_fapirc != fapi::RC_MVPD_RING_FUNC_INVALID_PARAMETER )
            {
                //  note:  "uint32_t" below is an _operator_ of fapi::ReturnCode
                TS_FAIL("testRepairRings:invalid ring size rc FAIL:"
                         " exp=0x%x, act=0x%x",
                         fapi::RC_REPAIR_RING_INVALID_SIZE,
                         static_cast<uint32_t>(l_fapirc));

                fapiLogError(l_fapirc);
            }

            //  ----------------------------------------------------------------
            //  Pass in 0 for the ring modifier, should return with "not found"
            //  error
            //  ----------------------------------------------------------------
            TS_TRACE( "testRepairRings: pass in invalid ringId" );
            l_ringBufsize   =   l_ringModifiers[TEST_INDEX].size;
            l_ringId        =   0;     // ringId
            l_chipletId     =   0;     // chipletId
            l_fapirc    =   setMvpdRing(  MVPD_RECORD_CP00,
                                          MVPD_KEYWORD_PDR,
                                          l_fapi_cpu_target,
                                          l_chipletId,
                                          l_ringId,
                                          l_pRingBuf,
                                          l_ringBufsize );

            TS_TRACE("testRepairRings:ringId=0x%x chipletId=0x%x size=0x%x",
                      l_ringId,
                      l_chipletId,
                      l_ringBufsize );
            if ( l_fapirc != fapi::RC_MVPD_RING_FUNC_INVALID_PARAMETER )
            {
                //  note:  "uint32_t" below is an _operator_ of fapi::ReturnCode
                TS_FAIL( "testRepairRings:  rc FAIL: exp=0x%x, act=0x%x",
                         fapi::RC_REPAIR_RING_NOT_FOUND,
                         static_cast<uint32_t>(l_fapirc) );
                fapiLogError(l_fapirc);
            }
            //  ----------------------------------------------------------------
            //  Pass in a NULL pointer with a valid ringId/chipletId, should
            //  return with correct length and successful return code.
            //  ----------------------------------------------------------------
            TS_TRACE( "testRepairRings: get size of ring(from set) %d ",
                     TEST_INDEX );
            l_ringBufsize   =   0x0;
            l_ringId        =   l_ringModifiers[TEST_INDEX].ringIdval;
            l_chipletId     =   l_ringModifiers[TEST_INDEX].chipletIdval;
            l_fapirc    =   setMvpdRing(  MVPD_RECORD_CP00,
                                          MVPD_KEYWORD_PDR,
                                          l_fapi_cpu_target,
                                          l_chipletId,
                                          l_ringId,
                                          NULL,
                                          l_ringBufsize );

            TS_TRACE("testRepairRings:ringId=0x%x chipletId=0x%x size=0x%x",
                      l_ringId,
                      l_chipletId,
                      l_ringBufsize );
            if ( l_fapirc != fapi::RC_MVPD_RING_FUNC_INVALID_PARAMETER )
            {
                //  note:  "uint32_t" below is an _operator_ of fapi::ReturnCode
                TS_FAIL( "testRepairRings: setMvpdRing rc FAIL 5:"
                         " exp=0x%x, act=0x%x",
                         fapi::RC_MVPD_RING_FUNC_INVALID_PARAMETER,
                         static_cast<uint32_t>(l_fapirc));

                fapiLogError(l_fapirc);
            }

            //  ----------------------------------------------------------------
            //  Pass in an invalid chiplet id with a valid ring, should fail
            //  ----------------------------------------------------------------
            l_ringBufsize   =   l_bufsize;
            l_ringId        =   l_ringModifiers[TEST_INDEX].ringIdval;
            l_chipletId     =   0x22;
            TS_TRACE("testRepairRing:invalid chiplet ring=0x%X chiplet=0x%X"
                      " size=0x%x",
                      l_ringId,
                      l_chipletId,
                      l_ringBufsize );
            l_fapirc    =   getMvpdRing(  MVPD_RECORD_CP00,
                                          MVPD_KEYWORD_PDR,
                                          l_fapi_cpu_target,
                                          l_chipletId,
                                          l_ringId,
                                          l_pRingBuf,
                                          l_ringBufsize );

            if ( l_fapirc != fapi::RC_REPAIR_RING_NOT_FOUND )
            {
                //  note:  "uint32_t" below is an _operator_ of fapi::ReturnCode
                TS_FAIL("testRepairRings:invalid chipletid rc FAIL:"
                         " exp=0x%x, act=0x%x",
                         fapi::RC_REPAIR_RING_NOT_FOUND,
                         static_cast<uint32_t>(l_fapirc));

                fapiLogError(l_fapirc);
            }

        }

        //-- Put the original data back into the vpd
        for( std::list<saveRestoreData_t>::iterator sv = l_srData.begin();
             sv != l_srData.end();
             ++sv )
        {
            if( sv->target == NULL )
            {
                continue;
            }

            if( sv->CP00_pdG != NULL )
            {
                l_errhdl = deviceWrite( sv->target,
                                        sv->CP00_pdG,
                                        sv->CP00_pdG_size,
                                        DEVICE_MVPD_ADDRESS( MVPD_RECORD_CP00,
                                                          MVPD_KEYWORD_PDG ) );
                if( l_errhdl )
                {
                    TS_FAIL("Error restoring CP00/#G to %.8X",
                            TARGETING::get_huid(sv->target));
                    errlCommit( l_errhdl, VPD_COMP_ID );
                }
                delete[] sv->CP00_pdG;
                sv->CP00_pdG = NULL;
            }

            if( sv->CP00_pdR != NULL )
            {
                l_errhdl = deviceWrite( sv->target,
                                        sv->CP00_pdR,
                                        sv->CP00_pdR_size,
                                        DEVICE_MVPD_ADDRESS( MVPD_RECORD_CP00,
                                                          MVPD_KEYWORD_PDR ) );
                if( l_errhdl )
                {
                    TS_FAIL("Error restoring CP00/#R to %.8X",
                            TARGETING::get_huid(sv->target));
                    errlCommit( l_errhdl, VPD_COMP_ID );
                }
                delete[] sv->CP00_pdR;
                sv->CP00_pdR = NULL;
            }
        }
        //--

        //  delete allocated space
        if( l_pRingBuf )
        {
            delete[]    l_pRingBuf;
        }
        for( std::list<saveRestoreData_t>::iterator sv = l_srData.begin();
             sv != l_srData.end();
             ++sv )
        {
            if( sv->CP00_pdG != NULL )
            {
                delete[] sv->CP00_pdG;
                sv->CP00_pdG = NULL;
            }
            if( sv->CP00_pdR != NULL )
            {
                delete[] sv->CP00_pdR;
                sv->CP00_pdR = NULL;
            }
        }


        TS_TRACE( "testRepairRings exit" );
    }

};  // end class

#endif
OpenPOWER on IntegriCloud