summaryrefslogtreecommitdiffstats
path: root/src/occApplet/testApplet/errlTest.c
blob: c466c8f92f6edd441f1881c98711518be14fdb43 (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
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
/******************************************************************************
// @file errlTest.c
// @brief OCC errl component test applet
*/
/******************************************************************************
 *
 *       @page ChangeLogs Change Logs
 *       @section errlTest.c ERRLTEST.c
 *       @verbatim
 *
 *   Flag    Def/Fea    Userid    Date        Description
 *   ------- ---------- --------  ----------  ----------------------------------
 *   @at002             alvinwan  02/10/2012  Created
 *   @nh001             neilhsu   05/23/2012  Add missing error log tags 
 *   @at012  868019     alvinwan  01/25/2014  TRAC_get_buffer_partial() can result in TLB Miss Exception
 *   @jh001  881996     joshych   05/07/2013  Support SRAM error log format
 *   @jh003  890574     joshych   15/07/2013  Fix errlTest Applet
 *   @rt001  901927     tapiar    10/02/2013  Update error log to use unique module id
 *   @fk006  914801     fmkassem  01/05/2013  Remove wrong reference to a reasoncode
 *   @sb100  916174     sbroyles  02/18/2014  Remove rand.h include for ssx release release20140214
 *
 *  @endverbatim
 *
 *///*************************************************************************/

#define ERRL_DEBUG
/*****************************************************************************/
// Includes
/*****************************************************************************/
#include <common_types.h>   // imageHdr_t declaration and image header macro
#include "ssx.h"
#include "ssx_io.h"         // For ERRL_DBGs
#include <errl.h>
#include <appletId.h>       // For applet ID
// #include <rand.h> @sb100
#include <trac.h>           // For traces
#include <occ_service_codes.h> // Reason code
#include <cmdh_fsp.h>       // Needed for rc codes.
#include <trac_interface.h>
#include <aplt_service_codes.h>         // For test applet module ID
#include <testApltId.h>     // For test applet ID

//*************************************************************************
// Externs
//*************************************************************************

//*************************************************************************
// Macros
//*************************************************************************
#define CHECK_CONDITION(cond, rv) \
    if( !(cond) ) \
    { \
        rv = __LINE__; \
        break; \
    }

//*************************************************************************
// Defines/Enums
//*************************************************************************
#define ERRLTESTMAIN_ID  "errl Test\0"
#define TRAC_PATTERN 0x55
#define MAX_BUFFER_SIZE MAX_ERRL_CALL_HOME_SZ
#define TEST_MODULE_ID 0x1616                           // @nh001a

// sensor test module ID enumeration
typedef enum
{
    TEST_ERROR_HANDLING = 0x00,
    TEST_CREATE_COMMIT_DELETE_LOG = 0x01,
    TEST_ADD_USRDTLS_TO_ERRL = 0x02,
    TEST_ADD_TRACE_TO_ERRL = 0x03,
    TEST_TIME = 0x04,
    TEST_CREATE2INFO_CALLHOMELOG = 0x05,
    TEST_CREATE_MAX_LOGS = 0x06,
    TEST_CALLOUTS = 0x07,
    TEST_SET_ERRLSEV_TO_INFO = 0x08,
    TEST_ERRL_TEST_WORD_ALIGN = 0x09
} errlTestModId;

// errl test return codes
typedef enum
{
    SUCCESS_RC = 0x00000000,
} errlTestRc;
        
//*************************************************************************
// Structures
//*************************************************************************

//*************************************************************************
// Globals
//*************************************************************************
// TRACE: Trace buffers initialized
uint8_t G_data[ MAX_BUFFER_SIZE];
//*************************************************************************
// Function Prototypes
//*************************************************************************
uint32_t errlTestErrorHandling();
uint32_t errlTestAddUsrDtlsToErrl();
uint32_t errlTestAddTraceToErrl();
uint32_t errlTestDtlSizeLimit();
uint32_t errlTestTime();
uint32_t errlTestCreateCommitDeleteLog();
uint32_t errlTestCreate2InfoCallhomeLog();
uint32_t errlTestCreateMaxLogs();
uint32_t errlTestCallouts();
uint32_t errlTestSetErrlSevToInfo();
uint32_t errlTestWordAlign();
void dumpLog( errlHndl_t i_log, uint32_t i_len );
void ppdumpslot(void);

//*************************************************************************
// Functions
//*************************************************************************
// Function errlTestMain
//
// Name: sensorTestMain
//
// Description: Entry point function
//
// Flow:              FN=None
//
// End Function Specification
errlHndl_t errlTestMain(void * i_arg)
{

    errlHndl_t l_err = NULL;
    uint16_t l_modId = 0;
    uint32_t l_rc = ERRL_RC_SUCCESS;

    ERRL_DBG("Enter errlTestMain\n");

    do
    {
        l_rc = errlTestErrorHandling();
        l_modId = TEST_ERROR_HANDLING;

        if( l_rc != ERRL_RC_SUCCESS)
        {
            TRAC_INFO("Failure on error handling test");
            break;
        };

        l_rc = errlTestCreateCommitDeleteLog();
        l_modId = TEST_CREATE_COMMIT_DELETE_LOG ;
        if( l_rc != ERRL_RC_SUCCESS)
        {
            TRAC_INFO("Failure on Log test");
            break;
        }

        l_rc = errlTestAddUsrDtlsToErrl();
        l_modId = TEST_ADD_USRDTLS_TO_ERRL ;
        if( l_rc != ERRL_RC_SUCCESS)
        {
            TRAC_INFO("Failure on add user detail test");
            break;
        }

        l_rc = errlTestAddTraceToErrl();
        l_modId = TEST_ADD_TRACE_TO_ERRL ;
        if( l_rc != ERRL_RC_SUCCESS)
        {
            TRAC_INFO("Failure on add trace test");
            break;
        }

        l_rc = errlTestTime();
        l_modId = TEST_TIME ;
        if( l_rc != ERRL_RC_SUCCESS)
        {
            TRAC_INFO("Failure on time test");
            break;
        }

        l_rc = errlTestCreate2InfoCallhomeLog();
        l_modId = TEST_CREATE2INFO_CALLHOMELOG ;
        if( l_rc != ERRL_RC_SUCCESS)
        {
            TRAC_INFO("Failure on create call home log test");
            break;
        }

        l_rc = errlTestCreateMaxLogs();
        l_modId = TEST_CREATE_MAX_LOGS ;
        if( l_rc != ERRL_RC_SUCCESS)
        {
            TRAC_INFO("Failure on create max logs test");
            break;
        }

        l_rc = errlTestCallouts();
        l_modId = TEST_CALLOUTS ;
        if( l_rc != ERRL_RC_SUCCESS)
        {
            TRAC_INFO("Failure on callouts test");
            break;
        }

        l_rc = errlTestSetErrlSevToInfo();
        l_modId = TEST_SET_ERRLSEV_TO_INFO ;
        if( l_rc != ERRL_RC_SUCCESS)
        {
            TRAC_INFO("Failure on SetErrlSevToInfo test");
            break;
        }

        // @jh003c
        // comment out the test case since we no longer add the alignment in addUsrDtlsToErrl
        //l_rc = errlTestWordAlign(); 
        //l_modId = TEST_ERRL_TEST_WORD_ALIGN ;
        //if( l_rc != ERRL_RC_SUCCESS)
        //{
        //    TRAC_INFO("Failure on word alignment test");
        //    break;
        //}
    } while (0);

    if( l_rc != ERRL_RC_SUCCESS)
    {
        ERRL_DBG("**********************************************");
        ERRL_DBG("* errl Test Failed (errlTest.c): line: %d",l_rc);
        ERRL_DBG("**********************************************");
        /* @
         * @errortype
         * @moduleid       TEST_APLT_MODID_ERRLTEST
         * @reasoncode     INTERNAL_FAILURE
         * @userdata1      Test Applet ID
         * @userdata2      Return Code
         * @userdata4      OCC_NO_EXTENDED_RC
         * @devdesc        Failure executing test applet
         */
        l_err = createErrl(TEST_APLT_MODID_ERRLTEST,
                           INTERNAL_FAILURE,        // @nh001c
                           OCC_NO_EXTENDED_RC,
                           ERRL_SEV_INFORMATIONAL,
                           NULL,
                           0,
                           ERRL_TEST_APLT,
                           l_rc);
    }
    else
    {
        ERRL_DBG("**********************************************");
        ERRL_DBG("* errl Test Passed (errlTest.c)");
        ERRL_DBG("**********************************************");
    }

    ERRL_DBG("Exit errlTestMain\n");

    return l_err;
}


// Function Specification
//
// Name: errlTestErrorHandling
//
// Description: errlTestErrorHandling
//
// Flow:              FN=None
//
// End Function Specification
uint32_t errlTestErrorHandling()
{
    uint32_t l_rc = 0;
    errlHndl_t l_errlHnd = NULL;
    uint8_t l_dataPtr[10];
    uint16_t l_entrySizeBefore = 0;
    uint16_t l_entrySizeAfter = 0;

    ERRL_DBG(" START");
    do
    {
        /****************************************************/
        // Test createErrl  with incorrect parameter
        // Set ERRL_SEVERITY to 0x04, out of range so log won't be created
        l_errlHnd = createErrl(TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, 0x04, NULL, 0, 0x01, 0x02);        // @nh001c
        CHECK_CONDITION( l_errlHnd == INVALID_ERR_HNDL, l_rc);

         /****************************************************/
        // Test addTraceToErrl  with incorrect parameter
        // Create a log
        l_errlHnd = createErrl(TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE, NULL, 0, 0x01, 0x02);        // @nh001c
        CHECK_CONDITION( l_errlHnd != INVALID_ERR_HNDL, l_rc);

        // i_trace = NULL, so entry size doesn't change
        l_entrySizeBefore = l_errlHnd->iv_userDetails.iv_entrySize;
        addTraceToErrl(NULL, 5, l_errlHnd);
        l_entrySizeAfter = l_errlHnd->iv_userDetails.iv_entrySize;
        CHECK_CONDITION(l_entrySizeBefore == l_entrySizeAfter, l_rc);

        // i_traceSz = 0, entry size doesn't change
        l_entrySizeBefore = l_errlHnd->iv_userDetails.iv_entrySize;
        addTraceToErrl(g_trac_inf, 0, l_errlHnd); // @at012c
        l_entrySizeAfter = l_errlHnd->iv_userDetails.iv_entrySize;
        CHECK_CONDITION( l_entrySizeBefore == l_entrySizeAfter, l_rc);

        // io_err = NULL, entry size doesn't change
        l_entrySizeBefore = l_errlHnd->iv_userDetails.iv_entrySize;
        addTraceToErrl(g_trac_inf, 32, NULL); // @at012c
        l_entrySizeAfter = l_errlHnd->iv_userDetails.iv_entrySize;
        CHECK_CONDITION( l_entrySizeBefore == l_entrySizeAfter, l_rc);

        // test addTraceToErrl after log is comitted so entry size doesn't change
        errlHndl_t l_errlHndx = l_errlHnd;
        commitErrl(&l_errlHnd);
        l_entrySizeBefore = l_errlHndx->iv_userDetails.iv_entrySize;
        addTraceToErrl(g_trac_inf, 32, l_errlHndx); // @at012c
        l_entrySizeAfter = l_errlHndx->iv_userDetails.iv_entrySize;
        CHECK_CONDITION( l_entrySizeBefore == l_entrySizeAfter, l_rc);

        deleteErrl(&l_errlHndx);
        CHECK_CONDITION( l_errlHndx == NULL, l_rc);

        // io_err = INVALID_ERR_HNDL
        // We are making sure that this function
        // handles a INVALID_ERR_HNDL being passed, and that we can't verify if
        // an error occured by checking anything. (It will just cause
        // a TLB exception)
        l_errlHnd = INVALID_ERR_HNDL;
        addTraceToErrl(g_trac_inf, 32, l_errlHnd); // @at012c

        /****************************************************/
        // Test commitErrl  with incorrect parameter
        // io_err = NULL
        // We are making sure that this function
        // handles a NULL being passed, and that we can't verify if
        // an error occured by checking anything. (It will just cause
        // a TLB exception)
        commitErrl( NULL);

        // l_errlHnd should be set to NULL
        l_errlHnd = INVALID_ERR_HNDL;
        commitErrl(&l_errlHnd);
        CHECK_CONDITION( l_errlHnd == NULL, l_rc);

        /****************************************************/
        // Test deleteErrl  with incorrect parameter
        // io_err = NULL
        // We are making sure that this function
        // handles a NULL being passed, and that we can't verify if
        // an error occured by checking anything. (It will just cause
        // a TLB exception)
        deleteErrl( NULL);

        // l_errlHnd should be set to NULL
        l_errlHnd = INVALID_ERR_HNDL;
        deleteErrl(&l_errlHnd);
        CHECK_CONDITION( l_errlHnd == NULL, l_rc);

        /****************************************************/
        // Test addCalloutToErrl  with incorrect parameter
        // Set io_err to NULL
        // We are making sure that this function
        // handles a NULL being passed, and that we can't verify if
        // an error occured by checking anything. (It will just cause
        // a TLB exception)
        addCalloutToErrl(NULL, ERRL_CALLOUT_TYPE_HUID, 0, ERRL_CALLOUT_PRIORITY_LOW); // @jh001c

        // Set io_err to INVALID_ERR_HNDL
        // We are making sure that this function
        // handles a INVALID_ERR_HNDL being passed, and that we can't verify if
        // an error occured by checking anything. (It will just cause
        // a TLB exception)
        addCalloutToErrl(INVALID_ERR_HNDL, ERRL_CALLOUT_TYPE_HUID, 0, ERRL_CALLOUT_PRIORITY_LOW); // @jh001c

        /****************************************************/
        // Test addUsrDtlsToErrl with incorrect parameter
        // Create a log
        l_errlHnd = createErrl(TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE, NULL, 0, 0x01, 0x02);        // @nh001c
        CHECK_CONDITION( l_errlHnd != INVALID_ERR_HNDL, l_rc);

        // io_err = NULL
        // We are making sure that this function
        // handles a NULL being passed, and that we can't verify if
        // an error occured by checking anything. (It will just cause
        // a TLB exception)
        addUsrDtlsToErrl(NULL, l_dataPtr, 10, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA);

        // io_err = INVALID_ERR_HNDL
        // We are making sure that this function
        // handles a INVALID_ERR_HNDL being passed, and that we can't verify if
        // an error occured by checking anything. (It will just cause
        // a TLB exception)
        addUsrDtlsToErrl(INVALID_ERR_HNDL, l_dataPtr, 10, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA);

        // i_dataPtr = NULL so entry size doesn't change
        l_entrySizeBefore = l_errlHnd->iv_userDetails.iv_entrySize;
        addUsrDtlsToErrl(l_errlHnd, NULL, 10, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA);
        l_entrySizeAfter = l_errlHnd->iv_userDetails.iv_entrySize;
        CHECK_CONDITION( l_entrySizeBefore == l_entrySizeAfter, l_rc);

        // i_size = 0 so so entry size doesn't change
        l_entrySizeBefore = l_errlHnd->iv_userDetails.iv_entrySize;
        addUsrDtlsToErrl(l_errlHnd, l_dataPtr, 0, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA);
        l_entrySizeAfter = l_errlHnd->iv_userDetails.iv_entrySize;
        CHECK_CONDITION( l_entrySizeBefore == l_entrySizeAfter, l_rc);

        // test addUsrDtlsToErrl after log is committed so entry size doesn't change
        l_errlHndx = l_errlHnd;
        commitErrl(&l_errlHnd);
        l_entrySizeBefore = l_errlHndx->iv_userDetails.iv_entrySize;
        addUsrDtlsToErrl(l_errlHndx, l_dataPtr, 10, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA);
        l_entrySizeAfter = l_errlHndx->iv_userDetails.iv_entrySize;
        CHECK_CONDITION( l_entrySizeBefore == l_entrySizeAfter, l_rc);

        deleteErrl(&l_errlHndx);
        CHECK_CONDITION( l_errlHndx == NULL, l_rc);

        /****************************************************/
        // Test setErrlSevToInfo  with incorrect parameter
        // Set io_err to NULL.
        // We are making sure that this function
        // handles a NULL being passed, and that we can't verify if
        // an error occured by checking anything. (It will just cause
        // a TLB exception)
        setErrlSevToInfo(NULL);

        // Set io_err to INVALID_ERR_HNDL
        // We are making sure that this function
        // handles a INVALID_ERR_HNDL being passed, and that we can't verify if
        // an error occured by checking anything. (It will just cause
        // a TLB exception)
        setErrlSevToInfo(INVALID_ERR_HNDL);
    }while(0);

    return l_rc;
}

// Function Specification
//
// Name: errlTestCreateCommitDeleteLog
//
// Description: errlTestCreateCommitDeleteLog
//
// Flow:              FN=None
//
// End Function Specification
uint32_t errlTestCreateCommitDeleteLog()
{
    ERRL_DBG("START");
    uint32_t l_rc = 0;

    do
    {
        /****************************************************/
        // Test create log
        errlHndl_t l_handle = NULL;
        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_CALLHOME_DATA, g_trac_inf, 512, 0x1, 0x2);        // @nh001c @at012c
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);

        ERRL_DBG("Slots after Creating call home log" );
        ppdumpslot();

        /****************************************************/
        // Test commit log
        errlHndl_t l_handle2 = l_handle;
        commitErrl( &l_handle );
        CHECK_CONDITION( (l_handle == NULL) &&
                         (l_handle2->iv_userDetails.iv_committed == 1), l_rc);

        ERRL_DBG("Slots after Commiting call home log" );
        dumpLog( l_handle2, l_handle2->iv_userDetails.iv_entrySize );
        ppdumpslot();

        /****************************************************/
        // Test delete log
        deleteErrl(&l_handle2);
        CHECK_CONDITION( l_handle2 == NULL, l_rc);

        ERRL_DBG("Slots after delete Log" );
        ppdumpslot();

        ERRL_DBG("END \n");

    }while(0);

    return l_rc;
}

