summaryrefslogtreecommitdiffstats
path: root/src/usr/hwas/test/hwasSysAvailSvcTest.H
blob: 0e5839ce2f13beb87afdfd9340093e751fef9d28 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwas/test/hwasSysAvailSvcTest.H $                     */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2013                   */
/*                                                                        */
/* 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 otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#ifndef _HWASSYSAVAILTEST_H
#define _HWASSYSAVAILTEST_H

/**
 *  @file hwasSysAvailTest.H
 *
 *  @brief Unit tests for HWAS System Availability Test.
 */

//******************************************************************************
// Includes
//******************************************************************************

// CXXTEST
#include <cxxtest/TestSuite.H>
#include <errl/errlmanager.H>
#include <targeting/common/targetservice.H>
#include <hwas/common/hwas_reasoncodes.H>
#include <hwas/common/hwasCommon.H>
#include <targeting/common/utilFilter.H>


//  $$  make sure this is disabled before checking in!!
#define DISABLE_UNIT_TESTS    1
//$$#define DISABLE_UNIT_TESTS    0

using   namespace   TARGETING;

class HwasSysAvailTest: public CxxTest::TestSuite
{
public:

    enum    TargetState_t  {
        RESTORE         =   0,
        SET_NONFUNC     =   1,
    };


    /*
     *  @brief  Set all or most of the targets in the target list to
     *      i_state ==  SET_NONFUNC :   non-functional
     *      i_state ==  RESTORE     :   back to its' original state
     *  Stores the original State in i_origStates; it is assumed that this
     *  will be called first with SET_NONFUNC to fill in i_origStates.
     *  @param  i_state         - SET_NONFUNC or RESTORE
     *  @param  i_targetHList   -   TargetHandleList of targets to work on
     *  @param  i_origStatew    -   array of HWasStates to store the original
     *                              state in.
     *  @param  l_keep          -   number of states to keep (i.e. leave alone)
     *                              when running SET_NONFUNC
     *
     **/

    void    setTargetStates( TargetState_t          i_state,
                             TargetHandleList     & i_targetHList,
                             TARGETING::HwasState   *i_origStates,
                             uint8_t                l_keep=0
                             )
    {

        TARGETING::HwasState    l_fakeState;

        for( uint8_t i = l_keep;
             i < i_targetHList.size();
             i++ )
        {
            TARGETING::Target * l_target  =   i_targetHList[i];

            if ( i_state  == SET_NONFUNC  )
            {
                //  set nonfunctional
                i_origStates[i] =
                    l_target->getAttr<TARGETING::ATTR_HWAS_STATE>();
                l_fakeState =   i_origStates[i];
                TS_TRACE( "setTargetStates: HwasState fakeState: "
                          "deconf=0x%x,PO=0x%x,pres=0x%x,func=0x%x,dumpf=0x%x",
                          l_fakeState.deconfiguredByEid,
                          l_fakeState.poweredOn,
                          l_fakeState.present,
                          l_fakeState.functional,
                          l_fakeState.dumpfunctional
                          );

                l_fakeState.functional  =   0 ;

                l_target->setAttr<TARGETING::ATTR_HWAS_STATE>(l_fakeState);
            }
            else
            {
                // Restore to original state.
                l_target->setAttr<TARGETING::ATTR_HWAS_STATE>(i_origStates[i]);

            }
        }   //  endfor
    }

    /**
     *  @brief mark all cores nonfunctional and then call checkMinimumHardware()
     */
    void testCheckMinimumHardwareCore()
    {
#if DISABLE_UNIT_TESTS

        //  NOTE:  These tests mark targets nonfunctional and then
        //  restore them.  Since all the unit tests run in parallel, this
        //  may cause other tests to fail.
        //  Do not leave this test enabled for normal operations.
        TS_TRACE(INFO_MRK "SKIPPING:  other tests could be affected.");
#else
        errlHndl_t  l_errl  =   NULL;
        TS_TRACE(INFO_MRK "testCheckMinimumHardwareCore");

        TargetHandleList l_cores;
        getAllChiplets(l_cores, TYPE_CORE, true );
        TS_TRACE( "testCheckMinimumHardwareCore: %d functional cores",
                  l_cores.size() );
        TARGETING::HwasState    l_origStates[ l_cores.size() ]  ;

        TS_TRACE( "testCheckMinimumHardwareCore: set cores nonfunctional");
        setTargetStates( SET_NONFUNC, l_cores, &l_origStates[0]  );

        TS_TRACE( "testCheckMinimumHardwareCore: check for minimum hardware" );
        l_errl  =   HWAS::checkMinimumHardware();
        if ( l_errl )
        {
            //  got an errorlog, no cores
            TS_TRACE( "testCheckMinimumHardwareCore: PASSED");
            errlCommit( l_errl, HWAS_COMP_ID );
        }
        else
        {
            //  no errorlog, bad news
            TS_FAIL( "testCheckMinimumHardwareCore:  FAILED, no errlog" );
        }

        TS_TRACE( "testCheckMinimumHardwareCore: restore original states");
        setTargetStates( RESTORE, l_cores, &(l_origStates[0])  );

#endif
    }


