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, "-n", "1",
380 "-c", "1", vdev, "eth_dummy"};
382 /* Test with valid vdev option */
383 const char *vdevval1[] = {prgname, prefix, "-n", "1",
384 "-c", "1", vdev, "net_ring0"};
386 const char *vdevval2[] = {prgname, prefix, "-n", "1",
387 "-c", "1", vdev, "net_ring0,args=test"};
389 const char *vdevval3[] = {prgname, prefix, "-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 */
853 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
854 no_shconf, nosh_prefix };
856 #ifdef RTE_EXEC_ENV_BSDAPP
859 /* With --huge-dir */
860 const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
861 "--file-prefix=hugedir", "--huge-dir", hugepath};
862 /* With empty --huge-dir (should fail) */
863 const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
864 "--file-prefix=hugedir", "--huge-dir"};
865 /* With invalid --huge-dir */
866 const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
867 "--file-prefix=hugedir", "--huge-dir", "invalid"};
868 /* Secondary process with invalid --huge-dir (should run as flag has no
869 * effect on secondary processes) */
870 const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
872 /* try running with base-virtaddr param */
873 const char *argv11[] = {prgname, "--file-prefix=virtaddr",
874 "-c", "1", "-n", "2", "--base-virtaddr=0x12345678"};
876 /* try running with --vfio-intr INTx flag */
877 const char *argv12[] = {prgname, "--file-prefix=intr",
878 "-c", "1", "-n", "2", "--vfio-intr=legacy"};
880 /* try running with --vfio-intr MSI flag */
881 const char *argv13[] = {prgname, "--file-prefix=intr",
882 "-c", "1", "-n", "2", "--vfio-intr=msi"};
884 /* try running with --vfio-intr MSI-X flag */
885 const char *argv14[] = {prgname, "--file-prefix=intr",
886 "-c", "1", "-n", "2", "--vfio-intr=msix"};
888 /* try running with --vfio-intr invalid flag */
889 const char *argv15[] = {prgname, "--file-prefix=intr",
890 "-c", "1", "-n", "2", "--vfio-intr=invalid"};
893 if (launch_proc(argv0) == 0) {
894 printf("Error - process ran ok with invalid flag\n");
897 if (launch_proc(argv1) != 0) {
898 printf("Error - process did not run ok with --no-pci flag\n");
901 if (launch_proc(argv2) != 0) {
902 printf("Error - process did not run ok with -v flag\n");
905 if (launch_proc(argv3) != 0) {
906 printf("Error - process did not run ok with --syslog flag\n");
909 if (launch_proc(argv4) == 0) {
910 printf("Error - process run ok with empty --syslog flag\n");
913 if (launch_proc(argv5) == 0) {
914 printf("Error - process run ok with invalid --syslog flag\n");
917 if (launch_proc(argv6) != 0) {
918 printf("Error - process did not run ok with --no-shconf flag\n");
921 #ifdef RTE_EXEC_ENV_BSDAPP
924 if (launch_proc(argv7) != 0) {
925 printf("Error - process did not run ok with --huge-dir flag\n");
928 if (launch_proc(argv8) == 0) {
929 printf("Error - process run ok with empty --huge-dir flag\n");
932 if (launch_proc(argv9) == 0) {
933 printf("Error - process run ok with invalid --huge-dir flag\n");
936 if (launch_proc(argv10) != 0) {
937 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
940 if (launch_proc(argv11) != 0) {
941 printf("Error - process did not run ok with --base-virtaddr parameter\n");
944 if (launch_proc(argv12) != 0) {
945 printf("Error - process did not run ok with "
946 "--vfio-intr INTx parameter\n");
949 if (launch_proc(argv13) != 0) {
950 printf("Error - process did not run ok with "
951 "--vfio-intr MSI parameter\n");
954 if (launch_proc(argv14) != 0) {
955 printf("Error - process did not run ok with "
956 "--vfio-intr MSI-X parameter\n");
959 if (launch_proc(argv15) == 0) {
960 printf("Error - process run ok with "
961 "--vfio-intr invalid parameter\n");
968 test_file_prefix(void)
971 * 1. check if current process hugefiles are locked
972 * 2. try to run secondary process without a corresponding primary process
973 * (while failing to run, it will also remove any unused hugepage files)
974 * 3. check if current process hugefiles are still in place and are locked
975 * 4. run a primary process with memtest1 prefix
976 * 5. check if memtest1 hugefiles are created
977 * 6. run a primary process with memtest2 prefix
978 * 7. check that only memtest2 hugefiles are present in the hugedir
981 #ifdef RTE_EXEC_ENV_BSDAPP
985 /* this should fail unless the test itself is run with "memtest" prefix */
986 const char *argv0[] = {prgname, mp_flag, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
987 "--file-prefix=" memtest };
989 /* primary process with memtest1 */
990 const char *argv1[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
991 "--file-prefix=" memtest1 };
993 /* primary process with memtest2 */
994 const char *argv2[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
995 "--file-prefix=" memtest2 };
998 if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
999 printf("Error - unable to get current prefix!\n");
1003 /* check if files for current prefix are present */
1004 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1005 printf("Error - hugepage files for %s were not created!\n", prefix);
1009 /* checks if files for current prefix are locked */
1010 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1011 printf("Error - hugepages for current process aren't locked!\n");
1015 /* check if files for secondary process are present */
1016 if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
1017 /* check if they are not locked */
1018 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
1019 printf("Error - hugepages for current process are locked!\n");
1022 /* they aren't locked, delete them */
1024 if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
1025 printf("Error - deleting hugepages failed!\n");
1031 if (launch_proc(argv0) == 0) {
1032 printf("Error - secondary process ran ok without primary process\n");
1036 /* check if files for current prefix are present */
1037 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1038 printf("Error - hugepage files for %s were not created!\n", prefix);
1042 /* checks if files for current prefix are locked */
1043 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1044 printf("Error - hugepages for current process aren't locked!\n");
1048 if (launch_proc(argv1) != 0) {
1049 printf("Error - failed to run with --file-prefix=%s\n", memtest);
1053 /* check if memtest1_map0 is present */
1054 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
1055 printf("Error - hugepage files for %s were not created!\n", memtest1);
1059 if (launch_proc(argv2) != 0) {
1060 printf("Error - failed to run with --file-prefix=%s\n", memtest2);
1064 /* check if hugefiles for memtest2 are present */
1065 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
1066 printf("Error - hugepage files for %s were not created!\n", memtest2);
1070 /* check if hugefiles for memtest1 are present */
1071 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1072 printf("Error - hugepage files for %s were not deleted!\n", memtest1);
1080 * Tests for correct handling of -m and --socket-mem flags
1083 test_memory_flags(void)
1085 #ifdef RTE_EXEC_ENV_BSDAPP
1086 /* BSD target doesn't support prefixes at this point */
1087 const char * prefix = "";
1089 char prefix[PATH_MAX], tmp[PATH_MAX];
1090 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
1091 printf("Error - unable to get current prefix!\n");
1094 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
1097 /* valid -m flag and mp flag */
1098 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "10",
1099 "-n", "2", "-m", DEFAULT_MEM_SIZE};
1102 const char *argv1[] = {prgname, "-c", "10", "-n", "2",
1103 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE};
1105 /* invalid (zero) --socket-mem flag */
1106 const char *argv2[] = {prgname, "-c", "10", "-n", "2",
1107 "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
1109 /* invalid (incomplete) --socket-mem flag */
1110 const char *argv3[] = {prgname, "-c", "10", "-n", "2",
1111 "--file-prefix=" memtest, "--socket-mem=2,2,"};
1113 /* invalid (mixed with invalid data) --socket-mem flag */
1114 const char *argv4[] = {prgname, "-c", "10", "-n", "2",
1115 "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
1117 /* invalid (with numeric value as last character) --socket-mem flag */
1118 const char *argv5[] = {prgname, "-c", "10", "-n", "2",
1119 "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
1121 /* invalid (with empty socket) --socket-mem flag */
1122 const char *argv6[] = {prgname, "-c", "10", "-n", "2",
1123 "--file-prefix=" memtest, "--socket-mem=2,,2"};
1125 /* invalid (null) --socket-mem flag */
1126 const char *argv7[] = {prgname, "-c", "10", "-n", "2",
1127 "--file-prefix=" memtest, "--socket-mem="};
1129 /* valid --socket-mem specified together with -m flag */
1130 const char *argv8[] = {prgname, "-c", "10", "-n", "2",
1131 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE, "--socket-mem=2,2"};
1133 /* construct an invalid socket mask with 2 megs on each socket plus
1134 * extra 2 megs on socket that doesn't exist on current system */
1135 char invalid_socket_mem[SOCKET_MEM_STRLEN];
1136 char buf[SOCKET_MEM_STRLEN]; /* to avoid copying string onto itself */
1138 #ifdef RTE_EXEC_ENV_BSDAPP
1139 int i, num_sockets = 1;
1141 int i, num_sockets = RTE_MIN(get_number_of_sockets(),
1142 RTE_MAX_NUMA_NODES);
1145 if (num_sockets <= 0) {
1146 printf("Error - cannot get number of sockets!\n");
1150 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
1152 /* add one extra socket */
1153 for (i = 0; i < num_sockets + 1; i++) {
1154 snprintf(buf, sizeof(buf), "%s%s", invalid_socket_mem, DEFAULT_MEM_SIZE);
1155 strlcpy(invalid_socket_mem, buf, sizeof(invalid_socket_mem));
1157 if (num_sockets + 1 - i > 1) {
1158 snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
1159 strlcpy(invalid_socket_mem, buf,
1160 sizeof(invalid_socket_mem));
1164 /* construct a valid socket mask with 2 megs on each existing socket */
1165 char valid_socket_mem[SOCKET_MEM_STRLEN];
1167 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
1169 /* add one extra socket */
1170 for (i = 0; i < num_sockets; i++) {
1171 snprintf(buf, sizeof(buf), "%s%s", valid_socket_mem, DEFAULT_MEM_SIZE);
1172 strlcpy(valid_socket_mem, buf, sizeof(valid_socket_mem));
1174 if (num_sockets - i > 1) {
1175 snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
1176 strlcpy(valid_socket_mem, buf,
1177 sizeof(valid_socket_mem));
1181 /* invalid --socket-mem flag (with extra socket) */
1182 const char *argv9[] = {prgname, "-c", "10", "-n", "2",
1183 "--file-prefix=" memtest, invalid_socket_mem};
1185 /* valid --socket-mem flag */
1186 const char *argv10[] = {prgname, "-c", "10", "-n", "2",
1187 "--file-prefix=" memtest, valid_socket_mem};
1189 if (launch_proc(argv0) != 0) {
1190 printf("Error - secondary process failed with valid -m flag !\n");
1194 #ifdef RTE_EXEC_ENV_BSDAPP
1195 /* no other tests are applicable to BSD */
1199 if (launch_proc(argv1) != 0) {
1200 printf("Error - process failed with valid -m flag!\n");
1203 if (launch_proc(argv2) == 0) {
1204 printf("Error - process run ok with invalid (zero) --socket-mem!\n");
1208 if (launch_proc(argv3) == 0) {
1209 printf("Error - process run ok with invalid "
1210 "(incomplete) --socket-mem!\n");
1214 if (launch_proc(argv4) == 0) {
1215 printf("Error - process run ok with invalid "
1216 "(mixed with invalid input) --socket-mem!\n");
1220 if (launch_proc(argv5) == 0) {
1221 printf("Error - process run ok with invalid "
1222 "(mixed with invalid input with a numeric value as "
1223 "last character) --socket-mem!\n");
1227 if (launch_proc(argv6) == 0) {
1228 printf("Error - process run ok with invalid "
1229 "(with empty socket) --socket-mem!\n");
1233 if (launch_proc(argv7) == 0) {
1234 printf("Error - process run ok with invalid (null) --socket-mem!\n");
1238 if (launch_proc(argv8) == 0) {
1239 printf("Error - process run ok with --socket-mem and -m specified!\n");
1243 if (launch_proc(argv9) == 0) {
1244 printf("Error - process run ok with extra socket in --socket-mem!\n");
1248 if (launch_proc(argv10) != 0) {
1249 printf("Error - process failed with valid --socket-mem!\n");
1257 test_eal_flags(void)
1261 ret = test_missing_c_flag();
1263 printf("Error in test_missing_c_flag()\n");
1267 ret = test_master_lcore_flag();
1269 printf("Error in test_master_lcore_flag()\n");
1273 ret = test_invalid_n_flag();
1275 printf("Error in test_invalid_n_flag()\n");
1279 ret = test_no_hpet_flag();
1281 printf("Error in test_no_hpet_flag()\n");
1285 ret = test_no_huge_flag();
1287 printf("Error in test_no_huge_flag()\n");
1291 ret = test_whitelist_flag();
1293 printf("Error in test_invalid_whitelist_flag()\n");
1297 ret = test_invalid_b_flag();
1299 printf("Error in test_invalid_b_flag()\n");
1303 #ifdef RTE_LIBRTE_PMD_RING
1304 ret = test_invalid_vdev_flag();
1306 printf("Error in test_invalid_vdev_flag()\n");
1310 ret = test_invalid_r_flag();
1312 printf("Error in test_invalid_r_flag()\n");
1316 ret = test_memory_flags();
1318 printf("Error in test_memory_flags()\n");
1322 ret = test_file_prefix();
1324 printf("Error in test_file_prefix()\n");
1328 ret = test_misc_flags();
1330 printf("Error in test_misc_flags()");
1337 REGISTER_TEST_COMMAND(eal_flags_autotest, test_eal_flags);