summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/test/fapiRcTest.C
blob: c9c1281d5d973b90a17f681292298fc2e1e2aa08 (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
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
//  IBM_PROLOG_BEGIN_TAG
//  This is an automatically generated prolog.
//
//  $Source: src/usr/hwpf/test/fapiRcTest.C $
//
//  IBM CONFIDENTIAL
//
//  COPYRIGHT International Business Machines Corp. 2011
//
//  p1
//
//  Object Code Only (OCO) source materials
//  Licensed Internal Code Source Materials
//  IBM HostBoot Licensed Internal Code
//
//  The source code for this program is not published or other-
//  wise divested of its trade secrets, irrespective of what has
//  been deposited with the U.S. Copyright Office.
//
//  Origin: 30
//
//  IBM_PROLOG_END
/**
 *  @file fapiTargetTest.C
 *
 *  @brief Implements Target class unit test functions.
 */

/*
 * Change Log ******************************************************************
 * Flag     Defect/Feature  User        Date        Description
 * ------   --------------  ----------  ----------- ----------------------------
 *                          mjjones     04/13/2011  Created.
 *                          mjjones     07/26/2011  Added more tests
 *                          mjjones     09/23/2011  Updated test for ErrorInfo
 *                          mjjones     01/13/2012  Use new ReturnCode interfaces
 */

#include <fapi.H>

namespace fapi
{

//******************************************************************************
// rcTest1. Ensures that the ReturnCode default constructor works
//******************************************************************************
uint32_t rcTest1()
{
    uint32_t l_result = 0;

    // Create ReturnCode using default constructor
    ReturnCode l_rc;

    // Ensure that the embedded return code is success
    if (l_rc != FAPI_RC_SUCCESS)
    {
        FAPI_ERR("rcTest1. Code is 0x%x, expected success",
                 static_cast<uint32_t>(l_rc));
        l_result = 1;
    }
    else
    {
        // Ensure that ok function works
        if (l_rc.ok() == false)
        {
            FAPI_ERR("rcTest1. ok returned false");
            l_result = 2;
        }
        else
        {
            // Ensure that testing l_rc works
            if (l_rc)
            {
                FAPI_ERR("rcTest1. testing rc returned true");
                l_result = 3;
            }
            else
            {
                FAPI_INF("rcTest1. Success!");
            }
        }
    }

    return l_result;
}

//******************************************************************************
// rcTest2. Ensures that the ReturnCode creator reflects the return code
//******************************************************************************
uint32_t rcTest2()
{
    uint32_t l_result = 0;

    // Create ReturnCode using default constructor
    ReturnCode l_rc;

    // Set the return code to a FAPI code
    l_rc.setFapiError(FAPI_RC_INVALID_ATTR_GET);

    // Ensure that the creator is FAPI
    ReturnCode::returnCodeCreator l_creator = l_rc.getCreator();

    if (l_creator != ReturnCode::CREATOR_FAPI)
    {
        FAPI_ERR("rcTest2. Creator is 0x%x, expected FAPI", l_creator);
        l_result = 1;
    }
    else
    {
        // Set the return code to a PLAT code
        l_rc.setPlatError(NULL);

        // Ensure that the creator is PLAT
        l_creator = l_rc.getCreator();

        if (l_creator != ReturnCode::CREATOR_PLAT)
        {
            FAPI_ERR("rcTest2. Creator is 0x%x, expected PLAT", l_creator);
            l_result = 2;
        }
        else
        {
            // Set the return code to a HWP code (intentionally use function
            // that does not add error information).
            l_rc._setHwpError(RC_TEST_ERROR_A);

            // Ensure that the creator is HWP
            l_creator = l_rc.getCreator();

            if (l_creator != ReturnCode::CREATOR_HWP)
            {
                FAPI_ERR("rcTest2. Creator is 0x%x, expected HWP", l_creator);
                l_result = 3;
            }
            else
            {
                FAPI_INF("rcTest2. Success!");
            }
        }
    }

    return l_result;
}

//******************************************************************************
// rcTest3. Ensures that the ReturnCode constructor works when specifying a
//          return code
//******************************************************************************
uint32_t rcTest3()
{
    uint32_t l_result = 0;

    // Create ReturnCode specifying a return code
    ReturnCode l_rc(FAPI_RC_INVALID_ATTR_GET);

    // Ensure that the embedded return code is as expected
    uint32_t l_codeCheck = l_rc;

    if (l_codeCheck != FAPI_RC_INVALID_ATTR_GET)
    {
        FAPI_ERR("rcTest3. Code is 0x%x, expected FAPI_RC_INVALID_ATTR_GET",
                 l_codeCheck);
        l_result = 1;
    }
    else
    {
        // Ensure that ok function returns false
        if (l_rc.ok())
        {
            FAPI_ERR("rcTest3. ok returned true");
            l_result = 2;
        }
        else
        {
            // Ensure that testing l_rc works
            if (!l_rc)
            {
                FAPI_ERR("rcTest3. testing rc returned false");
                l_result = 3;
            }
            else
            {
                FAPI_INF("rcTest3. Success!");
            }
        }
    }

    return l_result;
}

//******************************************************************************
// rcTest4. Ensures that the comparison operators work (comparing with another
//          ReturnCode)
//******************************************************************************
uint32_t rcTest4()
{
    uint32_t l_result = 0;

    // Create similar ReturnCodes
    ReturnCode l_rc(FAPI_RC_INVALID_ATTR_GET);
    ReturnCode l_rc2(FAPI_RC_INVALID_ATTR_GET);

    // Ensure that the equality comparison returns true
    if (!(l_rc == l_rc2))
    {
        FAPI_ERR("rcTest4. 1. Equality comparison false");
        l_result = 1;
    }
    else
    {
        // Ensure that the inequality comparison returns false
        if (l_rc != l_rc2)
        {
            FAPI_ERR("rcTest4. 2. Inequality comparison true");
            l_result = 2;
        }
        else
        {
            // Change the code of l_rc2
            l_rc2.setFapiError(FAPI_RC_PLAT_ERR_SEE_DATA);

            // Ensure that the equality comparison returns false
            if (l_rc == l_rc2)
            {
                FAPI_ERR("rcTest4. 3. Equality comparison true");
                l_result = 3;
            }
            else
            {
                // Ensure that the inequality comparison returns true
                if (!(l_rc != l_rc2))
                {
                    FAPI_ERR("rcTest4. 4. Inequality comparison false");
                    l_result = 4;
                }
                else
                {
                    FAPI_INF("rcTest4. Success!");
                }
            }
        }
    }

    return l_result;
}

//******************************************************************************
// rcTest5. Ensures that the comparison operators work (comparing with a return
//          code value)
//******************************************************************************
uint32_t rcTest5()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    ReturnCode l_rc(FAPI_RC_INVALID_ATTR_GET);

    // Ensure that the equality comparison returns true when comparing to the
    // same return code value
    if (!(l_rc == FAPI_RC_INVALID_ATTR_GET))
    {
        FAPI_ERR("rcTest5. 1. Equality comparison false");
        l_result = 1;
    }
    else
    {
        // Ensure that the inequality comparison returns false when comparing to
        // the same return code value
        if (l_rc != FAPI_RC_INVALID_ATTR_GET)
        {
            FAPI_ERR("rcTest5. 2. Inequality comparison true");
            l_result = 2;
        }
        else
        {
            // Ensure that the equality comparison returns false when comparing
            // to a different return code value
            if (l_rc == FAPI_RC_PLAT_ERR_SEE_DATA)
            {
                FAPI_ERR("rcTest5. 3. Equality comparison true");
                l_result = 3;
            }
            else
            {
                // Ensure that the inequality comparison returns true when
                // comparing to a different return code value
                if (!(l_rc != FAPI_RC_PLAT_ERR_SEE_DATA))
                {
                    FAPI_ERR("rcTest5. 4. Inequality comparison false");
                    l_result = 4;
                }
                else
                {
                    FAPI_INF("rcTest5. Success!");
                }
            }
        }
    }

    return l_result;
}

//******************************************************************************
// rcTest6. Ensures that the getPlatData and releasePlatData functions work when
//          there is no attached data
//******************************************************************************
uint32_t rcTest6()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    ReturnCode l_rc(FAPI_RC_INVALID_ATTR_GET);

    // Ensure that the getPlatData function returns NULL
    void * l_pData = reinterpret_cast<void *> (0x12345678);

    l_pData = l_rc.getPlatData();

    if (l_pData != NULL)
    {
        FAPI_ERR("rcTest6. getPlatData did not return NULL");
        l_result = 1;
    }
    else
    {
        // Ensure that the releasePlatData function returns NULL
        l_pData = reinterpret_cast<void *> (0x12345678);

        l_pData = l_rc.releasePlatData();

        if (l_pData != NULL)
        {
            FAPI_ERR("rcTest6. releasePlatData did not return NULL");
            l_result = 2;
        }
        else
        {
            FAPI_INF("rcTest6. Success!");
        }
    }

    return l_result;
}