    /**
     *  @brief mark all dimms nonfunctional and then call checkMinimumHardware()
     */
    void testCheckMinimumHardwareDimm()
    {
#if DISABLE_UNIT_TESTS
        //  NOTE:  These tests mark targets nonfunctional and then
        //  restore them.  Since all the unit tests run in parallel, this
        //  may cause other tests to fail.
        //  Do not leave this test enabled for normal operations.
        TS_TRACE(INFO_MRK "SKIPPING:  other tests could be affected.");
#else
        errlHndl_t  l_errl  =   NULL;
        TS_TRACE(INFO_MRK "testCheckMinimumHardwareDimm");

        //  check for functional dimms
        TargetHandleList l_dimms;
        getAllLogicalCards(l_dimms, TYPE_DIMM, true );
        TS_TRACE( "testCheckMinimumHardwareDimm: %d functional dimms",
                  l_dimms.size() );

        TARGETING::HwasState    l_origStates[ l_dimms.size() ]  ;

        setTargetStates( SET_NONFUNC, l_dimms, &(l_origStates[0])  );

        TS_TRACE( "testCheckMinimumHardwareDimm: check for minimum hardware" );
        l_errl  =   HWAS::checkMinimumHardware();
        if ( l_errl )
        {
            //  got an errorlog, no dimms
            TS_TRACE( "testCheckMinimumHardwareDimm: PASSED");
            errlCommit( l_errl, HWAS_COMP_ID );
        }
        else
        {
            //  no errorlog, bad news
            TS_FAIL( "testCheckMinimumHardwareDimm:  FAILED, no errlog" );
        }

        setTargetStates( RESTORE, l_dimms, &(l_origStates[0])  );

#endif
    }


    /**
     *  @brief mark all cores AND dimms nonfunctional and
     *      then call checkMinimumHardware()
     *  Test should fail and we should have 2 errorlogs with a common plid.
     */
    void testCheckMinimumHardwareBoth()
    {
#if DISABLE_UNIT_TESTS
        //  NOTE:  These tests mark targets  nonfunctional and then
        //  restore them.  Since all the unit tests run in parallel, this
        //  may cause other tests to fail.
        //  Do not leave this test enabled for normal operations.
        TS_TRACE(INFO_MRK "SKIPPING:  other tests could be affected.");
#else
        errlHndl_t  l_errl  =   NULL;
        TS_TRACE(INFO_MRK "testCheckMinimumHardwareBoth");

        //  set all cores nonfunctional
        TargetHandleList l_cores;
        getAllChiplets(l_cores, TYPE_CORE, true );
        TS_TRACE( "testCheckMinimumHardwareBoth: %d functional cores",
                  l_cores.size() );
        TARGETING::HwasState    l_origCoreStates[ l_cores.size() ]  ;
        TS_TRACE( "testCheckMinimumHardwareBoth: set cores nonfunctional");
        setTargetStates( SET_NONFUNC, l_cores, &l_origCoreStates[0]  );

        //  set all dimms nonfunctional
        TargetHandleList l_dimms;
        getAllLogicalCards(l_dimms, TYPE_DIMM, true );
        TS_TRACE( "testCheckMinimumHardwareBoth: %d functional dimms",
                  l_dimms.size() );
        TARGETING::HwasState    l_origDimmStates[ l_dimms.size() ]  ;
        TS_TRACE( "testCheckMinimumHardwareBoth: set dimms nonfunctional");
        setTargetStates( SET_NONFUNC, l_dimms, &(l_origDimmStates[0])  );

        TS_TRACE( "testCheckMinimumHardwareBoth: check for minimum hardware" );
        l_errl  =   HWAS::checkMinimumHardware();
        if ( l_errl )
        {
            //  got an errorlog, this is good.  Commit the errorlog.
            //  There should be 2 errorlogs with a common plid.
            TS_TRACE( "testCheckMinimumHardwareBoth: PASSED");
            errlCommit( l_errl, HWAS_COMP_ID );
        }
        else
        {
            //  no errorlog, bad news
            TS_FAIL( "testCheckMinimumHardwareBoth:  FAILED, no errorlog." );
        }

        //  restore everything to normal.
        setTargetStates( RESTORE, l_cores, &(l_origCoreStates[0])  );
        setTargetStates( RESTORE, l_dimms, &(l_origDimmStates[0])  );

#endif
    }


    /**
     *  @brief mark all dimms (except 1) nonfunctional and
     *      then call checkMinimumHardware()
     *  Test should pass.
     */
    void testCheckMinimumHardwareOneDimm()
    {
#if DISABLE_UNIT_TESTS
        //  NOTE:  These tests mark targets nonfunctional and then
        //  restore them.  Since all the unit tests run in parallel, this
        //  may cause other tests to fail.
        //  Do not leave this test enabled for normal operations.
        TS_TRACE(INFO_MRK "SKIPPING:  other tests could be affected.");
#else
        errlHndl_t  l_errl  =   NULL;
        TS_TRACE(INFO_MRK "testCheckMinimumHardwareOneDimm");

        //  check for functional dimms
        TargetHandleList l_dimms;
        getAllLogicalCards(l_dimms, TYPE_DIMM, true );
        TS_TRACE( "testCheckMinimumHardwareOneDimm: %d functional dimms",
                  l_dimms.size() );

        TARGETING::HwasState    l_origStates[ l_dimms.size() ]  ;

        setTargetStates( SET_NONFUNC, l_dimms, &(l_origStates[0]), 1  );

        TS_TRACE( "testCheckMinimumHardwareOneDimm: "
                  "check for minimum hardware" );
        l_errl  =   HWAS::checkMinimumHardware();
        if ( l_errl )
        {
            //  got an errorlog, bad news
            TS_FAIL( "testCheckMinimumHardwareOneDimm:  FAILED " );
            errlCommit( l_errl, HWAS_COMP_ID );
        }
        else
        {
            //  No errorlog, this is good.
            TS_TRACE( "testCheckMinimumHardwareOneDimm: PASSED");
        }

        setTargetStates( RESTORE, l_dimms, &(l_origStates[0]), 1  );

#endif
    }

};  // end class

#endif
OpenPOWER on IntegriCloud