// Function Specification
//
// Name: errlTestAddUsrDtlsToErrl
//
// Description: errlTestAddUsrDtlsToErrl
//
// Flow:              FN=None
//
// End Function Specification
uint32_t errlTestAddUsrDtlsToErrl()
{
    uint32_t l_rc = 0;
    ERRL_DBG("START");
    uint16_t l_entrySizeBefore = 0;
    uint16_t l_entrySizeAfter = 0;

    do
    {
        // Create three err logs
        errlHndl_t l_handle = NULL;
        errlHndl_t l_handle2 = NULL;
        errlHndl_t l_handle3 = NULL;

        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_UNRECOVERABLE, NULL, 512, 0x1, 0x2);        // @nh001c
        l_handle2 = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_CALLHOME_DATA, NULL, 512, 0x1, 0x2);        // @nh001c
        l_handle3 = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_INFORMATIONAL, NULL, 512, 0x1, 0x2);        // @nh001c

        // l_handle will set to NULL after calling the commitErrl, so we need to store it
        errlHndl_t l_handleX = l_handle;
        errlHndl_t l_handle2X = l_handle2;
        errlHndl_t l_handle3X = l_handle3;
        ERRL_DBG("Slots after Create - 3 slots should be used (one of each");
        ppdumpslot();

        CHECK_CONDITION( (l_handle != INVALID_ERR_HNDL) &&
                         (l_handle2 != INVALID_ERR_HNDL) &&
                         (l_handle3 != INVALID_ERR_HNDL), l_rc);

        /****************************************************/
        // Test sizelimit for addUsrDtlsToErrl
        // Add "user details" data that exceeds the max size for l_handle
        l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize;
        memset( G_data, 0xCC, sizeof( G_data ) );
        addUsrDtlsToErrl( l_handle, G_data, sizeof( G_data ), ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA );
        l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize;
        CHECK_CONDITION( l_entrySizeAfter == MAX_ERRL_ENTRY_SZ, l_rc);

        // Add "user details" data that exceeds the max size for l_handle2
        l_entrySizeBefore = l_handle2->iv_userDetails.iv_entrySize;
        memset( G_data, 0xDD, sizeof( G_data ) );
        addUsrDtlsToErrl( l_handle2, G_data, sizeof( G_data ), ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_CALLHOME_DATA );
        l_entrySizeAfter = l_handle2->iv_userDetails.iv_entrySize;
        CHECK_CONDITION( l_entrySizeAfter == MAX_ERRL_CALL_HOME_SZ, l_rc);

        // Add "user details" with size 76 for l_handle3
        l_entrySizeBefore = l_handle3->iv_userDetails.iv_entrySize;
        memset( G_data, 0xEE, sizeof( G_data ) );
        addUsrDtlsToErrl( l_handle3, G_data, 76, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA );
        l_entrySizeAfter = l_handle3->iv_userDetails.iv_entrySize;
        // (header + 76) is the size that add to entry
        CHECK_CONDITION( l_entrySizeAfter == (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+76), l_rc);

        dumpLog( l_handle, l_handle->iv_userDetails.iv_entrySize );
        dumpLog( l_handle2, l_handle2->iv_userDetails.iv_entrySize );
        dumpLog( l_handle3, l_handle3->iv_userDetails.iv_entrySize );

        commitErrl( &l_handle );
        commitErrl( &l_handle2 );
        commitErrl( &l_handle3 );
        ERRL_DBG("Slots after Commit -  3 slots should be used/committed");
        ppdumpslot();

        deleteErrl(&l_handleX);
        deleteErrl(&l_handle2X);
        deleteErrl(&l_handle3X);
        CHECK_CONDITION( (l_handleX == NULL) &&
                         (l_handle2X == NULL) &&
                         (l_handle3X == NULL), l_rc);

        ERRL_DBG("Slots after delete Log - All slots should be empty");
        ppdumpslot();

        /****************************************************/
        // Test sizelimit for addUsrDtlsToErrl with continuous calls
        // Create log with 512 bytes trace
        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE, g_trac_inf, 512, 0x1, 0x2);        // @nh001c @at012c
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);

        // l_handle will set to NULL after calling the commitErrl, so we need to store it
        l_handleX = l_handle;
        ppdumpslot();

        // add 256 bytes of "user details" (512+256)
        l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize;
        memset( G_data, 0xAA, sizeof( G_data ) );
        addUsrDtlsToErrl( l_handle, G_data, 256, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA );
        l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize;
        ERRL_DBG("Slots after create + 256 bytes" );
        ppdumpslot();
        // (header + 256) is the size that add to entry
        CHECK_CONDITION( l_entrySizeAfter == (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+256), l_rc);

        // add 512 bytes of "user details" (512+256+512)
        l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize;
        memset( G_data, 0xBB, sizeof( G_data ) );
        addUsrDtlsToErrl( l_handle, G_data, 512, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA );
        l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize;
        ERRL_DBG("Slots after create + 256 + 512 bytes");
        ppdumpslot();
        // (header + 512) is the size that add to entry
        CHECK_CONDITION( l_entrySizeAfter == (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+512), l_rc);

        // add 1024 bytes of "user details" (512+256+512+1024), the entry size is more than 2048 now
        l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize;
        memset( G_data, 0xCC, sizeof( G_data ) );
        addUsrDtlsToErrl( l_handle, G_data, 1024, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA );
        l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize;
        ERRL_DBG("Slots after create + 256 + 512 +1024 bytes");
        ppdumpslot();
        // (header + 1024) is the size that add to entry
        CHECK_CONDITION( l_entrySizeAfter <= MAX_ERRL_ENTRY_SZ, l_rc); // @at012c

        commitErrl( &l_handle );
        deleteErrl(&l_handleX);
        ERRL_DBG("Slots should now be empty");
        ppdumpslot();
        ERRL_DBG("END \n");
    }while(0);

    return l_rc;
}

