summaryrefslogtreecommitdiffstats
path: root/src/usr/initservice/test/initservicetest.H
blob: 1c2d9991a42cd919a38b79ddf451705a82066494 (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
/****************************************************************************
 * $IBMCopyrightBlock:
 * 
 *  IBM Confidential
 * 
 *  Licensed Internal Code Source Materials
 * 
 *  IBM Flexible Support Processor Licensed Internal Code
 * 
 *  (C) Copyright IBM Corp. 2011
 * 
 *  The source code for this program is not published or other-
 *  wise divested of its trade secrets, irrespective of what has
 *  been deposited with the U.S. Copyright Office.
 * $
****************************************************************************/

/**
 * @file    initservicetest.H
 *
 *  Private functions for VFS2 phase.
 */

#ifndef __TEST_INIT_SERVICETEST_H
#define __TEST_INIT_SERVICETEST_H

/**
 *  @file initservicetest.H
 *
 *  @brief Unit tests for initservice module
 */

#include    <cxxtest/TestSuite.H>

#include    "../baseinitsvc/initservice.H"

/**
 * @brief   set up a dummy TaskInfo struct for test 1.
 * this taskname should not exist, so we are expecting an error log back.
 *
 */
const   INITSERVICE::TaskInfo    TASK_TEST1  =  {
        "libtestinitsvc_noexist.so" ,                   // taskname
        NULL,                                           // ptr to fn
        {
                INITSERVICE::START_TASK,                // startflag=true, try to start
                INITSERVICE::BASE_IMAGE,                // Base Module
                INITSERVICE::INIT_SVC_TEST1_ERRL_ID,    // module id for errorlog
        },
};


/**
 * @brief   set up a dummy TaskInfo struct for test 2.
 *  tasktest2 does indeed have a _start() function so this should return OK.
 *
 */
const   INITSERVICE::TaskInfo    TASK_TEST2  =  {
        "libtasktest2.so" ,                               // taskname
        NULL,                                           // ptr to fn
        {
                INITSERVICE::START_TASK,                // startflag=true, try to start
                INITSERVICE::BASE_IMAGE,                // Base Module
                INITSERVICE::INIT_SVC_TEST2_ERRL_ID,    // module id for errorlog
        },
};


/**
 * @brief   set up a dummy TaskInfo struct.
 *  libtrace does NOT have a _start() function so this should return an errorlog.
 *
 *  @todo   this needs to be replaced with a test module
 */
const   INITSERVICE::TaskInfo    TASK_TEST3  =  {
        "libtrace.so" ,                                 // taskname
        NULL,                                           // ptr to fn
        {
                INITSERVICE::START_TASK,                // startflag=true, try to start
                INITSERVICE::BASE_IMAGE,                // Base Module
                INITSERVICE::INIT_SVC_TEST3_ERRL_ID,    // module id for errorlog
        },
};

/**
 * @class InitServiceTest
 *
 *  runs unit testa against InitService class
 *
 */
class InitServiceTest: public CxxTest::TestSuite
{

public:
    /**
     *  @brief  testInitServiceStartTask1
     *      this should try to run a nonexistent task, return an
     *      errorlog, and not blow up
     *
     */
    void testInitServiceStartTask1(void)
    {

        errlHndl_t  errl    = NULL;
        /**
         * @todo    use a separate instance here, not the singleton
         */
        INITSERVICE::InitService &l_is = INITSERVICE::InitService::getTheInstance();

        TS_TRACE( "=====>Attempt to run a nonexistent task, expect an ERROR.");
        errl = l_is.startTask(  &TASK_TEST1,        // task struct
                                NULL );             //  args
        if ( errl  )
        {
            TS_TRACE( "SUCCESS: startTask returned an errorlog.\n");
        }
        else
        {
            TS_FAIL( "ERROR: no error log was returned.\n");
        }


        return;
    }

    /**
     *  @brief  testInitServiceStartTask2
     *  this should try to run a task that does have a _start() function.
     *          it should return OK.
     */
    void testInitServiceStartTask2(void)
    {
        errlHndl_t  errl    = NULL;
        /**
         * @todo    use a separate instance here, not the singleton
         */
        INITSERVICE::InitService &l_is = INITSERVICE::InitService::getTheInstance();

        TS_TRACE( "=====>Attempt to run a task with a _start() function, expect SUCCESS.");
        errl = l_is.startTask(  &TASK_TEST2,        // task struct
                                NULL );             // args
        if ( errl )
        {
            TS_FAIL( "ERROR: StartTask returned an error log.\n");
        }
        else
        {
            TS_TRACE( "SUCCESS: startTask returned OK.\n");
        }


        return;
    }


    /**
     *  @brief  testInitServiceStartTask3
     *  this should try to run a task that does NOT have a  _start() function.
     *          it should fail
     */
    void testInitServiceStartTask3(void)
    {
        errlHndl_t  errl    = NULL;
        /**
         * @todo    use a separate instance here, not the singleton
         */
        INITSERVICE::InitService   &l_is = INITSERVICE::InitService::getTheInstance();

        TS_TRACE( "====>Attempt to run a task with NO _start() function, expect an ERROR.");
        errl = l_is.startTask(  &TASK_TEST3,            // task struct
                                NULL );                 //  args
        if ( errl )
        {
            TS_TRACE( "SUCCESS: startTask returned an error log.\n");
        }
        else
        {
            TS_FAIL( "ERROR: StartTask did not return an error log.\n");
        }

        return;
    }

    /**
     *  @brief  testInitServicereportError1
     *      This will call reportError with a NULL errlHndl_t .  It should handle it
     *      OK (reportError() will print an error message to trace)
     */
    void testInitServicereportError1(void)
    {
        errlHndl_t  errl    = NULL;
        /**
         * @todo    use a separate instance here, not the singleton
         */
        INITSERVICE::InitService   &l_is = INITSERVICE::InitService::getTheInstance();

        TS_TRACE( "====> call reportError with NULL handle, should handle it OK\n  ");
        l_is.reportError( errl );

        // reportError() might crash, if it returns, just make sure it didn't modify
        //  the input pointer
        if ( errl != NULL)
        {
            TS_FAIL( "ERROR:  expected the NULL errlHndl_t to stay NULL\n");
        }
        else
        {
            TS_TRACE( "SUCCESS: reportError returned OK.");
        }

        return;
    }

    /**
     *  @brief  testInitServicereportError1
     *      This will call reportError with a good errorlog.
     *      on return, it should be NULLED out
     *      @todo can we check with the errorlogging facility to see if it got
     *      posted??
     */
    void testInitServicereportError2(void)
    {
        errlHndl_t  errl    = NULL;
        /**
         * @todo    use a separate instance here, not the singleton
         */
        INITSERVICE::InitService   &l_is = INITSERVICE::InitService::getTheInstance();

        errl = new ERRORLOG::ErrlEntry(
                ERRORLOG::ERRL_SEV_INFORMATIONAL,
                INITSERVICE::INIT_SVC_TEST5_ERRL_ID,
                INITSERVICE::START_TASK_FAILED,
                0,
                0
        );

        TS_TRACE( "====> call reportError with good error handle, should commit and then delete  ");
        l_is.reportError( errl );
        if ( errl !=NULL )
        {
            TS_FAIL( "ERROR: reportError did not delete the errlHndl_t handle!\n" );
        }
        else
        {
            TS_TRACE( "SUCCESS: reportError returned OK.");
        }

        return;
    }

};  // class InitServiceTest


#endif  // __TEST_INIT_SERVICETEST_H

OpenPOWER on IntegriCloud