summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/mdia/test/mdiatestsm.H
blob: 11e675029f0bbf82f01949dc3b8617dd30433a94 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/mdia/test/mdiatestsm.H $                         */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,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 __TEST_MDIATESTSM_H
#define __TEST_MDIATESTSM_H

/**
 * @file mdiatestsm.H
 * @brief state machine unit test
 */

#include <builtins.h>
#include <cxxtest/TestSuite.H>
#include "../mdiasm.H"
#include "../mdiasmimpl.H"
#include <diag/mdia/mdiamevent.H>
#include <targeting/common/utilFilter.H>
#include "../mdiatrace.H"
#include "../mdiamonitor.H"
#include "../mdiafwd.H"
#include <sys/time.h>
#include "mdiafakesm.H"

using namespace MDIA;
using namespace TARGETING;

class MdiaSmTest : public CxxTest::TestSuite
{
    private:

        void getTargets(uint64_t i_count, TARGETING::TargetHandleList & o_list)
        {
            TargetHandleList tmp;
            TARGETING::getAllChiplets(tmp, TYPE_MBA);

            TargetHandleList::iterator it = tmp.end();

            while(i_count-- != 0 && it-- != tmp.begin())
            {
                o_list.push_back(*it);
            }
        }

        static void* startSm(void * i_sm)
        {
            static_cast<MDIA::StateMachine *>(i_sm)->start();
            return NULL;
        }

    public:

        void testSmReset(void)
        {
            using namespace MDIA;
            using namespace TARGETING;

            TS_TRACE(ENTER_MRK "testSmReset");

            StateMachine s;

            // should be able to call reset

            s.reset();

            if(!s.iv_workFlowProperties.empty())
            {
                TS_FAIL("unexpected workflow properties found (1)");
            }

            // should be able to call reset again

            s.reset();

            if(!s.iv_workFlowProperties.empty())
            {
                TS_FAIL("unexpected workflow properties found (2)");
            }

            // should be able to call reset multiple times

            s.reset();

            if(!s.iv_workFlowProperties.empty())
            {
                TS_FAIL("unexpected workflow properties found (3)");
            }

            WorkFlowAssocMap wkFlentries;
            s.setup(wkFlentries);

            // should be able to call reset after calling setup, with
            // empty list

            s.reset();

            if(!s.iv_workFlowProperties.empty())
            {
                TS_FAIL("unexpected workflow properties found (4)");
            }

            // should be able to call reset after calling setup, with
            // list

            TargetHandleList targets;
            getTargets(2, targets);

            wkFlentries[targets[0]] = wkFlentries[targets[1]];

            s.setup(wkFlentries);

            s.reset();

            if(!s.iv_workFlowProperties.empty())
            {
                TS_FAIL("unexpected workflow properties found (5)");
            }

            TS_TRACE(EXIT_MRK "testSmReset");
        }

        void testSmSetup(void)
        {
            using namespace MDIA;
            using namespace TARGETING;

            TS_TRACE(ENTER_MRK "testSmSetup");

            StateMachine s;

            // should be able to call setup with empty map entries

            WorkFlowAssocMap wkFlentries;

            s.setup(wkFlentries);

            if(s.iv_workFlowProperties.size() != wkFlentries.size())
            {
                TS_FAIL("unexpected number of workflow properties (1)");
            }

            s.reset();

            if(!s.iv_workFlowProperties.empty())
            {
                TS_FAIL("unexpected number of workflow properties (2)");
            }

            // should be able to call setup with a list

            TargetHandleList targets;
            getTargets(2, targets);

            wkFlentries[targets[0]] = wkFlentries[targets[1]];

            s.setup(wkFlentries);

            uint64_t idx = s.iv_workFlowProperties.size();

            while(idx-- != 0)
            {
                TargetHandle_t t = getTarget(*s.iv_workFlowProperties[idx]);

                WorkFlowAssoc assoc = wkFlentries.find(t);

                if(static_cast<const WorkFlowAssocMap &>(wkFlentries).end()
                    == assoc)
                {
                    TS_FAIL("unexpected target found in workflow properties");
                }

                if(s.iv_workFlowProperties[idx]->status != IN_PROGRESS)
                {
                    TS_FAIL("unexpected status found in workflow properties");
                }

                if(s.iv_workFlowProperties[idx]->workItem
                    != getWorkFlow(assoc).begin())
                {
                    TS_FAIL("unexpected work item found in"
                            " workflow properties");
                }
            }

            TS_TRACE(EXIT_MRK "testSmSetup");
        }