// Function Specification
//
// Name: errlTestAddTraceToErrl
//
// Description: errlTestAddTraceToErrl
//
// Flow:              FN=None
//
// End Function Specification
uint32_t errlTestAddTraceToErrl()
{
    uint32_t l_rc = 0;
    uint16_t l_entrySizeBefore = 0;
    uint16_t l_entrySizeAfter = 0;
    ERRL_DBG("START");

    do
    {
        // Create one err log
        errlHndl_t l_handle = NULL;
        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE, NULL, 512, 0x1, 0x2);        // @nh001c
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);

        // l_handle will set to NULL after calling the commitErrl, so we need to store it
        errlHndl_t l_handleX = l_handle;
        ERRL_DBG("Slots after Create - 1 slots should be used (one of each");
        ppdumpslot();

        /****************************************************/
        // Test sizelimit for addTraceToErrl
        // Add "trace" data that exceeds the max size
        l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize;
        addTraceToErrl(g_trac_inf, MAX_BUFFER_SIZE, l_handle); // @at012c
        l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize;
        CHECK_CONDITION( l_entrySizeAfter <= MAX_ERRL_ENTRY_SZ, l_rc); // @at012c

        dumpLog( l_handle, l_handle->iv_userDetails.iv_entrySize );
        commitErrl( &l_handle );
        ERRL_DBG("Slots after Commit -  1 slots should be used/committed");
        ppdumpslot();

        deleteErrl(&l_handleX);
        ERRL_DBG("Slots after delete Log - All slots should be empty");
        ppdumpslot();

        /****************************************************/
        // Test sizelimit for addTraceToErrl with continuous calls
        // Create log with 512 bytes trace
        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE, g_trac_inf, 512, 0x1, 0x2);        // @nh001c @at012c
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);

        // l_handle will set to NULL after calling the commitErrl, so we need to store it
        l_handleX = l_handle;
        ppdumpslot();

        // Add 256 bytes of trace (512+256)
        l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize;
        addTraceToErrl(g_trac_inf, 256, l_handle); // @at012c
        l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize;
        ERRL_DBG("Slots after create + 256 bytes" );
        ppdumpslot();
        // (header + 256) is the size that add to entry
        CHECK_CONDITION( l_entrySizeAfter <= (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+256), l_rc); // @at012c

        // Add 512 bytes of trace (512+256+512)
        l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize;
        addTraceToErrl(g_trac_inf, 512, l_handle); // @at012c
        l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize;
        ERRL_DBG("Slots after create + 256 + 512 bytes");
        ppdumpslot();
        CHECK_CONDITION( l_entrySizeAfter <= (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+512), l_rc); // @at012c

        // Add 1024 bytes of trace (512+256+512+1024), the entry size is more than 2048 now
        l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize;
        addTraceToErrl(g_trac_inf, 1024, l_handle); // @at012c
        l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize;
        ERRL_DBG("Slots after create + 256 + 512 bytes");
        ppdumpslot();
        CHECK_CONDITION( l_entrySizeAfter <= MAX_ERRL_ENTRY_SZ, l_rc); // @at012c

        commitErrl( &l_handle );
        deleteErrl(&l_handleX);
        ERRL_DBG("Slots should now be empty");
        ppdumpslot();
        ERRL_DBG("END \n");

    }while(0);

    return l_rc;
}