//******************************************************************************
// rcTest7. Ensures that the getPlatData function works when there is attached
//          data
//******************************************************************************
uint32_t rcTest7()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    ReturnCode l_rc;

    // Assign PlatData. Note that this should really be an errlHndl_t, because
    // the FSP deleteData function will attempt to delete an error log, but this
    // is just for test, the data will be released before the ReturnCode is
    // destructed.
    uint32_t l_myData = 6;
    void * l_pMyData = reinterpret_cast<void *> (&l_myData);
    (void) l_rc.setPlatError(l_pMyData);

    // Ensure that getPlatData retrieves the PlatData
    void * l_pMyDataCheck = l_rc.getPlatData();

    if (l_pMyDataCheck != l_pMyData)
    {
        FAPI_ERR("rcTest7. 1. getPlatData returned unexpected data ptr");
        l_result = 1;
    }
    else
    {
        // Ensure that getPlatData retrieves the PlatData again
        l_pMyDataCheck = NULL;
        l_pMyDataCheck = l_rc.getPlatData();

        if (l_pMyDataCheck != l_pMyData)
        {
            FAPI_ERR("rcTest7. 2. getPlatData returned unexpected data ptr");
            l_result = 2;
        }
        else
        {
            FAPI_INF("rcTest7. Success!");
        }
    }

    // Release the data to avoid ReturnCode from deleting in on destruction
    l_pMyDataCheck = l_rc.releasePlatData();

    return l_result;
}

