4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5 * Copyright(c) 2014 6WIND S.A.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 #include <rte_debug.h>
50 #include <rte_string_fns.h>
54 #define DEFAULT_MEM_SIZE "18"
55 #define mp_flag "--proc-type=secondary"
56 #define no_hpet "--no-hpet"
57 #define no_huge "--no-huge"
58 #define no_shconf "--no-shconf"
59 #define pci_whitelist "--pci-whitelist"
61 #define memtest "memtest"
62 #define memtest1 "memtest1"
63 #define memtest2 "memtest2"
64 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 20)
65 #define launch_proc(ARGV) process_dup(ARGV, \
66 sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
68 enum hugepage_action {
69 HUGEPAGE_CHECK_EXISTS = 0,
70 HUGEPAGE_CHECK_LOCKED,
75 /* if string contains a hugepage path */
77 get_hugepage_path(char * src, int src_len, char * dst, int dst_len)
80 char *tokens[NUM_TOKENS];
82 /* if we couldn't properly split the string */
83 if (rte_strsplit(src, src_len, tokens, NUM_TOKENS, ' ') < NUM_TOKENS)
86 if (strncmp(tokens[2], "hugetlbfs", sizeof("hugetlbfs")) == 0) {
87 snprintf(dst, dst_len, "%s", tokens[1]);
94 * Cycles through hugepage directories and looks for hugepage
95 * files associated with a given prefix. Depending on value of
96 * action, the hugepages are checked if they exist, checked if
97 * they can be locked, or are simply deleted.
99 * Returns 1 if it finds at least one hugepage matching the action
100 * Returns 0 if no matching hugepages were found
101 * Returns -1 if it encounters an error
104 process_hugefiles(const char * prefix, enum hugepage_action action)
106 FILE * hugedir_handle = NULL;
107 DIR * hugepage_dir = NULL;
108 struct dirent *dirent = NULL;
110 char hugefile_prefix[PATH_MAX] = {0};
111 char hugedir[PATH_MAX] = {0};
112 char line[PATH_MAX] = {0};
114 int fd, lck_result, result = 0;
116 const int prefix_len = snprintf(hugefile_prefix,
117 sizeof(hugefile_prefix), "%smap_", prefix);
118 if (prefix_len <= 0 || prefix_len >= (int)sizeof(hugefile_prefix)
119 || prefix_len >= (int)sizeof(dirent->d_name)) {
120 printf("Error creating hugefile filename prefix\n");
124 /* get hugetlbfs mountpoints from /proc/mounts */
125 hugedir_handle = fopen("/proc/mounts", "r");
127 if (hugedir_handle == NULL) {
128 printf("Error parsing /proc/mounts!\n");
132 /* read and parse script output */
133 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
135 /* check if we have a hugepage filesystem path */
136 if (!get_hugepage_path(line, sizeof(line), hugedir, sizeof(hugedir)))
139 /* check if directory exists */
140 if ((hugepage_dir = opendir(hugedir)) == NULL) {
141 fclose(hugedir_handle);
142 printf("Error reading %s: %s\n", hugedir, strerror(errno));
146 while ((dirent = readdir(hugepage_dir)) != NULL) {
147 if (memcmp(dirent->d_name, hugefile_prefix, prefix_len) != 0)
151 case HUGEPAGE_CHECK_EXISTS:
153 /* file exists, return */
158 case HUGEPAGE_DELETE:
160 char file_path[PATH_MAX] = {0};
162 snprintf(file_path, sizeof(file_path),
163 "%s/%s", hugedir, dirent->d_name);
166 if (remove(file_path) < 0) {
167 printf("Error deleting %s - %s!\n",
168 dirent->d_name, strerror(errno));
169 closedir(hugepage_dir);
176 case HUGEPAGE_CHECK_LOCKED:
178 /* try and lock the file */
179 fd = openat(dirfd(hugepage_dir), dirent->d_name, O_RDONLY);
181 /* this shouldn't happen */
183 printf("Error opening %s - %s!\n",
184 dirent->d_name, strerror(errno));
185 closedir(hugepage_dir);
190 /* non-blocking lock */
191 lck_result = flock(fd, LOCK_EX | LOCK_NB);
193 /* if lock succeeds, there's something wrong */
194 if (lck_result != -1) {
197 /* unlock the resulting lock */
200 closedir(hugepage_dir);
207 /* shouldn't happen */
212 } /* read hugepage directory */
213 closedir(hugepage_dir);
214 } /* read /proc/mounts */
216 fclose(hugedir_handle);
220 #ifdef RTE_EXEC_ENV_LINUXAPP
222 * count the number of "node*" files in /sys/devices/system/node/
225 get_number_of_sockets(void)
227 struct dirent *dirent = NULL;
228 const char * nodedir = "/sys/devices/system/node/";
232 /* check if directory exists */
233 if ((dir = opendir(nodedir)) == NULL) {
234 /* if errno==ENOENT this means we don't have NUMA support */
235 if (errno == ENOENT) {
236 printf("No NUMA nodes detected: assuming 1 available socket\n");
239 printf("Error opening %s: %s\n", nodedir, strerror(errno));
243 while ((dirent = readdir(dir)) != NULL)
244 if (strncmp(dirent->d_name, "node", sizeof("node") - 1) == 0)
253 get_current_prefix(char * prefix, int size)
255 char path[PATH_MAX] = {0};
256 char buf[PATH_MAX] = {0};
258 /* get file for config (fd is always 3) */
259 snprintf(path, sizeof(path), "/proc/self/fd/%d", 3);
261 /* return NULL on error */
262 if (readlink(path, buf, sizeof(buf)) == -1)
265 /* get the basename */
266 snprintf(buf, sizeof(buf), "%s", basename(buf));
268 /* copy string all the way from second char up to start of _config */
269 snprintf(prefix, size, "%.*s",
270 (int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
277 * Test that the app doesn't run with invalid whitelist option.
278 * Final tests ensures it does run with valid options as sanity check (one
279 * test for with Domain+BDF, second for just with BDF)
282 test_whitelist_flag(void)
285 #ifdef RTE_EXEC_ENV_BSDAPP
286 /* BSD target doesn't support prefixes at this point */
287 const char * prefix = "";
289 char prefix[PATH_MAX], tmp[PATH_MAX];
290 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
291 printf("Error - unable to get current prefix!\n");
294 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
297 const char *wlinval[][11] = {
298 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
299 pci_whitelist, "error", "", ""},
300 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
301 pci_whitelist, "0:0:0", "", ""},
302 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
303 pci_whitelist, "0:error:0.1", "", ""},
304 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
305 pci_whitelist, "0:0:0.1error", "", ""},
306 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
307 pci_whitelist, "error0:0:0.1", "", ""},
308 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
309 pci_whitelist, "0:0:0.1.2", "", ""},
311 /* Test with valid whitelist option */
312 const char *wlval1[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
313 pci_whitelist, "00FF:09:0B.3"};
314 const char *wlval2[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
315 pci_whitelist, "09:0B.3", pci_whitelist, "0a:0b.1"};
316 const char *wlval3[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
317 pci_whitelist, "09:0B.3,type=test",
318 pci_whitelist, "08:00.1,type=normal",
321 for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
322 if (launch_proc(wlinval[i]) == 0) {
323 printf("Error - process did run ok with invalid "
324 "whitelist parameter\n");
328 if (launch_proc(wlval1) != 0 ) {
329 printf("Error - process did not run ok with valid whitelist\n");
332 if (launch_proc(wlval2) != 0 ) {
333 printf("Error - process did not run ok with valid whitelist value set\n");
336 if (launch_proc(wlval3) != 0 ) {
337 printf("Error - process did not run ok with valid whitelist + args\n");
345 * Test that the app doesn't run with invalid blacklist option.
346 * Final test ensures it does run with valid options as sanity check
349 test_invalid_b_flag(void)
351 #ifdef RTE_EXEC_ENV_BSDAPP
352 /* BSD target doesn't support prefixes at this point */
353 const char * prefix = "";
355 char prefix[PATH_MAX], tmp[PATH_MAX];
356 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
357 printf("Error - unable to get current prefix!\n");
360 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
363 const char *blinval[][9] = {
364 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error"},
365 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0"},
366 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:error:0.1"},
367 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1error"},
368 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error0:0:0.1"},
369 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1.2"},
371 /* Test with valid blacklist option */
372 const char *blval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
376 for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
377 if (launch_proc(blinval[i]) == 0) {
378 printf("Error - process did run ok with invalid "
379 "blacklist parameter\n");
383 if (launch_proc(blval) != 0) {
384 printf("Error - process did not run ok with valid blacklist value\n");
391 * Test that the app doesn't run with invalid vdev option.
392 * Final test ensures it does run with valid options as sanity check
394 #ifdef RTE_LIBRTE_PMD_RING
396 test_invalid_vdev_flag(void)
398 #ifdef RTE_EXEC_ENV_BSDAPP
399 /* BSD target doesn't support prefixes at this point, and we also need to
400 * run another primary process here */
401 const char * prefix = no_shconf;
403 const char * prefix = "--file-prefix=vdev";
406 /* Test with invalid vdev option */
407 const char *vdevinval[] = {prgname, prefix, no_huge, "-n", "1",
408 "-c", "1", vdev, "eth_dummy"};
410 /* Test with valid vdev option */
411 const char *vdevval1[] = {prgname, prefix, no_huge, "-n", "1",
412 "-c", "1", vdev, "net_ring0"};
414 const char *vdevval2[] = {prgname, prefix, no_huge, "-n", "1",
415 "-c", "1", vdev, "net_ring0,args=test"};
417 const char *vdevval3[] = {prgname, prefix, no_huge, "-n", "1",
418 "-c", "1", vdev, "net_ring0,nodeaction=r1:0:CREATE"};
420 if (launch_proc(vdevinval) == 0) {
421 printf("Error - process did run ok with invalid "
426 if (launch_proc(vdevval1) != 0) {
427 printf("Error - process did not run ok with valid vdev value\n");
431 if (launch_proc(vdevval2) != 0) {
432 printf("Error - process did not run ok with valid vdev value,"
433 "with dummy args\n");
437 if (launch_proc(vdevval3) != 0) {
438 printf("Error - process did not run ok with valid vdev value,"
439 "with valid args\n");
447 * Test that the app doesn't run with invalid -r option.
450 test_invalid_r_flag(void)
452 #ifdef RTE_EXEC_ENV_BSDAPP
453 /* BSD target doesn't support prefixes at this point */
454 const char * prefix = "";
456 char prefix[PATH_MAX], tmp[PATH_MAX];
457 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
458 printf("Error - unable to get current prefix!\n");
461 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
464 const char *rinval[][9] = {
465 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "error"},
466 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "0"},
467 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "-1"},
468 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "17"},
470 /* Test with valid blacklist option */
471 const char *rval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
475 for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
476 if (launch_proc(rinval[i]) == 0) {
477 printf("Error - process did run ok with invalid "
478 "-r (rank) parameter\n");
482 if (launch_proc(rval) != 0) {
483 printf("Error - process did not run ok with valid -r (rank) value\n");
490 * Test that the app doesn't run without the coremask/corelist flags. In all cases
491 * should give an error and fail to run
494 test_missing_c_flag(void)
496 #ifdef RTE_EXEC_ENV_BSDAPP
497 /* BSD target doesn't support prefixes at this point */
498 const char * prefix = "";
500 char prefix[PATH_MAX], tmp[PATH_MAX];
501 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
502 printf("Error - unable to get current prefix!\n");
505 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
508 /* -c flag but no coremask value */
509 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "3", "-c"};
510 /* No -c, -l or --lcores flag at all */
511 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "3"};
512 /* bad coremask value */
513 const char *argv3[] = { prgname, prefix, mp_flag,
514 "-n", "3", "-c", "error" };
515 /* sanity check of tests - valid coremask value */
516 const char *argv4[] = { prgname, prefix, mp_flag,
517 "-n", "3", "-c", "1" };
518 /* -l flag but no corelist value */
519 const char *argv5[] = { prgname, prefix, mp_flag,
521 const char *argv6[] = { prgname, prefix, mp_flag,
522 "-n", "3", "-l", " " };
523 /* bad corelist values */
524 const char *argv7[] = { prgname, prefix, mp_flag,
525 "-n", "3", "-l", "error" };
526 const char *argv8[] = { prgname, prefix, mp_flag,
527 "-n", "3", "-l", "1-" };
528 const char *argv9[] = { prgname, prefix, mp_flag,
529 "-n", "3", "-l", "1," };
530 const char *argv10[] = { prgname, prefix, mp_flag,
531 "-n", "3", "-l", "1#2" };
532 /* sanity check test - valid corelist value */
533 const char *argv11[] = { prgname, prefix, mp_flag,
534 "-n", "3", "-l", "1-2,3" };
536 /* --lcores flag but no lcores value */
537 const char *argv12[] = { prgname, prefix, mp_flag,
538 "-n", "3", "--lcores" };
539 const char *argv13[] = { prgname, prefix, mp_flag,
540 "-n", "3", "--lcores", " " };
541 /* bad lcores value */
542 const char *argv14[] = { prgname, prefix, mp_flag,
543 "-n", "3", "--lcores", "1-3-5" };
544 const char *argv15[] = { prgname, prefix, mp_flag,
545 "-n", "3", "--lcores", "0-1,,2" };
546 const char *argv16[] = { prgname, prefix, mp_flag,
547 "-n", "3", "--lcores", "0-,1" };
548 const char *argv17[] = { prgname, prefix, mp_flag,
549 "-n", "3", "--lcores", "(0-,2-4)" };
550 const char *argv18[] = { prgname, prefix, mp_flag,
551 "-n", "3", "--lcores", "(-1,2)" };
552 const char *argv19[] = { prgname, prefix, mp_flag,
553 "-n", "3", "--lcores", "(2-4)@(2-4-6)" };
554 const char *argv20[] = { prgname, prefix, mp_flag,
555 "-n", "3", "--lcores", "(a,2)" };
556 const char *argv21[] = { prgname, prefix, mp_flag,
557 "-n", "3", "--lcores", "1-3@(1,3)" };
558 const char *argv22[] = { prgname, prefix, mp_flag,
559 "-n", "3", "--lcores", "3@((1,3)" };
560 const char *argv23[] = { prgname, prefix, mp_flag,
561 "-n", "3", "--lcores", "(4-7)=(1,3)" };
562 const char *argv24[] = { prgname, prefix, mp_flag,
563 "-n", "3", "--lcores", "[4-7]@(1,3)" };
564 /* sanity check of tests - valid lcores value */
565 const char *argv25[] = { prgname, prefix, mp_flag,
566 "-n", "3", "--lcores",
567 "0-1,2@(5-7),(3-5)@(0,2),(0,6),7"};
569 if (launch_proc(argv2) != 0) {
571 "process did not run ok when missing -c flag\n");
575 if (launch_proc(argv1) == 0
576 || launch_proc(argv3) == 0) {
578 "process ran without error with invalid -c flag\n");
581 if (launch_proc(argv4) != 0) {
583 "process did not run ok with valid coremask value\n");
588 if (launch_proc(argv5) == 0
589 || launch_proc(argv6) == 0
590 || launch_proc(argv7) == 0
591 || launch_proc(argv8) == 0
592 || launch_proc(argv9) == 0
593 || launch_proc(argv10) == 0) {
595 "process ran without error with invalid -l flag\n");
598 if (launch_proc(argv11) != 0) {
600 "process did not run ok with valid corelist value\n");
604 /* start --lcores tests */
605 if (launch_proc(argv12) == 0 || launch_proc(argv13) == 0 ||
606 launch_proc(argv14) == 0 || launch_proc(argv15) == 0 ||
607 launch_proc(argv16) == 0 || launch_proc(argv17) == 0 ||
608 launch_proc(argv18) == 0 || launch_proc(argv19) == 0 ||
609 launch_proc(argv20) == 0 || launch_proc(argv21) == 0 ||
610 launch_proc(argv21) == 0 || launch_proc(argv22) == 0 ||
611 launch_proc(argv23) == 0 || launch_proc(argv24) == 0) {
613 "process ran without error with invalid --lcore flag\n");
617 if (launch_proc(argv25) != 0) {
619 "process did not run ok with valid corelist value\n");
627 * Test --master-lcore option with matching coremask
630 test_master_lcore_flag(void)
632 #ifdef RTE_EXEC_ENV_BSDAPP
633 /* BSD target doesn't support prefixes at this point */
634 const char *prefix = "";
636 char prefix[PATH_MAX], tmp[PATH_MAX];
637 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
638 printf("Error - unable to get current prefix!\n");
641 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
644 /* --master-lcore flag but no value */
645 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore"};
646 /* --master-lcore flag with invalid value */
647 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "-1"};
648 const char *argv3[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "X"};
649 /* master lcore not in coremask */
650 const char *argv4[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "2"};
652 const char *argv5[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "1"};
653 /* valid value set before coremask */
654 const char *argv6[] = { prgname, prefix, mp_flag, "-n", "1", "--master-lcore", "1", "-c", "3"};
656 if (launch_proc(argv1) == 0
657 || launch_proc(argv2) == 0
658 || launch_proc(argv3) == 0
659 || launch_proc(argv4) == 0) {
660 printf("Error - process ran without error with wrong --master-lcore\n");
663 if (launch_proc(argv5) != 0
664 || launch_proc(argv6) != 0) {
665 printf("Error - process did not run ok with valid --master-lcore\n");
672 * Test that the app doesn't run with invalid -n flag option.
673 * Final test ensures it does run with valid options as sanity check
674 * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
678 test_invalid_n_flag(void)
680 #ifdef RTE_EXEC_ENV_BSDAPP
681 /* BSD target doesn't support prefixes at this point */
682 const char * prefix = "";
684 char prefix[PATH_MAX], tmp[PATH_MAX];
685 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
686 printf("Error - unable to get current prefix!\n");
689 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
692 /* -n flag but no value */
693 const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"};
694 /* bad numeric value */
695 const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" };
696 /* zero is invalid */
697 const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "0" };
698 /* sanity test - check with good value */
699 const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" };
700 /* sanity test - check with no -n flag */
701 const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"};
703 if (launch_proc(argv1) == 0
704 || launch_proc(argv2) == 0
705 || launch_proc(argv3) == 0) {
706 printf("Error - process ran without error when"
707 "invalid -n flag\n");
710 if (launch_proc(argv4) != 0) {
711 printf("Error - process did not run ok with valid num-channel value\n");
714 if (launch_proc(argv5) != 0) {
715 printf("Error - process did not run ok without -n flag\n");
723 * Test that the app runs with HPET, and without HPET
726 test_no_hpet_flag(void)
728 char prefix[PATH_MAX], tmp[PATH_MAX];
730 #ifdef RTE_EXEC_ENV_BSDAPP
733 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
734 printf("Error - unable to get current prefix!\n");
737 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
740 const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"};
741 /* Without --no-hpet */
742 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-n", "2"};
744 if (launch_proc(argv1) != 0) {
745 printf("Error - process did not run ok with --no-hpet flag\n");
748 if (launch_proc(argv2) != 0) {
749 printf("Error - process did not run ok without --no-hpet flag\n");
756 * Test that the app runs with --no-huge and doesn't run when --socket-mem are
757 * specified with --no-huge.
760 test_no_huge_flag(void)
762 #ifdef RTE_EXEC_ENV_BSDAPP
763 /* BSD target doesn't support prefixes at this point, and we also need to
764 * run another primary process here */
765 const char * prefix = no_shconf;
767 const char * prefix = "--file-prefix=nohuge";
771 const char *argv1[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2"};
772 /* With --no-huge and -m */
773 const char *argv2[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
774 "-m", DEFAULT_MEM_SIZE};
776 /* With --no-huge and --socket-mem */
777 const char *argv3[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
778 "--socket-mem=" DEFAULT_MEM_SIZE};
779 /* With --no-huge, -m and --socket-mem */
780 const char *argv4[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
781 "-m", DEFAULT_MEM_SIZE, "--socket-mem=" DEFAULT_MEM_SIZE};
782 if (launch_proc(argv1) != 0) {
783 printf("Error - process did not run ok with --no-huge flag\n");
786 if (launch_proc(argv2) != 0) {
787 printf("Error - process did not run ok with --no-huge and -m flags\n");
790 #ifdef RTE_EXEC_ENV_BSDAPP
791 /* BSD target does not support NUMA, hence no --socket-mem tests */
795 if (launch_proc(argv3) == 0) {
796 printf("Error - process run ok with --no-huge and --socket-mem "
800 if (launch_proc(argv4) == 0) {
801 printf("Error - process run ok with --no-huge, -m and "
802 "--socket-mem flags\n");
809 test_misc_flags(void)
811 char hugepath[PATH_MAX] = {0};
812 #ifdef RTE_EXEC_ENV_BSDAPP
813 /* BSD target doesn't support prefixes at this point */
814 const char * prefix = "";
815 const char * nosh_prefix = "";
817 char prefix[PATH_MAX], tmp[PATH_MAX];
818 const char * nosh_prefix = "--file-prefix=noshconf";
819 FILE * hugedir_handle = NULL;
820 char line[PATH_MAX] = {0};
821 unsigned i, isempty = 1;
822 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
823 printf("Error - unable to get current prefix!\n");
826 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
829 * get first valid hugepage path
832 /* get hugetlbfs mountpoints from /proc/mounts */
833 hugedir_handle = fopen("/proc/mounts", "r");
835 if (hugedir_handle == NULL) {
836 printf("Error opening /proc/mounts!\n");
840 /* read /proc/mounts */
841 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
843 /* find first valid hugepath */
844 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
848 fclose(hugedir_handle);
850 /* check if path is not empty */
851 for (i = 0; i < sizeof(hugepath); i++)
852 if (hugepath[i] != '\0')
856 printf("No mounted hugepage dir found!\n");
862 /* check that some general flags don't prevent things from working.
863 * All cases, apart from the first, app should run.
864 * No further testing of output done.
866 /* sanity check - failure with invalid option */
867 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
870 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
872 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
873 /* With valid --syslog */
874 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
875 "--syslog", "syslog"};
876 /* With empty --syslog (should fail) */
877 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
878 /* With invalid --syslog */
879 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
880 /* With no-sh-conf, also use no-huge to ensure this test runs on BSD */
881 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
882 no_shconf, nosh_prefix, no_huge};
884 /* With --huge-dir */
885 const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
886 "--file-prefix=hugedir", "--huge-dir", hugepath};
887 /* With empty --huge-dir (should fail) */
888 const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
889 "--file-prefix=hugedir", "--huge-dir"};
890 /* With invalid --huge-dir */
891 const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
892 "--file-prefix=hugedir", "--huge-dir", "invalid"};
893 /* Secondary process with invalid --huge-dir (should run as flag has no
894 * effect on secondary processes) */
895 const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
897 /* try running with base-virtaddr param */
898 const char *argv11[] = {prgname, "--file-prefix=virtaddr",
899 "-c", "1", "-n", "2", "--base-virtaddr=0x12345678"};
901 /* try running with --vfio-intr INTx flag */
902 const char *argv12[] = {prgname, "--file-prefix=intr",
903 "-c", "1", "-n", "2", "--vfio-intr=legacy"};
905 /* try running with --vfio-intr MSI flag */
906 const char *argv13[] = {prgname, "--file-prefix=intr",
907 "-c", "1", "-n", "2", "--vfio-intr=msi"};
909 /* try running with --vfio-intr MSI-X flag */
910 const char *argv14[] = {prgname, "--file-prefix=intr",
911 "-c", "1", "-n", "2", "--vfio-intr=msix"};
913 /* try running with --vfio-intr invalid flag */
914 const char *argv15[] = {prgname, "--file-prefix=intr",
915 "-c", "1", "-n", "2", "--vfio-intr=invalid"};
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_BSDAPP
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");
997 test_file_prefix(void)
1000 * 1. check if current process hugefiles are locked
1001 * 2. try to run secondary process without a corresponding primary process
1002 * (while failing to run, it will also remove any unused hugepage files)
1003 * 3. check if current process hugefiles are still in place and are locked
1004 * 4. run a primary process with memtest1 prefix
1005 * 5. check if memtest1 hugefiles are created
1006 * 6. run a primary process with memtest2 prefix
1007 * 7. check that only memtest2 hugefiles are present in the hugedir
1010 #ifdef RTE_EXEC_ENV_BSDAPP
1014 /* this should fail unless the test itself is run with "memtest" prefix */
1015 const char *argv0[] = {prgname, mp_flag, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
1016 "--file-prefix=" memtest };
1018 /* primary process with memtest1 */
1019 const char *argv1[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
1020 "--file-prefix=" memtest1 };
1022 /* primary process with memtest2 */
1023 const char *argv2[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
1024 "--file-prefix=" memtest2 };
1027 if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
1028 printf("Error - unable to get current prefix!\n");
1032 /* check if files for current prefix are present */
1033 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1034 printf("Error - hugepage files for %s were not created!\n", prefix);
1038 /* checks if files for current prefix are locked */
1039 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1040 printf("Error - hugepages for current process aren't locked!\n");
1044 /* check if files for secondary process are present */
1045 if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
1046 /* check if they are not locked */
1047 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
1048 printf("Error - hugepages for current process are locked!\n");
1051 /* they aren't locked, delete them */
1053 if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
1054 printf("Error - deleting hugepages failed!\n");
1060 if (launch_proc(argv0) == 0) {
1061 printf("Error - secondary process ran ok without primary process\n");
1065 /* check if files for current prefix are present */
1066 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1067 printf("Error - hugepage files for %s were not created!\n", prefix);
1071 /* checks if files for current prefix are locked */
1072 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1073 printf("Error - hugepages for current process aren't locked!\n");
1077 if (launch_proc(argv1) != 0) {
1078 printf("Error - failed to run with --file-prefix=%s\n", memtest);
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", memtest1);
1088 if (launch_proc(argv2) != 0) {
1089 printf("Error - failed to run with --file-prefix=%s\n", memtest2);
1093 /* check if hugefiles for memtest2 are present */
1094 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
1095 printf("Error - hugepage files for %s were not created!\n", memtest2);
1099 /* check if hugefiles for memtest1 are present */
1100 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1101 printf("Error - hugepage files for %s were not deleted!\n", memtest1);
1109 * Tests for correct handling of -m and --socket-mem flags
1112 test_memory_flags(void)
1114 #ifdef RTE_EXEC_ENV_BSDAPP
1115 /* BSD target doesn't support prefixes at this point */
1116 const char * prefix = "";
1118 char prefix[PATH_MAX], tmp[PATH_MAX];
1119 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
1120 printf("Error - unable to get current prefix!\n");
1123 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
1126 /* valid -m flag and mp flag */
1127 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "10",
1128 "-n", "2", "-m", DEFAULT_MEM_SIZE};
1131 const char *argv1[] = {prgname, "-c", "10", "-n", "2",
1132 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE};
1134 /* invalid (zero) --socket-mem flag */
1135 const char *argv2[] = {prgname, "-c", "10", "-n", "2",
1136 "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
1138 /* invalid (incomplete) --socket-mem flag */
1139 const char *argv3[] = {prgname, "-c", "10", "-n", "2",
1140 "--file-prefix=" memtest, "--socket-mem=2,2,"};
1142 /* invalid (mixed with invalid data) --socket-mem flag */
1143 const char *argv4[] = {prgname, "-c", "10", "-n", "2",
1144 "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
1146 /* invalid (with numeric value as last character) --socket-mem flag */
1147 const char *argv5[] = {prgname, "-c", "10", "-n", "2",
1148 "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
1150 /* invalid (with empty socket) --socket-mem flag */
1151 const char *argv6[] = {prgname, "-c", "10", "-n", "2",
1152 "--file-prefix=" memtest, "--socket-mem=2,,2"};
1154 /* invalid (null) --socket-mem flag */
1155 const char *argv7[] = {prgname, "-c", "10", "-n", "2",
1156 "--file-prefix=" memtest, "--socket-mem="};
1158 /* valid --socket-mem specified together with -m flag */
1159 const char *argv8[] = {prgname, "-c", "10", "-n", "2",
1160 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE, "--socket-mem=2,2"};
1162 /* construct an invalid socket mask with 2 megs on each socket plus
1163 * extra 2 megs on socket that doesn't exist on current system */
1164 char invalid_socket_mem[SOCKET_MEM_STRLEN];
1165 char buf[SOCKET_MEM_STRLEN]; /* to avoid copying string onto itself */
1167 #ifdef RTE_EXEC_ENV_BSDAPP
1168 int i, num_sockets = 1;
1170 int i, num_sockets = RTE_MIN(get_number_of_sockets(),
1171 RTE_MAX_NUMA_NODES);
1174 if (num_sockets <= 0) {
1175 printf("Error - cannot get number of sockets!\n");
1179 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
1181 /* add one extra socket */
1182 for (i = 0; i < num_sockets + 1; i++) {
1183 snprintf(buf, sizeof(buf), "%s%s", invalid_socket_mem, DEFAULT_MEM_SIZE);
1184 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1186 if (num_sockets + 1 - i > 1) {
1187 snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
1188 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1192 /* construct a valid socket mask with 2 megs on each existing socket */
1193 char valid_socket_mem[SOCKET_MEM_STRLEN];
1195 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
1197 /* add one extra socket */
1198 for (i = 0; i < num_sockets; i++) {
1199 snprintf(buf, sizeof(buf), "%s%s", valid_socket_mem, DEFAULT_MEM_SIZE);
1200 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1202 if (num_sockets - i > 1) {
1203 snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
1204 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1208 /* invalid --socket-mem flag (with extra socket) */
1209 const char *argv9[] = {prgname, "-c", "10", "-n", "2",
1210 "--file-prefix=" memtest, invalid_socket_mem};
1212 /* valid --socket-mem flag */
1213 const char *argv10[] = {prgname, "-c", "10", "-n", "2",
1214 "--file-prefix=" memtest, valid_socket_mem};
1216 if (launch_proc(argv0) != 0) {
1217 printf("Error - secondary process failed with valid -m flag !\n");
1221 #ifdef RTE_EXEC_ENV_BSDAPP
1222 /* no other tests are applicable to BSD */
1226 if (launch_proc(argv1) != 0) {
1227 printf("Error - process failed with valid -m flag!\n");
1230 if (launch_proc(argv2) == 0) {
1231 printf("Error - process run ok with invalid (zero) --socket-mem!\n");
1235 if (launch_proc(argv3) == 0) {
1236 printf("Error - process run ok with invalid "
1237 "(incomplete) --socket-mem!\n");
1241 if (launch_proc(argv4) == 0) {
1242 printf("Error - process run ok with invalid "
1243 "(mixed with invalid input) --socket-mem!\n");
1247 if (launch_proc(argv5) == 0) {
1248 printf("Error - process run ok with invalid "
1249 "(mixed with invalid input with a numeric value as "
1250 "last character) --socket-mem!\n");
1254 if (launch_proc(argv6) == 0) {
1255 printf("Error - process run ok with invalid "
1256 "(with empty socket) --socket-mem!\n");
1260 if (launch_proc(argv7) == 0) {
1261 printf("Error - process run ok with invalid (null) --socket-mem!\n");
1265 if (launch_proc(argv8) == 0) {
1266 printf("Error - process run ok with --socket-mem and -m specified!\n");
1270 if (launch_proc(argv9) == 0) {
1271 printf("Error - process run ok with extra socket in --socket-mem!\n");
1275 if (launch_proc(argv10) != 0) {
1276 printf("Error - process failed with valid --socket-mem!\n");
1284 test_eal_flags(void)
1288 ret = test_missing_c_flag();
1290 printf("Error in test_missing_c_flag()\n");
1294 ret = test_master_lcore_flag();
1296 printf("Error in test_master_lcore_flag()\n");
1300 ret = test_invalid_n_flag();
1302 printf("Error in test_invalid_n_flag()\n");
1306 ret = test_no_hpet_flag();
1308 printf("Error in test_no_hpet_flag()\n");
1312 ret = test_no_huge_flag();
1314 printf("Error in test_no_huge_flag()\n");
1318 ret = test_whitelist_flag();
1320 printf("Error in test_invalid_whitelist_flag()\n");
1324 ret = test_invalid_b_flag();
1326 printf("Error in test_invalid_b_flag()\n");
1330 #ifdef RTE_LIBRTE_PMD_RING
1331 ret = test_invalid_vdev_flag();
1333 printf("Error in test_invalid_vdev_flag()\n");
1337 ret = test_invalid_r_flag();
1339 printf("Error in test_invalid_r_flag()\n");
1343 ret = test_memory_flags();
1345 printf("Error in test_memory_flags()\n");
1349 ret = test_file_prefix();
1351 printf("Error in test_file_prefix()\n");
1355 ret = test_misc_flags();
1357 printf("Error in test_misc_flags()");
1364 REGISTER_TEST_COMMAND(eal_flags_autotest, test_eal_flags);