        void testSmWait(void)
        {
            using namespace MDIA;
            using namespace TARGETING;

            TS_TRACE(ENTER_MRK "testSmWait");

            // start & wait without calling setup shouldn't hang

            int status;
            StateMachine s;

            tid_t tid = task_create(&startSm, &s);

            if(tid < 0)
            {
                TS_FAIL("child task not started (1)");
            }

            s.wait();

            task_wait_tid(tid, &status, 0);

            if(status != TASK_STATUS_EXITED_CLEAN)
            {
                TS_FAIL("child task crashed (1)");
            }

            // start & wait with empty list shouldn't hang

            WorkFlowAssocMap wkFlentries;

            s.setup(wkFlentries);

            tid = task_create(&startSm, &s);

            if(tid < 0)
            {
                TS_FAIL("child task not started (2)");
            }

            s.wait();

            task_wait_tid(tid, &status, 0);

            if(status != TASK_STATUS_EXITED_CLEAN)
            {
                TS_FAIL("child task crashed (2)");
            }

            // start & wait with list shouldn't hang

            TargetHandleList targets;
            getTargets(2, targets);

            wkFlentries[targets[0]] = wkFlentries[targets[1]];

            s.setup(wkFlentries);

            tid = task_create(&startSm, &s);

            if(tid < 0)
            {
                TS_FAIL("child task not started (3)");
            }

            s.wait();

            task_wait_tid(tid, &status, 0);

            if(status != TASK_STATUS_EXITED_CLEAN)
            {
                TS_FAIL("child task crashed (3)");
            }

            TS_TRACE(ENTER_MRK "testSmWait");
        }

        void testSmWorkItemIsAsync(void)
        {
            using namespace MDIA;
            using namespace TARGETING;

            TS_TRACE(ENTER_MRK "testSmWorkItemIsAsync");

            static const struct Checks
            {
                Checks(WorkFlowPhase i_workItem, bool i_expected) :
                    workItem(i_workItem), expected(i_expected)
                {

                }

                WorkFlowPhase workItem;
                bool expected;

            } checks[] = {
                Checks(RESTORE_DRAM_REPAIRS, false),
                Checks(DUMMY_SYNC_PHASE, false),
                Checks(DUMMY_ASYNC_PHASE, true),
                Checks(START_PATTERN_0, true),
                Checks(START_PATTERN_1, true),
                Checks(START_PATTERN_2, true),
                Checks(START_PATTERN_3, true),
                Checks(START_PATTERN_4, true),
                Checks(START_PATTERN_5, true),
                Checks(START_PATTERN_6, true),
                Checks(START_PATTERN_7, true),
                Checks(START_SCRUB, true)
            };

            StateMachine sm;
            WorkFlowAssocMap wkFlentries;
            TargetHandleList targets;

            getTargets(1, targets);

            const Checks * it = checks + sizeof(checks)/sizeof(*checks);
            while(it-- != checks)
            {
                sm.reset();
                wkFlentries.clear();
                wkFlentries[targets[0]].push_back(it->workItem);

                sm.setup(wkFlentries);
                WorkFlowProperties & tmp = *sm.iv_workFlowProperties.front();

                if(StateMachine::workItemIsAsync(tmp) != it->expected)
                {
                    TS_FAIL("unexpected result from " 
                            "StateMachine::workItemIsAsync: %d", it->workItem);
                }
            }

            TS_TRACE(EXIT_MRK "testSmWorkItemIsAsync");
        }

        void testSmAllWorkFlowsComplete(void)
        {
            using namespace MDIA;
            using namespace TARGETING;

            TS_TRACE(ENTER_MRK "testSmAllWorkFlowsComplete");

            StateMachine s;

            // empty state machine should indicate all workflows complete

            if(!s.allWorkFlowsComplete())
            {
                TS_FAIL("unexpected result from "
                        "StateMachine::allWorkFlowsComplete (1)");
            }

            s.reset();

            // empty list should indicate all workflows complete

            WorkFlowAssocMap wkFlentries;

            s.setup(wkFlentries);

            if(!s.allWorkFlowsComplete())
            {
                TS_FAIL("unexpected result from "
                        "StateMachine::allWorkFlowsComplete (2)");
            }

            s.reset();

            // list with empty workflow should indicate all workflows complete
            TargetHandleList targets;
            getTargets(2, targets);

            wkFlentries[targets[0]] = wkFlentries[targets[0]];

            s.setup(wkFlentries);

            if(s.allWorkFlowsComplete())
            {
                TS_FAIL("unexpected result from "
                        "StateMachine::allWorkFlowsComplete (3)");
            }

            s.reset();

            // list with non-empty workflow should not indicate
            // all workflows complete

            wkFlentries[targets[0]].push_back(RESTORE_DRAM_REPAIRS);

            s.setup(wkFlentries);

            if(s.allWorkFlowsComplete())
            {
                TS_FAIL("unexpected result from "
                        "StateMachine::allWorkFlowsComplete (4)");
            }

            // single entry with FAILED status should indicate
            // all workflows complete

            s.iv_workFlowProperties.front()->status = FAILED;

            if(!s.allWorkFlowsComplete())
            {
                TS_FAIL("unexpected result from "
                        "StateMachine::allWorkFlowsComplete (5)");
            }

            // single entry with TIMED_OUT status should indicate
            // all workflows complete

            s.iv_workFlowProperties.front()->status = COMMAND_TIMED_OUT;

            if(!s.allWorkFlowsComplete())
            {
                TS_FAIL("unexpected result from "
                        "StateMachine::allWorkFlowsComplete (6)");
            }

            // single entry with COMPLETE status should indicate
            // all workflows complete

            s.iv_workFlowProperties.front()->status = COMPLETE;

            if(!s.allWorkFlowsComplete())
            {
                TS_FAIL("unexpected result from "
                        "StateMachine::allWorkFlowsComplete (7)");
            }

            s.reset();

            // list with two non-empty workflow should not indicate
            // all workflows complete

            wkFlentries[targets[0]] = wkFlentries[targets[1]];

            wkFlentries[targets[0]].push_back(RESTORE_DRAM_REPAIRS);
            wkFlentries[targets[1]].push_back(RESTORE_DRAM_REPAIRS);

            s.setup(wkFlentries);

            if(s.allWorkFlowsComplete())
            {
                TS_FAIL("unexpected result from "
                        "StateMachine::allWorkFlowsComplete (8)");
            }

            // single entry with FAILED status should not indicate
            // not workflows complete

            s.iv_workFlowProperties.front()->status = FAILED;

            if(s.allWorkFlowsComplete())
            {
                TS_FAIL("unexpected result from "
                        "StateMachine::allWorkFlowsComplete (9)");
            }

            // single entry with TIMED_OUT status should not
            // indicate all workflows complete

            s.iv_workFlowProperties.front()->status = COMMAND_TIMED_OUT;

            if(s.allWorkFlowsComplete())
            {
                TS_FAIL("unexpected result from "
                        "StateMachine::allWorkFlowsComplete (10)");
            }

            // single entry with COMPLETE status should not indicate
            // all workflows complete

            s.iv_workFlowProperties.front()->status = COMPLETE;

            if(s.allWorkFlowsComplete())
            {
                TS_FAIL("unexpected result from "
                        "StateMachine::allWorkFlowsComplete (11)");
            }

            TS_TRACE(EXIT_MRK "testSmAllWorkFlowsComplete");
        }