// Function Specification
//
// Name: errlTestTime
//
// Description: errlTestTime
//
// Flow:              FN=None
//
// End Function Specification
uint32_t errlTestTime()
{
    uint32_t l_rc = 0;

    do
    {
        ERRL_DBG("START");
        errlHndl_t l_handle = NULL;
        uint64_t l_start = 0;
        uint64_t l_end = 0;


        /****************************************************/
        // Check timeStamp
        // Create one log
        l_start = ssx_timebase_get();
        l_handle = createErrl( 0x1716, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_CALLHOME_DATA, g_trac_inf, 128, 0x1, 0x2);        // @nh001c @at012c
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);


        // check time stamp
        errlHndl_t l_handle2 = l_handle;
        commitErrl( &l_handle );
        l_end = ssx_timebase_get();
        CHECK_CONDITION( (l_handle2->iv_userDetails.iv_timeStamp >= l_start) &&
                         (l_handle2->iv_userDetails.iv_timeStamp <= l_end ), l_rc);

        deleteErrl(&l_handle2);
        ERRL_DBG("END \n");

    }while(0);

    return l_rc;
}

/*****************************************************************************/
// errlTestCreate2InfoCallhomeLog
/*****************************************************************************/
uint32_t errlTestCreate2InfoCallhomeLog()
{
    ERRL_DBG("START" );
    uint32_t l_rc = 0;

    do
    {
        /****************************************************/
        // Check creating Info logs twice
        // Create first Info log
        errlHndl_t l_handle = NULL;
        errlHndl_t l_handle2= NULL;
        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_INFORMATIONAL,g_trac_inf, 32, 0x1, 0x2);        // @nh001c @at012c
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);

        // Create second Info log and it should fail
        l_handle2 = createErrl( 0x2727, 0x19, OCC_NO_EXTENDED_RC, ERRL_SEV_INFORMATIONAL, g_trac_inf, 32, 0x2, 0x3);        // @nh001c @at012c
        CHECK_CONDITION( l_handle2 == INVALID_ERR_HNDL, l_rc);

        deleteErrl(&l_handle);

        /****************************************************/
        // Check creating Callhome logs twice
        // Create first Callhome log
        l_handle = NULL;
        l_handle2= NULL;
        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_CALLHOME_DATA,g_trac_inf, 32, 0x1, 0x2);        // @nh001c @at012c
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);

        // Create second Callhome log and it should fail
        l_handle2 = createErrl( 0x2727, 0x19, OCC_NO_EXTENDED_RC, ERRL_SEV_CALLHOME_DATA, g_trac_inf, 32, 0x2, 0x3);        // @nh001c @at012c
        CHECK_CONDITION( l_handle2 == INVALID_ERR_HNDL, l_rc);

        deleteErrl(&l_handle);

        ERRL_DBG("END \n");
    }while(0);

    return l_rc;
}

