1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright(c) 2014 6WIND S.A.
22 #include <rte_lcore.h>
23 #include <rte_debug.h>
24 #include <rte_string_fns.h>
28 #define DEFAULT_MEM_SIZE "18"
29 #define mp_flag "--proc-type=secondary"
30 #define no_hpet "--no-hpet"
31 #define no_huge "--no-huge"
32 #define no_shconf "--no-shconf"
33 #define pci_whitelist "--pci-whitelist"
35 #define memtest "memtest"
36 #define memtest1 "memtest1"
37 #define memtest2 "memtest2"
38 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 20)
39 #define launch_proc(ARGV) process_dup(ARGV, \
40 sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
42 enum hugepage_action {
43 HUGEPAGE_CHECK_EXISTS = 0,
44 HUGEPAGE_CHECK_LOCKED,
49 /* if string contains a hugepage path */
51 get_hugepage_path(char * src, int src_len, char * dst, int dst_len)
54 char *tokens[NUM_TOKENS];
56 /* if we couldn't properly split the string */
57 if (rte_strsplit(src, src_len, tokens, NUM_TOKENS, ' ') < NUM_TOKENS)
60 if (strncmp(tokens[2], "hugetlbfs", sizeof("hugetlbfs")) == 0) {
61 strlcpy(dst, tokens[1], dst_len);
68 * Cycles through hugepage directories and looks for hugepage
69 * files associated with a given prefix. Depending on value of
70 * action, the hugepages are checked if they exist, checked if
71 * they can be locked, or are simply deleted.
73 * Returns 1 if it finds at least one hugepage matching the action
74 * Returns 0 if no matching hugepages were found
75 * Returns -1 if it encounters an error
78 process_hugefiles(const char * prefix, enum hugepage_action action)
80 FILE * hugedir_handle = NULL;
81 DIR * hugepage_dir = NULL;
82 struct dirent *dirent = NULL;
84 char hugefile_prefix[PATH_MAX] = {0};
85 char hugedir[PATH_MAX] = {0};
86 char line[PATH_MAX] = {0};
88 int fd, lck_result, result = 0;
90 const int prefix_len = snprintf(hugefile_prefix,
91 sizeof(hugefile_prefix), "%smap_", prefix);
92 if (prefix_len <= 0 || prefix_len >= (int)sizeof(hugefile_prefix)
93 || prefix_len >= (int)sizeof(dirent->d_name)) {
94 printf("Error creating hugefile filename prefix\n");
98 /* get hugetlbfs mountpoints from /proc/mounts */
99 hugedir_handle = fopen("/proc/mounts", "r");
101 if (hugedir_handle == NULL) {
102 printf("Error parsing /proc/mounts!\n");
106 /* read and parse script output */
107 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
109 /* check if we have a hugepage filesystem path */
110 if (!get_hugepage_path(line, sizeof(line), hugedir, sizeof(hugedir)))
113 /* check if directory exists */
114 if ((hugepage_dir = opendir(hugedir)) == NULL) {
115 fclose(hugedir_handle);
116 printf("Error reading %s: %s\n", hugedir, strerror(errno));
120 while ((dirent = readdir(hugepage_dir)) != NULL) {
121 if (memcmp(dirent->d_name, hugefile_prefix, prefix_len) != 0)
125 case HUGEPAGE_CHECK_EXISTS:
127 /* file exists, return */
132 case HUGEPAGE_DELETE:
134 char file_path[PATH_MAX] = {0};
136 snprintf(file_path, sizeof(file_path),
137 "%s/%s", hugedir, dirent->d_name);
140 if (remove(file_path) < 0) {
141 printf("Error deleting %s - %s!\n",
142 dirent->d_name, strerror(errno));
143 closedir(hugepage_dir);
150 case HUGEPAGE_CHECK_LOCKED:
152 /* try and lock the file */
153 fd = openat(dirfd(hugepage_dir), dirent->d_name, O_RDONLY);
155 /* this shouldn't happen */
157 printf("Error opening %s - %s!\n",
158 dirent->d_name, strerror(errno));
159 closedir(hugepage_dir);
164 /* non-blocking lock */
165 lck_result = flock(fd, LOCK_EX | LOCK_NB);
167 /* if lock succeeds, there's something wrong */
168 if (lck_result != -1) {
171 /* unlock the resulting lock */
174 closedir(hugepage_dir);
181 /* shouldn't happen */
186 } /* read hugepage directory */
187 closedir(hugepage_dir);
188 } /* read /proc/mounts */
190 fclose(hugedir_handle);
194 #ifdef RTE_EXEC_ENV_LINUX
196 * count the number of "node*" files in /sys/devices/system/node/
199 get_number_of_sockets(void)
201 struct dirent *dirent = NULL;
202 const char * nodedir = "/sys/devices/system/node/";
206 /* check if directory exists */
207 if ((dir = opendir(nodedir)) == NULL) {
208 /* if errno==ENOENT this means we don't have NUMA support */
209 if (errno == ENOENT) {
210 printf("No NUMA nodes detected: assuming 1 available socket\n");
213 printf("Error opening %s: %s\n", nodedir, strerror(errno));
217 while ((dirent = readdir(dir)) != NULL)
218 if (strncmp(dirent->d_name, "node", sizeof("node") - 1) == 0)
227 * Test that the app doesn't run with invalid whitelist option.
228 * Final tests ensures it does run with valid options as sanity check (one
229 * test for with Domain+BDF, second for just with BDF)
232 test_whitelist_flag(void)
235 #ifdef RTE_EXEC_ENV_FREEBSD
236 /* BSD target doesn't support prefixes at this point */
237 const char * prefix = "";
239 char prefix[PATH_MAX], tmp[PATH_MAX];
240 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
241 printf("Error - unable to get current prefix!\n");
244 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
247 const char *wlinval[][11] = {
248 {prgname, prefix, mp_flag,
249 pci_whitelist, "error", "", ""},
250 {prgname, prefix, mp_flag,
251 pci_whitelist, "0:0:0", "", ""},
252 {prgname, prefix, mp_flag,
253 pci_whitelist, "0:error:0.1", "", ""},
254 {prgname, prefix, mp_flag,
255 pci_whitelist, "0:0:0.1error", "", ""},
256 {prgname, prefix, mp_flag,
257 pci_whitelist, "error0:0:0.1", "", ""},
258 {prgname, prefix, mp_flag,
259 pci_whitelist, "0:0:0.1.2", "", ""},
261 /* Test with valid whitelist option */
262 const char *wlval1[] = {prgname, prefix, mp_flag,
263 pci_whitelist, "00FF:09:0B.3"};
264 const char *wlval2[] = {prgname, prefix, mp_flag,
265 pci_whitelist, "09:0B.3", pci_whitelist, "0a:0b.1"};
266 const char *wlval3[] = {prgname, prefix, mp_flag,
267 pci_whitelist, "09:0B.3,type=test",
268 pci_whitelist, "08:00.1,type=normal",
271 for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
272 if (launch_proc(wlinval[i]) == 0) {
273 printf("Error - process did run ok with invalid "
274 "whitelist parameter\n");
278 if (launch_proc(wlval1) != 0 ) {
279 printf("Error - process did not run ok with valid whitelist\n");
282 if (launch_proc(wlval2) != 0 ) {
283 printf("Error - process did not run ok with valid whitelist value set\n");
286 if (launch_proc(wlval3) != 0 ) {
287 printf("Error - process did not run ok with valid whitelist + args\n");
295 * Test that the app doesn't run with invalid blacklist option.
296 * Final test ensures it does run with valid options as sanity check
299 test_invalid_b_flag(void)
301 #ifdef RTE_EXEC_ENV_FREEBSD
302 /* BSD target doesn't support prefixes at this point */
303 const char * prefix = "";
305 char prefix[PATH_MAX], tmp[PATH_MAX];
306 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
307 printf("Error - unable to get current prefix!\n");
310 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
313 const char *blinval[][9] = {
314 {prgname, prefix, mp_flag, "-b", "error"},
315 {prgname, prefix, mp_flag, "-b", "0:0:0"},
316 {prgname, prefix, mp_flag, "-b", "0:error:0.1"},
317 {prgname, prefix, mp_flag, "-b", "0:0:0.1error"},
318 {prgname, prefix, mp_flag, "-b", "error0:0:0.1"},
319 {prgname, prefix, mp_flag, "-b", "0:0:0.1.2"},
321 /* Test with valid blacklist option */
322 const char *blval[] = {prgname, prefix, mp_flag,
327 for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
328 if (launch_proc(blinval[i]) == 0) {
329 printf("Error - process did run ok with invalid "
330 "blacklist parameter\n");
334 if (launch_proc(blval) != 0) {
335 printf("Error - process did not run ok with valid blacklist value\n");
342 * Test that the app doesn't run with invalid vdev option.
343 * Final test ensures it does run with valid options as sanity check
345 #ifdef RTE_LIBRTE_PMD_RING
347 test_invalid_vdev_flag(void)
349 #ifdef RTE_EXEC_ENV_FREEBSD
350 /* BSD target doesn't support prefixes at this point, and we also need to
351 * run another primary process here */
352 const char * prefix = no_shconf;
354 const char * prefix = "--file-prefix=vdev";
357 /* Test with invalid vdev option */
358 const char *vdevinval[] = {prgname, prefix, no_huge,
361 /* Test with valid vdev option */
362 const char *vdevval1[] = {prgname, prefix, no_huge,
365 const char *vdevval2[] = {prgname, prefix, no_huge,
366 vdev, "net_ring0,args=test"};
368 const char *vdevval3[] = {prgname, prefix, no_huge,
369 vdev, "net_ring0,nodeaction=r1:0:CREATE"};
371 if (launch_proc(vdevinval) == 0) {
372 printf("Error - process did run ok with invalid "
377 if (launch_proc(vdevval1) != 0) {
378 printf("Error - process did not run ok with valid vdev value\n");
382 if (launch_proc(vdevval2) != 0) {
383 printf("Error - process did not run ok with valid vdev value,"
384 "with dummy args\n");
388 if (launch_proc(vdevval3) != 0) {
389 printf("Error - process did not run ok with valid vdev value,"
390 "with valid args\n");
398 * Test that the app doesn't run with invalid -r option.
401 test_invalid_r_flag(void)
403 #ifdef RTE_EXEC_ENV_FREEBSD
404 /* BSD target doesn't support prefixes at this point */
405 const char * prefix = "";
407 char prefix[PATH_MAX], tmp[PATH_MAX];
408 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
409 printf("Error - unable to get current prefix!\n");
412 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
415 const char *rinval[][9] = {
416 {prgname, prefix, mp_flag, "-r", "error"},
417 {prgname, prefix, mp_flag, "-r", "0"},
418 {prgname, prefix, mp_flag, "-r", "-1"},
419 {prgname, prefix, mp_flag, "-r", "17"},
421 /* Test with valid blacklist option */
422 const char *rval[] = {prgname, prefix, mp_flag, "-r", "16"};
426 for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
427 if (launch_proc(rinval[i]) == 0) {
428 printf("Error - process did run ok with invalid "
429 "-r (rank) parameter\n");
433 if (launch_proc(rval) != 0) {
434 printf("Error - process did not run ok with valid -r (rank) value\n");
441 * Test that the app doesn't run without the coremask/corelist flags. In all cases
442 * should give an error and fail to run
445 test_missing_c_flag(void)
447 #ifdef RTE_EXEC_ENV_FREEBSD
448 /* BSD target doesn't support prefixes at this point */
449 const char * prefix = "";
451 char prefix[PATH_MAX], tmp[PATH_MAX];
452 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
453 printf("Error - unable to get current prefix!\n");
456 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
459 /* -c flag but no coremask value */
460 const char *argv1[] = { prgname, prefix, mp_flag, "-c"};
461 /* No -c, -l or --lcores flag at all */
462 const char *argv2[] = { prgname, prefix, mp_flag};
463 /* bad coremask value */
464 const char *argv3[] = { prgname, prefix, mp_flag,
466 /* sanity check of tests - valid coremask value */
467 const char *argv4[] = { prgname, prefix, mp_flag,
469 /* -l flag but no corelist value */
470 const char *argv5[] = { prgname, prefix, mp_flag,
472 const char *argv6[] = { prgname, prefix, mp_flag,
474 /* bad corelist values */
475 const char *argv7[] = { prgname, prefix, mp_flag,
477 const char *argv8[] = { prgname, prefix, mp_flag,
479 const char *argv9[] = { prgname, prefix, mp_flag,
481 const char *argv10[] = { prgname, prefix, mp_flag,
483 /* core number is negative value */
484 const char * const argv11[] = { prgname, prefix, mp_flag,
486 const char * const argv12[] = { prgname, prefix, mp_flag,
488 /* core number is maximum value */
489 const char * const argv13[] = { prgname, prefix, mp_flag,
490 "-l", RTE_STR(RTE_MAX_LCORE) };
491 const char * const argv14[] = { prgname, prefix, mp_flag,
492 "-l", "1-"RTE_STR(RTE_MAX_LCORE) };
493 /* sanity check test - valid corelist value */
494 const char * const argv15[] = { prgname, prefix, mp_flag,
497 /* --lcores flag but no lcores value */
498 const char * const argv16[] = { prgname, prefix, mp_flag,
500 const char * const argv17[] = { prgname, prefix, mp_flag,
502 /* bad lcores value */
503 const char * const argv18[] = { prgname, prefix, mp_flag,
504 "--lcores", "1-3-5" };
505 const char * const argv19[] = { prgname, prefix, mp_flag,
506 "--lcores", "0-1,,2" };
507 const char * const argv20[] = { prgname, prefix, mp_flag,
508 "--lcores", "0-,1" };
509 const char * const argv21[] = { prgname, prefix, mp_flag,
510 "--lcores", "(0-,2-4)" };
511 const char * const argv22[] = { prgname, prefix, mp_flag,
512 "--lcores", "(-1,2)" };
513 const char * const argv23[] = { prgname, prefix, mp_flag,
514 "--lcores", "(2-4)@(2-4-6)" };
515 const char * const argv24[] = { prgname, prefix, mp_flag,
516 "--lcores", "(a,2)" };
517 const char * const argv25[] = { prgname, prefix, mp_flag,
518 "--lcores", "1-3@(1,3)" };
519 const char * const argv26[] = { prgname, prefix, mp_flag,
520 "--lcores", "3@((1,3)" };
521 const char * const argv27[] = { prgname, prefix, mp_flag,
522 "--lcores", "(4-7)=(1,3)" };
523 const char * const argv28[] = { prgname, prefix, mp_flag,
524 "--lcores", "[4-7]@(1,3)" };
525 /* sanity check of tests - valid lcores value */
526 const char * const argv29[] = { prgname, prefix, mp_flag,
528 "0-1,2@(5-7),(3-5)@(0,2),(0,6),7"};
530 if (launch_proc(argv2) != 0) {
532 "process did not run ok when missing -c flag\n");
536 if (launch_proc(argv1) == 0
537 || launch_proc(argv3) == 0) {
539 "process ran without error with invalid -c flag\n");
542 if (launch_proc(argv4) != 0) {
544 "process did not run ok with valid coremask value\n");
549 if (launch_proc(argv5) == 0
550 || launch_proc(argv6) == 0
551 || launch_proc(argv7) == 0
552 || launch_proc(argv8) == 0
553 || launch_proc(argv9) == 0
554 || launch_proc(argv10) == 0
555 || launch_proc(argv11) == 0
556 || launch_proc(argv12) == 0
557 || launch_proc(argv13) == 0
558 || launch_proc(argv14) == 0) {
560 "process ran without error with invalid -l flag\n");
563 if (rte_lcore_is_enabled(0) && rte_lcore_is_enabled(1) &&
564 rte_lcore_is_enabled(2) && rte_lcore_is_enabled(3) &&
565 launch_proc(argv15) != 0) {
567 "process did not run ok with valid corelist value\n");
571 /* start --lcores tests */
572 if (launch_proc(argv16) == 0 || launch_proc(argv17) == 0 ||
573 launch_proc(argv18) == 0 || launch_proc(argv19) == 0 ||
574 launch_proc(argv20) == 0 || launch_proc(argv21) == 0 ||
575 launch_proc(argv22) == 0 || launch_proc(argv23) == 0 ||
576 launch_proc(argv24) == 0 || launch_proc(argv25) == 0 ||
577 launch_proc(argv26) == 0 || launch_proc(argv27) == 0 ||
578 launch_proc(argv28) == 0) {
580 "process ran without error with invalid --lcore flag\n");
584 if (rte_lcore_is_enabled(0) && rte_lcore_is_enabled(1) &&
585 rte_lcore_is_enabled(2) && rte_lcore_is_enabled(3) &&
586 rte_lcore_is_enabled(3) && rte_lcore_is_enabled(5) &&
587 rte_lcore_is_enabled(4) && rte_lcore_is_enabled(7) &&
588 launch_proc(argv29) != 0) {
590 "process did not run ok with valid corelist value\n");
598 * Test --master-lcore option with matching coremask
601 test_master_lcore_flag(void)
603 #ifdef RTE_EXEC_ENV_FREEBSD
604 /* BSD target doesn't support prefixes at this point */
605 const char *prefix = "";
607 char prefix[PATH_MAX], tmp[PATH_MAX];
608 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
609 printf("Error - unable to get current prefix!\n");
612 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
615 if (!rte_lcore_is_enabled(0) || !rte_lcore_is_enabled(1))
618 /* --master-lcore flag but no value */
619 const char *argv1[] = { prgname, prefix, mp_flag,
620 "-c", "3", "--master-lcore"};
621 /* --master-lcore flag with invalid value */
622 const char *argv2[] = { prgname, prefix, mp_flag,
623 "-c", "3", "--master-lcore", "-1"};
624 const char *argv3[] = { prgname, prefix, mp_flag,
625 "-c", "3", "--master-lcore", "X"};
626 /* master lcore not in coremask */
627 const char *argv4[] = { prgname, prefix, mp_flag,
628 "-c", "3", "--master-lcore", "2"};
630 const char *argv5[] = { prgname, prefix, mp_flag,
631 "-c", "3", "--master-lcore", "1"};
632 /* valid value set before coremask */
633 const char *argv6[] = { prgname, prefix, mp_flag,
634 "--master-lcore", "1", "-c", "3"};
636 if (launch_proc(argv1) == 0
637 || launch_proc(argv2) == 0
638 || launch_proc(argv3) == 0
639 || launch_proc(argv4) == 0) {
640 printf("Error - process ran without error with wrong --master-lcore\n");
643 if (launch_proc(argv5) != 0
644 || launch_proc(argv6) != 0) {
645 printf("Error - process did not run ok with valid --master-lcore\n");
652 * Test that the app doesn't run with invalid -n flag option.
653 * Final test ensures it does run with valid options as sanity check
654 * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
658 test_invalid_n_flag(void)
660 #ifdef RTE_EXEC_ENV_FREEBSD
661 /* BSD target doesn't support prefixes at this point */
662 const char * prefix = "";
664 char prefix[PATH_MAX], tmp[PATH_MAX];
665 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
666 printf("Error - unable to get current prefix!\n");
669 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
672 /* -n flag but no value */
673 const char *argv1[] = { prgname, prefix, no_huge, no_shconf,
675 /* bad numeric value */
676 const char *argv2[] = { prgname, prefix, no_huge, no_shconf,
678 /* zero is invalid */
679 const char *argv3[] = { prgname, prefix, no_huge, no_shconf,
681 /* sanity test - check with good value */
682 const char *argv4[] = { prgname, prefix, no_huge, no_shconf,
684 /* sanity test - check with no -n flag */
685 const char *argv5[] = { prgname, prefix, no_huge, no_shconf};
687 if (launch_proc(argv1) == 0
688 || launch_proc(argv2) == 0
689 || launch_proc(argv3) == 0) {
690 printf("Error - process ran without error when"
691 "invalid -n flag\n");
694 if (launch_proc(argv4) != 0) {
695 printf("Error - process did not run ok with valid num-channel value\n");
698 if (launch_proc(argv5) != 0) {
699 printf("Error - process did not run ok without -n flag\n");
707 * Test that the app runs with HPET, and without HPET
710 test_no_hpet_flag(void)
712 char prefix[PATH_MAX] = "";
714 #ifdef RTE_EXEC_ENV_FREEBSD
718 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
719 printf("Error - unable to get current prefix!\n");
722 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
726 const char *argv1[] = {prgname, prefix, mp_flag, no_hpet};
727 /* Without --no-hpet */
728 const char *argv2[] = {prgname, prefix, mp_flag};
730 if (launch_proc(argv1) != 0) {
731 printf("Error - process did not run ok with --no-hpet flag\n");
734 if (launch_proc(argv2) != 0) {
735 printf("Error - process did not run ok without --no-hpet flag\n");
742 * Test that the app runs with --no-huge and doesn't run when --socket-mem are
743 * specified with --no-huge.
746 test_no_huge_flag(void)
748 #ifdef RTE_EXEC_ENV_FREEBSD
749 /* BSD target doesn't support prefixes at this point, and we also need to
750 * run another primary process here */
751 const char * prefix = no_shconf;
753 const char * prefix = "--file-prefix=nohuge";
757 const char *argv1[] = {prgname, prefix, no_huge};
758 /* With --no-huge and -m */
759 const char *argv2[] = {prgname, prefix, no_huge,
760 "-m", DEFAULT_MEM_SIZE};
762 /* With --no-huge and --socket-mem */
763 const char *argv3[] = {prgname, prefix, no_huge,
764 "--socket-mem=" DEFAULT_MEM_SIZE};
765 /* With --no-huge, -m and --socket-mem */
766 const char *argv4[] = {prgname, prefix, no_huge,
767 "-m", DEFAULT_MEM_SIZE, "--socket-mem=" DEFAULT_MEM_SIZE};
768 if (launch_proc(argv1) != 0) {
769 printf("Error - process did not run ok with --no-huge flag\n");
772 if (launch_proc(argv2) != 0) {
773 printf("Error - process did not run ok with --no-huge and -m flags\n");
776 #ifdef RTE_EXEC_ENV_FREEBSD
777 /* BSD target does not support NUMA, hence no --socket-mem tests */
781 if (launch_proc(argv3) == 0) {
782 printf("Error - process run ok with --no-huge and --socket-mem "
786 if (launch_proc(argv4) == 0) {
787 printf("Error - process run ok with --no-huge, -m and "
788 "--socket-mem flags\n");
795 test_misc_flags(void)
797 char hugepath[PATH_MAX] = {0};
798 #ifdef RTE_EXEC_ENV_FREEBSD
799 /* BSD target doesn't support prefixes at this point */
800 const char * prefix = "";
801 const char * nosh_prefix = "";
803 char prefix[PATH_MAX], tmp[PATH_MAX];
804 const char * nosh_prefix = "--file-prefix=noshconf";
805 FILE * hugedir_handle = NULL;
806 char line[PATH_MAX] = {0};
807 unsigned i, isempty = 1;
808 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
809 printf("Error - unable to get current prefix!\n");
812 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
815 * get first valid hugepage path
818 /* get hugetlbfs mountpoints from /proc/mounts */
819 hugedir_handle = fopen("/proc/mounts", "r");
821 if (hugedir_handle == NULL) {
822 printf("Error opening /proc/mounts!\n");
826 /* read /proc/mounts */
827 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
829 /* find first valid hugepath */
830 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
834 fclose(hugedir_handle);
836 /* check if path is not empty */
837 for (i = 0; i < sizeof(hugepath); i++)
838 if (hugepath[i] != '\0')
842 printf("No mounted hugepage dir found!\n");
848 /* check that some general flags don't prevent things from working.
849 * All cases, apart from the first, app should run.
850 * No further testing of output done.
852 /* sanity check - failure with invalid option */
853 const char *argv0[] = {prgname, prefix, mp_flag, "--invalid-opt"};
856 const char *argv1[] = {prgname, prefix, mp_flag, "--no-pci"};
858 const char *argv2[] = {prgname, prefix, mp_flag, "-v"};
859 /* With valid --syslog */
860 const char *argv3[] = {prgname, prefix, mp_flag,
861 "--syslog", "syslog"};
862 /* With empty --syslog (should fail) */
863 const char *argv4[] = {prgname, prefix, mp_flag, "--syslog"};
864 /* With invalid --syslog */
865 const char *argv5[] = {prgname, prefix, mp_flag, "--syslog", "error"};
866 /* With no-sh-conf, also use no-huge to ensure this test runs on BSD */
867 const char *argv6[] = {prgname, "-m", DEFAULT_MEM_SIZE,
868 no_shconf, nosh_prefix, no_huge};
870 /* With --huge-dir */
871 const char *argv7[] = {prgname, "-m", DEFAULT_MEM_SIZE,
872 "--file-prefix=hugedir", "--huge-dir", hugepath};
873 /* With empty --huge-dir (should fail) */
874 const char *argv8[] = {prgname, "-m", DEFAULT_MEM_SIZE,
875 "--file-prefix=hugedir", "--huge-dir"};
876 /* With invalid --huge-dir */
877 const char *argv9[] = {prgname, "-m", DEFAULT_MEM_SIZE,
878 "--file-prefix=hugedir", "--huge-dir", "invalid"};
879 /* Secondary process with invalid --huge-dir (should run as flag has no
880 * effect on secondary processes) */
881 const char *argv10[] = {prgname, prefix, mp_flag,
882 "--huge-dir", "invalid"};
884 /* try running with base-virtaddr param */
885 const char *argv11[] = {prgname, "--file-prefix=virtaddr",
886 "--base-virtaddr=0x12345678"};
888 /* try running with --vfio-intr INTx flag */
889 const char *argv12[] = {prgname, "--file-prefix=intr",
890 "--vfio-intr=legacy"};
892 /* try running with --vfio-intr MSI flag */
893 const char *argv13[] = {prgname, "--file-prefix=intr",
896 /* try running with --vfio-intr MSI-X flag */
897 const char *argv14[] = {prgname, "--file-prefix=intr",
900 /* try running with --vfio-intr invalid flag */
901 const char *argv15[] = {prgname, "--file-prefix=intr",
902 "--vfio-intr=invalid"};
904 /* run all tests also applicable to FreeBSD first */
906 if (launch_proc(argv0) == 0) {
907 printf("Error - process ran ok with invalid flag\n");
910 if (launch_proc(argv1) != 0) {
911 printf("Error - process did not run ok with --no-pci flag\n");
914 if (launch_proc(argv2) != 0) {
915 printf("Error - process did not run ok with -v flag\n");
918 if (launch_proc(argv6) != 0) {
919 printf("Error - process did not run ok with --no-shconf flag\n");
923 #ifdef RTE_EXEC_ENV_FREEBSD
924 /* no more tests to be done on FreeBSD */
928 if (launch_proc(argv3) != 0) {
929 printf("Error - process did not run ok with --syslog flag\n");
932 if (launch_proc(argv4) == 0) {
933 printf("Error - process run ok with empty --syslog flag\n");
936 if (launch_proc(argv5) == 0) {
937 printf("Error - process run ok with invalid --syslog flag\n");
940 if (launch_proc(argv7) != 0) {
941 printf("Error - process did not run ok with --huge-dir flag\n");
944 if (launch_proc(argv8) == 0) {
945 printf("Error - process run ok with empty --huge-dir flag\n");
948 if (launch_proc(argv9) == 0) {
949 printf("Error - process run ok with invalid --huge-dir flag\n");
952 if (launch_proc(argv10) != 0) {
953 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
956 if (launch_proc(argv11) != 0) {
957 printf("Error - process did not run ok with --base-virtaddr parameter\n");
960 if (launch_proc(argv12) != 0) {
961 printf("Error - process did not run ok with "
962 "--vfio-intr INTx parameter\n");
965 if (launch_proc(argv13) != 0) {
966 printf("Error - process did not run ok with "
967 "--vfio-intr MSI parameter\n");
970 if (launch_proc(argv14) != 0) {
971 printf("Error - process did not run ok with "
972 "--vfio-intr MSI-X parameter\n");
975 if (launch_proc(argv15) == 0) {
976 printf("Error - process run ok with "
977 "--vfio-intr invalid parameter\n");
984 test_file_prefix(void)
987 * 1. check if current process hugefiles are locked
988 * 2. try to run secondary process without a corresponding primary process
989 * (while failing to run, it will also remove any unused hugepage files)
990 * 3. check if current process hugefiles are still in place and are locked
991 * 4. run a primary process with memtest1 prefix in default and legacy
993 * 5. check if memtest1 hugefiles are created in case of legacy mem
994 * mode, and deleted in case of default mem mode
995 * 6. run a primary process with memtest2 prefix in default and legacy
997 * 7. check that memtest2 hugefiles are present in the hugedir after a
998 * run in legacy mode, and not present at all after run in default
1001 char prefix[PATH_MAX] = "";
1003 #ifdef RTE_EXEC_ENV_FREEBSD
1006 if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
1007 printf("Error - unable to get current prefix!\n");
1012 /* this should fail unless the test itself is run with "memtest" prefix */
1013 const char *argv0[] = {prgname, mp_flag, "-m",
1014 DEFAULT_MEM_SIZE, "--file-prefix=" memtest };
1016 /* primary process with memtest1 and default mem mode */
1017 const char *argv1[] = {prgname, "-m",
1018 DEFAULT_MEM_SIZE, "--file-prefix=" memtest1 };
1020 /* primary process with memtest1 and legacy mem mode */
1021 const char *argv2[] = {prgname, "-m",
1022 DEFAULT_MEM_SIZE, "--file-prefix=" memtest1,
1025 /* primary process with memtest2 and legacy mem mode */
1026 const char *argv3[] = {prgname, "-m",
1027 DEFAULT_MEM_SIZE, "--file-prefix=" memtest2,
1030 /* primary process with memtest2 and default mem mode */
1031 const char *argv4[] = {prgname, "-m",
1032 DEFAULT_MEM_SIZE, "--file-prefix=" memtest2 };
1034 /* check if files for current prefix are present */
1035 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1036 printf("Error - hugepage files for %s were not created!\n", prefix);
1040 /* checks if files for current prefix are locked */
1041 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1042 printf("Error - hugepages for current process aren't locked!\n");
1046 /* check if files for secondary process are present */
1047 if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
1048 /* check if they are not locked */
1049 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
1050 printf("Error - hugepages for current process are locked!\n");
1053 /* they aren't locked, delete them */
1055 if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
1056 printf("Error - deleting hugepages failed!\n");
1062 if (launch_proc(argv0) == 0) {
1063 printf("Error - secondary process ran ok without primary process\n");
1067 /* check if files for current prefix are present */
1068 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1069 printf("Error - hugepage files for %s were not created!\n", prefix);
1073 /* checks if files for current prefix are locked */
1074 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1075 printf("Error - hugepages for current process aren't locked!\n");
1079 /* we're running this process in default memory mode, which means it
1080 * should clean up after itself on exit and leave no hugepages behind.
1082 if (launch_proc(argv1) != 0) {
1083 printf("Error - failed to run with --file-prefix=%s\n",
1088 /* check if memtest1_map0 is present */
1089 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1090 printf("Error - hugepage files for %s were not deleted!\n",
1095 /* now, we're running a process under the same prefix, but with legacy
1096 * mem mode - this should leave behind hugepage files.
1098 if (launch_proc(argv2) != 0) {
1099 printf("Error - failed to run with --file-prefix=%s\n",
1104 /* check if memtest1_map0 is present */
1105 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
1106 printf("Error - hugepage files for %s were not created!\n",
1111 if (launch_proc(argv3) != 0) {
1112 printf("Error - failed to run with --file-prefix=%s\n",
1117 /* check if hugefiles for memtest2 are present */
1118 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
1119 printf("Error - hugepage files for %s were not created!\n",
1124 /* check if hugefiles for memtest1 are present */
1125 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1126 printf("Error - hugepage files for %s were not deleted!\n",
1131 /* this process will run in default mem mode, so it should not leave any
1132 * hugepage files behind.
1134 if (launch_proc(argv4) != 0) {
1135 printf("Error - failed to run with --file-prefix=%s\n",
1140 /* check if hugefiles for memtest2 are present */
1141 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 0) {
1142 printf("Error - hugepage files for %s were not deleted!\n",
1147 /* check if hugefiles for memtest1 are present */
1148 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1149 printf("Error - hugepage files for %s were not deleted!\n",
1158 * Tests for correct handling of -m and --socket-mem flags
1161 test_memory_flags(void)
1163 #ifdef RTE_EXEC_ENV_FREEBSD
1164 /* BSD target doesn't support prefixes at this point */
1165 const char * prefix = "";
1167 char prefix[PATH_MAX], tmp[PATH_MAX];
1168 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
1169 printf("Error - unable to get current prefix!\n");
1172 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
1175 /* valid -m flag and mp flag */
1176 const char *argv0[] = {prgname, prefix, mp_flag,
1177 "-m", DEFAULT_MEM_SIZE};
1180 const char *argv1[] = {prgname,
1181 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE};
1183 /* valid (zero) --socket-mem flag */
1184 const char *argv2[] = {prgname,
1185 "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
1187 /* invalid (incomplete) --socket-mem flag */
1188 const char *argv3[] = {prgname,
1189 "--file-prefix=" memtest, "--socket-mem=2,2,"};
1191 /* invalid (mixed with invalid data) --socket-mem flag */
1192 const char *argv4[] = {prgname,
1193 "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
1195 /* invalid (with numeric value as last character) --socket-mem flag */
1196 const char *argv5[] = {prgname,
1197 "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
1199 /* invalid (with empty socket) --socket-mem flag */
1200 const char *argv6[] = {prgname,
1201 "--file-prefix=" memtest, "--socket-mem=2,,2"};
1203 /* invalid (null) --socket-mem flag */
1204 const char *argv7[] = {prgname,
1205 "--file-prefix=" memtest, "--socket-mem="};
1207 /* valid --socket-mem specified together with -m flag */
1208 const char *argv8[] = {prgname,
1209 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE, "--socket-mem=2,2"};
1211 /* construct an invalid socket mask with 2 megs on each socket plus
1212 * extra 2 megs on socket that doesn't exist on current system */
1213 char invalid_socket_mem[SOCKET_MEM_STRLEN];
1214 char buf[SOCKET_MEM_STRLEN]; /* to avoid copying string onto itself */
1216 #ifdef RTE_EXEC_ENV_FREEBSD
1217 int i, num_sockets = 1;
1219 int i, num_sockets = RTE_MIN(get_number_of_sockets(),
1220 RTE_MAX_NUMA_NODES);
1223 if (num_sockets <= 0) {
1224 printf("Error - cannot get number of sockets!\n");
1228 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
1230 /* add one extra socket */
1231 for (i = 0; i < num_sockets + 1; i++) {
1232 snprintf(buf, sizeof(buf), "%s%s", invalid_socket_mem, DEFAULT_MEM_SIZE);
1233 strlcpy(invalid_socket_mem, buf, sizeof(invalid_socket_mem));
1235 if (num_sockets + 1 - i > 1) {
1236 snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
1237 strlcpy(invalid_socket_mem, buf,
1238 sizeof(invalid_socket_mem));
1242 /* construct a valid socket mask with 2 megs on each existing socket */
1243 char valid_socket_mem[SOCKET_MEM_STRLEN];
1245 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
1247 /* add one extra socket */
1248 for (i = 0; i < num_sockets; i++) {
1249 snprintf(buf, sizeof(buf), "%s%s", valid_socket_mem, DEFAULT_MEM_SIZE);
1250 strlcpy(valid_socket_mem, buf, sizeof(valid_socket_mem));
1252 if (num_sockets - i > 1) {
1253 snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
1254 strlcpy(valid_socket_mem, buf,
1255 sizeof(valid_socket_mem));
1259 /* invalid --socket-mem flag (with extra socket) */
1260 const char *argv9[] = {prgname,
1261 "--file-prefix=" memtest, invalid_socket_mem};
1263 /* valid --socket-mem flag */
1264 const char *argv10[] = {prgname,
1265 "--file-prefix=" memtest, valid_socket_mem};
1267 if (launch_proc(argv0) != 0) {
1268 printf("Error - secondary process failed with valid -m flag !\n");
1272 #ifdef RTE_EXEC_ENV_FREEBSD
1273 /* no other tests are applicable to BSD */
1277 if (launch_proc(argv1) != 0) {
1278 printf("Error - process failed with valid -m flag!\n");
1281 if (launch_proc(argv2) != 0) {
1282 printf("Error - process failed with valid (zero) --socket-mem!\n");
1286 if (launch_proc(argv3) == 0) {
1287 printf("Error - process run ok with invalid "
1288 "(incomplete) --socket-mem!\n");
1292 if (launch_proc(argv4) == 0) {
1293 printf("Error - process run ok with invalid "
1294 "(mixed with invalid input) --socket-mem!\n");
1298 if (launch_proc(argv5) == 0) {
1299 printf("Error - process run ok with invalid "
1300 "(mixed with invalid input with a numeric value as "
1301 "last character) --socket-mem!\n");
1305 if (launch_proc(argv6) == 0) {
1306 printf("Error - process run ok with invalid "
1307 "(with empty socket) --socket-mem!\n");
1311 if (launch_proc(argv7) == 0) {
1312 printf("Error - process run ok with invalid (null) --socket-mem!\n");
1316 if (launch_proc(argv8) == 0) {
1317 printf("Error - process run ok with --socket-mem and -m specified!\n");
1321 if (launch_proc(argv9) == 0) {
1322 printf("Error - process run ok with extra socket in --socket-mem!\n");
1326 if (launch_proc(argv10) != 0) {
1327 printf("Error - process failed with valid --socket-mem!\n");
1335 test_eal_flags(void)
1339 ret = test_missing_c_flag();
1341 printf("Error in test_missing_c_flag()\n");
1345 ret = test_master_lcore_flag();
1347 printf("Error in test_master_lcore_flag()\n");
1351 ret = test_invalid_n_flag();
1353 printf("Error in test_invalid_n_flag()\n");
1357 ret = test_no_hpet_flag();
1359 printf("Error in test_no_hpet_flag()\n");
1363 ret = test_no_huge_flag();
1365 printf("Error in test_no_huge_flag()\n");
1369 ret = test_whitelist_flag();
1371 printf("Error in test_invalid_whitelist_flag()\n");
1375 ret = test_invalid_b_flag();
1377 printf("Error in test_invalid_b_flag()\n");
1381 #ifdef RTE_LIBRTE_PMD_RING
1382 ret = test_invalid_vdev_flag();
1384 printf("Error in test_invalid_vdev_flag()\n");
1388 ret = test_invalid_r_flag();
1390 printf("Error in test_invalid_r_flag()\n");
1394 ret = test_memory_flags();
1396 printf("Error in test_memory_flags()\n");
1400 ret = test_file_prefix();
1402 printf("Error in test_file_prefix()\n");
1406 ret = test_misc_flags();
1408 printf("Error in test_misc_flags()");
1415 REGISTER_TEST_COMMAND(eal_flags_autotest, test_eal_flags);