1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright(c) 2014 6WIND S.A.
21 #include <rte_per_lcore.h>
22 #include <rte_debug.h>
23 #include <rte_string_fns.h>
27 #define DEFAULT_MEM_SIZE "18"
28 #define mp_flag "--proc-type=secondary"
29 #define no_hpet "--no-hpet"
30 #define no_huge "--no-huge"
31 #define no_shconf "--no-shconf"
32 #define pci_whitelist "--pci-whitelist"
34 #define memtest "memtest"
35 #define memtest1 "memtest1"
36 #define memtest2 "memtest2"
37 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 20)
38 #define launch_proc(ARGV) process_dup(ARGV, \
39 sizeof(ARGV)/(sizeof(ARGV[0])), __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 snprintf(dst, dst_len, "%s", tokens[1]);
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_LINUXAPP
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_BSDAPP
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[][11] = {
247 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
248 pci_whitelist, "error", "", ""},
249 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
250 pci_whitelist, "0:0:0", "", ""},
251 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
252 pci_whitelist, "0:error:0.1", "", ""},
253 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
254 pci_whitelist, "0:0:0.1error", "", ""},
255 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
256 pci_whitelist, "error0:0:0.1", "", ""},
257 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
258 pci_whitelist, "0:0:0.1.2", "", ""},
260 /* Test with valid whitelist option */
261 const char *wlval1[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
262 pci_whitelist, "00FF:09:0B.3"};
263 const char *wlval2[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
264 pci_whitelist, "09:0B.3", pci_whitelist, "0a:0b.1"};
265 const char *wlval3[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
266 pci_whitelist, "09:0B.3,type=test",
267 pci_whitelist, "08:00.1,type=normal",
270 for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); 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_BSDAPP
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[][9] = {
313 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error"},
314 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0"},
315 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:error:0.1"},
316 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1error"},
317 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error0:0:0.1"},
318 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1.2"},
320 /* Test with valid blacklist option */
321 const char *blval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
325 for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
326 if (launch_proc(blinval[i]) == 0) {
327 printf("Error - process did run ok with invalid "
328 "blacklist parameter\n");
332 if (launch_proc(blval) != 0) {
333 printf("Error - process did not run ok with valid blacklist value\n");
340 * Test that the app doesn't run with invalid vdev option.
341 * Final test ensures it does run with valid options as sanity check
343 #ifdef RTE_LIBRTE_PMD_RING
345 test_invalid_vdev_flag(void)
347 #ifdef RTE_EXEC_ENV_BSDAPP
348 /* BSD target doesn't support prefixes at this point, and we also need to
349 * run another primary process here */
350 const char * prefix = no_shconf;
352 const char * prefix = "--file-prefix=vdev";
355 /* Test with invalid vdev option */
356 const char *vdevinval[] = {prgname, prefix, no_huge, "-n", "1",
357 "-c", "1", vdev, "eth_dummy"};
359 /* Test with valid vdev option */
360 const char *vdevval1[] = {prgname, prefix, no_huge, "-n", "1",
361 "-c", "1", vdev, "net_ring0"};
363 const char *vdevval2[] = {prgname, prefix, no_huge, "-n", "1",
364 "-c", "1", vdev, "net_ring0,args=test"};
366 const char *vdevval3[] = {prgname, prefix, no_huge, "-n", "1",
367 "-c", "1", vdev, "net_ring0,nodeaction=r1:0:CREATE"};
369 if (launch_proc(vdevinval) == 0) {
370 printf("Error - process did run ok with invalid "
375 if (launch_proc(vdevval1) != 0) {
376 printf("Error - process did not run ok with valid vdev value\n");
380 if (launch_proc(vdevval2) != 0) {
381 printf("Error - process did not run ok with valid vdev value,"
382 "with dummy args\n");
386 if (launch_proc(vdevval3) != 0) {
387 printf("Error - process did not run ok with valid vdev value,"
388 "with valid args\n");
396 * Test that the app doesn't run with invalid -r option.
399 test_invalid_r_flag(void)
401 #ifdef RTE_EXEC_ENV_BSDAPP
402 /* BSD target doesn't support prefixes at this point */
403 const char * prefix = "";
405 char prefix[PATH_MAX], tmp[PATH_MAX];
406 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
407 printf("Error - unable to get current prefix!\n");
410 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
413 const char *rinval[][9] = {
414 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "error"},
415 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "0"},
416 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "-1"},
417 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "17"},
419 /* Test with valid blacklist option */
420 const char *rval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
424 for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
425 if (launch_proc(rinval[i]) == 0) {
426 printf("Error - process did run ok with invalid "
427 "-r (rank) parameter\n");
431 if (launch_proc(rval) != 0) {
432 printf("Error - process did not run ok with valid -r (rank) value\n");
439 * Test that the app doesn't run without the coremask/corelist flags. In all cases
440 * should give an error and fail to run
443 test_missing_c_flag(void)
445 #ifdef RTE_EXEC_ENV_BSDAPP
446 /* BSD target doesn't support prefixes at this point */
447 const char * prefix = "";
449 char prefix[PATH_MAX], tmp[PATH_MAX];
450 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
451 printf("Error - unable to get current prefix!\n");
454 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
457 /* -c flag but no coremask value */
458 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "3", "-c"};
459 /* No -c, -l or --lcores flag at all */
460 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "3"};
461 /* bad coremask value */
462 const char *argv3[] = { prgname, prefix, mp_flag,
463 "-n", "3", "-c", "error" };
464 /* sanity check of tests - valid coremask value */
465 const char *argv4[] = { prgname, prefix, mp_flag,
466 "-n", "3", "-c", "1" };
467 /* -l flag but no corelist value */
468 const char *argv5[] = { prgname, prefix, mp_flag,
470 const char *argv6[] = { prgname, prefix, mp_flag,
471 "-n", "3", "-l", " " };
472 /* bad corelist values */
473 const char *argv7[] = { prgname, prefix, mp_flag,
474 "-n", "3", "-l", "error" };
475 const char *argv8[] = { prgname, prefix, mp_flag,
476 "-n", "3", "-l", "1-" };
477 const char *argv9[] = { prgname, prefix, mp_flag,
478 "-n", "3", "-l", "1," };
479 const char *argv10[] = { prgname, prefix, mp_flag,
480 "-n", "3", "-l", "1#2" };
481 /* core number is negative value */
482 const char * const argv11[] = { prgname, prefix, mp_flag,
483 "-n", "3", "-l", "-5" };
484 const char * const argv12[] = { prgname, prefix, mp_flag,
485 "-n", "3", "-l", "-5-7" };
486 /* core number is maximum value */
487 const char * const argv13[] = { prgname, prefix, mp_flag,
488 "-n", "3", "-l", RTE_STR(RTE_MAX_LCORE) };
489 const char * const argv14[] = { prgname, prefix, mp_flag,
490 "-n", "3", "-l", "1-"RTE_STR(RTE_MAX_LCORE) };
491 /* sanity check test - valid corelist value */
492 const char * const argv15[] = { prgname, prefix, mp_flag,
493 "-n", "3", "-l", "1-2,3" };
495 /* --lcores flag but no lcores value */
496 const char * const argv16[] = { prgname, prefix, mp_flag,
497 "-n", "3", "--lcores" };
498 const char * const argv17[] = { prgname, prefix, mp_flag,
499 "-n", "3", "--lcores", " " };
500 /* bad lcores value */
501 const char * const argv18[] = { prgname, prefix, mp_flag,
502 "-n", "3", "--lcores", "1-3-5" };
503 const char * const argv19[] = { prgname, prefix, mp_flag,
504 "-n", "3", "--lcores", "0-1,,2" };
505 const char * const argv20[] = { prgname, prefix, mp_flag,
506 "-n", "3", "--lcores", "0-,1" };
507 const char * const argv21[] = { prgname, prefix, mp_flag,
508 "-n", "3", "--lcores", "(0-,2-4)" };
509 const char * const argv22[] = { prgname, prefix, mp_flag,
510 "-n", "3", "--lcores", "(-1,2)" };
511 const char * const argv23[] = { prgname, prefix, mp_flag,
512 "-n", "3", "--lcores", "(2-4)@(2-4-6)" };
513 const char * const argv24[] = { prgname, prefix, mp_flag,
514 "-n", "3", "--lcores", "(a,2)" };
515 const char * const argv25[] = { prgname, prefix, mp_flag,
516 "-n", "3", "--lcores", "1-3@(1,3)" };
517 const char * const argv26[] = { prgname, prefix, mp_flag,
518 "-n", "3", "--lcores", "3@((1,3)" };
519 const char * const argv27[] = { prgname, prefix, mp_flag,
520 "-n", "3", "--lcores", "(4-7)=(1,3)" };
521 const char * const argv28[] = { prgname, prefix, mp_flag,
522 "-n", "3", "--lcores", "[4-7]@(1,3)" };
523 /* sanity check of tests - valid lcores value */
524 const char * const argv29[] = { prgname, prefix, mp_flag,
525 "-n", "3", "--lcores",
526 "0-1,2@(5-7),(3-5)@(0,2),(0,6),7"};
528 if (launch_proc(argv2) != 0) {
530 "process did not run ok when missing -c flag\n");
534 if (launch_proc(argv1) == 0
535 || launch_proc(argv3) == 0) {
537 "process ran without error with invalid -c flag\n");
540 if (launch_proc(argv4) != 0) {
542 "process did not run ok with valid coremask value\n");
547 if (launch_proc(argv5) == 0
548 || launch_proc(argv6) == 0
549 || launch_proc(argv7) == 0
550 || launch_proc(argv8) == 0
551 || launch_proc(argv9) == 0
552 || launch_proc(argv10) == 0
553 || launch_proc(argv11) == 0
554 || launch_proc(argv12) == 0
555 || launch_proc(argv13) == 0
556 || launch_proc(argv14) == 0) {
558 "process ran without error with invalid -l flag\n");
561 if (launch_proc(argv15) != 0) {
563 "process did not run ok with valid corelist value\n");
567 /* start --lcores tests */
568 if (launch_proc(argv16) == 0 || launch_proc(argv17) == 0 ||
569 launch_proc(argv18) == 0 || launch_proc(argv19) == 0 ||
570 launch_proc(argv20) == 0 || launch_proc(argv21) == 0 ||
571 launch_proc(argv22) == 0 || launch_proc(argv23) == 0 ||
572 launch_proc(argv24) == 0 || launch_proc(argv25) == 0 ||
573 launch_proc(argv26) == 0 || launch_proc(argv27) == 0 ||
574 launch_proc(argv28) == 0) {
576 "process ran without error with invalid --lcore flag\n");
580 if (launch_proc(argv29) != 0) {
582 "process did not run ok with valid corelist value\n");
590 * Test --master-lcore option with matching coremask
593 test_master_lcore_flag(void)
595 #ifdef RTE_EXEC_ENV_BSDAPP
596 /* BSD target doesn't support prefixes at this point */
597 const char *prefix = "";
599 char prefix[PATH_MAX], tmp[PATH_MAX];
600 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
601 printf("Error - unable to get current prefix!\n");
604 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
607 /* --master-lcore flag but no value */
608 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore"};
609 /* --master-lcore flag with invalid value */
610 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "-1"};
611 const char *argv3[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "X"};
612 /* master lcore not in coremask */
613 const char *argv4[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "2"};
615 const char *argv5[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "1"};
616 /* valid value set before coremask */
617 const char *argv6[] = { prgname, prefix, mp_flag, "-n", "1", "--master-lcore", "1", "-c", "3"};
619 if (launch_proc(argv1) == 0
620 || launch_proc(argv2) == 0
621 || launch_proc(argv3) == 0
622 || launch_proc(argv4) == 0) {
623 printf("Error - process ran without error with wrong --master-lcore\n");
626 if (launch_proc(argv5) != 0
627 || launch_proc(argv6) != 0) {
628 printf("Error - process did not run ok with valid --master-lcore\n");
635 * Test that the app doesn't run with invalid -n flag option.
636 * Final test ensures it does run with valid options as sanity check
637 * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
641 test_invalid_n_flag(void)
643 #ifdef RTE_EXEC_ENV_BSDAPP
644 /* BSD target doesn't support prefixes at this point */
645 const char * prefix = "";
647 char prefix[PATH_MAX], tmp[PATH_MAX];
648 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
649 printf("Error - unable to get current prefix!\n");
652 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
655 /* -n flag but no value */
656 const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"};
657 /* bad numeric value */
658 const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" };
659 /* zero is invalid */
660 const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "0" };
661 /* sanity test - check with good value */
662 const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" };
663 /* sanity test - check with no -n flag */
664 const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"};
666 if (launch_proc(argv1) == 0
667 || launch_proc(argv2) == 0
668 || launch_proc(argv3) == 0) {
669 printf("Error - process ran without error when"
670 "invalid -n flag\n");
673 if (launch_proc(argv4) != 0) {
674 printf("Error - process did not run ok with valid num-channel value\n");
677 if (launch_proc(argv5) != 0) {
678 printf("Error - process did not run ok without -n flag\n");
686 * Test that the app runs with HPET, and without HPET
689 test_no_hpet_flag(void)
691 char prefix[PATH_MAX] = "";
693 #ifdef RTE_EXEC_ENV_BSDAPP
697 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
698 printf("Error - unable to get current prefix!\n");
701 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
705 const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"};
706 /* Without --no-hpet */
707 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-n", "2"};
709 if (launch_proc(argv1) != 0) {
710 printf("Error - process did not run ok with --no-hpet flag\n");
713 if (launch_proc(argv2) != 0) {
714 printf("Error - process did not run ok without --no-hpet flag\n");
721 * Test that the app runs with --no-huge and doesn't run when --socket-mem are
722 * specified with --no-huge.
725 test_no_huge_flag(void)
727 #ifdef RTE_EXEC_ENV_BSDAPP
728 /* BSD target doesn't support prefixes at this point, and we also need to
729 * run another primary process here */
730 const char * prefix = no_shconf;
732 const char * prefix = "--file-prefix=nohuge";
736 const char *argv1[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2"};
737 /* With --no-huge and -m */
738 const char *argv2[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
739 "-m", DEFAULT_MEM_SIZE};
741 /* With --no-huge and --socket-mem */
742 const char *argv3[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
743 "--socket-mem=" DEFAULT_MEM_SIZE};
744 /* With --no-huge, -m and --socket-mem */
745 const char *argv4[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
746 "-m", DEFAULT_MEM_SIZE, "--socket-mem=" DEFAULT_MEM_SIZE};
747 if (launch_proc(argv1) != 0) {
748 printf("Error - process did not run ok with --no-huge flag\n");
751 if (launch_proc(argv2) != 0) {
752 printf("Error - process did not run ok with --no-huge and -m flags\n");
755 #ifdef RTE_EXEC_ENV_BSDAPP
756 /* BSD target does not support NUMA, hence no --socket-mem tests */
760 if (launch_proc(argv3) == 0) {
761 printf("Error - process run ok with --no-huge and --socket-mem "
765 if (launch_proc(argv4) == 0) {
766 printf("Error - process run ok with --no-huge, -m and "
767 "--socket-mem flags\n");
774 test_misc_flags(void)
776 char hugepath[PATH_MAX] = {0};
777 #ifdef RTE_EXEC_ENV_BSDAPP
778 /* BSD target doesn't support prefixes at this point */
779 const char * prefix = "";
780 const char * nosh_prefix = "";
782 char prefix[PATH_MAX], tmp[PATH_MAX];
783 const char * nosh_prefix = "--file-prefix=noshconf";
784 FILE * hugedir_handle = NULL;
785 char line[PATH_MAX] = {0};
786 unsigned i, isempty = 1;
787 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
788 printf("Error - unable to get current prefix!\n");
791 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
794 * get first valid hugepage path
797 /* get hugetlbfs mountpoints from /proc/mounts */
798 hugedir_handle = fopen("/proc/mounts", "r");
800 if (hugedir_handle == NULL) {
801 printf("Error opening /proc/mounts!\n");
805 /* read /proc/mounts */
806 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
808 /* find first valid hugepath */
809 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
813 fclose(hugedir_handle);
815 /* check if path is not empty */
816 for (i = 0; i < sizeof(hugepath); i++)
817 if (hugepath[i] != '\0')
821 printf("No mounted hugepage dir found!\n");
827 /* check that some general flags don't prevent things from working.
828 * All cases, apart from the first, app should run.
829 * No further testing of output done.
831 /* sanity check - failure with invalid option */
832 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
835 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
837 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
838 /* With valid --syslog */
839 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
840 "--syslog", "syslog"};
841 /* With empty --syslog (should fail) */
842 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
843 /* With invalid --syslog */
844 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
845 /* With no-sh-conf, also use no-huge to ensure this test runs on BSD */
846 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
847 no_shconf, nosh_prefix, no_huge};
849 /* With --huge-dir */
850 const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
851 "--file-prefix=hugedir", "--huge-dir", hugepath};
852 /* With empty --huge-dir (should fail) */
853 const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
854 "--file-prefix=hugedir", "--huge-dir"};
855 /* With invalid --huge-dir */
856 const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
857 "--file-prefix=hugedir", "--huge-dir", "invalid"};
858 /* Secondary process with invalid --huge-dir (should run as flag has no
859 * effect on secondary processes) */
860 const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
862 /* try running with base-virtaddr param */
863 const char *argv11[] = {prgname, "--file-prefix=virtaddr",
864 "-c", "1", "-n", "2", "--base-virtaddr=0x12345678"};
866 /* try running with --vfio-intr INTx flag */
867 const char *argv12[] = {prgname, "--file-prefix=intr",
868 "-c", "1", "-n", "2", "--vfio-intr=legacy"};
870 /* try running with --vfio-intr MSI flag */
871 const char *argv13[] = {prgname, "--file-prefix=intr",
872 "-c", "1", "-n", "2", "--vfio-intr=msi"};
874 /* try running with --vfio-intr MSI-X flag */
875 const char *argv14[] = {prgname, "--file-prefix=intr",
876 "-c", "1", "-n", "2", "--vfio-intr=msix"};
878 /* try running with --vfio-intr invalid flag */
879 const char *argv15[] = {prgname, "--file-prefix=intr",
880 "-c", "1", "-n", "2", "--vfio-intr=invalid"};
882 /* run all tests also applicable to FreeBSD first */
884 if (launch_proc(argv0) == 0) {
885 printf("Error - process ran ok with invalid flag\n");
888 if (launch_proc(argv1) != 0) {
889 printf("Error - process did not run ok with --no-pci flag\n");
892 if (launch_proc(argv2) != 0) {
893 printf("Error - process did not run ok with -v flag\n");
896 if (launch_proc(argv6) != 0) {
897 printf("Error - process did not run ok with --no-shconf flag\n");
901 #ifdef RTE_EXEC_ENV_BSDAPP
902 /* no more tests to be done on FreeBSD */
906 if (launch_proc(argv3) != 0) {
907 printf("Error - process did not run ok with --syslog flag\n");
910 if (launch_proc(argv4) == 0) {
911 printf("Error - process run ok with empty --syslog flag\n");
914 if (launch_proc(argv5) == 0) {
915 printf("Error - process run ok with invalid --syslog flag\n");
918 if (launch_proc(argv7) != 0) {
919 printf("Error - process did not run ok with --huge-dir flag\n");
922 if (launch_proc(argv8) == 0) {
923 printf("Error - process run ok with empty --huge-dir flag\n");
926 if (launch_proc(argv9) == 0) {
927 printf("Error - process run ok with invalid --huge-dir flag\n");
930 if (launch_proc(argv10) != 0) {
931 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
934 if (launch_proc(argv11) != 0) {
935 printf("Error - process did not run ok with --base-virtaddr parameter\n");
938 if (launch_proc(argv12) != 0) {
939 printf("Error - process did not run ok with "
940 "--vfio-intr INTx parameter\n");
943 if (launch_proc(argv13) != 0) {
944 printf("Error - process did not run ok with "
945 "--vfio-intr MSI parameter\n");
948 if (launch_proc(argv14) != 0) {
949 printf("Error - process did not run ok with "
950 "--vfio-intr MSI-X parameter\n");
953 if (launch_proc(argv15) == 0) {
954 printf("Error - process run ok with "
955 "--vfio-intr invalid parameter\n");
962 test_file_prefix(void)
965 * 1. check if current process hugefiles are locked
966 * 2. try to run secondary process without a corresponding primary process
967 * (while failing to run, it will also remove any unused hugepage files)
968 * 3. check if current process hugefiles are still in place and are locked
969 * 4. run a primary process with memtest1 prefix in default and legacy
971 * 5. check if memtest1 hugefiles are created in case of legacy mem
972 * mode, and deleted in case of default mem mode
973 * 6. run a primary process with memtest2 prefix in default and legacy
975 * 7. check that memtest2 hugefiles are present in the hugedir after a
976 * run in legacy mode, and not present at all after run in default
979 char prefix[PATH_MAX] = "";
981 #ifdef RTE_EXEC_ENV_BSDAPP
984 if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
985 printf("Error - unable to get current prefix!\n");
990 /* this should fail unless the test itself is run with "memtest" prefix */
991 const char *argv0[] = {prgname, mp_flag, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
992 "--file-prefix=" memtest };
994 /* primary process with memtest1 and default mem mode */
995 const char *argv1[] = {prgname, "-c", "1", "-n", "2", "-m",
996 DEFAULT_MEM_SIZE, "--file-prefix=" memtest1 };
998 /* primary process with memtest1 and legacy mem mode */
999 const char *argv2[] = {prgname, "-c", "1", "-n", "2", "-m",
1000 DEFAULT_MEM_SIZE, "--file-prefix=" memtest1,
1003 /* primary process with memtest2 and legacy mem mode */
1004 const char *argv3[] = {prgname, "-c", "1", "-n", "2", "-m",
1005 DEFAULT_MEM_SIZE, "--file-prefix=" memtest2,
1008 /* primary process with memtest2 and default mem mode */
1009 const char *argv4[] = {prgname, "-c", "1", "-n", "2", "-m",
1010 DEFAULT_MEM_SIZE, "--file-prefix=" memtest2 };
1012 /* check if files for current prefix are present */
1013 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1014 printf("Error - hugepage files for %s were not created!\n", prefix);
1018 /* checks if files for current prefix are locked */
1019 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1020 printf("Error - hugepages for current process aren't locked!\n");
1024 /* check if files for secondary process are present */
1025 if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
1026 /* check if they are not locked */
1027 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
1028 printf("Error - hugepages for current process are locked!\n");
1031 /* they aren't locked, delete them */
1033 if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
1034 printf("Error - deleting hugepages failed!\n");
1040 if (launch_proc(argv0) == 0) {
1041 printf("Error - secondary process ran ok without primary process\n");
1045 /* check if files for current prefix are present */
1046 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1047 printf("Error - hugepage files for %s were not created!\n", prefix);
1051 /* checks if files for current prefix are locked */
1052 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1053 printf("Error - hugepages for current process aren't locked!\n");
1057 /* we're running this process in default memory mode, which means it
1058 * should clean up after itself on exit and leave no hugepages behind.
1060 if (launch_proc(argv1) != 0) {
1061 printf("Error - failed to run with --file-prefix=%s\n",
1066 /* check if memtest1_map0 is present */
1067 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1068 printf("Error - hugepage files for %s were not deleted!\n",
1073 /* now, we're running a process under the same prefix, but with legacy
1074 * mem mode - this should leave behind hugepage files.
1076 if (launch_proc(argv2) != 0) {
1077 printf("Error - failed to run with --file-prefix=%s\n",
1082 /* check if memtest1_map0 is present */
1083 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
1084 printf("Error - hugepage files for %s were not created!\n",
1089 if (launch_proc(argv3) != 0) {
1090 printf("Error - failed to run with --file-prefix=%s\n",
1095 /* check if hugefiles for memtest2 are present */
1096 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
1097 printf("Error - hugepage files for %s were not created!\n",
1102 /* check if hugefiles for memtest1 are present */
1103 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1104 printf("Error - hugepage files for %s were not deleted!\n",
1109 /* this process will run in default mem mode, so it should not leave any
1110 * hugepage files behind.
1112 if (launch_proc(argv4) != 0) {
1113 printf("Error - failed to run with --file-prefix=%s\n",
1118 /* check if hugefiles for memtest2 are present */
1119 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 0) {
1120 printf("Error - hugepage files for %s were not deleted!\n",
1125 /* check if hugefiles for memtest1 are present */
1126 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1127 printf("Error - hugepage files for %s were not deleted!\n",
1136 * Tests for correct handling of -m and --socket-mem flags
1139 test_memory_flags(void)
1141 #ifdef RTE_EXEC_ENV_BSDAPP
1142 /* BSD target doesn't support prefixes at this point */
1143 const char * prefix = "";
1145 char prefix[PATH_MAX], tmp[PATH_MAX];
1146 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
1147 printf("Error - unable to get current prefix!\n");
1150 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
1153 /* valid -m flag and mp flag */
1154 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "10",
1155 "-n", "2", "-m", DEFAULT_MEM_SIZE};
1158 const char *argv1[] = {prgname, "-c", "10", "-n", "2",
1159 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE};
1161 /* valid (zero) --socket-mem flag */
1162 const char *argv2[] = {prgname, "-c", "10", "-n", "2",
1163 "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
1165 /* invalid (incomplete) --socket-mem flag */
1166 const char *argv3[] = {prgname, "-c", "10", "-n", "2",
1167 "--file-prefix=" memtest, "--socket-mem=2,2,"};
1169 /* invalid (mixed with invalid data) --socket-mem flag */
1170 const char *argv4[] = {prgname, "-c", "10", "-n", "2",
1171 "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
1173 /* invalid (with numeric value as last character) --socket-mem flag */
1174 const char *argv5[] = {prgname, "-c", "10", "-n", "2",
1175 "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
1177 /* invalid (with empty socket) --socket-mem flag */
1178 const char *argv6[] = {prgname, "-c", "10", "-n", "2",
1179 "--file-prefix=" memtest, "--socket-mem=2,,2"};
1181 /* invalid (null) --socket-mem flag */
1182 const char *argv7[] = {prgname, "-c", "10", "-n", "2",
1183 "--file-prefix=" memtest, "--socket-mem="};
1185 /* valid --socket-mem specified together with -m flag */
1186 const char *argv8[] = {prgname, "-c", "10", "-n", "2",
1187 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE, "--socket-mem=2,2"};
1189 /* construct an invalid socket mask with 2 megs on each socket plus
1190 * extra 2 megs on socket that doesn't exist on current system */
1191 char invalid_socket_mem[SOCKET_MEM_STRLEN];
1192 char buf[SOCKET_MEM_STRLEN]; /* to avoid copying string onto itself */
1194 #ifdef RTE_EXEC_ENV_BSDAPP
1195 int i, num_sockets = 1;
1197 int i, num_sockets = RTE_MIN(get_number_of_sockets(),
1198 RTE_MAX_NUMA_NODES);
1201 if (num_sockets <= 0) {
1202 printf("Error - cannot get number of sockets!\n");
1206 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
1208 /* add one extra socket */
1209 for (i = 0; i < num_sockets + 1; i++) {
1210 snprintf(buf, sizeof(buf), "%s%s", invalid_socket_mem, DEFAULT_MEM_SIZE);
1211 strlcpy(invalid_socket_mem, buf, sizeof(invalid_socket_mem));
1213 if (num_sockets + 1 - i > 1) {
1214 snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
1215 strlcpy(invalid_socket_mem, buf,
1216 sizeof(invalid_socket_mem));
1220 /* construct a valid socket mask with 2 megs on each existing socket */
1221 char valid_socket_mem[SOCKET_MEM_STRLEN];
1223 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
1225 /* add one extra socket */
1226 for (i = 0; i < num_sockets; i++) {
1227 snprintf(buf, sizeof(buf), "%s%s", valid_socket_mem, DEFAULT_MEM_SIZE);
1228 strlcpy(valid_socket_mem, buf, sizeof(valid_socket_mem));
1230 if (num_sockets - i > 1) {
1231 snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
1232 strlcpy(valid_socket_mem, buf,
1233 sizeof(valid_socket_mem));
1237 /* invalid --socket-mem flag (with extra socket) */
1238 const char *argv9[] = {prgname, "-c", "10", "-n", "2",
1239 "--file-prefix=" memtest, invalid_socket_mem};
1241 /* valid --socket-mem flag */
1242 const char *argv10[] = {prgname, "-c", "10", "-n", "2",
1243 "--file-prefix=" memtest, valid_socket_mem};
1245 if (launch_proc(argv0) != 0) {
1246 printf("Error - secondary process failed with valid -m flag !\n");
1250 #ifdef RTE_EXEC_ENV_BSDAPP
1251 /* no other tests are applicable to BSD */
1255 if (launch_proc(argv1) != 0) {
1256 printf("Error - process failed with valid -m flag!\n");
1259 if (launch_proc(argv2) != 0) {
1260 printf("Error - process failed with valid (zero) --socket-mem!\n");
1264 if (launch_proc(argv3) == 0) {
1265 printf("Error - process run ok with invalid "
1266 "(incomplete) --socket-mem!\n");
1270 if (launch_proc(argv4) == 0) {
1271 printf("Error - process run ok with invalid "
1272 "(mixed with invalid input) --socket-mem!\n");
1276 if (launch_proc(argv5) == 0) {
1277 printf("Error - process run ok with invalid "
1278 "(mixed with invalid input with a numeric value as "
1279 "last character) --socket-mem!\n");
1283 if (launch_proc(argv6) == 0) {
1284 printf("Error - process run ok with invalid "
1285 "(with empty socket) --socket-mem!\n");
1289 if (launch_proc(argv7) == 0) {
1290 printf("Error - process run ok with invalid (null) --socket-mem!\n");
1294 if (launch_proc(argv8) == 0) {
1295 printf("Error - process run ok with --socket-mem and -m specified!\n");
1299 if (launch_proc(argv9) == 0) {
1300 printf("Error - process run ok with extra socket in --socket-mem!\n");
1304 if (launch_proc(argv10) != 0) {
1305 printf("Error - process failed with valid --socket-mem!\n");
1313 test_eal_flags(void)
1317 ret = test_missing_c_flag();
1319 printf("Error in test_missing_c_flag()\n");
1323 ret = test_master_lcore_flag();
1325 printf("Error in test_master_lcore_flag()\n");
1329 ret = test_invalid_n_flag();
1331 printf("Error in test_invalid_n_flag()\n");
1335 ret = test_no_hpet_flag();
1337 printf("Error in test_no_hpet_flag()\n");
1341 ret = test_no_huge_flag();
1343 printf("Error in test_no_huge_flag()\n");
1347 ret = test_whitelist_flag();
1349 printf("Error in test_invalid_whitelist_flag()\n");
1353 ret = test_invalid_b_flag();
1355 printf("Error in test_invalid_b_flag()\n");
1359 #ifdef RTE_LIBRTE_PMD_RING
1360 ret = test_invalid_vdev_flag();
1362 printf("Error in test_invalid_vdev_flag()\n");
1366 ret = test_invalid_r_flag();
1368 printf("Error in test_invalid_r_flag()\n");
1372 ret = test_memory_flags();
1374 printf("Error in test_memory_flags()\n");
1378 ret = test_file_prefix();
1380 printf("Error in test_file_prefix()\n");
1384 ret = test_misc_flags();
1386 printf("Error in test_misc_flags()");
1393 REGISTER_TEST_COMMAND(eal_flags_autotest, test_eal_flags);