//******************************************************************************
// rcTest8. Ensures that the releasePlatData function works when there is
//          attached data
//******************************************************************************
uint32_t rcTest8()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    ReturnCode l_rc;

    // Assign PlatData. Note that this should really be an errlHndl_t, because
    // the FSP deleteData function will attempt to delete an error log, but this
    // is just for test, the data will be released before the ReturnCode is
    // destructed.
    uint32_t l_myData = 6;
    void * l_pMyData = reinterpret_cast<void *> (&l_myData);
    (void) l_rc.setPlatError(l_pMyData);

    // Ensure that releasePlatData retrieves the PlatData
    void * l_pMyDataCheck = l_rc.releasePlatData();

    if (l_pMyDataCheck != l_pMyData)
    {
        FAPI_ERR("rcTest8. getPlatData returned unexpected data ptr");
        l_result = 1;
    }
    else
    {
        // Ensure that releasePlatData now returns NULL
        l_pMyDataCheck = NULL;
        l_pMyDataCheck = l_rc.releasePlatData();

        if (l_pMyDataCheck != NULL)
        {
            FAPI_ERR("rcTest8. 2. getPlatData returned non NULL ptr");
            l_result = 2;
        }
        else
        {
            FAPI_INF("rcTest8. Success!");
        }
    }

    return l_result;
}

