-
Notifications
You must be signed in to change notification settings - Fork 215
/
ut_osloader_module_test.c
319 lines (267 loc) · 11.6 KB
/
ut_osloader_module_test.c
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
/*
* NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer"
*
* Copyright (c) 2019 United States Government as represented by
* the Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*================================================================================*
** File: ut_osloader_module_test.c
** Owner: Tam Ngo
** Date: April 2013
**================================================================================*/
/*--------------------------------------------------------------------------------*
** Includes
**--------------------------------------------------------------------------------*/
#include "ut_osloader_module_test.h"
#include "ut_osloader_test_platforms.h"
/*--------------------------------------------------------------------------------*
** Macros
**--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*
** Data types
**--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*
** External global variables
**--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*
** Global variables
**--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*
** Local function prototypes
**--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*
** Local function definitions
**--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*
** Syntax: OS_ModuleLoad
** Purpose: Loads the new ELF object module into the RTOS
** Parameters: To-be-filled-in
** Returns: OS_INVALID_POINTER if any of the pointers passed in is null
** OS_ERR_NO_FREE_IDS if the module table is full
** OS_ERR_NAME_TAKEN if the module name has already been used
** OS_ERROR if the OS call failed
** OS_SUCCESS if succeeded
**--------------------------------------------------------------------------------*/
void UT_os_module_load_test()
{
int i;
int32 res = 0;
const char *testDesc;
uint32 test_setup_invalid = 0;
osal_id_t module_id;
osal_id_t module_id2;
char module_name[UT_OS_NAME_BUFF_SIZE];
char module_file_name[UT_OS_PATH_BUFF_SIZE];
/*-----------------------------------------------------*/
testDesc = "API Not implemented";
res = OS_ModuleLoad(0, "TestModule", UT_OS_GENERIC_MODULE_NAME1, OS_MODULE_FLAG_LOCAL_SYMBOLS);
if (res == OS_ERR_NOT_IMPLEMENTED)
{
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA);
goto UT_os_module_load_test_exit_tag;
}
/*-----------------------------------------------------*/
testDesc = "#1 Null-pointer-arg-1";
res = OS_ModuleLoad(0, "TestModule", UT_OS_GENERIC_MODULE_NAME1, OS_MODULE_FLAG_LOCAL_SYMBOLS);
if (res == OS_INVALID_POINTER)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);
/*-----------------------------------------------------*/
testDesc = "#2 Null-pointer-arg-2";
res = OS_ModuleLoad(&module_id, 0, UT_OS_GENERIC_MODULE_NAME1, OS_MODULE_FLAG_LOCAL_SYMBOLS);
if (res == OS_INVALID_POINTER)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);
/*-----------------------------------------------------*/
testDesc = "#3 Null-pointer-arg-3";
res = OS_ModuleLoad(&module_id, "TestModule", 0, OS_MODULE_FLAG_LOCAL_SYMBOLS);
if (res == OS_INVALID_POINTER)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);
/*-----------------------------------------------------*/
testDesc = "#4 No-free-IDs";
/* Setup */
for (i = 0; i < OS_MAX_MODULES; i++)
{
snprintf(module_name, sizeof(module_name), UT_OS_GENERIC_MODULE_NAME_TEMPLATE, i);
snprintf(module_file_name, sizeof(module_file_name), UT_OS_GENERIC_MODULE_FILE_TEMPLATE, i);
res = OS_ModuleLoad(&module_id, module_name, module_file_name, OS_MODULE_FLAG_LOCAL_SYMBOLS);
if (res != OS_SUCCESS)
{
testDesc = "#4 No-free-IDs - Module Load failed";
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF);
test_setup_invalid = 1;
break;
}
}
if (test_setup_invalid == 0)
{
res = OS_ModuleLoad(&module_id, "OneTooMany", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS);
if (res == OS_ERR_NO_FREE_IDS)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);
}
/* Reset test environment */
OS_DeleteAllObjects();
/*-----------------------------------------------------*/
testDesc = "#5 Duplicate-name";
/* Setup */
res = OS_ModuleLoad(&module_id2, "DUPLICATE", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS);
if (res != OS_SUCCESS)
{
testDesc = "#5 Duplicate-name - Module Load failed";
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF);
}
else
{
res = OS_ModuleLoad(&module_id, "DUPLICATE", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS);
if (res == OS_ERR_NAME_TAKEN)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);
/* Reset test environment */
res = OS_ModuleUnload(module_id2);
}
/*-----------------------------------------------------*/
testDesc = "#6 OS-call-failure";
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO);
/*-----------------------------------------------------*/
testDesc = "#7 Nominal";
res = OS_ModuleLoad(&module_id, "Good", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS);
if (res == OS_SUCCESS)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);
/* Reset test environment */
res = OS_ModuleUnload(module_id);
UT_os_module_load_test_exit_tag:
return;
}
/*--------------------------------------------------------------------------------*
** Syntax: OS_ModuleUnload
** Purpose: Unloads the module from the running RTOS
** Parameters: To-be-filled-in
** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid module id
** OS_ERROR if the OS call failed
** OS_SUCCESS if succeeded
**--------------------------------------------------------------------------------*/
void UT_os_module_unload_test()
{
int32 res = 0;
const char *testDesc;
osal_id_t module_id;
/*-----------------------------------------------------*/
testDesc = "API Not implemented";
res = OS_ModuleUnload(OS_OBJECT_ID_UNDEFINED);
if (res == OS_ERR_NOT_IMPLEMENTED)
{
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA);
goto UT_os_module_unload_test_exit_tag;
}
/*-----------------------------------------------------*/
testDesc = "#1 Invalid-ID-arg";
res = OS_ModuleUnload(UT_OBJID_INCORRECT);
if (res == OS_ERR_INVALID_ID)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);
/*-----------------------------------------------------*/
testDesc = "#2 OS-call-failure";
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO);
/*-----------------------------------------------------*/
testDesc = "#3 Nominal";
/* Setup */
res = OS_ModuleLoad(&module_id, "Good", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS);
if (res != OS_SUCCESS)
{
testDesc = "#3 Nominal - Module Load failed";
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF);
}
else
{
res = OS_ModuleUnload(module_id);
if (res == OS_SUCCESS)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);
}
UT_os_module_unload_test_exit_tag:
return;
}
/*--------------------------------------------------------------------------------*
** Syntax: OS_ModuleInfo
** Purpose: Returns module information about a given module id
** Parameters: To-be-filled-in
** Returns: OS_INVALID_POINTER if the pointer passed in is null
** OS_ERR_INVALID_ID if the id passed in is not a valid module id
** OS_SUCCESS if succeeded
**--------------------------------------------------------------------------------*/
void UT_os_module_info_test()
{
int32 res = 0;
const char * testDesc;
osal_id_t module_id;
OS_module_prop_t module_info;
/*-----------------------------------------------------*/
testDesc = "API Not implemented";
res = OS_ModuleInfo(OS_OBJECT_ID_UNDEFINED, &module_info);
if (res == OS_ERR_NOT_IMPLEMENTED)
{
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA);
goto UT_os_module_info_test_exit_tag;
}
/*-----------------------------------------------------*/
testDesc = "#1 Invalid-pointer-arg";
res = OS_ModuleInfo(OS_OBJECT_ID_UNDEFINED, NULL);
if (res == OS_INVALID_POINTER)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);
/*-----------------------------------------------------*/
testDesc = "#2 Invalid-ID-arg";
res = OS_ModuleInfo(UT_OBJID_INCORRECT, &module_info);
if (res == OS_ERR_INVALID_ID)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);
/*-----------------------------------------------------*/
testDesc = "#3 Nominal";
/* Setup */
res = OS_ModuleLoad(&module_id, "Good", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS);
if (res != OS_SUCCESS)
{
testDesc = "#3 Nominal - Module Load failed";
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF);
}
else
{
res = OS_ModuleInfo(module_id, &module_info);
if (res == OS_SUCCESS)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);
res = OS_ModuleUnload(module_id);
}
UT_os_module_info_test_exit_tag:
return;
}
/*================================================================================*
** End of File: ut_osloader_module_test.c
**================================================================================*/