4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <cmdline_parse.h>
39 #ifndef RTE_EXEC_ENV_BAREMETAL
52 #include <rte_debug.h>
53 #include <rte_string_fns.h>
57 #define mp_flag "--proc-type=secondary"
58 #define no_hpet "--no-hpet"
59 #define no_huge "--no-huge"
60 #define no_shconf "--no-shconf"
61 #define use_device "--use-device"
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 rte_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 = rte_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 rte_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 rte_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 rte_snprintf(buf, sizeof(buf), "%s", basename(buf));
269 /* copy string all the way from second char up to start of _config */
270 rte_snprintf(prefix, size, "%.*s",
271 strnlen(buf, sizeof(buf)) - sizeof("_config"), &buf[1]);
276 /* extra function prototypes for internal eal function to test in whitelist
277 * ICC 12 doesn't approve of this practice, so temporarily disable warnings for it */
278 #ifdef __INTEL_COMPILER
279 #pragma warning disable 1419
281 extern int eal_dev_whitelist_exists(void);
282 extern int eal_dev_whitelist_add_entry(const char *);
283 extern int eal_dev_whitelist_parse(void);
284 extern int eal_dev_is_whitelisted(const char *, const char **);
285 extern void eal_dev_whitelist_clear(void);
286 #ifdef __INTEL_COMPILER
287 #pragma warning enable 1419
291 * Test that the app doesn't run with invalid whitelist option.
292 * Final tests ensures it does run with valid options as sanity check (one
293 * test for with Domain+BDF, second for just with BDF)
296 test_whitelist_flag(void)
299 #ifdef RTE_EXEC_ENV_BSDAPP
300 /* BSD target doesn't support prefixes at this point */
301 const char * prefix = "";
303 char prefix[PATH_MAX], tmp[PATH_MAX];
304 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
305 printf("Error - unable to get current prefix!\n");
308 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
311 const char *wlinval[][11] = {
312 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
313 use_device, "error", "", ""},
314 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
315 use_device, "0:0:0", "", ""},
316 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
317 use_device, "0:error:0.1", "", ""},
318 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
319 use_device, "0:0:0.1error", "", ""},
320 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
321 use_device, "error0:0:0.1", "", ""},
322 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
323 use_device, "0:0:0.1.2", "", ""},
324 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
325 use_device, "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x",
326 use_device, "y,z,1,2,3,4,5,6,7,8,9,0"},
328 /* Test with valid whitelist option */
329 const char *wlval1[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
330 use_device, "00FF:09:0B.3"};
331 const char *wlval2[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
332 use_device, "09:0B.3,0a:0b.1"};
333 const char *wlval3[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
334 use_device, "09:0B.3;type=test,08:00.1;type=normal"};
336 for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
337 if (launch_proc(wlinval[i]) == 0) {
338 printf("Error - process did run ok with invalid "
339 "whitelist parameter\n");
343 if (launch_proc(wlval1) != 0 ) {
344 printf("Error - process did not run ok with valid whitelist\n");
347 if (launch_proc(wlval2) != 0 ) {
348 printf("Error - process did not run ok with valid whitelist value set\n");
351 if (launch_proc(wlval3) != 0 ) {
352 printf("Error - process did not run ok with valid whitelist + args\n");
356 /* extra-sanity checks of whitelists - to be run only if no whitelist */
357 if (eal_dev_whitelist_exists())
360 /* check that whitelist_parse returns error without whitelist */
361 if (eal_dev_whitelist_parse() != -1) {
362 printf("ERROR: calling whitelist parse without a whitelist doesn't "
363 "return an error\n");
366 if (eal_dev_is_whitelisted("adevice", NULL)) {
367 printf("Whitelist lookup does not return false if no whitelist\n");
370 eal_dev_whitelist_add_entry("0000:00:00.0");
371 eal_dev_whitelist_parse();
372 if (eal_dev_is_whitelisted("adevice", NULL)) {
373 printf("Whitelist lookup does not return false for unlisted dev\n");
376 if (!eal_dev_is_whitelisted("0000:00:00.0", NULL)) {
377 printf("Whitelist lookup does not return true for whitelisted dev\n");
380 eal_dev_whitelist_clear();
386 * Test that the app doesn't run with invalid blacklist option.
387 * Final test ensures it does run with valid options as sanity check
390 test_invalid_b_flag(void)
392 #ifdef RTE_EXEC_ENV_BSDAPP
393 /* BSD target doesn't support prefixes at this point */
394 const char * prefix = "";
396 char prefix[PATH_MAX], tmp[PATH_MAX];
397 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
398 printf("Error - unable to get current prefix!\n");
401 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
404 const char *blinval[][9] = {
405 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error"},
406 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0"},
407 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:error:0.1"},
408 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1error"},
409 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error0:0:0.1"},
410 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1.2"},
412 /* Test with valid blacklist option */
413 const char *blval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
417 for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
418 if (launch_proc(blinval[i]) == 0) {
419 printf("Error - process did run ok with invalid "
420 "blacklist parameter\n");
424 if (launch_proc(blval) != 0) {
425 printf("Error - process did not run ok with valid blacklist value\n");
433 * Test that the app doesn't run with invalid -r option.
436 test_invalid_r_flag(void)
438 #ifdef RTE_EXEC_ENV_BSDAPP
439 /* BSD target doesn't support prefixes at this point */
440 const char * prefix = "";
442 char prefix[PATH_MAX], tmp[PATH_MAX];
443 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
444 printf("Error - unable to get current prefix!\n");
447 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
450 const char *rinval[][9] = {
451 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "error"},
452 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "0"},
453 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "-1"},
454 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "17"},
456 /* Test with valid blacklist option */
457 const char *rval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
461 for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
462 if (launch_proc(rinval[i]) == 0) {
463 printf("Error - process did run ok with invalid "
464 "-r (rank) parameter\n");
468 if (launch_proc(rval) != 0) {
469 printf("Error - process did not run ok with valid -r (rank) value\n");
476 * Test that the app doesn't run without the coremask flag. In all cases
477 * should give an error and fail to run
480 test_missing_c_flag(void)
482 #ifdef RTE_EXEC_ENV_BSDAPP
483 /* BSD target doesn't support prefixes at this point */
484 const char * prefix = "";
486 char prefix[PATH_MAX], tmp[PATH_MAX];
487 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
488 printf("Error - unable to get current prefix!\n");
491 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
494 /* -c flag but no coremask value */
495 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "3", "-c"};
496 /* No -c flag at all */
497 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "3"};
498 /* bad coremask value */
499 const char *argv3[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "error" };
500 /* sanity check of tests - valid coremask value */
501 const char *argv4[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "1" };
503 if (launch_proc(argv1) == 0
504 || launch_proc(argv2) == 0
505 || launch_proc(argv3) == 0) {
506 printf("Error - process ran without error when missing -c flag\n");
509 if (launch_proc(argv4) != 0) {
510 printf("Error - process did not run ok with valid coremask value\n");
517 * Test that the app doesn't run without the -n flag. In all cases
518 * should give an error and fail to run.
519 * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
523 test_missing_n_flag(void)
525 #ifdef RTE_EXEC_ENV_BSDAPP
526 /* BSD target doesn't support prefixes at this point */
527 const char * prefix = "";
529 char prefix[PATH_MAX], tmp[PATH_MAX];
530 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
531 printf("Error - unable to get current prefix!\n");
534 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
537 /* -n flag but no value */
538 const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"};
539 /* No -n flag at all */
540 const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"};
541 /* bad numeric value */
542 const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" };
543 /* out-of-range value */
544 const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "9" };
545 /* sanity test - check with good value */
546 const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" };
548 if (launch_proc(argv1) == 0
549 || launch_proc(argv2) == 0
550 || launch_proc(argv3) == 0
551 || launch_proc(argv4) == 0) {
552 printf("Error - process ran without error when missing -n flag\n");
555 if (launch_proc(argv5) != 0) {
556 printf("Error - process did not run ok with valid num-channel value\n");
563 * Test that the app runs with HPET, and without HPET
566 test_no_hpet_flag(void)
568 char prefix[PATH_MAX], tmp[PATH_MAX];
570 #ifdef RTE_EXEC_ENV_BSDAPP
573 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
574 printf("Error - unable to get current prefix!\n");
577 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
580 const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"};
581 /* Without --no-hpet */
582 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-n", "2"};
584 if (launch_proc(argv1) != 0) {
585 printf("Error - process did not run ok with --no-hpet flag\n");
588 if (launch_proc(argv2) != 0) {
589 printf("Error - process did not run ok without --no-hpet flag\n");
596 * Test that the app runs with --no-huge and doesn't run when either
597 * -m or --socket-mem are specified with --no-huge.
600 test_no_huge_flag(void)
602 #ifdef RTE_EXEC_ENV_BSDAPP
603 /* BSD target doesn't support prefixes at this point, and we also need to
604 * run another primary process here */
605 const char * prefix = no_shconf;
607 const char * prefix = "--file-prefix=nohuge";
611 const char *argv1[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2"};
612 /* With --no-huge and -m */
613 const char *argv2[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2", "-m", "2"};
615 /* With --no-huge and --socket-mem */
616 const char *argv3[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
618 /* With --no-huge, -m and --socket-mem */
619 const char *argv4[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
620 "-m", "2", "--socket-mem=2"};
621 if (launch_proc(argv1) != 0) {
622 printf("Error - process did not run ok with --no-huge flag\n");
625 if (launch_proc(argv2) == 0) {
626 printf("Error - process run ok with --no-huge and -m flags\n");
629 #ifdef RTE_EXEC_ENV_BSDAPP
630 /* BSD target does not support NUMA, hence no --socket-mem tests */
634 if (launch_proc(argv3) == 0) {
635 printf("Error - process run ok with --no-huge and --socket-mem "
639 if (launch_proc(argv4) == 0) {
640 printf("Error - process run ok with --no-huge, -m and "
641 "--socket-mem flags\n");
647 #ifdef RTE_LIBRTE_XEN_DOM0
649 test_dom0_misc_flags(void)
651 char prefix[PATH_MAX], tmp[PATH_MAX];
653 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
654 printf("Error - unable to get current prefix!\n");
657 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
659 /* check that some general flags don't prevent things from working.
660 * All cases, apart from the first, app should run.
661 * No futher testing of output done.
663 /* sanity check - failure with invalid option */
664 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
667 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
669 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
670 /* With valid --syslog */
671 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
672 "--syslog", "syslog"};
673 /* With empty --syslog (should fail) */
674 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
675 /* With invalid --syslog */
676 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
677 /* With no-sh-conf */
678 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "20",
679 "--no-shconf", "--file-prefix=noshconf" };
681 if (launch_proc(argv0) == 0) {
682 printf("Error - process ran ok with invalid flag\n");
685 if (launch_proc(argv1) != 0) {
686 printf("Error - process did not run ok with --no-pci flag\n");
689 if (launch_proc(argv2) != 0) {
690 printf("Error - process did not run ok with -v flag\n");
693 if (launch_proc(argv3) != 0) {
694 printf("Error - process did not run ok with --syslog flag\n");
697 if (launch_proc(argv4) == 0) {
698 printf("Error - process run ok with empty --syslog flag\n");
701 if (launch_proc(argv5) == 0) {
702 printf("Error - process run ok with invalid --syslog flag\n");
705 if (launch_proc(argv6) != 0) {
706 printf("Error - process did not run ok with --no-shconf flag\n");
714 test_misc_flags(void)
716 char hugepath[PATH_MAX] = {0};
717 #ifdef RTE_EXEC_ENV_BSDAPP
718 /* BSD target doesn't support prefixes at this point */
719 const char * prefix = "";
720 const char * nosh_prefix = "";
722 char prefix[PATH_MAX], tmp[PATH_MAX];
723 const char * nosh_prefix = "--file-prefix=noshconf";
724 FILE * hugedir_handle = NULL;
725 char line[PATH_MAX] = {0};
726 unsigned i, isempty = 1;
727 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
728 printf("Error - unable to get current prefix!\n");
731 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
734 * get first valid hugepage path
737 /* get hugetlbfs mountpoints from /proc/mounts */
738 hugedir_handle = fopen("/proc/mounts", "r");
740 if (hugedir_handle == NULL) {
741 printf("Error opening /proc/mounts!\n");
745 /* read /proc/mounts */
746 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
748 /* find first valid hugepath */
749 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
753 fclose(hugedir_handle);
755 /* check if path is not empty */
756 for (i = 0; i < sizeof(hugepath); i++)
757 if (hugepath[i] != '\0')
761 printf("No mounted hugepage dir found!\n");
767 /* check that some general flags don't prevent things from working.
768 * All cases, apart from the first, app should run.
769 * No futher testing of output done.
771 /* sanity check - failure with invalid option */
772 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
775 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
777 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
778 /* With valid --syslog */
779 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
780 "--syslog", "syslog"};
781 /* With empty --syslog (should fail) */
782 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
783 /* With invalid --syslog */
784 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
785 /* With no-sh-conf */
786 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
787 no_shconf, nosh_prefix };
789 #ifdef RTE_EXEC_ENV_BSDAPP
792 /* With --huge-dir */
793 const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
794 "--file-prefix=hugedir", "--huge-dir", hugepath};
795 /* With empty --huge-dir (should fail) */
796 const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
797 "--file-prefix=hugedir", "--huge-dir"};
798 /* With invalid --huge-dir */
799 const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
800 "--file-prefix=hugedir", "--huge-dir", "invalid"};
801 /* Secondary process with invalid --huge-dir (should run as flag has no
802 * effect on secondary processes) */
803 const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
805 /* try running with base-virtaddr param */
806 const char *argv11[] = {prgname, "--file-prefix=virtaddr",
807 "-c", "1", "-n", "2", "--base-virtaddr=0x12345678"};
810 if (launch_proc(argv0) == 0) {
811 printf("Error - process ran ok with invalid flag\n");
814 if (launch_proc(argv1) != 0) {
815 printf("Error - process did not run ok with --no-pci flag\n");
818 if (launch_proc(argv2) != 0) {
819 printf("Error - process did not run ok with -v flag\n");
822 if (launch_proc(argv3) != 0) {
823 printf("Error - process did not run ok with --syslog flag\n");
826 if (launch_proc(argv4) == 0) {
827 printf("Error - process run ok with empty --syslog flag\n");
830 if (launch_proc(argv5) == 0) {
831 printf("Error - process run ok with invalid --syslog flag\n");
834 if (launch_proc(argv6) != 0) {
835 printf("Error - process did not run ok with --no-shconf flag\n");
838 #ifdef RTE_EXEC_ENV_BSDAPP
841 if (launch_proc(argv7) != 0) {
842 printf("Error - process did not run ok with --huge-dir flag\n");
845 if (launch_proc(argv8) == 0) {
846 printf("Error - process run ok with empty --huge-dir flag\n");
849 if (launch_proc(argv9) == 0) {
850 printf("Error - process run ok with invalid --huge-dir flag\n");
853 if (launch_proc(argv10) != 0) {
854 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
857 if (launch_proc(argv11) != 0) {
858 printf("Error - process did not run ok with --base-virtaddr parameter\n");
866 test_file_prefix(void)
869 * 1. check if current process hugefiles are locked
870 * 2. try to run secondary process without a corresponding primary process
871 * (while failing to run, it will also remove any unused hugepage files)
872 * 3. check if current process hugefiles are still in place and are locked
873 * 4. run a primary process with memtest1 prefix
874 * 5. check if memtest1 hugefiles are created
875 * 6. run a primary process with memtest2 prefix
876 * 7. check that only memtest2 hugefiles are present in the hugedir
879 #ifdef RTE_EXEC_ENV_BSDAPP
883 /* this should fail unless the test itself is run with "memtest" prefix */
884 const char *argv0[] = {prgname, mp_flag, "-c", "1", "-n", "2", "-m", "2",
885 "--file-prefix=" memtest };
887 /* primary process with memtest1 */
888 const char *argv1[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
889 "--file-prefix=" memtest1 };
891 /* primary process with memtest2 */
892 const char *argv2[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
893 "--file-prefix=" memtest2 };
896 if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
897 printf("Error - unable to get current prefix!\n");
900 #ifdef RTE_LIBRTE_XEN_DOM0
904 /* check if files for current prefix are present */
905 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
906 printf("Error - hugepage files for %s were not created!\n", prefix);
910 /* checks if files for current prefix are locked */
911 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
912 printf("Error - hugepages for current process aren't locked!\n");
916 /* check if files for secondary process are present */
917 if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
918 /* check if they are not locked */
919 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
920 printf("Error - hugepages for current process are locked!\n");
923 /* they aren't locked, delete them */
925 if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
926 printf("Error - deleting hugepages failed!\n");
932 if (launch_proc(argv0) == 0) {
933 printf("Error - secondary process ran ok without primary process\n");
937 /* check if files for current prefix are present */
938 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
939 printf("Error - hugepage files for %s were not created!\n", prefix);
943 /* checks if files for current prefix are locked */
944 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
945 printf("Error - hugepages for current process aren't locked!\n");
949 if (launch_proc(argv1) != 0) {
950 printf("Error - failed to run with --file-prefix=%s\n", memtest);
954 /* check if memtest1_map0 is present */
955 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
956 printf("Error - hugepage files for %s were not created!\n", memtest1);
960 if (launch_proc(argv2) != 0) {
961 printf("Error - failed to run with --file-prefix=%s\n", memtest2);
965 /* check if hugefiles for memtest2 are present */
966 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
967 printf("Error - hugepage files for %s were not created!\n", memtest2);
971 /* check if hugefiles for memtest1 are present */
972 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
973 printf("Error - hugepage files for %s were not deleted!\n", memtest1);
981 * Tests for correct handling of -m and --socket-mem flags
984 test_memory_flags(void)
986 const char* mem_size = NULL;
987 #ifdef RTE_EXEC_ENV_BSDAPP
988 /* BSD target doesn't support prefixes at this point */
989 const char * prefix = "";
991 char prefix[PATH_MAX], tmp[PATH_MAX];
992 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
993 printf("Error - unable to get current prefix!\n");
996 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
998 #ifdef RTE_LIBRTE_XEN_DOM0
1005 /* valid -m flag and mp flag */
1006 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "10",
1007 "-n", "2", "-m", mem_size};
1010 const char *argv1[] = {prgname, "-c", "10", "-n", "2",
1011 "--file-prefix=" memtest, "-m", mem_size};
1013 /* invalid (zero) --socket-mem flag */
1014 const char *argv2[] = {prgname, "-c", "10", "-n", "2",
1015 "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
1017 /* invalid (incomplete) --socket-mem flag */
1018 const char *argv3[] = {prgname, "-c", "10", "-n", "2",
1019 "--file-prefix=" memtest, "--socket-mem=2,2,"};
1021 /* invalid (mixed with invalid data) --socket-mem flag */
1022 const char *argv4[] = {prgname, "-c", "10", "-n", "2",
1023 "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
1025 /* invalid (with numeric value as last character) --socket-mem flag */
1026 const char *argv5[] = {prgname, "-c", "10", "-n", "2",
1027 "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
1029 /* invalid (with empty socket) --socket-mem flag */
1030 const char *argv6[] = {prgname, "-c", "10", "-n", "2",
1031 "--file-prefix=" memtest, "--socket-mem=2,,2"};
1033 /* invalid (null) --socket-mem flag */
1034 const char *argv7[] = {prgname, "-c", "10", "-n", "2",
1035 "--file-prefix=" memtest, "--socket-mem="};
1037 /* valid --socket-mem specified together with -m flag */
1038 const char *argv8[] = {prgname, "-c", "10", "-n", "2",
1039 "--file-prefix=" memtest, "-m", "2", "--socket-mem=2,2"};
1041 /* construct an invalid socket mask with 2 megs on each socket plus
1042 * extra 2 megs on socket that doesn't exist on current system */
1043 char invalid_socket_mem[SOCKET_MEM_STRLEN];
1044 char buf[SOCKET_MEM_STRLEN]; /* to avoid copying string onto itself */
1046 #ifdef RTE_EXEC_ENV_BSDAPP
1047 int i, num_sockets = 1;
1049 int i, num_sockets = get_number_of_sockets();
1052 if (num_sockets <= 0 || num_sockets > RTE_MAX_NUMA_NODES) {
1053 printf("Error - cannot get number of sockets!\n");
1057 rte_snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
1059 /* add one extra socket */
1060 for (i = 0; i < num_sockets + 1; i++) {
1061 rte_snprintf(buf, sizeof(buf), "%s2", invalid_socket_mem);
1062 rte_snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1064 if (num_sockets + 1 - i > 1) {
1065 rte_snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
1066 rte_snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1070 /* construct a valid socket mask with 2 megs on each existing socket */
1071 char valid_socket_mem[SOCKET_MEM_STRLEN];
1073 rte_snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
1075 /* add one extra socket */
1076 for (i = 0; i < num_sockets; i++) {
1077 rte_snprintf(buf, sizeof(buf), "%s2", valid_socket_mem);
1078 rte_snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1080 if (num_sockets - i > 1) {
1081 rte_snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
1082 rte_snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1086 /* invalid --socket-mem flag (with extra socket) */
1087 const char *argv9[] = {prgname, "-c", "10", "-n", "2",
1088 "--file-prefix=" memtest, invalid_socket_mem};
1090 /* valid --socket-mem flag */
1091 const char *argv10[] = {prgname, "-c", "10", "-n", "2",
1092 "--file-prefix=" memtest, valid_socket_mem};
1094 if (launch_proc(argv0) != 0) {
1095 printf("Error - secondary process failed with valid -m flag !\n");
1099 #ifdef RTE_EXEC_ENV_BSDAPP
1100 /* no other tests are applicable to BSD */
1104 if (launch_proc(argv1) != 0) {
1105 printf("Error - process failed with valid -m flag!\n");
1108 #ifdef RTE_LIBRTE_XEN_DOM0
1111 if (launch_proc(argv2) == 0) {
1112 printf("Error - process run ok with invalid (zero) --socket-mem!\n");
1116 if (launch_proc(argv3) == 0) {
1117 printf("Error - process run ok with invalid "
1118 "(incomplete) --socket-mem!\n");
1122 if (launch_proc(argv4) == 0) {
1123 printf("Error - process run ok with invalid "
1124 "(mixed with invalid input) --socket-mem!\n");
1128 if (launch_proc(argv5) == 0) {
1129 printf("Error - process run ok with invalid "
1130 "(mixed with invalid input with a numeric value as "
1131 "last character) --socket-mem!\n");
1135 if (launch_proc(argv6) == 0) {
1136 printf("Error - process run ok with invalid "
1137 "(with empty socket) --socket-mem!\n");
1141 if (launch_proc(argv7) == 0) {
1142 printf("Error - process run ok with invalid (null) --socket-mem!\n");
1146 if (launch_proc(argv8) == 0) {
1147 printf("Error - process run ok with --socket-mem and -m specified!\n");
1151 if (launch_proc(argv9) == 0) {
1152 printf("Error - process run ok with extra socket in --socket-mem!\n");
1156 if (launch_proc(argv10) != 0) {
1157 printf("Error - process failed with valid --socket-mem!\n");
1165 test_eal_flags(void)
1169 ret = test_missing_c_flag();
1171 printf("Error in test_missing_c_flag()\n");
1175 ret = test_missing_n_flag();
1177 printf("Error in test_missing_n_flag()\n");
1181 ret = test_no_hpet_flag();
1183 printf("Error in test_no_hpet_flag()\n");
1187 ret = test_no_huge_flag();
1189 printf("Error in test_no_huge_flag()\n");
1193 ret = test_whitelist_flag();
1195 printf("Error in test_invalid_whitelist_flag()\n");
1199 ret = test_invalid_b_flag();
1201 printf("Error in test_invalid_b_flag()\n");
1205 ret = test_invalid_r_flag();
1207 printf("Error in test_invalid_r_flag()\n");
1211 ret = test_memory_flags();
1213 printf("Error in test_memory_flags()\n");
1217 ret = test_file_prefix();
1219 printf("Error in test_file_prefix()\n");
1223 #ifdef RTE_LIBRTE_XEN_DOM0
1224 ret = test_dom0_misc_flags();
1226 ret = test_misc_flags();
1229 printf("Error in test_misc_flags()");
1237 /* Baremetal version
1238 * Multiprocess not applicable, so just return 0 always
1241 test_eal_flags(void)
1243 printf("Multi-process not possible for baremetal, cannot test EAL flags\n");