//******************************************************************************
// rcTest9. Ensures that the copy constructor works when there is attached
//          PlatData and that the getPlatData function works
//******************************************************************************
uint32_t rcTest9()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    ReturnCode l_rc;

    // Assign PlatData. Note that this should really be an errlHndl_t, because
    // the FSP deleteData function will attempt to delete an error log, but this
    // is just for test, the data will be released before the ReturnCode is
    // destructed.
    uint32_t l_myData = 6;
    void * l_pMyData = reinterpret_cast<void *> (&l_myData);
    (void) l_rc.setPlatError(l_pMyData);

    // Create a ReturnCode using the copy constructor
    ReturnCode l_rc2(l_rc);

    // Ensure that the two ReturnCodes are the same
    if (l_rc != l_rc2)
    {
        FAPI_ERR("rcTest9. ReturnCodes differ");
        l_result = 1;
    }
    else
    {
        // Ensure that getPlatData retrieves the PlatData from l_rc
        void * l_pMyDataCheck = l_rc.getPlatData();

        if (l_pMyDataCheck != l_pMyData)
        {
            FAPI_ERR("rcTest9. 1. getPlatData returned unexpected data ptr");
            l_result = 2;
        }
        else
        {
            // Ensure that getPlatData retrieves the PlatData from l_rc2
            l_pMyDataCheck = NULL;
            l_pMyDataCheck = l_rc2.getPlatData();

            if (l_pMyDataCheck != l_pMyData)
            {
                FAPI_ERR("rcTest9. 2. getPlatData returned unexpected data ptr");
                l_result = 3;
            }
            else
            {
                FAPI_INF("rcTest9. Success!");
            }
        }
    }

    // Release the data to avoid ReturnCode from deleting in on destruction.
    // This will release the data from both copies of the ReturnCode.
    (void) l_rc.releasePlatData();

    return l_result;
}

//******************************************************************************
// rcTest10. Ensures that the assignment operator works when there is attached
//           PlatData and that the releasePlatData function works
//******************************************************************************
uint32_t rcTest10()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    ReturnCode l_rc;

    // Assign PlatData. Note that this should really be an errlHndl_t, because
    // the PLAT deleteData function will attempt to delete an error log, but
    // this is just for test, the data will be released before the ReturnCode is
    // destructed.
    uint32_t l_myData = 6;
    void * l_pMyData = reinterpret_cast<void *> (&l_myData);
    (void) l_rc.setPlatError(l_pMyData);

    // Create a ReturnCode using the assignment operator
    ReturnCode l_rc2;
    l_rc2 = l_rc;

    // Ensure that the two ReturnCodes are the same
    if (l_rc != l_rc2)
    {
        FAPI_ERR("rcTest10. ReturnCodes differ");
        l_result = 1;
    }
    else
    {
        // Ensure that releasePlatData retrieves the PlatData from l_rc
        void * l_pMyDataCheck = l_rc.releasePlatData();

        if (l_pMyDataCheck != l_pMyData)
        {
            FAPI_ERR("rcTest10. releasePlatData returned unexpected data ptr");
            l_result = 2;
        }
        else
        {
            // Ensure that releasePlatData retrieves NULL from l_rc2
            l_pMyDataCheck = NULL;
            l_pMyDataCheck = l_rc2.releasePlatData();

            if (l_pMyDataCheck != NULL)
            {
                FAPI_ERR("rcTest10. releasePlatData returned non NULL ptr");
                l_result = 3;
            }
            else
            {
                FAPI_INF("rcTest10. Success!");
            }
        }
    }

    return l_result;
}

//******************************************************************************
// rcTest11. Ensures that the getErrorInfo function works when there is no
//           ErrorInfo
//******************************************************************************
uint32_t rcTest11()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    ReturnCode l_rc;

    // Ensure that the getErrorInfo function returns NULL
    const ErrorInfo * l_pErrInfo =
        reinterpret_cast<const ErrorInfo *> (0x12345678);

    l_pErrInfo = l_rc.getErrorInfo();

    if (l_pErrInfo != NULL)
    {
        FAPI_ERR("rcTest11. getErrorInfo did not return NULL");
        l_result = 1;
    }
    else
    {
        FAPI_INF("rcTest11. Success!");
    }

    return l_result;
}

