4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5 * Copyright(c) 2014 6WIND S.A.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #ifndef RTE_EXEC_ENV_BAREMETAL
51 #include <rte_debug.h>
52 #include <rte_string_fns.h>
56 #define mp_flag "--proc-type=secondary"
57 #define no_hpet "--no-hpet"
58 #define no_huge "--no-huge"
59 #define no_shconf "--no-shconf"
60 #define pci_whitelist "--pci-whitelist"
62 #define memtest "memtest"
63 #define memtest1 "memtest1"
64 #define memtest2 "memtest2"
65 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 10)
66 #define launch_proc(ARGV) process_dup(ARGV, \
67 sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
69 enum hugepage_action {
70 HUGEPAGE_CHECK_EXISTS = 0,
71 HUGEPAGE_CHECK_LOCKED,
76 /* if string contains a hugepage path */
78 get_hugepage_path(char * src, int src_len, char * dst, int dst_len)
81 char *tokens[NUM_TOKENS];
83 /* if we couldn't properly split the string */
84 if (rte_strsplit(src, src_len, tokens, NUM_TOKENS, ' ') < NUM_TOKENS)
87 if (strncmp(tokens[2], "hugetlbfs", sizeof("hugetlbfs")) == 0) {
88 snprintf(dst, dst_len, "%s", tokens[1]);
95 * Cycles through hugepage directories and looks for hugepage
96 * files associated with a given prefix. Depending on value of
97 * action, the hugepages are checked if they exist, checked if
98 * they can be locked, or are simply deleted.
100 * Returns 1 if it finds at least one hugepage matching the action
101 * Returns 0 if no matching hugepages were found
102 * Returns -1 if it encounters an error
105 process_hugefiles(const char * prefix, enum hugepage_action action)
107 FILE * hugedir_handle = NULL;
108 DIR * hugepage_dir = NULL;
109 struct dirent *dirent = NULL;
111 char hugefile_prefix[PATH_MAX] = {0};
112 char hugedir[PATH_MAX] = {0};
113 char line[PATH_MAX] = {0};
115 int fd, lck_result, result = 0;
117 const int prefix_len = snprintf(hugefile_prefix,
118 sizeof(hugefile_prefix), "%smap_", prefix);
119 if (prefix_len <= 0 || prefix_len >= (int)sizeof(hugefile_prefix)
120 || prefix_len >= (int)sizeof(dirent->d_name)) {
121 printf("Error creating hugefile filename prefix\n");
125 /* get hugetlbfs mountpoints from /proc/mounts */
126 hugedir_handle = fopen("/proc/mounts", "r");
128 if (hugedir_handle == NULL) {
129 printf("Error parsing /proc/mounts!\n");
133 /* read and parse script output */
134 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
136 /* check if we have a hugepage filesystem path */
137 if (!get_hugepage_path(line, sizeof(line), hugedir, sizeof(hugedir)))
140 /* check if directory exists */
141 if ((hugepage_dir = opendir(hugedir)) == NULL) {
142 fclose(hugedir_handle);
143 printf("Error reading %s: %s\n", hugedir, strerror(errno));
147 while ((dirent = readdir(hugepage_dir)) != NULL) {
148 if (memcmp(dirent->d_name, hugefile_prefix, prefix_len) != 0)
152 case HUGEPAGE_CHECK_EXISTS:
154 /* file exists, return */
159 case HUGEPAGE_DELETE:
161 char file_path[PATH_MAX] = {0};
163 snprintf(file_path, sizeof(file_path),
164 "%s/%s", hugedir, dirent->d_name);
167 if (remove(file_path) < 0) {
168 printf("Error deleting %s - %s!\n",
169 dirent->d_name, strerror(errno));
170 closedir(hugepage_dir);
177 case HUGEPAGE_CHECK_LOCKED:
179 /* try and lock the file */
180 fd = openat(dirfd(hugepage_dir), dirent->d_name, O_RDONLY);
182 /* this shouldn't happen */
184 printf("Error opening %s - %s!\n",
185 dirent->d_name, strerror(errno));
186 closedir(hugepage_dir);
191 /* non-blocking lock */
192 lck_result = flock(fd, LOCK_EX | LOCK_NB);
194 /* if lock succeeds, there's something wrong */
195 if (lck_result != -1) {
198 /* unlock the resulting lock */
201 closedir(hugepage_dir);
208 /* shouldn't happen */
213 } /* read hugepage directory */
214 closedir(hugepage_dir);
215 } /* read /proc/mounts */
217 fclose(hugedir_handle);
221 #ifdef RTE_EXEC_ENV_LINUXAPP
223 * count the number of "node*" files in /sys/devices/system/node/
226 get_number_of_sockets(void)
228 struct dirent *dirent = NULL;
229 const char * nodedir = "/sys/devices/system/node/";
233 /* check if directory exists */
234 if ((dir = opendir(nodedir)) == NULL) {
235 /* if errno==ENOENT this means we don't have NUMA support */
236 if (errno == ENOENT) {
237 printf("No NUMA nodes detected: assuming 1 available socket\n");
240 printf("Error opening %s: %s\n", nodedir, strerror(errno));
244 while ((dirent = readdir(dir)) != NULL)
245 if (strncmp(dirent->d_name, "node", sizeof("node") - 1) == 0)
254 get_current_prefix(char * prefix, int size)
256 char path[PATH_MAX] = {0};
257 char buf[PATH_MAX] = {0};
259 /* get file for config (fd is always 3) */
260 snprintf(path, sizeof(path), "/proc/self/fd/%d", 3);
262 /* return NULL on error */
263 if (readlink(path, buf, sizeof(buf)) == -1)
266 /* get the basename */
267 snprintf(buf, sizeof(buf), "%s", basename(buf));
269 /* copy string all the way from second char up to start of _config */
270 snprintf(prefix, size, "%.*s",
271 (int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
278 * Test that the app doesn't run with invalid whitelist option.
279 * Final tests ensures it does run with valid options as sanity check (one
280 * test for with Domain+BDF, second for just with BDF)
283 test_whitelist_flag(void)
286 #ifdef RTE_EXEC_ENV_BSDAPP
287 /* BSD target doesn't support prefixes at this point */
288 const char * prefix = "";
290 char prefix[PATH_MAX], tmp[PATH_MAX];
291 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
292 printf("Error - unable to get current prefix!\n");
295 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
298 const char *wlinval[][11] = {
299 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
300 pci_whitelist, "error", "", ""},
301 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
302 pci_whitelist, "0:0:0", "", ""},
303 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
304 pci_whitelist, "0:error:0.1", "", ""},
305 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
306 pci_whitelist, "0:0:0.1error", "", ""},
307 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
308 pci_whitelist, "error0:0:0.1", "", ""},
309 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
310 pci_whitelist, "0:0:0.1.2", "", ""},
312 /* Test with valid whitelist option */
313 const char *wlval1[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
314 pci_whitelist, "00FF:09:0B.3"};
315 const char *wlval2[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
316 pci_whitelist, "09:0B.3", pci_whitelist, "0a:0b.1"};
317 const char *wlval3[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
318 pci_whitelist, "09:0B.3,type=test",
319 pci_whitelist, "08:00.1,type=normal",
320 #ifdef RTE_LIBRTE_PMD_RING
321 vdev, "eth_ring,arg=test",
325 for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
326 if (launch_proc(wlinval[i]) == 0) {
327 printf("Error - process did run ok with invalid "
328 "whitelist parameter\n");
332 if (launch_proc(wlval1) != 0 ) {
333 printf("Error - process did not run ok with valid whitelist\n");
336 if (launch_proc(wlval2) != 0 ) {
337 printf("Error - process did not run ok with valid whitelist value set\n");
340 if (launch_proc(wlval3) != 0 ) {
341 printf("Error - process did not run ok with valid whitelist + args\n");
349 * Test that the app doesn't run with invalid blacklist option.
350 * Final test ensures it does run with valid options as sanity check
353 test_invalid_b_flag(void)
355 #ifdef RTE_EXEC_ENV_BSDAPP
356 /* BSD target doesn't support prefixes at this point */
357 const char * prefix = "";
359 char prefix[PATH_MAX], tmp[PATH_MAX];
360 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
361 printf("Error - unable to get current prefix!\n");
364 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
367 const char *blinval[][9] = {
368 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error"},
369 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0"},
370 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:error:0.1"},
371 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1error"},
372 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error0:0:0.1"},
373 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1.2"},
375 /* Test with valid blacklist option */
376 const char *blval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
380 for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
381 if (launch_proc(blinval[i]) == 0) {
382 printf("Error - process did run ok with invalid "
383 "blacklist parameter\n");
387 if (launch_proc(blval) != 0) {
388 printf("Error - process did not run ok with valid blacklist value\n");
396 * Test that the app doesn't run with invalid -r option.
399 test_invalid_r_flag(void)
401 #ifdef RTE_EXEC_ENV_BSDAPP
402 /* BSD target doesn't support prefixes at this point */
403 const char * prefix = "";
405 char prefix[PATH_MAX], tmp[PATH_MAX];
406 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
407 printf("Error - unable to get current prefix!\n");
410 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
413 const char *rinval[][9] = {
414 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "error"},
415 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "0"},
416 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "-1"},
417 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "17"},
419 /* Test with valid blacklist option */
420 const char *rval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
424 for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
425 if (launch_proc(rinval[i]) == 0) {
426 printf("Error - process did run ok with invalid "
427 "-r (rank) parameter\n");
431 if (launch_proc(rval) != 0) {
432 printf("Error - process did not run ok with valid -r (rank) value\n");
439 * Test that the app doesn't run without the coremask flag. In all cases
440 * should give an error and fail to run
443 test_missing_c_flag(void)
445 #ifdef RTE_EXEC_ENV_BSDAPP
446 /* BSD target doesn't support prefixes at this point */
447 const char * prefix = "";
449 char prefix[PATH_MAX], tmp[PATH_MAX];
450 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
451 printf("Error - unable to get current prefix!\n");
454 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
457 /* -c flag but no coremask value */
458 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "3", "-c"};
459 /* No -c flag at all */
460 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "3"};
461 /* bad coremask value */
462 const char *argv3[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "error" };
463 /* sanity check of tests - valid coremask value */
464 const char *argv4[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "1" };
466 if (launch_proc(argv1) == 0
467 || launch_proc(argv2) == 0
468 || launch_proc(argv3) == 0) {
469 printf("Error - process ran without error when missing -c flag\n");
472 if (launch_proc(argv4) != 0) {
473 printf("Error - process did not run ok with valid coremask value\n");
480 * Test that the app doesn't run without the -n flag. In all cases
481 * should give an error and fail to run.
482 * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
486 test_missing_n_flag(void)
488 #ifdef RTE_EXEC_ENV_BSDAPP
489 /* BSD target doesn't support prefixes at this point */
490 const char * prefix = "";
492 char prefix[PATH_MAX], tmp[PATH_MAX];
493 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
494 printf("Error - unable to get current prefix!\n");
497 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
500 /* -n flag but no value */
501 const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"};
502 /* No -n flag at all */
503 const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"};
504 /* bad numeric value */
505 const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" };
506 /* out-of-range value */
507 const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "9" };
508 /* sanity test - check with good value */
509 const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" };
511 if (launch_proc(argv1) == 0
512 || launch_proc(argv2) == 0
513 || launch_proc(argv3) == 0
514 || launch_proc(argv4) == 0) {
515 printf("Error - process ran without error when missing -n flag\n");
518 if (launch_proc(argv5) != 0) {
519 printf("Error - process did not run ok with valid num-channel value\n");
526 * Test that the app runs with HPET, and without HPET
529 test_no_hpet_flag(void)
531 char prefix[PATH_MAX], tmp[PATH_MAX];
533 #ifdef RTE_EXEC_ENV_BSDAPP
536 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
537 printf("Error - unable to get current prefix!\n");
540 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
543 const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"};
544 /* Without --no-hpet */
545 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-n", "2"};
547 if (launch_proc(argv1) != 0) {
548 printf("Error - process did not run ok with --no-hpet flag\n");
551 if (launch_proc(argv2) != 0) {
552 printf("Error - process did not run ok without --no-hpet flag\n");
559 * Test that the app runs with --no-huge and doesn't run when either
560 * -m or --socket-mem are specified with --no-huge.
563 test_no_huge_flag(void)
565 #ifdef RTE_EXEC_ENV_BSDAPP
566 /* BSD target doesn't support prefixes at this point, and we also need to
567 * run another primary process here */
568 const char * prefix = no_shconf;
570 const char * prefix = "--file-prefix=nohuge";
574 const char *argv1[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2"};
575 /* With --no-huge and -m */
576 const char *argv2[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2", "-m", "2"};
578 /* With --no-huge and --socket-mem */
579 const char *argv3[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
581 /* With --no-huge, -m and --socket-mem */
582 const char *argv4[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
583 "-m", "2", "--socket-mem=2"};
584 if (launch_proc(argv1) != 0) {
585 printf("Error - process did not run ok with --no-huge flag\n");
588 if (launch_proc(argv2) == 0) {
589 printf("Error - process run ok with --no-huge and -m flags\n");
592 #ifdef RTE_EXEC_ENV_BSDAPP
593 /* BSD target does not support NUMA, hence no --socket-mem tests */
597 if (launch_proc(argv3) == 0) {
598 printf("Error - process run ok with --no-huge and --socket-mem "
602 if (launch_proc(argv4) == 0) {
603 printf("Error - process run ok with --no-huge, -m and "
604 "--socket-mem flags\n");
610 #ifdef RTE_LIBRTE_XEN_DOM0
612 test_dom0_misc_flags(void)
614 char prefix[PATH_MAX], tmp[PATH_MAX];
616 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
617 printf("Error - unable to get current prefix!\n");
620 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
622 /* check that some general flags don't prevent things from working.
623 * All cases, apart from the first, app should run.
624 * No futher testing of output done.
626 /* sanity check - failure with invalid option */
627 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
630 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
632 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
633 /* With valid --syslog */
634 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
635 "--syslog", "syslog"};
636 /* With empty --syslog (should fail) */
637 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
638 /* With invalid --syslog */
639 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
640 /* With no-sh-conf */
641 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "20",
642 "--no-shconf", "--file-prefix=noshconf" };
644 if (launch_proc(argv0) == 0) {
645 printf("Error - process ran ok with invalid flag\n");
648 if (launch_proc(argv1) != 0) {
649 printf("Error - process did not run ok with --no-pci flag\n");
652 if (launch_proc(argv2) != 0) {
653 printf("Error - process did not run ok with -v flag\n");
656 if (launch_proc(argv3) != 0) {
657 printf("Error - process did not run ok with --syslog flag\n");
660 if (launch_proc(argv4) == 0) {
661 printf("Error - process run ok with empty --syslog flag\n");
664 if (launch_proc(argv5) == 0) {
665 printf("Error - process run ok with invalid --syslog flag\n");
668 if (launch_proc(argv6) != 0) {
669 printf("Error - process did not run ok with --no-shconf flag\n");
677 test_misc_flags(void)
679 char hugepath[PATH_MAX] = {0};
680 #ifdef RTE_EXEC_ENV_BSDAPP
681 /* BSD target doesn't support prefixes at this point */
682 const char * prefix = "";
683 const char * nosh_prefix = "";
685 char prefix[PATH_MAX], tmp[PATH_MAX];
686 const char * nosh_prefix = "--file-prefix=noshconf";
687 FILE * hugedir_handle = NULL;
688 char line[PATH_MAX] = {0};
689 unsigned i, isempty = 1;
690 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
691 printf("Error - unable to get current prefix!\n");
694 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
697 * get first valid hugepage path
700 /* get hugetlbfs mountpoints from /proc/mounts */
701 hugedir_handle = fopen("/proc/mounts", "r");
703 if (hugedir_handle == NULL) {
704 printf("Error opening /proc/mounts!\n");
708 /* read /proc/mounts */
709 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
711 /* find first valid hugepath */
712 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
716 fclose(hugedir_handle);
718 /* check if path is not empty */
719 for (i = 0; i < sizeof(hugepath); i++)
720 if (hugepath[i] != '\0')
724 printf("No mounted hugepage dir found!\n");
730 /* check that some general flags don't prevent things from working.
731 * All cases, apart from the first, app should run.
732 * No futher testing of output done.
734 /* sanity check - failure with invalid option */
735 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
738 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
740 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
741 /* With valid --syslog */
742 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
743 "--syslog", "syslog"};
744 /* With empty --syslog (should fail) */
745 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
746 /* With invalid --syslog */
747 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
748 /* With no-sh-conf */
749 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
750 no_shconf, nosh_prefix };
752 #ifdef RTE_EXEC_ENV_BSDAPP
755 /* With --huge-dir */
756 const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
757 "--file-prefix=hugedir", "--huge-dir", hugepath};
758 /* With empty --huge-dir (should fail) */
759 const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
760 "--file-prefix=hugedir", "--huge-dir"};
761 /* With invalid --huge-dir */
762 const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
763 "--file-prefix=hugedir", "--huge-dir", "invalid"};
764 /* Secondary process with invalid --huge-dir (should run as flag has no
765 * effect on secondary processes) */
766 const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
768 /* try running with base-virtaddr param */
769 const char *argv11[] = {prgname, "--file-prefix=virtaddr",
770 "-c", "1", "-n", "2", "--base-virtaddr=0x12345678"};
772 /* try running with --vfio-intr INTx flag */
773 const char *argv12[] = {prgname, "--file-prefix=intr",
774 "-c", "1", "-n", "2", "--vfio-intr=legacy"};
776 /* try running with --vfio-intr MSI flag */
777 const char *argv13[] = {prgname, "--file-prefix=intr",
778 "-c", "1", "-n", "2", "--vfio-intr=msi"};
780 /* try running with --vfio-intr MSI-X flag */
781 const char *argv14[] = {prgname, "--file-prefix=intr",
782 "-c", "1", "-n", "2", "--vfio-intr=msix"};
784 /* try running with --vfio-intr invalid flag */
785 const char *argv15[] = {prgname, "--file-prefix=intr",
786 "-c", "1", "-n", "2", "--vfio-intr=invalid"};
789 if (launch_proc(argv0) == 0) {
790 printf("Error - process ran ok with invalid flag\n");
793 if (launch_proc(argv1) != 0) {
794 printf("Error - process did not run ok with --no-pci flag\n");
797 if (launch_proc(argv2) != 0) {
798 printf("Error - process did not run ok with -v flag\n");
801 if (launch_proc(argv3) != 0) {
802 printf("Error - process did not run ok with --syslog flag\n");
805 if (launch_proc(argv4) == 0) {
806 printf("Error - process run ok with empty --syslog flag\n");
809 if (launch_proc(argv5) == 0) {
810 printf("Error - process run ok with invalid --syslog flag\n");
813 if (launch_proc(argv6) != 0) {
814 printf("Error - process did not run ok with --no-shconf flag\n");
817 #ifdef RTE_EXEC_ENV_BSDAPP
820 if (launch_proc(argv7) != 0) {
821 printf("Error - process did not run ok with --huge-dir flag\n");
824 if (launch_proc(argv8) == 0) {
825 printf("Error - process run ok with empty --huge-dir flag\n");
828 if (launch_proc(argv9) == 0) {
829 printf("Error - process run ok with invalid --huge-dir flag\n");
832 if (launch_proc(argv10) != 0) {
833 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
836 if (launch_proc(argv11) != 0) {
837 printf("Error - process did not run ok with --base-virtaddr parameter\n");
840 if (launch_proc(argv12) != 0) {
841 printf("Error - process did not run ok with "
842 "--vfio-intr INTx parameter\n");
845 if (launch_proc(argv13) != 0) {
846 printf("Error - process did not run ok with "
847 "--vfio-intr MSI parameter\n");
850 if (launch_proc(argv14) != 0) {
851 printf("Error - process did not run ok with "
852 "--vfio-intr MSI-X parameter\n");
855 if (launch_proc(argv15) == 0) {
856 printf("Error - process run ok with "
857 "--vfio-intr invalid parameter\n");
865 test_file_prefix(void)
868 * 1. check if current process hugefiles are locked
869 * 2. try to run secondary process without a corresponding primary process
870 * (while failing to run, it will also remove any unused hugepage files)
871 * 3. check if current process hugefiles are still in place and are locked
872 * 4. run a primary process with memtest1 prefix
873 * 5. check if memtest1 hugefiles are created
874 * 6. run a primary process with memtest2 prefix
875 * 7. check that only memtest2 hugefiles are present in the hugedir
878 #ifdef RTE_EXEC_ENV_BSDAPP
882 /* this should fail unless the test itself is run with "memtest" prefix */
883 const char *argv0[] = {prgname, mp_flag, "-c", "1", "-n", "2", "-m", "2",
884 "--file-prefix=" memtest };
886 /* primary process with memtest1 */
887 const char *argv1[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
888 "--file-prefix=" memtest1 };
890 /* primary process with memtest2 */
891 const char *argv2[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
892 "--file-prefix=" memtest2 };
895 if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
896 printf("Error - unable to get current prefix!\n");
899 #ifdef RTE_LIBRTE_XEN_DOM0
903 /* check if files for current prefix are present */
904 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
905 printf("Error - hugepage files for %s were not created!\n", prefix);
909 /* checks if files for current prefix are locked */
910 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
911 printf("Error - hugepages for current process aren't locked!\n");
915 /* check if files for secondary process are present */
916 if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
917 /* check if they are not locked */
918 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
919 printf("Error - hugepages for current process are locked!\n");
922 /* they aren't locked, delete them */
924 if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
925 printf("Error - deleting hugepages failed!\n");
931 if (launch_proc(argv0) == 0) {
932 printf("Error - secondary process ran ok without primary process\n");
936 /* check if files for current prefix are present */
937 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
938 printf("Error - hugepage files for %s were not created!\n", prefix);
942 /* checks if files for current prefix are locked */
943 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
944 printf("Error - hugepages for current process aren't locked!\n");
948 if (launch_proc(argv1) != 0) {
949 printf("Error - failed to run with --file-prefix=%s\n", memtest);
953 /* check if memtest1_map0 is present */
954 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
955 printf("Error - hugepage files for %s were not created!\n", memtest1);
959 if (launch_proc(argv2) != 0) {
960 printf("Error - failed to run with --file-prefix=%s\n", memtest2);
964 /* check if hugefiles for memtest2 are present */
965 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
966 printf("Error - hugepage files for %s were not created!\n", memtest2);
970 /* check if hugefiles for memtest1 are present */
971 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
972 printf("Error - hugepage files for %s were not deleted!\n", memtest1);
980 * Tests for correct handling of -m and --socket-mem flags
983 test_memory_flags(void)
985 const char* mem_size = NULL;
986 #ifdef RTE_EXEC_ENV_BSDAPP
987 /* BSD target doesn't support prefixes at this point */
988 const char * prefix = "";
990 char prefix[PATH_MAX], tmp[PATH_MAX];
991 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
992 printf("Error - unable to get current prefix!\n");
995 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
997 #ifdef RTE_LIBRTE_XEN_DOM0
1004 /* valid -m flag and mp flag */
1005 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "10",
1006 "-n", "2", "-m", mem_size};
1009 const char *argv1[] = {prgname, "-c", "10", "-n", "2",
1010 "--file-prefix=" memtest, "-m", mem_size};
1012 /* invalid (zero) --socket-mem flag */
1013 const char *argv2[] = {prgname, "-c", "10", "-n", "2",
1014 "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
1016 /* invalid (incomplete) --socket-mem flag */
1017 const char *argv3[] = {prgname, "-c", "10", "-n", "2",
1018 "--file-prefix=" memtest, "--socket-mem=2,2,"};
1020 /* invalid (mixed with invalid data) --socket-mem flag */
1021 const char *argv4[] = {prgname, "-c", "10", "-n", "2",
1022 "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
1024 /* invalid (with numeric value as last character) --socket-mem flag */
1025 const char *argv5[] = {prgname, "-c", "10", "-n", "2",
1026 "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
1028 /* invalid (with empty socket) --socket-mem flag */
1029 const char *argv6[] = {prgname, "-c", "10", "-n", "2",
1030 "--file-prefix=" memtest, "--socket-mem=2,,2"};
1032 /* invalid (null) --socket-mem flag */
1033 const char *argv7[] = {prgname, "-c", "10", "-n", "2",
1034 "--file-prefix=" memtest, "--socket-mem="};
1036 /* valid --socket-mem specified together with -m flag */
1037 const char *argv8[] = {prgname, "-c", "10", "-n", "2",
1038 "--file-prefix=" memtest, "-m", "2", "--socket-mem=2,2"};
1040 /* construct an invalid socket mask with 2 megs on each socket plus
1041 * extra 2 megs on socket that doesn't exist on current system */
1042 char invalid_socket_mem[SOCKET_MEM_STRLEN];
1043 char buf[SOCKET_MEM_STRLEN]; /* to avoid copying string onto itself */
1045 #ifdef RTE_EXEC_ENV_BSDAPP
1046 int i, num_sockets = 1;
1048 int i, num_sockets = get_number_of_sockets();
1051 if (num_sockets <= 0 || num_sockets > RTE_MAX_NUMA_NODES) {
1052 printf("Error - cannot get number of sockets!\n");
1056 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
1058 /* add one extra socket */
1059 for (i = 0; i < num_sockets + 1; i++) {
1060 snprintf(buf, sizeof(buf), "%s2", invalid_socket_mem);
1061 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1063 if (num_sockets + 1 - i > 1) {
1064 snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
1065 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1069 /* construct a valid socket mask with 2 megs on each existing socket */
1070 char valid_socket_mem[SOCKET_MEM_STRLEN];
1072 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
1074 /* add one extra socket */
1075 for (i = 0; i < num_sockets; i++) {
1076 snprintf(buf, sizeof(buf), "%s2", valid_socket_mem);
1077 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1079 if (num_sockets - i > 1) {
1080 snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
1081 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1085 /* invalid --socket-mem flag (with extra socket) */
1086 const char *argv9[] = {prgname, "-c", "10", "-n", "2",
1087 "--file-prefix=" memtest, invalid_socket_mem};
1089 /* valid --socket-mem flag */
1090 const char *argv10[] = {prgname, "-c", "10", "-n", "2",
1091 "--file-prefix=" memtest, valid_socket_mem};
1093 if (launch_proc(argv0) != 0) {
1094 printf("Error - secondary process failed with valid -m flag !\n");
1098 #ifdef RTE_EXEC_ENV_BSDAPP
1099 /* no other tests are applicable to BSD */
1103 if (launch_proc(argv1) != 0) {
1104 printf("Error - process failed with valid -m flag!\n");
1107 #ifdef RTE_LIBRTE_XEN_DOM0
1110 if (launch_proc(argv2) == 0) {
1111 printf("Error - process run ok with invalid (zero) --socket-mem!\n");
1115 if (launch_proc(argv3) == 0) {
1116 printf("Error - process run ok with invalid "
1117 "(incomplete) --socket-mem!\n");
1121 if (launch_proc(argv4) == 0) {
1122 printf("Error - process run ok with invalid "
1123 "(mixed with invalid input) --socket-mem!\n");
1127 if (launch_proc(argv5) == 0) {
1128 printf("Error - process run ok with invalid "
1129 "(mixed with invalid input with a numeric value as "
1130 "last character) --socket-mem!\n");
1134 if (launch_proc(argv6) == 0) {
1135 printf("Error - process run ok with invalid "
1136 "(with empty socket) --socket-mem!\n");
1140 if (launch_proc(argv7) == 0) {
1141 printf("Error - process run ok with invalid (null) --socket-mem!\n");
1145 if (launch_proc(argv8) == 0) {
1146 printf("Error - process run ok with --socket-mem and -m specified!\n");
1150 if (launch_proc(argv9) == 0) {
1151 printf("Error - process run ok with extra socket in --socket-mem!\n");
1155 if (launch_proc(argv10) != 0) {
1156 printf("Error - process failed with valid --socket-mem!\n");
1164 test_eal_flags(void)
1168 ret = test_missing_c_flag();
1170 printf("Error in test_missing_c_flag()\n");
1174 ret = test_missing_n_flag();
1176 printf("Error in test_missing_n_flag()\n");
1180 ret = test_no_hpet_flag();
1182 printf("Error in test_no_hpet_flag()\n");
1186 ret = test_no_huge_flag();
1188 printf("Error in test_no_huge_flag()\n");
1192 ret = test_whitelist_flag();
1194 printf("Error in test_invalid_whitelist_flag()\n");
1198 ret = test_invalid_b_flag();
1200 printf("Error in test_invalid_b_flag()\n");
1204 ret = test_invalid_r_flag();
1206 printf("Error in test_invalid_r_flag()\n");
1210 ret = test_memory_flags();
1212 printf("Error in test_memory_flags()\n");
1216 ret = test_file_prefix();
1218 printf("Error in test_file_prefix()\n");
1222 #ifdef RTE_LIBRTE_XEN_DOM0
1223 ret = test_dom0_misc_flags();
1225 ret = test_misc_flags();
1228 printf("Error in test_misc_flags()");
1236 /* Baremetal version
1237 * Multiprocess not applicable, so just return 0 always
1240 test_eal_flags(void)
1242 printf("Multi-process not possible for baremetal, cannot test EAL flags\n");