Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2014 Intel Corporation.
3 : : * Copyright(c) 2014 6WIND S.A.
4 : : */
5 : :
6 : : #include <stdio.h>
7 : :
8 : : #include "test.h"
9 : :
10 : : #include <string.h>
11 : : #include <stdarg.h>
12 : :
13 : : #ifdef RTE_EXEC_ENV_WINDOWS
14 : : static int
15 : : test_missing_c_flag(void)
16 : : {
17 : : printf("missing_c_flag not supported on Windows, skipping test\n");
18 : : return TEST_SKIPPED;
19 : : }
20 : :
21 : : static int
22 : : test_main_lcore_flag(void)
23 : : {
24 : : printf("main_lcore_flag not supported on Windows, skipping test\n");
25 : : return TEST_SKIPPED;
26 : : }
27 : :
28 : : static int
29 : : test_invalid_n_flag(void)
30 : : {
31 : : printf("invalid_n_flag not supported on Windows, skipping test\n");
32 : : return TEST_SKIPPED;
33 : : }
34 : :
35 : : static int
36 : : test_no_hpet_flag(void)
37 : : {
38 : : printf("no_hpet_flag not supported on Windows, skipping test\n");
39 : : return TEST_SKIPPED;
40 : : }
41 : :
42 : : static int
43 : : test_no_huge_flag(void)
44 : : {
45 : : printf("no_huge_flag not supported on Windows, skipping test\n");
46 : : return TEST_SKIPPED;
47 : : }
48 : :
49 : : static int
50 : : test_allow_flag(void)
51 : : {
52 : : printf("allow_flag not supported on Windows, skipping test\n");
53 : : return TEST_SKIPPED;
54 : : }
55 : :
56 : : static int
57 : : test_invalid_b_flag(void)
58 : : {
59 : : printf("invalid_b_flag not supported on Windows, skipping test\n");
60 : : return TEST_SKIPPED;
61 : : }
62 : :
63 : : static int
64 : : test_invalid_vdev_flag(void)
65 : : {
66 : : printf("invalid_vdev_flag not supported on Windows, skipping test\n");
67 : : return TEST_SKIPPED;
68 : : }
69 : :
70 : : static int
71 : : test_invalid_r_flag(void)
72 : : {
73 : : printf("invalid_r_flag not supported on Windows, skipping test\n");
74 : : return TEST_SKIPPED;
75 : : }
76 : :
77 : : static int
78 : : test_memory_flags(void)
79 : : {
80 : : printf("memory_flags not supported on Windows, skipping test\n");
81 : : return TEST_SKIPPED;
82 : : }
83 : :
84 : : static int
85 : : test_file_prefix(void)
86 : : {
87 : : printf("file_prefix not supported on Windows, skipping test\n");
88 : : return TEST_SKIPPED;
89 : : }
90 : :
91 : : static int
92 : : test_misc_flags(void)
93 : : {
94 : : printf("misc_flags not supported on Windows, skipping test\n");
95 : : return TEST_SKIPPED;
96 : : }
97 : :
98 : : #else
99 : :
100 : : #include <libgen.h>
101 : : #include <stdlib.h>
102 : : #include <errno.h>
103 : : #include <unistd.h>
104 : : #include <dirent.h>
105 : : #include <sys/file.h>
106 : : #include <sys/stat.h>
107 : : #include <sys/wait.h>
108 : : #include <limits.h>
109 : : #include <fcntl.h>
110 : :
111 : : #include <rte_lcore.h>
112 : : #include <rte_debug.h>
113 : : #include <rte_string_fns.h>
114 : :
115 : : #include "process.h"
116 : :
117 : : #define DEFAULT_MEM_SIZE "18"
118 : : #define mp_flag "--proc-type=secondary"
119 : : #define no_hpet "--no-hpet"
120 : : #define no_huge "--no-huge"
121 : : #define no_shconf "--no-shconf"
122 : : #define allow "--allow"
123 : : #define vdev "--vdev"
124 : : #define no_pci "--no-pci"
125 : : #define eal_debug_logs "--log-level=lib.eal:debug"
126 : : #define bus_debug_logs "--log-level=bus.*:debug"
127 : :
128 : : #define FS_HUGETLB "hugetlbfs"
129 : :
130 : : #define memtest "memtest"
131 : : #define memtest1 "memtest1"
132 : : #define memtest2 "memtest2"
133 : : #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 20)
134 : : #define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)
135 : :
136 : : #ifdef RTE_EXEC_ENV_LINUX
137 : : #include <mntent.h>
138 : :
139 : : enum hugepage_action {
140 : : HUGEPAGE_CHECK_EXISTS = 0,
141 : : HUGEPAGE_CHECK_LOCKED,
142 : : HUGEPAGE_DELETE,
143 : : HUGEPAGE_INVALID
144 : : };
145 : :
146 : : /*
147 : : * Cycles through hugepage directories and looks for hugepage
148 : : * files associated with a given prefix. Depending on value of
149 : : * action, the hugepages are checked if they exist, checked if
150 : : * they can be locked, or are simply deleted.
151 : : *
152 : : * Returns 1 if it finds at least one hugepage matching the action
153 : : * Returns 0 if no matching hugepages were found
154 : : * Returns -1 if it encounters an error
155 : : */
156 : : static int
157 [ - + ]: 15 : process_hugefiles(const char *prefix, enum hugepage_action action)
158 : : {
159 : : const struct mntent *entry;
160 : : char hugefile_prefix[PATH_MAX];
161 : : int result = 0;
162 : :
163 : : const int prefix_len = snprintf(hugefile_prefix, sizeof(hugefile_prefix), "%smap_", prefix);
164 [ - + ]: 15 : if (prefix_len <= 0 || prefix_len >= NAME_MAX) {
165 : : printf("Error (line %d) - cannot create hugefile filename prefix\n", __LINE__);
166 : 0 : return -1;
167 : : }
168 : :
169 : : /* get hugetlbfs mountpoints from /proc/mounts */
170 : 15 : FILE *mounts = setmntent("/proc/mounts", "r");
171 [ - + ]: 15 : if (mounts == NULL) {
172 : : printf("Error (line %d) - cannot parse /proc/mounts!\n", __LINE__);
173 : 0 : return -1;
174 : : }
175 : :
176 : : /* foreach mountpoint */
177 [ + + ]: 220 : while ((entry = getmntent(mounts)) != NULL) {
178 : : DIR *hugepage_dir;
179 : : struct dirent *dirent;
180 : :
181 : : /* only want hugetlbfs filesystems */
182 [ + + ]: 210 : if (strcmp(entry->mnt_type, FS_HUGETLB) != 0)
183 : 195 : continue;
184 : :
185 : : /* check if directory exists */
186 : 15 : hugepage_dir = opendir(entry->mnt_dir);
187 [ - + ]: 15 : if (hugepage_dir == NULL) {
188 : 0 : endmntent(mounts);
189 : 0 : printf("Error (line %d) - cannot open %s: %s\n",
190 : 0 : __LINE__, entry->mnt_dir, strerror(errno));
191 : 0 : return -1;
192 : : }
193 : :
194 [ + + ]: 73 : while ((dirent = readdir(hugepage_dir)) != NULL) {
195 [ + + ]: 63 : if (memcmp(dirent->d_name, hugefile_prefix, prefix_len) != 0)
196 : 47 : continue;
197 : :
198 [ + + + - ]: 16 : switch (action) {
199 : 5 : case HUGEPAGE_CHECK_EXISTS:
200 : : {
201 : : /* file exists, return */
202 : : printf("Hugepage file %s/%s exists, matching prefix %s\n",
203 : 5 : entry->mnt_dir, dirent->d_name, hugefile_prefix);
204 : 5 : closedir(hugepage_dir);
205 : : result = 1;
206 : 5 : goto end;
207 : : }
208 : : break;
209 : 9 : case HUGEPAGE_DELETE:
210 : : {
211 : : char file_path[PATH_MAX];
212 : :
213 : : snprintf(file_path, sizeof(file_path),
214 : 9 : "%s/%s", entry->mnt_dir, dirent->d_name);
215 : :
216 : : /* remove file */
217 [ - + ]: 9 : if (remove(file_path) < 0) {
218 : 0 : printf("Error (line %d) - cannot delete %s - %s!\n",
219 : 0 : __LINE__, dirent->d_name, strerror(errno));
220 : 0 : closedir(hugepage_dir);
221 : : result = -1;
222 : 0 : goto end;
223 : : }
224 : : printf("Deleted hugepage file %s\n", file_path);
225 : : result = 1;
226 : : }
227 : 9 : break;
228 : 2 : case HUGEPAGE_CHECK_LOCKED:
229 : : {
230 : : int fd;
231 : :
232 : : /* try and lock the file */
233 : 2 : fd = openat(dirfd(hugepage_dir), dirent->d_name, O_RDONLY);
234 : :
235 : : /* this shouldn't happen */
236 [ - + ]: 2 : if (fd == -1) {
237 : 0 : printf("Error (line %d) - cannot open %s - %s!\n",
238 : 0 : __LINE__, dirent->d_name, strerror(errno));
239 : 0 : closedir(hugepage_dir);
240 : : result = -1;
241 : 0 : goto end;
242 : : }
243 : :
244 : : /* non-blocking lock */
245 [ - + ]: 2 : if (flock(fd, LOCK_EX | LOCK_NB) != -1) {
246 : : result = 0;
247 : :
248 : : /* unlock the resulting lock */
249 : 0 : flock(fd, LOCK_UN);
250 : 0 : close(fd);
251 : 0 : closedir(hugepage_dir);
252 : 0 : goto end;
253 : : }
254 : : result = 1;
255 : : printf("Hugepage file %s/%s is locked\n",
256 : 2 : entry->mnt_dir, dirent->d_name);
257 : 2 : close(fd);
258 : : }
259 : 2 : break;
260 : : /* shouldn't happen */
261 : 0 : default:
262 : 0 : goto end;
263 : : } /* switch */
264 : :
265 : : } /* read hugepage directory */
266 : 10 : closedir(hugepage_dir);
267 : : } /* read /proc/mounts */
268 : 10 : end:
269 : 15 : endmntent(mounts);
270 : 15 : return result;
271 : : }
272 : :
273 : : /*
274 : : * count the number of "node*" files in /sys/devices/system/node/
275 : : */
276 : : static int
277 : 1 : get_number_of_sockets(void)
278 : : {
279 : : struct dirent *dirent = NULL;
280 : : const char * nodedir = "/sys/devices/system/node/";
281 : : DIR * dir = NULL;
282 : : int result = 0;
283 : :
284 : : /* check if directory exists */
285 [ - + ]: 1 : if ((dir = opendir(nodedir)) == NULL) {
286 : : /* if errno==ENOENT this means we don't have NUMA support */
287 [ # # ]: 0 : if (errno == ENOENT) {
288 : : printf("No NUMA nodes detected: assuming 1 available socket\n");
289 : 0 : return 1;
290 : : }
291 : 0 : printf("Error (line %d) - cannot open %s: %s\n",
292 : : __LINE__, nodedir, strerror(errno));
293 : 0 : return -1;
294 : : }
295 : :
296 [ + + ]: 13 : while ((dirent = readdir(dir)) != NULL)
297 [ + + ]: 12 : if (strncmp(dirent->d_name, "node", sizeof("node") - 1) == 0)
298 : 2 : result++;
299 : :
300 : 1 : closedir(dir);
301 : 1 : return result;
302 : : }
303 : : #endif /* RTE_EXEC_ENV_LINUX */
304 : :
305 : : /*
306 : : * Test that the app doesn't run with invalid allow option.
307 : : * Final tests ensures it does run with valid options as sanity check (one
308 : : * test for with Domain+BDF, second for just with BDF)
309 : : */
310 : : static int
311 : 1 : test_allow_flag(void)
312 : : {
313 : : unsigned int i;
314 : 1 : const char *prefix = file_prefix_arg();
315 [ + - ]: 1 : if (prefix == NULL)
316 : : return -1;
317 : :
318 : 1 : const char *wlinval[][8] = {
319 : : {prgname, prefix, mp_flag, eal_debug_logs,
320 : : allow, "error", "", ""},
321 : : {prgname, prefix, mp_flag, eal_debug_logs,
322 : : allow, "0:0:0", "", ""},
323 : : {prgname, prefix, mp_flag, eal_debug_logs,
324 : : allow, "0:error:0.1", "", ""},
325 : : {prgname, prefix, mp_flag, eal_debug_logs,
326 : : allow, "0:0:0.1error", "", ""},
327 : : {prgname, prefix, mp_flag, eal_debug_logs,
328 : : allow, "error0:0:0.1", "", ""},
329 : : {prgname, prefix, mp_flag, eal_debug_logs,
330 : : allow, "0:0:0.1.2", "", ""},
331 : : };
332 : : /* Test with valid allow option */
333 : 1 : const char *wlval1[] = {prgname, prefix, mp_flag, eal_debug_logs,
334 : : allow, "00FF:09:0B.3"};
335 : 1 : const char *wlval2[] = {prgname, prefix, mp_flag, eal_debug_logs,
336 : : allow, "09:0B.3", allow, "0a:0b.1"};
337 : 1 : const char *wlval3[] = {prgname, prefix, mp_flag, eal_debug_logs,
338 : : allow, "09:0B.3,type=test",
339 : : allow, "08:00.1,type=normal",
340 : : };
341 : :
342 [ + + ]: 7 : for (i = 0; i < RTE_DIM(wlinval); i++) {
343 [ - + ]: 6 : if (launch_proc(wlinval[i]) == 0) {
344 : : printf("Error (line %d) - process did run ok with invalid allow parameter\n",
345 : : __LINE__);
346 : 0 : return -1;
347 : : }
348 : : }
349 [ - + ]: 1 : if (launch_proc(wlval1) != 0 ) {
350 : : printf("Error (line %d) - process did not run ok with valid allow\n", __LINE__);
351 : 0 : return -1;
352 : : }
353 [ - + ]: 1 : if (launch_proc(wlval2) != 0 ) {
354 : : printf("Error (line %d) - process did not run ok with valid allow value set\n",
355 : : __LINE__);
356 : 0 : return -1;
357 : : }
358 [ - + ]: 1 : if (launch_proc(wlval3) != 0 ) {
359 : : printf("Error (line %d) - process did not run ok with valid allow + args\n",
360 : : __LINE__);
361 : 0 : return -1;
362 : : }
363 : :
364 : : return 0;
365 : : }
366 : :
367 : : /*
368 : : * Test that the app doesn't run with invalid blocklist option.
369 : : * Final test ensures it does run with valid options as sanity check
370 : : */
371 : : static int
372 : 1 : test_invalid_b_flag(void)
373 : : {
374 : 1 : const char *prefix = file_prefix_arg();
375 [ + - ]: 1 : if (prefix == NULL)
376 : : return -1;
377 : :
378 : 1 : const char *blinval[][6] = {
379 : : {prgname, prefix, mp_flag, eal_debug_logs, "-b", "error"},
380 : : {prgname, prefix, mp_flag, eal_debug_logs, "-b", "0:0:0"},
381 : : {prgname, prefix, mp_flag, eal_debug_logs, "-b", "0:error:0.1"},
382 : : {prgname, prefix, mp_flag, eal_debug_logs, "-b", "0:0:0.1error"},
383 : : {prgname, prefix, mp_flag, eal_debug_logs, "-b", "error0:0:0.1"},
384 : : {prgname, prefix, mp_flag, eal_debug_logs, "-b", "0:0:0.1.2"},
385 : : };
386 : : /* Test with valid blocklist option */
387 : 1 : const char *blval[] = {prgname, prefix, mp_flag, eal_debug_logs,
388 : : "-b", "FF:09:0B.3"};
389 : :
390 : : int i;
391 : :
392 [ + + ]: 7 : for (i = 0; i != RTE_DIM(blinval); i++) {
393 [ - + ]: 6 : if (launch_proc(blinval[i]) == 0) {
394 : : printf("Error (line %d) - process did run ok with invalid blocklist parameter\n",
395 : : __LINE__);
396 : 0 : return -1;
397 : : }
398 : : }
399 [ - + ]: 1 : if (launch_proc(blval) != 0) {
400 : : printf("Error (line %d) - process did not run ok with valid blocklist value\n",
401 : : __LINE__);
402 : 0 : return -1;
403 : : }
404 : : return 0;
405 : : }
406 : :
407 : : /*
408 : : * Test that the app doesn't run with invalid vdev option.
409 : : * Final test ensures it does run with valid options as sanity check
410 : : */
411 : : static int
412 : 1 : test_invalid_vdev_flag(void)
413 : : {
414 : : #ifdef RTE_NET_RING
415 : : #ifdef RTE_EXEC_ENV_FREEBSD
416 : : /* BSD target doesn't support prefixes at this point, and we also need to
417 : : * run another primary process here */
418 : : const char * prefix = no_shconf;
419 : : #else
420 : : const char * prefix = "--file-prefix=vdev";
421 : : #endif /* !RTE_EXEC_ENV_FREEBSD */
422 : :
423 : : /* Test with invalid vdev option */
424 : 1 : const char *vdevinval[] = {prgname, prefix, no_huge, eal_debug_logs,
425 : : bus_debug_logs, no_pci, vdev, "eth_dummy"};
426 : :
427 : : /* Test with valid vdev option */
428 : 1 : const char *vdevval1[] = {prgname, prefix, no_huge, eal_debug_logs,
429 : : bus_debug_logs, no_pci, vdev, "net_ring0"};
430 : :
431 : 1 : const char *vdevval2[] = {prgname, prefix, no_huge, eal_debug_logs,
432 : : bus_debug_logs, no_pci, vdev, "net_ring0,args=test"};
433 : :
434 : 1 : const char *vdevval3[] = {prgname, prefix, no_huge, eal_debug_logs,
435 : : bus_debug_logs, no_pci, vdev, "net_ring0,nodeaction=r1:0:CREATE"};
436 : :
437 [ - + ]: 1 : if (launch_proc(vdevinval) == 0) {
438 : : printf("Error (line %d) - process did run ok with invalid vdev parameter\n",
439 : : __LINE__);
440 : 0 : return -1;
441 : : }
442 : :
443 [ - + ]: 1 : if (launch_proc(vdevval1) != 0) {
444 : : printf("Error (line %d) - process did not run ok with valid vdev value\n",
445 : : __LINE__);
446 : 0 : return -1;
447 : : }
448 : :
449 [ - + ]: 1 : if (launch_proc(vdevval2) != 0) {
450 : : printf("Error (line %d) - process did not run ok with valid vdev value with dummy args\n",
451 : : __LINE__);
452 : 0 : return -1;
453 : : }
454 : :
455 [ - + ]: 1 : if (launch_proc(vdevval3) != 0) {
456 : : printf("Error (line %d) - process did not run ok with valid vdev value with valid args\n",
457 : : __LINE__);
458 : 0 : return -1;
459 : : }
460 : : return 0;
461 : : #else
462 : : return TEST_SKIPPED;
463 : : #endif /* !RTE_NET_RING */
464 : : }
465 : :
466 : : /*
467 : : * Test that the app doesn't run with invalid -r option.
468 : : */
469 : : static int
470 : 1 : test_invalid_r_flag(void)
471 : : {
472 : 1 : const char *prefix = file_prefix_arg();
473 [ + - ]: 1 : if (prefix == NULL)
474 : : return -1;
475 : :
476 : 1 : const char *rinval[][6] = {
477 : : {prgname, prefix, mp_flag, eal_debug_logs, "-r", "error"},
478 : : {prgname, prefix, mp_flag, eal_debug_logs, "-r", "0"},
479 : : {prgname, prefix, mp_flag, eal_debug_logs, "-r", "-1"},
480 : : {prgname, prefix, mp_flag, eal_debug_logs, "-r", "17"},
481 : : };
482 : : /* Test with valid blocklist option */
483 : 1 : const char *rval[] = {prgname, prefix, mp_flag, eal_debug_logs, "-r", "16"};
484 : :
485 : : int i;
486 : :
487 [ + + ]: 5 : for (i = 0; i != RTE_DIM(rinval); i++) {
488 [ - + ]: 4 : if (launch_proc(rinval[i]) == 0) {
489 : : printf("Error (line %d) - process did run ok with invalid -r (rank) parameter\n",
490 : : __LINE__);
491 : 0 : return -1;
492 : : }
493 : : }
494 [ - + ]: 1 : if (launch_proc(rval) != 0) {
495 : : printf("Error (line %d) - process did not run ok with valid -r (rank) value\n",
496 : : __LINE__);
497 : 0 : return -1;
498 : : }
499 : : return 0;
500 : : }
501 : :
502 : : /*
503 : : * Test that the app doesn't run without the coremask/corelist flags. In all cases
504 : : * should give an error and fail to run
505 : : */
506 : : static int
507 : 1 : test_missing_c_flag(void)
508 : : {
509 : 1 : const char *prefix = file_prefix_arg();
510 [ + - ]: 1 : if (prefix == NULL)
511 : : return -1;
512 : :
513 : : /* -c flag but no coremask value */
514 : 1 : const char *argv1[] = { prgname, prefix, mp_flag, eal_debug_logs, "-c"};
515 : : /* No -c, -l or --lcores flag at all */
516 : 1 : const char *argv2[] = { prgname, prefix, mp_flag};
517 : : /* bad coremask value */
518 : 1 : const char *argv3[] = { prgname, prefix, mp_flag, eal_debug_logs,
519 : : "-c", "error" };
520 : : /* sanity check of tests - valid coremask value */
521 : 1 : const char *argv4[] = { prgname, prefix, mp_flag, eal_debug_logs,
522 : : "-c", "1" };
523 : : /* -l flag but no corelist value */
524 : 1 : const char *argv5[] = { prgname, prefix, mp_flag, eal_debug_logs,
525 : : "-l"};
526 : 1 : const char *argv6[] = { prgname, prefix, mp_flag, eal_debug_logs,
527 : : "-l", " " };
528 : : /* bad corelist values */
529 : 1 : const char *argv7[] = { prgname, prefix, mp_flag, eal_debug_logs,
530 : : "-l", "error" };
531 : 1 : const char *argv8[] = { prgname, prefix, mp_flag, eal_debug_logs,
532 : : "-l", "1-" };
533 : 1 : const char *argv9[] = { prgname, prefix, mp_flag, eal_debug_logs,
534 : : "-l", "1," };
535 : 1 : const char *argv10[] = { prgname, prefix, mp_flag, eal_debug_logs,
536 : : "-l", "1#2" };
537 : : /* core number is negative value */
538 : 1 : const char * const argv11[] = { prgname, prefix, mp_flag, eal_debug_logs,
539 : : "-l", "-5" };
540 : 1 : const char * const argv12[] = { prgname, prefix, mp_flag, eal_debug_logs,
541 : : "-l", "-5-7" };
542 : : /* core number is maximum value */
543 : 1 : const char * const argv13[] = { prgname, prefix, mp_flag, eal_debug_logs,
544 : : "-l", RTE_STR(RTE_MAX_LCORE) };
545 : 1 : const char * const argv14[] = { prgname, prefix, mp_flag, eal_debug_logs,
546 : : "-l", "1-"RTE_STR(RTE_MAX_LCORE) };
547 : : /* sanity check test - valid corelist value */
548 : 1 : const char * const argv15[] = { prgname, prefix, mp_flag, eal_debug_logs,
549 : : "-l", "1-2,3" };
550 : :
551 : : /* --lcores flag but no lcores value */
552 : 1 : const char * const argv16[] = { prgname, prefix, mp_flag, eal_debug_logs,
553 : : "--lcores" };
554 : 1 : const char * const argv17[] = { prgname, prefix, mp_flag, eal_debug_logs,
555 : : "--lcores", " " };
556 : : /* bad lcores value */
557 : 1 : const char * const argv18[] = { prgname, prefix, mp_flag, eal_debug_logs,
558 : : "--lcores", "1-3-5" };
559 : 1 : const char * const argv19[] = { prgname, prefix, mp_flag, eal_debug_logs,
560 : : "--lcores", "0-1,,2" };
561 : 1 : const char * const argv20[] = { prgname, prefix, mp_flag, eal_debug_logs,
562 : : "--lcores", "0-,1" };
563 : 1 : const char * const argv21[] = { prgname, prefix, mp_flag, eal_debug_logs,
564 : : "--lcores", "(0-,2-4)" };
565 : 1 : const char * const argv22[] = { prgname, prefix, mp_flag, eal_debug_logs,
566 : : "--lcores", "(-1,2)" };
567 : 1 : const char * const argv23[] = { prgname, prefix, mp_flag, eal_debug_logs,
568 : : "--lcores", "(2-4)@(2-4-6)" };
569 : 1 : const char * const argv24[] = { prgname, prefix, mp_flag, eal_debug_logs,
570 : : "--lcores", "(a,2)" };
571 : 1 : const char * const argv25[] = { prgname, prefix, mp_flag, eal_debug_logs,
572 : : "--lcores", "1-3@(1,3)" };
573 : 1 : const char * const argv26[] = { prgname, prefix, mp_flag, eal_debug_logs,
574 : : "--lcores", "3@((1,3)" };
575 : 1 : const char * const argv27[] = { prgname, prefix, mp_flag, eal_debug_logs,
576 : : "--lcores", "(4-7)=(1,3)" };
577 : 1 : const char * const argv28[] = { prgname, prefix, mp_flag, eal_debug_logs,
578 : : "--lcores", "[4-7]@(1,3)" };
579 : : /* sanity check of tests - valid lcores value */
580 : 1 : const char * const argv29[] = { prgname, prefix, mp_flag, eal_debug_logs,
581 : : "--lcores",
582 : : "0-1,2@(5-7),(3-5)@(0,2),(0,6),7"};
583 : : /* check an invalid cpu value >= CPU_SETSIZE */
584 : 1 : const char * const argv30[] = { prgname, prefix, mp_flag, eal_debug_logs,
585 : : "--lcores", "3@" RTE_STR(CPU_SETSIZE) };
586 : :
587 [ - + ]: 1 : if (launch_proc(argv2) != 0) {
588 : : printf("Error (line %d) - process did not run ok when missing -c flag\n",
589 : : __LINE__);
590 : 0 : return -1;
591 : : }
592 : :
593 [ + - ]: 1 : if (launch_proc(argv1) == 0
594 [ - + ]: 1 : || launch_proc(argv3) == 0) {
595 : : printf("Error (line %d) - process ran without error with invalid -c flag\n",
596 : : __LINE__);
597 : 0 : return -1;
598 : : }
599 [ - + ]: 1 : if (launch_proc(argv4) != 0) {
600 : : printf("Error (line %d) - process did not run ok with valid coremask value\n",
601 : : __LINE__);
602 : 0 : return -1;
603 : : }
604 : :
605 : : /* start -l test */
606 [ + - ]: 1 : if (launch_proc(argv5) == 0
607 [ + - ]: 1 : || launch_proc(argv6) == 0
608 [ + - ]: 1 : || launch_proc(argv7) == 0
609 [ + - ]: 1 : || launch_proc(argv8) == 0
610 [ + - ]: 1 : || launch_proc(argv9) == 0
611 [ + - ]: 1 : || launch_proc(argv10) == 0
612 [ + - ]: 1 : || launch_proc(argv11) == 0
613 [ + - ]: 1 : || launch_proc(argv12) == 0
614 [ + - ]: 1 : || launch_proc(argv13) == 0
615 [ - + ]: 1 : || launch_proc(argv14) == 0) {
616 : : printf("Error (line %d) - process ran without error with invalid -l flag\n",
617 : : __LINE__);
618 : 0 : return -1;
619 : : }
620 [ + - + - : 2 : if (rte_lcore_is_enabled(0) && rte_lcore_is_enabled(1) &&
- + ]
621 [ - - - - ]: 1 : rte_lcore_is_enabled(2) && rte_lcore_is_enabled(3) &&
622 : 0 : launch_proc(argv15) != 0) {
623 : : printf("Error (line %d) - process did not run ok with valid corelist value\n",
624 : : __LINE__);
625 : 0 : return -1;
626 : : }
627 : :
628 : : /* start --lcores tests */
629 [ + - + - : 2 : if (launch_proc(argv16) == 0 || launch_proc(argv17) == 0 ||
+ - ]
630 [ + - + - ]: 3 : launch_proc(argv18) == 0 || launch_proc(argv19) == 0 ||
631 [ + - + - ]: 3 : launch_proc(argv20) == 0 || launch_proc(argv21) == 0 ||
632 [ + - + - ]: 3 : launch_proc(argv22) == 0 || launch_proc(argv23) == 0 ||
633 [ + - + - ]: 3 : launch_proc(argv24) == 0 || launch_proc(argv25) == 0 ||
634 [ + - + - ]: 3 : launch_proc(argv26) == 0 || launch_proc(argv27) == 0 ||
635 [ - + ]: 2 : launch_proc(argv28) == 0 || launch_proc(argv30) == 0) {
636 : : printf("Error (line %d) - process ran without error with invalid --lcores flag\n",
637 : : __LINE__);
638 : 0 : return -1;
639 : : }
640 : :
641 [ + - + - : 2 : if (rte_lcore_is_enabled(0) && rte_lcore_is_enabled(1) &&
- + ]
642 [ - - - - ]: 1 : rte_lcore_is_enabled(2) && rte_lcore_is_enabled(3) &&
643 [ # # # # ]: 0 : rte_lcore_is_enabled(4) && rte_lcore_is_enabled(5) &&
644 [ # # # # ]: 0 : rte_lcore_is_enabled(6) && rte_lcore_is_enabled(7) &&
645 : 0 : launch_proc(argv29) != 0) {
646 : : printf("Error (line %d) - process did not run ok with valid corelist value\n",
647 : : __LINE__);
648 : 0 : return -1;
649 : : }
650 : :
651 : : return 0;
652 : : }
653 : :
654 : : /*
655 : : * Test --main-lcore option with matching coremask
656 : : */
657 : : static int
658 : 1 : test_main_lcore_flag(void)
659 : : {
660 : 1 : const char *prefix = file_prefix_arg();
661 [ + - ]: 1 : if (prefix == NULL)
662 : : return -1;
663 : :
664 [ + - - + ]: 1 : if (!rte_lcore_is_enabled(0) || !rte_lcore_is_enabled(1))
665 : 0 : return TEST_SKIPPED;
666 : :
667 : : /* --main-lcore flag but no value */
668 : 1 : const char *argv1[] = { prgname, prefix, mp_flag, eal_debug_logs,
669 : : "-c", "3", "--main-lcore"};
670 : : /* --main-lcore flag with invalid value */
671 : 1 : const char *argv2[] = { prgname, prefix, mp_flag, eal_debug_logs,
672 : : "-c", "3", "--main-lcore", "-1"};
673 : 1 : const char *argv3[] = { prgname, prefix, mp_flag, eal_debug_logs,
674 : : "-c", "3", "--main-lcore", "X"};
675 : : /* main lcore not in coremask */
676 : 1 : const char *argv4[] = { prgname, prefix, mp_flag, eal_debug_logs,
677 : : "-c", "3", "--main-lcore", "2"};
678 : : /* valid value */
679 : 1 : const char *argv5[] = { prgname, prefix, mp_flag, eal_debug_logs,
680 : : "-c", "3", "--main-lcore", "1"};
681 : : /* valid value set before coremask */
682 : 1 : const char *argv6[] = { prgname, prefix, mp_flag, eal_debug_logs,
683 : : "--main-lcore", "1", "-c", "3"};
684 : :
685 [ + - ]: 1 : if (launch_proc(argv1) == 0
686 [ + - ]: 1 : || launch_proc(argv2) == 0
687 [ + - ]: 1 : || launch_proc(argv3) == 0
688 [ - + ]: 1 : || launch_proc(argv4) == 0) {
689 : : printf("Error (line %d) - process ran without error with wrong --main-lcore\n",
690 : : __LINE__);
691 : 0 : return -1;
692 : : }
693 [ + - ]: 1 : if (launch_proc(argv5) != 0
694 [ - + ]: 1 : || launch_proc(argv6) != 0) {
695 : : printf("Error (line %d) - process did not run ok with valid --main-lcore\n",
696 : : __LINE__);
697 : 0 : return -1;
698 : : }
699 : : return 0;
700 : : }
701 : :
702 : : /*
703 : : * Test that the app doesn't run with invalid -n flag option.
704 : : * Final test ensures it does run with valid options as sanity check
705 : : * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
706 : : * flags.
707 : : */
708 : : static int
709 : 1 : test_invalid_n_flag(void)
710 : : {
711 : 1 : const char *prefix = file_prefix_arg();
712 [ + - ]: 1 : if (prefix == NULL)
713 : : return -1;
714 : :
715 : : /* -n flag but no value */
716 : 1 : const char *argv1[] = { prgname, prefix, no_huge, no_shconf,
717 : : "-n"};
718 : : /* bad numeric value */
719 : 1 : const char *argv2[] = { prgname, prefix, no_huge, no_shconf,
720 : : "-n", "e" };
721 : : /* zero is invalid */
722 : 1 : const char *argv3[] = { prgname, prefix, no_huge, no_shconf,
723 : : "-n", "0" };
724 : : /* sanity test - check with good value */
725 : 1 : const char *argv4[] = { prgname, prefix, no_huge, no_shconf,
726 : : "-n", "2" };
727 : : /* sanity test - check with no -n flag */
728 : 1 : const char *argv5[] = { prgname, prefix, no_huge, no_shconf};
729 : :
730 [ + - ]: 1 : if (launch_proc(argv1) == 0
731 [ + - ]: 1 : || launch_proc(argv2) == 0
732 [ - + ]: 1 : || launch_proc(argv3) == 0) {
733 : : printf("Error (line %d) - process ran without error when invalid -n flag\n",
734 : : __LINE__);
735 : 0 : return -1;
736 : : }
737 [ - + ]: 1 : if (launch_proc(argv4) != 0) {
738 : : printf("Error (line %d) - process did not run ok with valid num-channel value\n",
739 : : __LINE__);
740 : 0 : return -1;
741 : : }
742 [ - + ]: 1 : if (launch_proc(argv5) != 0) {
743 : : printf("Error (line %d) - process did not run ok without -n flag\n", __LINE__);
744 : 0 : return -1;
745 : : }
746 : :
747 : : return 0;
748 : : }
749 : :
750 : : /*
751 : : * Test that the app runs with HPET, and without HPET
752 : : */
753 : : static int
754 : 1 : test_no_hpet_flag(void)
755 : : {
756 : : #ifdef RTE_EXEC_ENV_FREEBSD
757 : : return 0;
758 : : #else
759 : 1 : const char *prefix = file_prefix_arg();
760 [ - + ]: 1 : if (prefix == NULL) {
761 : : printf("Error (line %d) - unable to get current prefix!\n", __LINE__);
762 : 0 : return -1;
763 : : }
764 : :
765 : : /* With --no-hpet */
766 : 1 : const char *argv1[] = {prgname, prefix, mp_flag, eal_debug_logs, no_hpet};
767 : : /* Without --no-hpet */
768 : 1 : const char *argv2[] = {prgname, prefix, mp_flag, eal_debug_logs};
769 : :
770 [ - + ]: 1 : if (launch_proc(argv1) != 0) {
771 : : printf("Error (line %d) - process did not run ok with --no-hpet flag\n", __LINE__);
772 : 0 : return -1;
773 : : }
774 [ - + ]: 1 : if (launch_proc(argv2) != 0) {
775 : : printf("Error (line %d) - process did not run ok without --no-hpet flag\n",
776 : : __LINE__);
777 : 0 : return -1;
778 : : }
779 : : return 0;
780 : : #endif
781 : : }
782 : :
783 : : /*
784 : : * Test that the app runs with --no-huge and doesn't run when --socket-mem are
785 : : * specified with --no-huge.
786 : : */
787 : : static int
788 : 1 : test_no_huge_flag(void)
789 : : {
790 : : #ifdef RTE_EXEC_ENV_FREEBSD
791 : : /* BSD target doesn't support prefixes at this point, and we also need to
792 : : * run another primary process here */
793 : : const char * prefix = no_shconf;
794 : : #else
795 : : const char * prefix = "--file-prefix=nohuge";
796 : : #endif
797 : :
798 : : /* With --no-huge */
799 : 1 : const char *argv1[] = {prgname, prefix, no_huge};
800 : : /* With --no-huge and -m */
801 : 1 : const char *argv2[] = {prgname, prefix, no_huge,
802 : : "-m", DEFAULT_MEM_SIZE};
803 : :
804 [ - + ]: 1 : if (launch_proc(argv1) != 0) {
805 : : printf("Error - process did not run ok with --no-huge flag\n");
806 : 0 : return -1;
807 : : }
808 [ - + ]: 1 : if (launch_proc(argv2) != 0) {
809 : : printf("Error - process did not run ok with --no-huge and -m flags\n");
810 : 0 : return -1;
811 : : }
812 : : #ifndef RTE_EXEC_ENV_FREEBSD
813 : : /* With --no-huge and --socket-mem */
814 : 1 : const char *argv3[] = {prgname, prefix, no_huge,
815 : : "--socket-mem=" DEFAULT_MEM_SIZE};
816 : : /* With --no-huge, -m and --socket-mem */
817 : 1 : const char *argv4[] = {prgname, prefix, no_huge,
818 : : "-m", DEFAULT_MEM_SIZE, "--socket-mem=" DEFAULT_MEM_SIZE};
819 : :
820 : : /* With --no-huge and --huge-worker-stack (should fail) */
821 : 1 : const char * const argv5[] = {prgname, prefix, no_huge,
822 : : "--huge-worker-stack"};
823 : : /* With --no-huge and --huge-worker-stack=512 (should fail) */
824 : 1 : const char * const argv6[] = {prgname, prefix, no_huge,
825 : : "--huge-worker-stack=512"};
826 : :
827 [ - + ]: 1 : if (launch_proc(argv3) == 0) {
828 : : printf("Error (line %d) - process run ok with --no-huge and --socket-mem flags\n",
829 : : __LINE__);
830 : 0 : return -1;
831 : : }
832 [ - + ]: 1 : if (launch_proc(argv4) == 0) {
833 : : printf("Error (line %d) - process run ok with --no-huge, -m and --socket-mem flags\n",
834 : : __LINE__);
835 : 0 : return -1;
836 : : }
837 [ - + ]: 1 : if (launch_proc(argv5) == 0) {
838 : : printf("Error (line %d) - process run ok with --no-huge and --huge-worker-stack flags\n",
839 : : __LINE__);
840 : 0 : return -1;
841 : : }
842 [ - + ]: 1 : if (launch_proc(argv6) == 0) {
843 : : printf("Error (line %d) - process run ok with --no-huge and --huge-worker-stack=size flags\n",
844 : : __LINE__);
845 : 0 : return -1;
846 : : }
847 : : #endif /* !RTE_EXEC_ENV_FREEBSD */
848 : : return 0;
849 : : }
850 : :
851 : : static int
852 : 1 : test_misc_flags(void)
853 : : {
854 : : const char *hugepath = "";
855 : : char hugepath_dir[PATH_MAX];
856 : : char hugepath_dir2[PATH_MAX];
857 : : char hugepath_dir3[PATH_MAX];
858 : : #ifdef RTE_EXEC_ENV_FREEBSD
859 : : /* BSD target doesn't support prefixes at this point */
860 : : const char * prefix = "";
861 : : const char * nosh_prefix = "";
862 : : #else
863 : 1 : const char *prefix = file_prefix_arg();
864 : : const char * nosh_prefix = "--file-prefix=noshconf";
865 : : struct mntent *entry;
866 : :
867 [ - + ]: 1 : if (prefix == NULL) {
868 : : printf("Error (line %d) - unable to get current prefix!\n", __LINE__);
869 : 0 : return -1;
870 : : }
871 : :
872 : : /*
873 : : * get first valid hugepage path
874 : : */
875 : :
876 : : /* get hugetlbfs mountpoints from /proc/mounts */
877 : 1 : FILE *mounts = setmntent("/proc/mounts", "r");
878 [ - + ]: 1 : if (mounts == NULL) {
879 : : printf("Error (line %d) - cannot open /proc/mounts!\n", __LINE__);
880 : 0 : return -1;
881 : : }
882 : :
883 : : /* foreach mount point */
884 : : hugepath = NULL;
885 [ + - ]: 10 : while ((entry = getmntent(mounts)) != NULL) {
886 : : /* only want hugetlbfs filesystems */
887 [ + + ]: 10 : if (strcmp(entry->mnt_type, FS_HUGETLB) == 0) {
888 : 1 : hugepath = strdupa(entry->mnt_dir);
889 : 1 : break;
890 : : }
891 : : }
892 : 1 : endmntent(mounts);
893 : :
894 [ - + ]: 1 : if (hugepath == NULL) {
895 : : printf("No mounted hugepage dir found!\n");
896 : 0 : return -1;
897 : : }
898 : : #endif
899 : :
900 : : snprintf(hugepath_dir, sizeof(hugepath_dir), "%s/dpdk.missing", hugepath);
901 : : snprintf(hugepath_dir2, sizeof(hugepath_dir2), "%s/dpdk.dir", hugepath);
902 : :
903 [ - + - - ]: 1 : if (mkdir(hugepath_dir2, 0700) != 0 && errno != EEXIST) {
904 : : printf("Error (line %d) - failed to mkdir(%s)\n", __LINE__, hugepath_dir2);
905 : 0 : return -1;
906 : : }
907 : :
908 : : snprintf(hugepath_dir3, sizeof(hugepath_dir3), "%s/dpdk.dir/sub", hugepath);
909 : :
910 [ - + - - ]: 1 : if (mkdir(hugepath_dir3, 0700) != 0 && errno != EEXIST) {
911 : : printf("Error (line %d) - failed to mkdir(%s)\n", __LINE__, hugepath_dir3);
912 : 0 : goto fail;
913 : : }
914 : :
915 : : /* check that some general flags don't prevent things from working.
916 : : * All cases, apart from the first, app should run.
917 : : * No further testing of output done.
918 : : */
919 : : /* sanity check - failure with invalid option */
920 : 1 : const char *argv0[] = {prgname, prefix, mp_flag, eal_debug_logs, "--invalid-opt"};
921 : :
922 : : /* With --no-pci */
923 : 1 : const char *argv1[] = {prgname, prefix, mp_flag, eal_debug_logs, "--no-pci"};
924 : : /* With -v */
925 : 1 : const char *argv2[] = {prgname, prefix, mp_flag, eal_debug_logs, "-v"};
926 : : /* With valid --syslog */
927 : 1 : const char *argv3[] = {prgname, prefix, mp_flag, eal_debug_logs, "--syslog=user"};
928 : : /* With empty --syslog (now defaults) */
929 : 1 : const char *argv4[] = {prgname, prefix, mp_flag, eal_debug_logs, "--syslog"};
930 : : /* With invalid --syslog */
931 : 1 : const char *argv5[] = {prgname, prefix, mp_flag, eal_debug_logs, "--syslog=invalid"};
932 : :
933 : : /* With no-sh-conf, also use no-huge to ensure this test runs on BSD */
934 : 1 : const char *argv6[] = {prgname, eal_debug_logs, no_pci, "-m", DEFAULT_MEM_SIZE,
935 : : no_shconf, nosh_prefix, no_huge};
936 : :
937 : : /* With --huge-dir */
938 : 1 : const char *argv7[] = {prgname, "-m", DEFAULT_MEM_SIZE,
939 : : eal_debug_logs, no_pci,
940 : : "--file-prefix=hugedir", "--huge-dir", hugepath};
941 : : /* With empty --huge-dir (should fail) */
942 : 1 : const char *argv8[] = {prgname, "-m", DEFAULT_MEM_SIZE,
943 : : eal_debug_logs, no_pci,
944 : : "--file-prefix=hugedir", "--huge-dir"};
945 : : /* With invalid --huge-dir */
946 : 1 : const char *argv9[] = {prgname, "-m", DEFAULT_MEM_SIZE,
947 : : eal_debug_logs, no_pci,
948 : : "--file-prefix=hugedir", "--huge-dir", "invalid"};
949 : : /* With invalid --huge-dir sub-directory */
950 : 1 : const char *argv10[] = {prgname, "-m", DEFAULT_MEM_SIZE,
951 : : eal_debug_logs, no_pci,
952 : : "--file-prefix=hugedir", "--huge-dir", hugepath_dir};
953 : : /* With valid --huge-dir sub-directory */
954 : 1 : const char *argv11[] = {prgname, "-m", DEFAULT_MEM_SIZE,
955 : : eal_debug_logs, no_pci,
956 : : "--file-prefix=hugedir", "--huge-dir", hugepath_dir2};
957 : : /* Secondary process with invalid --huge-dir (should run as flag has no
958 : : * effect on secondary processes) */
959 : 1 : const char *argv12[] = {prgname, prefix, mp_flag, eal_debug_logs,
960 : : "--huge-dir", "invalid"};
961 : :
962 : : /* try running with base-virtaddr param */
963 : 1 : const char *argv13[] = {prgname, "--file-prefix=virtaddr",
964 : : eal_debug_logs, no_pci,
965 : : "--base-virtaddr=0x23456789"};
966 : :
967 : : /* try running with --vfio-intr INTx flag */
968 : 1 : const char *argv14[] = {prgname, "--file-prefix=intr",
969 : : eal_debug_logs, no_pci,
970 : : "--vfio-intr=legacy"};
971 : :
972 : : /* try running with --vfio-intr MSI flag */
973 : 1 : const char *argv15[] = {prgname, "--file-prefix=intr",
974 : : eal_debug_logs, no_pci,
975 : : "--vfio-intr=msi"};
976 : :
977 : : /* try running with --vfio-intr MSI-X flag */
978 : 1 : const char *argv16[] = {prgname, "--file-prefix=intr",
979 : : eal_debug_logs, no_pci,
980 : : "--vfio-intr=msix"};
981 : :
982 : : /* try running with --vfio-intr invalid flag */
983 : 1 : const char *argv17[] = {prgname, "--file-prefix=intr",
984 : : eal_debug_logs, no_pci,
985 : : "--vfio-intr=invalid"};
986 : :
987 : : /* With process type as auto-detect */
988 : 1 : const char * const argv18[] = {prgname, "--file-prefix=auto",
989 : : eal_debug_logs, no_pci,
990 : : "--proc-type=auto"};
991 : :
992 : : /* With process type as auto-detect with no-shconf */
993 : 1 : const char * const argv19[] = {prgname, "--proc-type=auto", eal_debug_logs, no_pci,
994 : : no_shconf, nosh_prefix, no_huge};
995 : :
996 : : /* With process type as --create-uio-dev flag */
997 : 1 : const char * const argv20[] = {prgname, "--file-prefix=uiodev",
998 : : eal_debug_logs, no_pci,
999 : : "--create-uio-dev"};
1000 : :
1001 : : /* Try running with --huge-worker-stack flag */
1002 : 1 : const char * const argv21[] = {prgname, prefix, mp_flag, eal_debug_logs,
1003 : : "--huge-worker-stack"};
1004 : :
1005 : : /* Try running with --huge-worker-stack=512 flag */
1006 : 1 : const char * const argv22[] = {prgname, prefix, mp_flag, eal_debug_logs,
1007 : : "--huge-worker-stack=512"};
1008 : :
1009 : : /* Try running with --log-timestamp */
1010 : 1 : const char * const argv23[] = {prgname, prefix, mp_flag, eal_debug_logs,
1011 : : "--log-timestamp" };
1012 : :
1013 : : /* Try running with --log-timestamp=iso */
1014 : 1 : const char * const argv24[] = {prgname, prefix, mp_flag, eal_debug_logs,
1015 : : "--log-timestamp=iso" };
1016 : :
1017 : : /* Try running with invalid timestamp */
1018 : 1 : const char * const argv25[] = {prgname, prefix, mp_flag, eal_debug_logs,
1019 : : "--log-timestamp=invalid" };
1020 : :
1021 : : /* Try running with --log-color */
1022 : 1 : const char * const argv26[] = {prgname, prefix, mp_flag, eal_debug_logs,
1023 : : "--log-color" };
1024 : :
1025 : : /* Try running with --log-color=never */
1026 : 1 : const char * const argv27[] = {prgname, prefix, mp_flag, eal_debug_logs,
1027 : : "--log-color=never" };
1028 : :
1029 : : /* Try running with --log-color=invalid */
1030 : 1 : const char * const argv28[] = {prgname, prefix, mp_flag, eal_debug_logs,
1031 : : "--log-color=invalid" };
1032 : :
1033 : : /* run all tests also applicable to FreeBSD first */
1034 : :
1035 [ - + ]: 1 : if (launch_proc(argv0) == 0) {
1036 : : printf("Error (line %d) - process ran ok with invalid flag\n", __LINE__);
1037 : 0 : goto fail;
1038 : : }
1039 [ - + ]: 1 : if (launch_proc(argv1) != 0) {
1040 : : printf("Error (line %d) - process did not run ok with --no-pci flag\n", __LINE__);
1041 : 0 : goto fail;
1042 : : }
1043 [ - + ]: 1 : if (launch_proc(argv2) != 0) {
1044 : : printf("Error (line %d) - process did not run ok with -v flag\n", __LINE__);
1045 : 0 : goto fail;
1046 : : }
1047 [ - + ]: 1 : if (launch_proc(argv6) != 0) {
1048 : : printf("Error (line %d) - process did not run ok with --no-shconf flag\n",
1049 : : __LINE__);
1050 : 0 : goto fail;
1051 : : }
1052 : :
1053 : : #ifdef RTE_EXEC_ENV_FREEBSD
1054 : : /* no more tests to be done on FreeBSD */
1055 : : return 0;
1056 : : #endif
1057 : :
1058 [ - + ]: 1 : if (launch_proc(argv3) != 0) {
1059 : : printf("Error (line %d) - process did not run ok with --syslog=user flag\n",
1060 : : __LINE__);
1061 : 0 : goto fail;
1062 : : }
1063 [ - + ]: 1 : if (launch_proc(argv4) != 0) {
1064 : : printf("Error (line %d) - process did not run ok with --syslog flag\n", __LINE__);
1065 : 0 : goto fail;
1066 : : }
1067 [ - + ]: 1 : if (launch_proc(argv5) == 0) {
1068 : : printf("Error (line %d) - process run ok with --syslog=invalid flag\n", __LINE__);
1069 : 0 : goto fail;
1070 : : }
1071 [ - + ]: 1 : if (launch_proc(argv7) != 0) {
1072 : : printf("Error (line %d) - process did not run ok with --huge-dir flag\n",
1073 : : __LINE__);
1074 : 0 : goto fail;
1075 : : }
1076 [ - + ]: 1 : if (launch_proc(argv8) == 0) {
1077 : : printf("Error (line %d) - process run ok with empty --huge-dir flag\n", __LINE__);
1078 : 0 : goto fail;
1079 : : }
1080 [ - + ]: 1 : if (launch_proc(argv9) == 0) {
1081 : : printf("Error (line %d) - process run ok with invalid --huge-dir flag\n", __LINE__);
1082 : 0 : goto fail;
1083 : : }
1084 [ - + ]: 1 : if (launch_proc(argv10) == 0) {
1085 : : printf("Error (line %d) - process run ok with invalid --huge-dir sub-dir flag\n",
1086 : : __LINE__);
1087 : 0 : goto fail;
1088 : : }
1089 [ - + ]: 1 : if (launch_proc(argv11) != 0) {
1090 : : printf("Error (line %d) - process did not run ok with --huge-dir subdir flag\n",
1091 : : __LINE__);
1092 : 0 : goto fail;
1093 : : }
1094 [ - + ]: 1 : if (launch_proc(argv12) != 0) {
1095 : : printf("Error (line %d) - secondary process did not run ok with invalid --huge-dir flag\n",
1096 : : __LINE__);
1097 : 0 : goto fail;
1098 : : }
1099 [ - + ]: 1 : if (launch_proc(argv13) != 0) {
1100 : : printf("Error (line %d) - process did not run ok with --base-virtaddr parameter\n",
1101 : : __LINE__);
1102 : 0 : goto fail;
1103 : : }
1104 [ - + ]: 1 : if (launch_proc(argv14) != 0) {
1105 : : printf("Error (line %d) - process did not run ok with --vfio-intr INTx parameter\n",
1106 : : __LINE__);
1107 : 0 : goto fail;
1108 : : }
1109 [ - + ]: 1 : if (launch_proc(argv15) != 0) {
1110 : : printf("Error (line %d) - process did not run ok with --vfio-intr MSI parameter\n",
1111 : : __LINE__);
1112 : 0 : goto fail;
1113 : : }
1114 [ - + ]: 1 : if (launch_proc(argv16) != 0) {
1115 : : printf("Error (line %d) - process did not run ok with --vfio-intr MSI-X parameter\n",
1116 : : __LINE__);
1117 : 0 : goto fail;
1118 : : }
1119 [ - + ]: 1 : if (launch_proc(argv17) == 0) {
1120 : : printf("Error (line %d) - process run ok with --vfio-intr invalid parameter\n",
1121 : : __LINE__);
1122 : 0 : goto fail;
1123 : : }
1124 [ - + ]: 1 : if (launch_proc(argv18) != 0) {
1125 : : printf("Error (line %d) - process did not run ok with --proc-type as auto parameter\n",
1126 : : __LINE__);
1127 : 0 : goto fail;
1128 : : }
1129 [ - + ]: 1 : if (launch_proc(argv19) != 0) {
1130 : : printf("Error (line %d) - process did not run ok with --proc-type and --no-shconf parameter\n",
1131 : : __LINE__);
1132 : 0 : goto fail;
1133 : : }
1134 [ - + ]: 1 : if (launch_proc(argv20) != 0) {
1135 : : printf("Error (line %d) - process did not run ok with --create-uio-dev parameter\n",
1136 : : __LINE__);
1137 : 0 : goto fail;
1138 : : }
1139 [ - + ]: 1 : if (launch_proc(argv21) != 0) {
1140 : : printf("Error (line %d) - process did not run ok with --huge-worker-stack parameter\n",
1141 : : __LINE__);
1142 : 0 : goto fail;
1143 : : }
1144 [ - + ]: 1 : if (launch_proc(argv22) != 0) {
1145 : : printf("Error (line %d) - process did not run ok with --huge-worker-stack=size parameter\n",
1146 : : __LINE__);
1147 : 0 : goto fail;
1148 : : }
1149 [ - + ]: 1 : if (launch_proc(argv23) != 0) {
1150 : : printf("Error (line %d) - process did not run ok with --log-timestamp parameter\n",
1151 : : __LINE__);
1152 : 0 : goto fail;
1153 : : }
1154 [ - + ]: 1 : if (launch_proc(argv24) != 0) {
1155 : : printf("Error (line %d) - process did not run ok with --log-timestamp=iso parameter\n",
1156 : : __LINE__);
1157 : 0 : goto fail;
1158 : : }
1159 [ - + ]: 1 : if (launch_proc(argv25) == 0) {
1160 : : printf("Error (line %d) - process did run ok with --log-timestamp=invalid parameter\n",
1161 : : __LINE__);
1162 : 0 : goto fail;
1163 : : }
1164 [ - + ]: 1 : if (launch_proc(argv26) != 0) {
1165 : : printf("Error (line %d) - process did not run ok with --log-color parameter\n",
1166 : : __LINE__);
1167 : 0 : goto fail;
1168 : : }
1169 [ - + ]: 1 : if (launch_proc(argv27) != 0) {
1170 : : printf("Error (line %d) - process did not run ok with --log-color=never parameter\n",
1171 : : __LINE__);
1172 : 0 : goto fail;
1173 : : }
1174 [ - + ]: 1 : if (launch_proc(argv28) == 0) {
1175 : : printf("Error (line %d) - process did run ok with --log-timestamp=invalid parameter\n",
1176 : : __LINE__);
1177 : 0 : goto fail;
1178 : : }
1179 : :
1180 : 1 : rmdir(hugepath_dir3);
1181 : 1 : rmdir(hugepath_dir2);
1182 : 1 : return 0;
1183 : :
1184 : 0 : fail:
1185 : 0 : rmdir(hugepath_dir3);
1186 : 0 : rmdir(hugepath_dir2);
1187 : 0 : return -1;
1188 : : }
1189 : :
1190 : : #ifdef RTE_EXEC_ENV_FREEBSD
1191 : :
1192 : : static int
1193 : : test_file_prefix(void)
1194 : : {
1195 : : printf("file_prefix not supported on FreeBSD, skipping test\n");
1196 : : return TEST_SKIPPED;
1197 : : }
1198 : :
1199 : : #else
1200 : :
1201 : : static int
1202 : 1 : test_file_prefix(void)
1203 : : {
1204 : : /*
1205 : : * 1. check if current process hugefiles are locked
1206 : : * 2. try to run secondary process without a corresponding primary process
1207 : : * (while failing to run, it will also remove any unused hugepage files)
1208 : : * 3. check if current process hugefiles are still in place and are locked
1209 : : * 4. run a primary process with memtest1 prefix in default and legacy
1210 : : * mem mode
1211 : : * 5. check if memtest1 hugefiles are created in case of legacy mem
1212 : : * mode, and deleted in case of default mem mode
1213 : : * 6. run a primary process with memtest2 prefix in default and legacy
1214 : : * mem modes
1215 : : * 7. check that memtest2 hugefiles are present in the hugedir after a
1216 : : * run in legacy mode, and not present at all after run in default
1217 : : * mem mode
1218 : : */
1219 : : char prefix[PATH_MAX];
1220 : :
1221 : : if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
1222 : : printf("Error (line %d) - unable to get current prefix!\n", __LINE__);
1223 : : return -1;
1224 : : }
1225 : :
1226 : : /* this should fail unless the test itself is run with "memtest" prefix */
1227 : 1 : const char *argv0[] = {prgname, mp_flag, eal_debug_logs, "-m",
1228 : : DEFAULT_MEM_SIZE, "--file-prefix=" memtest };
1229 : :
1230 : : /* primary process with memtest1 and default mem mode */
1231 : 1 : const char *argv1[] = {prgname, eal_debug_logs, no_pci, "-m",
1232 : : DEFAULT_MEM_SIZE, "--file-prefix=" memtest1 };
1233 : :
1234 : : /* primary process with memtest1 and legacy mem mode */
1235 : 1 : const char *argv2[] = {prgname, eal_debug_logs, no_pci, "-m",
1236 : : DEFAULT_MEM_SIZE, "--file-prefix=" memtest1,
1237 : : "--legacy-mem" };
1238 : :
1239 : : /* primary process with memtest2 and legacy mem mode */
1240 : 1 : const char *argv3[] = {prgname, eal_debug_logs, no_pci, "-m",
1241 : : DEFAULT_MEM_SIZE, "--file-prefix=" memtest2,
1242 : : "--legacy-mem" };
1243 : :
1244 : : /* primary process with memtest2 and default mem mode */
1245 : 1 : const char *argv4[] = {prgname, eal_debug_logs, no_pci, "-m",
1246 : : DEFAULT_MEM_SIZE, "--file-prefix=" memtest2 };
1247 : :
1248 : : /* primary process with --in-memory mode */
1249 : 1 : const char * const argv5[] = {prgname, eal_debug_logs, no_pci, "-m",
1250 : : DEFAULT_MEM_SIZE, "--in-memory" };
1251 : :
1252 : : /* primary process with memtest1 and --in-memory mode */
1253 : 1 : const char * const argv6[] = {prgname, eal_debug_logs, no_pci, "-m",
1254 : : DEFAULT_MEM_SIZE, "--in-memory",
1255 : : "--file-prefix=" memtest1 };
1256 : :
1257 : : /* primary process with parent file-prefix and --in-memory mode */
1258 : 1 : const char * const argv7[] = {prgname, eal_debug_logs, no_pci, "-m",
1259 : : DEFAULT_MEM_SIZE, "--in-memory", "--file-prefix", prefix };
1260 : :
1261 : : /* primary process with memtest1 and --single-file-segments mode */
1262 : 1 : const char * const argv8[] = {prgname, eal_debug_logs, no_pci, "-m",
1263 : : DEFAULT_MEM_SIZE, "--single-file-segments",
1264 : : "--file-prefix=" memtest1 };
1265 : :
1266 : : /* primary process with memtest1 and --huge-unlink=never mode */
1267 : 1 : const char * const argv9[] = {prgname, eal_debug_logs, no_pci, "-m",
1268 : : DEFAULT_MEM_SIZE, "--huge-unlink=never",
1269 : : "--file-prefix=" memtest1 };
1270 : :
1271 : : /* check if files for current prefix are present */
1272 [ - + ]: 1 : if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1273 : : printf("Error (line %d) - hugepage files for %s were not created!\n",
1274 : : __LINE__, prefix);
1275 : 0 : return -1;
1276 : : }
1277 : :
1278 : : /* checks if files for current prefix are locked */
1279 [ - + ]: 1 : if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1280 : : printf("Error (line %d) - hugepages for current process aren't locked!\n",
1281 : : __LINE__);
1282 : 0 : return -1;
1283 : : }
1284 : :
1285 : : /* check if files for secondary process are present */
1286 [ - + ]: 1 : if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
1287 : : /* check if they are not locked */
1288 [ # # ]: 0 : if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
1289 : : printf("Error (line %d) - hugepages for current process are locked!\n",
1290 : : __LINE__);
1291 : 0 : return -1;
1292 : : }
1293 : : /* they aren't locked, delete them */
1294 : : else {
1295 [ # # ]: 0 : if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
1296 : : printf("Error (line %d) - deleting hugepages failed!\n",
1297 : : __LINE__);
1298 : 0 : return -1;
1299 : : }
1300 : : }
1301 : : }
1302 : :
1303 [ - + ]: 1 : if (launch_proc(argv0) == 0) {
1304 : : printf("Error (line %d) - secondary process ran ok without primary process\n",
1305 : : __LINE__);
1306 : 0 : return -1;
1307 : : }
1308 : :
1309 : : /* check if files for current prefix are present */
1310 [ - + ]: 1 : if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1311 : : printf("Error (line %d) - hugepage files for %s were not created!\n",
1312 : : __LINE__, prefix);
1313 : 0 : return -1;
1314 : : }
1315 : :
1316 : : /* checks if files for current prefix are locked */
1317 [ - + ]: 1 : if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1318 : : printf("Error (line %d) - hugepages for current process aren't locked!\n",
1319 : : __LINE__);
1320 : 0 : return -1;
1321 : : }
1322 : :
1323 : : /* we're running this process in default memory mode, which means it
1324 : : * should clean up after itself on exit and leave no hugepages behind.
1325 : : */
1326 [ - + ]: 1 : if (launch_proc(argv1) != 0) {
1327 : : printf("Error (line %d) - failed to run with --file-prefix=%s\n",
1328 : : __LINE__, memtest1);
1329 : 0 : return -1;
1330 : : }
1331 : :
1332 : : /* check if memtest1_map0 is present */
1333 [ - + ]: 1 : if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1334 : : printf("Error (line %d) - hugepage files for %s were not deleted!\n",
1335 : : __LINE__, memtest1);
1336 : 0 : return -1;
1337 : : }
1338 : :
1339 : : /* now, we're running a process under the same prefix, but with legacy
1340 : : * mem mode - this should leave behind hugepage files.
1341 : : */
1342 [ - + ]: 1 : if (launch_proc(argv2) != 0) {
1343 : : printf("Error (line %d) - failed to run with --file-prefix=%s\n",
1344 : : __LINE__, memtest1);
1345 : 0 : return -1;
1346 : : }
1347 : :
1348 : : /* check if memtest1_map0 is present */
1349 [ - + ]: 1 : if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
1350 : : printf("Error (line %d) - hugepage files for %s were not created!\n",
1351 : : __LINE__, memtest1);
1352 : 0 : return -1;
1353 : : }
1354 : :
1355 [ - + ]: 1 : if (launch_proc(argv3) != 0) {
1356 : : printf("Error (line %d) - failed to run with --file-prefix=%s\n",
1357 : : __LINE__, memtest2);
1358 : 0 : return -1;
1359 : : }
1360 : :
1361 : : /* check if hugefiles for memtest2 are present */
1362 [ - + ]: 1 : if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
1363 : : printf("Error (line %d) - hugepage files for %s were not created!\n",
1364 : : __LINE__, memtest2);
1365 : 0 : return -1;
1366 : : }
1367 : :
1368 : : /* check if hugefiles for memtest1 are present */
1369 [ - + ]: 1 : if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1370 : : printf("Error (line %d) - hugepage files for %s were not deleted!\n",
1371 : : __LINE__, memtest1);
1372 : 0 : return -1;
1373 : : }
1374 : :
1375 : : /* this process will run in default mem mode, so it should not leave any
1376 : : * hugepage files behind.
1377 : : */
1378 [ - + ]: 1 : if (launch_proc(argv4) != 0) {
1379 : : printf("Error (line %d) - failed to run with --file-prefix=%s\n",
1380 : : __LINE__, memtest2);
1381 : 0 : return -1;
1382 : : }
1383 : :
1384 : : /* check if hugefiles for memtest2 are present */
1385 [ - + ]: 1 : if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 0) {
1386 : : printf("Error (line %d) - hugepage files for %s were not deleted!\n",
1387 : : __LINE__, memtest2);
1388 : 0 : return -1;
1389 : : }
1390 : :
1391 : : /* check if hugefiles for memtest1 are present */
1392 [ - + ]: 1 : if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1393 : : printf("Error (line %d) - hugepage files for %s were not deleted!\n",
1394 : : __LINE__, memtest1);
1395 : 0 : return -1;
1396 : : }
1397 : :
1398 : : /* this process will run in --in-memory mode, so it should not leave any
1399 : : * hugepage files behind.
1400 : : */
1401 : :
1402 : : /* test case to check eal-options with --in-memory mode */
1403 [ - + ]: 1 : if (launch_proc(argv5) != 0) {
1404 : : printf("Error (line %d) - failed to run with --in-memory mode\n",
1405 : : __LINE__);
1406 : 0 : return -1;
1407 : : }
1408 : :
1409 : : /*test case to check eal-options with --in-memory mode with
1410 : : * custom file-prefix.
1411 : : */
1412 [ - + ]: 1 : if (launch_proc(argv6) != 0) {
1413 : : printf("Error (line %d) - failed to run with --in-memory mode\n", __LINE__);
1414 : 0 : return -1;
1415 : : }
1416 : :
1417 : : /* check if hugefiles for memtest1 are present */
1418 [ - + ]: 1 : if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1419 : : printf("Error (line %d) - hugepage files for %s were created and not deleted!\n",
1420 : : __LINE__, memtest1);
1421 : 0 : return -1;
1422 : : }
1423 : :
1424 : : /* test case to check eal-options with --in-memory mode with
1425 : : * parent file-prefix.
1426 : : */
1427 [ - + ]: 1 : if (launch_proc(argv7) != 0) {
1428 : : printf("Error (line %d) - failed to run with --file-prefix=%s\n", __LINE__, prefix);
1429 : 0 : return -1;
1430 : : }
1431 : :
1432 : : /* this process will run in --single-file-segments mode,
1433 : : * so it should not leave any hugepage files behind.
1434 : : */
1435 [ - + ]: 1 : if (launch_proc(argv8) != 0) {
1436 : : printf("Error (line %d) - failed to run with --single-file-segments mode\n",
1437 : : __LINE__);
1438 : 0 : return -1;
1439 : : }
1440 : :
1441 : : /* check if hugefiles for memtest1 are present */
1442 [ - + ]: 1 : if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1443 : : printf("Error (line %d) - hugepage files for %s were not deleted!\n",
1444 : : __LINE__, memtest1);
1445 : 0 : return -1;
1446 : : }
1447 : :
1448 : : /* this process will run with --huge-unlink,
1449 : : * so it should not remove hugepage files when it exits
1450 : : */
1451 [ - + ]: 1 : if (launch_proc(argv9) != 0) {
1452 : : printf("Error (line %d) - failed to run with --huge-unlink=never\n", __LINE__);
1453 : 0 : return -1;
1454 : : }
1455 : :
1456 : : /* check if hugefiles for memtest1 are present */
1457 [ - + ]: 1 : if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) == 0) {
1458 : : printf("Error (line %d) - hugepage files for %s were deleted!\n",
1459 : : __LINE__, memtest1);
1460 : 0 : return -1;
1461 : : }
1462 [ - + ]: 1 : if (process_hugefiles(memtest1, HUGEPAGE_DELETE) != 1) {
1463 : : printf("Error (line %d) - deleting hugepages failed!\n", __LINE__);
1464 : 0 : return -1;
1465 : : }
1466 : :
1467 : : return 0;
1468 : : }
1469 : : #endif
1470 : :
1471 : : /* This function writes in passed buf pointer a valid --socket-mem= option
1472 : : * for num_sockets then concatenates the provided suffix string.
1473 : : *
1474 : : * Example for num_sockets 4, mem "2", suffix "plop"
1475 : : * --socket-mem=2,2,2,2plop
1476 : : */
1477 : : static void
1478 [ + - ]: 7 : populate_socket_mem_param(int num_sockets, const char *mem,
1479 : : const char *suffix, char *buf, size_t buf_size)
1480 : : {
1481 : : unsigned int offset = 0;
1482 : : int written;
1483 : : int i;
1484 : :
1485 : : written = snprintf(&buf[offset], buf_size - offset, "--socket-mem=");
1486 [ + - + - ]: 7 : if (written < 0 || written + offset >= buf_size)
1487 : : return;
1488 : : offset += written;
1489 : :
1490 [ + + ]: 12 : for (i = 0; i < num_sockets - 1; i++) {
1491 [ + - ]: 5 : written = snprintf(&buf[offset], buf_size - offset,
1492 : : "%s,", mem);
1493 [ + - + - ]: 5 : if (written < 0 || written + offset >= buf_size)
1494 : : return;
1495 : : offset += written;
1496 : : }
1497 : :
1498 : 7 : written = snprintf(&buf[offset], buf_size - offset, "%s%s", mem,
1499 : : suffix);
1500 : : if (written < 0 || written + offset >= buf_size)
1501 : 7 : return;
1502 : : offset += written;
1503 : : }
1504 : :
1505 : : /*
1506 : : * Tests for correct handling of -m and --socket-mem flags
1507 : : */
1508 : : static int
1509 : 1 : test_memory_flags(void)
1510 : : {
1511 : 1 : const char *prefix = file_prefix_arg();
1512 [ - + ]: 1 : if (prefix == NULL) {
1513 : : printf("Error (line %d) - unable to get current prefix!\n", __LINE__);
1514 : 0 : return -1;
1515 : : }
1516 : :
1517 : : /* valid -m flag and mp flag */
1518 : 1 : const char *argv0[] = {prgname, prefix, mp_flag, eal_debug_logs,
1519 : : "-m", DEFAULT_MEM_SIZE};
1520 : :
1521 : : /* valid -m flag */
1522 : 1 : const char *argv1[] = {prgname, eal_debug_logs, no_pci,
1523 : : "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE};
1524 : :
1525 : : /* valid (zero) --socket-mem flag */
1526 : : char arg2_socket_mem[SOCKET_MEM_STRLEN];
1527 : 1 : const char *argv2[] = {prgname, eal_debug_logs, no_pci,
1528 : : "--file-prefix=" memtest, arg2_socket_mem};
1529 : :
1530 : : /* invalid (incomplete) --socket-mem flag */
1531 : : char arg3_socket_mem[SOCKET_MEM_STRLEN];
1532 : 1 : const char *argv3[] = {prgname, eal_debug_logs, no_pci,
1533 : : "--file-prefix=" memtest, arg3_socket_mem};
1534 : :
1535 : : /* invalid (mixed with invalid data) --socket-mem flag */
1536 : : char arg4_socket_mem[SOCKET_MEM_STRLEN];
1537 : 1 : const char *argv4[] = {prgname, eal_debug_logs, no_pci,
1538 : : "--file-prefix=" memtest, arg4_socket_mem};
1539 : :
1540 : : /* invalid (with numeric value as last character) --socket-mem flag */
1541 : : char arg5_socket_mem[SOCKET_MEM_STRLEN];
1542 : 1 : const char *argv5[] = {prgname, eal_debug_logs, no_pci,
1543 : : "--file-prefix=" memtest, arg5_socket_mem};
1544 : :
1545 : : /* invalid (with empty socket) --socket-mem flag */
1546 : : char arg6_socket_mem[SOCKET_MEM_STRLEN];
1547 : 1 : const char *argv6[] = {prgname, eal_debug_logs, no_pci,
1548 : : "--file-prefix=" memtest, arg6_socket_mem};
1549 : :
1550 : : /* invalid (null) --socket-mem flag */
1551 : 1 : const char *argv7[] = {prgname, eal_debug_logs, no_pci,
1552 : : "--file-prefix=" memtest, "--socket-mem="};
1553 : :
1554 : : /* valid --socket-mem specified together with -m flag */
1555 : : char arg8_socket_mem[SOCKET_MEM_STRLEN];
1556 : 1 : const char *argv8[] = {prgname, eal_debug_logs, no_pci,
1557 : : "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE,
1558 : : arg8_socket_mem};
1559 : :
1560 : : #ifdef RTE_EXEC_ENV_FREEBSD
1561 : : int num_sockets = 1;
1562 : : #else
1563 : 1 : int num_sockets = RTE_MIN(get_number_of_sockets(),
1564 : : RTE_MAX_NUMA_NODES);
1565 : : #endif
1566 : :
1567 [ - + ]: 1 : if (num_sockets <= 0) {
1568 : : printf("Error (line %d) - cannot get number of sockets!\n", __LINE__);
1569 : 0 : return -1;
1570 : : }
1571 : :
1572 : : /* invalid --socket-mem flag (with extra socket) */
1573 : : char invalid_socket_mem[SOCKET_MEM_STRLEN];
1574 : 1 : const char *argv9[] = {prgname, eal_debug_logs, no_pci,
1575 : : "--file-prefix=" memtest, invalid_socket_mem};
1576 : :
1577 : : /* valid --socket-mem flag */
1578 : : char valid_socket_mem[SOCKET_MEM_STRLEN];
1579 : 1 : const char *argv10[] = {prgname, eal_debug_logs, no_pci,
1580 : : "--file-prefix=" memtest, valid_socket_mem};
1581 : :
1582 [ - + ]: 1 : if (launch_proc(argv0) != 0) {
1583 : : printf("Error (line %d) - secondary process failed with valid -m flag !\n",
1584 : : __LINE__);
1585 : 0 : return -1;
1586 : : }
1587 : :
1588 : : #ifdef RTE_EXEC_ENV_FREEBSD
1589 : : /* no other tests are applicable to BSD */
1590 : : return 0;
1591 : : #endif
1592 : :
1593 [ - + ]: 1 : if (launch_proc(argv1) != 0) {
1594 : : printf("Error (line %d) - process failed with valid -m flag!\n", __LINE__);
1595 : 0 : return -1;
1596 : : }
1597 : :
1598 : 1 : populate_socket_mem_param(num_sockets, "0", "",
1599 : : arg2_socket_mem, sizeof(arg2_socket_mem));
1600 [ - + ]: 1 : if (launch_proc(argv2) != 0) {
1601 : : printf("Error (line %d) - process failed with valid (zero) --socket-mem!\n",
1602 : : __LINE__);
1603 : 0 : return -1;
1604 : : }
1605 : :
1606 [ + - ]: 1 : if (num_sockets > 1) {
1607 : 1 : populate_socket_mem_param(num_sockets - 1, "2", ",",
1608 : : arg3_socket_mem, sizeof(arg3_socket_mem));
1609 [ - + ]: 1 : if (launch_proc(argv3) == 0) {
1610 : : printf("Error (line %d) - process run ok with invalid (incomplete) --socket-mem!\n",
1611 : : __LINE__);
1612 : 0 : return -1;
1613 : : }
1614 : :
1615 : 1 : populate_socket_mem_param(num_sockets - 1, "2", ",Fred",
1616 : : arg4_socket_mem, sizeof(arg4_socket_mem));
1617 [ - + ]: 1 : if (launch_proc(argv4) == 0) {
1618 : : printf("Error (line %d) - process run ok with invalid (mixed with invalid input) --socket-mem!\n",
1619 : : __LINE__);
1620 : 0 : return -1;
1621 : : }
1622 : :
1623 : 1 : populate_socket_mem_param(num_sockets - 1, "2", ",Fred0",
1624 : : arg5_socket_mem, sizeof(arg5_socket_mem));
1625 [ - + ]: 1 : if (launch_proc(argv5) == 0) {
1626 : : printf("Error (line %d) - process run ok with invalid (mixed with invalid input with a numeric value as last character) --socket-mem!\n",
1627 : : __LINE__);
1628 : 0 : return -1;
1629 : : }
1630 : : }
1631 : :
1632 [ - + ]: 1 : if (num_sockets > 2) {
1633 : 0 : populate_socket_mem_param(num_sockets - 2, "2", ",,2",
1634 : : arg6_socket_mem, sizeof(arg6_socket_mem));
1635 [ # # ]: 0 : if (launch_proc(argv6) == 0) {
1636 : : printf("Error (line %d) - process run ok with invalid (with empty socket) --socket-mem!\n",
1637 : : __LINE__);
1638 : 0 : return -1;
1639 : : }
1640 : : }
1641 : :
1642 [ - + ]: 1 : if (launch_proc(argv7) == 0) {
1643 : : printf("Error (line %d) - process run ok with invalid (null) --socket-mem!\n",
1644 : : __LINE__);
1645 : 0 : return -1;
1646 : : }
1647 : :
1648 : 1 : populate_socket_mem_param(num_sockets, "2", "",
1649 : : arg8_socket_mem, sizeof(arg8_socket_mem));
1650 [ - + ]: 1 : if (launch_proc(argv8) == 0) {
1651 : : printf("Error (line %d) - process run ok with --socket-mem and -m specified!\n",
1652 : : __LINE__);
1653 : 0 : return -1;
1654 : : }
1655 : :
1656 : 1 : populate_socket_mem_param(num_sockets + 1, "2", "",
1657 : : invalid_socket_mem, sizeof(invalid_socket_mem));
1658 [ - + ]: 1 : if (launch_proc(argv9) == 0) {
1659 : : printf("Error (line %d) - process run ok with extra socket in --socket-mem!\n",
1660 : : __LINE__);
1661 : 0 : return -1;
1662 : : }
1663 : :
1664 : 1 : populate_socket_mem_param(num_sockets, "2", "",
1665 : : valid_socket_mem, sizeof(valid_socket_mem));
1666 [ - + ]: 1 : if (launch_proc(argv10) != 0) {
1667 : : printf("Error (line %d) - process failed with valid --socket-mem!\n", __LINE__);
1668 : 0 : return -1;
1669 : : }
1670 : :
1671 : : return 0;
1672 : : }
1673 : :
1674 : : #endif /* !RTE_EXEC_ENV_WINDOWS */
1675 : :
1676 : 276 : REGISTER_FAST_TEST(eal_flags_c_opt_autotest, NOHUGE_SKIP, ASAN_SKIP, test_missing_c_flag);
1677 : 276 : REGISTER_FAST_TEST(eal_flags_main_opt_autotest, NOHUGE_SKIP, ASAN_SKIP, test_main_lcore_flag);
1678 : 276 : REGISTER_FAST_TEST(eal_flags_n_opt_autotest, NOHUGE_SKIP, ASAN_SKIP, test_invalid_n_flag);
1679 : 276 : REGISTER_FAST_TEST(eal_flags_hpet_autotest, NOHUGE_SKIP, ASAN_SKIP, test_no_hpet_flag);
1680 : 276 : REGISTER_FAST_TEST(eal_flags_no_huge_autotest, NOHUGE_SKIP, ASAN_SKIP, test_no_huge_flag);
1681 : 276 : REGISTER_FAST_TEST(eal_flags_a_opt_autotest, NOHUGE_SKIP, ASAN_SKIP, test_allow_flag);
1682 : 276 : REGISTER_FAST_TEST(eal_flags_b_opt_autotest, NOHUGE_SKIP, ASAN_SKIP, test_invalid_b_flag);
1683 : 276 : REGISTER_FAST_TEST(eal_flags_vdev_opt_autotest, NOHUGE_SKIP, ASAN_SKIP, test_invalid_vdev_flag);
1684 : 276 : REGISTER_FAST_TEST(eal_flags_r_opt_autotest, NOHUGE_SKIP, ASAN_SKIP, test_invalid_r_flag);
1685 : 276 : REGISTER_FAST_TEST(eal_flags_mem_autotest, NOHUGE_SKIP, ASAN_SKIP, test_memory_flags);
1686 : 276 : REGISTER_FAST_TEST(eal_flags_file_prefix_autotest, NOHUGE_SKIP, ASAN_SKIP, test_file_prefix);
1687 : 276 : REGISTER_FAST_TEST(eal_flags_misc_autotest, NOHUGE_SKIP, ASAN_SKIP, test_misc_flags);
|