//******************************************************************************
// rcTest12. Ensures that the getErrorInfo function works when there is
//           ErrorInfo
//******************************************************************************
uint32_t rcTest12()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    ReturnCode l_rc;
    l_rc.setFapiError(FAPI_RC_INVALID_ATTR_GET);

    // Create a DIMM target
    uint32_t l_targetHandle = 3;
    Target l_target(TARGET_TYPE_DIMM, &l_targetHandle);
    
    // Create some FFDC
    uint8_t l_ffdc = 0x12;

    // Add error information to the ReturnCode
    const void * l_objects[] = {&l_ffdc, &l_target};
    fapi::ReturnCode::ErrorInfoEntry l_entries[] =
        {{fapi::ReturnCode::EI_TYPE_FFDC, 0,
          fapi::ReturnCodeFfdc::getErrorInfoFfdcSize(l_ffdc)},
         {fapi::ReturnCode::EI_TYPE_CALLOUT, 1, fapi::PRI_MEDIUM},
         {fapi::ReturnCode::EI_TYPE_DECONF, 1},
         {fapi::ReturnCode::EI_TYPE_GARD, 1}};
    l_rc.addErrorInfo(l_objects, l_entries, 4);

    do
    {
        // Check that the Error Info can be retrieved
        const ErrorInfo * l_pErrInfo = NULL;
        l_pErrInfo = l_rc.getErrorInfo();

        if (l_pErrInfo == NULL)
        {
            FAPI_ERR("rcTest12. getErrorInfo returned NULL");
            l_result = 1;
            break;
        }

        // Check the FFDC error information
        if (l_pErrInfo->iv_ffdcs.size() != 1)
        {
            FAPI_ERR("rcTest12. %d FFDCs", l_pErrInfo->iv_ffdcs.size());
            l_result = 2;
            break;
        }

        uint32_t l_size = 0;
        const void * l_pFfdc = NULL;

        l_pFfdc = l_pErrInfo->iv_ffdcs[0]->getData(l_size);

        if (l_size != sizeof(l_ffdc))
        {
            FAPI_ERR("rcTest12. FFDC size is %d", l_size);
            l_result = 3;
            break;
        }

        const uint8_t * l_pFfdcCheck = static_cast<const uint8_t *>(l_pFfdc);
        if (*l_pFfdcCheck != 0x12)
        {
            FAPI_ERR("rcTest12. FFDC is 0x%x", *l_pFfdcCheck);
            l_result = 4;
            break;
        }

        // Check the callout error information
        if (l_pErrInfo->iv_callouts.size() != 1)
        {
            FAPI_ERR("rcTest12. %d callouts", l_pErrInfo->iv_ffdcs.size());
            l_result = 5;
            break;
        }

        if (l_pErrInfo->iv_callouts[0]->iv_target != l_target)
        {
            FAPI_ERR("rcTest12. callout target mismatch");
            l_result = 6;
            break;
        }

        if (l_pErrInfo->iv_callouts[0]->iv_priority != PRI_MEDIUM)
        {
            FAPI_ERR("rcTest12. callout priority mismatch");
            l_result = 7;
            break;
        }

        // Check the deconfig error information
        if (l_pErrInfo->iv_deconfigs.size() != 1)
        {
            FAPI_ERR("rcTest12. %d deconfigs", l_pErrInfo->iv_deconfigs.size());
            l_result = 8;
            break;
        }

        if (l_pErrInfo->iv_deconfigs[0]->iv_target != l_target)
        {
            FAPI_ERR("rcTest12. deconfig target mismatch");
            l_result = 9;
            break;
        }

        // Check the GARD error information
        if (l_pErrInfo->iv_gards.size() != 1)
        {
            FAPI_ERR("rcTest12. %d gards", l_pErrInfo->iv_gards.size());
            l_result = 10;
            break;
        }

        if (l_pErrInfo->iv_gards[0]->iv_target != l_target)
        {
            FAPI_ERR("rcTest12. gard target mismatch");
            l_result = 11;
            break;
        }

        FAPI_INF("rcTest12. Success!");
    }
    while(0);

    return l_result;
}

