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, RTE_DIM(ARGV), __func__)
41 enum hugepage_action {
42 HUGEPAGE_CHECK_EXISTS = 0,
43 HUGEPAGE_CHECK_LOCKED,
48 /* if string contains a hugepage path */
50 get_hugepage_path(char * src, int src_len, char * dst, int dst_len)
53 char *tokens[NUM_TOKENS];
55 /* if we couldn't properly split the string */
56 if (rte_strsplit(src, src_len, tokens, NUM_TOKENS, ' ') < NUM_TOKENS)
59 if (strncmp(tokens[2], "hugetlbfs", sizeof("hugetlbfs")) == 0) {
60 strlcpy(dst, tokens[1], dst_len);
67 * Cycles through hugepage directories and looks for hugepage
68 * files associated with a given prefix. Depending on value of
69 * action, the hugepages are checked if they exist, checked if
70 * they can be locked, or are simply deleted.
72 * Returns 1 if it finds at least one hugepage matching the action
73 * Returns 0 if no matching hugepages were found
74 * Returns -1 if it encounters an error
77 process_hugefiles(const char * prefix, enum hugepage_action action)
79 FILE * hugedir_handle = NULL;
80 DIR * hugepage_dir = NULL;
81 struct dirent *dirent = NULL;
83 char hugefile_prefix[PATH_MAX] = {0};
84 char hugedir[PATH_MAX] = {0};
85 char line[PATH_MAX] = {0};
87 int fd, lck_result, result = 0;
89 const int prefix_len = snprintf(hugefile_prefix,
90 sizeof(hugefile_prefix), "%smap_", prefix);
91 if (prefix_len <= 0 || prefix_len >= (int)sizeof(hugefile_prefix)
92 || prefix_len >= (int)sizeof(dirent->d_name)) {
93 printf("Error creating hugefile filename prefix\n");
97 /* get hugetlbfs mountpoints from /proc/mounts */
98 hugedir_handle = fopen("/proc/mounts", "r");
100 if (hugedir_handle == NULL) {
101 printf("Error parsing /proc/mounts!\n");
105 /* read and parse script output */
106 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
108 /* check if we have a hugepage filesystem path */
109 if (!get_hugepage_path(line, sizeof(line), hugedir, sizeof(hugedir)))
112 /* check if directory exists */
113 if ((hugepage_dir = opendir(hugedir)) == NULL) {
114 fclose(hugedir_handle);
115 printf("Error reading %s: %s\n", hugedir, strerror(errno));
119 while ((dirent = readdir(hugepage_dir)) != NULL) {
120 if (memcmp(dirent->d_name, hugefile_prefix, prefix_len) != 0)
124 case HUGEPAGE_CHECK_EXISTS:
126 /* file exists, return */
131 case HUGEPAGE_DELETE:
133 char file_path[PATH_MAX] = {0};
135 snprintf(file_path, sizeof(file_path),
136 "%s/%s", hugedir, dirent->d_name);
139 if (remove(file_path) < 0) {
140 printf("Error deleting %s - %s!\n",
141 dirent->d_name, strerror(errno));
142 closedir(hugepage_dir);
149 case HUGEPAGE_CHECK_LOCKED:
151 /* try and lock the file */
152 fd = openat(dirfd(hugepage_dir), dirent->d_name, O_RDONLY);
154 /* this shouldn't happen */
156 printf("Error opening %s - %s!\n",
157 dirent->d_name, strerror(errno));
158 closedir(hugepage_dir);
163 /* non-blocking lock */
164 lck_result = flock(fd, LOCK_EX | LOCK_NB);
166 /* if lock succeeds, there's something wrong */
167 if (lck_result != -1) {
170 /* unlock the resulting lock */
173 closedir(hugepage_dir);
180 /* shouldn't happen */
185 } /* read hugepage directory */
186 closedir(hugepage_dir);
187 } /* read /proc/mounts */
189 fclose(hugedir_handle);
193 #ifdef RTE_EXEC_ENV_LINUX
195 * count the number of "node*" files in /sys/devices/system/node/
198 get_number_of_sockets(void)
200 struct dirent *dirent = NULL;
201 const char * nodedir = "/sys/devices/system/node/";
205 /* check if directory exists */
206 if ((dir = opendir(nodedir)) == NULL) {
207 /* if errno==ENOENT this means we don't have NUMA support */
208 if (errno == ENOENT) {
209 printf("No NUMA nodes detected: assuming 1 available socket\n");
212 printf("Error opening %s: %s\n", nodedir, strerror(errno));
216 while ((dirent = readdir(dir)) != NULL)
217 if (strncmp(dirent->d_name, "node", sizeof("node") - 1) == 0)
226 * Test that the app doesn't run with invalid whitelist option.
227 * Final tests ensures it does run with valid options as sanity check (one
228 * test for with Domain+BDF, second for just with BDF)
231 test_whitelist_flag(void)
234 #ifdef RTE_EXEC_ENV_FREEBSD
235 /* BSD target doesn't support prefixes at this point */
236 const char * prefix = "";
238 char prefix[PATH_MAX], tmp[PATH_MAX];
239 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
240 printf("Error - unable to get current prefix!\n");
243 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
246 const char *wlinval[][7] = {
247 {prgname, prefix, mp_flag,
248 pci_whitelist, "error", "", ""},
249 {prgname, prefix, mp_flag,
250 pci_whitelist, "0:0:0", "", ""},
251 {prgname, prefix, mp_flag,
252 pci_whitelist, "0:error:0.1", "", ""},
253 {prgname, prefix, mp_flag,
254 pci_whitelist, "0:0:0.1error", "", ""},
255 {prgname, prefix, mp_flag,
256 pci_whitelist, "error0:0:0.1", "", ""},
257 {prgname, prefix, mp_flag,
258 pci_whitelist, "0:0:0.1.2", "", ""},
260 /* Test with valid whitelist option */
261 const char *wlval1[] = {prgname, prefix, mp_flag,
262 pci_whitelist, "00FF:09:0B.3"};
263 const char *wlval2[] = {prgname, prefix, mp_flag,
264 pci_whitelist, "09:0B.3", pci_whitelist, "0a:0b.1"};
265 const char *wlval3[] = {prgname, prefix, mp_flag,
266 pci_whitelist, "09:0B.3,type=test",
267 pci_whitelist, "08:00.1,type=normal",
270 for (i = 0; i < RTE_DIM(wlinval); i++) {
271 if (launch_proc(wlinval[i]) == 0) {
272 printf("Error - process did run ok with invalid "
273 "whitelist parameter\n");
277 if (launch_proc(wlval1) != 0 ) {
278 printf("Error - process did not run ok with valid whitelist\n");
281 if (launch_proc(wlval2) != 0 ) {
282 printf("Error - process did not run ok with valid whitelist value set\n");
285 if (launch_proc(wlval3) != 0 ) {
286 printf("Error - process did not run ok with valid whitelist + args\n");
294 * Test that the app doesn't run with invalid blacklist option.
295 * Final test ensures it does run with valid options as sanity check
298 test_invalid_b_flag(void)
300 #ifdef RTE_EXEC_ENV_FREEBSD
301 /* BSD target doesn't support prefixes at this point */
302 const char * prefix = "";
304 char prefix[PATH_MAX], tmp[PATH_MAX];
305 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
306 printf("Error - unable to get current prefix!\n");
309 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
312 const char *blinval[][5] = {
313 {prgname, prefix, mp_flag, "-b", "error"},
314 {prgname, prefix, mp_flag, "-b", "0:0:0"},
315 {prgname, prefix, mp_flag, "-b", "0:error:0.1"},
316 {prgname, prefix, mp_flag, "-b", "0:0:0.1error"},
317 {prgname, prefix, mp_flag, "-b", "error0:0:0.1"},
318 {prgname, prefix, mp_flag, "-b", "0:0:0.1.2"},
320 /* Test with valid blacklist option */
321 const char *blval[] = {prgname, prefix, mp_flag,
326 for (i = 0; i != RTE_DIM(blinval); i++) {
327 if (launch_proc(blinval[i]) == 0) {
328 printf("Error - process did run ok with invalid "
329 "blacklist parameter\n");
333 if (launch_proc(blval) != 0) {
334 printf("Error - process did not run ok with valid blacklist value\n");
341 * Test that the app doesn't run with invalid vdev option.
342 * Final test ensures it does run with valid options as sanity check
345 test_invalid_vdev_flag(void)
347 #ifdef RTE_LIBRTE_PMD_RING
348 #ifdef RTE_EXEC_ENV_FREEBSD
349 /* BSD target doesn't support prefixes at this point, and we also need to
350 * run another primary process here */
351 const char * prefix = no_shconf;
353 const char * prefix = "--file-prefix=vdev";
356 /* Test with invalid vdev option */
357 const char *vdevinval[] = {prgname, prefix, no_huge,
360 /* Test with valid vdev option */
361 const char *vdevval1[] = {prgname, prefix, no_huge,
364 const char *vdevval2[] = {prgname, prefix, no_huge,
365 vdev, "net_ring0,args=test"};
367 const char *vdevval3[] = {prgname, prefix, no_huge,
368 vdev, "net_ring0,nodeaction=r1:0:CREATE"};
370 if (launch_proc(vdevinval) == 0) {
371 printf("Error - process did run ok with invalid "
376 if (launch_proc(vdevval1) != 0) {
377 printf("Error - process did not run ok with valid vdev value\n");
381 if (launch_proc(vdevval2) != 0) {
382 printf("Error - process did not run ok with valid vdev value,"
383 "with dummy args\n");
387 if (launch_proc(vdevval3) != 0) {
388 printf("Error - process did not run ok with valid vdev value,"
389 "with valid args\n");
399 * Test that the app doesn't run with invalid -r option.
402 test_invalid_r_flag(void)
404 #ifdef RTE_EXEC_ENV_FREEBSD
405 /* BSD target doesn't support prefixes at this point */
406 const char * prefix = "";
408 char prefix[PATH_MAX], tmp[PATH_MAX];
409 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
410 printf("Error - unable to get current prefix!\n");
413 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
416 const char *rinval[][5] = {
417 {prgname, prefix, mp_flag, "-r", "error"},
418 {prgname, prefix, mp_flag, "-r", "0"},
419 {prgname, prefix, mp_flag, "-r", "-1"},
420 {prgname, prefix, mp_flag, "-r", "17"},
422 /* Test with valid blacklist option */
423 const char *rval[] = {prgname, prefix, mp_flag, "-r", "16"};
427 for (i = 0; i != RTE_DIM(rinval); i++) {
428 if (launch_proc(rinval[i]) == 0) {
429 printf("Error - process did run ok with invalid "
430 "-r (rank) parameter\n");
434 if (launch_proc(rval) != 0) {
435 printf("Error - process did not run ok with valid -r (rank) value\n");
442 * Test that the app doesn't run without the coremask/corelist flags. In all cases
443 * should give an error and fail to run
446 test_missing_c_flag(void)
448 #ifdef RTE_EXEC_ENV_FREEBSD
449 /* BSD target doesn't support prefixes at this point */
450 const char * prefix = "";
452 char prefix[PATH_MAX], tmp[PATH_MAX];
453 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
454 printf("Error - unable to get current prefix!\n");
457 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
460 /* -c flag but no coremask value */
461 const char *argv1[] = { prgname, prefix, mp_flag, "-c"};
462 /* No -c, -l or --lcores flag at all */
463 const char *argv2[] = { prgname, prefix, mp_flag};
464 /* bad coremask value */
465 const char *argv3[] = { prgname, prefix, mp_flag,
467 /* sanity check of tests - valid coremask value */
468 const char *argv4[] = { prgname, prefix, mp_flag,
470 /* -l flag but no corelist value */
471 const char *argv5[] = { prgname, prefix, mp_flag,
473 const char *argv6[] = { prgname, prefix, mp_flag,
475 /* bad corelist values */
476 const char *argv7[] = { prgname, prefix, mp_flag,
478 const char *argv8[] = { prgname, prefix, mp_flag,
480 const char *argv9[] = { prgname, prefix, mp_flag,
482 const char *argv10[] = { prgname, prefix, mp_flag,
484 /* core number is negative value */
485 const char * const argv11[] = { prgname, prefix, mp_flag,
487 const char * const argv12[] = { prgname, prefix, mp_flag,
489 /* core number is maximum value */
490 const char * const argv13[] = { prgname, prefix, mp_flag,
491 "-l", RTE_STR(RTE_MAX_LCORE) };
492 const char * const argv14[] = { prgname, prefix, mp_flag,
493 "-l", "1-"RTE_STR(RTE_MAX_LCORE) };
494 /* sanity check test - valid corelist value */
495 const char * const argv15[] = { prgname, prefix, mp_flag,
498 /* --lcores flag but no lcores value */
499 const char * const argv16[] = { prgname, prefix, mp_flag,
501 const char * const argv17[] = { prgname, prefix, mp_flag,
503 /* bad lcores value */
504 const char * const argv18[] = { prgname, prefix, mp_flag,
505 "--lcores", "1-3-5" };
506 const char * const argv19[] = { prgname, prefix, mp_flag,
507 "--lcores", "0-1,,2" };
508 const char * const argv20[] = { prgname, prefix, mp_flag,
509 "--lcores", "0-,1" };
510 const char * const argv21[] = { prgname, prefix, mp_flag,
511 "--lcores", "(0-,2-4)" };
512 const char * const argv22[] = { prgname, prefix, mp_flag,
513 "--lcores", "(-1,2)" };
514 const char * const argv23[] = { prgname, prefix, mp_flag,
515 "--lcores", "(2-4)@(2-4-6)" };
516 const char * const argv24[] = { prgname, prefix, mp_flag,
517 "--lcores", "(a,2)" };
518 const char * const argv25[] = { prgname, prefix, mp_flag,
519 "--lcores", "1-3@(1,3)" };
520 const char * const argv26[] = { prgname, prefix, mp_flag,
521 "--lcores", "3@((1,3)" };
522 const char * const argv27[] = { prgname, prefix, mp_flag,
523 "--lcores", "(4-7)=(1,3)" };
524 const char * const argv28[] = { prgname, prefix, mp_flag,
525 "--lcores", "[4-7]@(1,3)" };
526 /* sanity check of tests - valid lcores value */
527 const char * const argv29[] = { prgname, prefix, mp_flag,
529 "0-1,2@(5-7),(3-5)@(0,2),(0,6),7"};
531 if (launch_proc(argv2) != 0) {
533 "process did not run ok when missing -c flag\n");
537 if (launch_proc(argv1) == 0
538 || launch_proc(argv3) == 0) {
540 "process ran without error with invalid -c flag\n");
543 if (launch_proc(argv4) != 0) {
545 "process did not run ok with valid coremask value\n");
550 if (launch_proc(argv5) == 0
551 || launch_proc(argv6) == 0
552 || launch_proc(argv7) == 0
553 || launch_proc(argv8) == 0
554 || launch_proc(argv9) == 0
555 || launch_proc(argv10) == 0
556 || launch_proc(argv11) == 0
557 || launch_proc(argv12) == 0
558 || launch_proc(argv13) == 0
559 || launch_proc(argv14) == 0) {
561 "process ran without error with invalid -l flag\n");
564 if (rte_lcore_is_enabled(0) && rte_lcore_is_enabled(1) &&
565 rte_lcore_is_enabled(2) && rte_lcore_is_enabled(3) &&
566 launch_proc(argv15) != 0) {
568 "process did not run ok with valid corelist value\n");
572 /* start --lcores tests */
573 if (launch_proc(argv16) == 0 || launch_proc(argv17) == 0 ||
574 launch_proc(argv18) == 0 || launch_proc(argv19) == 0 ||
575 launch_proc(argv20) == 0 || launch_proc(argv21) == 0 ||
576 launch_proc(argv22) == 0 || launch_proc(argv23) == 0 ||
577 launch_proc(argv24) == 0 || launch_proc(argv25) == 0 ||
578 launch_proc(argv26) == 0 || launch_proc(argv27) == 0 ||
579 launch_proc(argv28) == 0) {
581 "process ran without error with invalid --lcore flag\n");
585 if (rte_lcore_is_enabled(0) && rte_lcore_is_enabled(1) &&
586 rte_lcore_is_enabled(2) && rte_lcore_is_enabled(3) &&
587 rte_lcore_is_enabled(3) && rte_lcore_is_enabled(5) &&
588 rte_lcore_is_enabled(4) && rte_lcore_is_enabled(7) &&
589 launch_proc(argv29) != 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_FREEBSD
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 if (!rte_lcore_is_enabled(0) || !rte_lcore_is_enabled(1))
619 /* --master-lcore flag but no value */
620 const char *argv1[] = { prgname, prefix, mp_flag,
621 "-c", "3", "--master-lcore"};
622 /* --master-lcore flag with invalid value */
623 const char *argv2[] = { prgname, prefix, mp_flag,
624 "-c", "3", "--master-lcore", "-1"};
625 const char *argv3[] = { prgname, prefix, mp_flag,
626 "-c", "3", "--master-lcore", "X"};
627 /* master lcore not in coremask */
628 const char *argv4[] = { prgname, prefix, mp_flag,
629 "-c", "3", "--master-lcore", "2"};
631 const char *argv5[] = { prgname, prefix, mp_flag,
632 "-c", "3", "--master-lcore", "1"};
633 /* valid value set before coremask */
634 const char *argv6[] = { prgname, prefix, mp_flag,
635 "--master-lcore", "1", "-c", "3"};
637 if (launch_proc(argv1) == 0
638 || launch_proc(argv2) == 0
639 || launch_proc(argv3) == 0
640 || launch_proc(argv4) == 0) {
641 printf("Error - process ran without error with wrong --master-lcore\n");
644 if (launch_proc(argv5) != 0
645 || launch_proc(argv6) != 0) {
646 printf("Error - process did not run ok with valid --master-lcore\n");
653 * Test that the app doesn't run with invalid -n flag option.
654 * Final test ensures it does run with valid options as sanity check
655 * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
659 test_invalid_n_flag(void)
661 #ifdef RTE_EXEC_ENV_FREEBSD
662 /* BSD target doesn't support prefixes at this point */
663 const char * prefix = "";
665 char prefix[PATH_MAX], tmp[PATH_MAX];
666 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
667 printf("Error - unable to get current prefix!\n");
670 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
673 /* -n flag but no value */
674 const char *argv1[] = { prgname, prefix, no_huge, no_shconf,
676 /* bad numeric value */
677 const char *argv2[] = { prgname, prefix, no_huge, no_shconf,
679 /* zero is invalid */
680 const char *argv3[] = { prgname, prefix, no_huge, no_shconf,
682 /* sanity test - check with good value */
683 const char *argv4[] = { prgname, prefix, no_huge, no_shconf,
685 /* sanity test - check with no -n flag */
686 const char *argv5[] = { prgname, prefix, no_huge, no_shconf};
688 if (launch_proc(argv1) == 0
689 || launch_proc(argv2) == 0
690 || launch_proc(argv3) == 0) {
691 printf("Error - process ran without error when"
692 "invalid -n flag\n");
695 if (launch_proc(argv4) != 0) {
696 printf("Error - process did not run ok with valid num-channel value\n");
699 if (launch_proc(argv5) != 0) {
700 printf("Error - process did not run ok without -n flag\n");
708 * Test that the app runs with HPET, and without HPET
711 test_no_hpet_flag(void)
713 char prefix[PATH_MAX] = "";
715 #ifdef RTE_EXEC_ENV_FREEBSD
719 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
720 printf("Error - unable to get current prefix!\n");
723 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
727 const char *argv1[] = {prgname, prefix, mp_flag, no_hpet};
728 /* Without --no-hpet */
729 const char *argv2[] = {prgname, prefix, mp_flag};
731 if (launch_proc(argv1) != 0) {
732 printf("Error - process did not run ok with --no-hpet flag\n");
735 if (launch_proc(argv2) != 0) {
736 printf("Error - process did not run ok without --no-hpet flag\n");
743 * Test that the app runs with --no-huge and doesn't run when --socket-mem are
744 * specified with --no-huge.
747 test_no_huge_flag(void)
749 #ifdef RTE_EXEC_ENV_FREEBSD
750 /* BSD target doesn't support prefixes at this point, and we also need to
751 * run another primary process here */
752 const char * prefix = no_shconf;
754 const char * prefix = "--file-prefix=nohuge";
758 const char *argv1[] = {prgname, prefix, no_huge};
759 /* With --no-huge and -m */
760 const char *argv2[] = {prgname, prefix, no_huge,
761 "-m", DEFAULT_MEM_SIZE};
763 /* With --no-huge and --socket-mem */
764 const char *argv3[] = {prgname, prefix, no_huge,
765 "--socket-mem=" DEFAULT_MEM_SIZE};
766 /* With --no-huge, -m and --socket-mem */
767 const char *argv4[] = {prgname, prefix, no_huge,
768 "-m", DEFAULT_MEM_SIZE, "--socket-mem=" DEFAULT_MEM_SIZE};
769 if (launch_proc(argv1) != 0) {
770 printf("Error - process did not run ok with --no-huge flag\n");
773 if (launch_proc(argv2) != 0) {
774 printf("Error - process did not run ok with --no-huge and -m flags\n");
777 #ifdef RTE_EXEC_ENV_FREEBSD
778 /* BSD target does not support NUMA, hence no --socket-mem tests */
782 if (launch_proc(argv3) == 0) {
783 printf("Error - process run ok with --no-huge and --socket-mem "
787 if (launch_proc(argv4) == 0) {
788 printf("Error - process run ok with --no-huge, -m and "
789 "--socket-mem flags\n");
796 test_misc_flags(void)
798 char hugepath[PATH_MAX] = {0};
799 #ifdef RTE_EXEC_ENV_FREEBSD
800 /* BSD target doesn't support prefixes at this point */
801 const char * prefix = "";
802 const char * nosh_prefix = "";
804 char prefix[PATH_MAX], tmp[PATH_MAX];
805 const char * nosh_prefix = "--file-prefix=noshconf";
806 FILE * hugedir_handle = NULL;
807 char line[PATH_MAX] = {0};
808 unsigned i, isempty = 1;
809 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
810 printf("Error - unable to get current prefix!\n");
813 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
816 * get first valid hugepage path
819 /* get hugetlbfs mountpoints from /proc/mounts */
820 hugedir_handle = fopen("/proc/mounts", "r");
822 if (hugedir_handle == NULL) {
823 printf("Error opening /proc/mounts!\n");
827 /* read /proc/mounts */
828 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
830 /* find first valid hugepath */
831 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
835 fclose(hugedir_handle);
837 /* check if path is not empty */
838 for (i = 0; i < sizeof(hugepath); i++)
839 if (hugepath[i] != '\0')
843 printf("No mounted hugepage dir found!\n");
849 /* check that some general flags don't prevent things from working.
850 * All cases, apart from the first, app should run.
851 * No further testing of output done.
853 /* sanity check - failure with invalid option */
854 const char *argv0[] = {prgname, prefix, mp_flag, "--invalid-opt"};
857 const char *argv1[] = {prgname, prefix, mp_flag, "--no-pci"};
859 const char *argv2[] = {prgname, prefix, mp_flag, "-v"};
860 /* With valid --syslog */
861 const char *argv3[] = {prgname, prefix, mp_flag,
862 "--syslog", "syslog"};
863 /* With empty --syslog (should fail) */
864 const char *argv4[] = {prgname, prefix, mp_flag, "--syslog"};
865 /* With invalid --syslog */
866 const char *argv5[] = {prgname, prefix, mp_flag, "--syslog", "error"};
867 /* With no-sh-conf, also use no-huge to ensure this test runs on BSD */
868 const char *argv6[] = {prgname, "-m", DEFAULT_MEM_SIZE,
869 no_shconf, nosh_prefix, no_huge};
871 /* With --huge-dir */
872 const char *argv7[] = {prgname, "-m", DEFAULT_MEM_SIZE,
873 "--file-prefix=hugedir", "--huge-dir", hugepath};
874 /* With empty --huge-dir (should fail) */
875 const char *argv8[] = {prgname, "-m", DEFAULT_MEM_SIZE,
876 "--file-prefix=hugedir", "--huge-dir"};
877 /* With invalid --huge-dir */
878 const char *argv9[] = {prgname, "-m", DEFAULT_MEM_SIZE,
879 "--file-prefix=hugedir", "--huge-dir", "invalid"};
880 /* Secondary process with invalid --huge-dir (should run as flag has no
881 * effect on secondary processes) */
882 const char *argv10[] = {prgname, prefix, mp_flag,
883 "--huge-dir", "invalid"};
885 /* try running with base-virtaddr param */
886 const char *argv11[] = {prgname, "--file-prefix=virtaddr",
887 "--base-virtaddr=0x12345678"};
889 /* try running with --vfio-intr INTx flag */
890 const char *argv12[] = {prgname, "--file-prefix=intr",
891 "--vfio-intr=legacy"};
893 /* try running with --vfio-intr MSI flag */
894 const char *argv13[] = {prgname, "--file-prefix=intr",
897 /* try running with --vfio-intr MSI-X flag */
898 const char *argv14[] = {prgname, "--file-prefix=intr",
901 /* try running with --vfio-intr invalid flag */
902 const char *argv15[] = {prgname, "--file-prefix=intr",
903 "--vfio-intr=invalid"};
905 /* With process type as auto-detect */
906 const char * const argv16[] = {prgname, "--file-prefix=auto",
909 /* With process type as auto-detect with no-shconf */
910 const char * const argv17[] = {prgname, "--proc-type=auto",
911 no_shconf, nosh_prefix, no_huge};
913 /* With process type as --create-uio-dev flag */
914 const char * const argv18[] = {prgname, "--file-prefix=uiodev",
917 /* run all tests also applicable to FreeBSD first */
919 if (launch_proc(argv0) == 0) {
920 printf("Error - process ran ok with invalid flag\n");
923 if (launch_proc(argv1) != 0) {
924 printf("Error - process did not run ok with --no-pci flag\n");
927 if (launch_proc(argv2) != 0) {
928 printf("Error - process did not run ok with -v flag\n");
931 if (launch_proc(argv6) != 0) {
932 printf("Error - process did not run ok with --no-shconf flag\n");
936 #ifdef RTE_EXEC_ENV_FREEBSD
937 /* no more tests to be done on FreeBSD */
941 if (launch_proc(argv3) != 0) {
942 printf("Error - process did not run ok with --syslog flag\n");
945 if (launch_proc(argv4) == 0) {
946 printf("Error - process run ok with empty --syslog flag\n");
949 if (launch_proc(argv5) == 0) {
950 printf("Error - process run ok with invalid --syslog flag\n");
953 if (launch_proc(argv7) != 0) {
954 printf("Error - process did not run ok with --huge-dir flag\n");
957 if (launch_proc(argv8) == 0) {
958 printf("Error - process run ok with empty --huge-dir flag\n");
961 if (launch_proc(argv9) == 0) {
962 printf("Error - process run ok with invalid --huge-dir flag\n");
965 if (launch_proc(argv10) != 0) {
966 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
969 if (launch_proc(argv11) != 0) {
970 printf("Error - process did not run ok with --base-virtaddr parameter\n");
973 if (launch_proc(argv12) != 0) {
974 printf("Error - process did not run ok with "
975 "--vfio-intr INTx parameter\n");
978 if (launch_proc(argv13) != 0) {
979 printf("Error - process did not run ok with "
980 "--vfio-intr MSI parameter\n");
983 if (launch_proc(argv14) != 0) {
984 printf("Error - process did not run ok with "
985 "--vfio-intr MSI-X parameter\n");
988 if (launch_proc(argv15) == 0) {
989 printf("Error - process run ok with "
990 "--vfio-intr invalid parameter\n");
993 if (launch_proc(argv16) != 0) {
994 printf("Error - process did not run ok with "
995 "--proc-type as auto parameter\n");
998 if (launch_proc(argv17) != 0) {
999 printf("Error - process did not run ok with "
1000 "--proc-type and --no-shconf parameter\n");
1003 if (launch_proc(argv18) != 0) {
1004 printf("Error - process did not run ok with "
1005 "--create-uio-dev parameter\n");
1013 test_file_prefix(void)
1016 * 1. check if current process hugefiles are locked
1017 * 2. try to run secondary process without a corresponding primary process
1018 * (while failing to run, it will also remove any unused hugepage files)
1019 * 3. check if current process hugefiles are still in place and are locked
1020 * 4. run a primary process with memtest1 prefix in default and legacy
1022 * 5. check if memtest1 hugefiles are created in case of legacy mem
1023 * mode, and deleted in case of default mem mode
1024 * 6. run a primary process with memtest2 prefix in default and legacy
1026 * 7. check that memtest2 hugefiles are present in the hugedir after a
1027 * run in legacy mode, and not present at all after run in default
1030 char prefix[PATH_MAX] = "";
1032 #ifdef RTE_EXEC_ENV_FREEBSD
1035 if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
1036 printf("Error - unable to get current prefix!\n");
1041 /* this should fail unless the test itself is run with "memtest" prefix */
1042 const char *argv0[] = {prgname, mp_flag, "-m",
1043 DEFAULT_MEM_SIZE, "--file-prefix=" memtest };
1045 /* primary process with memtest1 and default mem mode */
1046 const char *argv1[] = {prgname, "-m",
1047 DEFAULT_MEM_SIZE, "--file-prefix=" memtest1 };
1049 /* primary process with memtest1 and legacy mem mode */
1050 const char *argv2[] = {prgname, "-m",
1051 DEFAULT_MEM_SIZE, "--file-prefix=" memtest1,
1054 /* primary process with memtest2 and legacy mem mode */
1055 const char *argv3[] = {prgname, "-m",
1056 DEFAULT_MEM_SIZE, "--file-prefix=" memtest2,
1059 /* primary process with memtest2 and default mem mode */
1060 const char *argv4[] = {prgname, "-m",
1061 DEFAULT_MEM_SIZE, "--file-prefix=" memtest2 };
1063 /* primary process with --in-memory mode */
1064 const char * const argv5[] = {prgname, "-m",
1065 DEFAULT_MEM_SIZE, "--in-memory" };
1067 /* primary process with memtest1 and --in-memory mode */
1068 const char * const argv6[] = {prgname, "-m",
1069 DEFAULT_MEM_SIZE, "--in-memory",
1070 "--file-prefix=" memtest1 };
1072 /* primary process with parent file-prefix and --in-memory mode */
1073 const char * const argv7[] = {prgname, "-m",
1074 DEFAULT_MEM_SIZE, "--in-memory", "--file-prefix", prefix };
1076 /* primary process with memtest1 and --single-file-segments mode */
1077 const char * const argv8[] = {prgname, "-m",
1078 DEFAULT_MEM_SIZE, "--single-file-segments",
1079 "--file-prefix=" memtest1 };
1081 /* check if files for current prefix are present */
1082 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1083 printf("Error - hugepage files for %s were not created!\n", prefix);
1087 /* checks if files for current prefix are locked */
1088 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1089 printf("Error - hugepages for current process aren't locked!\n");
1093 /* check if files for secondary process are present */
1094 if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
1095 /* check if they are not locked */
1096 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
1097 printf("Error - hugepages for current process are locked!\n");
1100 /* they aren't locked, delete them */
1102 if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
1103 printf("Error - deleting hugepages failed!\n");
1109 if (launch_proc(argv0) == 0) {
1110 printf("Error - secondary process ran ok without primary process\n");
1114 /* check if files for current prefix are present */
1115 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1116 printf("Error - hugepage files for %s were not created!\n", prefix);
1120 /* checks if files for current prefix are locked */
1121 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1122 printf("Error - hugepages for current process aren't locked!\n");
1126 /* we're running this process in default memory mode, which means it
1127 * should clean up after itself on exit and leave no hugepages behind.
1129 if (launch_proc(argv1) != 0) {
1130 printf("Error - failed to run with --file-prefix=%s\n",
1135 /* check if memtest1_map0 is present */
1136 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1137 printf("Error - hugepage files for %s were not deleted!\n",
1142 /* now, we're running a process under the same prefix, but with legacy
1143 * mem mode - this should leave behind hugepage files.
1145 if (launch_proc(argv2) != 0) {
1146 printf("Error - failed to run with --file-prefix=%s\n",
1151 /* check if memtest1_map0 is present */
1152 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
1153 printf("Error - hugepage files for %s were not created!\n",
1158 if (launch_proc(argv3) != 0) {
1159 printf("Error - failed to run with --file-prefix=%s\n",
1164 /* check if hugefiles for memtest2 are present */
1165 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
1166 printf("Error - hugepage files for %s were not created!\n",
1171 /* check if hugefiles for memtest1 are present */
1172 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1173 printf("Error - hugepage files for %s were not deleted!\n",
1178 /* this process will run in default mem mode, so it should not leave any
1179 * hugepage files behind.
1181 if (launch_proc(argv4) != 0) {
1182 printf("Error - failed to run with --file-prefix=%s\n",
1187 /* check if hugefiles for memtest2 are present */
1188 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 0) {
1189 printf("Error - hugepage files for %s were not deleted!\n",
1194 /* check if hugefiles for memtest1 are present */
1195 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1196 printf("Error - hugepage files for %s were not deleted!\n",
1201 /* this process will run in --in-memory mode, so it should not leave any
1202 * hugepage files behind.
1205 /* test case to check eal-options with --in-memory mode */
1206 if (launch_proc(argv5) != 0) {
1207 printf("Error - failed to run with --in-memory mode\n");
1211 /*test case to check eal-options with --in-memory mode with
1212 * custom file-prefix.
1214 if (launch_proc(argv6) != 0) {
1215 printf("Error - failed to run with --in-memory mode\n");
1219 /* check if hugefiles for memtest1 are present */
1220 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1221 printf("Error - hugepage files for %s were created and not deleted!\n",
1226 /* test case to check eal-options with --in-memory mode with
1227 * parent file-prefix.
1229 if (launch_proc(argv7) != 0) {
1230 printf("Error - failed to run with --file-prefix=%s\n", prefix);
1234 /* this process will run in --single-file-segments mode,
1235 * so it should not leave any hugepage files behind.
1237 if (launch_proc(argv8) != 0) {
1238 printf("Error - failed to run with --single-file-segments mode\n");
1242 /* check if hugefiles for memtest1 are present */
1243 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1244 printf("Error - hugepage files for %s were not deleted!\n",
1252 /* This function writes in passed buf pointer a valid --socket-mem= option
1253 * for num_sockets then concatenates the provided suffix string.
1255 * Example for num_sockets 4, mem "2", suffix "plop"
1256 * --socket-mem=2,2,2,2plop
1259 populate_socket_mem_param(int num_sockets, const char *mem,
1260 const char *suffix, char *buf, size_t buf_size)
1262 unsigned int offset = 0;
1266 written = snprintf(&buf[offset], buf_size - offset, "--socket-mem=");
1267 if (written < 0 || written + offset >= buf_size)
1271 for (i = 0; i < num_sockets - 1; i++) {
1272 written = snprintf(&buf[offset], buf_size - offset,
1274 if (written < 0 || written + offset >= buf_size)
1279 written = snprintf(&buf[offset], buf_size - offset, "%s%s", mem,
1281 if (written < 0 || written + offset >= buf_size)
1287 * Tests for correct handling of -m and --socket-mem flags
1290 test_memory_flags(void)
1292 #ifdef RTE_EXEC_ENV_FREEBSD
1293 /* BSD target doesn't support prefixes at this point */
1294 const char * prefix = "";
1296 char prefix[PATH_MAX], tmp[PATH_MAX];
1297 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
1298 printf("Error - unable to get current prefix!\n");
1301 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
1304 /* valid -m flag and mp flag */
1305 const char *argv0[] = {prgname, prefix, mp_flag,
1306 "-m", DEFAULT_MEM_SIZE};
1309 const char *argv1[] = {prgname,
1310 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE};
1312 /* valid (zero) --socket-mem flag */
1313 char arg2_socket_mem[SOCKET_MEM_STRLEN];
1314 const char *argv2[] = {prgname,
1315 "--file-prefix=" memtest, arg2_socket_mem};
1317 /* invalid (incomplete) --socket-mem flag */
1318 char arg3_socket_mem[SOCKET_MEM_STRLEN];
1319 const char *argv3[] = {prgname,
1320 "--file-prefix=" memtest, arg3_socket_mem};
1322 /* invalid (mixed with invalid data) --socket-mem flag */
1323 char arg4_socket_mem[SOCKET_MEM_STRLEN];
1324 const char *argv4[] = {prgname,
1325 "--file-prefix=" memtest, arg4_socket_mem};
1327 /* invalid (with numeric value as last character) --socket-mem flag */
1328 char arg5_socket_mem[SOCKET_MEM_STRLEN];
1329 const char *argv5[] = {prgname,
1330 "--file-prefix=" memtest, arg5_socket_mem};
1332 /* invalid (with empty socket) --socket-mem flag */
1333 char arg6_socket_mem[SOCKET_MEM_STRLEN];
1334 const char *argv6[] = {prgname,
1335 "--file-prefix=" memtest, arg6_socket_mem};
1337 /* invalid (null) --socket-mem flag */
1338 const char *argv7[] = {prgname,
1339 "--file-prefix=" memtest, "--socket-mem="};
1341 /* valid --socket-mem specified together with -m flag */
1342 char arg8_socket_mem[SOCKET_MEM_STRLEN];
1343 const char *argv8[] = {prgname,
1344 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE,
1347 #ifdef RTE_EXEC_ENV_FREEBSD
1348 int num_sockets = 1;
1350 int num_sockets = RTE_MIN(get_number_of_sockets(),
1351 RTE_MAX_NUMA_NODES);
1354 if (num_sockets <= 0) {
1355 printf("Error - cannot get number of sockets!\n");
1359 /* invalid --socket-mem flag (with extra socket) */
1360 char invalid_socket_mem[SOCKET_MEM_STRLEN];
1361 const char *argv9[] = {prgname,
1362 "--file-prefix=" memtest, invalid_socket_mem};
1364 /* valid --socket-mem flag */
1365 char valid_socket_mem[SOCKET_MEM_STRLEN];
1366 const char *argv10[] = {prgname,
1367 "--file-prefix=" memtest, valid_socket_mem};
1369 if (launch_proc(argv0) != 0) {
1370 printf("Error - secondary process failed with valid -m flag !\n");
1374 #ifdef RTE_EXEC_ENV_FREEBSD
1375 /* no other tests are applicable to BSD */
1379 if (launch_proc(argv1) != 0) {
1380 printf("Error - process failed with valid -m flag!\n");
1384 populate_socket_mem_param(num_sockets, "0", "",
1385 arg2_socket_mem, sizeof(arg2_socket_mem));
1386 if (launch_proc(argv2) != 0) {
1387 printf("Error - process failed with valid (zero) --socket-mem!\n");
1391 if (num_sockets > 1) {
1392 populate_socket_mem_param(num_sockets - 1, "2", ",",
1393 arg3_socket_mem, sizeof(arg3_socket_mem));
1394 if (launch_proc(argv3) == 0) {
1395 printf("Error - process run ok with invalid "
1396 "(incomplete) --socket-mem!\n");
1400 populate_socket_mem_param(num_sockets - 1, "2", ",Fred",
1401 arg4_socket_mem, sizeof(arg4_socket_mem));
1402 if (launch_proc(argv4) == 0) {
1403 printf("Error - process run ok with invalid "
1404 "(mixed with invalid input) --socket-mem!\n");
1408 populate_socket_mem_param(num_sockets - 1, "2", ",Fred0",
1409 arg5_socket_mem, sizeof(arg5_socket_mem));
1410 if (launch_proc(argv5) == 0) {
1411 printf("Error - process run ok with invalid "
1412 "(mixed with invalid input with a numeric value as "
1413 "last character) --socket-mem!\n");
1418 if (num_sockets > 2) {
1419 populate_socket_mem_param(num_sockets - 2, "2", ",,2",
1420 arg6_socket_mem, sizeof(arg6_socket_mem));
1421 if (launch_proc(argv6) == 0) {
1422 printf("Error - process run ok with invalid "
1423 "(with empty socket) --socket-mem!\n");
1428 if (launch_proc(argv7) == 0) {
1429 printf("Error - process run ok with invalid (null) --socket-mem!\n");
1433 populate_socket_mem_param(num_sockets, "2", "",
1434 arg8_socket_mem, sizeof(arg8_socket_mem));
1435 if (launch_proc(argv8) == 0) {
1436 printf("Error - process run ok with --socket-mem and -m specified!\n");
1440 populate_socket_mem_param(num_sockets + 1, "2", "",
1441 invalid_socket_mem, sizeof(invalid_socket_mem));
1442 if (launch_proc(argv9) == 0) {
1443 printf("Error - process run ok with extra socket in --socket-mem!\n");
1447 populate_socket_mem_param(num_sockets, "2", "",
1448 valid_socket_mem, sizeof(valid_socket_mem));
1449 if (launch_proc(argv10) != 0) {
1450 printf("Error - process failed with valid --socket-mem!\n");
1458 test_eal_flags(void)
1462 ret = test_missing_c_flag();
1464 printf("Error in test_missing_c_flag()\n");
1468 ret = test_master_lcore_flag();
1470 printf("Error in test_master_lcore_flag()\n");
1474 ret = test_invalid_n_flag();
1476 printf("Error in test_invalid_n_flag()\n");
1480 ret = test_no_hpet_flag();
1482 printf("Error in test_no_hpet_flag()\n");
1486 ret = test_no_huge_flag();
1488 printf("Error in test_no_huge_flag()\n");
1492 ret = test_whitelist_flag();
1494 printf("Error in test_invalid_whitelist_flag()\n");
1498 ret = test_invalid_b_flag();
1500 printf("Error in test_invalid_b_flag()\n");
1504 #ifdef RTE_LIBRTE_PMD_RING
1505 ret = test_invalid_vdev_flag();
1507 printf("Error in test_invalid_vdev_flag()\n");
1511 ret = test_invalid_r_flag();
1513 printf("Error in test_invalid_r_flag()\n");
1517 ret = test_memory_flags();
1519 printf("Error in test_memory_flags()\n");
1523 ret = test_file_prefix();
1525 printf("Error in test_file_prefix()\n");
1529 ret = test_misc_flags();
1531 printf("Error in test_misc_flags()");
1538 REGISTER_TEST_COMMAND(eal_flags_autotest, test_eal_flags);
1540 /* subtests used in meson for CI */
1541 REGISTER_TEST_COMMAND(eal_flags_c_opt_autotest, test_missing_c_flag);
1542 REGISTER_TEST_COMMAND(eal_flags_master_opt_autotest, test_master_lcore_flag);
1543 REGISTER_TEST_COMMAND(eal_flags_n_opt_autotest, test_invalid_n_flag);
1544 REGISTER_TEST_COMMAND(eal_flags_hpet_autotest, test_no_hpet_flag);
1545 REGISTER_TEST_COMMAND(eal_flags_no_huge_autotest, test_no_huge_flag);
1546 REGISTER_TEST_COMMAND(eal_flags_w_opt_autotest, test_whitelist_flag);
1547 REGISTER_TEST_COMMAND(eal_flags_b_opt_autotest, test_invalid_b_flag);
1548 REGISTER_TEST_COMMAND(eal_flags_vdev_opt_autotest, test_invalid_vdev_flag);
1549 REGISTER_TEST_COMMAND(eal_flags_r_opt_autotest, test_invalid_r_flag);
1550 REGISTER_TEST_COMMAND(eal_flags_mem_autotest, test_memory_flags);
1551 REGISTER_TEST_COMMAND(eal_flags_file_prefix_autotest, test_file_prefix);
1552 REGISTER_TEST_COMMAND(eal_flags_misc_autotest, test_misc_flags);