4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5 * Copyright(c) 2014 6WIND S.A.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 #include <rte_debug.h>
51 #include <rte_string_fns.h>
55 #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 pci_whitelist "--pci-whitelist"
61 #define memtest "memtest"
62 #define memtest1 "memtest1"
63 #define memtest2 "memtest2"
64 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 10)
65 #define launch_proc(ARGV) process_dup(ARGV, \
66 sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
68 enum hugepage_action {
69 HUGEPAGE_CHECK_EXISTS = 0,
70 HUGEPAGE_CHECK_LOCKED,
75 /* if string contains a hugepage path */
77 get_hugepage_path(char * src, int src_len, char * dst, int dst_len)
80 char *tokens[NUM_TOKENS];
82 /* if we couldn't properly split the string */
83 if (rte_strsplit(src, src_len, tokens, NUM_TOKENS, ' ') < NUM_TOKENS)
86 if (strncmp(tokens[2], "hugetlbfs", sizeof("hugetlbfs")) == 0) {
87 snprintf(dst, dst_len, "%s", tokens[1]);
94 * Cycles through hugepage directories and looks for hugepage
95 * files associated with a given prefix. Depending on value of
96 * action, the hugepages are checked if they exist, checked if
97 * they can be locked, or are simply deleted.
99 * Returns 1 if it finds at least one hugepage matching the action
100 * Returns 0 if no matching hugepages were found
101 * Returns -1 if it encounters an error
104 process_hugefiles(const char * prefix, enum hugepage_action action)
106 FILE * hugedir_handle = NULL;
107 DIR * hugepage_dir = NULL;
108 struct dirent *dirent = NULL;
110 char hugefile_prefix[PATH_MAX] = {0};
111 char hugedir[PATH_MAX] = {0};
112 char line[PATH_MAX] = {0};
114 int fd, lck_result, result = 0;
116 const int prefix_len = snprintf(hugefile_prefix,
117 sizeof(hugefile_prefix), "%smap_", prefix);
118 if (prefix_len <= 0 || prefix_len >= (int)sizeof(hugefile_prefix)
119 || prefix_len >= (int)sizeof(dirent->d_name)) {
120 printf("Error creating hugefile filename prefix\n");
124 /* get hugetlbfs mountpoints from /proc/mounts */
125 hugedir_handle = fopen("/proc/mounts", "r");
127 if (hugedir_handle == NULL) {
128 printf("Error parsing /proc/mounts!\n");
132 /* read and parse script output */
133 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
135 /* check if we have a hugepage filesystem path */
136 if (!get_hugepage_path(line, sizeof(line), hugedir, sizeof(hugedir)))
139 /* check if directory exists */
140 if ((hugepage_dir = opendir(hugedir)) == NULL) {
141 fclose(hugedir_handle);
142 printf("Error reading %s: %s\n", hugedir, strerror(errno));
146 while ((dirent = readdir(hugepage_dir)) != NULL) {
147 if (memcmp(dirent->d_name, hugefile_prefix, prefix_len) != 0)
151 case HUGEPAGE_CHECK_EXISTS:
153 /* file exists, return */
158 case HUGEPAGE_DELETE:
160 char file_path[PATH_MAX] = {0};
162 snprintf(file_path, sizeof(file_path),
163 "%s/%s", hugedir, dirent->d_name);
166 if (remove(file_path) < 0) {
167 printf("Error deleting %s - %s!\n",
168 dirent->d_name, strerror(errno));
169 closedir(hugepage_dir);
176 case HUGEPAGE_CHECK_LOCKED:
178 /* try and lock the file */
179 fd = openat(dirfd(hugepage_dir), dirent->d_name, O_RDONLY);
181 /* this shouldn't happen */
183 printf("Error opening %s - %s!\n",
184 dirent->d_name, strerror(errno));
185 closedir(hugepage_dir);
190 /* non-blocking lock */
191 lck_result = flock(fd, LOCK_EX | LOCK_NB);
193 /* if lock succeeds, there's something wrong */
194 if (lck_result != -1) {
197 /* unlock the resulting lock */
200 closedir(hugepage_dir);
207 /* shouldn't happen */
212 } /* read hugepage directory */
213 closedir(hugepage_dir);
214 } /* read /proc/mounts */
216 fclose(hugedir_handle);
220 #ifdef RTE_EXEC_ENV_LINUXAPP
222 * count the number of "node*" files in /sys/devices/system/node/
225 get_number_of_sockets(void)
227 struct dirent *dirent = NULL;
228 const char * nodedir = "/sys/devices/system/node/";
232 /* check if directory exists */
233 if ((dir = opendir(nodedir)) == NULL) {
234 /* if errno==ENOENT this means we don't have NUMA support */
235 if (errno == ENOENT) {
236 printf("No NUMA nodes detected: assuming 1 available socket\n");
239 printf("Error opening %s: %s\n", nodedir, strerror(errno));
243 while ((dirent = readdir(dir)) != NULL)
244 if (strncmp(dirent->d_name, "node", sizeof("node") - 1) == 0)
253 get_current_prefix(char * prefix, int size)
255 char path[PATH_MAX] = {0};
256 char buf[PATH_MAX] = {0};
258 /* get file for config (fd is always 3) */
259 snprintf(path, sizeof(path), "/proc/self/fd/%d", 3);
261 /* return NULL on error */
262 if (readlink(path, buf, sizeof(buf)) == -1)
265 /* get the basename */
266 snprintf(buf, sizeof(buf), "%s", basename(buf));
268 /* copy string all the way from second char up to start of _config */
269 snprintf(prefix, size, "%.*s",
270 (int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
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 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",
321 for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
322 if (launch_proc(wlinval[i]) == 0) {
323 printf("Error - process did run ok with invalid "
324 "whitelist parameter\n");
328 if (launch_proc(wlval1) != 0 ) {
329 printf("Error - process did not run ok with valid whitelist\n");
332 if (launch_proc(wlval2) != 0 ) {
333 printf("Error - process did not run ok with valid whitelist value set\n");
336 if (launch_proc(wlval3) != 0 ) {
337 printf("Error - process did not run ok with valid whitelist + args\n");
345 * Test that the app doesn't run with invalid blacklist option.
346 * Final test ensures it does run with valid options as sanity check
349 test_invalid_b_flag(void)
351 #ifdef RTE_EXEC_ENV_BSDAPP
352 /* BSD target doesn't support prefixes at this point */
353 const char * prefix = "";
355 char prefix[PATH_MAX], tmp[PATH_MAX];
356 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
357 printf("Error - unable to get current prefix!\n");
360 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
363 const char *blinval[][9] = {
364 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error"},
365 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0"},
366 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:error:0.1"},
367 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1error"},
368 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error0:0:0.1"},
369 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1.2"},
371 /* Test with valid blacklist option */
372 const char *blval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
376 for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
377 if (launch_proc(blinval[i]) == 0) {
378 printf("Error - process did run ok with invalid "
379 "blacklist parameter\n");
383 if (launch_proc(blval) != 0) {
384 printf("Error - process did not run ok with valid blacklist value\n");
391 * Test that the app doesn't run with invalid vdev option.
392 * Final test ensures it does run with valid options as sanity check
394 #ifdef RTE_LIBRTE_PMD_RING
396 test_invalid_vdev_flag(void)
398 /* Test with invalid vdev option */
399 const char *vdevinval[] = {prgname, "--file-prefix=vdev","-n", "1",
400 "-c", "1", vdev, "eth_dummy"};
402 /* Test with valid vdev option */
403 const char *vdevval1[] = {prgname, "--file-prefix=vdev", "-n", "1",
404 "-c", "1", vdev, "eth_ring0"};
406 const char *vdevval2[] = {prgname, "--file-prefix=vdev", "-n", "1",
407 "-c", "1", vdev, "eth_ring0,args=test"};
409 const char *vdevval3[] = {prgname, "--file-prefix=vdev", "-n", "1",
410 "-c", "1", vdev, "eth_ring0,nodeaction=r1:0:CREATE"};
412 if (launch_proc(vdevinval) == 0) {
413 printf("Error - process did run ok with invalid "
418 if (launch_proc(vdevval1) != 0) {
419 printf("Error - process did not run ok with valid vdev value\n");
423 if (launch_proc(vdevval2) != 0) {
424 printf("Error - process did not run ok with valid vdev value,"
425 "with dummy args\n");
429 if (launch_proc(vdevval3) != 0) {
430 printf("Error - process did not run ok with valid vdev value,"
431 "with valid args\n");
439 * Test that the app doesn't run with invalid -r option.
442 test_invalid_r_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 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
456 const char *rinval[][9] = {
457 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "error"},
458 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "0"},
459 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "-1"},
460 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "17"},
462 /* Test with valid blacklist option */
463 const char *rval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
467 for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
468 if (launch_proc(rinval[i]) == 0) {
469 printf("Error - process did run ok with invalid "
470 "-r (rank) parameter\n");
474 if (launch_proc(rval) != 0) {
475 printf("Error - process did not run ok with valid -r (rank) value\n");
482 * Test that the app doesn't run without the coremask flag. In all cases
483 * should give an error and fail to run
486 test_missing_c_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 /* -c flag but no coremask value */
501 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "3", "-c"};
502 /* No -c flag at all */
503 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "3"};
504 /* bad coremask value */
505 const char *argv3[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "error" };
506 /* sanity check of tests - valid coremask value */
507 const char *argv4[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "1" };
509 if (launch_proc(argv1) == 0
510 || launch_proc(argv2) == 0
511 || launch_proc(argv3) == 0) {
512 printf("Error - process ran without error when missing -c flag\n");
515 if (launch_proc(argv4) != 0) {
516 printf("Error - process did not run ok with valid coremask value\n");
523 * Test that the app doesn't run without the -n flag. In all cases
524 * should give an error and fail to run.
525 * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
529 test_missing_n_flag(void)
531 #ifdef RTE_EXEC_ENV_BSDAPP
532 /* BSD target doesn't support prefixes at this point */
533 const char * prefix = "";
535 char prefix[PATH_MAX], tmp[PATH_MAX];
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 /* -n flag but no value */
544 const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"};
545 /* No -n flag at all */
546 const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"};
547 /* bad numeric value */
548 const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" };
549 /* out-of-range value */
550 const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "9" };
551 /* sanity test - check with good value */
552 const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" };
554 if (launch_proc(argv1) == 0
555 || launch_proc(argv2) == 0
556 || launch_proc(argv3) == 0
557 || launch_proc(argv4) == 0) {
558 printf("Error - process ran without error when missing -n flag\n");
561 if (launch_proc(argv5) != 0) {
562 printf("Error - process did not run ok with valid num-channel value\n");
569 * Test that the app runs with HPET, and without HPET
572 test_no_hpet_flag(void)
574 char prefix[PATH_MAX], tmp[PATH_MAX];
576 #ifdef RTE_EXEC_ENV_BSDAPP
579 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
580 printf("Error - unable to get current prefix!\n");
583 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
586 const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"};
587 /* Without --no-hpet */
588 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-n", "2"};
590 if (launch_proc(argv1) != 0) {
591 printf("Error - process did not run ok with --no-hpet flag\n");
594 if (launch_proc(argv2) != 0) {
595 printf("Error - process did not run ok without --no-hpet flag\n");
602 * Test that the app runs with --no-huge and doesn't run when either
603 * -m or --socket-mem are specified with --no-huge.
606 test_no_huge_flag(void)
608 #ifdef RTE_EXEC_ENV_BSDAPP
609 /* BSD target doesn't support prefixes at this point, and we also need to
610 * run another primary process here */
611 const char * prefix = no_shconf;
613 const char * prefix = "--file-prefix=nohuge";
617 const char *argv1[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2"};
618 /* With --no-huge and -m */
619 const char *argv2[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2", "-m", "2"};
621 /* With --no-huge and --socket-mem */
622 const char *argv3[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
624 /* With --no-huge, -m and --socket-mem */
625 const char *argv4[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
626 "-m", "2", "--socket-mem=2"};
627 if (launch_proc(argv1) != 0) {
628 printf("Error - process did not run ok with --no-huge flag\n");
631 if (launch_proc(argv2) == 0) {
632 printf("Error - process run ok with --no-huge and -m flags\n");
635 #ifdef RTE_EXEC_ENV_BSDAPP
636 /* BSD target does not support NUMA, hence no --socket-mem tests */
640 if (launch_proc(argv3) == 0) {
641 printf("Error - process run ok with --no-huge and --socket-mem "
645 if (launch_proc(argv4) == 0) {
646 printf("Error - process run ok with --no-huge, -m and "
647 "--socket-mem flags\n");
653 #ifdef RTE_LIBRTE_XEN_DOM0
655 test_dom0_misc_flags(void)
657 char prefix[PATH_MAX], tmp[PATH_MAX];
659 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
660 printf("Error - unable to get current prefix!\n");
663 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
665 /* check that some general flags don't prevent things from working.
666 * All cases, apart from the first, app should run.
667 * No futher testing of output done.
669 /* sanity check - failure with invalid option */
670 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
673 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
675 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
676 /* With valid --syslog */
677 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
678 "--syslog", "syslog"};
679 /* With empty --syslog (should fail) */
680 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
681 /* With invalid --syslog */
682 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
683 /* With no-sh-conf */
684 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "20",
685 "--no-shconf", "--file-prefix=noshconf" };
687 if (launch_proc(argv0) == 0) {
688 printf("Error - process ran ok with invalid flag\n");
691 if (launch_proc(argv1) != 0) {
692 printf("Error - process did not run ok with --no-pci flag\n");
695 if (launch_proc(argv2) != 0) {
696 printf("Error - process did not run ok with -v flag\n");
699 if (launch_proc(argv3) != 0) {
700 printf("Error - process did not run ok with --syslog flag\n");
703 if (launch_proc(argv4) == 0) {
704 printf("Error - process run ok with empty --syslog flag\n");
707 if (launch_proc(argv5) == 0) {
708 printf("Error - process run ok with invalid --syslog flag\n");
711 if (launch_proc(argv6) != 0) {
712 printf("Error - process did not run ok with --no-shconf flag\n");
720 test_misc_flags(void)
722 char hugepath[PATH_MAX] = {0};
723 #ifdef RTE_EXEC_ENV_BSDAPP
724 /* BSD target doesn't support prefixes at this point */
725 const char * prefix = "";
726 const char * nosh_prefix = "";
728 char prefix[PATH_MAX], tmp[PATH_MAX];
729 const char * nosh_prefix = "--file-prefix=noshconf";
730 FILE * hugedir_handle = NULL;
731 char line[PATH_MAX] = {0};
732 unsigned i, isempty = 1;
733 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
734 printf("Error - unable to get current prefix!\n");
737 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
740 * get first valid hugepage path
743 /* get hugetlbfs mountpoints from /proc/mounts */
744 hugedir_handle = fopen("/proc/mounts", "r");
746 if (hugedir_handle == NULL) {
747 printf("Error opening /proc/mounts!\n");
751 /* read /proc/mounts */
752 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
754 /* find first valid hugepath */
755 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
759 fclose(hugedir_handle);
761 /* check if path is not empty */
762 for (i = 0; i < sizeof(hugepath); i++)
763 if (hugepath[i] != '\0')
767 printf("No mounted hugepage dir found!\n");
773 /* check that some general flags don't prevent things from working.
774 * All cases, apart from the first, app should run.
775 * No futher testing of output done.
777 /* sanity check - failure with invalid option */
778 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
781 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
783 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
784 /* With valid --syslog */
785 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
786 "--syslog", "syslog"};
787 /* With empty --syslog (should fail) */
788 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
789 /* With invalid --syslog */
790 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
791 /* With no-sh-conf */
792 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
793 no_shconf, nosh_prefix };
795 #ifdef RTE_EXEC_ENV_BSDAPP
798 /* With --huge-dir */
799 const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
800 "--file-prefix=hugedir", "--huge-dir", hugepath};
801 /* With empty --huge-dir (should fail) */
802 const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
803 "--file-prefix=hugedir", "--huge-dir"};
804 /* With invalid --huge-dir */
805 const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
806 "--file-prefix=hugedir", "--huge-dir", "invalid"};
807 /* Secondary process with invalid --huge-dir (should run as flag has no
808 * effect on secondary processes) */
809 const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
811 /* try running with base-virtaddr param */
812 const char *argv11[] = {prgname, "--file-prefix=virtaddr",
813 "-c", "1", "-n", "2", "--base-virtaddr=0x12345678"};
815 /* try running with --vfio-intr INTx flag */
816 const char *argv12[] = {prgname, "--file-prefix=intr",
817 "-c", "1", "-n", "2", "--vfio-intr=legacy"};
819 /* try running with --vfio-intr MSI flag */
820 const char *argv13[] = {prgname, "--file-prefix=intr",
821 "-c", "1", "-n", "2", "--vfio-intr=msi"};
823 /* try running with --vfio-intr MSI-X flag */
824 const char *argv14[] = {prgname, "--file-prefix=intr",
825 "-c", "1", "-n", "2", "--vfio-intr=msix"};
827 /* try running with --vfio-intr invalid flag */
828 const char *argv15[] = {prgname, "--file-prefix=intr",
829 "-c", "1", "-n", "2", "--vfio-intr=invalid"};
832 if (launch_proc(argv0) == 0) {
833 printf("Error - process ran ok with invalid flag\n");
836 if (launch_proc(argv1) != 0) {
837 printf("Error - process did not run ok with --no-pci flag\n");
840 if (launch_proc(argv2) != 0) {
841 printf("Error - process did not run ok with -v flag\n");
844 if (launch_proc(argv3) != 0) {
845 printf("Error - process did not run ok with --syslog flag\n");
848 if (launch_proc(argv4) == 0) {
849 printf("Error - process run ok with empty --syslog flag\n");
852 if (launch_proc(argv5) == 0) {
853 printf("Error - process run ok with invalid --syslog flag\n");
856 if (launch_proc(argv6) != 0) {
857 printf("Error - process did not run ok with --no-shconf flag\n");
860 #ifdef RTE_EXEC_ENV_BSDAPP
863 if (launch_proc(argv7) != 0) {
864 printf("Error - process did not run ok with --huge-dir flag\n");
867 if (launch_proc(argv8) == 0) {
868 printf("Error - process run ok with empty --huge-dir flag\n");
871 if (launch_proc(argv9) == 0) {
872 printf("Error - process run ok with invalid --huge-dir flag\n");
875 if (launch_proc(argv10) != 0) {
876 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
879 if (launch_proc(argv11) != 0) {
880 printf("Error - process did not run ok with --base-virtaddr parameter\n");
883 if (launch_proc(argv12) != 0) {
884 printf("Error - process did not run ok with "
885 "--vfio-intr INTx parameter\n");
888 if (launch_proc(argv13) != 0) {
889 printf("Error - process did not run ok with "
890 "--vfio-intr MSI parameter\n");
893 if (launch_proc(argv14) != 0) {
894 printf("Error - process did not run ok with "
895 "--vfio-intr MSI-X parameter\n");
898 if (launch_proc(argv15) == 0) {
899 printf("Error - process run ok with "
900 "--vfio-intr invalid parameter\n");
908 test_file_prefix(void)
911 * 1. check if current process hugefiles are locked
912 * 2. try to run secondary process without a corresponding primary process
913 * (while failing to run, it will also remove any unused hugepage files)
914 * 3. check if current process hugefiles are still in place and are locked
915 * 4. run a primary process with memtest1 prefix
916 * 5. check if memtest1 hugefiles are created
917 * 6. run a primary process with memtest2 prefix
918 * 7. check that only memtest2 hugefiles are present in the hugedir
921 #ifdef RTE_EXEC_ENV_BSDAPP
925 /* this should fail unless the test itself is run with "memtest" prefix */
926 const char *argv0[] = {prgname, mp_flag, "-c", "1", "-n", "2", "-m", "2",
927 "--file-prefix=" memtest };
929 /* primary process with memtest1 */
930 const char *argv1[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
931 "--file-prefix=" memtest1 };
933 /* primary process with memtest2 */
934 const char *argv2[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
935 "--file-prefix=" memtest2 };
938 if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
939 printf("Error - unable to get current prefix!\n");
942 #ifdef RTE_LIBRTE_XEN_DOM0
946 /* check if files for current prefix are present */
947 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
948 printf("Error - hugepage files for %s were not created!\n", prefix);
952 /* checks if files for current prefix are locked */
953 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
954 printf("Error - hugepages for current process aren't locked!\n");
958 /* check if files for secondary process are present */
959 if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
960 /* check if they are not locked */
961 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
962 printf("Error - hugepages for current process are locked!\n");
965 /* they aren't locked, delete them */
967 if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
968 printf("Error - deleting hugepages failed!\n");
974 if (launch_proc(argv0) == 0) {
975 printf("Error - secondary process ran ok without primary process\n");
979 /* check if files for current prefix are present */
980 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
981 printf("Error - hugepage files for %s were not created!\n", prefix);
985 /* checks if files for current prefix are locked */
986 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
987 printf("Error - hugepages for current process aren't locked!\n");
991 if (launch_proc(argv1) != 0) {
992 printf("Error - failed to run with --file-prefix=%s\n", memtest);
996 /* check if memtest1_map0 is present */
997 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
998 printf("Error - hugepage files for %s were not created!\n", memtest1);
1002 if (launch_proc(argv2) != 0) {
1003 printf("Error - failed to run with --file-prefix=%s\n", memtest2);
1007 /* check if hugefiles for memtest2 are present */
1008 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
1009 printf("Error - hugepage files for %s were not created!\n", memtest2);
1013 /* check if hugefiles for memtest1 are present */
1014 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1015 printf("Error - hugepage files for %s were not deleted!\n", memtest1);
1023 * Tests for correct handling of -m and --socket-mem flags
1026 test_memory_flags(void)
1028 const char* mem_size = NULL;
1029 #ifdef RTE_EXEC_ENV_BSDAPP
1030 /* BSD target doesn't support prefixes at this point */
1031 const char * prefix = "";
1033 char prefix[PATH_MAX], tmp[PATH_MAX];
1034 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
1035 printf("Error - unable to get current prefix!\n");
1038 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
1040 #ifdef RTE_LIBRTE_XEN_DOM0
1047 /* valid -m flag and mp flag */
1048 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "10",
1049 "-n", "2", "-m", mem_size};
1052 const char *argv1[] = {prgname, "-c", "10", "-n", "2",
1053 "--file-prefix=" memtest, "-m", mem_size};
1055 /* invalid (zero) --socket-mem flag */
1056 const char *argv2[] = {prgname, "-c", "10", "-n", "2",
1057 "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
1059 /* invalid (incomplete) --socket-mem flag */
1060 const char *argv3[] = {prgname, "-c", "10", "-n", "2",
1061 "--file-prefix=" memtest, "--socket-mem=2,2,"};
1063 /* invalid (mixed with invalid data) --socket-mem flag */
1064 const char *argv4[] = {prgname, "-c", "10", "-n", "2",
1065 "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
1067 /* invalid (with numeric value as last character) --socket-mem flag */
1068 const char *argv5[] = {prgname, "-c", "10", "-n", "2",
1069 "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
1071 /* invalid (with empty socket) --socket-mem flag */
1072 const char *argv6[] = {prgname, "-c", "10", "-n", "2",
1073 "--file-prefix=" memtest, "--socket-mem=2,,2"};
1075 /* invalid (null) --socket-mem flag */
1076 const char *argv7[] = {prgname, "-c", "10", "-n", "2",
1077 "--file-prefix=" memtest, "--socket-mem="};
1079 /* valid --socket-mem specified together with -m flag */
1080 const char *argv8[] = {prgname, "-c", "10", "-n", "2",
1081 "--file-prefix=" memtest, "-m", "2", "--socket-mem=2,2"};
1083 /* construct an invalid socket mask with 2 megs on each socket plus
1084 * extra 2 megs on socket that doesn't exist on current system */
1085 char invalid_socket_mem[SOCKET_MEM_STRLEN];
1086 char buf[SOCKET_MEM_STRLEN]; /* to avoid copying string onto itself */
1088 #ifdef RTE_EXEC_ENV_BSDAPP
1089 int i, num_sockets = 1;
1091 int i, num_sockets = get_number_of_sockets();
1094 if (num_sockets <= 0 || num_sockets > RTE_MAX_NUMA_NODES) {
1095 printf("Error - cannot get number of sockets!\n");
1099 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
1101 /* add one extra socket */
1102 for (i = 0; i < num_sockets + 1; i++) {
1103 snprintf(buf, sizeof(buf), "%s2", invalid_socket_mem);
1104 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1106 if (num_sockets + 1 - i > 1) {
1107 snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
1108 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1112 /* construct a valid socket mask with 2 megs on each existing socket */
1113 char valid_socket_mem[SOCKET_MEM_STRLEN];
1115 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
1117 /* add one extra socket */
1118 for (i = 0; i < num_sockets; i++) {
1119 snprintf(buf, sizeof(buf), "%s2", valid_socket_mem);
1120 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1122 if (num_sockets - i > 1) {
1123 snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
1124 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1128 /* invalid --socket-mem flag (with extra socket) */
1129 const char *argv9[] = {prgname, "-c", "10", "-n", "2",
1130 "--file-prefix=" memtest, invalid_socket_mem};
1132 /* valid --socket-mem flag */
1133 const char *argv10[] = {prgname, "-c", "10", "-n", "2",
1134 "--file-prefix=" memtest, valid_socket_mem};
1136 if (launch_proc(argv0) != 0) {
1137 printf("Error - secondary process failed with valid -m flag !\n");
1141 #ifdef RTE_EXEC_ENV_BSDAPP
1142 /* no other tests are applicable to BSD */
1146 if (launch_proc(argv1) != 0) {
1147 printf("Error - process failed with valid -m flag!\n");
1150 #ifdef RTE_LIBRTE_XEN_DOM0
1153 if (launch_proc(argv2) == 0) {
1154 printf("Error - process run ok with invalid (zero) --socket-mem!\n");
1158 if (launch_proc(argv3) == 0) {
1159 printf("Error - process run ok with invalid "
1160 "(incomplete) --socket-mem!\n");
1164 if (launch_proc(argv4) == 0) {
1165 printf("Error - process run ok with invalid "
1166 "(mixed with invalid input) --socket-mem!\n");
1170 if (launch_proc(argv5) == 0) {
1171 printf("Error - process run ok with invalid "
1172 "(mixed with invalid input with a numeric value as "
1173 "last character) --socket-mem!\n");
1177 if (launch_proc(argv6) == 0) {
1178 printf("Error - process run ok with invalid "
1179 "(with empty socket) --socket-mem!\n");
1183 if (launch_proc(argv7) == 0) {
1184 printf("Error - process run ok with invalid (null) --socket-mem!\n");
1188 if (launch_proc(argv8) == 0) {
1189 printf("Error - process run ok with --socket-mem and -m specified!\n");
1193 if (launch_proc(argv9) == 0) {
1194 printf("Error - process run ok with extra socket in --socket-mem!\n");
1198 if (launch_proc(argv10) != 0) {
1199 printf("Error - process failed with valid --socket-mem!\n");
1207 test_eal_flags(void)
1211 ret = test_missing_c_flag();
1213 printf("Error in test_missing_c_flag()\n");
1217 ret = test_missing_n_flag();
1219 printf("Error in test_missing_n_flag()\n");
1223 ret = test_no_hpet_flag();
1225 printf("Error in test_no_hpet_flag()\n");
1229 ret = test_no_huge_flag();
1231 printf("Error in test_no_huge_flag()\n");
1235 ret = test_whitelist_flag();
1237 printf("Error in test_invalid_whitelist_flag()\n");
1241 ret = test_invalid_b_flag();
1243 printf("Error in test_invalid_b_flag()\n");
1247 #ifdef RTE_LIBRTE_PMD_RING
1248 ret = test_invalid_vdev_flag();
1250 printf("Error in test_invalid_vdev_flag()\n");
1254 ret = test_invalid_r_flag();
1256 printf("Error in test_invalid_r_flag()\n");
1260 ret = test_memory_flags();
1262 printf("Error in test_memory_flags()\n");
1266 ret = test_file_prefix();
1268 printf("Error in test_file_prefix()\n");
1272 #ifdef RTE_LIBRTE_XEN_DOM0
1273 ret = test_dom0_misc_flags();
1275 ret = test_misc_flags();
1278 printf("Error in test_misc_flags()");
1285 static struct test_command eal_flags_cmd = {
1286 .command = "eal_flags_autotest",
1287 .callback = test_eal_flags,
1289 REGISTER_TEST_COMMAND(eal_flags_cmd);