//******************************************************************************
// rcTest13. Ensures that the copy constructor works when there is ErrorInfo
//******************************************************************************
uint32_t rcTest13()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    ReturnCode l_rc;
    l_rc.setFapiError(FAPI_RC_INVALID_ATTR_GET);

    // Create a DIMM target
    uint32_t l_targetHandle = 3;
    Target l_target(TARGET_TYPE_DIMM, &l_targetHandle);

    // Add error information to the ReturnCode
    const void * l_objects[] = {&l_target};
    fapi::ReturnCode::ErrorInfoEntry l_entries[] =
        {{fapi::ReturnCode::EI_TYPE_GARD, 0}};
    l_rc.addErrorInfo(l_objects, l_entries, 1);

    // Create a ReturnCode using the copy constructor
    ReturnCode l_rc2(l_rc);

    do
    {
        // Ensure that the two ReturnCodes are the same
        if (l_rc != l_rc2)
        {
            FAPI_ERR("rcTest13. ReturnCodes differ");
            l_result = 1;
            break;
        }

        // Ensure that getErrorInfo returns correct information from l_rc
        const ErrorInfo * l_pErrInfo = NULL;

        l_pErrInfo = l_rc.getErrorInfo();

        if (l_pErrInfo == NULL)
        {
            FAPI_ERR("rcTest13. getErrorInfo returned NULL");
            l_result = 2;
            break;
        }
       
        if (l_pErrInfo->iv_gards.size() != 1)
        {
            FAPI_ERR("rcTest13. %d gards", l_pErrInfo->iv_gards.size());
            l_result = 3;
            break;
        }

        if (l_pErrInfo->iv_gards[0]->iv_target != l_target)
        {
            FAPI_ERR("rcTest13. gard target mismatch");
            l_result = 4;
            break;
        }

        // Ensure that getErrorInfo from l_rc2 returns the same pointer
        const ErrorInfo * l_pErrInfo2 = l_rc2.getErrorInfo();

        if (l_pErrInfo != l_pErrInfo2)
        {
            FAPI_ERR("rcTest13. error info mismatch");
            l_result = 5;
            break;
        }

        FAPI_INF("rcTest13. Success!");
    }
    while(0);

    return l_result;
}

//******************************************************************************
// rcTest14. Ensures that the assignment operator works when there ErrorInfo
//******************************************************************************
uint32_t rcTest14()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    ReturnCode l_rc;
    l_rc.setFapiError(FAPI_RC_INVALID_ATTR_GET);

    // Create a DIMM target
    uint32_t l_targetHandle = 3;
    Target l_target(TARGET_TYPE_DIMM, &l_targetHandle);

    // Add error information to the ReturnCode
    const void * l_objects[] = {&l_target};
    fapi::ReturnCode::ErrorInfoEntry l_entries[] =
        {{fapi::ReturnCode::EI_TYPE_GARD, 0}};
    l_rc.addErrorInfo(l_objects, l_entries, 1);

    // Create a ReturnCode using the assignment operator
    ReturnCode l_rc2;
    l_rc2 = l_rc;

    do
    {
        // Ensure that the two ReturnCodes are the same
        if (l_rc != l_rc2)
        {
            FAPI_ERR("rcTest14. ReturnCodes differ");
            l_result = 1;
            break;
        }

        // Ensure that getErrorInfo returns correct information from l_rc
        const ErrorInfo * l_pErrInfo = NULL;

        l_pErrInfo = l_rc.getErrorInfo();

        if (l_pErrInfo == NULL)
        {
            FAPI_ERR("rcTest14. getErrorInfo returned NULL");
            l_result = 2;
            break;
        }

        if (l_pErrInfo->iv_gards.size() != 1)
        {
            FAPI_ERR("rcTest14. %d gards", l_pErrInfo->iv_gards.size());
            l_result = 3;
            break;
        }

        if (l_pErrInfo->iv_gards[0]->iv_target != l_target)
        {
            FAPI_ERR("rcTest14. gard target mismatch");
            l_result = 4;
            break;
        }

        // Ensure that getErrorInfo from l_rc2 returns the same pointer
        const ErrorInfo * l_pErrInfo2 = l_rc2.getErrorInfo();

        if (l_pErrInfo != l_pErrInfo2)
        {
            FAPI_ERR("rcTest14. error info mismatch");
            l_result = 5;
            break;
        }

        FAPI_INF("rcTest14. Success!");
    }
    while(0);

    return l_result;
}

