1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright(c) 2014 6WIND S.A.
21 #include <rte_debug.h>
22 #include <rte_string_fns.h>
26 #define DEFAULT_MEM_SIZE "18"
27 #define mp_flag "--proc-type=secondary"
28 #define no_hpet "--no-hpet"
29 #define no_huge "--no-huge"
30 #define no_shconf "--no-shconf"
31 #define pci_whitelist "--pci-whitelist"
33 #define memtest "memtest"
34 #define memtest1 "memtest1"
35 #define memtest2 "memtest2"
36 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 20)
37 #define launch_proc(ARGV) process_dup(ARGV, \
38 sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
40 enum hugepage_action {
41 HUGEPAGE_CHECK_EXISTS = 0,
42 HUGEPAGE_CHECK_LOCKED,
47 /* if string contains a hugepage path */
49 get_hugepage_path(char * src, int src_len, char * dst, int dst_len)
52 char *tokens[NUM_TOKENS];
54 /* if we couldn't properly split the string */
55 if (rte_strsplit(src, src_len, tokens, NUM_TOKENS, ' ') < NUM_TOKENS)
58 if (strncmp(tokens[2], "hugetlbfs", sizeof("hugetlbfs")) == 0) {
59 snprintf(dst, dst_len, "%s", tokens[1]);
66 * Cycles through hugepage directories and looks for hugepage
67 * files associated with a given prefix. Depending on value of
68 * action, the hugepages are checked if they exist, checked if
69 * they can be locked, or are simply deleted.
71 * Returns 1 if it finds at least one hugepage matching the action
72 * Returns 0 if no matching hugepages were found
73 * Returns -1 if it encounters an error
76 process_hugefiles(const char * prefix, enum hugepage_action action)
78 FILE * hugedir_handle = NULL;
79 DIR * hugepage_dir = NULL;
80 struct dirent *dirent = NULL;
82 char hugefile_prefix[PATH_MAX] = {0};
83 char hugedir[PATH_MAX] = {0};
84 char line[PATH_MAX] = {0};
86 int fd, lck_result, result = 0;
88 const int prefix_len = snprintf(hugefile_prefix,
89 sizeof(hugefile_prefix), "%smap_", prefix);
90 if (prefix_len <= 0 || prefix_len >= (int)sizeof(hugefile_prefix)
91 || prefix_len >= (int)sizeof(dirent->d_name)) {
92 printf("Error creating hugefile filename prefix\n");
96 /* get hugetlbfs mountpoints from /proc/mounts */
97 hugedir_handle = fopen("/proc/mounts", "r");
99 if (hugedir_handle == NULL) {
100 printf("Error parsing /proc/mounts!\n");
104 /* read and parse script output */
105 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
107 /* check if we have a hugepage filesystem path */
108 if (!get_hugepage_path(line, sizeof(line), hugedir, sizeof(hugedir)))
111 /* check if directory exists */
112 if ((hugepage_dir = opendir(hugedir)) == NULL) {
113 fclose(hugedir_handle);
114 printf("Error reading %s: %s\n", hugedir, strerror(errno));
118 while ((dirent = readdir(hugepage_dir)) != NULL) {
119 if (memcmp(dirent->d_name, hugefile_prefix, prefix_len) != 0)
123 case HUGEPAGE_CHECK_EXISTS:
125 /* file exists, return */
130 case HUGEPAGE_DELETE:
132 char file_path[PATH_MAX] = {0};
134 snprintf(file_path, sizeof(file_path),
135 "%s/%s", hugedir, dirent->d_name);
138 if (remove(file_path) < 0) {
139 printf("Error deleting %s - %s!\n",
140 dirent->d_name, strerror(errno));
141 closedir(hugepage_dir);
148 case HUGEPAGE_CHECK_LOCKED:
150 /* try and lock the file */
151 fd = openat(dirfd(hugepage_dir), dirent->d_name, O_RDONLY);
153 /* this shouldn't happen */
155 printf("Error opening %s - %s!\n",
156 dirent->d_name, strerror(errno));
157 closedir(hugepage_dir);
162 /* non-blocking lock */
163 lck_result = flock(fd, LOCK_EX | LOCK_NB);
165 /* if lock succeeds, there's something wrong */
166 if (lck_result != -1) {
169 /* unlock the resulting lock */
172 closedir(hugepage_dir);
179 /* shouldn't happen */
184 } /* read hugepage directory */
185 closedir(hugepage_dir);
186 } /* read /proc/mounts */
188 fclose(hugedir_handle);
192 #ifdef RTE_EXEC_ENV_LINUXAPP
194 * count the number of "node*" files in /sys/devices/system/node/
197 get_number_of_sockets(void)
199 struct dirent *dirent = NULL;
200 const char * nodedir = "/sys/devices/system/node/";
204 /* check if directory exists */
205 if ((dir = opendir(nodedir)) == NULL) {
206 /* if errno==ENOENT this means we don't have NUMA support */
207 if (errno == ENOENT) {
208 printf("No NUMA nodes detected: assuming 1 available socket\n");
211 printf("Error opening %s: %s\n", nodedir, strerror(errno));
215 while ((dirent = readdir(dir)) != NULL)
216 if (strncmp(dirent->d_name, "node", sizeof("node") - 1) == 0)
225 get_current_prefix(char * prefix, int size)
227 char path[PATH_MAX] = {0};
228 char buf[PATH_MAX] = {0};
230 /* get file for config (fd is always 3) */
231 snprintf(path, sizeof(path), "/proc/self/fd/%d", 3);
233 /* return NULL on error */
234 if (readlink(path, buf, sizeof(buf)) == -1)
237 /* get the basename */
238 snprintf(buf, sizeof(buf), "%s", basename(buf));
240 /* copy string all the way from second char up to start of _config */
241 snprintf(prefix, size, "%.*s",
242 (int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
249 * Test that the app doesn't run with invalid whitelist option.
250 * Final tests ensures it does run with valid options as sanity check (one
251 * test for with Domain+BDF, second for just with BDF)
254 test_whitelist_flag(void)
257 #ifdef RTE_EXEC_ENV_BSDAPP
258 /* BSD target doesn't support prefixes at this point */
259 const char * prefix = "";
261 char prefix[PATH_MAX], tmp[PATH_MAX];
262 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
263 printf("Error - unable to get current prefix!\n");
266 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
269 const char *wlinval[][11] = {
270 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
271 pci_whitelist, "error", "", ""},
272 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
273 pci_whitelist, "0:0:0", "", ""},
274 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
275 pci_whitelist, "0:error:0.1", "", ""},
276 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
277 pci_whitelist, "0:0:0.1error", "", ""},
278 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
279 pci_whitelist, "error0:0:0.1", "", ""},
280 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
281 pci_whitelist, "0:0:0.1.2", "", ""},
283 /* Test with valid whitelist option */
284 const char *wlval1[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
285 pci_whitelist, "00FF:09:0B.3"};
286 const char *wlval2[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
287 pci_whitelist, "09:0B.3", pci_whitelist, "0a:0b.1"};
288 const char *wlval3[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
289 pci_whitelist, "09:0B.3,type=test",
290 pci_whitelist, "08:00.1,type=normal",
293 for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
294 if (launch_proc(wlinval[i]) == 0) {
295 printf("Error - process did run ok with invalid "
296 "whitelist parameter\n");
300 if (launch_proc(wlval1) != 0 ) {
301 printf("Error - process did not run ok with valid whitelist\n");
304 if (launch_proc(wlval2) != 0 ) {
305 printf("Error - process did not run ok with valid whitelist value set\n");
308 if (launch_proc(wlval3) != 0 ) {
309 printf("Error - process did not run ok with valid whitelist + args\n");
317 * Test that the app doesn't run with invalid blacklist option.
318 * Final test ensures it does run with valid options as sanity check
321 test_invalid_b_flag(void)
323 #ifdef RTE_EXEC_ENV_BSDAPP
324 /* BSD target doesn't support prefixes at this point */
325 const char * prefix = "";
327 char prefix[PATH_MAX], tmp[PATH_MAX];
328 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
329 printf("Error - unable to get current prefix!\n");
332 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
335 const char *blinval[][9] = {
336 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error"},
337 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0"},
338 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:error:0.1"},
339 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1error"},
340 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error0:0:0.1"},
341 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1.2"},
343 /* Test with valid blacklist option */
344 const char *blval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
348 for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
349 if (launch_proc(blinval[i]) == 0) {
350 printf("Error - process did run ok with invalid "
351 "blacklist parameter\n");
355 if (launch_proc(blval) != 0) {
356 printf("Error - process did not run ok with valid blacklist value\n");
363 * Test that the app doesn't run with invalid vdev option.
364 * Final test ensures it does run with valid options as sanity check
366 #ifdef RTE_LIBRTE_PMD_RING
368 test_invalid_vdev_flag(void)
370 #ifdef RTE_EXEC_ENV_BSDAPP
371 /* BSD target doesn't support prefixes at this point, and we also need to
372 * run another primary process here */
373 const char * prefix = no_shconf;
375 const char * prefix = "--file-prefix=vdev";
378 /* Test with invalid vdev option */
379 const char *vdevinval[] = {prgname, prefix, no_huge, "-n", "1",
380 "-c", "1", vdev, "eth_dummy"};
382 /* Test with valid vdev option */
383 const char *vdevval1[] = {prgname, prefix, no_huge, "-n", "1",
384 "-c", "1", vdev, "net_ring0"};
386 const char *vdevval2[] = {prgname, prefix, no_huge, "-n", "1",
387 "-c", "1", vdev, "net_ring0,args=test"};
389 const char *vdevval3[] = {prgname, prefix, no_huge, "-n", "1",
390 "-c", "1", vdev, "net_ring0,nodeaction=r1:0:CREATE"};
392 if (launch_proc(vdevinval) == 0) {
393 printf("Error - process did run ok with invalid "
398 if (launch_proc(vdevval1) != 0) {
399 printf("Error - process did not run ok with valid vdev value\n");
403 if (launch_proc(vdevval2) != 0) {
404 printf("Error - process did not run ok with valid vdev value,"
405 "with dummy args\n");
409 if (launch_proc(vdevval3) != 0) {
410 printf("Error - process did not run ok with valid vdev value,"
411 "with valid args\n");
419 * Test that the app doesn't run with invalid -r option.
422 test_invalid_r_flag(void)
424 #ifdef RTE_EXEC_ENV_BSDAPP
425 /* BSD target doesn't support prefixes at this point */
426 const char * prefix = "";
428 char prefix[PATH_MAX], tmp[PATH_MAX];
429 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
430 printf("Error - unable to get current prefix!\n");
433 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
436 const char *rinval[][9] = {
437 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "error"},
438 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "0"},
439 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "-1"},
440 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "17"},
442 /* Test with valid blacklist option */
443 const char *rval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
447 for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
448 if (launch_proc(rinval[i]) == 0) {
449 printf("Error - process did run ok with invalid "
450 "-r (rank) parameter\n");
454 if (launch_proc(rval) != 0) {
455 printf("Error - process did not run ok with valid -r (rank) value\n");
462 * Test that the app doesn't run without the coremask/corelist flags. In all cases
463 * should give an error and fail to run
466 test_missing_c_flag(void)
468 #ifdef RTE_EXEC_ENV_BSDAPP
469 /* BSD target doesn't support prefixes at this point */
470 const char * prefix = "";
472 char prefix[PATH_MAX], tmp[PATH_MAX];
473 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
474 printf("Error - unable to get current prefix!\n");
477 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
480 /* -c flag but no coremask value */
481 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "3", "-c"};
482 /* No -c, -l or --lcores flag at all */
483 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "3"};
484 /* bad coremask value */
485 const char *argv3[] = { prgname, prefix, mp_flag,
486 "-n", "3", "-c", "error" };
487 /* sanity check of tests - valid coremask value */
488 const char *argv4[] = { prgname, prefix, mp_flag,
489 "-n", "3", "-c", "1" };
490 /* -l flag but no corelist value */
491 const char *argv5[] = { prgname, prefix, mp_flag,
493 const char *argv6[] = { prgname, prefix, mp_flag,
494 "-n", "3", "-l", " " };
495 /* bad corelist values */
496 const char *argv7[] = { prgname, prefix, mp_flag,
497 "-n", "3", "-l", "error" };
498 const char *argv8[] = { prgname, prefix, mp_flag,
499 "-n", "3", "-l", "1-" };
500 const char *argv9[] = { prgname, prefix, mp_flag,
501 "-n", "3", "-l", "1," };
502 const char *argv10[] = { prgname, prefix, mp_flag,
503 "-n", "3", "-l", "1#2" };
504 /* sanity check test - valid corelist value */
505 const char *argv11[] = { prgname, prefix, mp_flag,
506 "-n", "3", "-l", "1-2,3" };
508 /* --lcores flag but no lcores value */
509 const char *argv12[] = { prgname, prefix, mp_flag,
510 "-n", "3", "--lcores" };
511 const char *argv13[] = { prgname, prefix, mp_flag,
512 "-n", "3", "--lcores", " " };
513 /* bad lcores value */
514 const char *argv14[] = { prgname, prefix, mp_flag,
515 "-n", "3", "--lcores", "1-3-5" };
516 const char *argv15[] = { prgname, prefix, mp_flag,
517 "-n", "3", "--lcores", "0-1,,2" };
518 const char *argv16[] = { prgname, prefix, mp_flag,
519 "-n", "3", "--lcores", "0-,1" };
520 const char *argv17[] = { prgname, prefix, mp_flag,
521 "-n", "3", "--lcores", "(0-,2-4)" };
522 const char *argv18[] = { prgname, prefix, mp_flag,
523 "-n", "3", "--lcores", "(-1,2)" };
524 const char *argv19[] = { prgname, prefix, mp_flag,
525 "-n", "3", "--lcores", "(2-4)@(2-4-6)" };
526 const char *argv20[] = { prgname, prefix, mp_flag,
527 "-n", "3", "--lcores", "(a,2)" };
528 const char *argv21[] = { prgname, prefix, mp_flag,
529 "-n", "3", "--lcores", "1-3@(1,3)" };
530 const char *argv22[] = { prgname, prefix, mp_flag,
531 "-n", "3", "--lcores", "3@((1,3)" };
532 const char *argv23[] = { prgname, prefix, mp_flag,
533 "-n", "3", "--lcores", "(4-7)=(1,3)" };
534 const char *argv24[] = { prgname, prefix, mp_flag,
535 "-n", "3", "--lcores", "[4-7]@(1,3)" };
536 /* sanity check of tests - valid lcores value */
537 const char *argv25[] = { prgname, prefix, mp_flag,
538 "-n", "3", "--lcores",
539 "0-1,2@(5-7),(3-5)@(0,2),(0,6),7"};
541 if (launch_proc(argv2) != 0) {
543 "process did not run ok when missing -c flag\n");
547 if (launch_proc(argv1) == 0
548 || launch_proc(argv3) == 0) {
550 "process ran without error with invalid -c flag\n");
553 if (launch_proc(argv4) != 0) {
555 "process did not run ok with valid coremask value\n");
560 if (launch_proc(argv5) == 0
561 || launch_proc(argv6) == 0
562 || launch_proc(argv7) == 0
563 || launch_proc(argv8) == 0
564 || launch_proc(argv9) == 0
565 || launch_proc(argv10) == 0) {
567 "process ran without error with invalid -l flag\n");
570 if (launch_proc(argv11) != 0) {
572 "process did not run ok with valid corelist value\n");
576 /* start --lcores tests */
577 if (launch_proc(argv12) == 0 || launch_proc(argv13) == 0 ||
578 launch_proc(argv14) == 0 || launch_proc(argv15) == 0 ||
579 launch_proc(argv16) == 0 || launch_proc(argv17) == 0 ||
580 launch_proc(argv18) == 0 || launch_proc(argv19) == 0 ||
581 launch_proc(argv20) == 0 || launch_proc(argv21) == 0 ||
582 launch_proc(argv21) == 0 || launch_proc(argv22) == 0 ||
583 launch_proc(argv23) == 0 || launch_proc(argv24) == 0) {
585 "process ran without error with invalid --lcore flag\n");
589 if (launch_proc(argv25) != 0) {
591 "process did not run ok with valid corelist value\n");
599 * Test --master-lcore option with matching coremask
602 test_master_lcore_flag(void)
604 #ifdef RTE_EXEC_ENV_BSDAPP
605 /* BSD target doesn't support prefixes at this point */
606 const char *prefix = "";
608 char prefix[PATH_MAX], tmp[PATH_MAX];
609 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
610 printf("Error - unable to get current prefix!\n");
613 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
616 /* --master-lcore flag but no value */
617 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore"};
618 /* --master-lcore flag with invalid value */
619 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "-1"};
620 const char *argv3[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "X"};
621 /* master lcore not in coremask */
622 const char *argv4[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "2"};
624 const char *argv5[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "1"};
625 /* valid value set before coremask */
626 const char *argv6[] = { prgname, prefix, mp_flag, "-n", "1", "--master-lcore", "1", "-c", "3"};
628 if (launch_proc(argv1) == 0
629 || launch_proc(argv2) == 0
630 || launch_proc(argv3) == 0
631 || launch_proc(argv4) == 0) {
632 printf("Error - process ran without error with wrong --master-lcore\n");
635 if (launch_proc(argv5) != 0
636 || launch_proc(argv6) != 0) {
637 printf("Error - process did not run ok with valid --master-lcore\n");
644 * Test that the app doesn't run with invalid -n flag option.
645 * Final test ensures it does run with valid options as sanity check
646 * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
650 test_invalid_n_flag(void)
652 #ifdef RTE_EXEC_ENV_BSDAPP
653 /* BSD target doesn't support prefixes at this point */
654 const char * prefix = "";
656 char prefix[PATH_MAX], tmp[PATH_MAX];
657 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
658 printf("Error - unable to get current prefix!\n");
661 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
664 /* -n flag but no value */
665 const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"};
666 /* bad numeric value */
667 const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" };
668 /* zero is invalid */
669 const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "0" };
670 /* sanity test - check with good value */
671 const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" };
672 /* sanity test - check with no -n flag */
673 const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"};
675 if (launch_proc(argv1) == 0
676 || launch_proc(argv2) == 0
677 || launch_proc(argv3) == 0) {
678 printf("Error - process ran without error when"
679 "invalid -n flag\n");
682 if (launch_proc(argv4) != 0) {
683 printf("Error - process did not run ok with valid num-channel value\n");
686 if (launch_proc(argv5) != 0) {
687 printf("Error - process did not run ok without -n flag\n");
695 * Test that the app runs with HPET, and without HPET
698 test_no_hpet_flag(void)
700 char prefix[PATH_MAX], tmp[PATH_MAX];
702 #ifdef RTE_EXEC_ENV_BSDAPP
705 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
706 printf("Error - unable to get current prefix!\n");
709 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
712 const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"};
713 /* Without --no-hpet */
714 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-n", "2"};
716 if (launch_proc(argv1) != 0) {
717 printf("Error - process did not run ok with --no-hpet flag\n");
720 if (launch_proc(argv2) != 0) {
721 printf("Error - process did not run ok without --no-hpet flag\n");
728 * Test that the app runs with --no-huge and doesn't run when --socket-mem are
729 * specified with --no-huge.
732 test_no_huge_flag(void)
734 #ifdef RTE_EXEC_ENV_BSDAPP
735 /* BSD target doesn't support prefixes at this point, and we also need to
736 * run another primary process here */
737 const char * prefix = no_shconf;
739 const char * prefix = "--file-prefix=nohuge";
743 const char *argv1[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2"};
744 /* With --no-huge and -m */
745 const char *argv2[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
746 "-m", DEFAULT_MEM_SIZE};
748 /* With --no-huge and --socket-mem */
749 const char *argv3[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
750 "--socket-mem=" DEFAULT_MEM_SIZE};
751 /* With --no-huge, -m and --socket-mem */
752 const char *argv4[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
753 "-m", DEFAULT_MEM_SIZE, "--socket-mem=" DEFAULT_MEM_SIZE};
754 if (launch_proc(argv1) != 0) {
755 printf("Error - process did not run ok with --no-huge flag\n");
758 if (launch_proc(argv2) != 0) {
759 printf("Error - process did not run ok with --no-huge and -m flags\n");
762 #ifdef RTE_EXEC_ENV_BSDAPP
763 /* BSD target does not support NUMA, hence no --socket-mem tests */
767 if (launch_proc(argv3) == 0) {
768 printf("Error - process run ok with --no-huge and --socket-mem "
772 if (launch_proc(argv4) == 0) {
773 printf("Error - process run ok with --no-huge, -m and "
774 "--socket-mem flags\n");
781 test_misc_flags(void)
783 char hugepath[PATH_MAX] = {0};
784 #ifdef RTE_EXEC_ENV_BSDAPP
785 /* BSD target doesn't support prefixes at this point */
786 const char * prefix = "";
787 const char * nosh_prefix = "";
789 char prefix[PATH_MAX], tmp[PATH_MAX];
790 const char * nosh_prefix = "--file-prefix=noshconf";
791 FILE * hugedir_handle = NULL;
792 char line[PATH_MAX] = {0};
793 unsigned i, isempty = 1;
794 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
795 printf("Error - unable to get current prefix!\n");
798 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
801 * get first valid hugepage path
804 /* get hugetlbfs mountpoints from /proc/mounts */
805 hugedir_handle = fopen("/proc/mounts", "r");
807 if (hugedir_handle == NULL) {
808 printf("Error opening /proc/mounts!\n");
812 /* read /proc/mounts */
813 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
815 /* find first valid hugepath */
816 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
820 fclose(hugedir_handle);
822 /* check if path is not empty */
823 for (i = 0; i < sizeof(hugepath); i++)
824 if (hugepath[i] != '\0')
828 printf("No mounted hugepage dir found!\n");
834 /* check that some general flags don't prevent things from working.
835 * All cases, apart from the first, app should run.
836 * No further testing of output done.
838 /* sanity check - failure with invalid option */
839 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
842 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
844 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
845 /* With valid --syslog */
846 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
847 "--syslog", "syslog"};
848 /* With empty --syslog (should fail) */
849 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
850 /* With invalid --syslog */
851 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
852 /* With no-sh-conf, also use no-huge to ensure this test runs on BSD */
853 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
854 no_shconf, nosh_prefix, no_huge};
856 /* With --huge-dir */
857 const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
858 "--file-prefix=hugedir", "--huge-dir", hugepath};
859 /* With empty --huge-dir (should fail) */
860 const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
861 "--file-prefix=hugedir", "--huge-dir"};
862 /* With invalid --huge-dir */
863 const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
864 "--file-prefix=hugedir", "--huge-dir", "invalid"};
865 /* Secondary process with invalid --huge-dir (should run as flag has no
866 * effect on secondary processes) */
867 const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
869 /* try running with base-virtaddr param */
870 const char *argv11[] = {prgname, "--file-prefix=virtaddr",
871 "-c", "1", "-n", "2", "--base-virtaddr=0x12345678"};
873 /* try running with --vfio-intr INTx flag */
874 const char *argv12[] = {prgname, "--file-prefix=intr",
875 "-c", "1", "-n", "2", "--vfio-intr=legacy"};
877 /* try running with --vfio-intr MSI flag */
878 const char *argv13[] = {prgname, "--file-prefix=intr",
879 "-c", "1", "-n", "2", "--vfio-intr=msi"};
881 /* try running with --vfio-intr MSI-X flag */
882 const char *argv14[] = {prgname, "--file-prefix=intr",
883 "-c", "1", "-n", "2", "--vfio-intr=msix"};
885 /* try running with --vfio-intr invalid flag */
886 const char *argv15[] = {prgname, "--file-prefix=intr",
887 "-c", "1", "-n", "2", "--vfio-intr=invalid"};
889 /* run all tests also applicable to FreeBSD first */
891 if (launch_proc(argv0) == 0) {
892 printf("Error - process ran ok with invalid flag\n");
895 if (launch_proc(argv1) != 0) {
896 printf("Error - process did not run ok with --no-pci flag\n");
899 if (launch_proc(argv2) != 0) {
900 printf("Error - process did not run ok with -v flag\n");
903 if (launch_proc(argv6) != 0) {
904 printf("Error - process did not run ok with --no-shconf flag\n");
908 #ifdef RTE_EXEC_ENV_BSDAPP
909 /* no more tests to be done on FreeBSD */
913 if (launch_proc(argv3) != 0) {
914 printf("Error - process did not run ok with --syslog flag\n");
917 if (launch_proc(argv4) == 0) {
918 printf("Error - process run ok with empty --syslog flag\n");
921 if (launch_proc(argv5) == 0) {
922 printf("Error - process run ok with invalid --syslog flag\n");
925 if (launch_proc(argv7) != 0) {
926 printf("Error - process did not run ok with --huge-dir flag\n");
929 if (launch_proc(argv8) == 0) {
930 printf("Error - process run ok with empty --huge-dir flag\n");
933 if (launch_proc(argv9) == 0) {
934 printf("Error - process run ok with invalid --huge-dir flag\n");
937 if (launch_proc(argv10) != 0) {
938 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
941 if (launch_proc(argv11) != 0) {
942 printf("Error - process did not run ok with --base-virtaddr parameter\n");
945 if (launch_proc(argv12) != 0) {
946 printf("Error - process did not run ok with "
947 "--vfio-intr INTx parameter\n");
950 if (launch_proc(argv13) != 0) {
951 printf("Error - process did not run ok with "
952 "--vfio-intr MSI parameter\n");
955 if (launch_proc(argv14) != 0) {
956 printf("Error - process did not run ok with "
957 "--vfio-intr MSI-X parameter\n");
960 if (launch_proc(argv15) == 0) {
961 printf("Error - process run ok with "
962 "--vfio-intr invalid parameter\n");
969 test_file_prefix(void)
972 * 1. check if current process hugefiles are locked
973 * 2. try to run secondary process without a corresponding primary process
974 * (while failing to run, it will also remove any unused hugepage files)
975 * 3. check if current process hugefiles are still in place and are locked
976 * 4. run a primary process with memtest1 prefix
977 * 5. check if memtest1 hugefiles are created
978 * 6. run a primary process with memtest2 prefix
979 * 7. check that only memtest2 hugefiles are present in the hugedir
982 #ifdef RTE_EXEC_ENV_BSDAPP
986 /* this should fail unless the test itself is run with "memtest" prefix */
987 const char *argv0[] = {prgname, mp_flag, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
988 "--file-prefix=" memtest };
990 /* primary process with memtest1 */
991 const char *argv1[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
992 "--file-prefix=" memtest1 };
994 /* primary process with memtest2 */
995 const char *argv2[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
996 "--file-prefix=" memtest2 };
999 if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
1000 printf("Error - unable to get current prefix!\n");
1004 /* check if files for current prefix are present */
1005 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1006 printf("Error - hugepage files for %s were not created!\n", prefix);
1010 /* checks if files for current prefix are locked */
1011 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1012 printf("Error - hugepages for current process aren't locked!\n");
1016 /* check if files for secondary process are present */
1017 if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
1018 /* check if they are not locked */
1019 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
1020 printf("Error - hugepages for current process are locked!\n");
1023 /* they aren't locked, delete them */
1025 if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
1026 printf("Error - deleting hugepages failed!\n");
1032 if (launch_proc(argv0) == 0) {
1033 printf("Error - secondary process ran ok without primary process\n");
1037 /* check if files for current prefix are present */
1038 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1039 printf("Error - hugepage files for %s were not created!\n", prefix);
1043 /* checks if files for current prefix are locked */
1044 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1045 printf("Error - hugepages for current process aren't locked!\n");
1049 if (launch_proc(argv1) != 0) {
1050 printf("Error - failed to run with --file-prefix=%s\n", memtest);
1054 /* check if memtest1_map0 is present */
1055 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
1056 printf("Error - hugepage files for %s were not created!\n", memtest1);
1060 if (launch_proc(argv2) != 0) {
1061 printf("Error - failed to run with --file-prefix=%s\n", memtest2);
1065 /* check if hugefiles for memtest2 are present */
1066 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
1067 printf("Error - hugepage files for %s were not created!\n", memtest2);
1071 /* check if hugefiles for memtest1 are present */
1072 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1073 printf("Error - hugepage files for %s were not deleted!\n", memtest1);
1081 * Tests for correct handling of -m and --socket-mem flags
1084 test_memory_flags(void)
1086 #ifdef RTE_EXEC_ENV_BSDAPP
1087 /* BSD target doesn't support prefixes at this point */
1088 const char * prefix = "";
1090 char prefix[PATH_MAX], tmp[PATH_MAX];
1091 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
1092 printf("Error - unable to get current prefix!\n");
1095 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
1098 /* valid -m flag and mp flag */
1099 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "10",
1100 "-n", "2", "-m", DEFAULT_MEM_SIZE};
1103 const char *argv1[] = {prgname, "-c", "10", "-n", "2",
1104 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE};
1106 /* invalid (zero) --socket-mem flag */
1107 const char *argv2[] = {prgname, "-c", "10", "-n", "2",
1108 "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
1110 /* invalid (incomplete) --socket-mem flag */
1111 const char *argv3[] = {prgname, "-c", "10", "-n", "2",
1112 "--file-prefix=" memtest, "--socket-mem=2,2,"};
1114 /* invalid (mixed with invalid data) --socket-mem flag */
1115 const char *argv4[] = {prgname, "-c", "10", "-n", "2",
1116 "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
1118 /* invalid (with numeric value as last character) --socket-mem flag */
1119 const char *argv5[] = {prgname, "-c", "10", "-n", "2",
1120 "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
1122 /* invalid (with empty socket) --socket-mem flag */
1123 const char *argv6[] = {prgname, "-c", "10", "-n", "2",
1124 "--file-prefix=" memtest, "--socket-mem=2,,2"};
1126 /* invalid (null) --socket-mem flag */
1127 const char *argv7[] = {prgname, "-c", "10", "-n", "2",
1128 "--file-prefix=" memtest, "--socket-mem="};
1130 /* valid --socket-mem specified together with -m flag */
1131 const char *argv8[] = {prgname, "-c", "10", "-n", "2",
1132 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE, "--socket-mem=2,2"};
1134 /* construct an invalid socket mask with 2 megs on each socket plus
1135 * extra 2 megs on socket that doesn't exist on current system */
1136 char invalid_socket_mem[SOCKET_MEM_STRLEN];
1137 char buf[SOCKET_MEM_STRLEN]; /* to avoid copying string onto itself */
1139 #ifdef RTE_EXEC_ENV_BSDAPP
1140 int i, num_sockets = 1;
1142 int i, num_sockets = RTE_MIN(get_number_of_sockets(),
1143 RTE_MAX_NUMA_NODES);
1146 if (num_sockets <= 0) {
1147 printf("Error - cannot get number of sockets!\n");
1151 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
1153 /* add one extra socket */
1154 for (i = 0; i < num_sockets + 1; i++) {
1155 snprintf(buf, sizeof(buf), "%s%s", invalid_socket_mem, DEFAULT_MEM_SIZE);
1156 strlcpy(invalid_socket_mem, buf, sizeof(invalid_socket_mem));
1158 if (num_sockets + 1 - i > 1) {
1159 snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
1160 strlcpy(invalid_socket_mem, buf,
1161 sizeof(invalid_socket_mem));
1165 /* construct a valid socket mask with 2 megs on each existing socket */
1166 char valid_socket_mem[SOCKET_MEM_STRLEN];
1168 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
1170 /* add one extra socket */
1171 for (i = 0; i < num_sockets; i++) {
1172 snprintf(buf, sizeof(buf), "%s%s", valid_socket_mem, DEFAULT_MEM_SIZE);
1173 strlcpy(valid_socket_mem, buf, sizeof(valid_socket_mem));
1175 if (num_sockets - i > 1) {
1176 snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
1177 strlcpy(valid_socket_mem, buf,
1178 sizeof(valid_socket_mem));
1182 /* invalid --socket-mem flag (with extra socket) */
1183 const char *argv9[] = {prgname, "-c", "10", "-n", "2",
1184 "--file-prefix=" memtest, invalid_socket_mem};
1186 /* valid --socket-mem flag */
1187 const char *argv10[] = {prgname, "-c", "10", "-n", "2",
1188 "--file-prefix=" memtest, valid_socket_mem};
1190 if (launch_proc(argv0) != 0) {
1191 printf("Error - secondary process failed with valid -m flag !\n");
1195 #ifdef RTE_EXEC_ENV_BSDAPP
1196 /* no other tests are applicable to BSD */
1200 if (launch_proc(argv1) != 0) {
1201 printf("Error - process failed with valid -m flag!\n");
1204 if (launch_proc(argv2) == 0) {
1205 printf("Error - process run ok with invalid (zero) --socket-mem!\n");
1209 if (launch_proc(argv3) == 0) {
1210 printf("Error - process run ok with invalid "
1211 "(incomplete) --socket-mem!\n");
1215 if (launch_proc(argv4) == 0) {
1216 printf("Error - process run ok with invalid "
1217 "(mixed with invalid input) --socket-mem!\n");
1221 if (launch_proc(argv5) == 0) {
1222 printf("Error - process run ok with invalid "
1223 "(mixed with invalid input with a numeric value as "
1224 "last character) --socket-mem!\n");
1228 if (launch_proc(argv6) == 0) {
1229 printf("Error - process run ok with invalid "
1230 "(with empty socket) --socket-mem!\n");
1234 if (launch_proc(argv7) == 0) {
1235 printf("Error - process run ok with invalid (null) --socket-mem!\n");
1239 if (launch_proc(argv8) == 0) {
1240 printf("Error - process run ok with --socket-mem and -m specified!\n");
1244 if (launch_proc(argv9) == 0) {
1245 printf("Error - process run ok with extra socket in --socket-mem!\n");
1249 if (launch_proc(argv10) != 0) {
1250 printf("Error - process failed with valid --socket-mem!\n");
1258 test_eal_flags(void)
1262 ret = test_missing_c_flag();
1264 printf("Error in test_missing_c_flag()\n");
1268 ret = test_master_lcore_flag();
1270 printf("Error in test_master_lcore_flag()\n");
1274 ret = test_invalid_n_flag();
1276 printf("Error in test_invalid_n_flag()\n");
1280 ret = test_no_hpet_flag();
1282 printf("Error in test_no_hpet_flag()\n");
1286 ret = test_no_huge_flag();
1288 printf("Error in test_no_huge_flag()\n");
1292 ret = test_whitelist_flag();
1294 printf("Error in test_invalid_whitelist_flag()\n");
1298 ret = test_invalid_b_flag();
1300 printf("Error in test_invalid_b_flag()\n");
1304 #ifdef RTE_LIBRTE_PMD_RING
1305 ret = test_invalid_vdev_flag();
1307 printf("Error in test_invalid_vdev_flag()\n");
1311 ret = test_invalid_r_flag();
1313 printf("Error in test_invalid_r_flag()\n");
1317 ret = test_memory_flags();
1319 printf("Error in test_memory_flags()\n");
1323 ret = test_file_prefix();
1325 printf("Error in test_file_prefix()\n");
1329 ret = test_misc_flags();
1331 printf("Error in test_misc_flags()");
1338 REGISTER_TEST_COMMAND(eal_flags_autotest, test_eal_flags);