// Function Specification
//
// Name: errlTestCreateMaxLogs
//
// Description: errlTestCreateMaxLogs
//
// Flow:              FN=None
//
// End Function Specification
uint32_t errlTestCreateMaxLogs()
{
    uint32_t l_rc = 0;

    ERRL_DBG("START");
    do
    {

        /****************************************************/
        // Check max logs
        ERRL_SEVERITY l_sev = 0;
        errlHndl_t l_backupHandle[ERRL_MAX_SLOTS-2];
        errlHndl_t l_handle = NULL;

        uint32_t l_index = 0;
        // Create 7 ERRL_SEV_PREDICTIVE or ERRL_SEV_UNRECOVERABLE slots randomly
        for(l_index =0; l_index < ERRL_MAX_SLOTS-2; l_index++)
        {

            uint64_t l_time = ssx_timebase_get();
            l_sev = l_time%2 ? ERRL_SEV_PREDICTIVE : ERRL_SEV_UNRECOVERABLE;
            l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, l_sev, g_trac_inf, 512, 0x1, l_index);        // @nh001c @at012c
            CHECK_CONDITION( (l_handle != INVALID_ERR_HNDL) &&
                             (l_handle != NULL), l_rc);

            // backup handle
            l_backupHandle[l_index] = l_handle;

            ERRL_DBG("Log Created @ %p with Sev: %d\n",l_handle, l_sev );
            // addUsrDtlsToErrl
            memset( G_data, l_index, sizeof( G_data ) );
            addUsrDtlsToErrl( l_handle, G_data, sizeof(G_data), ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA );

            // commitErrl( &l_handle );
        }
        // check if something wrong in for loop
        if(l_rc != 0)
        	break;

        // Create one more and it should fail
        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, l_sev, g_trac_inf, 512, 0x1, l_index);        // @nh001c @at012c
        CHECK_CONDITION( l_handle == INVALID_ERR_HNDL, l_rc);

        // delete errl
        for(l_index = 0; l_index < ERRL_MAX_SLOTS-2; l_index++)
        {
            deleteErrl(&l_backupHandle[l_index]);
        }
        ppdumpslot();

        /****************************************************/
        // Check log id overflow
         for(l_index = 0; l_index < 256; l_index++)
        {
            l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, l_sev, g_trac_inf, 512, 0x1, l_index);        // @nh001c @at012c
            CHECK_CONDITION( (l_handle != INVALID_ERR_HNDL) &&
                             (l_handle != NULL), l_rc);

            deleteErrl(&l_handle);
        }

        ERRL_DBG("END \n");
    }while(0);

    return l_rc;
}

