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 #ifdef RTE_LIBRTE_XEN_DOM0
55 #define DEFAULT_MEM_SIZE "30"
57 #define DEFAULT_MEM_SIZE "18"
59 #define mp_flag "--proc-type=secondary"
60 #define no_hpet "--no-hpet"
61 #define no_huge "--no-huge"
62 #define no_shconf "--no-shconf"
63 #define pci_whitelist "--pci-whitelist"
65 #define memtest "memtest"
66 #define memtest1 "memtest1"
67 #define memtest2 "memtest2"
68 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 10)
69 #define launch_proc(ARGV) process_dup(ARGV, \
70 sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
72 enum hugepage_action {
73 HUGEPAGE_CHECK_EXISTS = 0,
74 HUGEPAGE_CHECK_LOCKED,
79 /* if string contains a hugepage path */
81 get_hugepage_path(char * src, int src_len, char * dst, int dst_len)
84 char *tokens[NUM_TOKENS];
86 /* if we couldn't properly split the string */
87 if (rte_strsplit(src, src_len, tokens, NUM_TOKENS, ' ') < NUM_TOKENS)
90 if (strncmp(tokens[2], "hugetlbfs", sizeof("hugetlbfs")) == 0) {
91 snprintf(dst, dst_len, "%s", tokens[1]);
98 * Cycles through hugepage directories and looks for hugepage
99 * files associated with a given prefix. Depending on value of
100 * action, the hugepages are checked if they exist, checked if
101 * they can be locked, or are simply deleted.
103 * Returns 1 if it finds at least one hugepage matching the action
104 * Returns 0 if no matching hugepages were found
105 * Returns -1 if it encounters an error
108 process_hugefiles(const char * prefix, enum hugepage_action action)
110 FILE * hugedir_handle = NULL;
111 DIR * hugepage_dir = NULL;
112 struct dirent *dirent = NULL;
114 char hugefile_prefix[PATH_MAX] = {0};
115 char hugedir[PATH_MAX] = {0};
116 char line[PATH_MAX] = {0};
118 int fd, lck_result, result = 0;
120 const int prefix_len = snprintf(hugefile_prefix,
121 sizeof(hugefile_prefix), "%smap_", prefix);
122 if (prefix_len <= 0 || prefix_len >= (int)sizeof(hugefile_prefix)
123 || prefix_len >= (int)sizeof(dirent->d_name)) {
124 printf("Error creating hugefile filename prefix\n");
128 /* get hugetlbfs mountpoints from /proc/mounts */
129 hugedir_handle = fopen("/proc/mounts", "r");
131 if (hugedir_handle == NULL) {
132 printf("Error parsing /proc/mounts!\n");
136 /* read and parse script output */
137 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
139 /* check if we have a hugepage filesystem path */
140 if (!get_hugepage_path(line, sizeof(line), hugedir, sizeof(hugedir)))
143 /* check if directory exists */
144 if ((hugepage_dir = opendir(hugedir)) == NULL) {
145 fclose(hugedir_handle);
146 printf("Error reading %s: %s\n", hugedir, strerror(errno));
150 while ((dirent = readdir(hugepage_dir)) != NULL) {
151 if (memcmp(dirent->d_name, hugefile_prefix, prefix_len) != 0)
155 case HUGEPAGE_CHECK_EXISTS:
157 /* file exists, return */
162 case HUGEPAGE_DELETE:
164 char file_path[PATH_MAX] = {0};
166 snprintf(file_path, sizeof(file_path),
167 "%s/%s", hugedir, dirent->d_name);
170 if (remove(file_path) < 0) {
171 printf("Error deleting %s - %s!\n",
172 dirent->d_name, strerror(errno));
173 closedir(hugepage_dir);
180 case HUGEPAGE_CHECK_LOCKED:
182 /* try and lock the file */
183 fd = openat(dirfd(hugepage_dir), dirent->d_name, O_RDONLY);
185 /* this shouldn't happen */
187 printf("Error opening %s - %s!\n",
188 dirent->d_name, strerror(errno));
189 closedir(hugepage_dir);
194 /* non-blocking lock */
195 lck_result = flock(fd, LOCK_EX | LOCK_NB);
197 /* if lock succeeds, there's something wrong */
198 if (lck_result != -1) {
201 /* unlock the resulting lock */
204 closedir(hugepage_dir);
211 /* shouldn't happen */
216 } /* read hugepage directory */
217 closedir(hugepage_dir);
218 } /* read /proc/mounts */
220 fclose(hugedir_handle);
224 #ifdef RTE_EXEC_ENV_LINUXAPP
226 * count the number of "node*" files in /sys/devices/system/node/
229 get_number_of_sockets(void)
231 struct dirent *dirent = NULL;
232 const char * nodedir = "/sys/devices/system/node/";
236 /* check if directory exists */
237 if ((dir = opendir(nodedir)) == NULL) {
238 /* if errno==ENOENT this means we don't have NUMA support */
239 if (errno == ENOENT) {
240 printf("No NUMA nodes detected: assuming 1 available socket\n");
243 printf("Error opening %s: %s\n", nodedir, strerror(errno));
247 while ((dirent = readdir(dir)) != NULL)
248 if (strncmp(dirent->d_name, "node", sizeof("node") - 1) == 0)
257 get_current_prefix(char * prefix, int size)
259 char path[PATH_MAX] = {0};
260 char buf[PATH_MAX] = {0};
262 /* get file for config (fd is always 3) */
263 snprintf(path, sizeof(path), "/proc/self/fd/%d", 3);
265 /* return NULL on error */
266 if (readlink(path, buf, sizeof(buf)) == -1)
269 /* get the basename */
270 snprintf(buf, sizeof(buf), "%s", basename(buf));
272 /* copy string all the way from second char up to start of _config */
273 snprintf(prefix, size, "%.*s",
274 (int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
281 * Test that the app doesn't run with invalid whitelist option.
282 * Final tests ensures it does run with valid options as sanity check (one
283 * test for with Domain+BDF, second for just with BDF)
286 test_whitelist_flag(void)
289 #ifdef RTE_EXEC_ENV_BSDAPP
290 /* BSD target doesn't support prefixes at this point */
291 const char * prefix = "";
293 char prefix[PATH_MAX], tmp[PATH_MAX];
294 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
295 printf("Error - unable to get current prefix!\n");
298 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
301 const char *wlinval[][11] = {
302 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
303 pci_whitelist, "error", "", ""},
304 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
305 pci_whitelist, "0:0:0", "", ""},
306 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
307 pci_whitelist, "0:error:0.1", "", ""},
308 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
309 pci_whitelist, "0:0:0.1error", "", ""},
310 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
311 pci_whitelist, "error0:0:0.1", "", ""},
312 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
313 pci_whitelist, "0:0:0.1.2", "", ""},
315 /* Test with valid whitelist option */
316 const char *wlval1[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
317 pci_whitelist, "00FF:09:0B.3"};
318 const char *wlval2[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
319 pci_whitelist, "09:0B.3", pci_whitelist, "0a:0b.1"};
320 const char *wlval3[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
321 pci_whitelist, "09:0B.3,type=test",
322 pci_whitelist, "08:00.1,type=normal",
325 for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
326 if (launch_proc(wlinval[i]) == 0) {
327 printf("Error - process did run ok with invalid "
328 "whitelist parameter\n");
332 if (launch_proc(wlval1) != 0 ) {
333 printf("Error - process did not run ok with valid whitelist\n");
336 if (launch_proc(wlval2) != 0 ) {
337 printf("Error - process did not run ok with valid whitelist value set\n");
340 if (launch_proc(wlval3) != 0 ) {
341 printf("Error - process did not run ok with valid whitelist + args\n");
349 * Test that the app doesn't run with invalid blacklist option.
350 * Final test ensures it does run with valid options as sanity check
353 test_invalid_b_flag(void)
355 #ifdef RTE_EXEC_ENV_BSDAPP
356 /* BSD target doesn't support prefixes at this point */
357 const char * prefix = "";
359 char prefix[PATH_MAX], tmp[PATH_MAX];
360 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
361 printf("Error - unable to get current prefix!\n");
364 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
367 const char *blinval[][9] = {
368 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error"},
369 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0"},
370 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:error:0.1"},
371 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1error"},
372 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error0:0:0.1"},
373 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1.2"},
375 /* Test with valid blacklist option */
376 const char *blval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
380 for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
381 if (launch_proc(blinval[i]) == 0) {
382 printf("Error - process did run ok with invalid "
383 "blacklist parameter\n");
387 if (launch_proc(blval) != 0) {
388 printf("Error - process did not run ok with valid blacklist value\n");
395 * Test that the app doesn't run with invalid vdev option.
396 * Final test ensures it does run with valid options as sanity check
398 #ifdef RTE_LIBRTE_PMD_RING
400 test_invalid_vdev_flag(void)
402 #ifdef RTE_EXEC_ENV_BSDAPP
403 /* BSD target doesn't support prefixes at this point, and we also need to
404 * run another primary process here */
405 const char * prefix = no_shconf;
407 const char * prefix = "--file-prefix=vdev";
410 /* Test with invalid vdev option */
411 const char *vdevinval[] = {prgname, prefix, "-n", "1",
412 "-c", "1", vdev, "eth_dummy"};
414 /* Test with valid vdev option */
415 const char *vdevval1[] = {prgname, prefix, "-n", "1",
416 "-c", "1", vdev, "net_ring0"};
418 const char *vdevval2[] = {prgname, prefix, "-n", "1",
419 "-c", "1", vdev, "net_ring0,args=test"};
421 const char *vdevval3[] = {prgname, prefix, "-n", "1",
422 "-c", "1", vdev, "net_ring0,nodeaction=r1:0:CREATE"};
424 if (launch_proc(vdevinval) == 0) {
425 printf("Error - process did run ok with invalid "
430 if (launch_proc(vdevval1) != 0) {
431 printf("Error - process did not run ok with valid vdev value\n");
435 if (launch_proc(vdevval2) != 0) {
436 printf("Error - process did not run ok with valid vdev value,"
437 "with dummy args\n");
441 if (launch_proc(vdevval3) != 0) {
442 printf("Error - process did not run ok with valid vdev value,"
443 "with valid args\n");
451 * Test that the app doesn't run with invalid -r option.
454 test_invalid_r_flag(void)
456 #ifdef RTE_EXEC_ENV_BSDAPP
457 /* BSD target doesn't support prefixes at this point */
458 const char * prefix = "";
460 char prefix[PATH_MAX], tmp[PATH_MAX];
461 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
462 printf("Error - unable to get current prefix!\n");
465 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
468 const char *rinval[][9] = {
469 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "error"},
470 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "0"},
471 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "-1"},
472 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "17"},
474 /* Test with valid blacklist option */
475 const char *rval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
479 for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
480 if (launch_proc(rinval[i]) == 0) {
481 printf("Error - process did run ok with invalid "
482 "-r (rank) parameter\n");
486 if (launch_proc(rval) != 0) {
487 printf("Error - process did not run ok with valid -r (rank) value\n");
494 * Test that the app doesn't run without the coremask/corelist flags. In all cases
495 * should give an error and fail to run
498 test_missing_c_flag(void)
500 #ifdef RTE_EXEC_ENV_BSDAPP
501 /* BSD target doesn't support prefixes at this point */
502 const char * prefix = "";
504 char prefix[PATH_MAX], tmp[PATH_MAX];
505 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
506 printf("Error - unable to get current prefix!\n");
509 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
512 /* -c flag but no coremask value */
513 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "3", "-c"};
514 /* No -c, -l or --lcores flag at all */
515 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "3"};
516 /* bad coremask value */
517 const char *argv3[] = { prgname, prefix, mp_flag,
518 "-n", "3", "-c", "error" };
519 /* sanity check of tests - valid coremask value */
520 const char *argv4[] = { prgname, prefix, mp_flag,
521 "-n", "3", "-c", "1" };
522 /* -l flag but no corelist value */
523 const char *argv5[] = { prgname, prefix, mp_flag,
525 const char *argv6[] = { prgname, prefix, mp_flag,
526 "-n", "3", "-l", " " };
527 /* bad corelist values */
528 const char *argv7[] = { prgname, prefix, mp_flag,
529 "-n", "3", "-l", "error" };
530 const char *argv8[] = { prgname, prefix, mp_flag,
531 "-n", "3", "-l", "1-" };
532 const char *argv9[] = { prgname, prefix, mp_flag,
533 "-n", "3", "-l", "1," };
534 const char *argv10[] = { prgname, prefix, mp_flag,
535 "-n", "3", "-l", "1#2" };
536 /* sanity check test - valid corelist value */
537 const char *argv11[] = { prgname, prefix, mp_flag,
538 "-n", "3", "-l", "1-2,3" };
540 /* --lcores flag but no lcores value */
541 const char *argv12[] = { prgname, prefix, mp_flag,
542 "-n", "3", "--lcores" };
543 const char *argv13[] = { prgname, prefix, mp_flag,
544 "-n", "3", "--lcores", " " };
545 /* bad lcores value */
546 const char *argv14[] = { prgname, prefix, mp_flag,
547 "-n", "3", "--lcores", "1-3-5" };
548 const char *argv15[] = { prgname, prefix, mp_flag,
549 "-n", "3", "--lcores", "0-1,,2" };
550 const char *argv16[] = { prgname, prefix, mp_flag,
551 "-n", "3", "--lcores", "0-,1" };
552 const char *argv17[] = { prgname, prefix, mp_flag,
553 "-n", "3", "--lcores", "(0-,2-4)" };
554 const char *argv18[] = { prgname, prefix, mp_flag,
555 "-n", "3", "--lcores", "(-1,2)" };
556 const char *argv19[] = { prgname, prefix, mp_flag,
557 "-n", "3", "--lcores", "(2-4)@(2-4-6)" };
558 const char *argv20[] = { prgname, prefix, mp_flag,
559 "-n", "3", "--lcores", "(a,2)" };
560 const char *argv21[] = { prgname, prefix, mp_flag,
561 "-n", "3", "--lcores", "1-3@(1,3)" };
562 const char *argv22[] = { prgname, prefix, mp_flag,
563 "-n", "3", "--lcores", "3@((1,3)" };
564 const char *argv23[] = { prgname, prefix, mp_flag,
565 "-n", "3", "--lcores", "(4-7)=(1,3)" };
566 const char *argv24[] = { prgname, prefix, mp_flag,
567 "-n", "3", "--lcores", "[4-7]@(1,3)" };
568 /* sanity check of tests - valid lcores value */
569 const char *argv25[] = { prgname, prefix, mp_flag,
570 "-n", "3", "--lcores",
571 "0-1,2@(5-7),(3-5)@(0,2),(0,6),7"};
573 if (launch_proc(argv2) != 0) {
575 "process did not run ok when missing -c flag\n");
579 if (launch_proc(argv1) == 0
580 || launch_proc(argv3) == 0) {
582 "process ran without error with invalid -c flag\n");
585 if (launch_proc(argv4) != 0) {
587 "process did not run ok with valid coremask value\n");
592 if (launch_proc(argv5) == 0
593 || launch_proc(argv6) == 0
594 || launch_proc(argv7) == 0
595 || launch_proc(argv8) == 0
596 || launch_proc(argv9) == 0
597 || launch_proc(argv10) == 0) {
599 "process ran without error with invalid -l flag\n");
602 if (launch_proc(argv11) != 0) {
604 "process did not run ok with valid corelist value\n");
608 /* start --lcores tests */
609 if (launch_proc(argv12) == 0 || launch_proc(argv13) == 0 ||
610 launch_proc(argv14) == 0 || launch_proc(argv15) == 0 ||
611 launch_proc(argv16) == 0 || launch_proc(argv17) == 0 ||
612 launch_proc(argv18) == 0 || launch_proc(argv19) == 0 ||
613 launch_proc(argv20) == 0 || launch_proc(argv21) == 0 ||
614 launch_proc(argv21) == 0 || launch_proc(argv22) == 0 ||
615 launch_proc(argv23) == 0 || launch_proc(argv24) == 0) {
617 "process ran without error with invalid --lcore flag\n");
621 if (launch_proc(argv25) != 0) {
623 "process did not run ok with valid corelist value\n");
631 * Test --master-lcore option with matching coremask
634 test_master_lcore_flag(void)
636 #ifdef RTE_EXEC_ENV_BSDAPP
637 /* BSD target doesn't support prefixes at this point */
638 const char *prefix = "";
640 char prefix[PATH_MAX], tmp[PATH_MAX];
641 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
642 printf("Error - unable to get current prefix!\n");
645 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
648 /* --master-lcore flag but no value */
649 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore"};
650 /* --master-lcore flag with invalid value */
651 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "-1"};
652 const char *argv3[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "X"};
653 /* master lcore not in coremask */
654 const char *argv4[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "2"};
656 const char *argv5[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "1"};
657 /* valid value set before coremask */
658 const char *argv6[] = { prgname, prefix, mp_flag, "-n", "1", "--master-lcore", "1", "-c", "3"};
660 if (launch_proc(argv1) == 0
661 || launch_proc(argv2) == 0
662 || launch_proc(argv3) == 0
663 || launch_proc(argv4) == 0) {
664 printf("Error - process ran without error with wrong --master-lcore\n");
667 if (launch_proc(argv5) != 0
668 || launch_proc(argv6) != 0) {
669 printf("Error - process did not run ok with valid --master-lcore\n");
676 * Test that the app doesn't run with invalid -n flag option.
677 * Final test ensures it does run with valid options as sanity check
678 * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
682 test_invalid_n_flag(void)
684 #ifdef RTE_EXEC_ENV_BSDAPP
685 /* BSD target doesn't support prefixes at this point */
686 const char * prefix = "";
688 char prefix[PATH_MAX], tmp[PATH_MAX];
689 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
690 printf("Error - unable to get current prefix!\n");
693 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
696 /* -n flag but no value */
697 const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"};
698 /* bad numeric value */
699 const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" };
700 /* zero is invalid */
701 const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "0" };
702 /* sanity test - check with good value */
703 const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" };
704 /* sanity test - check with no -n flag */
705 const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"};
707 if (launch_proc(argv1) == 0
708 || launch_proc(argv2) == 0
709 || launch_proc(argv3) == 0) {
710 printf("Error - process ran without error when"
711 "invalid -n flag\n");
714 if (launch_proc(argv4) != 0) {
715 printf("Error - process did not run ok with valid num-channel value\n");
718 if (launch_proc(argv5) != 0) {
719 printf("Error - process did not run ok without -n flag\n");
727 * Test that the app runs with HPET, and without HPET
730 test_no_hpet_flag(void)
732 char prefix[PATH_MAX], tmp[PATH_MAX];
734 #ifdef RTE_EXEC_ENV_BSDAPP
737 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
738 printf("Error - unable to get current prefix!\n");
741 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
744 const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"};
745 /* Without --no-hpet */
746 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-n", "2"};
748 if (launch_proc(argv1) != 0) {
749 printf("Error - process did not run ok with --no-hpet flag\n");
752 if (launch_proc(argv2) != 0) {
753 printf("Error - process did not run ok without --no-hpet flag\n");
760 * Test that the app runs with --no-huge and doesn't run when --socket-mem are
761 * specified with --no-huge.
764 test_no_huge_flag(void)
766 #ifdef RTE_EXEC_ENV_BSDAPP
767 /* BSD target doesn't support prefixes at this point, and we also need to
768 * run another primary process here */
769 const char * prefix = no_shconf;
771 const char * prefix = "--file-prefix=nohuge";
775 const char *argv1[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2"};
776 /* With --no-huge and -m */
777 const char *argv2[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
778 "-m", DEFAULT_MEM_SIZE};
780 /* With --no-huge and --socket-mem */
781 const char *argv3[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
782 "--socket-mem=" DEFAULT_MEM_SIZE};
783 /* With --no-huge, -m and --socket-mem */
784 const char *argv4[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
785 "-m", DEFAULT_MEM_SIZE, "--socket-mem=" DEFAULT_MEM_SIZE};
786 if (launch_proc(argv1) != 0) {
787 printf("Error - process did not run ok with --no-huge flag\n");
790 if (launch_proc(argv2) != 0) {
791 printf("Error - process did not run ok with --no-huge and -m flags\n");
794 #ifdef RTE_EXEC_ENV_BSDAPP
795 /* BSD target does not support NUMA, hence no --socket-mem tests */
799 if (launch_proc(argv3) == 0) {
800 printf("Error - process run ok with --no-huge and --socket-mem "
804 if (launch_proc(argv4) == 0) {
805 printf("Error - process run ok with --no-huge, -m and "
806 "--socket-mem flags\n");
812 #ifdef RTE_LIBRTE_XEN_DOM0
814 test_dom0_misc_flags(void)
816 char prefix[PATH_MAX], tmp[PATH_MAX];
818 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
819 printf("Error - unable to get current prefix!\n");
822 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
824 /* check that some general flags don't prevent things from working.
825 * All cases, apart from the first, app should run.
826 * No further testing of output done.
828 /* sanity check - failure with invalid option */
829 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
832 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
834 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
835 /* With valid --syslog */
836 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
837 "--syslog", "syslog"};
838 /* With empty --syslog (should fail) */
839 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
840 /* With invalid --syslog */
841 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
842 /* With no-sh-conf */
843 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "20",
844 "--no-shconf", "--file-prefix=noshconf" };
846 if (launch_proc(argv0) == 0) {
847 printf("Error - process ran ok with invalid flag\n");
850 if (launch_proc(argv1) != 0) {
851 printf("Error - process did not run ok with --no-pci flag\n");
854 if (launch_proc(argv2) != 0) {
855 printf("Error - process did not run ok with -v flag\n");
858 if (launch_proc(argv3) != 0) {
859 printf("Error - process did not run ok with --syslog flag\n");
862 if (launch_proc(argv4) == 0) {
863 printf("Error - process run ok with empty --syslog flag\n");
866 if (launch_proc(argv5) == 0) {
867 printf("Error - process run ok with invalid --syslog flag\n");
870 if (launch_proc(argv6) != 0) {
871 printf("Error - process did not run ok with --no-shconf flag\n");
879 test_misc_flags(void)
881 char hugepath[PATH_MAX] = {0};
882 #ifdef RTE_EXEC_ENV_BSDAPP
883 /* BSD target doesn't support prefixes at this point */
884 const char * prefix = "";
885 const char * nosh_prefix = "";
887 char prefix[PATH_MAX], tmp[PATH_MAX];
888 const char * nosh_prefix = "--file-prefix=noshconf";
889 FILE * hugedir_handle = NULL;
890 char line[PATH_MAX] = {0};
891 unsigned i, isempty = 1;
892 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
893 printf("Error - unable to get current prefix!\n");
896 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
899 * get first valid hugepage path
902 /* get hugetlbfs mountpoints from /proc/mounts */
903 hugedir_handle = fopen("/proc/mounts", "r");
905 if (hugedir_handle == NULL) {
906 printf("Error opening /proc/mounts!\n");
910 /* read /proc/mounts */
911 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
913 /* find first valid hugepath */
914 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
918 fclose(hugedir_handle);
920 /* check if path is not empty */
921 for (i = 0; i < sizeof(hugepath); i++)
922 if (hugepath[i] != '\0')
926 printf("No mounted hugepage dir found!\n");
932 /* check that some general flags don't prevent things from working.
933 * All cases, apart from the first, app should run.
934 * No further testing of output done.
936 /* sanity check - failure with invalid option */
937 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
940 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
942 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
943 /* With valid --syslog */
944 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
945 "--syslog", "syslog"};
946 /* With empty --syslog (should fail) */
947 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
948 /* With invalid --syslog */
949 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
950 /* With no-sh-conf */
951 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
952 no_shconf, nosh_prefix };
954 #ifdef RTE_EXEC_ENV_BSDAPP
957 /* With --huge-dir */
958 const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
959 "--file-prefix=hugedir", "--huge-dir", hugepath};
960 /* With empty --huge-dir (should fail) */
961 const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
962 "--file-prefix=hugedir", "--huge-dir"};
963 /* With invalid --huge-dir */
964 const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
965 "--file-prefix=hugedir", "--huge-dir", "invalid"};
966 /* Secondary process with invalid --huge-dir (should run as flag has no
967 * effect on secondary processes) */
968 const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
970 /* try running with base-virtaddr param */
971 const char *argv11[] = {prgname, "--file-prefix=virtaddr",
972 "-c", "1", "-n", "2", "--base-virtaddr=0x12345678"};
974 /* try running with --vfio-intr INTx flag */
975 const char *argv12[] = {prgname, "--file-prefix=intr",
976 "-c", "1", "-n", "2", "--vfio-intr=legacy"};
978 /* try running with --vfio-intr MSI flag */
979 const char *argv13[] = {prgname, "--file-prefix=intr",
980 "-c", "1", "-n", "2", "--vfio-intr=msi"};
982 /* try running with --vfio-intr MSI-X flag */
983 const char *argv14[] = {prgname, "--file-prefix=intr",
984 "-c", "1", "-n", "2", "--vfio-intr=msix"};
986 /* try running with --vfio-intr invalid flag */
987 const char *argv15[] = {prgname, "--file-prefix=intr",
988 "-c", "1", "-n", "2", "--vfio-intr=invalid"};
991 if (launch_proc(argv0) == 0) {
992 printf("Error - process ran ok with invalid flag\n");
995 if (launch_proc(argv1) != 0) {
996 printf("Error - process did not run ok with --no-pci flag\n");
999 if (launch_proc(argv2) != 0) {
1000 printf("Error - process did not run ok with -v flag\n");
1003 if (launch_proc(argv3) != 0) {
1004 printf("Error - process did not run ok with --syslog flag\n");
1007 if (launch_proc(argv4) == 0) {
1008 printf("Error - process run ok with empty --syslog flag\n");
1011 if (launch_proc(argv5) == 0) {
1012 printf("Error - process run ok with invalid --syslog flag\n");
1015 if (launch_proc(argv6) != 0) {
1016 printf("Error - process did not run ok with --no-shconf flag\n");
1019 #ifdef RTE_EXEC_ENV_BSDAPP
1022 if (launch_proc(argv7) != 0) {
1023 printf("Error - process did not run ok with --huge-dir flag\n");
1026 if (launch_proc(argv8) == 0) {
1027 printf("Error - process run ok with empty --huge-dir flag\n");
1030 if (launch_proc(argv9) == 0) {
1031 printf("Error - process run ok with invalid --huge-dir flag\n");
1034 if (launch_proc(argv10) != 0) {
1035 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
1038 if (launch_proc(argv11) != 0) {
1039 printf("Error - process did not run ok with --base-virtaddr parameter\n");
1042 if (launch_proc(argv12) != 0) {
1043 printf("Error - process did not run ok with "
1044 "--vfio-intr INTx parameter\n");
1047 if (launch_proc(argv13) != 0) {
1048 printf("Error - process did not run ok with "
1049 "--vfio-intr MSI parameter\n");
1052 if (launch_proc(argv14) != 0) {
1053 printf("Error - process did not run ok with "
1054 "--vfio-intr MSI-X parameter\n");
1057 if (launch_proc(argv15) == 0) {
1058 printf("Error - process run ok with "
1059 "--vfio-intr invalid parameter\n");
1067 test_file_prefix(void)
1070 * 1. check if current process hugefiles are locked
1071 * 2. try to run secondary process without a corresponding primary process
1072 * (while failing to run, it will also remove any unused hugepage files)
1073 * 3. check if current process hugefiles are still in place and are locked
1074 * 4. run a primary process with memtest1 prefix
1075 * 5. check if memtest1 hugefiles are created
1076 * 6. run a primary process with memtest2 prefix
1077 * 7. check that only memtest2 hugefiles are present in the hugedir
1080 #ifdef RTE_EXEC_ENV_BSDAPP
1084 /* this should fail unless the test itself is run with "memtest" prefix */
1085 const char *argv0[] = {prgname, mp_flag, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
1086 "--file-prefix=" memtest };
1088 /* primary process with memtest1 */
1089 const char *argv1[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
1090 "--file-prefix=" memtest1 };
1092 /* primary process with memtest2 */
1093 const char *argv2[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
1094 "--file-prefix=" memtest2 };
1097 if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
1098 printf("Error - unable to get current prefix!\n");
1101 #ifdef RTE_LIBRTE_XEN_DOM0
1105 /* check if files for current prefix are present */
1106 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1107 printf("Error - hugepage files for %s were not created!\n", prefix);
1111 /* checks if files for current prefix are locked */
1112 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1113 printf("Error - hugepages for current process aren't locked!\n");
1117 /* check if files for secondary process are present */
1118 if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
1119 /* check if they are not locked */
1120 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
1121 printf("Error - hugepages for current process are locked!\n");
1124 /* they aren't locked, delete them */
1126 if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
1127 printf("Error - deleting hugepages failed!\n");
1133 if (launch_proc(argv0) == 0) {
1134 printf("Error - secondary process ran ok without primary process\n");
1138 /* check if files for current prefix are present */
1139 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1140 printf("Error - hugepage files for %s were not created!\n", prefix);
1144 /* checks if files for current prefix are locked */
1145 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1146 printf("Error - hugepages for current process aren't locked!\n");
1150 if (launch_proc(argv1) != 0) {
1151 printf("Error - failed to run with --file-prefix=%s\n", memtest);
1155 /* check if memtest1_map0 is present */
1156 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
1157 printf("Error - hugepage files for %s were not created!\n", memtest1);
1161 if (launch_proc(argv2) != 0) {
1162 printf("Error - failed to run with --file-prefix=%s\n", memtest2);
1166 /* check if hugefiles for memtest2 are present */
1167 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
1168 printf("Error - hugepage files for %s were not created!\n", memtest2);
1172 /* check if hugefiles for memtest1 are present */
1173 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1174 printf("Error - hugepage files for %s were not deleted!\n", memtest1);
1182 * Tests for correct handling of -m and --socket-mem flags
1185 test_memory_flags(void)
1187 #ifdef RTE_EXEC_ENV_BSDAPP
1188 /* BSD target doesn't support prefixes at this point */
1189 const char * prefix = "";
1191 char prefix[PATH_MAX], tmp[PATH_MAX];
1192 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
1193 printf("Error - unable to get current prefix!\n");
1196 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
1199 /* valid -m flag and mp flag */
1200 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "10",
1201 "-n", "2", "-m", DEFAULT_MEM_SIZE};
1204 const char *argv1[] = {prgname, "-c", "10", "-n", "2",
1205 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE};
1207 /* invalid (zero) --socket-mem flag */
1208 const char *argv2[] = {prgname, "-c", "10", "-n", "2",
1209 "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
1211 /* invalid (incomplete) --socket-mem flag */
1212 const char *argv3[] = {prgname, "-c", "10", "-n", "2",
1213 "--file-prefix=" memtest, "--socket-mem=2,2,"};
1215 /* invalid (mixed with invalid data) --socket-mem flag */
1216 const char *argv4[] = {prgname, "-c", "10", "-n", "2",
1217 "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
1219 /* invalid (with numeric value as last character) --socket-mem flag */
1220 const char *argv5[] = {prgname, "-c", "10", "-n", "2",
1221 "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
1223 /* invalid (with empty socket) --socket-mem flag */
1224 const char *argv6[] = {prgname, "-c", "10", "-n", "2",
1225 "--file-prefix=" memtest, "--socket-mem=2,,2"};
1227 /* invalid (null) --socket-mem flag */
1228 const char *argv7[] = {prgname, "-c", "10", "-n", "2",
1229 "--file-prefix=" memtest, "--socket-mem="};
1231 /* valid --socket-mem specified together with -m flag */
1232 const char *argv8[] = {prgname, "-c", "10", "-n", "2",
1233 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE, "--socket-mem=2,2"};
1235 /* construct an invalid socket mask with 2 megs on each socket plus
1236 * extra 2 megs on socket that doesn't exist on current system */
1237 char invalid_socket_mem[SOCKET_MEM_STRLEN];
1238 char buf[SOCKET_MEM_STRLEN]; /* to avoid copying string onto itself */
1240 #ifdef RTE_EXEC_ENV_BSDAPP
1241 int i, num_sockets = 1;
1243 int i, num_sockets = get_number_of_sockets();
1246 if (num_sockets <= 0 || num_sockets > RTE_MAX_NUMA_NODES) {
1247 printf("Error - cannot get number of sockets!\n");
1251 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
1253 /* add one extra socket */
1254 for (i = 0; i < num_sockets + 1; i++) {
1255 snprintf(buf, sizeof(buf), "%s%s", invalid_socket_mem, DEFAULT_MEM_SIZE);
1256 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1258 if (num_sockets + 1 - i > 1) {
1259 snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
1260 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1264 /* construct a valid socket mask with 2 megs on each existing socket */
1265 char valid_socket_mem[SOCKET_MEM_STRLEN];
1267 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
1269 /* add one extra socket */
1270 for (i = 0; i < num_sockets; i++) {
1271 snprintf(buf, sizeof(buf), "%s%s", valid_socket_mem, DEFAULT_MEM_SIZE);
1272 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1274 if (num_sockets - i > 1) {
1275 snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
1276 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1280 /* invalid --socket-mem flag (with extra socket) */
1281 const char *argv9[] = {prgname, "-c", "10", "-n", "2",
1282 "--file-prefix=" memtest, invalid_socket_mem};
1284 /* valid --socket-mem flag */
1285 const char *argv10[] = {prgname, "-c", "10", "-n", "2",
1286 "--file-prefix=" memtest, valid_socket_mem};
1288 if (launch_proc(argv0) != 0) {
1289 printf("Error - secondary process failed with valid -m flag !\n");
1293 #ifdef RTE_EXEC_ENV_BSDAPP
1294 /* no other tests are applicable to BSD */
1298 if (launch_proc(argv1) != 0) {
1299 printf("Error - process failed with valid -m flag!\n");
1302 #ifdef RTE_LIBRTE_XEN_DOM0
1305 if (launch_proc(argv2) == 0) {
1306 printf("Error - process run ok with invalid (zero) --socket-mem!\n");
1310 if (launch_proc(argv3) == 0) {
1311 printf("Error - process run ok with invalid "
1312 "(incomplete) --socket-mem!\n");
1316 if (launch_proc(argv4) == 0) {
1317 printf("Error - process run ok with invalid "
1318 "(mixed with invalid input) --socket-mem!\n");
1322 if (launch_proc(argv5) == 0) {
1323 printf("Error - process run ok with invalid "
1324 "(mixed with invalid input with a numeric value as "
1325 "last character) --socket-mem!\n");
1329 if (launch_proc(argv6) == 0) {
1330 printf("Error - process run ok with invalid "
1331 "(with empty socket) --socket-mem!\n");
1335 if (launch_proc(argv7) == 0) {
1336 printf("Error - process run ok with invalid (null) --socket-mem!\n");
1340 if (launch_proc(argv8) == 0) {
1341 printf("Error - process run ok with --socket-mem and -m specified!\n");
1345 if (launch_proc(argv9) == 0) {
1346 printf("Error - process run ok with extra socket in --socket-mem!\n");
1350 if (launch_proc(argv10) != 0) {
1351 printf("Error - process failed with valid --socket-mem!\n");
1359 test_eal_flags(void)
1363 ret = test_missing_c_flag();
1365 printf("Error in test_missing_c_flag()\n");
1369 ret = test_master_lcore_flag();
1371 printf("Error in test_master_lcore_flag()\n");
1375 ret = test_invalid_n_flag();
1377 printf("Error in test_invalid_n_flag()\n");
1381 ret = test_no_hpet_flag();
1383 printf("Error in test_no_hpet_flag()\n");
1387 ret = test_no_huge_flag();
1389 printf("Error in test_no_huge_flag()\n");
1393 ret = test_whitelist_flag();
1395 printf("Error in test_invalid_whitelist_flag()\n");
1399 ret = test_invalid_b_flag();
1401 printf("Error in test_invalid_b_flag()\n");
1405 #ifdef RTE_LIBRTE_PMD_RING
1406 ret = test_invalid_vdev_flag();
1408 printf("Error in test_invalid_vdev_flag()\n");
1412 ret = test_invalid_r_flag();
1414 printf("Error in test_invalid_r_flag()\n");
1418 ret = test_memory_flags();
1420 printf("Error in test_memory_flags()\n");
1424 ret = test_file_prefix();
1426 printf("Error in test_file_prefix()\n");
1430 #ifdef RTE_LIBRTE_XEN_DOM0
1431 ret = test_dom0_misc_flags();
1433 ret = test_misc_flags();
1436 printf("Error in test_misc_flags()");
1443 REGISTER_TEST_COMMAND(eal_flags_autotest, test_eal_flags);