//******************************************************************************
// rcTest15. Ensures that setting the ReturnCode to success clears ErrorInfo
//******************************************************************************
uint32_t rcTest15()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    ReturnCode l_rc;
    l_rc.setFapiError(FAPI_RC_INVALID_ATTR_GET);

    // Create a DIMM target
    uint32_t l_targetHandle = 3;
    Target l_target(TARGET_TYPE_DIMM, &l_targetHandle);

    // Add error information to the ReturnCode
    const void * l_objects[] = {&l_target};
    fapi::ReturnCode::ErrorInfoEntry l_entries[] =
        {{fapi::ReturnCode::EI_TYPE_GARD, 0}};
    l_rc.addErrorInfo(l_objects, l_entries, 1);

    // Set the ReturnCode to success
    l_rc = FAPI_RC_SUCCESS;

    // Check that there is no ErrorInfo
    const ErrorInfo * l_pErrInfo = NULL;

    l_pErrInfo = l_rc.getErrorInfo();

    if (l_pErrInfo != NULL)
    {
        FAPI_ERR("rcTest15. getErrorInfo returned NULL");
        l_result = 1;
    }
    else
    {
        FAPI_INF("rcTest15. Success!");
    }

    return l_result;
}

//******************************************************************************
// rcTest16. Ensures that multiple Error Info of each type can be added
//******************************************************************************
uint32_t rcTest16()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    ReturnCode l_rc;
    l_rc.setFapiError(FAPI_RC_INVALID_ATTR_GET);

    // Create 2 targets
    uint32_t l_targetHandle = 3;
    Target l_target(TARGET_TYPE_DIMM, &l_targetHandle);

    uint32_t l_targetHandle2 = 4;
    Target l_target2(TARGET_TYPE_MCS_CHIPLET, &l_targetHandle2);

    // Create 2 FFDCs
    uint8_t l_ffdc = 0x12;
    uint32_t l_ffdc2 = 0x12345678;

    // Add error information to the ReturnCode
    const void * l_objects[] = {&l_ffdc, &l_ffdc2, &l_target, &l_target2};
    fapi::ReturnCode::ErrorInfoEntry l_entries[] =
        {{fapi::ReturnCode::EI_TYPE_FFDC, 0,
          fapi::ReturnCodeFfdc::getErrorInfoFfdcSize(l_ffdc)},
         {fapi::ReturnCode::EI_TYPE_FFDC, 1,
          fapi::ReturnCodeFfdc::getErrorInfoFfdcSize(l_ffdc2)},
         {fapi::ReturnCode::EI_TYPE_CALLOUT, 2, fapi::PRI_HIGH},
         {fapi::ReturnCode::EI_TYPE_CALLOUT, 3, fapi::PRI_LOW},
         {fapi::ReturnCode::EI_TYPE_DECONF, 2},
         {fapi::ReturnCode::EI_TYPE_DECONF, 3},
         {fapi::ReturnCode::EI_TYPE_GARD, 2},
         {fapi::ReturnCode::EI_TYPE_GARD, 3}};
    l_rc.addErrorInfo(l_objects, l_entries, 8);

    do
    {
        // Check that the Error Info can be retrieved
        const ErrorInfo * l_pErrInfo = NULL;
        l_pErrInfo = l_rc.getErrorInfo();

        if (l_pErrInfo == NULL)
        {
            FAPI_ERR("rcTest16. getErrorInfo returned NULL");
            l_result = 1;
            break;
        }

        // Check the FFDC error information
        if (l_pErrInfo->iv_ffdcs.size() != 2)
        {
            FAPI_ERR("rcTest16. %d FFDCs", l_pErrInfo->iv_ffdcs.size());
            l_result = 2;
            break;
        }

        uint32_t l_size = 0;
        const void * l_pFfdc = NULL;

        l_pFfdc = l_pErrInfo->iv_ffdcs[0]->getData(l_size);

        if (l_size != sizeof(l_ffdc))
        {
            FAPI_ERR("rcTest16. FFDC[0] size is %d", l_size);
            l_result = 3;
            break;
        }

        const uint8_t * l_pFfdcCheck = static_cast<const uint8_t *>(l_pFfdc);
        if (*l_pFfdcCheck != 0x12)
        {
            FAPI_ERR("rcTest16. FFDC[0] is 0x%x", *l_pFfdcCheck);
            l_result = 4;
            break;
        }

        l_pFfdc = l_pErrInfo->iv_ffdcs[1]->getData(l_size);

        if (l_size != sizeof(l_ffdc2))
        {
            FAPI_ERR("rcTest16. FFDC[1] size is %d", l_size);
            l_result = 5;
            break;
        }

        const uint32_t * l_pFfdc2Check = static_cast<const uint32_t *>(l_pFfdc);
        if (*l_pFfdc2Check != 0x12345678)
        {
            FAPI_ERR("rcTest16. FFDC[1] is 0x%x", *l_pFfdc2Check);
            l_result = 6;
            break;
        }

        // Check the callout error information
        if (l_pErrInfo->iv_callouts.size() != 2)
        {
            FAPI_ERR("rcTest16. %d callouts", l_pErrInfo->iv_ffdcs.size());
            l_result = 7;
            break;
        }

        if (l_pErrInfo->iv_callouts[0]->iv_target != l_target)
        {
            FAPI_ERR("rcTest16. callout[0] target mismatch");
            l_result = 8;
            break;
        }

        if (l_pErrInfo->iv_callouts[0]->iv_priority != PRI_HIGH)
        {
            FAPI_ERR("rcTest16. callout[0] priority mismatch");
            l_result = 9;
            break;
        }

        if (l_pErrInfo->iv_callouts[1]->iv_target != l_target2)
        {
            FAPI_ERR("rcTest16. callout[1] target mismatch");
            l_result = 10;
            break;
        }

        if (l_pErrInfo->iv_callouts[1]->iv_priority != PRI_LOW)
        {
            FAPI_ERR("rcTest16. callout[1] priority mismatch");
            l_result = 11;
            break;
        }

        // Check the deconfig error information
        if (l_pErrInfo->iv_deconfigs.size() != 2)
        {
            FAPI_ERR("rcTest16. %d deconfigs", l_pErrInfo->iv_deconfigs.size());
            l_result = 12;
            break;
        }

        if (l_pErrInfo->iv_deconfigs[0]->iv_target != l_target)
        {
            FAPI_ERR("rcTest16. deconfig[0] target mismatch");
            l_result = 13;
            break;
        }

        if (l_pErrInfo->iv_deconfigs[1]->iv_target != l_target2)
        {
            FAPI_ERR("rcTest16. deconfig[1] target mismatch");
            l_result = 13;
            break;
        }

        // Check the GARD error information
        if (l_pErrInfo->iv_gards.size() != 2)
        {
            FAPI_ERR("rcTest16. %d gards", l_pErrInfo->iv_gards.size());
            l_result = 14;
            break;
        }

        if (l_pErrInfo->iv_gards[0]->iv_target != l_target)
        {
            FAPI_ERR("rcTest16. gard[0] target mismatch");
            l_result = 15;
            break;
        }

        if (l_pErrInfo->iv_gards[1]->iv_target != l_target2)
        {
            FAPI_ERR("rcTest16. gard[1] target mismatch");
            l_result = 16;
            break;
        }

        FAPI_INF("rcTest16. Success!");
    }
    while(0);

    return l_result;
}

//******************************************************************************
// rcTest17. Ensures that static_cast can be applied to a ReturnCode
//******************************************************************************
uint32_t rcTest17()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    ReturnCode l_rc(FAPI_RC_INVALID_ATTR_GET);

    uint32_t l_check = static_cast<uint32_t>(l_rc);

    if (l_check != FAPI_RC_INVALID_ATTR_GET)
    {
        FAPI_ERR("rcTest17. RC is not FAPI_RC_INVALID_ATTR_GET, it is 0x%x",
        l_check);
        l_result = 1;
    }
    else
    {
        FAPI_INF("rcTest17. Success!");
    }

    return l_result;
}

}
OpenPOWER on IntegriCloud