summaryrefslogtreecommitdiffstats
path: root/src/usr/sbe/test/sbeupdatetest.H
blob: 173aa7c97b0a9022a58fb5abe7c50372dcc67020 (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
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/sbe/test/sbeupdatetest.H $                            */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2013,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 __SBEUPDATETEST_H
#define __SBEUPDATETEST_H
/**
 *  @file sbeupdatetest.H
 *
 *  @brief Test cases for SBE Update code
 */
#include <sys/time.h>
#include <vector>
#include <cxxtest/TestSuite.H>
#include <errl/errlmanager.H>
#include <errl/errlentry.H>
#include <devicefw/driverif.H>
#include <vfs/vfs.H>
#include <targeting/common/utilFilter.H>
#include <sbe/sbeif.H>
#include "../sbe_update.H"


extern trace_desc_t* g_trac_sbe;

// Macros for unit testing
//#define TRACUCOMP(args...)  TRACFCOMP(args)
#define TRACUCOMP(args...)

const char SBE_BUILD_WINK_NAME[30] = "libbuild_winkle_images.so";
const char SBE_LIBRARY_NAME[16]    = "libsbe.so";


using namespace SBE;


void getTargetList( TARGETING::TYPE i_targetType,
                    TARGETING::TargetHandleList & o_targetList,
                    bool i_functional ) // if true: return functional targets
{


    TARGETING::getAllChips(o_targetList,
                           i_targetType,
                           i_functional);

    if ( o_targetList.size() == 0 )
    {
        TRACFCOMP( g_trac_sbe,
                   INFO_MRK"getTargetList() - Found Zero (%d) Targets of "
                   "type 0x%X",
                   o_targetList.size(), i_targetType );
    }

    TRACDCOMP( g_trac_sbe,
               "getTargetList() - found %d Targets of type 0x%X",
               o_targetList.size(), i_targetType );

    return;
}

TARGETING::Target* getFunctionalTarget(TARGETING::TYPE i_targetType)
{
    TARGETING::Target * theTarget = NULL;
    TRACDCOMP( g_trac_sbe,
               "getFunctionalTarget() - Finding Target of Type 0x%0x",
               i_targetType );

    do {
        // Get the Processor targets
        TARGETING::TargetHandleList targetList;
        getTargetList( i_targetType, targetList, true );

        if( ( 0 == targetList.size() ) ||
            ( NULL == targetList[0] ) )
        {
            TRACFCOMP( g_trac_sbe, ERR_MRK"getFunctionalTarget() - Couldn't "
                       "find functional Target of Type 0x%0x (list.size=%d)",
                       i_targetType, targetList.size());
            continue;  // continue because have no valid targets
        }

        // List is of functional targets, so just return the first one
        theTarget = targetList[0];

    }while(0);

    TRACDCOMP( g_trac_sbe,
               "getFunctionalTarget() - Returning Target 0x%0x of Type 0x%0x",
               TARGETING::get_huid(theTarget), i_targetType );

    return theTarget;

}


errlHndl_t loadSbeModule(bool& o_loaded)
{
    errlHndl_t err = NULL;
    o_loaded = false;

    if(!VFS::module_is_loaded(SBE_LIBRARY_NAME))
    {
        err = VFS::module_load(SBE_LIBRARY_NAME);
        if(err)
        {
            // Don't use g_trac_sbe - libsbe might not be loaded
            TS_FAIL("loadSbeModule() - %s load failed", SBE_LIBRARY_NAME );

        }
        else
        {
            o_loaded = true;
        }
    }

    // This module is needed for certain HW procedure (like p8_xip_customize())
    if(!VFS::module_is_loaded(SBE_BUILD_WINK_NAME))
    {
        err = VFS::module_load(SBE_BUILD_WINK_NAME);
        if(err)
        {
            // Don't use g_trac_sbe - libsbe might not be loaded
            TS_FAIL("loadSbeModule() - %s load failed", SBE_BUILD_WINK_NAME);
        }
        else
        {
            o_loaded = true;
        }
    }

    return err;
}

errlHndl_t unloadSbeModule()
{
    errlHndl_t err = NULL;

    err = VFS::module_unload(SBE_LIBRARY_NAME);
    if(err)
    {
        // Don't use g_trac_sbe - libsbe might be unloaded
        TS_FAIL("unloadSbeModule() - %s unload failed", SBE_LIBRARY_NAME );

        // No break or return - still try and unload other module
    }

    err = VFS::module_unload(SBE_BUILD_WINK_NAME);
    if(err)
    {
        // Don't use g_trac_sbe - libsbe might be unloaded
        TS_FAIL("unloadSbeModule() - %s unload failed", SBE_BUILD_WINK_NAME);
    }

    return err;
}


class SBEUpdateTest: public CxxTest::TestSuite
{
  public:

    /**
     * @brief This function will test __trimCoreMask
     */
    void testTrimBitMask( void )
    {

        uint64_t fails = 0x0;
        uint64_t total = 0x0;

        do{

            TRACFCOMP( g_trac_sbe,
                       ENTER_MRK"testTrimBitMask()" );

            struct
            {
                uint32_t inMask;
                uint32_t maxBits;
                uint32_t outMask;
            } testData[] =
            {
                {0xFFFFFFFF, 10, 0x000003FF},
                {0xFFFFFFFF, 32, 0xFFFFFFFF},
                {0x0000FF00, 4,  0x00000F00},
                {0x0000FA30, 3,  0x00000230},
                {0x0000FF00, 8,  0x0000FF00},
                {0x0000FF50, 16, 0x0000FF50},
                {0x0000EC50, 4,  0x00000C50},
                {0x000000FF, 5,  0x0000001F},
                {0x000000FF, 8,  0x000000FF},
                {0x11111111, 5,  0x00011111},
                {0x55555555, 11, 0x00155555},
            };
            const uint32_t NUM_TESTS = sizeof(testData)/sizeof(testData[0]);

            uint32_t retMask = 0;

            for(uint32_t i=0; i < NUM_TESTS; i++)
            {
                retMask = trimBitMask(testData[i].inMask,
                                      testData[i].maxBits);
                total++;
                if(retMask != testData[i].outMask)
                {
                    fails++;
                    TRACFCOMP( g_trac_sbe, ERR_MRK"testTrimBitMask() - i=%d, "
                               "retMask=0x%.8X, expMask=0x%.8X",
                               i, retMask, testData[i].outMask);
                    TS_FAIL("testTrimBitMask() - Return data did not match "
                            "expected data.");
                }
            }

        }while(0);

        TRACFCOMP( g_trac_sbe,
                   EXIT_MRK"testTrimBitMask - %d/%d fails",
                   fails, total );
    }

    /**
     * @brief This function will test SBE Update's ability
     *        to find SBE images in PNOR
     */

    void testFindSbeInPnor ( void )
    {
        errlHndl_t err = NULL;
        uint64_t fails = 0x0;
        uint64_t total = 0x0;

        TARGETING::Target* theTarget = NULL;
        void* sbeImgPtr = NULL;
        size_t sbeImgSize = 0;
        sbe_image_version_t version;

        do{

            TRACFCOMP( g_trac_sbe,
                       ENTER_MRK"testFindSbeInPnor()" );

            /****************************************************/
            /* Find a valid Processor                           */
            /****************************************************/
            theTarget = getFunctionalTarget(TARGETING::TYPE_PROC);
            if(theTarget == NULL)
            {
                total++;
                fails++;
                TS_FAIL("testReadSbeFromPnor() - No Functional Proc Targets found!");
                break;
            }

            total++;
            err = findSBEInPnor(theTarget,
                                sbeImgPtr,
                                sbeImgSize,
                                &version);

            if(err || (sbeImgPtr == NULL) || (sbeImgSize == 0) )
            {
                fails++;
                TRACFCOMP( g_trac_sbe, ERR_MRK"testFindSbeInPnor() - failure "
                           "finding Proc SBE image for uid=0x%X, ec=0x%.2X"
                           "sbeImgPtr=%p, sbeImgSize=0x%x",
                           TARGETING::get_huid(theTarget),
                           theTarget->getAttr<TARGETING::ATTR_EC>(),
                           sbeImgPtr, sbeImgSize );
                TS_FAIL("testFindSbeInPnor() -failure finding SBE image!");
                errlCommit( err,
                            SBE_COMP_ID );

            }
            TRACDBIN(g_trac_sbe, "testFindSbeInPnor()-Proc PNOR Version", &version, sizeof(version));
            TRACDBIN(g_trac_sbe, "testFindSbeInPnor()-Proc PNOR Image", sbeImgPtr, 0x80);


            /****************************************************/
            /*  Find a valid MemBuf                             */
            /****************************************************/
            theTarget = getFunctionalTarget(TARGETING::TYPE_MEMBUF);
            if(theTarget == NULL)
            {
                total++;
                fails++;
                TS_FAIL("testReadSbeFromPnor() - No Functional MemBuf Targets found!");
                break;
            }

            total++;
            err = findSBEInPnor(theTarget,
                                sbeImgPtr,
                                sbeImgSize,
                                &version);

            if(err || (sbeImgPtr == NULL) || (sbeImgSize == 0) )
            {
                fails++;
                TRACFCOMP( g_trac_sbe, ERR_MRK"testFindSbeInPnor() - failure "
                           "finding MemBuf SBE image for uid=0x%X, ec=0x%.2X, "
                           "sbeImgPtr=%p, sbeImgSize=0x%x",
                           TARGETING::get_huid(theTarget),
                           theTarget->getAttr<TARGETING::ATTR_EC>(),
                           sbeImgPtr, sbeImgSize );
                TS_FAIL("testFindSbeInPnor() -failure finding SBE image!");
                errlCommit( err,
                            SBE_COMP_ID );

            }
            TRACDBIN(g_trac_sbe, "testFindSbeInPnor()-MEMBUF PNOR Version", &version, sizeof(version));
            TRACDBIN(g_trac_sbe, "testFindSbeInPnor()-MEMBUF PNOR Image", sbeImgPtr, 0x80);


            /****************************************************/
            /* Verify invalid target Type is not found          */
            /****************************************************/
            // test with system target -- safe that this target is configured
            TARGETING::TargetService & tS = TARGETING::targetService();
            tS.getTopLevelTarget( theTarget );
            if(theTarget == NULL)
            {
                total++;
                fails++;
                TS_FAIL("testFindSbeInPnor() - System target Not Found!");
                break;
            }

            total++;
            err = findSBEInPnor(theTarget,
                                sbeImgPtr,
                                sbeImgSize);

            if(err)
            {
                TRACFCOMP( g_trac_sbe, "testFindSbeInPnor() - Did not "
                           "find system-target SBE image as expected: "
                           "uid=0x%X, err=0x%X",
                           TARGETING::get_huid(theTarget),
                           err->reasonCode() );
                delete err;
                err = NULL;
            }
            else
            {
                fails++;
                TRACFCOMP( g_trac_sbe, ERR_MRK"testFindSbeInPnor() - Fail "
                           " expected when searching for invalid target "
                           "(Xbus): uid=0x%X, ec=0x%.2X",
                           TARGETING::get_huid(theTarget),
                           theTarget->getAttr<TARGETING::ATTR_EC>() );

                TS_FAIL("testFindSbeInPnor() - Fail expected when searching for invalid EC level!");
                errlCommit( err,
                            SBE_COMP_ID );
            }

            TRACFCOMP( g_trac_sbe,
                       EXIT_MRK"testFindSbeInPnor - %d/%d fails",
                       fails, total );

        }while(0);

    }


    /**
     * @brief This function will run through the functions used to collect
     *        SBE information on a single target, determine if that target
     *        needs to be updated, and perform the update.
     */
    void testSbeUpdateTarget ( void )
    {

        errlHndl_t err = NULL;
        errlHndl_t err_cleanup = NULL;

        uint64_t fails = 0x0;
        uint64_t total = 0x0;
        sbeTargetState_t sbeState;

        do{

            /****************************************************/
            /* Get Functional Target and Create VMM Space       */
            /****************************************************/
            TARGETING::Target * theTarget =
                                getFunctionalTarget(TARGETING::TYPE_PROC);
            if(theTarget == NULL)
            {
                total++;
                fails++;
                TS_FAIL("testSbeUpdateTarget() - No Functional Targets found!");
                break;
            }

            TRACFCOMP( g_trac_sbe,
                       ENTER_MRK"testSbeUpdateTarget()" );

            uint8_t local_ec = theTarget->getAttr<TARGETING::ATTR_EC>();

            err = createSbeImageVmmSpace();
            if(err)
            {
                total++;
                fails++;
                TS_FAIL("testSbeUpdateTarget() - Call to createSbeImageVmmSpace() failed");
                break;
            }


            /****************************************************/
            /* Get SBE Info State                               */
            /****************************************************/
            // Clear struct
            memset(&sbeState, 0, sizeof(sbeState));

            // Must set struct's target field
            sbeState.target = theTarget;

            // set bad ec just for comparison to local_ec later
            sbeState.ec = 0xFF;


            total++;
            err = getSbeInfoState(sbeState);
            if(err)
            {
                fails++;
                TS_FAIL("testSbeUpdateTarget() - call getSbeInfoState() failed.");
                break;
            }


            /****************************************************/
            /* Compare/Display SBE Version Information          */
            /****************************************************/

            // Quick EC check
            if (local_ec != sbeState.ec)
            {
                fails++;
                TS_FAIL("testSbeUpdateTarget() - Bad ec check: local=0x%X, other=0x%X", local_ec, sbeState);
                break;
            }

            // Display sbeState
            TRACUCOMP( g_trac_sbe,
                       "testSbeUpdateTarget() Info For Target 0x%X ec=0x%X "
                       "cur=0x%X alt=0x%X, ECC_fail 0/1=%d/%d, isMaster=%d "
                       "Custom Image Size=0x%X, CRC=0x%X",
                       TARGETING::get_huid(sbeState.target), sbeState.ec,
                       sbeState.cur_seeprom_side, sbeState.alt_seeprom_side,
                       sbeState.seeprom_0_ver_ECC_fail,
                       sbeState.seeprom_1_ver_ECC_fail,
                       sbeState.target_is_master,
                       sbeState.customizedImage_size,
                       sbeState.customizedImage_crc);

            TRACDBIN( g_trac_sbe, "testSbeUpdateTarget()-pnorVersion",
                      &sbeState.pnorVersion, sizeof(sbe_image_version_t));
            TRACDBIN( g_trac_sbe, "testSbeUpdateTarget()-mvpdSbKeyword",
                      &sbeState.mvpdSbKeyword, sizeof(mvpdSbeVersion_t));
            TRACDBIN( g_trac_sbe, "testSbeUpdateTarget()-seeprom_0_ver",
                      &sbeState.seeprom_0_ver,
                      sizeof(sbeSeepromVersionInfo_t));
            TRACDBIN( g_trac_sbe, "testSbeUpdateTarget()-seeprom_1_ver",
                      &sbeState.seeprom_1_ver,
                      sizeof(sbeSeepromVersionInfo_t));



            /****************************************************/
            /* Get Target Update Actions                        */
            /****************************************************/

            total++;
            err = getTargetUpdateActions(sbeState);
            if(err)
            {
                fails++;
                TS_FAIL("testSbeUpdateTarget() - getTargetUpdateActions() failed");
                break;
            }


            /****************************************************/
            /* Update SBE Backup                                */
            /****************************************************/
            // force backup to SEEPROM 1 just in case
            if ( !(sbeState.update_actions & DO_UPDATE ) )
            {
                sbeState.update_actions =
                    static_cast<sbeUpdateActions_t>
                         (DO_UPDATE|UPDATE_MVPD|UPDATE_SBE),

                sbeState.seeprom_side_to_update = EEPROM::SBE_BACKUP;

                sbeState.new_readBack_check = true;
            }
            total++;

            err = performUpdateActions(sbeState);
            if(err)
            {
                fails++;
                TS_FAIL("testSbeUpdateTarget() - performUpdateActions() failed.");
                break;
            }

            // Make sure MVPD and SBE were updated
            if ( ! ( ( sbeState.update_actions & MVPD_UPDATE_COMPLETE ) &&
                     ( sbeState.update_actions & SBE_UPDATE_COMPLETE  ) ) )
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"testSbeUpdateTarget(): "
                           "'COMPLETE' actions were not found: 0x%.8X",
                           sbeState.update_actions);
                fails++;
                TS_FAIL("testSbeUpdateTarget() - performUpdateActions() did not complete actions");
                break;
            }


        }while(0);

        err_cleanup = cleanupSbeImageVmmSpace();
        if(err_cleanup)
        {
            total++;
            fails++;
            TS_FAIL("testSbeUpdateTarget() -Call to cleanupSbeImageVmmSpace() failed.");
            errlCommit( err_cleanup, SBE_COMP_ID );

        }

        TRACFCOMP( g_trac_sbe,
                   EXIT_MRK"testSbeUpdateTarget() - %d/%d fails",
                   fails, total );
    }



    /**
     * @brief This function will call decisionTreeForUpdates() and make
              sure the correct update action is returned for a specific
              situation.
     */
    void testSbeDecisionTree ( void )
    {

        uint64_t fails = 0x0;
        uint64_t total = 0x0;

        sbeTargetState_t sbeState;

        struct
        {
            // Inputs
            uint8_t                      i_situation;
            sbeSeepromSide_t             i_cur;     // current_seeprom_side
            uint8_t                      i_flags;   // mvpdSbKeyword.flags

            // Expected Output
            sbeUpdateActions_t            o_update_actions;
            EEPROM::eeprom_chip_types_t   o_seeprom;
            uint8_t                       o_flags;   // mvpdSbKeyword.flags

        }  testData[] =
        {

            // case 0xE0: cur=temp, cur=dirty, alt=dirty
            // Arbitrarily set cur side to 0 (therefore perm set to 1)
            // - update alt=1
            // - make cur=perm
            // - re-IPL
            { 0xE0, SBE_SEEPROM0, 0x80,
              static_cast<sbeUpdateActions_t>
                     (DO_UPDATE|IPL_RESTART|UPDATE_MVPD|UPDATE_SBE),
              EEPROM::SBE_BACKUP, 0x40 },


            // case 0xC0: cur=temp, cur=dirty, alt=dirty
            // Arbitrarily set cur side to 1 (therefore perm set to 0)
            // - update alt=0
            // - make cur=perm
            // - re-IPL
            { 0xC0, SBE_SEEPROM1, 0x00,
              static_cast<sbeUpdateActions_t>
                     (DO_UPDATE|IPL_RESTART|UPDATE_MVPD|UPDATE_SBE),
              EEPROM::SBE_PRIMARY, 0x80 },

            // case 0xA0: cur=temp, cur=clean, alt=dirty
            // Arbitarily Set cur side to 1 (therefore perm set to 0)
            // - update alt=0
            // - make cur=perm
            // - Continue IPL
            { 0xA0, SBE_SEEPROM1, 0x00,
              static_cast<sbeUpdateActions_t>
                     (DO_UPDATE|UPDATE_MVPD|UPDATE_SBE),
              EEPROM::SBE_PRIMARY, 0x80 },

            // case 0x80: cur=temp, cur=clean, alt=clean
            // Arbitrarily set cur side to 1 (therefore perm set to 0)
            // - No updates
            // - Continue IPL
            { 0x80, SBE_SEEPROM1, 0x00,
              static_cast<sbeUpdateActions_t>(CLEAR_ACTIONS),
              EEPROM::LAST_CHIP_TYPE, 0x00 },

            // case 0x60: cur=perm, cur=dirty, alt=dirty
            // Arbitrarily set cur side to 0 (therefore perm set to 0)
            // - update alt=1
            // - re-IPL
            { 0x60, SBE_SEEPROM0, 0x00,
              static_cast<sbeUpdateActions_t>
                     (DO_UPDATE|IPL_RESTART|UPDATE_MVPD|UPDATE_SBE),
              EEPROM::SBE_BACKUP, 0x40 },

            // case 0x40: cur=perm, cur=dirty, alt=clean
            // This case asks FSP if we just re-IPLed, but assume we don't
            // get mbox msg back in sim so update and re-IPL on alt
            // Arbitrarily set cur side to 1 (therefore perm set to 1)
            // - update alt=0
            // - re-IPL
            { 0x40, SBE_SEEPROM1, 0x80,
              static_cast<sbeUpdateActions_t>
                     (DO_UPDATE|IPL_RESTART|UPDATE_MVPD|UPDATE_SBE),
              EEPROM::SBE_PRIMARY, 0x80 },

            // Repeat previous case to make sure global variables are used
            // correctly to save MBOX value
            { 0x40, SBE_SEEPROM1, 0x80,
              static_cast<sbeUpdateActions_t>
                     (DO_UPDATE|IPL_RESTART|UPDATE_MVPD|UPDATE_SBE),
              EEPROM::SBE_PRIMARY, 0x80 },

            // case 0x20: cur=perm, cur=clean, alt=dirty
            // Arbitrarily set cur side to 0 (therefore perm set to 0)
            // - update alt=1
            // - Continue IPL
            { 0x20, SBE_SEEPROM0, 0x00,
              static_cast<sbeUpdateActions_t>(DO_UPDATE|UPDATE_SBE),
              EEPROM::SBE_BACKUP, 0x00 },

            // case 0x00: cur=perm, cur=clean, alt=clean
            // Arbitrarily set cur side to 0 (therefore perm set to 0)
            // - No Updates
            // - Continue IPL
            // NOTE: this will test that right-most-bit is ignored:
            //  so techincally case 0x01, which should be = case 0x00
            { 0x01, SBE_SEEPROM0, 0x00,
              static_cast<sbeUpdateActions_t>(CLEAR_ACTIONS),
              EEPROM::LAST_CHIP_TYPE, 0x00 },

        };

        const uint32_t NUM_CMDS = sizeof(testData)/sizeof(testData[0]);


        do{

            TRACFCOMP( g_trac_sbe,
                       ENTER_MRK"testSbeDecisionTree()" );

            // Get and Set a target for sbeState
            TARGETING::Target * theTarget =
                                getFunctionalTarget(TARGETING::TYPE_PROC);
            if(theTarget == NULL)
            {
                total++;
                fails++;
                TS_FAIL("testSbeUpdateTarget() - No Functional Targets found!");
                break;
            }
            sbeState.target = theTarget;

            // Loop through each situation
            for( uint32_t i = 0; i < NUM_CMDS; i++ )
            {

                sbeState.update_actions   = CLEAR_ACTIONS;

                /****************************************************/
                /* Set Input Values                                 */
                /****************************************************/
                sbeState.cur_seeprom_side = testData[i].i_cur;

                sbeState.alt_seeprom_side =
                             ( ( testData[i].i_cur == SBE_SEEPROM0 )
                               ? SBE_SEEPROM1 : SBE_SEEPROM0 );

                sbeState.mvpdSbKeyword.flags = testData[i].i_flags;


                /****************************************************/
                /* Get Target Update Actions                        */
                /****************************************************/

                total++;
                SBE::decisionTreeForUpdates(sbeState,
                                            testData[i].i_situation);


                /****************************************************/
                /* Check Output Values                              */
                /****************************************************/
                if (( testData[i].o_update_actions != sbeState.update_actions )
                     ||
                    ( testData[i].o_seeprom != sbeState.seeprom_side_to_update )
                     ||
                    ( testData[i].o_flags != sbeState.mvpdSbKeyword.flags )
                   )
                {
                    fails++;

                    TRACFCOMP( g_trac_sbe, ERR_MRK"testSbeDecisionTree() - "
                    "Fail! Unexpected results for situation=0x%.2X (i=%d): "
                    "Inputs: cur=%d, flags=0x%.2X",
                    testData[i].i_situation, i,
                    testData[i].i_cur, testData[i].i_flags);

                    TRACFCOMP( g_trac_sbe, ERR_MRK"testSbeDecisionTree() - "
                    "Expected/Returned: update_actions=0x%.4X/0x%.4X, "
                    "update seeprom=%d/%d, flags=0x%.2X/0x%.2X",
                    testData[i].o_update_actions, sbeState.update_actions,
                    testData[i].o_seeprom, sbeState.seeprom_side_to_update,
                    testData[i].o_flags, sbeState.mvpdSbKeyword.flags);

                    TS_FAIL("testSbeDecisionTree() - Fail! Unexpected results for pass %d, situation=0x%.2X", i, testData[i].i_situation);

                    // Don't break - complete the remaining tests
                }

           } // end of for-loop

        }while(0);

        TRACFCOMP( g_trac_sbe, EXIT_MRK
                   EXIT_MRK"testSbeDecisionTree() - %d/%d fails",
                   fails, total );
    }

    /**
     * @brief This function will call preReIplCheck() and make sure that
              all the targets are ready for the Re-Ipl Request
     */
    void testSbePreReIplCheck ( void )
    {


        TRACFCOMP( g_trac_sbe,
                   ENTER_MRK"testSbePreReIplCheck");

        uint64_t fails = 0x0;
        uint64_t total = 0x0;
        errlHndl_t err = NULL;

        std::vector<sbeTargetState_t> sbeStates_vector;
        sbeTargetState_t sbeState;

        struct
        {
            // Inputs
            sbeUpdateActions_t      i_update_actions;
            uint8_t                 i_flags;   // mvpdSbKeyword.flags

            // Expected Output
            sbeUpdateActions_t      o_update_actions;
            uint8_t                 o_flags;   // mvpdSbKeyword.flags

        }  testData[] =
        {

            // Update already done -- Flags match
            { static_cast<sbeUpdateActions_t>(MVPD_UPDATE_COMPLETE), 0x00,
              static_cast<sbeUpdateActions_t>(MVPD_UPDATE_COMPLETE), 0x00},

            // Update already done -- Flags don't match A
            { static_cast<sbeUpdateActions_t>(MVPD_UPDATE_COMPLETE), 0x80,
              static_cast<sbeUpdateActions_t>(MVPD_UPDATE_COMPLETE), 0x80},

            // Update already done -- Flags don't match B
            { static_cast<sbeUpdateActions_t>(MVPD_UPDATE_COMPLETE), 0x40,
              static_cast<sbeUpdateActions_t>(MVPD_UPDATE_COMPLETE), 0x40},

            // Update Not Done -- Flags match 0
            { static_cast<sbeUpdateActions_t>(CLEAR_ACTIONS), 0x00,
              static_cast<sbeUpdateActions_t>(CLEAR_ACTIONS), 0x00},

            // Update Not Done -- Flags match 1
            // AND testing that other actions aren't being lost
            { static_cast<sbeUpdateActions_t>(DO_UPDATE), 0xC0,
              static_cast<sbeUpdateActions_t>(DO_UPDATE), 0xC0},

            // Update Note Done -- Flags don't match A
            { static_cast<sbeUpdateActions_t>(CLEAR_ACTIONS), 0x80,
              static_cast<sbeUpdateActions_t>(MVPD_UPDATE_COMPLETE), 0xC0},

            // Update Note Done -- Flags don't match B
            { static_cast<sbeUpdateActions_t>(CLEAR_ACTIONS), 0x40,
              static_cast<sbeUpdateActions_t>(MVPD_UPDATE_COMPLETE), 0x00},



        };

        const uint32_t NUM_CMDS = sizeof(testData)/sizeof(testData[0]);

        do{


            /****************************************************/
            /* Get Functional Target and Create VMM Space       */
            /****************************************************/
            TARGETING::Target * theTarget =
                                getFunctionalTarget(TARGETING::TYPE_PROC);
            if(theTarget == NULL)
            {
                total++;
                fails++;
                TS_FAIL("testSbePreReIplCheck() - No Functional Targets found!");
                break;
            }

            /****************************************************/
            /* Create vector of sbeStates for testing           */
            /****************************************************/
            for (uint8_t i = 0; i < NUM_CMDS ; i++)
            {
                // Setup Test Data
                sbeState.mvpdSbKeyword.flags = testData[i].i_flags;
                sbeState.update_actions = testData[i].i_update_actions;

                // Put the same target into each sbeState
                sbeState.target = theTarget;

                // Push this sbeState onto the vector
                sbeStates_vector.push_back(sbeState);
            }


            /****************************************************/
            /* Call preReIplCheck()                             */
            /****************************************************/
            total++;
            err = preReIplCheck(sbeStates_vector);
            if(err)
            {
                fails++;
                TS_FAIL("testSbePreReIplCheck() - preReIplCheck() failed");
                break;
            }

            /****************************************************/
            /* Check Ouput Values                               */
            /****************************************************/
            for (uint8_t i = 0; i < NUM_CMDS ; i++)
            {
                if (( testData[i].o_update_actions !=
                                  sbeStates_vector[i].update_actions )
                     ||
                    ( testData[i].o_flags !=
                                  sbeStates_vector[i].mvpdSbKeyword.flags )
                   )
                {
                    fails++;

                    TRACFCOMP( g_trac_sbe, ERR_MRK"testSbePreReIplCheck() - "
                    "Fail! Unexpected results (i=%d): Input/Expected/Returned "
                    "flags=0x%.2X/0x%.2X/0x%.2X, update_actions=0x%.4X/0x%.4x"
                    "/0x%.4X", i, testData[i].i_flags, testData[i].o_flags,
                    sbeStates_vector[i].mvpdSbKeyword.flags,
                    testData[i].i_update_actions,
                    testData[i].o_update_actions,
                    sbeStates_vector[i].update_actions);

                    TS_FAIL("testSbePreReIplCheck() - Fail! Unexpected results for pass %d", i);

                    // Don't break - complete the remaining tests
                }
            }

        }while(0);

        TRACFCOMP( g_trac_sbe, EXIT_MRK
                   EXIT_MRK"testSbePreReIplCheck() - %d/%d fails",
                   fails, total );
    }




    /**
     * @brief Constructor
     */
    SBEUpdateTest() : CxxTest::TestSuite()
    {
        errlHndl_t err = NULL;
        uint64_t fails = 0x0;
        uint64_t total = 0x0;
        bool sbe_loaded = false;

        err = loadSbeModule(sbe_loaded);
        if(err)
        {
            total++;
            fails++;
            TS_FAIL("SBEUpdateTest() - Constuctor: failed to load modules");
            errlCommit( err, SBE_COMP_ID );
        }

    };


    /**
     * @brief Destructor
     */
    ~SBEUpdateTest()
    {
        errlHndl_t err = NULL;
        uint64_t fails = 0x0;
        uint64_t total = 0x0;

        err = unloadSbeModule();
        if(err)
        {
            total++;
            fails++;
            TS_FAIL("~SBEUpdateTest() - Destuctor: failed to load modules");
            errlCommit( err, SBE_COMP_ID );
        }

    };

};

#endif
OpenPOWER on IntegriCloud