summaryrefslogtreecommitdiffstats
path: root/src/usr/errl/test/errltest.H
blob: 40e58a2665edc223005ff034579b76d0a86a6a32 (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
#ifndef __ERRLTEST_H
#define __ERRLTEST_H

/**
 *  @file errltest.H
 *
 *  @brief Test case for Error Logging
*/

#include <cxxtest/TestSuite.H>
#include <errl/errlmanager.H>
#include <errl/errlentry.H>
#include <hbotcompid.H>

#define TEST_REASON_CODE    (ERRL_COMP_ID | 0x0F)
#define TEST_SEVERITY       ERRORLOG::ERRL_SEV_INFORMATIONAL
#define TEST_MOD_ID         0x0022

#define TEST_USR_8BIT_1    0x80
#define TEST_USR_8BIT_2    0x93

#define TEST_USR_16BIT_1    0x8000
#define TEST_USR_16BIT_2    0x9003

#define TEST_USR_32BIT_1     0x80000001
#define TEST_USR_32BIT_2     0x90000003

#define TEST_USR_64BIT_1    0x8000000000000001
#define TEST_USR_64BIT_2    0x9000000000000003



class ErrlTest: public CxxTest::TestSuite
{
public:


    /**
     * @brief Test error log creation
     *  - Create an error log
     *  - Verify data of created log
     *  - Commit an error log
     *  - Delete an error log
     */
    void testErrl1(void)
    {
        ERRORLOG::ErrlFFDC * pffdc;

        // An example that shows how to use macros to stuff data into
        // the two 64-bit user data parameters in the error log.
        // l_userData1 = 16bit(0):l_bit8_1:l_bit8_2:l_32bit_1
        uint8_t l_8bit_1 = TEST_USR_8BIT_1;      // 0x80
        uint8_t l_8bit_2 = TEST_USR_8BIT_2;      // 0x93 
        uint32_t l_32bit_1 = TEST_USR_32BIT_1;   // 0x80000001
        uint64_t l_userData1 = 
          TWO_UINT32_TO_UINT64( TO_UINT32(TWO_UINT8_TO_UINT16(l_8bit_1, l_8bit_2)), l_32bit_1);
            // yields 0x0000809380000001


        // l_userData2 = l_16bit_1:l_16bit_2:l_32bit_2
        uint16_t l_16bit_1 = TEST_USR_16BIT_1;  // 0x8000
        uint16_t l_16bit_2 = TEST_USR_16BIT_2;  // 0x9003
        uint32_t l_32bit_2 = TEST_USR_32BIT_2;  // 0x90000003
        uint64_t l_userData2 = TWO_UINT16_ONE_UINT32_TO_UINT64(l_16bit_1, l_16bit_2, l_32bit_2);
            // yields 0x8000900390000003

        // Create an error log
        errlHndl_t l_err = new ERRORLOG::ErrlEntry(
                                ERRORLOG::ERRL_SEV_INFORMATIONAL,
                                TEST_MOD_ID,
                                TEST_REASON_CODE,
                                l_userData1,
                                l_userData2);


        // Make sure log is created
        if (l_err == NULL)
        {
            TS_FAIL("testErrl1: createErrlLog() outputs NULL pointer!");
        }


        // These addFFDC() calls return a pointer to class ERRORLOG::ErrlFFDC
        // but errlffdc.H is not publicly includable to give me the definition
        // for it.  addFFDC() should return a Boolean indication of success.

        const char * pch = "martha washington";
        pffdc = l_err->addFFDC( ERRL_COMP_ID, pch, strlen( pch ), 1, 2 );
        if ( NULL == pffdc )
        {
            TS_FAIL("testErrl1: addFFDC() output NULL pointer");
        }

        pch = "george washington"; 
        pffdc = l_err->addFFDC( DEVFW_COMP_ID, pch, strlen( pch ), 3, 4 );
        if ( NULL == pffdc )
        {
            TS_FAIL("testErrl1: addFFDC() output NULL pointer");
        }

        pch = "dwight eisenhour";  
        pffdc = l_err->addFFDC( SCOM_COMP_ID, pch, strlen( pch ), 5, 6 );
        if ( NULL == pffdc )
        {
            TS_FAIL("testErrl1: addFFDC() output NULL pointer");
        }

        pch = "ronald ";
        pffdc = l_err->addFFDC( ERRL_COMP_ID, pch, strlen( pch ), 7, 8 );
        if ( NULL == pffdc )
        {
            TS_FAIL("testErrl1: addFFDC() output NULL pointer");
        }

        // Append data to something already added.
        pch = "reagan";
        l_err->appendToFFDC( pffdc, pch, strlen(pch) );


        // Add null data.
        pffdc = l_err->addFFDC( ERRL_COMP_ID, NULL, 0,  9, 10 );
        if ( NULL != pffdc )
        {
            TS_FAIL("testErrl1: addFFDC() returned non null");
        }
     
 






        // Verify log data
        else if (l_err->sev() != ERRORLOG::ERRL_SEV_INFORMATIONAL)
        {
            TS_FAIL("testErrl1: createErrlLog() returns incorrect severity!");
        }
        else if (l_err->reasonCode() != TEST_REASON_CODE)
        {
             TS_FAIL("testErrl1: createErrlLog() returns incorrect reason code!");
        }
        else if (l_err->eventType() != ERRORLOG::ERRL_ETYPE_NOT_APPLICABLE)
        {
             TS_FAIL("testErrl1: createErrlLog() returns incorrect event type!");
        }
        else if (l_err->subSys() != ERRORLOG::EPUB_RESERVED_0)
        {
             TS_FAIL("testErrl1: createErrlLog() returns incorrect sub system!");
        }
        else if (l_err->srcType() != ERRORLOG::SRC_ERR_INFO)
        {
             TS_FAIL("testErrl1: createErrlLog() returns incorrect SRC type!");
        }
        else if (l_err->termState() != ERRORLOG::TERM_STATE_UNKNOWN)
        {
             TS_FAIL("testErrl1: termState() returns incorrect term state!");
        }
        else
        {
            // Commit error log
            errlCommit(l_err);
            // Make sure error log has been deleted by manager
            if (l_err != NULL)
            {
                TS_FAIL("testErrl1: commitErrLog() did not delete error!");
            }
        }
    }

    /**
     * @brief Test error log parameter settings
     */
    void testErrl2(void)
    {
        // An example that shows how to use macros to stuff data into
        // the two 64-bit user data parameters in the error log.
        // l_userData1 = l_bit32_1:l_bit32_2
        uint32_t l_32bit_1 = TEST_USR_32BIT_1;
        uint32_t l_32bit_2 = TEST_USR_32BIT_2;
        uint64_t l_userData1 = TWO_UINT32_TO_UINT64(l_32bit_1, l_32bit_2);

        // l_userData2 = 24bit(0):l_8bit_1:16bit(0):l_16bit_1
        uint8_t l_8bit_1 = TEST_USR_8BIT_1;
        uint16_t l_16bit_1 = TEST_USR_16BIT_1;
        uint64_t l_userData2 =
                TWO_UINT32_TO_UINT64(TO_UINT32(l_8bit_1), TO_UINT32(l_16bit_1));

        // Create an error log
        errlHndl_t l_err = new ERRORLOG::ErrlEntry(
                                ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                TEST_MOD_ID,
                                TEST_REASON_CODE,
                                l_userData1,
                                l_userData2);

        // Make sure log is created
        if (l_err == NULL)
        {
            TS_FAIL("testErrl2: createErrlLog() returns NULL pointer!");
        }
        else
        {
            // Set and verify log data
            l_err->setSev(ERRORLOG::ERRL_SEV_UNKNOWN);
            l_err->setEventType(ERRORLOG::ERRL_ETYPE_CAPACITY_UPGRADE);
            l_err->setSubSys(ERRORLOG::EPUB_UNKNOWN);
            l_err->setSrcType(ERRORLOG::SRC_ERR_INFO);
            l_err->setTermState(ERRORLOG::TERM_STATE_NO_FLAGS);

            if (l_err->sev() != ERRORLOG::ERRL_SEV_UNKNOWN)
            {
                TS_FAIL("testErrl2: setSev() fails!");
            }
            else if (l_err->eventType() != ERRORLOG::ERRL_ETYPE_CAPACITY_UPGRADE)
            {
                TS_FAIL("testErrl2: setEventType() fails!");
            }
            else if (l_err->subSys() != ERRORLOG::EPUB_UNKNOWN)
            {
                TS_FAIL("testErrl2: setSubSys() fails!");
            }
            else if (l_err->srcType() != ERRORLOG::SRC_ERR_INFO)
            {
                TS_FAIL("testErrl2: setSrcType() fails!");
            }
            else if (l_err->termState() != ERRORLOG::TERM_STATE_NO_FLAGS)
            {
                 TS_FAIL("testErrl2: setTermState() fails!");
            }

            // Delete the log
            delete l_err;
            l_err = NULL;

        }
    }
};

#endif
OpenPOWER on IntegriCloud