summaryrefslogtreecommitdiffstats
path: root/src/usr/targeting/test/targetingtest.H
blob: bd8ffdb0eeef5613821280468b58ad2377f841e1 (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
#ifndef __TESTTARGETING_H
#define __TESTTARGETING_H

/**
 *  @file testtargeting.H
 *
 *  @brief All unit tests for the targeting infrastructure
 */

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

// STD
#include <stdio.h>
#include <sys/time.h>

// CXXTEST
#include <cxxtest/TestSuite.H>

// This component
#include <targeting/attributes.H>
#include <targeting/entitypath.H>
#include <targeting/target.H>
#include <targeting/targetservice.H>

class TargetingTestSuite: public CxxTest::TestSuite
{
    public:

        /**
         *  @brief Test the TargetService class (except debug cases)
         */
        void testTargetServiceClass()
        {
            nanosleep(1,0);
            TS_TRACE(ENTER_MRK "testTargetServiceClass" );

            using namespace TARGETING;

            TargetService& l_targetService = targetService();

            l_targetService.init();

            // Post init
            // Test: void masterProcChipTarget(
            //          TargetHandleList& o_masterProcChipTarget) const;

            Target* l_pMasterProcChipTargetHandle = NULL;
            (void) l_targetService.masterProcChipTargetHandle(
                l_pMasterProcChipTargetHandle);

            if (   l_pMasterProcChipTargetHandle
                == MASTER_PROCESSOR_CHIP_TARGET_SENTINEL)
            {
                TS_FAIL("Post init; master proc chip target handle should not "
                        "be the sentinel value");
            }

            if (l_pMasterProcChipTargetHandle == NULL)
            {
                TS_FAIL("Post init; master proc chip target handle should not "
                        "be the NULL value");
            }

            if (   l_pMasterProcChipTargetHandle->getAttr<ATTR_CLASS> ()
                != CLASS_CHIP)
            {
                TS_FAIL("Post init; master proc chip target handle was not of "
                        "chip class");
            }

            if (   l_pMasterProcChipTargetHandle->getAttr<ATTR_TYPE> ()
                != TYPE_PROC)
            {
                TS_FAIL("Post init; master proc chip target handle was not of "
                        "proc type");
            }

            // Post init
            // Test: void getTopLevelTarget(Target*& o_targetHandle) const;

            Target* l_pTopLevel = NULL;
            (void) l_targetService.getTopLevelTarget(l_pTopLevel);
            if (l_pTopLevel == NULL)
            {
                TS_FAIL("Top level handle was NULL when initialization "
                        "complete");
            }

            if (l_pTopLevel->getAttr<ATTR_CLASS> () != CLASS_SYS)
            {
                TS_FAIL("Post init; top level target class != CLASS_SYS");
            }

            // Post init
            // Test: void exists(
            //           const EntityPath& i_entityPath,
            //               bool&       o_exists) const;

            bool l_exists = false;
            (void) l_targetService.exists(
                l_pTopLevel->getAttr<ATTR_PHYS_PATH> (), l_exists);

            if (l_exists != true)
            {
                TS_FAIL("Expected top level target to exist");
            }

            // Post init
            // Test: Target* toTarget(
            //     const EntityPath& i_entityPath) const;

            Target* l_pInverseTarget = NULL;
            l_pInverseTarget = l_targetService.toTarget(
                l_pTopLevel->getAttr<ATTR_PHYS_PATH> ());

            if (l_pInverseTarget != l_pTopLevel)
            {
                TS_FAIL("Expected to get the original target");
            }

            // Post init
            // Test: void getAssociated(
            // const Target*           i_pTarget,
            //      ASSOCIATION_TYPE  i_type,
            //      RECURSION_LEVEL   i_recursionLevel,
            //      TargetHandleList& o_list) const;

            TargetHandleList l_list;
            (void) l_targetService.getAssociated(l_pTopLevel,
                TARGETING::TargetService::CHILD,
                TARGETING::TargetService::IMMEDIATE, l_list);
            if (!l_list.size())
            {
                TS_FAIL("Should have found some child elements" );
            }

            // Verify child of given target has a parent that is the original
            // target

            TargetHandleList l_parentList;
            (void) l_targetService.getAssociated(l_list[0],
                TARGETING::TargetService::PARENT,
                TARGETING::TargetService::IMMEDIATE, l_parentList);

            if (l_parentList.size() != 1)
            {
                TS_FAIL("Should have found a parent element" );
            }

            if (l_parentList[0] != l_pTopLevel)
            {
                TS_FAIL("Parent handle should have matched original target "
                        "handle" );
            }

            (void) l_targetService.getAssociated(l_pTopLevel,
                TARGETING::TargetService::CHILD_BY_AFFINITY,
                TARGETING::TargetService::IMMEDIATE, l_list);

            if (!l_list.size())
            {
                TS_FAIL("Should have found some child elements" );
            }

            (void) l_targetService.getAssociated(l_pTopLevel,
                TARGETING::TargetService::CHILD_BY_AFFINITY,
                TARGETING::TargetService::ALL, l_list);

            if (!l_list.size())
            {
                TS_FAIL("Should have found more child elements" );
            }

            l_targetService.dump();

            TS_TRACE(EXIT_MRK "testTargetServiceClass" );
        }

        /**
         *  @test Tests the EntityPath class (except debug cases)
         */
        void testEntityPathClass(void)
        {
            TS_TRACE(ENTER_MRK "testEntityPathClass" );

            using namespace TARGETING;

            EntityPath l_defaultPath;
            if(l_defaultPath.size() != 0)
            {
                TS_FAIL("Default entity path's size was not 0");
            }

            if(l_defaultPath.type() != EntityPath::PATH_NA)
            {
                TS_FAIL("Default entity path's type was not PATH_NA");
            }

            EntityPath l_nonDefaultPath(EntityPath::PATH_PHYSICAL);
            if(l_nonDefaultPath.size() != 0)
            {
                TS_FAIL("Non-default entity path's size was not 0");
            }

            if(l_nonDefaultPath.type() != EntityPath::PATH_PHYSICAL)
            {
                TS_FAIL("Non-default entity path's type was not "
                        "EntityPath::PATH_PHYSICAL");
            }

            l_defaultPath.setType(EntityPath::PATH_AFFINITY);
            if(l_defaultPath.type() != EntityPath::PATH_AFFINITY)
            {
                TS_FAIL("Default entity path's type was not "
                        "EntityPath::PATH_AFFINITY after setting");
            }

            l_defaultPath.setType(EntityPath::PATH_PHYSICAL);
            if(!(l_defaultPath == l_nonDefaultPath))
            {
                TS_FAIL("Default entity path should have been equal to "
                        "the non-default entity path");
            }

            if(!l_defaultPath.equals(l_nonDefaultPath,0))
            {
                TS_FAIL("Default entity path should have been equal to "
                        "the non-default entity path (equals API)");
            }

            l_defaultPath.addLast(TYPE_PROC,0);
            if(l_defaultPath == l_nonDefaultPath)
            {
                TS_FAIL("Default entity path should NOT have been equal to "
                        "the non-default entity path");
            }

            if(l_defaultPath.equals(l_nonDefaultPath,1))
            {
                TS_FAIL("Default entity path should NOT have been equal to "
                        "the non-default entity path (equals API, comparing 1 "
                        "element)");
            }

            if(l_defaultPath.size() != 1)
            {
                TS_FAIL("Default entity path should have had one path element"
                        "after adding PROC0");
            }

            l_nonDefaultPath.addLast(TYPE_PROC,0);
            if(! (l_defaultPath == l_nonDefaultPath) )
            {
                TS_FAIL("Default entity path should have been equal to "
                        "the non-default entity path since they now"
                        "both have the same 1 path element");
            }

            l_defaultPath.addLast(TYPE_MBA,1).addLast(TYPE_MBS,2);
            if(l_defaultPath.size() != 3)
            {
                TS_FAIL("Default entity path should have had two path elements"
                        "after adding MBA1 and MBS2");
            }

            if( (l_defaultPath[0].type != TYPE_PROC)
                || (l_defaultPath[0].instance != 0)
                || (l_defaultPath[1].type != TYPE_MBA)
                || (l_defaultPath[1].instance != 1)
                || (l_defaultPath[2].type != TYPE_MBS)
                || (l_defaultPath[2].instance != 2))
            {
                TS_FAIL("Default entity path should have had correct 3 path "
                        "elements");
            }

            l_defaultPath.removeLast();
            if(l_defaultPath.size() != 2)
            {
                TS_FAIL("Default entity path should have had two path elements"
                        "after removing MBS2");
            }

            if( (l_defaultPath[0].type != TYPE_PROC)
                || (l_defaultPath[0].instance != 0)
                || (l_defaultPath[1].type != TYPE_MBA)
                || (l_defaultPath[1].instance != 1))
            {
                TS_FAIL("Default entity path should have had correct 2 path "
                        "elements");
            }

            l_nonDefaultPath.addLast(TYPE_MBA,1).addLast(TYPE_MBS,2);

            // Default now has proc/mba/
            // Non-default now has proc/mba/mbs
            if(l_defaultPath == l_nonDefaultPath)
            {
                TS_FAIL("Default entity path should NOT have been equal to "
                        "the non-default entity path since they now"
                        "have different number of path elements");
            }

            if( !l_defaultPath.equals(l_nonDefaultPath,2) )
            {
                TS_FAIL("Default entity path should have been equal to "
                        "the non-default entity path since they have the same"
                        "first two path elements");
            }

            l_defaultPath.removeLast().removeLast();
            if(l_defaultPath.size() != 0)
            {
                TS_FAIL("Default entity path should have had no path element"
                        "after removing MBA1 and PROC0");
            }

            TargetService& l_targetService = targetService();
            l_targetService.init();

            EntityPath l_realPath(EntityPath::PATH_PHYSICAL);
            l_realPath.addLast(TYPE_SYS,0).addLast(TYPE_NODE,0)
                .addLast(TYPE_PROC,0);

            Target* l_pTarget = l_realPath.operator->();
            if(l_pTarget == NULL)
            {
                TS_FAIL("Real entity path should have mapped to an existing "
                        "target");
            }

            EntityPath l_path(EntityPath::PATH_PHYSICAL);
            l_path.addLast(TYPE_SYS,0);
            EntityPath l_changedPath = l_path.copyRemoveLast();
            if(   (l_changedPath.size() != 0)
               || (l_path.size() != 1))
            {
                TS_FAIL("Const entity path should not have been altered in "
                        "const add test");
            }

            l_changedPath = l_path.copyAddLast(TYPE_NODE,0);
            if(   (l_changedPath.size() != 2)
               || (l_path.size() != 1))
            {
                TS_FAIL("Const entity path should not have been altered "
                        "in const add test");
            }

            TS_TRACE(EXIT_MRK "testEntityPathClass" );
        }

        /**
         *  @test Tests the EntityPath class (except debug cases)
         */
        void testTargetClass(void)
        {
            TS_TRACE(ENTER_MRK "testTargetClass" );

            using namespace TARGETING;
            TargetService& l_targetService = targetService();
            l_targetService.init();

            EntityPath l_realPath(EntityPath::PATH_PHYSICAL);
            l_realPath.addLast(TYPE_SYS,0).addLast(TYPE_NODE,0)
                .addLast(TYPE_PROC,0);
            l_realPath.dump();

            Target* l_pTarget = l_realPath.operator->();
            if(l_pTarget == NULL)
            {
                TS_FAIL("Failed to convert entity path to initial target");
            }

            CLASS l_class = l_pTarget->getAttr<ATTR_CLASS>();
            if(l_class != CLASS_CHIP)
            {
                TS_FAIL("Failed to get the class attribute");
            }

            l_class = CLASS_NA;
            if( !l_pTarget->tryGetAttr<ATTR_CLASS>(l_class) )
            {
                TS_FAIL("Failed to get the class attribute");
            }

            if(l_class != CLASS_CHIP)
            {
                TS_FAIL("Failed to try/get the class attribute");
            }

            attrToString<ATTR_CLASS>(l_class);

            uint8_t l_scom = 0;
            if( l_pTarget->tryGetAttr<ATTR_DUMMY_RO>(l_scom) )
            {
                TS_FAIL("ATTR_DUMMY_RO attribute should not have been available "
                        "to read");
            }

            if(l_scom != 0)
            {
                TS_FAIL("Failed ! try/get should not have set the SCOM attribute");
            }

            l_scom = 5;
            if( l_pTarget->trySetAttr<ATTR_DUMMY_WO>(l_scom) )
            {
                TS_FAIL("ATTR_DUMMY_WO attribute should not have been available "
                        "to write");
            }

            if(l_scom != 5)
            {
                TS_FAIL("SCOM attribute should not have been altered in the failed "
                        "write");
            }

            uint8_t l_wo = 6;
            if( !l_pTarget->trySetAttr<ATTR_DUMMY_RW>(l_wo) )
            {
                TS_FAIL("ATTR_DUMMY_RW should have been available for write");
            }

            if(l_wo != 6)
            {
                TS_FAIL("ATTR_DUMMY_RW local attribute should not have been "
                        "altered in the successful write");
            }

            uint8_t l_read = l_pTarget->getAttr<ATTR_DUMMY_RW>();
            if(l_read != l_wo)
            {
                TS_FAIL("Failed to read back the correct ATTR_DUMMY_RW");
            }

            uint8_t l_setWo = 9;
            l_pTarget->setAttr<ATTR_DUMMY_RW>(l_setWo);
            if(l_setWo != 9)
            {
                TS_FAIL("ATTR_DUMMY_RW local attribute should not have been "
                        "altered in the successful setAttr");
            }

            uint8_t l_setWoVerify = l_pTarget->getAttr<ATTR_DUMMY_RW>();
            if(l_setWoVerify != l_setWo)
            {
                TS_FAIL("ATTR_DUMMY_RW read should have matched prior write");
            }

            TS_TRACE(EXIT_MRK "testTargetClass" );
        }
};

#endif // End __TESTTARGETING_H
OpenPOWER on IntegriCloud