summaryrefslogtreecommitdiffstats
path: root/src/usr/errl/test/errluserdetailtest.H
blob: 204951e381c799ea167a6c8502facf9189daf93a (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/errl/test/errluserdetailtest.H $                      */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2011,2016                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#ifndef __TEST_ERRLUSERDETAILSTEST_H
#define __TEST_USERUSERDETAILSTEST_H

/**
 *  @file errluserdetailstest.H
 *
 *  @brief Test user data plugins for errorlog.
 *
 */

#include <stdio.h>
#include <cxxtest/TestSuite.H>
#include <errl/errlentry.H>
#include <errl/errluserdetails.H>
#include <errl/errlreasoncodes.H>
#include <errl/errludstring.H>
#include <errl/errludbacktrace.H>
#include <errl/errludtarget.H>
#include <errl/errludlogregister.H>
#include <errl/errludcallout.H>
#include <errl/errludattribute.H>
#include <targeting/common/targetservice.H>
#include <targeting/common/iterators/rangefilter.H>
#include <targeting/common/predicates/predicates.H>
#include <targeting/common/util.H>
#include <hwas/common/deconfigGard.H>

#include <devicefw/driverif.H>

using   namespace   ERRORLOG;

class UtilErrlUsrDataTest: public CxxTest::TestSuite
{
public:

    // Note that errlUserDetailsTarget is tested in the targeting unit test

    /**
     * @test testString - Capture a String in an error log
     */
    void testString(void)
    {
        errlHndl_t errl = NULL;

        TS_TRACE( "testString errorlog user detail data");
        /*@
        * @errortype
        * @severity ERRORLOG_SEV_INFORMATIONAL
        * @moduleid ERRL_USERDATA_TEST_MOD_ID
        * @reasoncode ERRL_TEST_STRING_UD
        * @userdata1 Test data 1
        * @userdata2 Test data 2
        * @devdesc  User Details unit test - create string user detail data.
        * @custdesc A problem occurred during the IPL of the system.
        */
        errl = new ErrlEntry(
                ERRL_SEV_INFORMATIONAL,
                ERRL_USERDATA_TEST_MOD_ID,
                ERRL_TEST_STRING_UD,
                0x1234567890,                   //  user1
                0x9876543210 );                 //  user2

        // Create a test string and add it to the error log as user detail data
        const char * l_pString = "This is a test string";
        ErrlUserDetailsString(l_pString).addToLog(errl);

        // create more and make sure that they get merged into 1 sub-section
        ErrlUserDetailsString("String test - string 2").addToLog(errl);

        ErrlUserDetailsString stringUD("String test - string 3");
        stringUD.addToLog(errl);

        // Add a little test for making strings on the fly
        {
            const int test_data = 0xfeedface;
            const char* format = "msg_respond() i/o error (transmit) 0x%x";
            const size_t output_size = strlen(format) + (sizeof(int) * 2) + 1;
            char output[output_size];
            snprintf(output, output_size, format, test_data);

            // Add msg_respond rc
            ERRORLOG::ErrlUserDetailsString(output).addToLog(errl);
        }

        // shove a lot of traces here, so that we test the truncate in the
        // write to PNOR
        errl->collectTrace("TARG", 1024);
        errl->collectTrace("TARG", 48);
        errl->collectTrace("TARG", 1024);
        errl->collectTrace("TARG", 48);
        errl->collectTrace("TARG", 1024);
        errl->collectTrace("TARG", 48);
        errl->collectTrace("TARG", 1024);
        errl->collectTrace("TARG", 48);
        errl->collectTrace("TARG", 1024);
        errl->collectTrace("TARG", 48);

        // commit the errorlog
        errlCommit(errl, CXXTEST_COMP_ID);
    }

    /**
     * @test testAttribute - Capture a String in an error log
     */
    void testAttribute(void)
    {
        errlHndl_t errl = NULL;

        TS_TRACE( "testAttribute errorlog user detail data and merge");
        /*@
        * @errortype
        * @severity ERRORLOG_SEV_INFORMATIONAL
        * @moduleid ERRL_USERDATA_TEST_MOD_ID
        * @reasoncode ERRL_TEST_ATTRIBUTE_UD
        * @userdata1 Test data 1
        * @userdata2 Test data 2
        * @devdesc  User Details unit test - create string user detail data.
        * @custdesc A problem occurred during the IPL of the system.
        */
        errl = new ErrlEntry(
                ERRL_SEV_INFORMATIONAL,
                ERRL_USERDATA_TEST_MOD_ID,
                ERRL_TEST_ATTRIBUTE_UD,
                0x0001002300450067,
                0x008900AB00CD00EF);

        using namespace TARGETING;

        // find a proc target
        PredicateCTM procChipFilter(CLASS_CHIP,TYPE_PROC);
        TargetRangeFilter pProc(
            targetService().begin(), targetService().end(),
            &procChipFilter);

        // find a membuf target
        PredicateCTM membufChipFilter(CLASS_CHIP,TYPE_MEMBUF);
        TargetRangeFilter pMembuf(
            targetService().begin(), targetService().end(),
            &membufChipFilter);

        // find a dimm target
        PredicateCTM dimmChipFilter(CLASS_NA,TYPE_DIMM);
        TargetRangeFilter pDimm(
            targetService().begin(), targetService().end(),
            &dimmChipFilter);

        const Target* c_target;
        c_target = *pProc;
        TS_TRACE( "testAttribute pProc %p", c_target);
        ErrlUserDetailsTarget(c_target).addToLog(errl);

        // all attributes
        ErrlUserDetailsAttribute(c_target).addToLog(errl);

        // HUID repeated for each addToLog()
        ErrlUserDetailsTarget(c_target).addToLog(errl);
        ErrlUserDetailsAttribute(c_target,ATTR_EC).addToLog(errl);
        ErrlUserDetailsAttribute(c_target,ATTR_CHIP_ID).addToLog(errl);

        // 1 HUID only
        ErrlUserDetailsTarget(c_target).addToLog(errl);
        ErrlUserDetailsAttribute(c_target,ATTR_HUID).addToLog(errl);

        // HUID only - not there
        ErrlUserDetailsAttribute(c_target,ATTR_SCRATCH_UINT8_1).addToLog(errl);

        // HUID only - write only
        ErrlUserDetailsAttribute(c_target,ATTR_DUMMY_WO).addToLog(errl);

        // HUID only - read only
        ErrlUserDetailsAttribute(c_target,ATTR_CLASS).addToLog(errl);

        //
        // one HUID then each attribute
        ErrlUserDetailsAttribute pProcEUDA(c_target,ATTR_CHIP_ID);
        pProcEUDA.addData(ATTR_EC);
        pProcEUDA.addData(ATTR_CHIP_ID);

        // skipped - not there
        pProcEUDA.addData(ATTR_SCRATCH_UINT8_1);

        // skipped - write only
        pProcEUDA.addData(ATTR_DUMMY_WO);

        // skipped - read only
        pProcEUDA.addData(ATTR_CLASS);

        // done - write it out
        pProcEUDA.addToLog(errl);


        if(*pMembuf != NULL)
        {
            c_target = *pMembuf;
            TS_TRACE( "testAttribute pMembuf %p", c_target);
            ErrlUserDetailsTarget(c_target).addToLog(errl);

            // all attributes
            ErrlUserDetailsAttribute(c_target).addToLog(errl);

            // one HUID then each attribute
            ErrlUserDetailsAttribute pMembufEUDA(c_target,ATTR_CHIP_ID);
            pMembufEUDA.addData(ATTR_EC);
            pMembufEUDA.addData(ATTR_CHIP_ID);
            pMembufEUDA.addData(ATTR_MSS_VOLT_VDDR_MILLIVOLTS);
            pMembufEUDA.addData(ATTR_MSS_FREQ);

            // skipped - not there
            pMembufEUDA.addData(ATTR_SCRATCH_UINT8_1);

            // skipped - write only
            pMembufEUDA.addData(ATTR_DUMMY_WO);

            // skipped - read only
            pMembufEUDA.addData(ATTR_CLASS);

            // done - write it out
            pMembufEUDA.addToLog(errl);
        }

        if(*pDimm != NULL)
        {
            c_target = *pDimm;
            TS_TRACE( "testAttribute pDimm %p", c_target);
            ErrlUserDetailsTarget(c_target).addToLog(errl);

            // all attributes
            ErrlUserDetailsAttribute(c_target).addToLog(errl);

            // one HUID then each attribute
            ErrlUserDetailsAttribute pDimmEUDA(c_target,ATTR_CHIP_ID);
            pDimmEUDA.addData(ATTR_EC);
            pDimmEUDA.addData(ATTR_CHIP_ID);
            pDimmEUDA.addData(ATTR_MSS_VOLT_VDDR_MILLIVOLTS);
            pDimmEUDA.addData(ATTR_MSS_FREQ);

            // skipped - not there
            pDimmEUDA.addData(ATTR_SCRATCH_UINT8_1);

            // skipped - write only
            pDimmEUDA.addData(ATTR_DUMMY_WO);

            // skipped - read only
            pDimmEUDA.addData(ATTR_CLASS);

            // done - write it out
            pDimmEUDA.addToLog(errl);
        }
#if 0
        // extended test
        uint32_t i = 0;
        for (TargetIterator target = targetService().begin();
            (i < 10) && (target != targetService().end());
            ++i, ++target)
        {
            TS_TRACE( "testAttribute %p", *target);
            const Target* c_target = *target;
            ErrlUserDetailsTarget(c_target).addToLog(errl);
            ErrlUserDetailsAttribute(c_target).addToLog(errl);
        }
#endif

        // commit the errorlog
        errlCommit(errl, CXXTEST_COMP_ID);
        TS_TRACE( "testAttribute done");
    } // testAttribute


    /**
     * @test testLogRegister - Capture a register in an error log
     */
    void testLogRegister(void)
    {
        errlHndl_t errl = NULL;

        TS_TRACE( "testLogRegister errorlog user detail data");
        /*@
        * @errortype
        * @severity ERRORLOG_SEV_INFORMATIONAL
        * @moduleid ERRL_USERDATA_TEST_MOD_ID
        * @reasoncode ERRL_TEST_LOGREGISTER_UD
        * @userdata1 Test data 1
        * @userdata2 Test data 2
        * @devdesc User Details unit test
        *          - create log register user detail data.
        * @custdesc A problem occurred during the IPL of the system.
        */
        errl = new ERRORLOG::ErrlEntry(
                ERRORLOG::ERRL_SEV_INFORMATIONAL,
                ERRL_USERDATA_TEST_MOD_ID,
                ERRL_TEST_LOGREGISTER_UD,
                0x008900AB00CD00EF,                   //  user1
                0x0001002300450067 );                 //  user2

        using namespace TARGETING;
        ErrlUserDetailsString("LogRegister test").addToLog(errl);

        // find a proc target
        PredicateCTM procChipFilter(CLASS_CHIP,TYPE_PROC);
        TargetRangeFilter pProc(
            targetService().begin(), targetService().end(),
            &procChipFilter);

        // find a membuf target
        PredicateCTM membufChipFilter(CLASS_CHIP,TYPE_MEMBUF);
        TargetRangeFilter pMembuf(
            targetService().begin(), targetService().end(),
            &membufChipFilter);

        // find a dimm target
        PredicateCTM dimmChipFilter(CLASS_NA,TYPE_DIMM);
        TargetRangeFilter pDimm(
            targetService().begin(), targetService().end(),
            &dimmChipFilter);

        Target* c_target;

        // first do a test w/ the special MASTER SENTINAL constant
        c_target = MASTER_PROCESSOR_CHIP_TARGET_SENTINEL;
        ErrlUserDetailsTarget(c_target).addToLog(errl);
        {
            ErrlUserDetailsLogRegister eudlr(c_target);
            eudlr.addData(DEVICE_XSCOM_ADDRESS(0x000F000Full));
            eudlr.addData(DEVICE_SCOM_ADDRESS(0x000F000Full));
            eudlr.addToLog(errl);
        }

        c_target = *pProc;
        ErrlUserDetailsTarget(c_target, "Target: pProc").addToLog(errl);

        // 1-shot way first - each will have HUID before register data
        ErrlUserDetailsLogRegister(c_target,
                    DEVICE_SCOM_ADDRESS(0x000F000Full)).addToLog(errl);
        ErrlUserDetailsLogRegister(c_target,
                    DEVICE_MVPD_ADDRESS(3,0)).addToLog(errl);
        // error:
        ErrlUserDetailsLogRegister(c_target,
                    DEVICE_FSI_ADDRESS(0x01028)).addToLog(errl);
        // can't do this - use the addData methodology for driverif.H addresses
        //ErrlUserDetailsLogRegister(c_target,
                    //DEVICE_FSISCOM_ADDRESS(0x000F000Full)).addToLog(errl);

        // more efficient - HUID then each register
        {
            ErrlUserDetailsLogRegister eudlr(c_target);
            eudlr.addData(DEVICE_SCOM_ADDRESS(0x000F000Full));
            eudlr.addData(DEVICE_MVPD_ADDRESS(3,0));
            // error:
            eudlr.addData(DEVICE_FSI_ADDRESS(0x01028));
            //TODO RTC: 123019 I2CM changes for P9
            //Need to uncomment this when this work is complete
//          eudlr.addData(DEVICE_I2C_ADDRESS(0,0,0xAC));
//          eudlr.addData(DEVICE_EEPROM_ADDRESS(0x0,0x0));
            eudlr.addToLog(errl);
        }

        // do the read first, then capture the data
        //  this mirrors the previous set of LogRegister calls at the
        //  top of this function, so the results should match..
        ErrlUserDetailsTarget(c_target).addToLog(errl);
        errlHndl_t errl_deviceRead;

        uint64_t reg1_data = 0;
        size_t reg1_size = sizeof(reg1_data);
        errl_deviceRead = DeviceFW::deviceRead(c_target,
                        &reg1_data, reg1_size,
                        DEVICE_SCOM_ADDRESS(0x000F000Full));

        if (errl_deviceRead != NULL)
        {
            TS_TRACE( "testLogRegister deviceRead return errl; deleting;");
            delete errl_deviceRead;
            reg1_size = 0;
        }
        ErrlUserDetailsLogRegister(c_target, &reg1_data, reg1_size,
                DEVICE_SCOM_ADDRESS(0x000F000Full)).addToLog(errl);
        uint64_t reg2_data = 0;
        size_t reg2_size = sizeof(reg2_data);
        errl_deviceRead = DeviceFW::deviceRead(c_target,
                                               &reg2_data, reg2_size,
                                               DEVICE_MVPD_ADDRESS(3,0));

        if (errl_deviceRead != NULL)
        {
            TS_TRACE( "testLogRegister deviceRead return errl; deleting;");
            delete errl_deviceRead;
            reg2_size = 0;
        }
        ErrlUserDetailsLogRegister(c_target, &reg2_data, reg2_size,
                                   DEVICE_MVPD_ADDRESS(3,0)).addToLog(errl);

        uint32_t reg3_data = 0;
        size_t reg3_size = sizeof(reg3_data);
        errl_deviceRead = DeviceFW::deviceRead(c_target,
                        &reg3_data, reg3_size,
                        DEVICE_FSI_ADDRESS(0x01028));

        if (errl_deviceRead != NULL)
        {
            TS_TRACE( "testLogRegister deviceRead return errl; deleting;");
            delete errl_deviceRead;
            reg3_size = 0;
        }
        else
        {   // we expect an error here
            TS_TRACE( "testLogRegister deviceRead DIDN'T return errl!");
        }
        ErrlUserDetailsLogRegister(c_target, &reg3_data, reg3_size,
                DEVICE_FSI_ADDRESS(0x01028)).addToLog(errl);

        // more efficient - HUID then each register
        {
            ErrlUserDetailsLogRegister eudlr(c_target);
            eudlr.addDataBuffer(&reg1_data, reg1_size,
                    DEVICE_SCOM_ADDRESS(0x000F000Full));
            eudlr.addDataBuffer(&reg2_data, reg2_size,
                    DEVICE_MVPD_ADDRESS(3,0));
             eudlr.addDataBuffer(&reg3_data, reg3_size,
                     DEVICE_FSI_ADDRESS(0x01028));
            eudlr.addToLog(errl);
        }

        // send some that aren't logged:
      //TODO RTC: 123019 I2CM changes for P9
      //Need to uncomment this when this work is complete
//         ErrlUserDetailsLogRegister(c_target,
//                 DEVICE_PRESENT_ADDRESS()).addToLog(errl);
        ErrlUserDetailsLogRegister(c_target,
                DEVICE_PNOR_ADDRESS(0, 0)).addToLog(errl);
        ErrlUserDetailsLogRegister(c_target,
                DEVICE_MBOX_ADDRESS(0)).addToLog(errl);


        if(*pMembuf != NULL)
        {
            c_target = *pMembuf;
            ErrlUserDetailsTarget(c_target, "Target: pMembuf").addToLog(errl);

            // HUID then each register
            {
                ErrlUserDetailsLogRegister eudlr(c_target);
                eudlr.addData(DEVICE_FSI_ADDRESS(0x01028));
                eudlr.addData(DEVICE_SCOM_ADDRESS(0x000F000Full));
                eudlr.addToLog(errl);
            }
        }
        if(*pDimm != NULL)
        {
            c_target = *pDimm;
            ErrlUserDetailsTarget(c_target, "Target: pDimm").addToLog(errl);

            // HUID then each register
            {
                ErrlUserDetailsLogRegister eudlr(c_target);
                eudlr.addData(DEVICE_SPD_ADDRESS(0));
                eudlr.addData(DEVICE_FSI_ADDRESS(0x01028));
                eudlr.addData(DEVICE_SCOM_ADDRESS(0x000F000Full));
                eudlr.addToLog(errl);
            }

            {
                ErrlUserDetailsLogRegister eudlr(c_target);
                eudlr.addData(DEVICE_FSISCOM_ADDRESS(0x01028));
                eudlr.addData(DEVICE_XSCOM_ADDRESS(0x000F000Full));
                eudlr.addToLog(errl);
            }

            // commit the errorlog
            errlCommit(errl, CXXTEST_COMP_ID);
            TS_TRACE( "testLogRegister errorlog user detail data - complete");
        }
    } // testLogRegister

};

#endif
OpenPOWER on IntegriCloud