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 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]);
277 * Test that the app doesn't run with invalid whitelist option.
278 * Final tests ensures it does run with valid options as sanity check (one
279 * test for with Domain+BDF, second for just with BDF)
282 test_whitelist_flag(void)
285 #ifdef RTE_EXEC_ENV_BSDAPP
286 /* BSD target doesn't support prefixes at this point */
287 const char * prefix = "";
289 char prefix[PATH_MAX], tmp[PATH_MAX];
290 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
291 printf("Error - unable to get current prefix!\n");
294 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
297 const char *wlinval[][11] = {
298 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
299 pci_whitelist, "error", "", ""},
300 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
301 pci_whitelist, "0:0:0", "", ""},
302 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
303 pci_whitelist, "0:error:0.1", "", ""},
304 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
305 pci_whitelist, "0:0:0.1error", "", ""},
306 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
307 pci_whitelist, "error0:0:0.1", "", ""},
308 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
309 pci_whitelist, "0:0:0.1.2", "", ""},
311 /* Test with valid whitelist option */
312 const char *wlval1[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
313 pci_whitelist, "00FF:09:0B.3"};
314 const char *wlval2[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
315 pci_whitelist, "09:0B.3", pci_whitelist, "0a:0b.1"};
316 const char *wlval3[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
317 pci_whitelist, "09:0B.3,type=test",
318 pci_whitelist, "08:00.1,type=normal",
319 #ifdef CONFIG_RTE_LIBRTE_PMD_RING
320 vdev, "eth_ring,arg=test",
324 for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
325 if (launch_proc(wlinval[i]) == 0) {
326 printf("Error - process did run ok with invalid "
327 "whitelist parameter\n");
331 if (launch_proc(wlval1) != 0 ) {
332 printf("Error - process did not run ok with valid whitelist\n");
335 if (launch_proc(wlval2) != 0 ) {
336 printf("Error - process did not run ok with valid whitelist value set\n");
339 if (launch_proc(wlval3) != 0 ) {
340 printf("Error - process did not run ok with valid whitelist + args\n");
348 * Test that the app doesn't run with invalid blacklist option.
349 * Final test ensures it does run with valid options as sanity check
352 test_invalid_b_flag(void)
354 #ifdef RTE_EXEC_ENV_BSDAPP
355 /* BSD target doesn't support prefixes at this point */
356 const char * prefix = "";
358 char prefix[PATH_MAX], tmp[PATH_MAX];
359 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
360 printf("Error - unable to get current prefix!\n");
363 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
366 const char *blinval[][9] = {
367 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error"},
368 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0"},
369 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:error:0.1"},
370 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1error"},
371 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error0:0:0.1"},
372 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1.2"},
374 /* Test with valid blacklist option */
375 const char *blval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
379 for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
380 if (launch_proc(blinval[i]) == 0) {
381 printf("Error - process did run ok with invalid "
382 "blacklist parameter\n");
386 if (launch_proc(blval) != 0) {
387 printf("Error - process did not run ok with valid blacklist value\n");
395 * Test that the app doesn't run with invalid -r option.
398 test_invalid_r_flag(void)
400 #ifdef RTE_EXEC_ENV_BSDAPP
401 /* BSD target doesn't support prefixes at this point */
402 const char * prefix = "";
404 char prefix[PATH_MAX], tmp[PATH_MAX];
405 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
406 printf("Error - unable to get current prefix!\n");
409 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
412 const char *rinval[][9] = {
413 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "error"},
414 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "0"},
415 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "-1"},
416 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "17"},
418 /* Test with valid blacklist option */
419 const char *rval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
423 for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
424 if (launch_proc(rinval[i]) == 0) {
425 printf("Error - process did run ok with invalid "
426 "-r (rank) parameter\n");
430 if (launch_proc(rval) != 0) {
431 printf("Error - process did not run ok with valid -r (rank) value\n");
438 * Test that the app doesn't run without the coremask flag. In all cases
439 * should give an error and fail to run
442 test_missing_c_flag(void)
444 #ifdef RTE_EXEC_ENV_BSDAPP
445 /* BSD target doesn't support prefixes at this point */
446 const char * prefix = "";
448 char prefix[PATH_MAX], tmp[PATH_MAX];
449 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
450 printf("Error - unable to get current prefix!\n");
453 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
456 /* -c flag but no coremask value */
457 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "3", "-c"};
458 /* No -c flag at all */
459 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "3"};
460 /* bad coremask value */
461 const char *argv3[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "error" };
462 /* sanity check of tests - valid coremask value */
463 const char *argv4[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "1" };
465 if (launch_proc(argv1) == 0
466 || launch_proc(argv2) == 0
467 || launch_proc(argv3) == 0) {
468 printf("Error - process ran without error when missing -c flag\n");
471 if (launch_proc(argv4) != 0) {
472 printf("Error - process did not run ok with valid coremask value\n");
479 * Test that the app doesn't run without the -n flag. In all cases
480 * should give an error and fail to run.
481 * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
485 test_missing_n_flag(void)
487 #ifdef RTE_EXEC_ENV_BSDAPP
488 /* BSD target doesn't support prefixes at this point */
489 const char * prefix = "";
491 char prefix[PATH_MAX], tmp[PATH_MAX];
492 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
493 printf("Error - unable to get current prefix!\n");
496 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
499 /* -n flag but no value */
500 const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"};
501 /* No -n flag at all */
502 const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"};
503 /* bad numeric value */
504 const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" };
505 /* out-of-range value */
506 const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "9" };
507 /* sanity test - check with good value */
508 const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" };
510 if (launch_proc(argv1) == 0
511 || launch_proc(argv2) == 0
512 || launch_proc(argv3) == 0
513 || launch_proc(argv4) == 0) {
514 printf("Error - process ran without error when missing -n flag\n");
517 if (launch_proc(argv5) != 0) {
518 printf("Error - process did not run ok with valid num-channel value\n");
525 * Test that the app runs with HPET, and without HPET
528 test_no_hpet_flag(void)
530 char prefix[PATH_MAX], tmp[PATH_MAX];
532 #ifdef RTE_EXEC_ENV_BSDAPP
535 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
536 printf("Error - unable to get current prefix!\n");
539 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
542 const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"};
543 /* Without --no-hpet */
544 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-n", "2"};
546 if (launch_proc(argv1) != 0) {
547 printf("Error - process did not run ok with --no-hpet flag\n");
550 if (launch_proc(argv2) != 0) {
551 printf("Error - process did not run ok without --no-hpet flag\n");
558 * Test that the app runs with --no-huge and doesn't run when either
559 * -m or --socket-mem are specified with --no-huge.
562 test_no_huge_flag(void)
564 #ifdef RTE_EXEC_ENV_BSDAPP
565 /* BSD target doesn't support prefixes at this point, and we also need to
566 * run another primary process here */
567 const char * prefix = no_shconf;
569 const char * prefix = "--file-prefix=nohuge";
573 const char *argv1[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2"};
574 /* With --no-huge and -m */
575 const char *argv2[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2", "-m", "2"};
577 /* With --no-huge and --socket-mem */
578 const char *argv3[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
580 /* With --no-huge, -m and --socket-mem */
581 const char *argv4[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
582 "-m", "2", "--socket-mem=2"};
583 if (launch_proc(argv1) != 0) {
584 printf("Error - process did not run ok with --no-huge flag\n");
587 if (launch_proc(argv2) == 0) {
588 printf("Error - process run ok with --no-huge and -m flags\n");
591 #ifdef RTE_EXEC_ENV_BSDAPP
592 /* BSD target does not support NUMA, hence no --socket-mem tests */
596 if (launch_proc(argv3) == 0) {
597 printf("Error - process run ok with --no-huge and --socket-mem "
601 if (launch_proc(argv4) == 0) {
602 printf("Error - process run ok with --no-huge, -m and "
603 "--socket-mem flags\n");
609 #ifdef RTE_LIBRTE_XEN_DOM0
611 test_dom0_misc_flags(void)
613 char prefix[PATH_MAX], tmp[PATH_MAX];
615 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
616 printf("Error - unable to get current prefix!\n");
619 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
621 /* check that some general flags don't prevent things from working.
622 * All cases, apart from the first, app should run.
623 * No futher testing of output done.
625 /* sanity check - failure with invalid option */
626 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
629 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
631 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
632 /* With valid --syslog */
633 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
634 "--syslog", "syslog"};
635 /* With empty --syslog (should fail) */
636 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
637 /* With invalid --syslog */
638 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
639 /* With no-sh-conf */
640 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "20",
641 "--no-shconf", "--file-prefix=noshconf" };
643 if (launch_proc(argv0) == 0) {
644 printf("Error - process ran ok with invalid flag\n");
647 if (launch_proc(argv1) != 0) {
648 printf("Error - process did not run ok with --no-pci flag\n");
651 if (launch_proc(argv2) != 0) {
652 printf("Error - process did not run ok with -v flag\n");
655 if (launch_proc(argv3) != 0) {
656 printf("Error - process did not run ok with --syslog flag\n");
659 if (launch_proc(argv4) == 0) {
660 printf("Error - process run ok with empty --syslog flag\n");
663 if (launch_proc(argv5) == 0) {
664 printf("Error - process run ok with invalid --syslog flag\n");
667 if (launch_proc(argv6) != 0) {
668 printf("Error - process did not run ok with --no-shconf flag\n");
676 test_misc_flags(void)
678 char hugepath[PATH_MAX] = {0};
679 #ifdef RTE_EXEC_ENV_BSDAPP
680 /* BSD target doesn't support prefixes at this point */
681 const char * prefix = "";
682 const char * nosh_prefix = "";
684 char prefix[PATH_MAX], tmp[PATH_MAX];
685 const char * nosh_prefix = "--file-prefix=noshconf";
686 FILE * hugedir_handle = NULL;
687 char line[PATH_MAX] = {0};
688 unsigned i, isempty = 1;
689 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
690 printf("Error - unable to get current prefix!\n");
693 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
696 * get first valid hugepage path
699 /* get hugetlbfs mountpoints from /proc/mounts */
700 hugedir_handle = fopen("/proc/mounts", "r");
702 if (hugedir_handle == NULL) {
703 printf("Error opening /proc/mounts!\n");
707 /* read /proc/mounts */
708 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
710 /* find first valid hugepath */
711 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
715 fclose(hugedir_handle);
717 /* check if path is not empty */
718 for (i = 0; i < sizeof(hugepath); i++)
719 if (hugepath[i] != '\0')
723 printf("No mounted hugepage dir found!\n");
729 /* check that some general flags don't prevent things from working.
730 * All cases, apart from the first, app should run.
731 * No futher testing of output done.
733 /* sanity check - failure with invalid option */
734 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
737 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
739 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
740 /* With valid --syslog */
741 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
742 "--syslog", "syslog"};
743 /* With empty --syslog (should fail) */
744 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
745 /* With invalid --syslog */
746 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
747 /* With no-sh-conf */
748 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
749 no_shconf, nosh_prefix };
751 #ifdef RTE_EXEC_ENV_BSDAPP
754 /* With --huge-dir */
755 const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
756 "--file-prefix=hugedir", "--huge-dir", hugepath};
757 /* With empty --huge-dir (should fail) */
758 const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
759 "--file-prefix=hugedir", "--huge-dir"};
760 /* With invalid --huge-dir */
761 const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
762 "--file-prefix=hugedir", "--huge-dir", "invalid"};
763 /* Secondary process with invalid --huge-dir (should run as flag has no
764 * effect on secondary processes) */
765 const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
767 /* try running with base-virtaddr param */
768 const char *argv11[] = {prgname, "--file-prefix=virtaddr",
769 "-c", "1", "-n", "2", "--base-virtaddr=0x12345678"};
771 /* try running with --vfio-intr INTx flag */
772 const char *argv12[] = {prgname, "--file-prefix=intr",
773 "-c", "1", "-n", "2", "--vfio-intr=legacy"};
775 /* try running with --vfio-intr MSI flag */
776 const char *argv13[] = {prgname, "--file-prefix=intr",
777 "-c", "1", "-n", "2", "--vfio-intr=msi"};
779 /* try running with --vfio-intr MSI-X flag */
780 const char *argv14[] = {prgname, "--file-prefix=intr",
781 "-c", "1", "-n", "2", "--vfio-intr=msix"};
783 /* try running with --vfio-intr invalid flag */
784 const char *argv15[] = {prgname, "--file-prefix=intr",
785 "-c", "1", "-n", "2", "--vfio-intr=invalid"};
788 if (launch_proc(argv0) == 0) {
789 printf("Error - process ran ok with invalid flag\n");
792 if (launch_proc(argv1) != 0) {
793 printf("Error - process did not run ok with --no-pci flag\n");
796 if (launch_proc(argv2) != 0) {
797 printf("Error - process did not run ok with -v flag\n");
800 if (launch_proc(argv3) != 0) {
801 printf("Error - process did not run ok with --syslog flag\n");
804 if (launch_proc(argv4) == 0) {
805 printf("Error - process run ok with empty --syslog flag\n");
808 if (launch_proc(argv5) == 0) {
809 printf("Error - process run ok with invalid --syslog flag\n");
812 if (launch_proc(argv6) != 0) {
813 printf("Error - process did not run ok with --no-shconf flag\n");
816 #ifdef RTE_EXEC_ENV_BSDAPP
819 if (launch_proc(argv7) != 0) {
820 printf("Error - process did not run ok with --huge-dir flag\n");
823 if (launch_proc(argv8) == 0) {
824 printf("Error - process run ok with empty --huge-dir flag\n");
827 if (launch_proc(argv9) == 0) {
828 printf("Error - process run ok with invalid --huge-dir flag\n");
831 if (launch_proc(argv10) != 0) {
832 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
835 if (launch_proc(argv11) != 0) {
836 printf("Error - process did not run ok with --base-virtaddr parameter\n");
839 if (launch_proc(argv12) != 0) {
840 printf("Error - process did not run ok with "
841 "--vfio-intr INTx parameter\n");
844 if (launch_proc(argv13) != 0) {
845 printf("Error - process did not run ok with "
846 "--vfio-intr MSI parameter\n");
849 if (launch_proc(argv14) != 0) {
850 printf("Error - process did not run ok with "
851 "--vfio-intr MSI-X parameter\n");
854 if (launch_proc(argv15) == 0) {
855 printf("Error - process run ok with "
856 "--vfio-intr invalid 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");