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 * 10)
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, "-n", "1",
408 "-c", "1", vdev, "eth_dummy"};
410 /* Test with valid vdev option */
411 const char *vdevval1[] = {prgname, prefix, "-n", "1",
412 "-c", "1", vdev, "net_ring0"};
414 const char *vdevval2[] = {prgname, prefix, "-n", "1",
415 "-c", "1", vdev, "net_ring0,args=test"};
417 const char *vdevval3[] = {prgname, prefix, "-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 */
881 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
882 no_shconf, nosh_prefix };
884 #ifdef RTE_EXEC_ENV_BSDAPP
887 /* With --huge-dir */
888 const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
889 "--file-prefix=hugedir", "--huge-dir", hugepath};
890 /* With empty --huge-dir (should fail) */
891 const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
892 "--file-prefix=hugedir", "--huge-dir"};
893 /* With invalid --huge-dir */
894 const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
895 "--file-prefix=hugedir", "--huge-dir", "invalid"};
896 /* Secondary process with invalid --huge-dir (should run as flag has no
897 * effect on secondary processes) */
898 const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
900 /* try running with base-virtaddr param */
901 const char *argv11[] = {prgname, "--file-prefix=virtaddr",
902 "-c", "1", "-n", "2", "--base-virtaddr=0x12345678"};
904 /* try running with --vfio-intr INTx flag */
905 const char *argv12[] = {prgname, "--file-prefix=intr",
906 "-c", "1", "-n", "2", "--vfio-intr=legacy"};
908 /* try running with --vfio-intr MSI flag */
909 const char *argv13[] = {prgname, "--file-prefix=intr",
910 "-c", "1", "-n", "2", "--vfio-intr=msi"};
912 /* try running with --vfio-intr MSI-X flag */
913 const char *argv14[] = {prgname, "--file-prefix=intr",
914 "-c", "1", "-n", "2", "--vfio-intr=msix"};
916 /* try running with --vfio-intr invalid flag */
917 const char *argv15[] = {prgname, "--file-prefix=intr",
918 "-c", "1", "-n", "2", "--vfio-intr=invalid"};
921 if (launch_proc(argv0) == 0) {
922 printf("Error - process ran ok with invalid flag\n");
925 if (launch_proc(argv1) != 0) {
926 printf("Error - process did not run ok with --no-pci flag\n");
929 if (launch_proc(argv2) != 0) {
930 printf("Error - process did not run ok with -v flag\n");
933 if (launch_proc(argv3) != 0) {
934 printf("Error - process did not run ok with --syslog flag\n");
937 if (launch_proc(argv4) == 0) {
938 printf("Error - process run ok with empty --syslog flag\n");
941 if (launch_proc(argv5) == 0) {
942 printf("Error - process run ok with invalid --syslog flag\n");
945 if (launch_proc(argv6) != 0) {
946 printf("Error - process did not run ok with --no-shconf flag\n");
949 #ifdef RTE_EXEC_ENV_BSDAPP
952 if (launch_proc(argv7) != 0) {
953 printf("Error - process did not run ok with --huge-dir flag\n");
956 if (launch_proc(argv8) == 0) {
957 printf("Error - process run ok with empty --huge-dir flag\n");
960 if (launch_proc(argv9) == 0) {
961 printf("Error - process run ok with invalid --huge-dir flag\n");
964 if (launch_proc(argv10) != 0) {
965 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
968 if (launch_proc(argv11) != 0) {
969 printf("Error - process did not run ok with --base-virtaddr parameter\n");
972 if (launch_proc(argv12) != 0) {
973 printf("Error - process did not run ok with "
974 "--vfio-intr INTx parameter\n");
977 if (launch_proc(argv13) != 0) {
978 printf("Error - process did not run ok with "
979 "--vfio-intr MSI parameter\n");
982 if (launch_proc(argv14) != 0) {
983 printf("Error - process did not run ok with "
984 "--vfio-intr MSI-X parameter\n");
987 if (launch_proc(argv15) == 0) {
988 printf("Error - process run ok with "
989 "--vfio-intr invalid parameter\n");
996 test_file_prefix(void)
999 * 1. check if current process hugefiles are locked
1000 * 2. try to run secondary process without a corresponding primary process
1001 * (while failing to run, it will also remove any unused hugepage files)
1002 * 3. check if current process hugefiles are still in place and are locked
1003 * 4. run a primary process with memtest1 prefix
1004 * 5. check if memtest1 hugefiles are created
1005 * 6. run a primary process with memtest2 prefix
1006 * 7. check that only memtest2 hugefiles are present in the hugedir
1009 #ifdef RTE_EXEC_ENV_BSDAPP
1013 /* this should fail unless the test itself is run with "memtest" prefix */
1014 const char *argv0[] = {prgname, mp_flag, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
1015 "--file-prefix=" memtest };
1017 /* primary process with memtest1 */
1018 const char *argv1[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
1019 "--file-prefix=" memtest1 };
1021 /* primary process with memtest2 */
1022 const char *argv2[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
1023 "--file-prefix=" memtest2 };
1026 if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
1027 printf("Error - unable to get current prefix!\n");
1031 /* check if files for current prefix are present */
1032 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1033 printf("Error - hugepage files for %s were not created!\n", prefix);
1037 /* checks if files for current prefix are locked */
1038 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1039 printf("Error - hugepages for current process aren't locked!\n");
1043 /* check if files for secondary process are present */
1044 if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
1045 /* check if they are not locked */
1046 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
1047 printf("Error - hugepages for current process are locked!\n");
1050 /* they aren't locked, delete them */
1052 if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
1053 printf("Error - deleting hugepages failed!\n");
1059 if (launch_proc(argv0) == 0) {
1060 printf("Error - secondary process ran ok without primary process\n");
1064 /* check if files for current prefix are present */
1065 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1066 printf("Error - hugepage files for %s were not created!\n", prefix);
1070 /* checks if files for current prefix are locked */
1071 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1072 printf("Error - hugepages for current process aren't locked!\n");
1076 if (launch_proc(argv1) != 0) {
1077 printf("Error - failed to run with --file-prefix=%s\n", memtest);
1081 /* check if memtest1_map0 is present */
1082 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
1083 printf("Error - hugepage files for %s were not created!\n", memtest1);
1087 if (launch_proc(argv2) != 0) {
1088 printf("Error - failed to run with --file-prefix=%s\n", memtest2);
1092 /* check if hugefiles for memtest2 are present */
1093 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
1094 printf("Error - hugepage files for %s were not created!\n", memtest2);
1098 /* check if hugefiles for memtest1 are present */
1099 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1100 printf("Error - hugepage files for %s were not deleted!\n", memtest1);
1108 * Tests for correct handling of -m and --socket-mem flags
1111 test_memory_flags(void)
1113 #ifdef RTE_EXEC_ENV_BSDAPP
1114 /* BSD target doesn't support prefixes at this point */
1115 const char * prefix = "";
1117 char prefix[PATH_MAX], tmp[PATH_MAX];
1118 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
1119 printf("Error - unable to get current prefix!\n");
1122 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
1125 /* valid -m flag and mp flag */
1126 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "10",
1127 "-n", "2", "-m", DEFAULT_MEM_SIZE};
1130 const char *argv1[] = {prgname, "-c", "10", "-n", "2",
1131 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE};
1133 /* invalid (zero) --socket-mem flag */
1134 const char *argv2[] = {prgname, "-c", "10", "-n", "2",
1135 "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
1137 /* invalid (incomplete) --socket-mem flag */
1138 const char *argv3[] = {prgname, "-c", "10", "-n", "2",
1139 "--file-prefix=" memtest, "--socket-mem=2,2,"};
1141 /* invalid (mixed with invalid data) --socket-mem flag */
1142 const char *argv4[] = {prgname, "-c", "10", "-n", "2",
1143 "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
1145 /* invalid (with numeric value as last character) --socket-mem flag */
1146 const char *argv5[] = {prgname, "-c", "10", "-n", "2",
1147 "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
1149 /* invalid (with empty socket) --socket-mem flag */
1150 const char *argv6[] = {prgname, "-c", "10", "-n", "2",
1151 "--file-prefix=" memtest, "--socket-mem=2,,2"};
1153 /* invalid (null) --socket-mem flag */
1154 const char *argv7[] = {prgname, "-c", "10", "-n", "2",
1155 "--file-prefix=" memtest, "--socket-mem="};
1157 /* valid --socket-mem specified together with -m flag */
1158 const char *argv8[] = {prgname, "-c", "10", "-n", "2",
1159 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE, "--socket-mem=2,2"};
1161 /* construct an invalid socket mask with 2 megs on each socket plus
1162 * extra 2 megs on socket that doesn't exist on current system */
1163 char invalid_socket_mem[SOCKET_MEM_STRLEN];
1164 char buf[SOCKET_MEM_STRLEN]; /* to avoid copying string onto itself */
1166 #ifdef RTE_EXEC_ENV_BSDAPP
1167 int i, num_sockets = 1;
1169 int i, num_sockets = get_number_of_sockets();
1172 if (num_sockets <= 0 || num_sockets > RTE_MAX_NUMA_NODES) {
1173 printf("Error - cannot get number of sockets!\n");
1177 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
1179 /* add one extra socket */
1180 for (i = 0; i < num_sockets + 1; i++) {
1181 snprintf(buf, sizeof(buf), "%s%s", invalid_socket_mem, DEFAULT_MEM_SIZE);
1182 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1184 if (num_sockets + 1 - i > 1) {
1185 snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
1186 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1190 /* construct a valid socket mask with 2 megs on each existing socket */
1191 char valid_socket_mem[SOCKET_MEM_STRLEN];
1193 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
1195 /* add one extra socket */
1196 for (i = 0; i < num_sockets; i++) {
1197 snprintf(buf, sizeof(buf), "%s%s", valid_socket_mem, DEFAULT_MEM_SIZE);
1198 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1200 if (num_sockets - i > 1) {
1201 snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
1202 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1206 /* invalid --socket-mem flag (with extra socket) */
1207 const char *argv9[] = {prgname, "-c", "10", "-n", "2",
1208 "--file-prefix=" memtest, invalid_socket_mem};
1210 /* valid --socket-mem flag */
1211 const char *argv10[] = {prgname, "-c", "10", "-n", "2",
1212 "--file-prefix=" memtest, valid_socket_mem};
1214 if (launch_proc(argv0) != 0) {
1215 printf("Error - secondary process failed with valid -m flag !\n");
1219 #ifdef RTE_EXEC_ENV_BSDAPP
1220 /* no other tests are applicable to BSD */
1224 if (launch_proc(argv1) != 0) {
1225 printf("Error - process failed with valid -m flag!\n");
1228 if (launch_proc(argv2) == 0) {
1229 printf("Error - process run ok with invalid (zero) --socket-mem!\n");
1233 if (launch_proc(argv3) == 0) {
1234 printf("Error - process run ok with invalid "
1235 "(incomplete) --socket-mem!\n");
1239 if (launch_proc(argv4) == 0) {
1240 printf("Error - process run ok with invalid "
1241 "(mixed with invalid input) --socket-mem!\n");
1245 if (launch_proc(argv5) == 0) {
1246 printf("Error - process run ok with invalid "
1247 "(mixed with invalid input with a numeric value as "
1248 "last character) --socket-mem!\n");
1252 if (launch_proc(argv6) == 0) {
1253 printf("Error - process run ok with invalid "
1254 "(with empty socket) --socket-mem!\n");
1258 if (launch_proc(argv7) == 0) {
1259 printf("Error - process run ok with invalid (null) --socket-mem!\n");
1263 if (launch_proc(argv8) == 0) {
1264 printf("Error - process run ok with --socket-mem and -m specified!\n");
1268 if (launch_proc(argv9) == 0) {
1269 printf("Error - process run ok with extra socket in --socket-mem!\n");
1273 if (launch_proc(argv10) != 0) {
1274 printf("Error - process failed with valid --socket-mem!\n");
1282 test_eal_flags(void)
1286 ret = test_missing_c_flag();
1288 printf("Error in test_missing_c_flag()\n");
1292 ret = test_master_lcore_flag();
1294 printf("Error in test_master_lcore_flag()\n");
1298 ret = test_invalid_n_flag();
1300 printf("Error in test_invalid_n_flag()\n");
1304 ret = test_no_hpet_flag();
1306 printf("Error in test_no_hpet_flag()\n");
1310 ret = test_no_huge_flag();
1312 printf("Error in test_no_huge_flag()\n");
1316 ret = test_whitelist_flag();
1318 printf("Error in test_invalid_whitelist_flag()\n");
1322 ret = test_invalid_b_flag();
1324 printf("Error in test_invalid_b_flag()\n");
1328 #ifdef RTE_LIBRTE_PMD_RING
1329 ret = test_invalid_vdev_flag();
1331 printf("Error in test_invalid_vdev_flag()\n");
1335 ret = test_invalid_r_flag();
1337 printf("Error in test_invalid_r_flag()\n");
1341 ret = test_memory_flags();
1343 printf("Error in test_memory_flags()\n");
1347 ret = test_file_prefix();
1349 printf("Error in test_file_prefix()\n");
1353 ret = test_misc_flags();
1355 printf("Error in test_misc_flags()");
1362 REGISTER_TEST_COMMAND(eal_flags_autotest, test_eal_flags);