first public release
[dpdk.git] / app / test / test_eal_flags.c
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  * 
7  *   Redistribution and use in source and binary forms, with or without 
8  *   modification, are permitted provided that the following conditions 
9  *   are met:
10  * 
11  *     * Redistributions of source code must retain the above copyright 
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright 
14  *       notice, this list of conditions and the following disclaimer in 
15  *       the documentation and/or other materials provided with the 
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its 
18  *       contributors may be used to endorse or promote products derived 
19  *       from this software without specific prior written permission.
20  * 
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  * 
33  *  version: DPDK.L.1.2.3-3
34  */
35 #include <stdio.h>
36
37 #include <cmdline_parse.h>
38
39 #include "test.h"
40
41 #ifndef RTE_EXEC_ENV_BAREMETAL
42 #include <string.h>
43 #include <stdarg.h>
44 #include <stdlib.h>
45 #include <errno.h>
46 #include <unistd.h>
47 #include <sys/wait.h>
48
49 #include <rte_debug.h>
50 #include <rte_string_fns.h>
51
52 #include "process.h"
53
54 #define mp_flag "--proc-type=secondary"
55 #define no_hpet "--no-hpet"
56 #define no_huge "--no-huge"
57 #define no_shconf "--no-shconf"
58 #define launch_proc(ARGV) process_dup(ARGV, \
59                 sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
60
61 /*
62  * Test that the app doesn't run without invalid blacklist option.
63  * Final test ensures it does run with valid options as sanity check
64  */
65 static int
66 test_invalid_b_flag(void)
67 {
68         const char *blinval[][8] = {
69                 {prgname, mp_flag, "-n", "1", "-c", "1", "-b", "error"},
70                 {prgname, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0"},
71                 {prgname, mp_flag, "-n", "1", "-c", "1", "-b", "0:error:0.1"},
72                 {prgname, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1error"},
73                 {prgname, mp_flag, "-n", "1", "-c", "1", "-b", "error0:0:0.1"},
74                 {prgname, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1.2"},
75         };
76         /* Test with valid blacklist option */
77         const char *blval[] = {prgname, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
78
79         int i;
80
81         for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
82                 if (launch_proc(blinval[i]) == 0) {
83                         printf("Error - process did run ok with invalid "
84                             "blacklist parameter\n");
85                         return -1;
86                 }
87         }
88         if (launch_proc(blval) != 0) {
89                 printf("Error - process did not run ok with valid blacklist value\n");
90                 return -1;
91         }
92         return 0;
93 }
94
95
96 /*
97  * Test that the app doesn't run with invalid -r option.
98  */
99 static int
100 test_invalid_r_flag(void)
101 {
102         const char *rinval[][8] = {
103                         {prgname, mp_flag, "-n", "1", "-c", "1", "-r", "error"},
104                         {prgname, mp_flag, "-n", "1", "-c", "1", "-r", "0"},
105                         {prgname, mp_flag, "-n", "1", "-c", "1", "-r", "-1"},
106                         {prgname, mp_flag, "-n", "1", "-c", "1", "-r", "17"},
107         };
108         /* Test with valid blacklist option */
109         const char *rval[] = {prgname, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
110
111         int i;
112
113         for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
114                 if (launch_proc(rinval[i]) == 0) {
115                         printf("Error - process did run ok with invalid "
116                             "-r (rank) parameter\n");
117                         return -1;
118                 }
119         }
120         if (launch_proc(rval) != 0) {
121                 printf("Error - process did not run ok with valid -r (rank) value\n");
122                 return -1;
123         }
124         return 0;
125 }
126
127 /*
128  * Test that the app doesn't run without the coremask flag. In all cases
129  * should give an error and fail to run
130  */
131 static int
132 test_missing_c_flag(void)
133 {
134         /* -c flag but no coremask value */
135         const char *argv1[] = { prgname, mp_flag, "-n", "3", "-c"};
136         /* No -c flag at all */
137         const char *argv2[] = { prgname, mp_flag, "-n", "3"};
138         /* bad coremask value */
139         const char *argv3[] = { prgname, mp_flag, "-n", "3", "-c", "error" };
140         /* sanity check of tests - valid coremask value */
141         const char *argv4[] = { prgname, mp_flag, "-n", "3", "-c", "1" };
142
143         if (launch_proc(argv1) == 0
144                         || launch_proc(argv2) == 0
145                         || launch_proc(argv3) == 0) {
146                 printf("Error - process ran without error when missing -c flag\n");
147                 return -1;
148         }
149         if (launch_proc(argv4) != 0) {
150                 printf("Error - process did not run ok with valid coremask value\n");
151                 return -1;
152         }
153         return 0;
154 }
155
156 /*
157  * Test that the app doesn't run without the -n flag. In all cases
158  * should give an error and fail to run.
159  * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
160  * flags.
161  */
162 static int
163 test_missing_n_flag(void)
164 {
165         /* -n flag but no value */
166         const char *argv1[] = { prgname, no_huge, no_shconf, "-c", "1", "-n"};
167         /* No -n flag at all */
168         const char *argv2[] = { prgname, no_huge, no_shconf, "-c", "1"};
169         /* bad numeric value */
170         const char *argv3[] = { prgname, no_huge, no_shconf, "-c", "1", "-n", "e" };
171         /* out-of-range value */
172         const char *argv4[] = { prgname, no_huge, no_shconf, "-c", "1", "-n", "9" };
173         /* sanity test - check with good value */
174         const char *argv5[] = { prgname, no_huge, no_shconf, "-c", "1", "-n", "2" };
175
176         if (launch_proc(argv1) == 0
177                         || launch_proc(argv2) == 0
178                         || launch_proc(argv3) == 0
179                         || launch_proc(argv4) == 0) {
180                 printf("Error - process ran without error when missing -n flag\n");
181                 return -1;
182         }
183         if (launch_proc(argv5) != 0) {
184                 printf("Error - process did not run ok with valid num-channel value\n");
185                 return -1;
186         }
187         return 0;
188 }
189
190 /*
191  * Test that the app runs with HPET, and without HPET
192  */
193 static int
194 test_no_hpet_flag(void)
195 {
196         /* With --no-hpet */
197         const char *argv1[] = {prgname, mp_flag, no_hpet, "-c", "1", "-n", "2"};
198         /* Without --no-hpet */
199         const char *argv2[] = {prgname, mp_flag, "-c", "1", "-n", "2"};
200
201         if (launch_proc(argv1) != 0) {
202                 printf("Error - process did not run ok with --no-hpet flag\n");
203                 return -1;
204         }
205         if (launch_proc(argv2) != 0) {
206                 printf("Error - process did not run ok without --no-hpet flag\n");
207                 return -1;
208         }
209         return 0;
210 }
211
212 static int
213 test_misc_flags(void)
214 {
215         /* check that some general flags don't prevent things from working.
216          * All cases, apart from the first, app should run.
217          * No futher testing of output done.
218          */
219         /* sanity check - failure with invalid option */
220         const char *argv0[] = {prgname, mp_flag, "-c", "1", "--invalid-opt"};
221
222         /* With --no-pci */
223         const char *argv1[] = {prgname, mp_flag, "-c", "1", "--no-pci"};
224         /* With -v */
225         const char *argv2[] = {prgname, mp_flag, "-c", "1", "-v"};
226         /* With -m - ignored for secondary processes */
227         const char *argv3[] = {prgname, mp_flag, "-c", "1", "-m", "32"};
228
229         if (launch_proc(argv0) == 0) {
230                 printf("Error - process ran ok with invalid flag\n");
231                 return -1;
232         }
233         if (launch_proc(argv1) != 0) {
234                 printf("Error - process did not run ok with --no-pci flag\n");
235                 return -1;
236         }
237         if (launch_proc(argv2) != 0) {
238                 printf("Error - process did not run ok with -v flag\n");
239                 return -1;
240         }
241         if (launch_proc(argv3) != 0) {
242                 printf("Error - process did not run ok with -m flag\n");
243                 return -1;
244         }
245         return 0;
246 }
247
248 int
249 test_eal_flags(void)
250 {
251         int ret = 0;
252
253         ret = test_missing_c_flag();
254         if (ret < 0) {
255                 printf("Error in test_missing_c_flag()");
256                 return ret;
257         }
258
259         ret = test_missing_n_flag();
260         if (ret < 0) {
261                 printf("Error in test_missing_n_flag()");
262                 return ret;
263         }
264
265         ret = test_no_hpet_flag();
266         if (ret < 0) {
267                 printf("Error in test_no_hpet_flag()");
268                 return ret;
269         }
270
271         ret = test_invalid_b_flag();
272         if (ret < 0) {
273                 printf("Error in test_invalid_b_flag()");
274                 return ret;
275         }
276
277         ret = test_invalid_r_flag();
278         if (ret < 0) {
279                 printf("Error in test_invalid_r_flag()");
280                 return ret;
281         }
282
283         ret = test_misc_flags();
284         if (ret < 0) {
285                 printf("Error in test_misc_flags()");
286                 return ret;
287         }
288
289         return ret;
290 }
291
292 #else
293 /* Baremetal version
294  * Multiprocess not applicable, so just return 0 always
295  */
296 int
297 test_eal_flags(void)
298 {
299         printf("Multi-process not possible for baremetal, cannot test EAL flags\n");
300         return 0;
301 }
302
303 #endif