remove version in all files
[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  */
34 #include <stdio.h>
35
36 #include <cmdline_parse.h>
37
38 #include "test.h"
39
40 #ifndef RTE_EXEC_ENV_BAREMETAL
41 #include <string.h>
42 #include <stdarg.h>
43 #include <stdlib.h>
44 #include <errno.h>
45 #include <unistd.h>
46 #include <sys/wait.h>
47
48 #include <rte_debug.h>
49 #include <rte_string_fns.h>
50
51 #include "process.h"
52
53 #define mp_flag "--proc-type=secondary"
54 #define no_hpet "--no-hpet"
55 #define no_huge "--no-huge"
56 #define no_shconf "--no-shconf"
57 #define launch_proc(ARGV) process_dup(ARGV, \
58                 sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
59
60 /*
61  * Test that the app doesn't run without invalid blacklist option.
62  * Final test ensures it does run with valid options as sanity check
63  */
64 static int
65 test_invalid_b_flag(void)
66 {
67         const char *blinval[][8] = {
68                 {prgname, mp_flag, "-n", "1", "-c", "1", "-b", "error"},
69                 {prgname, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0"},
70                 {prgname, mp_flag, "-n", "1", "-c", "1", "-b", "0:error:0.1"},
71                 {prgname, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1error"},
72                 {prgname, mp_flag, "-n", "1", "-c", "1", "-b", "error0:0:0.1"},
73                 {prgname, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1.2"},
74         };
75         /* Test with valid blacklist option */
76         const char *blval[] = {prgname, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
77
78         int i;
79
80         for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
81                 if (launch_proc(blinval[i]) == 0) {
82                         printf("Error - process did run ok with invalid "
83                             "blacklist parameter\n");
84                         return -1;
85                 }
86         }
87         if (launch_proc(blval) != 0) {
88                 printf("Error - process did not run ok with valid blacklist value\n");
89                 return -1;
90         }
91         return 0;
92 }
93
94
95 /*
96  * Test that the app doesn't run with invalid -r option.
97  */
98 static int
99 test_invalid_r_flag(void)
100 {
101         const char *rinval[][8] = {
102                         {prgname, mp_flag, "-n", "1", "-c", "1", "-r", "error"},
103                         {prgname, mp_flag, "-n", "1", "-c", "1", "-r", "0"},
104                         {prgname, mp_flag, "-n", "1", "-c", "1", "-r", "-1"},
105                         {prgname, mp_flag, "-n", "1", "-c", "1", "-r", "17"},
106         };
107         /* Test with valid blacklist option */
108         const char *rval[] = {prgname, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
109
110         int i;
111
112         for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
113                 if (launch_proc(rinval[i]) == 0) {
114                         printf("Error - process did run ok with invalid "
115                             "-r (rank) parameter\n");
116                         return -1;
117                 }
118         }
119         if (launch_proc(rval) != 0) {
120                 printf("Error - process did not run ok with valid -r (rank) value\n");
121                 return -1;
122         }
123         return 0;
124 }
125
126 /*
127  * Test that the app doesn't run without the coremask flag. In all cases
128  * should give an error and fail to run
129  */
130 static int
131 test_missing_c_flag(void)
132 {
133         /* -c flag but no coremask value */
134         const char *argv1[] = { prgname, mp_flag, "-n", "3", "-c"};
135         /* No -c flag at all */
136         const char *argv2[] = { prgname, mp_flag, "-n", "3"};
137         /* bad coremask value */
138         const char *argv3[] = { prgname, mp_flag, "-n", "3", "-c", "error" };
139         /* sanity check of tests - valid coremask value */
140         const char *argv4[] = { prgname, mp_flag, "-n", "3", "-c", "1" };
141
142         if (launch_proc(argv1) == 0
143                         || launch_proc(argv2) == 0
144                         || launch_proc(argv3) == 0) {
145                 printf("Error - process ran without error when missing -c flag\n");
146                 return -1;
147         }
148         if (launch_proc(argv4) != 0) {
149                 printf("Error - process did not run ok with valid coremask value\n");
150                 return -1;
151         }
152         return 0;
153 }
154
155 /*
156  * Test that the app doesn't run without the -n flag. In all cases
157  * should give an error and fail to run.
158  * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
159  * flags.
160  */
161 static int
162 test_missing_n_flag(void)
163 {
164         /* -n flag but no value */
165         const char *argv1[] = { prgname, no_huge, no_shconf, "-c", "1", "-n"};
166         /* No -n flag at all */
167         const char *argv2[] = { prgname, no_huge, no_shconf, "-c", "1"};
168         /* bad numeric value */
169         const char *argv3[] = { prgname, no_huge, no_shconf, "-c", "1", "-n", "e" };
170         /* out-of-range value */
171         const char *argv4[] = { prgname, no_huge, no_shconf, "-c", "1", "-n", "9" };
172         /* sanity test - check with good value */
173         const char *argv5[] = { prgname, no_huge, no_shconf, "-c", "1", "-n", "2" };
174
175         if (launch_proc(argv1) == 0
176                         || launch_proc(argv2) == 0
177                         || launch_proc(argv3) == 0
178                         || launch_proc(argv4) == 0) {
179                 printf("Error - process ran without error when missing -n flag\n");
180                 return -1;
181         }
182         if (launch_proc(argv5) != 0) {
183                 printf("Error - process did not run ok with valid num-channel value\n");
184                 return -1;
185         }
186         return 0;
187 }
188
189 /*
190  * Test that the app runs with HPET, and without HPET
191  */
192 static int
193 test_no_hpet_flag(void)
194 {
195         /* With --no-hpet */
196         const char *argv1[] = {prgname, mp_flag, no_hpet, "-c", "1", "-n", "2"};
197         /* Without --no-hpet */
198         const char *argv2[] = {prgname, mp_flag, "-c", "1", "-n", "2"};
199
200         if (launch_proc(argv1) != 0) {
201                 printf("Error - process did not run ok with --no-hpet flag\n");
202                 return -1;
203         }
204         if (launch_proc(argv2) != 0) {
205                 printf("Error - process did not run ok without --no-hpet flag\n");
206                 return -1;
207         }
208         return 0;
209 }
210
211 static int
212 test_misc_flags(void)
213 {
214         /* check that some general flags don't prevent things from working.
215          * All cases, apart from the first, app should run.
216          * No futher testing of output done.
217          */
218         /* sanity check - failure with invalid option */
219         const char *argv0[] = {prgname, mp_flag, "-c", "1", "--invalid-opt"};
220
221         /* With --no-pci */
222         const char *argv1[] = {prgname, mp_flag, "-c", "1", "--no-pci"};
223         /* With -v */
224         const char *argv2[] = {prgname, mp_flag, "-c", "1", "-v"};
225         /* With -m - ignored for secondary processes */
226         const char *argv3[] = {prgname, mp_flag, "-c", "1", "-m", "32"};
227
228         if (launch_proc(argv0) == 0) {
229                 printf("Error - process ran ok with invalid flag\n");
230                 return -1;
231         }
232         if (launch_proc(argv1) != 0) {
233                 printf("Error - process did not run ok with --no-pci flag\n");
234                 return -1;
235         }
236         if (launch_proc(argv2) != 0) {
237                 printf("Error - process did not run ok with -v flag\n");
238                 return -1;
239         }
240         if (launch_proc(argv3) != 0) {
241                 printf("Error - process did not run ok with -m flag\n");
242                 return -1;
243         }
244         return 0;
245 }
246
247 int
248 test_eal_flags(void)
249 {
250         int ret = 0;
251
252         ret = test_missing_c_flag();
253         if (ret < 0) {
254                 printf("Error in test_missing_c_flag()");
255                 return ret;
256         }
257
258         ret = test_missing_n_flag();
259         if (ret < 0) {
260                 printf("Error in test_missing_n_flag()");
261                 return ret;
262         }
263
264         ret = test_no_hpet_flag();
265         if (ret < 0) {
266                 printf("Error in test_no_hpet_flag()");
267                 return ret;
268         }
269
270         ret = test_invalid_b_flag();
271         if (ret < 0) {
272                 printf("Error in test_invalid_b_flag()");
273                 return ret;
274         }
275
276         ret = test_invalid_r_flag();
277         if (ret < 0) {
278                 printf("Error in test_invalid_r_flag()");
279                 return ret;
280         }
281
282         ret = test_misc_flags();
283         if (ret < 0) {
284                 printf("Error in test_misc_flags()");
285                 return ret;
286         }
287
288         return ret;
289 }
290
291 #else
292 /* Baremetal version
293  * Multiprocess not applicable, so just return 0 always
294  */
295 int
296 test_eal_flags(void)
297 {
298         printf("Multi-process not possible for baremetal, cannot test EAL flags\n");
299         return 0;
300 }
301
302 #endif