-
Notifications
You must be signed in to change notification settings - Fork 215
/
ut_osloader_symtable_test.c
207 lines (164 loc) · 7.87 KB
/
ut_osloader_symtable_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
/*
* 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_symtable_test.c
** Owner: Tam Ngo
** Date: April 2013
**================================================================================*/
/*--------------------------------------------------------------------------------*
** Includes
**--------------------------------------------------------------------------------*/
#include "ut_osloader_symtable_test.h"
#include "ut_osloader_test_platforms.h"
/*--------------------------------------------------------------------------------*
** Macros
**--------------------------------------------------------------------------------*/
/**
* The size limit to pass for OS_SymbolTableDump nominal test
*
* This must be large enough to actually accommodate all of the symbols
* in the target system.
*/
#define UT_SYMTABLE_SIZE_LIMIT 1048576
/*--------------------------------------------------------------------------------*
** Data types
**--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*
** External global variables
**--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*
** Global variables
**--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*
** Local function prototypes
**--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*
** Local function definitions
**--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*
** Syntax: OS_SymbolLookup
** Purpose: Returns the memory address of a symbol
** Parameters: To-be-filled-in
** Returns: OS_INVALID_POINTER if any of the pointers passed in is null
** OS_ERROR if the symbol name is not found
** OS_SUCCESS if succeeded
**--------------------------------------------------------------------------------*/
void UT_os_symbol_lookup_test()
{
cpuaddr symbol_addr;
osal_id_t module_id;
/*-----------------------------------------------------*/
/* API Not implemented */
if (!UT_IMPL(OS_SymbolLookup(&symbol_addr, "main")))
{
return;
}
/*-----------------------------------------------------*/
/* #1 Invalid-pointer-arg-1 */
UT_RETVAL(OS_SymbolLookup(0, "Sym"), OS_INVALID_POINTER);
/*-----------------------------------------------------*/
/* #2 Invalid-pointer-arg-2 */
UT_RETVAL(OS_SymbolLookup(&symbol_addr, 0), OS_INVALID_POINTER);
/*-----------------------------------------------------*/
/* Setup for remainder of tests */
if (UT_SETUP(OS_ModuleLoad(&module_id, "Mod1", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_GLOBAL_SYMBOLS)))
{
/*-----------------------------------------------------*/
/* #3 Symbol-not-found */
UT_RETVAL(OS_SymbolLookup(&symbol_addr, "NotFound"), OS_ERROR);
/*-----------------------------------------------------*/
/* #4 Nominal, Global Symbols */
UT_NOMINAL(OS_SymbolLookup(&symbol_addr, "module1"));
/* Reset test environment */
UT_TEARDOWN(OS_ModuleUnload(module_id));
}
}
/*--------------------------------------------------------------------------------*
** Syntax: OS_ModuleSymbolLookup
** Purpose: Returns the memory address of a symbol
** Parameters: To-be-filled-in
** Returns: OS_INVALID_POINTER if any of the pointers passed in is null
** OS_ERROR if the symbol name is not found
** OS_SUCCESS if succeeded
**--------------------------------------------------------------------------------*/
void UT_os_module_symbol_lookup_test()
{
cpuaddr symbol_addr;
osal_id_t module_id;
/*-----------------------------------------------------*/
/* API Not implemented */
if (!UT_IMPL(OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symbol_addr, "main")))
{
return;
}
/*-----------------------------------------------------*/
/* Invalid object ID */
UT_RETVAL(OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symbol_addr, "Sym"), OS_ERR_INVALID_ID);
UT_RETVAL(OS_ModuleSymbolLookup(UT_OBJID_INCORRECT, &symbol_addr, "Sym"), OS_ERR_INVALID_ID);
/*-----------------------------------------------------*/
/* Setup for remainder of tests */
if (UT_SETUP(OS_ModuleLoad(&module_id, "Mod1", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS)))
{
/*-----------------------------------------------------*/
/* #1 Invalid-pointer-arg */
UT_RETVAL(OS_ModuleSymbolLookup(module_id, NULL, "Sym"), OS_INVALID_POINTER);
UT_RETVAL(OS_ModuleSymbolLookup(module_id, &symbol_addr, NULL), OS_INVALID_POINTER);
/*-----------------------------------------------------*/
/* #3 Symbol-not-found */
UT_RETVAL(OS_ModuleSymbolLookup(module_id, &symbol_addr, "NotFound"), OS_ERROR);
/*-----------------------------------------------------*/
/* #4 Nominal, Local Symbols */
UT_NOMINAL(OS_ModuleSymbolLookup(module_id, &symbol_addr, "module1"));
/* Reset test environment */
UT_TEARDOWN(OS_ModuleUnload(module_id));
}
}
/*--------------------------------------------------------------------------------*
** Syntax: OS_SymbolTableDump
** Purpose: Dumps the system symbol table to the given filename
** Parameters: To-be-filled-in
** Returns: OS_INVALID_POINTER if the pointer passed in is null
** OS_FS_ERR_PATH_INVALID if the filename is invalid
** OS_ERROR if there was any problem writing the symbol table to the file
** OS_SUCCESS if succeeded
**--------------------------------------------------------------------------------*/
void UT_os_symbol_table_dump_test()
{
/*
* Note that even if the functionality is not implemented,
* the API still validates the input pointers (not null) and
* the validity of the file name.
*/
/*-----------------------------------------------------*/
/* #1 Invalid-pointer-arg */
UT_RETVAL(OS_SymbolTableDump(0, 10000), OS_INVALID_POINTER);
/*-----------------------------------------------------*/
/* #2 Invalid-path */
UT_RETVAL(OS_SymbolTableDump("/this/path/is/invalid.dat", 10000), OS_FS_ERR_PATH_INVALID);
/*-----------------------------------------------------*/
/* #3 Nominal */
if (UT_NOMINAL_OR_NOTIMPL(OS_SymbolTableDump(UT_OS_GENERIC_MODULE_DIR "SymbolReal.dat", UT_SYMTABLE_SIZE_LIMIT)))
{
UT_RETVAL(OS_SymbolTableDump(UT_OS_GENERIC_MODULE_DIR "SymbolZero.dat", 0), OS_ERR_OUTPUT_TOO_LARGE);
}
}
/*================================================================================*
** End of File: ut_osloader_symtable_test.c
**================================================================================*/