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.
33 * version: DPDK.L.1.2.3-3
37 #include <cmdline_parse.h>
41 #ifndef RTE_EXEC_ENV_BAREMETAL
49 #include <rte_debug.h>
50 #include <rte_string_fns.h>
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__)
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
66 test_invalid_b_flag(void)
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"},
76 /* Test with valid blacklist option */
77 const char *blval[] = {prgname, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
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");
88 if (launch_proc(blval) != 0) {
89 printf("Error - process did not run ok with valid blacklist value\n");
97 * Test that the app doesn't run with invalid -r option.
100 test_invalid_r_flag(void)
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"},
108 /* Test with valid blacklist option */
109 const char *rval[] = {prgname, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
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");
120 if (launch_proc(rval) != 0) {
121 printf("Error - process did not run ok with valid -r (rank) value\n");
128 * Test that the app doesn't run without the coremask flag. In all cases
129 * should give an error and fail to run
132 test_missing_c_flag(void)
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" };
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");
149 if (launch_proc(argv4) != 0) {
150 printf("Error - process did not run ok with valid coremask value\n");
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
163 test_missing_n_flag(void)
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" };
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");
183 if (launch_proc(argv5) != 0) {
184 printf("Error - process did not run ok with valid num-channel value\n");
191 * Test that the app runs with HPET, and without HPET
194 test_no_hpet_flag(void)
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"};
201 if (launch_proc(argv1) != 0) {
202 printf("Error - process did not run ok with --no-hpet flag\n");
205 if (launch_proc(argv2) != 0) {
206 printf("Error - process did not run ok without --no-hpet flag\n");
213 test_misc_flags(void)
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.
219 /* sanity check - failure with invalid option */
220 const char *argv0[] = {prgname, mp_flag, "-c", "1", "--invalid-opt"};
223 const char *argv1[] = {prgname, mp_flag, "-c", "1", "--no-pci"};
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"};
229 if (launch_proc(argv0) == 0) {
230 printf("Error - process ran ok with invalid flag\n");
233 if (launch_proc(argv1) != 0) {
234 printf("Error - process did not run ok with --no-pci flag\n");
237 if (launch_proc(argv2) != 0) {
238 printf("Error - process did not run ok with -v flag\n");
241 if (launch_proc(argv3) != 0) {
242 printf("Error - process did not run ok with -m flag\n");
253 ret = test_missing_c_flag();
255 printf("Error in test_missing_c_flag()");
259 ret = test_missing_n_flag();
261 printf("Error in test_missing_n_flag()");
265 ret = test_no_hpet_flag();
267 printf("Error in test_no_hpet_flag()");
271 ret = test_invalid_b_flag();
273 printf("Error in test_invalid_b_flag()");
277 ret = test_invalid_r_flag();
279 printf("Error in test_invalid_r_flag()");
283 ret = test_misc_flags();
285 printf("Error in test_misc_flags()");
294 * Multiprocess not applicable, so just return 0 always
299 printf("Multi-process not possible for baremetal, cannot test EAL flags\n");