// Function Specification
//
// Name: errlTestCallouts
//
// Description: errlTestCallouts
//
// Flow:              FN=None
//
// End Function Specification
// @jh001c
uint32_t errlTestCallouts()
{
    uint32_t l_rc = 0;
    ERRL_DBG("START");

    do
    {
        errlHndl_t l_handle = NULL;
        ERRL_DBG("--------------------------------\n");

        /****************************************************/
        // Check max callouts
        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE,g_trac_inf, 128, 0x1, 0x2);        // @nh001c @at012c
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);

        ERRL_CALLOUT_PRIORITY l_array[8] = {
                                             ERRL_CALLOUT_PRIORITY_HIGH,
                                             ERRL_CALLOUT_PRIORITY_MED,
                                             ERRL_CALLOUT_PRIORITY_LOW,
                                             ERRL_CALLOUT_PRIORITY_HIGH,
                                             ERRL_CALLOUT_PRIORITY_MED,
                                             ERRL_CALLOUT_PRIORITY_MED,
                                             ERRL_CALLOUT_PRIORITY_LOW,
                                             ERRL_CALLOUT_PRIORITY_LOW,
                                            };

        ERRL_CALLOUT_TYPE l_type[8] = {
                                        ERRL_CALLOUT_TYPE_HUID,
                                        ERRL_CALLOUT_TYPE_COMPONENT_ID,
                                        ERRL_CALLOUT_TYPE_HUID,
                                        ERRL_CALLOUT_TYPE_COMPONENT_ID,
                                        ERRL_CALLOUT_TYPE_HUID,
                                        ERRL_CALLOUT_TYPE_COMPONENT_ID,
                                        ERRL_CALLOUT_TYPE_HUID,
                                        ERRL_CALLOUT_TYPE_COMPONENT_ID,
                                       };

        // add 6 (ERRL_MAX_CALLOUTS) callouts
        uint8_t l_index = 0;
        for(l_index = 0; l_index < ERRL_MAX_CALLOUTS; l_index++)
        {
            ERRL_DBG("current callouts %d attempting to add callout # %d with type %d ,priority %d", l_handle->iv_numCallouts, l_index, l_type[l_index], l_array[l_index] );
            addCalloutToErrl(l_handle,l_type[l_index],l_index,l_array[l_index]);
        }
        CHECK_CONDITION( l_handle->iv_numCallouts == ERRL_MAX_CALLOUTS, l_rc);

        // add one more callout and it should fail
        addCalloutToErrl(l_handle,l_type[0],l_index,l_array[0]);
        CHECK_CONDITION( l_handle->iv_numCallouts == ERRL_MAX_CALLOUTS, l_rc);

        dumpLog( l_handle, l_handle->iv_userDetails.iv_entrySize );
        deleteErrl( &l_handle );
        ppdumpslot();

        /****************************************************/
        // Check callouts after errl is committed
        // Create log
        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE,g_trac_inf, 32, 0x1, 0x2);        // @nh001c @at012c
        errlHndl_t l_log = l_handle;
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);

        // Commit log and add callout. But adding callout should fail
        commitErrl( &l_handle );
        addCalloutToErrl(l_handle,l_type[0],0,l_array[0]);
        CHECK_CONDITION( l_log->iv_numCallouts == ERRL_MAX_CALLOUTS, l_rc); // @jh003c

        deleteErrl(&l_log);

        /****************************************************/
        // Check addCalloutToErrl for ERRL_SEV_INFORMATIONAL log
        // Create ERRL_SEV_INFORMATIONAL log
        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_INFORMATIONAL,g_trac_inf, 128, 0x1, 0x2);        // @nh001c @at012c
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);
        if(l_handle == INVALID_ERR_HNDL)

        // add one callout and it should fail
        addCalloutToErrl(l_handle,l_type[0],l_index,l_array[0]);
        CHECK_CONDITION( l_handle->iv_numCallouts == 0, l_rc);

        dumpLog( l_handle, l_handle->iv_userDetails.iv_entrySize );
        deleteErrl( &l_handle );
        ppdumpslot();

        ERRL_DBG("END \n");
    }while(0);

    return l_rc;
}

