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.
50 #include <rte_debug.h>
51 #include <rte_string_fns.h>
55 #ifdef RTE_LIBRTE_XEN_DOM0
56 #define DEFAULT_MEM_SIZE "30"
58 #define DEFAULT_MEM_SIZE "18"
60 #define mp_flag "--proc-type=secondary"
61 #define no_hpet "--no-hpet"
62 #define no_huge "--no-huge"
63 #define no_shconf "--no-shconf"
64 #define pci_whitelist "--pci-whitelist"
66 #define memtest "memtest"
67 #define memtest1 "memtest1"
68 #define memtest2 "memtest2"
69 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 10)
70 #define launch_proc(ARGV) process_dup(ARGV, \
71 sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
73 enum hugepage_action {
74 HUGEPAGE_CHECK_EXISTS = 0,
75 HUGEPAGE_CHECK_LOCKED,
80 /* if string contains a hugepage path */
82 get_hugepage_path(char * src, int src_len, char * dst, int dst_len)
85 char *tokens[NUM_TOKENS];
87 /* if we couldn't properly split the string */
88 if (rte_strsplit(src, src_len, tokens, NUM_TOKENS, ' ') < NUM_TOKENS)
91 if (strncmp(tokens[2], "hugetlbfs", sizeof("hugetlbfs")) == 0) {
92 snprintf(dst, dst_len, "%s", tokens[1]);
99 * Cycles through hugepage directories and looks for hugepage
100 * files associated with a given prefix. Depending on value of
101 * action, the hugepages are checked if they exist, checked if
102 * they can be locked, or are simply deleted.
104 * Returns 1 if it finds at least one hugepage matching the action
105 * Returns 0 if no matching hugepages were found
106 * Returns -1 if it encounters an error
109 process_hugefiles(const char * prefix, enum hugepage_action action)
111 FILE * hugedir_handle = NULL;
112 DIR * hugepage_dir = NULL;
113 struct dirent *dirent = NULL;
115 char hugefile_prefix[PATH_MAX] = {0};
116 char hugedir[PATH_MAX] = {0};
117 char line[PATH_MAX] = {0};
119 int fd, lck_result, result = 0;
121 const int prefix_len = snprintf(hugefile_prefix,
122 sizeof(hugefile_prefix), "%smap_", prefix);
123 if (prefix_len <= 0 || prefix_len >= (int)sizeof(hugefile_prefix)
124 || prefix_len >= (int)sizeof(dirent->d_name)) {
125 printf("Error creating hugefile filename prefix\n");
129 /* get hugetlbfs mountpoints from /proc/mounts */
130 hugedir_handle = fopen("/proc/mounts", "r");
132 if (hugedir_handle == NULL) {
133 printf("Error parsing /proc/mounts!\n");
137 /* read and parse script output */
138 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
140 /* check if we have a hugepage filesystem path */
141 if (!get_hugepage_path(line, sizeof(line), hugedir, sizeof(hugedir)))
144 /* check if directory exists */
145 if ((hugepage_dir = opendir(hugedir)) == NULL) {
146 fclose(hugedir_handle);
147 printf("Error reading %s: %s\n", hugedir, strerror(errno));
151 while ((dirent = readdir(hugepage_dir)) != NULL) {
152 if (memcmp(dirent->d_name, hugefile_prefix, prefix_len) != 0)
156 case HUGEPAGE_CHECK_EXISTS:
158 /* file exists, return */
163 case HUGEPAGE_DELETE:
165 char file_path[PATH_MAX] = {0};
167 snprintf(file_path, sizeof(file_path),
168 "%s/%s", hugedir, dirent->d_name);
171 if (remove(file_path) < 0) {
172 printf("Error deleting %s - %s!\n",
173 dirent->d_name, strerror(errno));
174 closedir(hugepage_dir);
181 case HUGEPAGE_CHECK_LOCKED:
183 /* try and lock the file */
184 fd = openat(dirfd(hugepage_dir), dirent->d_name, O_RDONLY);
186 /* this shouldn't happen */
188 printf("Error opening %s - %s!\n",
189 dirent->d_name, strerror(errno));
190 closedir(hugepage_dir);
195 /* non-blocking lock */
196 lck_result = flock(fd, LOCK_EX | LOCK_NB);
198 /* if lock succeeds, there's something wrong */
199 if (lck_result != -1) {
202 /* unlock the resulting lock */
205 closedir(hugepage_dir);
212 /* shouldn't happen */
217 } /* read hugepage directory */
218 closedir(hugepage_dir);
219 } /* read /proc/mounts */
221 fclose(hugedir_handle);
225 #ifdef RTE_EXEC_ENV_LINUXAPP
227 * count the number of "node*" files in /sys/devices/system/node/
230 get_number_of_sockets(void)
232 struct dirent *dirent = NULL;
233 const char * nodedir = "/sys/devices/system/node/";
237 /* check if directory exists */
238 if ((dir = opendir(nodedir)) == NULL) {
239 /* if errno==ENOENT this means we don't have NUMA support */
240 if (errno == ENOENT) {
241 printf("No NUMA nodes detected: assuming 1 available socket\n");
244 printf("Error opening %s: %s\n", nodedir, strerror(errno));
248 while ((dirent = readdir(dir)) != NULL)
249 if (strncmp(dirent->d_name, "node", sizeof("node") - 1) == 0)
258 get_current_prefix(char * prefix, int size)
260 char path[PATH_MAX] = {0};
261 char buf[PATH_MAX] = {0};
263 /* get file for config (fd is always 3) */
264 snprintf(path, sizeof(path), "/proc/self/fd/%d", 3);
266 /* return NULL on error */
267 if (readlink(path, buf, sizeof(buf)) == -1)
270 /* get the basename */
271 snprintf(buf, sizeof(buf), "%s", basename(buf));
273 /* copy string all the way from second char up to start of _config */
274 snprintf(prefix, size, "%.*s",
275 (int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
282 * Test that the app doesn't run with invalid whitelist option.
283 * Final tests ensures it does run with valid options as sanity check (one
284 * test for with Domain+BDF, second for just with BDF)
287 test_whitelist_flag(void)
290 #ifdef RTE_EXEC_ENV_BSDAPP
291 /* BSD target doesn't support prefixes at this point */
292 const char * prefix = "";
294 char prefix[PATH_MAX], tmp[PATH_MAX];
295 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
296 printf("Error - unable to get current prefix!\n");
299 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
302 const char *wlinval[][11] = {
303 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
304 pci_whitelist, "error", "", ""},
305 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
306 pci_whitelist, "0:0:0", "", ""},
307 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
308 pci_whitelist, "0:error:0.1", "", ""},
309 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
310 pci_whitelist, "0:0:0.1error", "", ""},
311 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
312 pci_whitelist, "error0:0:0.1", "", ""},
313 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
314 pci_whitelist, "0:0:0.1.2", "", ""},
316 /* Test with valid whitelist option */
317 const char *wlval1[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
318 pci_whitelist, "00FF:09:0B.3"};
319 const char *wlval2[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
320 pci_whitelist, "09:0B.3", pci_whitelist, "0a:0b.1"};
321 const char *wlval3[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
322 pci_whitelist, "09:0B.3,type=test",
323 pci_whitelist, "08:00.1,type=normal",
326 for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
327 if (launch_proc(wlinval[i]) == 0) {
328 printf("Error - process did run ok with invalid "
329 "whitelist parameter\n");
333 if (launch_proc(wlval1) != 0 ) {
334 printf("Error - process did not run ok with valid whitelist\n");
337 if (launch_proc(wlval2) != 0 ) {
338 printf("Error - process did not run ok with valid whitelist value set\n");
341 if (launch_proc(wlval3) != 0 ) {
342 printf("Error - process did not run ok with valid whitelist + args\n");
350 * Test that the app doesn't run with invalid blacklist option.
351 * Final test ensures it does run with valid options as sanity check
354 test_invalid_b_flag(void)
356 #ifdef RTE_EXEC_ENV_BSDAPP
357 /* BSD target doesn't support prefixes at this point */
358 const char * prefix = "";
360 char prefix[PATH_MAX], tmp[PATH_MAX];
361 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
362 printf("Error - unable to get current prefix!\n");
365 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
368 const char *blinval[][9] = {
369 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error"},
370 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0"},
371 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:error:0.1"},
372 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1error"},
373 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error0:0:0.1"},
374 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1.2"},
376 /* Test with valid blacklist option */
377 const char *blval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
381 for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
382 if (launch_proc(blinval[i]) == 0) {
383 printf("Error - process did run ok with invalid "
384 "blacklist parameter\n");
388 if (launch_proc(blval) != 0) {
389 printf("Error - process did not run ok with valid blacklist value\n");
396 * Test that the app doesn't run with invalid vdev option.
397 * Final test ensures it does run with valid options as sanity check
399 #ifdef RTE_LIBRTE_PMD_RING
401 test_invalid_vdev_flag(void)
403 #ifdef RTE_EXEC_ENV_BSDAPP
404 /* BSD target doesn't support prefixes at this point, and we also need to
405 * run another primary process here */
406 const char * prefix = no_shconf;
408 const char * prefix = "--file-prefix=vdev";
411 /* Test with invalid vdev option */
412 const char *vdevinval[] = {prgname, prefix, "-n", "1",
413 "-c", "1", vdev, "eth_dummy"};
415 /* Test with valid vdev option */
416 const char *vdevval1[] = {prgname, prefix, "-n", "1",
417 "-c", "1", vdev, "eth_ring0"};
419 const char *vdevval2[] = {prgname, prefix, "-n", "1",
420 "-c", "1", vdev, "eth_ring0,args=test"};
422 const char *vdevval3[] = {prgname, prefix, "-n", "1",
423 "-c", "1", vdev, "eth_ring0,nodeaction=r1:0:CREATE"};
425 if (launch_proc(vdevinval) == 0) {
426 printf("Error - process did run ok with invalid "
431 if (launch_proc(vdevval1) != 0) {
432 printf("Error - process did not run ok with valid vdev value\n");
436 if (launch_proc(vdevval2) != 0) {
437 printf("Error - process did not run ok with valid vdev value,"
438 "with dummy args\n");
442 if (launch_proc(vdevval3) != 0) {
443 printf("Error - process did not run ok with valid vdev value,"
444 "with valid args\n");
452 * Test that the app doesn't run with invalid -r option.
455 test_invalid_r_flag(void)
457 #ifdef RTE_EXEC_ENV_BSDAPP
458 /* BSD target doesn't support prefixes at this point */
459 const char * prefix = "";
461 char prefix[PATH_MAX], tmp[PATH_MAX];
462 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
463 printf("Error - unable to get current prefix!\n");
466 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
469 const char *rinval[][9] = {
470 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "error"},
471 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "0"},
472 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "-1"},
473 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "17"},
475 /* Test with valid blacklist option */
476 const char *rval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
480 for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
481 if (launch_proc(rinval[i]) == 0) {
482 printf("Error - process did run ok with invalid "
483 "-r (rank) parameter\n");
487 if (launch_proc(rval) != 0) {
488 printf("Error - process did not run ok with valid -r (rank) value\n");
495 * Test that the app doesn't run without the coremask/corelist flags. In all cases
496 * should give an error and fail to run
499 test_missing_c_flag(void)
501 #ifdef RTE_EXEC_ENV_BSDAPP
502 /* BSD target doesn't support prefixes at this point */
503 const char * prefix = "";
505 char prefix[PATH_MAX], tmp[PATH_MAX];
506 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
507 printf("Error - unable to get current prefix!\n");
510 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
513 /* -c flag but no coremask value */
514 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "3", "-c"};
515 /* No -c, -l or --lcores flag at all */
516 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "3"};
517 /* bad coremask value */
518 const char *argv3[] = { prgname, prefix, mp_flag,
519 "-n", "3", "-c", "error" };
520 /* sanity check of tests - valid coremask value */
521 const char *argv4[] = { prgname, prefix, mp_flag,
522 "-n", "3", "-c", "1" };
523 /* -l flag but no corelist value */
524 const char *argv5[] = { prgname, prefix, mp_flag,
526 const char *argv6[] = { prgname, prefix, mp_flag,
527 "-n", "3", "-l", " " };
528 /* bad corelist values */
529 const char *argv7[] = { prgname, prefix, mp_flag,
530 "-n", "3", "-l", "error" };
531 const char *argv8[] = { prgname, prefix, mp_flag,
532 "-n", "3", "-l", "1-" };
533 const char *argv9[] = { prgname, prefix, mp_flag,
534 "-n", "3", "-l", "1," };
535 const char *argv10[] = { prgname, prefix, mp_flag,
536 "-n", "3", "-l", "1#2" };
537 /* sanity check test - valid corelist value */
538 const char *argv11[] = { prgname, prefix, mp_flag,
539 "-n", "3", "-l", "1-2,3" };
541 /* --lcores flag but no lcores value */
542 const char *argv12[] = { prgname, prefix, mp_flag,
543 "-n", "3", "--lcores" };
544 const char *argv13[] = { prgname, prefix, mp_flag,
545 "-n", "3", "--lcores", " " };
546 /* bad lcores value */
547 const char *argv14[] = { prgname, prefix, mp_flag,
548 "-n", "3", "--lcores", "1-3-5" };
549 const char *argv15[] = { prgname, prefix, mp_flag,
550 "-n", "3", "--lcores", "0-1,,2" };
551 const char *argv16[] = { prgname, prefix, mp_flag,
552 "-n", "3", "--lcores", "0-,1" };
553 const char *argv17[] = { prgname, prefix, mp_flag,
554 "-n", "3", "--lcores", "(0-,2-4)" };
555 const char *argv18[] = { prgname, prefix, mp_flag,
556 "-n", "3", "--lcores", "(-1,2)" };
557 const char *argv19[] = { prgname, prefix, mp_flag,
558 "-n", "3", "--lcores", "(2-4)@(2-4-6)" };
559 const char *argv20[] = { prgname, prefix, mp_flag,
560 "-n", "3", "--lcores", "(a,2)" };
561 const char *argv21[] = { prgname, prefix, mp_flag,
562 "-n", "3", "--lcores", "1-3@(1,3)" };
563 const char *argv22[] = { prgname, prefix, mp_flag,
564 "-n", "3", "--lcores", "3@((1,3)" };
565 const char *argv23[] = { prgname, prefix, mp_flag,
566 "-n", "3", "--lcores", "(4-7)=(1,3)" };
567 const char *argv24[] = { prgname, prefix, mp_flag,
568 "-n", "3", "--lcores", "[4-7]@(1,3)" };
569 /* sanity check of tests - valid lcores value */
570 const char *argv25[] = { prgname, prefix, mp_flag,
571 "-n", "3", "--lcores",
572 "0-1,2@(5-7),(3-5)@(0,2),(0,6),7"};
574 if (launch_proc(argv2) != 0) {
576 "process did not run ok when missing -c flag\n");
580 if (launch_proc(argv1) == 0
581 || launch_proc(argv3) == 0) {
583 "process ran without error with invalid -c flag\n");
586 if (launch_proc(argv4) != 0) {
588 "process did not run ok with valid coremask value\n");
593 if (launch_proc(argv5) == 0
594 || launch_proc(argv6) == 0
595 || launch_proc(argv7) == 0
596 || launch_proc(argv8) == 0
597 || launch_proc(argv9) == 0
598 || launch_proc(argv10) == 0) {
600 "process ran without error with invalid -l flag\n");
603 if (launch_proc(argv11) != 0) {
605 "process did not run ok with valid corelist value\n");
609 /* start --lcores tests */
610 if (launch_proc(argv12) == 0 || launch_proc(argv13) == 0 ||
611 launch_proc(argv14) == 0 || launch_proc(argv15) == 0 ||
612 launch_proc(argv16) == 0 || launch_proc(argv17) == 0 ||
613 launch_proc(argv18) == 0 || launch_proc(argv19) == 0 ||
614 launch_proc(argv20) == 0 || launch_proc(argv21) == 0 ||
615 launch_proc(argv21) == 0 || launch_proc(argv22) == 0 ||
616 launch_proc(argv23) == 0 || launch_proc(argv24) == 0) {
618 "process ran without error with invalid --lcore flag\n");
622 if (launch_proc(argv25) != 0) {
624 "process did not run ok with valid corelist value\n");
632 * Test --master-lcore option with matching coremask
635 test_master_lcore_flag(void)
637 #ifdef RTE_EXEC_ENV_BSDAPP
638 /* BSD target doesn't support prefixes at this point */
639 const char *prefix = "";
641 char prefix[PATH_MAX], tmp[PATH_MAX];
642 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
643 printf("Error - unable to get current prefix!\n");
646 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
649 /* --master-lcore flag but no value */
650 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore"};
651 /* --master-lcore flag with invalid value */
652 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "-1"};
653 const char *argv3[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "X"};
654 /* master lcore not in coremask */
655 const char *argv4[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "2"};
657 const char *argv5[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "1"};
658 /* valid value set before coremask */
659 const char *argv6[] = { prgname, prefix, mp_flag, "-n", "1", "--master-lcore", "1", "-c", "3"};
661 if (launch_proc(argv1) == 0
662 || launch_proc(argv2) == 0
663 || launch_proc(argv3) == 0
664 || launch_proc(argv4) == 0) {
665 printf("Error - process ran without error with wrong --master-lcore\n");
668 if (launch_proc(argv5) != 0
669 || launch_proc(argv6) != 0) {
670 printf("Error - process did not run ok with valid --master-lcore\n");
677 * Test that the app doesn't run with invalid -n flag option.
678 * Final test ensures it does run with valid options as sanity check
679 * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
683 test_invalid_n_flag(void)
685 #ifdef RTE_EXEC_ENV_BSDAPP
686 /* BSD target doesn't support prefixes at this point */
687 const char * prefix = "";
689 char prefix[PATH_MAX], tmp[PATH_MAX];
690 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
691 printf("Error - unable to get current prefix!\n");
694 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
697 /* -n flag but no value */
698 const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"};
699 /* bad numeric value */
700 const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" };
701 /* out-of-range value */
702 const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "9" };
703 /* sanity test - check with good value */
704 const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" };
705 /* sanity test - check with no -n flag */
706 const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"};
708 if (launch_proc(argv1) == 0
709 || launch_proc(argv2) == 0
710 || launch_proc(argv3) == 0) {
711 printf("Error - process ran without error when"
712 "invalid -n flag\n");
715 if (launch_proc(argv4) != 0) {
716 printf("Error - process did not run ok with valid num-channel value\n");
719 if (launch_proc(argv5) != 0) {
720 printf("Error - process did not run ok without -n flag\n");
728 * Test that the app runs with HPET, and without HPET
731 test_no_hpet_flag(void)
733 char prefix[PATH_MAX], tmp[PATH_MAX];
735 #ifdef RTE_EXEC_ENV_BSDAPP
738 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
739 printf("Error - unable to get current prefix!\n");
742 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
745 const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"};
746 /* Without --no-hpet */
747 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-n", "2"};
749 if (launch_proc(argv1) != 0) {
750 printf("Error - process did not run ok with --no-hpet flag\n");
753 if (launch_proc(argv2) != 0) {
754 printf("Error - process did not run ok without --no-hpet flag\n");
761 * Test that the app runs with --no-huge and doesn't run when --socket-mem are
762 * specified with --no-huge.
765 test_no_huge_flag(void)
767 #ifdef RTE_EXEC_ENV_BSDAPP
768 /* BSD target doesn't support prefixes at this point, and we also need to
769 * run another primary process here */
770 const char * prefix = no_shconf;
772 const char * prefix = "--file-prefix=nohuge";
776 const char *argv1[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2"};
777 /* With --no-huge and -m */
778 const char *argv2[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
779 "-m", DEFAULT_MEM_SIZE};
781 /* With --no-huge and --socket-mem */
782 const char *argv3[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
783 "--socket-mem=" DEFAULT_MEM_SIZE};
784 /* With --no-huge, -m and --socket-mem */
785 const char *argv4[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
786 "-m", DEFAULT_MEM_SIZE, "--socket-mem=" DEFAULT_MEM_SIZE};
787 if (launch_proc(argv1) != 0) {
788 printf("Error - process did not run ok with --no-huge flag\n");
791 if (launch_proc(argv2) != 0) {
792 printf("Error - process did not run ok with --no-huge and -m flags\n");
795 #ifdef RTE_EXEC_ENV_BSDAPP
796 /* BSD target does not support NUMA, hence no --socket-mem tests */
800 if (launch_proc(argv3) == 0) {
801 printf("Error - process run ok with --no-huge and --socket-mem "
805 if (launch_proc(argv4) == 0) {
806 printf("Error - process run ok with --no-huge, -m and "
807 "--socket-mem flags\n");
813 #ifdef RTE_LIBRTE_XEN_DOM0
815 test_dom0_misc_flags(void)
817 char prefix[PATH_MAX], tmp[PATH_MAX];
819 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
820 printf("Error - unable to get current prefix!\n");
823 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
825 /* check that some general flags don't prevent things from working.
826 * All cases, apart from the first, app should run.
827 * No futher testing of output done.
829 /* sanity check - failure with invalid option */
830 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
833 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
835 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
836 /* With valid --syslog */
837 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
838 "--syslog", "syslog"};
839 /* With empty --syslog (should fail) */
840 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
841 /* With invalid --syslog */
842 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
843 /* With no-sh-conf */
844 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "20",
845 "--no-shconf", "--file-prefix=noshconf" };
847 if (launch_proc(argv0) == 0) {
848 printf("Error - process ran ok with invalid flag\n");
851 if (launch_proc(argv1) != 0) {
852 printf("Error - process did not run ok with --no-pci flag\n");
855 if (launch_proc(argv2) != 0) {
856 printf("Error - process did not run ok with -v flag\n");
859 if (launch_proc(argv3) != 0) {
860 printf("Error - process did not run ok with --syslog flag\n");
863 if (launch_proc(argv4) == 0) {
864 printf("Error - process run ok with empty --syslog flag\n");
867 if (launch_proc(argv5) == 0) {
868 printf("Error - process run ok with invalid --syslog flag\n");
871 if (launch_proc(argv6) != 0) {
872 printf("Error - process did not run ok with --no-shconf flag\n");
880 test_misc_flags(void)
882 char hugepath[PATH_MAX] = {0};
883 #ifdef RTE_EXEC_ENV_BSDAPP
884 /* BSD target doesn't support prefixes at this point */
885 const char * prefix = "";
886 const char * nosh_prefix = "";
888 char prefix[PATH_MAX], tmp[PATH_MAX];
889 const char * nosh_prefix = "--file-prefix=noshconf";
890 FILE * hugedir_handle = NULL;
891 char line[PATH_MAX] = {0};
892 unsigned i, isempty = 1;
893 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
894 printf("Error - unable to get current prefix!\n");
897 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
900 * get first valid hugepage path
903 /* get hugetlbfs mountpoints from /proc/mounts */
904 hugedir_handle = fopen("/proc/mounts", "r");
906 if (hugedir_handle == NULL) {
907 printf("Error opening /proc/mounts!\n");
911 /* read /proc/mounts */
912 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
914 /* find first valid hugepath */
915 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
919 fclose(hugedir_handle);
921 /* check if path is not empty */
922 for (i = 0; i < sizeof(hugepath); i++)
923 if (hugepath[i] != '\0')
927 printf("No mounted hugepage dir found!\n");
933 /* check that some general flags don't prevent things from working.
934 * All cases, apart from the first, app should run.
935 * No futher testing of output done.
937 /* sanity check - failure with invalid option */
938 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
941 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
943 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
944 /* With valid --syslog */
945 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
946 "--syslog", "syslog"};
947 /* With empty --syslog (should fail) */
948 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
949 /* With invalid --syslog */
950 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
951 /* With no-sh-conf */
952 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
953 no_shconf, nosh_prefix };
955 #ifdef RTE_EXEC_ENV_BSDAPP
958 /* With --huge-dir */
959 const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
960 "--file-prefix=hugedir", "--huge-dir", hugepath};
961 /* With empty --huge-dir (should fail) */
962 const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
963 "--file-prefix=hugedir", "--huge-dir"};
964 /* With invalid --huge-dir */
965 const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
966 "--file-prefix=hugedir", "--huge-dir", "invalid"};
967 /* Secondary process with invalid --huge-dir (should run as flag has no
968 * effect on secondary processes) */
969 const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
971 /* try running with base-virtaddr param */
972 const char *argv11[] = {prgname, "--file-prefix=virtaddr",
973 "-c", "1", "-n", "2", "--base-virtaddr=0x12345678"};
975 /* try running with --vfio-intr INTx flag */
976 const char *argv12[] = {prgname, "--file-prefix=intr",
977 "-c", "1", "-n", "2", "--vfio-intr=legacy"};
979 /* try running with --vfio-intr MSI flag */
980 const char *argv13[] = {prgname, "--file-prefix=intr",
981 "-c", "1", "-n", "2", "--vfio-intr=msi"};
983 /* try running with --vfio-intr MSI-X flag */
984 const char *argv14[] = {prgname, "--file-prefix=intr",
985 "-c", "1", "-n", "2", "--vfio-intr=msix"};
987 /* try running with --vfio-intr invalid flag */
988 const char *argv15[] = {prgname, "--file-prefix=intr",
989 "-c", "1", "-n", "2", "--vfio-intr=invalid"};
992 if (launch_proc(argv0) == 0) {
993 printf("Error - process ran ok with invalid flag\n");
996 if (launch_proc(argv1) != 0) {
997 printf("Error - process did not run ok with --no-pci flag\n");
1000 if (launch_proc(argv2) != 0) {
1001 printf("Error - process did not run ok with -v flag\n");
1004 if (launch_proc(argv3) != 0) {
1005 printf("Error - process did not run ok with --syslog flag\n");
1008 if (launch_proc(argv4) == 0) {
1009 printf("Error - process run ok with empty --syslog flag\n");
1012 if (launch_proc(argv5) == 0) {
1013 printf("Error - process run ok with invalid --syslog flag\n");
1016 if (launch_proc(argv6) != 0) {
1017 printf("Error - process did not run ok with --no-shconf flag\n");
1020 #ifdef RTE_EXEC_ENV_BSDAPP
1023 if (launch_proc(argv7) != 0) {
1024 printf("Error - process did not run ok with --huge-dir flag\n");
1027 if (launch_proc(argv8) == 0) {
1028 printf("Error - process run ok with empty --huge-dir flag\n");
1031 if (launch_proc(argv9) == 0) {
1032 printf("Error - process run ok with invalid --huge-dir flag\n");
1035 if (launch_proc(argv10) != 0) {
1036 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
1039 if (launch_proc(argv11) != 0) {
1040 printf("Error - process did not run ok with --base-virtaddr parameter\n");
1043 if (launch_proc(argv12) != 0) {
1044 printf("Error - process did not run ok with "
1045 "--vfio-intr INTx parameter\n");
1048 if (launch_proc(argv13) != 0) {
1049 printf("Error - process did not run ok with "
1050 "--vfio-intr MSI parameter\n");
1053 if (launch_proc(argv14) != 0) {
1054 printf("Error - process did not run ok with "
1055 "--vfio-intr MSI-X parameter\n");
1058 if (launch_proc(argv15) == 0) {
1059 printf("Error - process run ok with "
1060 "--vfio-intr invalid parameter\n");
1068 test_file_prefix(void)
1071 * 1. check if current process hugefiles are locked
1072 * 2. try to run secondary process without a corresponding primary process
1073 * (while failing to run, it will also remove any unused hugepage files)
1074 * 3. check if current process hugefiles are still in place and are locked
1075 * 4. run a primary process with memtest1 prefix
1076 * 5. check if memtest1 hugefiles are created
1077 * 6. run a primary process with memtest2 prefix
1078 * 7. check that only memtest2 hugefiles are present in the hugedir
1081 #ifdef RTE_EXEC_ENV_BSDAPP
1085 /* this should fail unless the test itself is run with "memtest" prefix */
1086 const char *argv0[] = {prgname, mp_flag, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
1087 "--file-prefix=" memtest };
1089 /* primary process with memtest1 */
1090 const char *argv1[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
1091 "--file-prefix=" memtest1 };
1093 /* primary process with memtest2 */
1094 const char *argv2[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
1095 "--file-prefix=" memtest2 };
1098 if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
1099 printf("Error - unable to get current prefix!\n");
1102 #ifdef RTE_LIBRTE_XEN_DOM0
1106 /* check if files for current prefix are present */
1107 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1108 printf("Error - hugepage files for %s were not created!\n", prefix);
1112 /* checks if files for current prefix are locked */
1113 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1114 printf("Error - hugepages for current process aren't locked!\n");
1118 /* check if files for secondary process are present */
1119 if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
1120 /* check if they are not locked */
1121 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
1122 printf("Error - hugepages for current process are locked!\n");
1125 /* they aren't locked, delete them */
1127 if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
1128 printf("Error - deleting hugepages failed!\n");
1134 if (launch_proc(argv0) == 0) {
1135 printf("Error - secondary process ran ok without primary process\n");
1139 /* check if files for current prefix are present */
1140 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1141 printf("Error - hugepage files for %s were not created!\n", prefix);
1145 /* checks if files for current prefix are locked */
1146 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1147 printf("Error - hugepages for current process aren't locked!\n");
1151 if (launch_proc(argv1) != 0) {
1152 printf("Error - failed to run with --file-prefix=%s\n", memtest);
1156 /* check if memtest1_map0 is present */
1157 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
1158 printf("Error - hugepage files for %s were not created!\n", memtest1);
1162 if (launch_proc(argv2) != 0) {
1163 printf("Error - failed to run with --file-prefix=%s\n", memtest2);
1167 /* check if hugefiles for memtest2 are present */
1168 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
1169 printf("Error - hugepage files for %s were not created!\n", memtest2);
1173 /* check if hugefiles for memtest1 are present */
1174 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1175 printf("Error - hugepage files for %s were not deleted!\n", memtest1);
1183 * Tests for correct handling of -m and --socket-mem flags
1186 test_memory_flags(void)
1188 #ifdef RTE_EXEC_ENV_BSDAPP
1189 /* BSD target doesn't support prefixes at this point */
1190 const char * prefix = "";
1192 char prefix[PATH_MAX], tmp[PATH_MAX];
1193 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
1194 printf("Error - unable to get current prefix!\n");
1197 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
1200 /* valid -m flag and mp flag */
1201 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "10",
1202 "-n", "2", "-m", DEFAULT_MEM_SIZE};
1205 const char *argv1[] = {prgname, "-c", "10", "-n", "2",
1206 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE};
1208 /* invalid (zero) --socket-mem flag */
1209 const char *argv2[] = {prgname, "-c", "10", "-n", "2",
1210 "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
1212 /* invalid (incomplete) --socket-mem flag */
1213 const char *argv3[] = {prgname, "-c", "10", "-n", "2",
1214 "--file-prefix=" memtest, "--socket-mem=2,2,"};
1216 /* invalid (mixed with invalid data) --socket-mem flag */
1217 const char *argv4[] = {prgname, "-c", "10", "-n", "2",
1218 "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
1220 /* invalid (with numeric value as last character) --socket-mem flag */
1221 const char *argv5[] = {prgname, "-c", "10", "-n", "2",
1222 "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
1224 /* invalid (with empty socket) --socket-mem flag */
1225 const char *argv6[] = {prgname, "-c", "10", "-n", "2",
1226 "--file-prefix=" memtest, "--socket-mem=2,,2"};
1228 /* invalid (null) --socket-mem flag */
1229 const char *argv7[] = {prgname, "-c", "10", "-n", "2",
1230 "--file-prefix=" memtest, "--socket-mem="};
1232 /* valid --socket-mem specified together with -m flag */
1233 const char *argv8[] = {prgname, "-c", "10", "-n", "2",
1234 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE, "--socket-mem=2,2"};
1236 /* construct an invalid socket mask with 2 megs on each socket plus
1237 * extra 2 megs on socket that doesn't exist on current system */
1238 char invalid_socket_mem[SOCKET_MEM_STRLEN];
1239 char buf[SOCKET_MEM_STRLEN]; /* to avoid copying string onto itself */
1241 #ifdef RTE_EXEC_ENV_BSDAPP
1242 int i, num_sockets = 1;
1244 int i, num_sockets = get_number_of_sockets();
1247 if (num_sockets <= 0 || num_sockets > RTE_MAX_NUMA_NODES) {
1248 printf("Error - cannot get number of sockets!\n");
1252 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
1254 /* add one extra socket */
1255 for (i = 0; i < num_sockets + 1; i++) {
1256 snprintf(buf, sizeof(buf), "%s%s", invalid_socket_mem, DEFAULT_MEM_SIZE);
1257 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1259 if (num_sockets + 1 - i > 1) {
1260 snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
1261 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1265 /* construct a valid socket mask with 2 megs on each existing socket */
1266 char valid_socket_mem[SOCKET_MEM_STRLEN];
1268 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
1270 /* add one extra socket */
1271 for (i = 0; i < num_sockets; i++) {
1272 snprintf(buf, sizeof(buf), "%s%s", valid_socket_mem, DEFAULT_MEM_SIZE);
1273 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1275 if (num_sockets - i > 1) {
1276 snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
1277 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1281 /* invalid --socket-mem flag (with extra socket) */
1282 const char *argv9[] = {prgname, "-c", "10", "-n", "2",
1283 "--file-prefix=" memtest, invalid_socket_mem};
1285 /* valid --socket-mem flag */
1286 const char *argv10[] = {prgname, "-c", "10", "-n", "2",
1287 "--file-prefix=" memtest, valid_socket_mem};
1289 if (launch_proc(argv0) != 0) {
1290 printf("Error - secondary process failed with valid -m flag !\n");
1294 #ifdef RTE_EXEC_ENV_BSDAPP
1295 /* no other tests are applicable to BSD */
1299 if (launch_proc(argv1) != 0) {
1300 printf("Error - process failed with valid -m flag!\n");
1303 #ifdef RTE_LIBRTE_XEN_DOM0
1306 if (launch_proc(argv2) == 0) {
1307 printf("Error - process run ok with invalid (zero) --socket-mem!\n");
1311 if (launch_proc(argv3) == 0) {
1312 printf("Error - process run ok with invalid "
1313 "(incomplete) --socket-mem!\n");
1317 if (launch_proc(argv4) == 0) {
1318 printf("Error - process run ok with invalid "
1319 "(mixed with invalid input) --socket-mem!\n");
1323 if (launch_proc(argv5) == 0) {
1324 printf("Error - process run ok with invalid "
1325 "(mixed with invalid input with a numeric value as "
1326 "last character) --socket-mem!\n");
1330 if (launch_proc(argv6) == 0) {
1331 printf("Error - process run ok with invalid "
1332 "(with empty socket) --socket-mem!\n");
1336 if (launch_proc(argv7) == 0) {
1337 printf("Error - process run ok with invalid (null) --socket-mem!\n");
1341 if (launch_proc(argv8) == 0) {
1342 printf("Error - process run ok with --socket-mem and -m specified!\n");
1346 if (launch_proc(argv9) == 0) {
1347 printf("Error - process run ok with extra socket in --socket-mem!\n");
1351 if (launch_proc(argv10) != 0) {
1352 printf("Error - process failed with valid --socket-mem!\n");
1360 test_eal_flags(void)
1364 ret = test_missing_c_flag();
1366 printf("Error in test_missing_c_flag()\n");
1370 ret = test_master_lcore_flag();
1372 printf("Error in test_master_lcore_flag()\n");
1376 ret = test_invalid_n_flag();
1378 printf("Error in test_invalid_n_flag()\n");
1382 ret = test_no_hpet_flag();
1384 printf("Error in test_no_hpet_flag()\n");
1388 ret = test_no_huge_flag();
1390 printf("Error in test_no_huge_flag()\n");
1394 ret = test_whitelist_flag();
1396 printf("Error in test_invalid_whitelist_flag()\n");
1400 ret = test_invalid_b_flag();
1402 printf("Error in test_invalid_b_flag()\n");
1406 #ifdef RTE_LIBRTE_PMD_RING
1407 ret = test_invalid_vdev_flag();
1409 printf("Error in test_invalid_vdev_flag()\n");
1413 ret = test_invalid_r_flag();
1415 printf("Error in test_invalid_r_flag()\n");
1419 ret = test_memory_flags();
1421 printf("Error in test_memory_flags()\n");
1425 ret = test_file_prefix();
1427 printf("Error in test_file_prefix()\n");
1431 #ifdef RTE_LIBRTE_XEN_DOM0
1432 ret = test_dom0_misc_flags();
1434 ret = test_misc_flags();
1437 printf("Error in test_misc_flags()");
1444 static struct test_command eal_flags_cmd = {
1445 .command = "eal_flags_autotest",
1446 .callback = test_eal_flags,
1448 REGISTER_TEST_COMMAND(eal_flags_cmd);