1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2012. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.com/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <tmacros.h> |
---|
15 | #include <rtems/bspcmdline.h> |
---|
16 | |
---|
17 | /* forward declarations to avoid warnings */ |
---|
18 | rtems_task Init(rtems_task_argument argument); |
---|
19 | void test_errors(void); |
---|
20 | void test_search(bool null_expected, const char *cmdline, const char *param); |
---|
21 | |
---|
22 | extern const char *bsp_boot_cmdline; |
---|
23 | |
---|
24 | void test_errors(void) |
---|
25 | { |
---|
26 | const char *p; |
---|
27 | char result[32]; |
---|
28 | |
---|
29 | bsp_boot_cmdline = NULL; |
---|
30 | |
---|
31 | puts( "rtems_bsp_cmdline_get_param - name=NULL - returns NULL" ); |
---|
32 | p = rtems_bsp_cmdline_get_param( NULL, result, 32 ); |
---|
33 | rtems_test_assert( p == NULL ); |
---|
34 | |
---|
35 | puts( "rtems_bsp_cmdline_get_param - result=NULL - returns NULL" ); |
---|
36 | p = rtems_bsp_cmdline_get_param( "name", NULL, 32 ); |
---|
37 | rtems_test_assert( p == NULL ); |
---|
38 | |
---|
39 | puts( "rtems_bsp_cmdline_get_param - length=0 - returns NULL" ); |
---|
40 | p = rtems_bsp_cmdline_get_param( "name", result, 0 ); |
---|
41 | rtems_test_assert( p == NULL ); |
---|
42 | |
---|
43 | puts( "rtems_bsp_cmdline_get_param_raw - name=NULL - returns NULL" ); |
---|
44 | p = rtems_bsp_cmdline_get_param_raw( NULL ); |
---|
45 | rtems_test_assert( p == NULL ); |
---|
46 | |
---|
47 | bsp_boot_cmdline = NULL; |
---|
48 | |
---|
49 | puts( "rtems_bsp_cmdline_get_param - bsp_boot_cmdline=NULL - returns NULL" ); |
---|
50 | p = rtems_bsp_cmdline_get_param( "name", result, 5 ); |
---|
51 | rtems_test_assert( p == NULL ); |
---|
52 | |
---|
53 | puts( |
---|
54 | "rtems_bsp_cmdline_get_param_raw - bsp_boot_cmdline=NULL - returns NULL" ); |
---|
55 | p = rtems_bsp_cmdline_get_param_raw( "name" ); |
---|
56 | rtems_test_assert( p == NULL ); |
---|
57 | |
---|
58 | bsp_boot_cmdline = "edit"; |
---|
59 | puts ( |
---|
60 | "rtems_bsp_cmdline_get_param - bsp_boot_cmdline = edit name = " |
---|
61 | "edit -no error" ); |
---|
62 | p = rtems_bsp_cmdline_get_param("edit", result, 5); |
---|
63 | rtems_test_assert( p != NULL ); |
---|
64 | |
---|
65 | bsp_boot_cmdline = "joel=123456789"; |
---|
66 | puts( "rtems_bsp_cmdline_get_param - too short buffer" ); |
---|
67 | p = rtems_bsp_cmdline_get_param("joel", result, 5); |
---|
68 | rtems_test_assert( p != NULL ); |
---|
69 | |
---|
70 | bsp_boot_cmdline = "--arg1=X`"; |
---|
71 | puts( "rtems_bsp_cmdline_get_param_rhs - short match" ); |
---|
72 | p = rtems_bsp_cmdline_get_param_rhs("arg", result, 10); |
---|
73 | rtems_test_assert( p == NULL ); |
---|
74 | } |
---|
75 | |
---|
76 | void test_search( |
---|
77 | bool null_expected, |
---|
78 | const char *cmdline, |
---|
79 | const char *param |
---|
80 | ) |
---|
81 | { |
---|
82 | const char *p; |
---|
83 | char value[80]; |
---|
84 | size_t length; |
---|
85 | |
---|
86 | bsp_boot_cmdline = cmdline; |
---|
87 | |
---|
88 | printf( |
---|
89 | "\n" |
---|
90 | "Testing for param=(%s)%s\n" |
---|
91 | " Command Line : (%s)\n", |
---|
92 | param, |
---|
93 | ((null_expected) ? " - Expect NULL" : ""), |
---|
94 | cmdline |
---|
95 | ); |
---|
96 | |
---|
97 | printf( "rtems_bsp_cmdline_get_param_raw(%s)\n", param ); |
---|
98 | p = rtems_bsp_cmdline_get_param_raw( param ); |
---|
99 | if ( null_expected ) { |
---|
100 | if ( p ) |
---|
101 | puts( "ERROR - rtems_bsp_cmdline_get_param_raw did not return NULL" ); |
---|
102 | else |
---|
103 | printf( "rtems_bsp_cmdline_get_param_raw(%s) returned NULL\n", param ); |
---|
104 | rtems_test_assert( !p ); |
---|
105 | } else { |
---|
106 | if ( p ) |
---|
107 | printf( "rtems_bsp_cmdline_get_param_raw(%s) returned (%s)\n", param, p ); |
---|
108 | else |
---|
109 | printf( "rtems_bsp_cmdline_get_param_raw(%s) returned NULL\n", param ); |
---|
110 | |
---|
111 | rtems_test_assert( p ); |
---|
112 | } |
---|
113 | |
---|
114 | printf( "rtems_bsp_cmdline_get_param_rhs(%s)\n", param ); |
---|
115 | length = sizeof(value); |
---|
116 | p = rtems_bsp_cmdline_get_param_rhs( param, value, length ); |
---|
117 | if ( null_expected ) { |
---|
118 | if ( p ) |
---|
119 | puts( "ERROR - rtems_bsp_cmdline_get_param_rhs did not return NULL" ); |
---|
120 | else |
---|
121 | printf( "rtems_bsp_cmdline_get_param_rhs(%s) returned NULL\n", param ); |
---|
122 | rtems_test_assert( !p ); |
---|
123 | } else { |
---|
124 | if ( !p ) |
---|
125 | puts( "ERROR - rtems_bsp_cmdline_get_param_rhs returned NULL" ); |
---|
126 | rtems_test_assert( p ); |
---|
127 | printf( |
---|
128 | "rtems_bsp_cmdline_get_param_rhs(%s) returned (%s) value=(%s)\n", |
---|
129 | param, |
---|
130 | ((*p == '\0') ? "ZERO_LENGTH_STRING" : p ), |
---|
131 | ((*value == '\0') ? "ZERO_LENGTH_STRING" : value ) |
---|
132 | ); |
---|
133 | } |
---|
134 | |
---|
135 | } |
---|
136 | |
---|
137 | rtems_task Init( |
---|
138 | rtems_task_argument ignored |
---|
139 | ) |
---|
140 | { |
---|
141 | const char *bspcmdline; |
---|
142 | |
---|
143 | puts( "\n\n*** TEST OF PARSING BOOT COMMAND STRING ***" ); |
---|
144 | |
---|
145 | bspcmdline = rtems_bsp_cmdline_get(); |
---|
146 | if ( bspcmdline ) { |
---|
147 | printf( |
---|
148 | "BSP has a boot command line:\n" |
---|
149 | "%s\n", |
---|
150 | bspcmdline |
---|
151 | ); |
---|
152 | } else { |
---|
153 | puts( "BSP does not have a boot command line" ); |
---|
154 | } |
---|
155 | |
---|
156 | puts( "\nTest Parameter Error Conditions" ); |
---|
157 | test_errors(); |
---|
158 | |
---|
159 | test_search( false, "--arg=", "--arg" ); |
---|
160 | test_search( true, "--arg=", "-g" ); |
---|
161 | test_search( false, "--ip=192.168.1.151 --name=fred", "-name" ); |
---|
162 | test_search( false, "--ip=192.168.1.151 --name=fred", "-ip" ); |
---|
163 | test_search( |
---|
164 | false, |
---|
165 | "--ip=192.168.1.151 --name=\"joel and michele\" --cpu=fast", |
---|
166 | "-name" |
---|
167 | ); |
---|
168 | |
---|
169 | puts( "*** END OF OF PARSING BOOT COMMAND STRING ***" ); |
---|
170 | rtems_test_exit(0); |
---|
171 | } |
---|
172 | |
---|
173 | /* configuration information */ |
---|
174 | |
---|
175 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
176 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
177 | |
---|
178 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
179 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
180 | |
---|
181 | #define CONFIGURE_INIT |
---|
182 | #include <rtems/confdefs.h> |
---|
183 | |
---|
184 | /* global variables */ |
---|