        void testSmExecuteWorkItem(void)
        {
            using namespace MDIA;
            using namespace TARGETING;

            TS_TRACE(ENTER_MRK "testSmExecuteWorkItem");

            StateMachine sm;
            WorkFlowAssocMap list;
            TargetHandleList targets;

            getTargets(1, targets);

            list[targets[0]].push_back(DUMMY_ASYNC_PHASE);
            sm.setup(list);

            WorkFlowProperties * tmp = sm.iv_workFlowProperties.front();

            WorkFlow::const_iterator sit = tmp->workItem;

            sm.executeWorkItem(tmp);

            // should not have advanced the work item for async

            if(sit != tmp->workItem)
            {
                TS_FAIL("unexpected next work item after "
                         "executing work item (1)");
            }

            if(tmp->status != IN_PROGRESS)
            {
                TS_FAIL("unexpected status after executing work item (1)");
            }

            sm.reset();
            list.clear();

            list[targets[0]].push_back(DUMMY_SYNC_PHASE);
            sm.setup(list);

            tmp = sm.iv_workFlowProperties.front();

            sit = tmp->workItem;

            sm.executeWorkItem(tmp);

            // should have advanced the work item for sync

            if(std::distance(sit, tmp->workItem) != 1)
            {
                TS_FAIL("unexpected next work item after "
                        "executing work item (2)");
            }

            if(tmp->status != COMPLETE)
            {
                TS_FAIL("unexpected status after executing work item (2)");
            }

            TS_TRACE(EXIT_MRK "testSmExecuteWorkItem");
        }

        void testSmRun(void)
        {
            using namespace MDIA;
            using namespace TARGETING;

            TS_TRACE(ENTER_MRK "testSmRun");

            StateMachine s;

            // run with empty list

            WorkFlowAssocMap wkFlentries;
            errlHndl_t err = s.run(wkFlentries);

            if(err)
            {
                TS_FAIL("StateMachine::run(1) failed unexpectedly");
            }

            err = s.run(wkFlentries);

            if(err)
            {
                TS_FAIL("StateMachine::run(2) failed unexpectedly");
            }

            // should be able to run again

            err = s.run(wkFlentries);

            if(err)
            {
                TS_FAIL("StateMachine::run(3) failed unexpectedly");
            }

            // run again, with a list but no workflow

            TargetHandleList targets;
            getTargets(2, targets);

            wkFlentries[targets[0]] = wkFlentries[targets[0]];

            err = s.run(wkFlentries);

            if(err)
            {
                TS_FAIL("StateMachine::run(4) failed unexpectedly");
            }

            // run again, with a list and workflow

            wkFlentries[targets[0]].push_back(DUMMY_SYNC_PHASE);
            wkFlentries[targets[0]].push_back(DUMMY_SYNC_PHASE);
            wkFlentries[targets[1]].push_back(DUMMY_SYNC_PHASE);
            wkFlentries[targets[1]].push_back(DUMMY_SYNC_PHASE);

            err = s.run(wkFlentries);

            if(err)
            {
                TS_FAIL("StateMachine::run(5) failed unexpectedly");
            }

            TS_TRACE(EXIT_MRK "testSmRun");
        }
};
#endif
OpenPOWER on IntegriCloud