4 * Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
36 #include <cmdline_parse.h>
40 #ifndef RTE_EXEC_ENV_BAREMETAL
48 #include <rte_debug.h>
49 #include <rte_string_fns.h>
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__)
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
65 test_invalid_b_flag(void)
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"},
75 /* Test with valid blacklist option */
76 const char *blval[] = {prgname, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
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");
87 if (launch_proc(blval) != 0) {
88 printf("Error - process did not run ok with valid blacklist value\n");
96 * Test that the app doesn't run with invalid -r option.
99 test_invalid_r_flag(void)
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"},
107 /* Test with valid blacklist option */
108 const char *rval[] = {prgname, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
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");
119 if (launch_proc(rval) != 0) {
120 printf("Error - process did not run ok with valid -r (rank) value\n");
127 * Test that the app doesn't run without the coremask flag. In all cases
128 * should give an error and fail to run
131 test_missing_c_flag(void)
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" };
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");
148 if (launch_proc(argv4) != 0) {
149 printf("Error - process did not run ok with valid coremask value\n");
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
162 test_missing_n_flag(void)
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" };
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");
182 if (launch_proc(argv5) != 0) {
183 printf("Error - process did not run ok with valid num-channel value\n");
190 * Test that the app runs with HPET, and without HPET
193 test_no_hpet_flag(void)
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"};
200 if (launch_proc(argv1) != 0) {
201 printf("Error - process did not run ok with --no-hpet flag\n");
204 if (launch_proc(argv2) != 0) {
205 printf("Error - process did not run ok without --no-hpet flag\n");
212 test_misc_flags(void)
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.
218 /* sanity check - failure with invalid option */
219 const char *argv0[] = {prgname, mp_flag, "-c", "1", "--invalid-opt"};
222 const char *argv1[] = {prgname, mp_flag, "-c", "1", "--no-pci"};
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"};
228 if (launch_proc(argv0) == 0) {
229 printf("Error - process ran ok with invalid flag\n");
232 if (launch_proc(argv1) != 0) {
233 printf("Error - process did not run ok with --no-pci flag\n");
236 if (launch_proc(argv2) != 0) {
237 printf("Error - process did not run ok with -v flag\n");
240 if (launch_proc(argv3) != 0) {
241 printf("Error - process did not run ok with -m flag\n");
252 ret = test_missing_c_flag();
254 printf("Error in test_missing_c_flag()");
258 ret = test_missing_n_flag();
260 printf("Error in test_missing_n_flag()");
264 ret = test_no_hpet_flag();
266 printf("Error in test_no_hpet_flag()");
270 ret = test_invalid_b_flag();
272 printf("Error in test_invalid_b_flag()");
276 ret = test_invalid_r_flag();
278 printf("Error in test_invalid_r_flag()");
282 ret = test_misc_flags();
284 printf("Error in test_misc_flags()");
293 * Multiprocess not applicable, so just return 0 always
298 printf("Multi-process not possible for baremetal, cannot test EAL flags\n");