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.
38 #ifndef RTE_EXEC_ENV_BAREMETAL
51 #include <rte_debug.h>
52 #include <rte_string_fns.h>
56 #define mp_flag "--proc-type=secondary"
57 #define no_hpet "--no-hpet"
58 #define no_huge "--no-huge"
59 #define no_shconf "--no-shconf"
60 #define pci_whitelist "--pci-whitelist"
62 #define memtest "memtest"
63 #define memtest1 "memtest1"
64 #define memtest2 "memtest2"
65 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 10)
66 #define launch_proc(ARGV) process_dup(ARGV, \
67 sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
69 enum hugepage_action {
70 HUGEPAGE_CHECK_EXISTS = 0,
71 HUGEPAGE_CHECK_LOCKED,
76 /* if string contains a hugepage path */
78 get_hugepage_path(char * src, int src_len, char * dst, int dst_len)
81 char *tokens[NUM_TOKENS];
83 /* if we couldn't properly split the string */
84 if (rte_strsplit(src, src_len, tokens, NUM_TOKENS, ' ') < NUM_TOKENS)
87 if (strncmp(tokens[2], "hugetlbfs", sizeof("hugetlbfs")) == 0) {
88 snprintf(dst, dst_len, "%s", tokens[1]);
95 * Cycles through hugepage directories and looks for hugepage
96 * files associated with a given prefix. Depending on value of
97 * action, the hugepages are checked if they exist, checked if
98 * they can be locked, or are simply deleted.
100 * Returns 1 if it finds at least one hugepage matching the action
101 * Returns 0 if no matching hugepages were found
102 * Returns -1 if it encounters an error
105 process_hugefiles(const char * prefix, enum hugepage_action action)
107 FILE * hugedir_handle = NULL;
108 DIR * hugepage_dir = NULL;
109 struct dirent *dirent = NULL;
111 char hugefile_prefix[PATH_MAX] = {0};
112 char hugedir[PATH_MAX] = {0};
113 char line[PATH_MAX] = {0};
115 int fd, lck_result, result = 0;
117 const int prefix_len = snprintf(hugefile_prefix,
118 sizeof(hugefile_prefix), "%smap_", prefix);
119 if (prefix_len <= 0 || prefix_len >= (int)sizeof(hugefile_prefix)
120 || prefix_len >= (int)sizeof(dirent->d_name)) {
121 printf("Error creating hugefile filename prefix\n");
125 /* get hugetlbfs mountpoints from /proc/mounts */
126 hugedir_handle = fopen("/proc/mounts", "r");
128 if (hugedir_handle == NULL) {
129 printf("Error parsing /proc/mounts!\n");
133 /* read and parse script output */
134 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
136 /* check if we have a hugepage filesystem path */
137 if (!get_hugepage_path(line, sizeof(line), hugedir, sizeof(hugedir)))
140 /* check if directory exists */
141 if ((hugepage_dir = opendir(hugedir)) == NULL) {
142 fclose(hugedir_handle);
143 printf("Error reading %s: %s\n", hugedir, strerror(errno));
147 while ((dirent = readdir(hugepage_dir)) != NULL) {
148 if (memcmp(dirent->d_name, hugefile_prefix, prefix_len) != 0)
152 case HUGEPAGE_CHECK_EXISTS:
154 /* file exists, return */
159 case HUGEPAGE_DELETE:
161 char file_path[PATH_MAX] = {0};
163 snprintf(file_path, sizeof(file_path),
164 "%s/%s", hugedir, dirent->d_name);
167 if (remove(file_path) < 0) {
168 printf("Error deleting %s - %s!\n",
169 dirent->d_name, strerror(errno));
170 closedir(hugepage_dir);
177 case HUGEPAGE_CHECK_LOCKED:
179 /* try and lock the file */
180 fd = openat(dirfd(hugepage_dir), dirent->d_name, O_RDONLY);
182 /* this shouldn't happen */
184 printf("Error opening %s - %s!\n",
185 dirent->d_name, strerror(errno));
186 closedir(hugepage_dir);
191 /* non-blocking lock */
192 lck_result = flock(fd, LOCK_EX | LOCK_NB);
194 /* if lock succeeds, there's something wrong */
195 if (lck_result != -1) {
198 /* unlock the resulting lock */
201 closedir(hugepage_dir);
208 /* shouldn't happen */
213 } /* read hugepage directory */
214 closedir(hugepage_dir);
215 } /* read /proc/mounts */
217 fclose(hugedir_handle);
221 #ifdef RTE_EXEC_ENV_LINUXAPP
223 * count the number of "node*" files in /sys/devices/system/node/
226 get_number_of_sockets(void)
228 struct dirent *dirent = NULL;
229 const char * nodedir = "/sys/devices/system/node/";
233 /* check if directory exists */
234 if ((dir = opendir(nodedir)) == NULL) {
235 /* if errno==ENOENT this means we don't have NUMA support */
236 if (errno == ENOENT) {
237 printf("No NUMA nodes detected: assuming 1 available socket\n");
240 printf("Error opening %s: %s\n", nodedir, strerror(errno));
244 while ((dirent = readdir(dir)) != NULL)
245 if (strncmp(dirent->d_name, "node", sizeof("node") - 1) == 0)
254 get_current_prefix(char * prefix, int size)
256 char path[PATH_MAX] = {0};
257 char buf[PATH_MAX] = {0};
259 /* get file for config (fd is always 3) */
260 snprintf(path, sizeof(path), "/proc/self/fd/%d", 3);
262 /* return NULL on error */
263 if (readlink(path, buf, sizeof(buf)) == -1)
266 /* get the basename */
267 snprintf(buf, sizeof(buf), "%s", basename(buf));
269 /* copy string all the way from second char up to start of _config */
270 snprintf(prefix, size, "%.*s",
271 (int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
278 * Test that the app doesn't run with invalid whitelist option.
279 * Final tests ensures it does run with valid options as sanity check (one
280 * test for with Domain+BDF, second for just with BDF)
283 test_whitelist_flag(void)
286 #ifdef RTE_EXEC_ENV_BSDAPP
287 /* BSD target doesn't support prefixes at this point */
288 const char * prefix = "";
290 char prefix[PATH_MAX], tmp[PATH_MAX];
291 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
292 printf("Error - unable to get current prefix!\n");
295 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
298 const char *wlinval[][11] = {
299 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
300 pci_whitelist, "error", "", ""},
301 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
302 pci_whitelist, "0:0:0", "", ""},
303 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
304 pci_whitelist, "0:error:0.1", "", ""},
305 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
306 pci_whitelist, "0:0:0.1error", "", ""},
307 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
308 pci_whitelist, "error0:0:0.1", "", ""},
309 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
310 pci_whitelist, "0:0:0.1.2", "", ""},
312 /* Test with valid whitelist option */
313 const char *wlval1[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
314 pci_whitelist, "00FF:09:0B.3"};
315 const char *wlval2[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
316 pci_whitelist, "09:0B.3", pci_whitelist, "0a:0b.1"};
317 const char *wlval3[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
318 pci_whitelist, "09:0B.3,type=test",
319 pci_whitelist, "08:00.1,type=normal",
322 for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
323 if (launch_proc(wlinval[i]) == 0) {
324 printf("Error - process did run ok with invalid "
325 "whitelist parameter\n");
329 if (launch_proc(wlval1) != 0 ) {
330 printf("Error - process did not run ok with valid whitelist\n");
333 if (launch_proc(wlval2) != 0 ) {
334 printf("Error - process did not run ok with valid whitelist value set\n");
337 if (launch_proc(wlval3) != 0 ) {
338 printf("Error - process did not run ok with valid whitelist + args\n");
346 * Test that the app doesn't run with invalid blacklist option.
347 * Final test ensures it does run with valid options as sanity check
350 test_invalid_b_flag(void)
352 #ifdef RTE_EXEC_ENV_BSDAPP
353 /* BSD target doesn't support prefixes at this point */
354 const char * prefix = "";
356 char prefix[PATH_MAX], tmp[PATH_MAX];
357 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
358 printf("Error - unable to get current prefix!\n");
361 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
364 const char *blinval[][9] = {
365 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error"},
366 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0"},
367 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:error:0.1"},
368 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1error"},
369 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error0:0:0.1"},
370 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1.2"},
372 /* Test with valid blacklist option */
373 const char *blval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
377 for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
378 if (launch_proc(blinval[i]) == 0) {
379 printf("Error - process did run ok with invalid "
380 "blacklist parameter\n");
384 if (launch_proc(blval) != 0) {
385 printf("Error - process did not run ok with valid blacklist value\n");
392 * Test that the app doesn't run with invalid vdev option.
393 * Final test ensures it does run with valid options as sanity check
395 #ifdef RTE_LIBRTE_PMD_RING
397 test_invalid_vdev_flag(void)
399 /* Test with invalid vdev option */
400 const char *vdevinval[] = {prgname, "--file-prefix=vdev","-n", "1",
401 "-c", "1", vdev, "eth_dummy"};
403 /* Test with valid vdev option */
404 const char *vdevval1[] = {prgname, "--file-prefix=vdev", "-n", "1",
405 "-c", "1", vdev, "eth_ring0"};
407 const char *vdevval2[] = {prgname, "--file-prefix=vdev", "-n", "1",
408 "-c", "1", vdev, "eth_ring0,args=test"};
410 const char *vdevval3[] = {prgname, "--file-prefix=vdev", "-n", "1",
411 "-c", "1", vdev, "eth_ring0,nodeaction=r1:0:CREATE"};
413 if (launch_proc(vdevinval) == 0) {
414 printf("Error - process did run ok with invalid "
419 if (launch_proc(vdevval1) != 0) {
420 printf("Error - process did not run ok with valid vdev value\n");
424 if (launch_proc(vdevval2) != 0) {
425 printf("Error - process did not run ok with valid vdev value,"
426 "with dummy args\n");
430 if (launch_proc(vdevval3) != 0) {
431 printf("Error - process did not run ok with valid vdev value,"
432 "with valid args\n");
440 * Test that the app doesn't run with invalid -r option.
443 test_invalid_r_flag(void)
445 #ifdef RTE_EXEC_ENV_BSDAPP
446 /* BSD target doesn't support prefixes at this point */
447 const char * prefix = "";
449 char prefix[PATH_MAX], tmp[PATH_MAX];
450 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
451 printf("Error - unable to get current prefix!\n");
454 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
457 const char *rinval[][9] = {
458 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "error"},
459 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "0"},
460 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "-1"},
461 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "17"},
463 /* Test with valid blacklist option */
464 const char *rval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
468 for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
469 if (launch_proc(rinval[i]) == 0) {
470 printf("Error - process did run ok with invalid "
471 "-r (rank) parameter\n");
475 if (launch_proc(rval) != 0) {
476 printf("Error - process did not run ok with valid -r (rank) value\n");
483 * Test that the app doesn't run without the coremask flag. In all cases
484 * should give an error and fail to run
487 test_missing_c_flag(void)
489 #ifdef RTE_EXEC_ENV_BSDAPP
490 /* BSD target doesn't support prefixes at this point */
491 const char * prefix = "";
493 char prefix[PATH_MAX], tmp[PATH_MAX];
494 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
495 printf("Error - unable to get current prefix!\n");
498 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
501 /* -c flag but no coremask value */
502 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "3", "-c"};
503 /* No -c flag at all */
504 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "3"};
505 /* bad coremask value */
506 const char *argv3[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "error" };
507 /* sanity check of tests - valid coremask value */
508 const char *argv4[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "1" };
510 if (launch_proc(argv1) == 0
511 || launch_proc(argv2) == 0
512 || launch_proc(argv3) == 0) {
513 printf("Error - process ran without error when missing -c flag\n");
516 if (launch_proc(argv4) != 0) {
517 printf("Error - process did not run ok with valid coremask value\n");
524 * Test that the app doesn't run without the -n flag. In all cases
525 * should give an error and fail to run.
526 * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
530 test_missing_n_flag(void)
532 #ifdef RTE_EXEC_ENV_BSDAPP
533 /* BSD target doesn't support prefixes at this point */
534 const char * prefix = "";
536 char prefix[PATH_MAX], tmp[PATH_MAX];
537 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
538 printf("Error - unable to get current prefix!\n");
541 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
544 /* -n flag but no value */
545 const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"};
546 /* No -n flag at all */
547 const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"};
548 /* bad numeric value */
549 const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" };
550 /* out-of-range value */
551 const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "9" };
552 /* sanity test - check with good value */
553 const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" };
555 if (launch_proc(argv1) == 0
556 || launch_proc(argv2) == 0
557 || launch_proc(argv3) == 0
558 || launch_proc(argv4) == 0) {
559 printf("Error - process ran without error when missing -n flag\n");
562 if (launch_proc(argv5) != 0) {
563 printf("Error - process did not run ok with valid num-channel value\n");
570 * Test that the app runs with HPET, and without HPET
573 test_no_hpet_flag(void)
575 char prefix[PATH_MAX], tmp[PATH_MAX];
577 #ifdef RTE_EXEC_ENV_BSDAPP
580 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
581 printf("Error - unable to get current prefix!\n");
584 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
587 const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"};
588 /* Without --no-hpet */
589 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-n", "2"};
591 if (launch_proc(argv1) != 0) {
592 printf("Error - process did not run ok with --no-hpet flag\n");
595 if (launch_proc(argv2) != 0) {
596 printf("Error - process did not run ok without --no-hpet flag\n");
603 * Test that the app runs with --no-huge and doesn't run when either
604 * -m or --socket-mem are specified with --no-huge.
607 test_no_huge_flag(void)
609 #ifdef RTE_EXEC_ENV_BSDAPP
610 /* BSD target doesn't support prefixes at this point, and we also need to
611 * run another primary process here */
612 const char * prefix = no_shconf;
614 const char * prefix = "--file-prefix=nohuge";
618 const char *argv1[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2"};
619 /* With --no-huge and -m */
620 const char *argv2[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2", "-m", "2"};
622 /* With --no-huge and --socket-mem */
623 const char *argv3[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
625 /* With --no-huge, -m and --socket-mem */
626 const char *argv4[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
627 "-m", "2", "--socket-mem=2"};
628 if (launch_proc(argv1) != 0) {
629 printf("Error - process did not run ok with --no-huge flag\n");
632 if (launch_proc(argv2) == 0) {
633 printf("Error - process run ok with --no-huge and -m flags\n");
636 #ifdef RTE_EXEC_ENV_BSDAPP
637 /* BSD target does not support NUMA, hence no --socket-mem tests */
641 if (launch_proc(argv3) == 0) {
642 printf("Error - process run ok with --no-huge and --socket-mem "
646 if (launch_proc(argv4) == 0) {
647 printf("Error - process run ok with --no-huge, -m and "
648 "--socket-mem flags\n");
654 #ifdef RTE_LIBRTE_XEN_DOM0
656 test_dom0_misc_flags(void)
658 char prefix[PATH_MAX], tmp[PATH_MAX];
660 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
661 printf("Error - unable to get current prefix!\n");
664 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
666 /* check that some general flags don't prevent things from working.
667 * All cases, apart from the first, app should run.
668 * No futher testing of output done.
670 /* sanity check - failure with invalid option */
671 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
674 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
676 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
677 /* With valid --syslog */
678 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
679 "--syslog", "syslog"};
680 /* With empty --syslog (should fail) */
681 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
682 /* With invalid --syslog */
683 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
684 /* With no-sh-conf */
685 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "20",
686 "--no-shconf", "--file-prefix=noshconf" };
688 if (launch_proc(argv0) == 0) {
689 printf("Error - process ran ok with invalid flag\n");
692 if (launch_proc(argv1) != 0) {
693 printf("Error - process did not run ok with --no-pci flag\n");
696 if (launch_proc(argv2) != 0) {
697 printf("Error - process did not run ok with -v flag\n");
700 if (launch_proc(argv3) != 0) {
701 printf("Error - process did not run ok with --syslog flag\n");
704 if (launch_proc(argv4) == 0) {
705 printf("Error - process run ok with empty --syslog flag\n");
708 if (launch_proc(argv5) == 0) {
709 printf("Error - process run ok with invalid --syslog flag\n");
712 if (launch_proc(argv6) != 0) {
713 printf("Error - process did not run ok with --no-shconf flag\n");
721 test_misc_flags(void)
723 char hugepath[PATH_MAX] = {0};
724 #ifdef RTE_EXEC_ENV_BSDAPP
725 /* BSD target doesn't support prefixes at this point */
726 const char * prefix = "";
727 const char * nosh_prefix = "";
729 char prefix[PATH_MAX], tmp[PATH_MAX];
730 const char * nosh_prefix = "--file-prefix=noshconf";
731 FILE * hugedir_handle = NULL;
732 char line[PATH_MAX] = {0};
733 unsigned i, isempty = 1;
734 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
735 printf("Error - unable to get current prefix!\n");
738 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
741 * get first valid hugepage path
744 /* get hugetlbfs mountpoints from /proc/mounts */
745 hugedir_handle = fopen("/proc/mounts", "r");
747 if (hugedir_handle == NULL) {
748 printf("Error opening /proc/mounts!\n");
752 /* read /proc/mounts */
753 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
755 /* find first valid hugepath */
756 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
760 fclose(hugedir_handle);
762 /* check if path is not empty */
763 for (i = 0; i < sizeof(hugepath); i++)
764 if (hugepath[i] != '\0')
768 printf("No mounted hugepage dir found!\n");
774 /* check that some general flags don't prevent things from working.
775 * All cases, apart from the first, app should run.
776 * No futher testing of output done.
778 /* sanity check - failure with invalid option */
779 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
782 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
784 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
785 /* With valid --syslog */
786 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
787 "--syslog", "syslog"};
788 /* With empty --syslog (should fail) */
789 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
790 /* With invalid --syslog */
791 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
792 /* With no-sh-conf */
793 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
794 no_shconf, nosh_prefix };
796 #ifdef RTE_EXEC_ENV_BSDAPP
799 /* With --huge-dir */
800 const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
801 "--file-prefix=hugedir", "--huge-dir", hugepath};
802 /* With empty --huge-dir (should fail) */
803 const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
804 "--file-prefix=hugedir", "--huge-dir"};
805 /* With invalid --huge-dir */
806 const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
807 "--file-prefix=hugedir", "--huge-dir", "invalid"};
808 /* Secondary process with invalid --huge-dir (should run as flag has no
809 * effect on secondary processes) */
810 const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
812 /* try running with base-virtaddr param */
813 const char *argv11[] = {prgname, "--file-prefix=virtaddr",
814 "-c", "1", "-n", "2", "--base-virtaddr=0x12345678"};
816 /* try running with --vfio-intr INTx flag */
817 const char *argv12[] = {prgname, "--file-prefix=intr",
818 "-c", "1", "-n", "2", "--vfio-intr=legacy"};
820 /* try running with --vfio-intr MSI flag */
821 const char *argv13[] = {prgname, "--file-prefix=intr",
822 "-c", "1", "-n", "2", "--vfio-intr=msi"};
824 /* try running with --vfio-intr MSI-X flag */
825 const char *argv14[] = {prgname, "--file-prefix=intr",
826 "-c", "1", "-n", "2", "--vfio-intr=msix"};
828 /* try running with --vfio-intr invalid flag */
829 const char *argv15[] = {prgname, "--file-prefix=intr",
830 "-c", "1", "-n", "2", "--vfio-intr=invalid"};
833 if (launch_proc(argv0) == 0) {
834 printf("Error - process ran ok with invalid flag\n");
837 if (launch_proc(argv1) != 0) {
838 printf("Error - process did not run ok with --no-pci flag\n");
841 if (launch_proc(argv2) != 0) {
842 printf("Error - process did not run ok with -v flag\n");
845 if (launch_proc(argv3) != 0) {
846 printf("Error - process did not run ok with --syslog flag\n");
849 if (launch_proc(argv4) == 0) {
850 printf("Error - process run ok with empty --syslog flag\n");
853 if (launch_proc(argv5) == 0) {
854 printf("Error - process run ok with invalid --syslog flag\n");
857 if (launch_proc(argv6) != 0) {
858 printf("Error - process did not run ok with --no-shconf flag\n");
861 #ifdef RTE_EXEC_ENV_BSDAPP
864 if (launch_proc(argv7) != 0) {
865 printf("Error - process did not run ok with --huge-dir flag\n");
868 if (launch_proc(argv8) == 0) {
869 printf("Error - process run ok with empty --huge-dir flag\n");
872 if (launch_proc(argv9) == 0) {
873 printf("Error - process run ok with invalid --huge-dir flag\n");
876 if (launch_proc(argv10) != 0) {
877 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
880 if (launch_proc(argv11) != 0) {
881 printf("Error - process did not run ok with --base-virtaddr parameter\n");
884 if (launch_proc(argv12) != 0) {
885 printf("Error - process did not run ok with "
886 "--vfio-intr INTx parameter\n");
889 if (launch_proc(argv13) != 0) {
890 printf("Error - process did not run ok with "
891 "--vfio-intr MSI parameter\n");
894 if (launch_proc(argv14) != 0) {
895 printf("Error - process did not run ok with "
896 "--vfio-intr MSI-X parameter\n");
899 if (launch_proc(argv15) == 0) {
900 printf("Error - process run ok with "
901 "--vfio-intr invalid parameter\n");
909 test_file_prefix(void)
912 * 1. check if current process hugefiles are locked
913 * 2. try to run secondary process without a corresponding primary process
914 * (while failing to run, it will also remove any unused hugepage files)
915 * 3. check if current process hugefiles are still in place and are locked
916 * 4. run a primary process with memtest1 prefix
917 * 5. check if memtest1 hugefiles are created
918 * 6. run a primary process with memtest2 prefix
919 * 7. check that only memtest2 hugefiles are present in the hugedir
922 #ifdef RTE_EXEC_ENV_BSDAPP
926 /* this should fail unless the test itself is run with "memtest" prefix */
927 const char *argv0[] = {prgname, mp_flag, "-c", "1", "-n", "2", "-m", "2",
928 "--file-prefix=" memtest };
930 /* primary process with memtest1 */
931 const char *argv1[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
932 "--file-prefix=" memtest1 };
934 /* primary process with memtest2 */
935 const char *argv2[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
936 "--file-prefix=" memtest2 };
939 if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
940 printf("Error - unable to get current prefix!\n");
943 #ifdef RTE_LIBRTE_XEN_DOM0
947 /* check if files for current prefix are present */
948 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
949 printf("Error - hugepage files for %s were not created!\n", prefix);
953 /* checks if files for current prefix are locked */
954 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
955 printf("Error - hugepages for current process aren't locked!\n");
959 /* check if files for secondary process are present */
960 if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
961 /* check if they are not locked */
962 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
963 printf("Error - hugepages for current process are locked!\n");
966 /* they aren't locked, delete them */
968 if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
969 printf("Error - deleting hugepages failed!\n");
975 if (launch_proc(argv0) == 0) {
976 printf("Error - secondary process ran ok without primary process\n");
980 /* check if files for current prefix are present */
981 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
982 printf("Error - hugepage files for %s were not created!\n", prefix);
986 /* checks if files for current prefix are locked */
987 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
988 printf("Error - hugepages for current process aren't locked!\n");
992 if (launch_proc(argv1) != 0) {
993 printf("Error - failed to run with --file-prefix=%s\n", memtest);
997 /* check if memtest1_map0 is present */
998 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
999 printf("Error - hugepage files for %s were not created!\n", memtest1);
1003 if (launch_proc(argv2) != 0) {
1004 printf("Error - failed to run with --file-prefix=%s\n", memtest2);
1008 /* check if hugefiles for memtest2 are present */
1009 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
1010 printf("Error - hugepage files for %s were not created!\n", memtest2);
1014 /* check if hugefiles for memtest1 are present */
1015 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1016 printf("Error - hugepage files for %s were not deleted!\n", memtest1);
1024 * Tests for correct handling of -m and --socket-mem flags
1027 test_memory_flags(void)
1029 const char* mem_size = NULL;
1030 #ifdef RTE_EXEC_ENV_BSDAPP
1031 /* BSD target doesn't support prefixes at this point */
1032 const char * prefix = "";
1034 char prefix[PATH_MAX], tmp[PATH_MAX];
1035 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
1036 printf("Error - unable to get current prefix!\n");
1039 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
1041 #ifdef RTE_LIBRTE_XEN_DOM0
1048 /* valid -m flag and mp flag */
1049 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "10",
1050 "-n", "2", "-m", mem_size};
1053 const char *argv1[] = {prgname, "-c", "10", "-n", "2",
1054 "--file-prefix=" memtest, "-m", mem_size};
1056 /* invalid (zero) --socket-mem flag */
1057 const char *argv2[] = {prgname, "-c", "10", "-n", "2",
1058 "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
1060 /* invalid (incomplete) --socket-mem flag */
1061 const char *argv3[] = {prgname, "-c", "10", "-n", "2",
1062 "--file-prefix=" memtest, "--socket-mem=2,2,"};
1064 /* invalid (mixed with invalid data) --socket-mem flag */
1065 const char *argv4[] = {prgname, "-c", "10", "-n", "2",
1066 "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
1068 /* invalid (with numeric value as last character) --socket-mem flag */
1069 const char *argv5[] = {prgname, "-c", "10", "-n", "2",
1070 "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
1072 /* invalid (with empty socket) --socket-mem flag */
1073 const char *argv6[] = {prgname, "-c", "10", "-n", "2",
1074 "--file-prefix=" memtest, "--socket-mem=2,,2"};
1076 /* invalid (null) --socket-mem flag */
1077 const char *argv7[] = {prgname, "-c", "10", "-n", "2",
1078 "--file-prefix=" memtest, "--socket-mem="};
1080 /* valid --socket-mem specified together with -m flag */
1081 const char *argv8[] = {prgname, "-c", "10", "-n", "2",
1082 "--file-prefix=" memtest, "-m", "2", "--socket-mem=2,2"};
1084 /* construct an invalid socket mask with 2 megs on each socket plus
1085 * extra 2 megs on socket that doesn't exist on current system */
1086 char invalid_socket_mem[SOCKET_MEM_STRLEN];
1087 char buf[SOCKET_MEM_STRLEN]; /* to avoid copying string onto itself */
1089 #ifdef RTE_EXEC_ENV_BSDAPP
1090 int i, num_sockets = 1;
1092 int i, num_sockets = get_number_of_sockets();
1095 if (num_sockets <= 0 || num_sockets > RTE_MAX_NUMA_NODES) {
1096 printf("Error - cannot get number of sockets!\n");
1100 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
1102 /* add one extra socket */
1103 for (i = 0; i < num_sockets + 1; i++) {
1104 snprintf(buf, sizeof(buf), "%s2", invalid_socket_mem);
1105 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1107 if (num_sockets + 1 - i > 1) {
1108 snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
1109 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1113 /* construct a valid socket mask with 2 megs on each existing socket */
1114 char valid_socket_mem[SOCKET_MEM_STRLEN];
1116 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
1118 /* add one extra socket */
1119 for (i = 0; i < num_sockets; i++) {
1120 snprintf(buf, sizeof(buf), "%s2", valid_socket_mem);
1121 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1123 if (num_sockets - i > 1) {
1124 snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
1125 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1129 /* invalid --socket-mem flag (with extra socket) */
1130 const char *argv9[] = {prgname, "-c", "10", "-n", "2",
1131 "--file-prefix=" memtest, invalid_socket_mem};
1133 /* valid --socket-mem flag */
1134 const char *argv10[] = {prgname, "-c", "10", "-n", "2",
1135 "--file-prefix=" memtest, valid_socket_mem};
1137 if (launch_proc(argv0) != 0) {
1138 printf("Error - secondary process failed with valid -m flag !\n");
1142 #ifdef RTE_EXEC_ENV_BSDAPP
1143 /* no other tests are applicable to BSD */
1147 if (launch_proc(argv1) != 0) {
1148 printf("Error - process failed with valid -m flag!\n");
1151 #ifdef RTE_LIBRTE_XEN_DOM0
1154 if (launch_proc(argv2) == 0) {
1155 printf("Error - process run ok with invalid (zero) --socket-mem!\n");
1159 if (launch_proc(argv3) == 0) {
1160 printf("Error - process run ok with invalid "
1161 "(incomplete) --socket-mem!\n");
1165 if (launch_proc(argv4) == 0) {
1166 printf("Error - process run ok with invalid "
1167 "(mixed with invalid input) --socket-mem!\n");
1171 if (launch_proc(argv5) == 0) {
1172 printf("Error - process run ok with invalid "
1173 "(mixed with invalid input with a numeric value as "
1174 "last character) --socket-mem!\n");
1178 if (launch_proc(argv6) == 0) {
1179 printf("Error - process run ok with invalid "
1180 "(with empty socket) --socket-mem!\n");
1184 if (launch_proc(argv7) == 0) {
1185 printf("Error - process run ok with invalid (null) --socket-mem!\n");
1189 if (launch_proc(argv8) == 0) {
1190 printf("Error - process run ok with --socket-mem and -m specified!\n");
1194 if (launch_proc(argv9) == 0) {
1195 printf("Error - process run ok with extra socket in --socket-mem!\n");
1199 if (launch_proc(argv10) != 0) {
1200 printf("Error - process failed with valid --socket-mem!\n");
1208 test_eal_flags(void)
1212 ret = test_missing_c_flag();
1214 printf("Error in test_missing_c_flag()\n");
1218 ret = test_missing_n_flag();
1220 printf("Error in test_missing_n_flag()\n");
1224 ret = test_no_hpet_flag();
1226 printf("Error in test_no_hpet_flag()\n");
1230 ret = test_no_huge_flag();
1232 printf("Error in test_no_huge_flag()\n");
1236 ret = test_whitelist_flag();
1238 printf("Error in test_invalid_whitelist_flag()\n");
1242 ret = test_invalid_b_flag();
1244 printf("Error in test_invalid_b_flag()\n");
1248 #ifdef RTE_LIBRTE_PMD_RING
1249 ret = test_invalid_vdev_flag();
1251 printf("Error in test_invalid_vdev_flag()\n");
1255 ret = test_invalid_r_flag();
1257 printf("Error in test_invalid_r_flag()\n");
1261 ret = test_memory_flags();
1263 printf("Error in test_memory_flags()\n");
1267 ret = test_file_prefix();
1269 printf("Error in test_file_prefix()\n");
1273 #ifdef RTE_LIBRTE_XEN_DOM0
1274 ret = test_dom0_misc_flags();
1276 ret = test_misc_flags();
1279 printf("Error in test_misc_flags()");
1286 static struct test_command eal_flags_cmd = {
1287 .command = "eal_flags_autotest",
1288 .callback = test_eal_flags,
1290 REGISTER_TEST_COMMAND(eal_flags_cmd);