// Function Specification
//
// Name: errlTestSetErrlSevToInfo
//
// Description: errlTestSetErrlSevToInfo
//
// Flow:              FN=None
//
// End Function Specification
uint32_t errlTestSetErrlSevToInfo()
{
    uint32_t l_rc = 0;
    ERRL_DBG("START");

    do
    {
        errlHndl_t l_handle = NULL;

        /****************************************************/
        // Check setErrlSevToInfo
        // Create ERRL_SEV_PREDICTIVE log
        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE,g_trac_inf, 128, 0x1, 0x2);        // @nh001c @at012c
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);

        // Add callout
        addCalloutToErrl(l_handle,ERRL_CALLOUT_TYPE_HUID,0x00,ERRL_CALLOUT_PRIORITY_LOW); // @jh001c
        CHECK_CONDITION( l_handle->iv_numCallouts == 1, l_rc);

        // Call setErrlSevToInfo. Callouts within log should be cleared and
        // iv_severity should be set to ERRL_SEV_INFORMATIONAL
        setErrlSevToInfo(l_handle);
        CHECK_CONDITION( (l_handle->iv_numCallouts == 0) &&
                         (l_handle->iv_severity == ERRL_SEV_INFORMATIONAL), l_rc);

        deleteErrl( &l_handle );
        ppdumpslot();

        /****************************************************/
        // Check setErrlSevToInfo after errl is committed
        // Create log
        l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE,g_trac_inf, 128, 0x1, 0x2);        // @nh001c @at012c
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);

        errlHndl_t l_log = l_handle;

        // Add callout
        addCalloutToErrl(l_handle,ERRL_CALLOUT_TYPE_HUID,0x00,ERRL_CALLOUT_PRIORITY_LOW); // @jh001c
        CHECK_CONDITION( l_handle->iv_numCallouts == 1, l_rc);

        // Commit log and call setErrlSevToInfo. But setErrlSevToInfo will do nothing
        commitErrl( &l_handle );
        setErrlSevToInfo(l_handle);
        CHECK_CONDITION( (l_log->iv_numCallouts == ERRL_MAX_CALLOUTS) && // @jh003c
                         (l_log->iv_severity == ERRL_SEV_PREDICTIVE), l_rc);

        deleteErrl(&l_log);
        ERRL_DBG("END \n");

    }while(0);

    return l_rc;
}

