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 "8"
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 /* Test with invalid vdev option */
404 const char *vdevinval[] = {prgname, "--file-prefix=vdev","-n", "1",
405 "-c", "1", vdev, "eth_dummy"};
407 /* Test with valid vdev option */
408 const char *vdevval1[] = {prgname, "--file-prefix=vdev", "-n", "1",
409 "-c", "1", vdev, "eth_ring0"};
411 const char *vdevval2[] = {prgname, "--file-prefix=vdev", "-n", "1",
412 "-c", "1", vdev, "eth_ring0,args=test"};
414 const char *vdevval3[] = {prgname, "--file-prefix=vdev", "-n", "1",
415 "-c", "1", vdev, "eth_ring0,nodeaction=r1:0:CREATE"};
417 if (launch_proc(vdevinval) == 0) {
418 printf("Error - process did run ok with invalid "
423 if (launch_proc(vdevval1) != 0) {
424 printf("Error - process did not run ok with valid vdev value\n");
428 if (launch_proc(vdevval2) != 0) {
429 printf("Error - process did not run ok with valid vdev value,"
430 "with dummy args\n");
434 if (launch_proc(vdevval3) != 0) {
435 printf("Error - process did not run ok with valid vdev value,"
436 "with valid args\n");
444 * Test that the app doesn't run with invalid -r option.
447 test_invalid_r_flag(void)
449 #ifdef RTE_EXEC_ENV_BSDAPP
450 /* BSD target doesn't support prefixes at this point */
451 const char * prefix = "";
453 char prefix[PATH_MAX], tmp[PATH_MAX];
454 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
455 printf("Error - unable to get current prefix!\n");
458 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
461 const char *rinval[][9] = {
462 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "error"},
463 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "0"},
464 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "-1"},
465 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "17"},
467 /* Test with valid blacklist option */
468 const char *rval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
472 for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
473 if (launch_proc(rinval[i]) == 0) {
474 printf("Error - process did run ok with invalid "
475 "-r (rank) parameter\n");
479 if (launch_proc(rval) != 0) {
480 printf("Error - process did not run ok with valid -r (rank) value\n");
487 * Test that the app doesn't run without the coremask flag. In all cases
488 * should give an error and fail to run
491 test_missing_c_flag(void)
493 #ifdef RTE_EXEC_ENV_BSDAPP
494 /* BSD target doesn't support prefixes at this point */
495 const char * prefix = "";
497 char prefix[PATH_MAX], tmp[PATH_MAX];
498 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
499 printf("Error - unable to get current prefix!\n");
502 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
505 /* -c flag but no coremask value */
506 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "3", "-c"};
507 /* No -c flag at all */
508 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "3"};
509 /* bad coremask value */
510 const char *argv3[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "error" };
511 /* sanity check of tests - valid coremask value */
512 const char *argv4[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "1" };
514 if (launch_proc(argv1) == 0
515 || launch_proc(argv2) == 0
516 || launch_proc(argv3) == 0) {
517 printf("Error - process ran without error when missing -c flag\n");
520 if (launch_proc(argv4) != 0) {
521 printf("Error - process did not run ok with valid coremask value\n");
528 * Test that the app doesn't run without the -n flag. In all cases
529 * should give an error and fail to run.
530 * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
534 test_missing_n_flag(void)
536 #ifdef RTE_EXEC_ENV_BSDAPP
537 /* BSD target doesn't support prefixes at this point */
538 const char * prefix = "";
540 char prefix[PATH_MAX], tmp[PATH_MAX];
541 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
542 printf("Error - unable to get current prefix!\n");
545 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
548 /* -n flag but no value */
549 const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"};
550 /* No -n flag at all */
551 const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"};
552 /* bad numeric value */
553 const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" };
554 /* out-of-range value */
555 const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "9" };
556 /* sanity test - check with good value */
557 const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" };
559 if (launch_proc(argv1) == 0
560 || launch_proc(argv2) == 0
561 || launch_proc(argv3) == 0
562 || launch_proc(argv4) == 0) {
563 printf("Error - process ran without error when missing -n flag\n");
566 if (launch_proc(argv5) != 0) {
567 printf("Error - process did not run ok with valid num-channel value\n");
574 * Test that the app runs with HPET, and without HPET
577 test_no_hpet_flag(void)
579 char prefix[PATH_MAX], tmp[PATH_MAX];
581 #ifdef RTE_EXEC_ENV_BSDAPP
584 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
585 printf("Error - unable to get current prefix!\n");
588 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
591 const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"};
592 /* Without --no-hpet */
593 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-n", "2"};
595 if (launch_proc(argv1) != 0) {
596 printf("Error - process did not run ok with --no-hpet flag\n");
599 if (launch_proc(argv2) != 0) {
600 printf("Error - process did not run ok without --no-hpet flag\n");
607 * Test that the app runs with --no-huge and doesn't run when either
608 * -m or --socket-mem are specified with --no-huge.
611 test_no_huge_flag(void)
613 #ifdef RTE_EXEC_ENV_BSDAPP
614 /* BSD target doesn't support prefixes at this point, and we also need to
615 * run another primary process here */
616 const char * prefix = no_shconf;
618 const char * prefix = "--file-prefix=nohuge";
622 const char *argv1[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2"};
623 /* With --no-huge and -m */
624 const char *argv2[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
625 "-m", DEFAULT_MEM_SIZE};
627 /* With --no-huge and --socket-mem */
628 const char *argv3[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
629 "--socket-mem=" DEFAULT_MEM_SIZE};
630 /* With --no-huge, -m and --socket-mem */
631 const char *argv4[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
632 "-m", DEFAULT_MEM_SIZE, "--socket-mem=" DEFAULT_MEM_SIZE};
633 if (launch_proc(argv1) != 0) {
634 printf("Error - process did not run ok with --no-huge flag\n");
637 if (launch_proc(argv2) == 0) {
638 printf("Error - process run ok with --no-huge and -m flags\n");
641 #ifdef RTE_EXEC_ENV_BSDAPP
642 /* BSD target does not support NUMA, hence no --socket-mem tests */
646 if (launch_proc(argv3) == 0) {
647 printf("Error - process run ok with --no-huge and --socket-mem "
651 if (launch_proc(argv4) == 0) {
652 printf("Error - process run ok with --no-huge, -m and "
653 "--socket-mem flags\n");
659 #ifdef RTE_LIBRTE_XEN_DOM0
661 test_dom0_misc_flags(void)
663 char prefix[PATH_MAX], tmp[PATH_MAX];
665 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
666 printf("Error - unable to get current prefix!\n");
669 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
671 /* check that some general flags don't prevent things from working.
672 * All cases, apart from the first, app should run.
673 * No futher testing of output done.
675 /* sanity check - failure with invalid option */
676 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
679 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
681 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
682 /* With valid --syslog */
683 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
684 "--syslog", "syslog"};
685 /* With empty --syslog (should fail) */
686 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
687 /* With invalid --syslog */
688 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
689 /* With no-sh-conf */
690 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "20",
691 "--no-shconf", "--file-prefix=noshconf" };
693 if (launch_proc(argv0) == 0) {
694 printf("Error - process ran ok with invalid flag\n");
697 if (launch_proc(argv1) != 0) {
698 printf("Error - process did not run ok with --no-pci flag\n");
701 if (launch_proc(argv2) != 0) {
702 printf("Error - process did not run ok with -v flag\n");
705 if (launch_proc(argv3) != 0) {
706 printf("Error - process did not run ok with --syslog flag\n");
709 if (launch_proc(argv4) == 0) {
710 printf("Error - process run ok with empty --syslog flag\n");
713 if (launch_proc(argv5) == 0) {
714 printf("Error - process run ok with invalid --syslog flag\n");
717 if (launch_proc(argv6) != 0) {
718 printf("Error - process did not run ok with --no-shconf flag\n");
726 test_misc_flags(void)
728 char hugepath[PATH_MAX] = {0};
729 #ifdef RTE_EXEC_ENV_BSDAPP
730 /* BSD target doesn't support prefixes at this point */
731 const char * prefix = "";
732 const char * nosh_prefix = "";
734 char prefix[PATH_MAX], tmp[PATH_MAX];
735 const char * nosh_prefix = "--file-prefix=noshconf";
736 FILE * hugedir_handle = NULL;
737 char line[PATH_MAX] = {0};
738 unsigned i, isempty = 1;
739 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
740 printf("Error - unable to get current prefix!\n");
743 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
746 * get first valid hugepage path
749 /* get hugetlbfs mountpoints from /proc/mounts */
750 hugedir_handle = fopen("/proc/mounts", "r");
752 if (hugedir_handle == NULL) {
753 printf("Error opening /proc/mounts!\n");
757 /* read /proc/mounts */
758 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
760 /* find first valid hugepath */
761 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
765 fclose(hugedir_handle);
767 /* check if path is not empty */
768 for (i = 0; i < sizeof(hugepath); i++)
769 if (hugepath[i] != '\0')
773 printf("No mounted hugepage dir found!\n");
779 /* check that some general flags don't prevent things from working.
780 * All cases, apart from the first, app should run.
781 * No futher testing of output done.
783 /* sanity check - failure with invalid option */
784 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
787 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
789 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
790 /* With valid --syslog */
791 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
792 "--syslog", "syslog"};
793 /* With empty --syslog (should fail) */
794 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
795 /* With invalid --syslog */
796 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
797 /* With no-sh-conf */
798 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
799 no_shconf, nosh_prefix };
801 #ifdef RTE_EXEC_ENV_BSDAPP
804 /* With --huge-dir */
805 const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
806 "--file-prefix=hugedir", "--huge-dir", hugepath};
807 /* With empty --huge-dir (should fail) */
808 const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
809 "--file-prefix=hugedir", "--huge-dir"};
810 /* With invalid --huge-dir */
811 const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
812 "--file-prefix=hugedir", "--huge-dir", "invalid"};
813 /* Secondary process with invalid --huge-dir (should run as flag has no
814 * effect on secondary processes) */
815 const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
817 /* try running with base-virtaddr param */
818 const char *argv11[] = {prgname, "--file-prefix=virtaddr",
819 "-c", "1", "-n", "2", "--base-virtaddr=0x12345678"};
821 /* try running with --vfio-intr INTx flag */
822 const char *argv12[] = {prgname, "--file-prefix=intr",
823 "-c", "1", "-n", "2", "--vfio-intr=legacy"};
825 /* try running with --vfio-intr MSI flag */
826 const char *argv13[] = {prgname, "--file-prefix=intr",
827 "-c", "1", "-n", "2", "--vfio-intr=msi"};
829 /* try running with --vfio-intr MSI-X flag */
830 const char *argv14[] = {prgname, "--file-prefix=intr",
831 "-c", "1", "-n", "2", "--vfio-intr=msix"};
833 /* try running with --vfio-intr invalid flag */
834 const char *argv15[] = {prgname, "--file-prefix=intr",
835 "-c", "1", "-n", "2", "--vfio-intr=invalid"};
838 if (launch_proc(argv0) == 0) {
839 printf("Error - process ran ok with invalid flag\n");
842 if (launch_proc(argv1) != 0) {
843 printf("Error - process did not run ok with --no-pci flag\n");
846 if (launch_proc(argv2) != 0) {
847 printf("Error - process did not run ok with -v flag\n");
850 if (launch_proc(argv3) != 0) {
851 printf("Error - process did not run ok with --syslog flag\n");
854 if (launch_proc(argv4) == 0) {
855 printf("Error - process run ok with empty --syslog flag\n");
858 if (launch_proc(argv5) == 0) {
859 printf("Error - process run ok with invalid --syslog flag\n");
862 if (launch_proc(argv6) != 0) {
863 printf("Error - process did not run ok with --no-shconf flag\n");
866 #ifdef RTE_EXEC_ENV_BSDAPP
869 if (launch_proc(argv7) != 0) {
870 printf("Error - process did not run ok with --huge-dir flag\n");
873 if (launch_proc(argv8) == 0) {
874 printf("Error - process run ok with empty --huge-dir flag\n");
877 if (launch_proc(argv9) == 0) {
878 printf("Error - process run ok with invalid --huge-dir flag\n");
881 if (launch_proc(argv10) != 0) {
882 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
885 if (launch_proc(argv11) != 0) {
886 printf("Error - process did not run ok with --base-virtaddr parameter\n");
889 if (launch_proc(argv12) != 0) {
890 printf("Error - process did not run ok with "
891 "--vfio-intr INTx parameter\n");
894 if (launch_proc(argv13) != 0) {
895 printf("Error - process did not run ok with "
896 "--vfio-intr MSI parameter\n");
899 if (launch_proc(argv14) != 0) {
900 printf("Error - process did not run ok with "
901 "--vfio-intr MSI-X parameter\n");
904 if (launch_proc(argv15) == 0) {
905 printf("Error - process run ok with "
906 "--vfio-intr invalid parameter\n");
914 test_file_prefix(void)
917 * 1. check if current process hugefiles are locked
918 * 2. try to run secondary process without a corresponding primary process
919 * (while failing to run, it will also remove any unused hugepage files)
920 * 3. check if current process hugefiles are still in place and are locked
921 * 4. run a primary process with memtest1 prefix
922 * 5. check if memtest1 hugefiles are created
923 * 6. run a primary process with memtest2 prefix
924 * 7. check that only memtest2 hugefiles are present in the hugedir
927 #ifdef RTE_EXEC_ENV_BSDAPP
931 /* this should fail unless the test itself is run with "memtest" prefix */
932 const char *argv0[] = {prgname, mp_flag, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
933 "--file-prefix=" memtest };
935 /* primary process with memtest1 */
936 const char *argv1[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
937 "--file-prefix=" memtest1 };
939 /* primary process with memtest2 */
940 const char *argv2[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
941 "--file-prefix=" memtest2 };
944 if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
945 printf("Error - unable to get current prefix!\n");
948 #ifdef RTE_LIBRTE_XEN_DOM0
952 /* check if files for current prefix are present */
953 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
954 printf("Error - hugepage files for %s were not created!\n", prefix);
958 /* checks if files for current prefix are locked */
959 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
960 printf("Error - hugepages for current process aren't locked!\n");
964 /* check if files for secondary process are present */
965 if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
966 /* check if they are not locked */
967 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
968 printf("Error - hugepages for current process are locked!\n");
971 /* they aren't locked, delete them */
973 if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
974 printf("Error - deleting hugepages failed!\n");
980 if (launch_proc(argv0) == 0) {
981 printf("Error - secondary process ran ok without primary process\n");
985 /* check if files for current prefix are present */
986 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
987 printf("Error - hugepage files for %s were not created!\n", prefix);
991 /* checks if files for current prefix are locked */
992 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
993 printf("Error - hugepages for current process aren't locked!\n");
997 if (launch_proc(argv1) != 0) {
998 printf("Error - failed to run with --file-prefix=%s\n", memtest);
1002 /* check if memtest1_map0 is present */
1003 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
1004 printf("Error - hugepage files for %s were not created!\n", memtest1);
1008 if (launch_proc(argv2) != 0) {
1009 printf("Error - failed to run with --file-prefix=%s\n", memtest2);
1013 /* check if hugefiles for memtest2 are present */
1014 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
1015 printf("Error - hugepage files for %s were not created!\n", memtest2);
1019 /* check if hugefiles for memtest1 are present */
1020 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1021 printf("Error - hugepage files for %s were not deleted!\n", memtest1);
1029 * Tests for correct handling of -m and --socket-mem flags
1032 test_memory_flags(void)
1034 #ifdef RTE_EXEC_ENV_BSDAPP
1035 /* BSD target doesn't support prefixes at this point */
1036 const char * prefix = "";
1038 char prefix[PATH_MAX], tmp[PATH_MAX];
1039 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
1040 printf("Error - unable to get current prefix!\n");
1043 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
1046 /* valid -m flag and mp flag */
1047 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "10",
1048 "-n", "2", "-m", DEFAULT_MEM_SIZE};
1051 const char *argv1[] = {prgname, "-c", "10", "-n", "2",
1052 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE};
1054 /* invalid (zero) --socket-mem flag */
1055 const char *argv2[] = {prgname, "-c", "10", "-n", "2",
1056 "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
1058 /* invalid (incomplete) --socket-mem flag */
1059 const char *argv3[] = {prgname, "-c", "10", "-n", "2",
1060 "--file-prefix=" memtest, "--socket-mem=2,2,"};
1062 /* invalid (mixed with invalid data) --socket-mem flag */
1063 const char *argv4[] = {prgname, "-c", "10", "-n", "2",
1064 "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
1066 /* invalid (with numeric value as last character) --socket-mem flag */
1067 const char *argv5[] = {prgname, "-c", "10", "-n", "2",
1068 "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
1070 /* invalid (with empty socket) --socket-mem flag */
1071 const char *argv6[] = {prgname, "-c", "10", "-n", "2",
1072 "--file-prefix=" memtest, "--socket-mem=2,,2"};
1074 /* invalid (null) --socket-mem flag */
1075 const char *argv7[] = {prgname, "-c", "10", "-n", "2",
1076 "--file-prefix=" memtest, "--socket-mem="};
1078 /* valid --socket-mem specified together with -m flag */
1079 const char *argv8[] = {prgname, "-c", "10", "-n", "2",
1080 "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE, "--socket-mem=2,2"};
1082 /* construct an invalid socket mask with 2 megs on each socket plus
1083 * extra 2 megs on socket that doesn't exist on current system */
1084 char invalid_socket_mem[SOCKET_MEM_STRLEN];
1085 char buf[SOCKET_MEM_STRLEN]; /* to avoid copying string onto itself */
1087 #ifdef RTE_EXEC_ENV_BSDAPP
1088 int i, num_sockets = 1;
1090 int i, num_sockets = get_number_of_sockets();
1093 if (num_sockets <= 0 || num_sockets > RTE_MAX_NUMA_NODES) {
1094 printf("Error - cannot get number of sockets!\n");
1098 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
1100 /* add one extra socket */
1101 for (i = 0; i < num_sockets + 1; i++) {
1102 snprintf(buf, sizeof(buf), "%s%s", invalid_socket_mem, DEFAULT_MEM_SIZE);
1103 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1105 if (num_sockets + 1 - i > 1) {
1106 snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
1107 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1111 /* construct a valid socket mask with 2 megs on each existing socket */
1112 char valid_socket_mem[SOCKET_MEM_STRLEN];
1114 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
1116 /* add one extra socket */
1117 for (i = 0; i < num_sockets; i++) {
1118 snprintf(buf, sizeof(buf), "%s%s", valid_socket_mem, DEFAULT_MEM_SIZE);
1119 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1121 if (num_sockets - i > 1) {
1122 snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
1123 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1127 /* invalid --socket-mem flag (with extra socket) */
1128 const char *argv9[] = {prgname, "-c", "10", "-n", "2",
1129 "--file-prefix=" memtest, invalid_socket_mem};
1131 /* valid --socket-mem flag */
1132 const char *argv10[] = {prgname, "-c", "10", "-n", "2",
1133 "--file-prefix=" memtest, valid_socket_mem};
1135 if (launch_proc(argv0) != 0) {
1136 printf("Error - secondary process failed with valid -m flag !\n");
1140 #ifdef RTE_EXEC_ENV_BSDAPP
1141 /* no other tests are applicable to BSD */
1145 if (launch_proc(argv1) != 0) {
1146 printf("Error - process failed with valid -m flag!\n");
1149 #ifdef RTE_LIBRTE_XEN_DOM0
1152 if (launch_proc(argv2) == 0) {
1153 printf("Error - process run ok with invalid (zero) --socket-mem!\n");
1157 if (launch_proc(argv3) == 0) {
1158 printf("Error - process run ok with invalid "
1159 "(incomplete) --socket-mem!\n");
1163 if (launch_proc(argv4) == 0) {
1164 printf("Error - process run ok with invalid "
1165 "(mixed with invalid input) --socket-mem!\n");
1169 if (launch_proc(argv5) == 0) {
1170 printf("Error - process run ok with invalid "
1171 "(mixed with invalid input with a numeric value as "
1172 "last character) --socket-mem!\n");
1176 if (launch_proc(argv6) == 0) {
1177 printf("Error - process run ok with invalid "
1178 "(with empty socket) --socket-mem!\n");
1182 if (launch_proc(argv7) == 0) {
1183 printf("Error - process run ok with invalid (null) --socket-mem!\n");
1187 if (launch_proc(argv8) == 0) {
1188 printf("Error - process run ok with --socket-mem and -m specified!\n");
1192 if (launch_proc(argv9) == 0) {
1193 printf("Error - process run ok with extra socket in --socket-mem!\n");
1197 if (launch_proc(argv10) != 0) {
1198 printf("Error - process failed with valid --socket-mem!\n");
1206 test_eal_flags(void)
1210 ret = test_missing_c_flag();
1212 printf("Error in test_missing_c_flag()\n");
1216 ret = test_missing_n_flag();
1218 printf("Error in test_missing_n_flag()\n");
1222 ret = test_no_hpet_flag();
1224 printf("Error in test_no_hpet_flag()\n");
1228 ret = test_no_huge_flag();
1230 printf("Error in test_no_huge_flag()\n");
1234 ret = test_whitelist_flag();
1236 printf("Error in test_invalid_whitelist_flag()\n");
1240 ret = test_invalid_b_flag();
1242 printf("Error in test_invalid_b_flag()\n");
1246 #ifdef RTE_LIBRTE_PMD_RING
1247 ret = test_invalid_vdev_flag();
1249 printf("Error in test_invalid_vdev_flag()\n");
1253 ret = test_invalid_r_flag();
1255 printf("Error in test_invalid_r_flag()\n");
1259 ret = test_memory_flags();
1261 printf("Error in test_memory_flags()\n");
1265 ret = test_file_prefix();
1267 printf("Error in test_file_prefix()\n");
1271 #ifdef RTE_LIBRTE_XEN_DOM0
1272 ret = test_dom0_misc_flags();
1274 ret = test_misc_flags();
1277 printf("Error in test_misc_flags()");
1284 static struct test_command eal_flags_cmd = {
1285 .command = "eal_flags_autotest",
1286 .callback = test_eal_flags,
1288 REGISTER_TEST_COMMAND(eal_flags_cmd);