summaryrefslogtreecommitdiffstats
path: root/src/usr/initservice/test/initservicetest.H
blob: 3edfa288575a6328bf671ed0ce0a722165d9a574 (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
/**
 * @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    "../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
        {
                true,                               // startflag=true, try to start
                INITSERVICE::BASE_MODULE,           // Base Module
                INITSERVICE::INIT_SVC_TEST1_ID,     // module id for errorlog
        },
};


/**
 * @brief   set up a dummy TaskInfo struct for test 2.
 *  example.C does indeed have a _start() function so this should return OK.
 *
 *  @todo   this needs to be replaced with a test module
 */
const   INITSERVICE::TaskInfo    TASK_TEST2  =  {
        "libexample.so" ,                           // taskname
        {
                true,                               // startflag=true, try to start
                INITSERVICE::BASE_MODULE,           // Base Module
                INITSERVICE::INIT_SVC_TEST2_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
        {
                true,                               // startflag=true, try to start
                INITSERVICE::BASE_MODULE,           // Base Module
                INITSERVICE::INIT_SVC_TEST3_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();
        tid_t   tidrc   =   0;


        TS_TRACE( "=====>Attempt to run a nonexistent task.\n  ");
        tidrc   =   l_is.startTask( TASK_TEST1, errl );
        printk( "testInitServiceStartTask1: startTask returned %d: errl=%p\n", tidrc, errl );
        if ( (int16_t)tidrc < 0  )
        {
            TS_TRACE( "SUCCESS: startTask returned an errorlog.\n");
            //  @todo   dump error log to trace?
        }
        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();
        tid_t   tidrc   =   0;


        TS_TRACE( "=====>Attempt to run a task with a _start() function.\n  ");
        tidrc   =   l_is.startTask( TASK_TEST2, errl );
        printk( "testInitServiceStartTask2: startTask returned %d: errl=%p\n", tidrc, errl );
        if ( (int16_t)tidrc >= 0  )
        {
            TS_TRACE( "SUCCESS: startTask returned OK.\n");
            //  @todo   dump error log to trace?
        }
        else
        {
            TS_FAIL( "ERROR: StartTask returned an error log.\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();
        tid_t   tidrc   =   0;


        TS_TRACE( "====>Attempt to run a task with NO _start() function.\n  ");
        tidrc   =   l_is.startTask( TASK_TEST3, errl );
        printk( "testInitServiceStartTask3: startTask returned %d: errl=%p\n", tidrc, errl );
        if ( (int16_t)tidrc < 0  )
        {
            TS_TRACE( "SUCCESS: startTask returned an error log.\n");
            //  @todo   dump error log to trace?
        }
        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");
        }

        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_ID,
                INITSERVICE::START_TASK_FAILED,
                0,
                0
        );

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



        return;
    }
};  // class InitServiceTest


#endif  // __TEST_INIT_SERVICETEST_H

OpenPOWER on IntegriCloud