// Function Specification
//
// Name: errlTestWordAlign
//
// Description: errlTestWordAlign
//
// Flow:              FN=None
//
// End Function Specification
uint32_t errlTestWordAlign()
{
    uint32_t l_rc = 0;
    uint16_t l_entrySizeBefore = 0;
    uint16_t l_entrySizeAfter = 0;
    ERRL_DBG("START");

    do
    {
        /****************************************************/
        // Test word align for addUsrDtlsToErrl
        // Create log
        errlHndl_t l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE, NULL, 0, 0x1, 0x2);        // @nh001c
        CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc);

        // l_handle will set to NULL after calling the commitErrl, so we need to store it
        errlHndl_t l_handleX = l_handle;
        ppdumpslot();

        // add 13 bytes of "user details"
        l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize;
        memset( G_data, 0xAA, sizeof( G_data ) );
        addUsrDtlsToErrl( l_handle, G_data, 13, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA );
        l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize;
        ERRL_DBG("Slots after create + 13 bytes" );
        ppdumpslot();
        // (header + WORDALIGN(13)) is the size that add to entry
        CHECK_CONDITION( l_entrySizeAfter == (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+16), l_rc);

        /****************************************************/
        // Test word align for addTraceToErrl
        // add 21 bytes of trace
        l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize;
        addTraceToErrl(g_trac_inf, 21, l_handle); // @at012c
        l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize;
        ERRL_DBG("Slots after create + 21 bytes" );
        ppdumpslot();
        // (header + WORDALIGN(21)) is the size that add to entry
        CHECK_CONDITION( l_entrySizeAfter <= (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+24), l_rc); // @at012c

        commitErrl( &l_handle );
        deleteErrl(&l_handleX);
        ERRL_DBG("Slots should now be empty");
        ppdumpslot();
        ERRL_DBG("END \n");
    }while(0);

    return l_rc;
}


// Function Specification
//
// Name: dumpLog
//
// Description: dumpLog
//
// Flow:              FN=None
//
// End Function Specification
void dumpLog( errlHndl_t i_log, uint32_t i_len )
{
    uint32_t    l_written = 0;
    uint32_t    l_counter = 0;
    uint8_t *   l_data = (uint8_t*) i_log;

    printf("----------%p---------- \n", i_log );

    if ( i_log == NULL )
        return;

    while ( l_counter < i_len)
    {
        printf("|   %08X     ", (uint32_t) l_data + l_counter);

        // Display 16 bytes in Hex with 2 spaces in between
        l_written = 0;
        uint8_t i = 0;
        for ( i = 0; i < 16 && l_counter < i_len; i++ )
        {
            l_written += printf("%02X",l_data[l_counter++]);

            if ( ! ( l_counter % 4 ) )
            {
                l_written += printf("  ");
            }
        }

        // Pad with spaces
        uint8_t l_space[64] = {0};
        memset( l_space, 0x00, sizeof( l_space ));
        memset( l_space, ' ', 43-l_written);
        printf("%s", l_space );

        // Display ASCII
        l_written = 0;
        uint8_t l_char = 0;
        for ( ; i > 0 ; i-- )
        {
            l_char = l_data[ l_counter-i ];

            if ( isprint( l_char ) &&
                 ( l_char != '&' ) &&
                 ( l_char != '<' ) &&
                 ( l_char != '>' )
               )
            {
                l_written += printf("%c",l_char );
            }
            else
            {
                l_written += printf("." );
            }
        }

        // Pad with spaces
        uint8_t l_space2[64] = {0};
        memset( l_space2, 0x00, sizeof( l_space2 ));
        memset( l_space2, ' ', 19-l_written);
        printf("%s\n", l_space2 );
    }
   printf("----------%p---------- \n", i_log );

}

// Function Specification
//
// Name: ppdumpslot
//
// Description: ppdumpslot
//
// Flow:              FN=None
//
// End Function Specification
void ppdumpslot(void)
{
    errlHndl_t l_array[ERRL_MAX_SLOTS] = {
                            (errlHndl_t)G_errslot1,
                            (errlHndl_t)G_errslot2,
                            (errlHndl_t)G_errslot3,
                            (errlHndl_t)G_errslot4,
                            (errlHndl_t)G_errslot5,
                            (errlHndl_t)G_errslot6,
                            (errlHndl_t)G_errslot7,
                            (errlHndl_t)G_infoslot,
                            (errlHndl_t)G_callslot,
                            };


    printf("-------- \n");

    uint8_t l_index = 0;
    for(l_index = 0; l_index < ERRL_MAX_SLOTS; l_index++)
    {
        if(l_array[l_index]->iv_version != 0)
        {
            printf("slot[%01d] sz[%04d] id[%03d] @[%p] \n",l_index,l_array[l_index]->iv_userDetails.iv_entrySize, l_array[l_index]->iv_entryId, l_array[l_index]);
        }
        else
        {
            printf("slot[%01d] [0] \n",l_index);
        }
    }
    printf("-------- \n");
}

/*****************************************************************************/
// Image Header
/*****************************************************************************/
IMAGE_HEADER (G_errlTestMain,errlTestMain,ERRLTESTMAIN_ID,OCC_APLT_TEST);

OpenPOWER on IntegriCloud