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.
37 #ifndef RTE_EXEC_ENV_BAREMETAL
50 #include <rte_debug.h>
51 #include <rte_string_fns.h>
55 #define mp_flag "--proc-type=secondary"
56 #define no_hpet "--no-hpet"
57 #define no_huge "--no-huge"
58 #define no_shconf "--no-shconf"
59 #define use_device "--use-device"
60 #define memtest "memtest"
61 #define memtest1 "memtest1"
62 #define memtest2 "memtest2"
63 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 10)
64 #define launch_proc(ARGV) process_dup(ARGV, \
65 sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
67 enum hugepage_action {
68 HUGEPAGE_CHECK_EXISTS = 0,
69 HUGEPAGE_CHECK_LOCKED,
74 /* if string contains a hugepage path */
76 get_hugepage_path(char * src, int src_len, char * dst, int dst_len)
79 char *tokens[NUM_TOKENS];
81 /* if we couldn't properly split the string */
82 if (rte_strsplit(src, src_len, tokens, NUM_TOKENS, ' ') < NUM_TOKENS)
85 if (strncmp(tokens[2], "hugetlbfs", sizeof("hugetlbfs")) == 0) {
86 rte_snprintf(dst, dst_len, "%s", tokens[1]);
93 * Cycles through hugepage directories and looks for hugepage
94 * files associated with a given prefix. Depending on value of
95 * action, the hugepages are checked if they exist, checked if
96 * they can be locked, or are simply deleted.
98 * Returns 1 if it finds at least one hugepage matching the action
99 * Returns 0 if no matching hugepages were found
100 * Returns -1 if it encounters an error
103 process_hugefiles(const char * prefix, enum hugepage_action action)
105 FILE * hugedir_handle = NULL;
106 DIR * hugepage_dir = NULL;
107 struct dirent *dirent = NULL;
109 char hugefile_prefix[PATH_MAX] = {0};
110 char hugedir[PATH_MAX] = {0};
111 char line[PATH_MAX] = {0};
113 int fd, lck_result, result = 0;
115 const int prefix_len = rte_snprintf(hugefile_prefix,
116 sizeof(hugefile_prefix), "%smap_", prefix);
117 if (prefix_len <= 0 || prefix_len >= (int)sizeof(hugefile_prefix)
118 || prefix_len >= (int)sizeof(dirent->d_name)) {
119 printf("Error creating hugefile filename prefix\n");
123 /* get hugetlbfs mountpoints from /proc/mounts */
124 hugedir_handle = fopen("/proc/mounts", "r");
126 if (hugedir_handle == NULL) {
127 printf("Error parsing /proc/mounts!\n");
131 /* read and parse script output */
132 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
134 /* check if we have a hugepage filesystem path */
135 if (!get_hugepage_path(line, sizeof(line), hugedir, sizeof(hugedir)))
138 /* check if directory exists */
139 if ((hugepage_dir = opendir(hugedir)) == NULL) {
140 fclose(hugedir_handle);
141 printf("Error reading %s: %s\n", hugedir, strerror(errno));
145 while ((dirent = readdir(hugepage_dir)) != NULL) {
146 if (memcmp(dirent->d_name, hugefile_prefix, prefix_len) != 0)
150 case HUGEPAGE_CHECK_EXISTS:
152 /* file exists, return */
157 case HUGEPAGE_DELETE:
159 char file_path[PATH_MAX] = {0};
161 rte_snprintf(file_path, sizeof(file_path),
162 "%s/%s", hugedir, dirent->d_name);
165 if (remove(file_path) < 0) {
166 printf("Error deleting %s - %s!\n",
167 dirent->d_name, strerror(errno));
168 closedir(hugepage_dir);
175 case HUGEPAGE_CHECK_LOCKED:
177 /* try and lock the file */
178 fd = openat(dirfd(hugepage_dir), dirent->d_name, O_RDONLY);
180 /* this shouldn't happen */
182 printf("Error opening %s - %s!\n",
183 dirent->d_name, strerror(errno));
184 closedir(hugepage_dir);
189 /* non-blocking lock */
190 lck_result = flock(fd, LOCK_EX | LOCK_NB);
192 /* if lock succeeds, there's something wrong */
193 if (lck_result != -1) {
196 /* unlock the resulting lock */
199 closedir(hugepage_dir);
206 /* shouldn't happen */
211 } /* read hugepage directory */
212 closedir(hugepage_dir);
213 } /* read /proc/mounts */
215 fclose(hugedir_handle);
219 #ifdef RTE_EXEC_ENV_LINUXAPP
221 * count the number of "node*" files in /sys/devices/system/node/
224 get_number_of_sockets(void)
226 struct dirent *dirent = NULL;
227 const char * nodedir = "/sys/devices/system/node/";
231 /* check if directory exists */
232 if ((dir = opendir(nodedir)) == NULL) {
233 /* if errno==ENOENT this means we don't have NUMA support */
234 if (errno == ENOENT) {
235 printf("No NUMA nodes detected: assuming 1 available socket\n");
238 printf("Error opening %s: %s\n", nodedir, strerror(errno));
242 while ((dirent = readdir(dir)) != NULL)
243 if (strncmp(dirent->d_name, "node", sizeof("node") - 1) == 0)
252 get_current_prefix(char * prefix, int size)
254 char path[PATH_MAX] = {0};
255 char buf[PATH_MAX] = {0};
257 /* get file for config (fd is always 3) */
258 rte_snprintf(path, sizeof(path), "/proc/self/fd/%d", 3);
260 /* return NULL on error */
261 if (readlink(path, buf, sizeof(buf)) == -1)
264 /* get the basename */
265 rte_snprintf(buf, sizeof(buf), "%s", basename(buf));
267 /* copy string all the way from second char up to start of _config */
268 rte_snprintf(prefix, size, "%.*s",
269 strnlen(buf, sizeof(buf)) - sizeof("_config"), &buf[1]);
274 /* extra function prototypes for internal eal function to test in whitelist
275 * ICC 12 doesn't approve of this practice, so temporarily disable warnings for it */
276 #ifdef __INTEL_COMPILER
277 #pragma warning disable 1419
279 extern int eal_dev_whitelist_exists(void);
280 extern int eal_dev_whitelist_add_entry(const char *);
281 extern int eal_dev_whitelist_parse(void);
282 extern int eal_dev_is_whitelisted(const char *, const char **);
283 extern void eal_dev_whitelist_clear(void);
284 #ifdef __INTEL_COMPILER
285 #pragma warning enable 1419
289 * Test that the app doesn't run with invalid whitelist option.
290 * Final tests ensures it does run with valid options as sanity check (one
291 * test for with Domain+BDF, second for just with BDF)
294 test_whitelist_flag(void)
297 #ifdef RTE_EXEC_ENV_BSDAPP
298 /* BSD target doesn't support prefixes at this point */
299 const char * prefix = "";
301 char prefix[PATH_MAX], tmp[PATH_MAX];
302 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
303 printf("Error - unable to get current prefix!\n");
306 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
309 const char *wlinval[][11] = {
310 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
311 use_device, "error", "", ""},
312 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
313 use_device, "0:0:0", "", ""},
314 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
315 use_device, "0:error:0.1", "", ""},
316 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
317 use_device, "0:0:0.1error", "", ""},
318 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
319 use_device, "error0:0:0.1", "", ""},
320 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
321 use_device, "0:0:0.1.2", "", ""},
322 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
323 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",
324 use_device, "y,z,1,2,3,4,5,6,7,8,9,0"},
326 /* Test with valid whitelist option */
327 const char *wlval1[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
328 use_device, "00FF:09:0B.3"};
329 const char *wlval2[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
330 use_device, "09:0B.3,0a:0b.1"};
331 const char *wlval3[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
332 use_device, "09:0B.3;type=test,08:00.1;type=normal"};
334 for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
335 if (launch_proc(wlinval[i]) == 0) {
336 printf("Error - process did run ok with invalid "
337 "whitelist parameter\n");
341 if (launch_proc(wlval1) != 0 ) {
342 printf("Error - process did not run ok with valid whitelist\n");
345 if (launch_proc(wlval2) != 0 ) {
346 printf("Error - process did not run ok with valid whitelist value set\n");
349 if (launch_proc(wlval3) != 0 ) {
350 printf("Error - process did not run ok with valid whitelist + args\n");
354 /* extra-sanity checks of whitelists - to be run only if no whitelist */
355 if (eal_dev_whitelist_exists())
358 /* check that whitelist_parse returns error without whitelist */
359 if (eal_dev_whitelist_parse() != -1) {
360 printf("ERROR: calling whitelist parse without a whitelist doesn't "
361 "return an error\n");
364 if (eal_dev_is_whitelisted("adevice", NULL)) {
365 printf("Whitelist lookup does not return false if no whitelist\n");
368 eal_dev_whitelist_add_entry("0000:00:00.0");
369 eal_dev_whitelist_parse();
370 if (eal_dev_is_whitelisted("adevice", NULL)) {
371 printf("Whitelist lookup does not return false for unlisted dev\n");
374 if (!eal_dev_is_whitelisted("0000:00:00.0", NULL)) {
375 printf("Whitelist lookup does not return true for whitelisted dev\n");
378 eal_dev_whitelist_clear();
384 * Test that the app doesn't run with invalid blacklist option.
385 * Final test ensures it does run with valid options as sanity check
388 test_invalid_b_flag(void)
390 #ifdef RTE_EXEC_ENV_BSDAPP
391 /* BSD target doesn't support prefixes at this point */
392 const char * prefix = "";
394 char prefix[PATH_MAX], tmp[PATH_MAX];
395 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
396 printf("Error - unable to get current prefix!\n");
399 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
402 const char *blinval[][9] = {
403 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error"},
404 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0"},
405 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:error:0.1"},
406 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1error"},
407 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error0:0:0.1"},
408 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1.2"},
410 /* Test with valid blacklist option */
411 const char *blval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
415 for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
416 if (launch_proc(blinval[i]) == 0) {
417 printf("Error - process did run ok with invalid "
418 "blacklist parameter\n");
422 if (launch_proc(blval) != 0) {
423 printf("Error - process did not run ok with valid blacklist value\n");
431 * Test that the app doesn't run with invalid -r option.
434 test_invalid_r_flag(void)
436 #ifdef RTE_EXEC_ENV_BSDAPP
437 /* BSD target doesn't support prefixes at this point */
438 const char * prefix = "";
440 char prefix[PATH_MAX], tmp[PATH_MAX];
441 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
442 printf("Error - unable to get current prefix!\n");
445 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
448 const char *rinval[][9] = {
449 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "error"},
450 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "0"},
451 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "-1"},
452 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "17"},
454 /* Test with valid blacklist option */
455 const char *rval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
459 for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
460 if (launch_proc(rinval[i]) == 0) {
461 printf("Error - process did run ok with invalid "
462 "-r (rank) parameter\n");
466 if (launch_proc(rval) != 0) {
467 printf("Error - process did not run ok with valid -r (rank) value\n");
474 * Test that the app doesn't run without the coremask flag. In all cases
475 * should give an error and fail to run
478 test_missing_c_flag(void)
480 #ifdef RTE_EXEC_ENV_BSDAPP
481 /* BSD target doesn't support prefixes at this point */
482 const char * prefix = "";
484 char prefix[PATH_MAX], tmp[PATH_MAX];
485 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
486 printf("Error - unable to get current prefix!\n");
489 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
492 /* -c flag but no coremask value */
493 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "3", "-c"};
494 /* No -c flag at all */
495 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "3"};
496 /* bad coremask value */
497 const char *argv3[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "error" };
498 /* sanity check of tests - valid coremask value */
499 const char *argv4[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "1" };
501 if (launch_proc(argv1) == 0
502 || launch_proc(argv2) == 0
503 || launch_proc(argv3) == 0) {
504 printf("Error - process ran without error when missing -c flag\n");
507 if (launch_proc(argv4) != 0) {
508 printf("Error - process did not run ok with valid coremask value\n");
515 * Test that the app doesn't run without the -n flag. In all cases
516 * should give an error and fail to run.
517 * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
521 test_missing_n_flag(void)
523 #ifdef RTE_EXEC_ENV_BSDAPP
524 /* BSD target doesn't support prefixes at this point */
525 const char * prefix = "";
527 char prefix[PATH_MAX], tmp[PATH_MAX];
528 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
529 printf("Error - unable to get current prefix!\n");
532 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
535 /* -n flag but no value */
536 const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"};
537 /* No -n flag at all */
538 const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"};
539 /* bad numeric value */
540 const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" };
541 /* out-of-range value */
542 const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "9" };
543 /* sanity test - check with good value */
544 const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" };
546 if (launch_proc(argv1) == 0
547 || launch_proc(argv2) == 0
548 || launch_proc(argv3) == 0
549 || launch_proc(argv4) == 0) {
550 printf("Error - process ran without error when missing -n flag\n");
553 if (launch_proc(argv5) != 0) {
554 printf("Error - process did not run ok with valid num-channel value\n");
561 * Test that the app runs with HPET, and without HPET
564 test_no_hpet_flag(void)
566 char prefix[PATH_MAX], tmp[PATH_MAX];
568 #ifdef RTE_EXEC_ENV_BSDAPP
571 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
572 printf("Error - unable to get current prefix!\n");
575 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
578 const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"};
579 /* Without --no-hpet */
580 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-n", "2"};
582 if (launch_proc(argv1) != 0) {
583 printf("Error - process did not run ok with --no-hpet flag\n");
586 if (launch_proc(argv2) != 0) {
587 printf("Error - process did not run ok without --no-hpet flag\n");
594 * Test that the app runs with --no-huge and doesn't run when either
595 * -m or --socket-mem are specified with --no-huge.
598 test_no_huge_flag(void)
600 #ifdef RTE_EXEC_ENV_BSDAPP
601 /* BSD target doesn't support prefixes at this point, and we also need to
602 * run another primary process here */
603 const char * prefix = no_shconf;
605 const char * prefix = "--file-prefix=nohuge";
609 const char *argv1[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2"};
610 /* With --no-huge and -m */
611 const char *argv2[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2", "-m", "2"};
613 /* With --no-huge and --socket-mem */
614 const char *argv3[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
616 /* With --no-huge, -m and --socket-mem */
617 const char *argv4[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
618 "-m", "2", "--socket-mem=2"};
619 if (launch_proc(argv1) != 0) {
620 printf("Error - process did not run ok with --no-huge flag\n");
623 if (launch_proc(argv2) == 0) {
624 printf("Error - process run ok with --no-huge and -m flags\n");
627 #ifdef RTE_EXEC_ENV_BSDAPP
628 /* BSD target does not support NUMA, hence no --socket-mem tests */
632 if (launch_proc(argv3) == 0) {
633 printf("Error - process run ok with --no-huge and --socket-mem "
637 if (launch_proc(argv4) == 0) {
638 printf("Error - process run ok with --no-huge, -m and "
639 "--socket-mem flags\n");
645 #ifdef RTE_LIBRTE_XEN_DOM0
647 test_dom0_misc_flags(void)
649 char prefix[PATH_MAX], tmp[PATH_MAX];
651 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
652 printf("Error - unable to get current prefix!\n");
655 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
657 /* check that some general flags don't prevent things from working.
658 * All cases, apart from the first, app should run.
659 * No futher testing of output done.
661 /* sanity check - failure with invalid option */
662 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
665 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
667 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
668 /* With valid --syslog */
669 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
670 "--syslog", "syslog"};
671 /* With empty --syslog (should fail) */
672 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
673 /* With invalid --syslog */
674 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
675 /* With no-sh-conf */
676 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "20",
677 "--no-shconf", "--file-prefix=noshconf" };
679 if (launch_proc(argv0) == 0) {
680 printf("Error - process ran ok with invalid flag\n");
683 if (launch_proc(argv1) != 0) {
684 printf("Error - process did not run ok with --no-pci flag\n");
687 if (launch_proc(argv2) != 0) {
688 printf("Error - process did not run ok with -v flag\n");
691 if (launch_proc(argv3) != 0) {
692 printf("Error - process did not run ok with --syslog flag\n");
695 if (launch_proc(argv4) == 0) {
696 printf("Error - process run ok with empty --syslog flag\n");
699 if (launch_proc(argv5) == 0) {
700 printf("Error - process run ok with invalid --syslog flag\n");
703 if (launch_proc(argv6) != 0) {
704 printf("Error - process did not run ok with --no-shconf flag\n");
712 test_misc_flags(void)
714 char hugepath[PATH_MAX] = {0};
715 #ifdef RTE_EXEC_ENV_BSDAPP
716 /* BSD target doesn't support prefixes at this point */
717 const char * prefix = "";
718 const char * nosh_prefix = "";
720 char prefix[PATH_MAX], tmp[PATH_MAX];
721 const char * nosh_prefix = "--file-prefix=noshconf";
722 FILE * hugedir_handle = NULL;
723 char line[PATH_MAX] = {0};
724 unsigned i, isempty = 1;
725 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
726 printf("Error - unable to get current prefix!\n");
729 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
732 * get first valid hugepage path
735 /* get hugetlbfs mountpoints from /proc/mounts */
736 hugedir_handle = fopen("/proc/mounts", "r");
738 if (hugedir_handle == NULL) {
739 printf("Error opening /proc/mounts!\n");
743 /* read /proc/mounts */
744 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
746 /* find first valid hugepath */
747 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
751 fclose(hugedir_handle);
753 /* check if path is not empty */
754 for (i = 0; i < sizeof(hugepath); i++)
755 if (hugepath[i] != '\0')
759 printf("No mounted hugepage dir found!\n");
765 /* check that some general flags don't prevent things from working.
766 * All cases, apart from the first, app should run.
767 * No futher testing of output done.
769 /* sanity check - failure with invalid option */
770 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
773 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
775 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
776 /* With valid --syslog */
777 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
778 "--syslog", "syslog"};
779 /* With empty --syslog (should fail) */
780 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
781 /* With invalid --syslog */
782 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
783 /* With no-sh-conf */
784 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
785 no_shconf, nosh_prefix };
787 #ifdef RTE_EXEC_ENV_BSDAPP
790 /* With --huge-dir */
791 const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
792 "--file-prefix=hugedir", "--huge-dir", hugepath};
793 /* With empty --huge-dir (should fail) */
794 const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
795 "--file-prefix=hugedir", "--huge-dir"};
796 /* With invalid --huge-dir */
797 const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
798 "--file-prefix=hugedir", "--huge-dir", "invalid"};
799 /* Secondary process with invalid --huge-dir (should run as flag has no
800 * effect on secondary processes) */
801 const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
803 /* try running with base-virtaddr param */
804 const char *argv11[] = {prgname, "--file-prefix=virtaddr",
805 "-c", "1", "-n", "2", "--base-virtaddr=0x12345678"};
808 if (launch_proc(argv0) == 0) {
809 printf("Error - process ran ok with invalid flag\n");
812 if (launch_proc(argv1) != 0) {
813 printf("Error - process did not run ok with --no-pci flag\n");
816 if (launch_proc(argv2) != 0) {
817 printf("Error - process did not run ok with -v flag\n");
820 if (launch_proc(argv3) != 0) {
821 printf("Error - process did not run ok with --syslog flag\n");
824 if (launch_proc(argv4) == 0) {
825 printf("Error - process run ok with empty --syslog flag\n");
828 if (launch_proc(argv5) == 0) {
829 printf("Error - process run ok with invalid --syslog flag\n");
832 if (launch_proc(argv6) != 0) {
833 printf("Error - process did not run ok with --no-shconf flag\n");
836 #ifdef RTE_EXEC_ENV_BSDAPP
839 if (launch_proc(argv7) != 0) {
840 printf("Error - process did not run ok with --huge-dir flag\n");
843 if (launch_proc(argv8) == 0) {
844 printf("Error - process run ok with empty --huge-dir flag\n");
847 if (launch_proc(argv9) == 0) {
848 printf("Error - process run ok with invalid --huge-dir flag\n");
851 if (launch_proc(argv10) != 0) {
852 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
855 if (launch_proc(argv11) != 0) {
856 printf("Error - process did not run ok with --base-virtaddr parameter\n");
864 test_file_prefix(void)
867 * 1. check if current process hugefiles are locked
868 * 2. try to run secondary process without a corresponding primary process
869 * (while failing to run, it will also remove any unused hugepage files)
870 * 3. check if current process hugefiles are still in place and are locked
871 * 4. run a primary process with memtest1 prefix
872 * 5. check if memtest1 hugefiles are created
873 * 6. run a primary process with memtest2 prefix
874 * 7. check that only memtest2 hugefiles are present in the hugedir
877 #ifdef RTE_EXEC_ENV_BSDAPP
881 /* this should fail unless the test itself is run with "memtest" prefix */
882 const char *argv0[] = {prgname, mp_flag, "-c", "1", "-n", "2", "-m", "2",
883 "--file-prefix=" memtest };
885 /* primary process with memtest1 */
886 const char *argv1[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
887 "--file-prefix=" memtest1 };
889 /* primary process with memtest2 */
890 const char *argv2[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
891 "--file-prefix=" memtest2 };
894 if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
895 printf("Error - unable to get current prefix!\n");
898 #ifdef RTE_LIBRTE_XEN_DOM0
902 /* check if files for current prefix are present */
903 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
904 printf("Error - hugepage files for %s were not created!\n", prefix);
908 /* checks if files for current prefix are locked */
909 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
910 printf("Error - hugepages for current process aren't locked!\n");
914 /* check if files for secondary process are present */
915 if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
916 /* check if they are not locked */
917 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
918 printf("Error - hugepages for current process are locked!\n");
921 /* they aren't locked, delete them */
923 if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
924 printf("Error - deleting hugepages failed!\n");
930 if (launch_proc(argv0) == 0) {
931 printf("Error - secondary process ran ok without primary process\n");
935 /* check if files for current prefix are present */
936 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
937 printf("Error - hugepage files for %s were not created!\n", prefix);
941 /* checks if files for current prefix are locked */
942 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
943 printf("Error - hugepages for current process aren't locked!\n");
947 if (launch_proc(argv1) != 0) {
948 printf("Error - failed to run with --file-prefix=%s\n", memtest);
952 /* check if memtest1_map0 is present */
953 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
954 printf("Error - hugepage files for %s were not created!\n", memtest1);
958 if (launch_proc(argv2) != 0) {
959 printf("Error - failed to run with --file-prefix=%s\n", memtest2);
963 /* check if hugefiles for memtest2 are present */
964 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
965 printf("Error - hugepage files for %s were not created!\n", memtest2);
969 /* check if hugefiles for memtest1 are present */
970 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
971 printf("Error - hugepage files for %s were not deleted!\n", memtest1);
979 * Tests for correct handling of -m and --socket-mem flags
982 test_memory_flags(void)
984 const char* mem_size = NULL;
985 #ifdef RTE_EXEC_ENV_BSDAPP
986 /* BSD target doesn't support prefixes at this point */
987 const char * prefix = "";
989 char prefix[PATH_MAX], tmp[PATH_MAX];
990 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
991 printf("Error - unable to get current prefix!\n");
994 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
996 #ifdef RTE_LIBRTE_XEN_DOM0
1003 /* valid -m flag and mp flag */
1004 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "10",
1005 "-n", "2", "-m", mem_size};
1008 const char *argv1[] = {prgname, "-c", "10", "-n", "2",
1009 "--file-prefix=" memtest, "-m", mem_size};
1011 /* invalid (zero) --socket-mem flag */
1012 const char *argv2[] = {prgname, "-c", "10", "-n", "2",
1013 "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
1015 /* invalid (incomplete) --socket-mem flag */
1016 const char *argv3[] = {prgname, "-c", "10", "-n", "2",
1017 "--file-prefix=" memtest, "--socket-mem=2,2,"};
1019 /* invalid (mixed with invalid data) --socket-mem flag */
1020 const char *argv4[] = {prgname, "-c", "10", "-n", "2",
1021 "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
1023 /* invalid (with numeric value as last character) --socket-mem flag */
1024 const char *argv5[] = {prgname, "-c", "10", "-n", "2",
1025 "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
1027 /* invalid (with empty socket) --socket-mem flag */
1028 const char *argv6[] = {prgname, "-c", "10", "-n", "2",
1029 "--file-prefix=" memtest, "--socket-mem=2,,2"};
1031 /* invalid (null) --socket-mem flag */
1032 const char *argv7[] = {prgname, "-c", "10", "-n", "2",
1033 "--file-prefix=" memtest, "--socket-mem="};
1035 /* valid --socket-mem specified together with -m flag */
1036 const char *argv8[] = {prgname, "-c", "10", "-n", "2",
1037 "--file-prefix=" memtest, "-m", "2", "--socket-mem=2,2"};
1039 /* construct an invalid socket mask with 2 megs on each socket plus
1040 * extra 2 megs on socket that doesn't exist on current system */
1041 char invalid_socket_mem[SOCKET_MEM_STRLEN];
1042 char buf[SOCKET_MEM_STRLEN]; /* to avoid copying string onto itself */
1044 #ifdef RTE_EXEC_ENV_BSDAPP
1045 int i, num_sockets = 1;
1047 int i, num_sockets = get_number_of_sockets();
1050 if (num_sockets <= 0 || num_sockets > RTE_MAX_NUMA_NODES) {
1051 printf("Error - cannot get number of sockets!\n");
1055 rte_snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
1057 /* add one extra socket */
1058 for (i = 0; i < num_sockets + 1; i++) {
1059 rte_snprintf(buf, sizeof(buf), "%s2", invalid_socket_mem);
1060 rte_snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1062 if (num_sockets + 1 - i > 1) {
1063 rte_snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
1064 rte_snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1068 /* construct a valid socket mask with 2 megs on each existing socket */
1069 char valid_socket_mem[SOCKET_MEM_STRLEN];
1071 rte_snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
1073 /* add one extra socket */
1074 for (i = 0; i < num_sockets; i++) {
1075 rte_snprintf(buf, sizeof(buf), "%s2", valid_socket_mem);
1076 rte_snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1078 if (num_sockets - i > 1) {
1079 rte_snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
1080 rte_snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1084 /* invalid --socket-mem flag (with extra socket) */
1085 const char *argv9[] = {prgname, "-c", "10", "-n", "2",
1086 "--file-prefix=" memtest, invalid_socket_mem};
1088 /* valid --socket-mem flag */
1089 const char *argv10[] = {prgname, "-c", "10", "-n", "2",
1090 "--file-prefix=" memtest, valid_socket_mem};
1092 if (launch_proc(argv0) != 0) {
1093 printf("Error - secondary process failed with valid -m flag !\n");
1097 #ifdef RTE_EXEC_ENV_BSDAPP
1098 /* no other tests are applicable to BSD */
1102 if (launch_proc(argv1) != 0) {
1103 printf("Error - process failed with valid -m flag!\n");
1106 #ifdef RTE_LIBRTE_XEN_DOM0
1109 if (launch_proc(argv2) == 0) {
1110 printf("Error - process run ok with invalid (zero) --socket-mem!\n");
1114 if (launch_proc(argv3) == 0) {
1115 printf("Error - process run ok with invalid "
1116 "(incomplete) --socket-mem!\n");
1120 if (launch_proc(argv4) == 0) {
1121 printf("Error - process run ok with invalid "
1122 "(mixed with invalid input) --socket-mem!\n");
1126 if (launch_proc(argv5) == 0) {
1127 printf("Error - process run ok with invalid "
1128 "(mixed with invalid input with a numeric value as "
1129 "last character) --socket-mem!\n");
1133 if (launch_proc(argv6) == 0) {
1134 printf("Error - process run ok with invalid "
1135 "(with empty socket) --socket-mem!\n");
1139 if (launch_proc(argv7) == 0) {
1140 printf("Error - process run ok with invalid (null) --socket-mem!\n");
1144 if (launch_proc(argv8) == 0) {
1145 printf("Error - process run ok with --socket-mem and -m specified!\n");
1149 if (launch_proc(argv9) == 0) {
1150 printf("Error - process run ok with extra socket in --socket-mem!\n");
1154 if (launch_proc(argv10) != 0) {
1155 printf("Error - process failed with valid --socket-mem!\n");
1163 test_eal_flags(void)
1167 ret = test_missing_c_flag();
1169 printf("Error in test_missing_c_flag()\n");
1173 ret = test_missing_n_flag();
1175 printf("Error in test_missing_n_flag()\n");
1179 ret = test_no_hpet_flag();
1181 printf("Error in test_no_hpet_flag()\n");
1185 ret = test_no_huge_flag();
1187 printf("Error in test_no_huge_flag()\n");
1191 ret = test_whitelist_flag();
1193 printf("Error in test_invalid_whitelist_flag()\n");
1197 ret = test_invalid_b_flag();
1199 printf("Error in test_invalid_b_flag()\n");
1203 ret = test_invalid_r_flag();
1205 printf("Error in test_invalid_r_flag()\n");
1209 ret = test_memory_flags();
1211 printf("Error in test_memory_flags()\n");
1215 ret = test_file_prefix();
1217 printf("Error in test_file_prefix()\n");
1221 #ifdef RTE_LIBRTE_XEN_DOM0
1222 ret = test_dom0_misc_flags();
1224 ret = test_misc_flags();
1227 printf("Error in test_misc_flags()");
1235 /* Baremetal version
1236 * Multiprocess not applicable, so just return 0 always
1239 test_eal_flags(void)
1241 printf("Multi-process not possible for baremetal, cannot test EAL flags\n");