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 use_device "--use-device"
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 rte_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 = rte_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 rte_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 rte_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 rte_snprintf(buf, sizeof(buf), "%s", basename(buf));
268 /* copy string all the way from second char up to start of _config */
269 rte_snprintf(prefix, size, "%.*s",
270 strnlen(buf, sizeof(buf)) - sizeof("_config"), &buf[1]);
276 * Test that the app doesn't run with invalid whitelist option.
277 * Final tests ensures it does run with valid options as sanity check (one
278 * test for with Domain+BDF, second for just with BDF)
281 test_whitelist_flag(void)
284 #ifdef RTE_EXEC_ENV_BSDAPP
285 /* BSD target doesn't support prefixes at this point */
286 const char * prefix = "";
288 char prefix[PATH_MAX], tmp[PATH_MAX];
289 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
290 printf("Error - unable to get current prefix!\n");
293 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
296 const char *wlinval[][11] = {
297 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
298 use_device, "error", "", ""},
299 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
300 use_device, "0:0:0", "", ""},
301 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
302 use_device, "0:error:0.1", "", ""},
303 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
304 use_device, "0:0:0.1error", "", ""},
305 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
306 use_device, "error0:0:0.1", "", ""},
307 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
308 use_device, "0:0:0.1.2", "", ""},
310 /* Test with valid whitelist option */
311 const char *wlval1[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
312 use_device, "00FF:09:0B.3"};
313 const char *wlval2[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
314 use_device, "09:0B.3", use_device, "0a:0b.1"};
315 const char *wlval3[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
316 use_device, "09:0B.3,type=test",
317 use_device, "08:00.1,type=normal"};
319 for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
320 if (launch_proc(wlinval[i]) == 0) {
321 printf("Error - process did run ok with invalid "
322 "whitelist parameter\n");
326 if (launch_proc(wlval1) != 0 ) {
327 printf("Error - process did not run ok with valid whitelist\n");
330 if (launch_proc(wlval2) != 0 ) {
331 printf("Error - process did not run ok with valid whitelist value set\n");
334 if (launch_proc(wlval3) != 0 ) {
335 printf("Error - process did not run ok with valid whitelist + args\n");
343 * Test that the app doesn't run with invalid blacklist option.
344 * Final test ensures it does run with valid options as sanity check
347 test_invalid_b_flag(void)
349 #ifdef RTE_EXEC_ENV_BSDAPP
350 /* BSD target doesn't support prefixes at this point */
351 const char * prefix = "";
353 char prefix[PATH_MAX], tmp[PATH_MAX];
354 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
355 printf("Error - unable to get current prefix!\n");
358 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
361 const char *blinval[][9] = {
362 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error"},
363 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0"},
364 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:error:0.1"},
365 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1error"},
366 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error0:0:0.1"},
367 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1.2"},
369 /* Test with valid blacklist option */
370 const char *blval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
374 for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
375 if (launch_proc(blinval[i]) == 0) {
376 printf("Error - process did run ok with invalid "
377 "blacklist parameter\n");
381 if (launch_proc(blval) != 0) {
382 printf("Error - process did not run ok with valid blacklist value\n");
390 * Test that the app doesn't run with invalid -r option.
393 test_invalid_r_flag(void)
395 #ifdef RTE_EXEC_ENV_BSDAPP
396 /* BSD target doesn't support prefixes at this point */
397 const char * prefix = "";
399 char prefix[PATH_MAX], tmp[PATH_MAX];
400 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
401 printf("Error - unable to get current prefix!\n");
404 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
407 const char *rinval[][9] = {
408 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "error"},
409 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "0"},
410 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "-1"},
411 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "17"},
413 /* Test with valid blacklist option */
414 const char *rval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
418 for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
419 if (launch_proc(rinval[i]) == 0) {
420 printf("Error - process did run ok with invalid "
421 "-r (rank) parameter\n");
425 if (launch_proc(rval) != 0) {
426 printf("Error - process did not run ok with valid -r (rank) value\n");
433 * Test that the app doesn't run without the coremask flag. In all cases
434 * should give an error and fail to run
437 test_missing_c_flag(void)
439 #ifdef RTE_EXEC_ENV_BSDAPP
440 /* BSD target doesn't support prefixes at this point */
441 const char * prefix = "";
443 char prefix[PATH_MAX], tmp[PATH_MAX];
444 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
445 printf("Error - unable to get current prefix!\n");
448 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
451 /* -c flag but no coremask value */
452 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "3", "-c"};
453 /* No -c flag at all */
454 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "3"};
455 /* bad coremask value */
456 const char *argv3[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "error" };
457 /* sanity check of tests - valid coremask value */
458 const char *argv4[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "1" };
460 if (launch_proc(argv1) == 0
461 || launch_proc(argv2) == 0
462 || launch_proc(argv3) == 0) {
463 printf("Error - process ran without error when missing -c flag\n");
466 if (launch_proc(argv4) != 0) {
467 printf("Error - process did not run ok with valid coremask value\n");
474 * Test that the app doesn't run without the -n flag. In all cases
475 * should give an error and fail to run.
476 * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
480 test_missing_n_flag(void)
482 #ifdef RTE_EXEC_ENV_BSDAPP
483 /* BSD target doesn't support prefixes at this point */
484 const char * prefix = "";
486 char prefix[PATH_MAX], tmp[PATH_MAX];
487 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
488 printf("Error - unable to get current prefix!\n");
491 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
494 /* -n flag but no value */
495 const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"};
496 /* No -n flag at all */
497 const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"};
498 /* bad numeric value */
499 const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" };
500 /* out-of-range value */
501 const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "9" };
502 /* sanity test - check with good value */
503 const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" };
505 if (launch_proc(argv1) == 0
506 || launch_proc(argv2) == 0
507 || launch_proc(argv3) == 0
508 || launch_proc(argv4) == 0) {
509 printf("Error - process ran without error when missing -n flag\n");
512 if (launch_proc(argv5) != 0) {
513 printf("Error - process did not run ok with valid num-channel value\n");
520 * Test that the app runs with HPET, and without HPET
523 test_no_hpet_flag(void)
525 char prefix[PATH_MAX], tmp[PATH_MAX];
527 #ifdef RTE_EXEC_ENV_BSDAPP
530 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
531 printf("Error - unable to get current prefix!\n");
534 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
537 const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"};
538 /* Without --no-hpet */
539 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-n", "2"};
541 if (launch_proc(argv1) != 0) {
542 printf("Error - process did not run ok with --no-hpet flag\n");
545 if (launch_proc(argv2) != 0) {
546 printf("Error - process did not run ok without --no-hpet flag\n");
553 * Test that the app runs with --no-huge and doesn't run when either
554 * -m or --socket-mem are specified with --no-huge.
557 test_no_huge_flag(void)
559 #ifdef RTE_EXEC_ENV_BSDAPP
560 /* BSD target doesn't support prefixes at this point, and we also need to
561 * run another primary process here */
562 const char * prefix = no_shconf;
564 const char * prefix = "--file-prefix=nohuge";
568 const char *argv1[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2"};
569 /* With --no-huge and -m */
570 const char *argv2[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2", "-m", "2"};
572 /* With --no-huge and --socket-mem */
573 const char *argv3[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
575 /* With --no-huge, -m and --socket-mem */
576 const char *argv4[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
577 "-m", "2", "--socket-mem=2"};
578 if (launch_proc(argv1) != 0) {
579 printf("Error - process did not run ok with --no-huge flag\n");
582 if (launch_proc(argv2) == 0) {
583 printf("Error - process run ok with --no-huge and -m flags\n");
586 #ifdef RTE_EXEC_ENV_BSDAPP
587 /* BSD target does not support NUMA, hence no --socket-mem tests */
591 if (launch_proc(argv3) == 0) {
592 printf("Error - process run ok with --no-huge and --socket-mem "
596 if (launch_proc(argv4) == 0) {
597 printf("Error - process run ok with --no-huge, -m and "
598 "--socket-mem flags\n");
604 #ifdef RTE_LIBRTE_XEN_DOM0
606 test_dom0_misc_flags(void)
608 char prefix[PATH_MAX], tmp[PATH_MAX];
610 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
611 printf("Error - unable to get current prefix!\n");
614 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
616 /* check that some general flags don't prevent things from working.
617 * All cases, apart from the first, app should run.
618 * No futher testing of output done.
620 /* sanity check - failure with invalid option */
621 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
624 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
626 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
627 /* With valid --syslog */
628 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
629 "--syslog", "syslog"};
630 /* With empty --syslog (should fail) */
631 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
632 /* With invalid --syslog */
633 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
634 /* With no-sh-conf */
635 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "20",
636 "--no-shconf", "--file-prefix=noshconf" };
638 if (launch_proc(argv0) == 0) {
639 printf("Error - process ran ok with invalid flag\n");
642 if (launch_proc(argv1) != 0) {
643 printf("Error - process did not run ok with --no-pci flag\n");
646 if (launch_proc(argv2) != 0) {
647 printf("Error - process did not run ok with -v flag\n");
650 if (launch_proc(argv3) != 0) {
651 printf("Error - process did not run ok with --syslog flag\n");
654 if (launch_proc(argv4) == 0) {
655 printf("Error - process run ok with empty --syslog flag\n");
658 if (launch_proc(argv5) == 0) {
659 printf("Error - process run ok with invalid --syslog flag\n");
662 if (launch_proc(argv6) != 0) {
663 printf("Error - process did not run ok with --no-shconf flag\n");
671 test_misc_flags(void)
673 char hugepath[PATH_MAX] = {0};
674 #ifdef RTE_EXEC_ENV_BSDAPP
675 /* BSD target doesn't support prefixes at this point */
676 const char * prefix = "";
677 const char * nosh_prefix = "";
679 char prefix[PATH_MAX], tmp[PATH_MAX];
680 const char * nosh_prefix = "--file-prefix=noshconf";
681 FILE * hugedir_handle = NULL;
682 char line[PATH_MAX] = {0};
683 unsigned i, isempty = 1;
684 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
685 printf("Error - unable to get current prefix!\n");
688 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
691 * get first valid hugepage path
694 /* get hugetlbfs mountpoints from /proc/mounts */
695 hugedir_handle = fopen("/proc/mounts", "r");
697 if (hugedir_handle == NULL) {
698 printf("Error opening /proc/mounts!\n");
702 /* read /proc/mounts */
703 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
705 /* find first valid hugepath */
706 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
710 fclose(hugedir_handle);
712 /* check if path is not empty */
713 for (i = 0; i < sizeof(hugepath); i++)
714 if (hugepath[i] != '\0')
718 printf("No mounted hugepage dir found!\n");
724 /* check that some general flags don't prevent things from working.
725 * All cases, apart from the first, app should run.
726 * No futher testing of output done.
728 /* sanity check - failure with invalid option */
729 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
732 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
734 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
735 /* With valid --syslog */
736 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
737 "--syslog", "syslog"};
738 /* With empty --syslog (should fail) */
739 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
740 /* With invalid --syslog */
741 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
742 /* With no-sh-conf */
743 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
744 no_shconf, nosh_prefix };
746 #ifdef RTE_EXEC_ENV_BSDAPP
749 /* With --huge-dir */
750 const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
751 "--file-prefix=hugedir", "--huge-dir", hugepath};
752 /* With empty --huge-dir (should fail) */
753 const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
754 "--file-prefix=hugedir", "--huge-dir"};
755 /* With invalid --huge-dir */
756 const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
757 "--file-prefix=hugedir", "--huge-dir", "invalid"};
758 /* Secondary process with invalid --huge-dir (should run as flag has no
759 * effect on secondary processes) */
760 const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
762 /* try running with base-virtaddr param */
763 const char *argv11[] = {prgname, "--file-prefix=virtaddr",
764 "-c", "1", "-n", "2", "--base-virtaddr=0x12345678"};
767 if (launch_proc(argv0) == 0) {
768 printf("Error - process ran ok with invalid flag\n");
771 if (launch_proc(argv1) != 0) {
772 printf("Error - process did not run ok with --no-pci flag\n");
775 if (launch_proc(argv2) != 0) {
776 printf("Error - process did not run ok with -v flag\n");
779 if (launch_proc(argv3) != 0) {
780 printf("Error - process did not run ok with --syslog flag\n");
783 if (launch_proc(argv4) == 0) {
784 printf("Error - process run ok with empty --syslog flag\n");
787 if (launch_proc(argv5) == 0) {
788 printf("Error - process run ok with invalid --syslog flag\n");
791 if (launch_proc(argv6) != 0) {
792 printf("Error - process did not run ok with --no-shconf flag\n");
795 #ifdef RTE_EXEC_ENV_BSDAPP
798 if (launch_proc(argv7) != 0) {
799 printf("Error - process did not run ok with --huge-dir flag\n");
802 if (launch_proc(argv8) == 0) {
803 printf("Error - process run ok with empty --huge-dir flag\n");
806 if (launch_proc(argv9) == 0) {
807 printf("Error - process run ok with invalid --huge-dir flag\n");
810 if (launch_proc(argv10) != 0) {
811 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
814 if (launch_proc(argv11) != 0) {
815 printf("Error - process did not run ok with --base-virtaddr parameter\n");
823 test_file_prefix(void)
826 * 1. check if current process hugefiles are locked
827 * 2. try to run secondary process without a corresponding primary process
828 * (while failing to run, it will also remove any unused hugepage files)
829 * 3. check if current process hugefiles are still in place and are locked
830 * 4. run a primary process with memtest1 prefix
831 * 5. check if memtest1 hugefiles are created
832 * 6. run a primary process with memtest2 prefix
833 * 7. check that only memtest2 hugefiles are present in the hugedir
836 #ifdef RTE_EXEC_ENV_BSDAPP
840 /* this should fail unless the test itself is run with "memtest" prefix */
841 const char *argv0[] = {prgname, mp_flag, "-c", "1", "-n", "2", "-m", "2",
842 "--file-prefix=" memtest };
844 /* primary process with memtest1 */
845 const char *argv1[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
846 "--file-prefix=" memtest1 };
848 /* primary process with memtest2 */
849 const char *argv2[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
850 "--file-prefix=" memtest2 };
853 if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
854 printf("Error - unable to get current prefix!\n");
857 #ifdef RTE_LIBRTE_XEN_DOM0
861 /* check if files for current prefix are present */
862 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
863 printf("Error - hugepage files for %s were not created!\n", prefix);
867 /* checks if files for current prefix are locked */
868 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
869 printf("Error - hugepages for current process aren't locked!\n");
873 /* check if files for secondary process are present */
874 if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
875 /* check if they are not locked */
876 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
877 printf("Error - hugepages for current process are locked!\n");
880 /* they aren't locked, delete them */
882 if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
883 printf("Error - deleting hugepages failed!\n");
889 if (launch_proc(argv0) == 0) {
890 printf("Error - secondary process ran ok without primary process\n");
894 /* check if files for current prefix are present */
895 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
896 printf("Error - hugepage files for %s were not created!\n", prefix);
900 /* checks if files for current prefix are locked */
901 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
902 printf("Error - hugepages for current process aren't locked!\n");
906 if (launch_proc(argv1) != 0) {
907 printf("Error - failed to run with --file-prefix=%s\n", memtest);
911 /* check if memtest1_map0 is present */
912 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
913 printf("Error - hugepage files for %s were not created!\n", memtest1);
917 if (launch_proc(argv2) != 0) {
918 printf("Error - failed to run with --file-prefix=%s\n", memtest2);
922 /* check if hugefiles for memtest2 are present */
923 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
924 printf("Error - hugepage files for %s were not created!\n", memtest2);
928 /* check if hugefiles for memtest1 are present */
929 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
930 printf("Error - hugepage files for %s were not deleted!\n", memtest1);
938 * Tests for correct handling of -m and --socket-mem flags
941 test_memory_flags(void)
943 const char* mem_size = NULL;
944 #ifdef RTE_EXEC_ENV_BSDAPP
945 /* BSD target doesn't support prefixes at this point */
946 const char * prefix = "";
948 char prefix[PATH_MAX], tmp[PATH_MAX];
949 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
950 printf("Error - unable to get current prefix!\n");
953 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
955 #ifdef RTE_LIBRTE_XEN_DOM0
962 /* valid -m flag and mp flag */
963 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "10",
964 "-n", "2", "-m", mem_size};
967 const char *argv1[] = {prgname, "-c", "10", "-n", "2",
968 "--file-prefix=" memtest, "-m", mem_size};
970 /* invalid (zero) --socket-mem flag */
971 const char *argv2[] = {prgname, "-c", "10", "-n", "2",
972 "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
974 /* invalid (incomplete) --socket-mem flag */
975 const char *argv3[] = {prgname, "-c", "10", "-n", "2",
976 "--file-prefix=" memtest, "--socket-mem=2,2,"};
978 /* invalid (mixed with invalid data) --socket-mem flag */
979 const char *argv4[] = {prgname, "-c", "10", "-n", "2",
980 "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
982 /* invalid (with numeric value as last character) --socket-mem flag */
983 const char *argv5[] = {prgname, "-c", "10", "-n", "2",
984 "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
986 /* invalid (with empty socket) --socket-mem flag */
987 const char *argv6[] = {prgname, "-c", "10", "-n", "2",
988 "--file-prefix=" memtest, "--socket-mem=2,,2"};
990 /* invalid (null) --socket-mem flag */
991 const char *argv7[] = {prgname, "-c", "10", "-n", "2",
992 "--file-prefix=" memtest, "--socket-mem="};
994 /* valid --socket-mem specified together with -m flag */
995 const char *argv8[] = {prgname, "-c", "10", "-n", "2",
996 "--file-prefix=" memtest, "-m", "2", "--socket-mem=2,2"};
998 /* construct an invalid socket mask with 2 megs on each socket plus
999 * extra 2 megs on socket that doesn't exist on current system */
1000 char invalid_socket_mem[SOCKET_MEM_STRLEN];
1001 char buf[SOCKET_MEM_STRLEN]; /* to avoid copying string onto itself */
1003 #ifdef RTE_EXEC_ENV_BSDAPP
1004 int i, num_sockets = 1;
1006 int i, num_sockets = get_number_of_sockets();
1009 if (num_sockets <= 0 || num_sockets > RTE_MAX_NUMA_NODES) {
1010 printf("Error - cannot get number of sockets!\n");
1014 rte_snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
1016 /* add one extra socket */
1017 for (i = 0; i < num_sockets + 1; i++) {
1018 rte_snprintf(buf, sizeof(buf), "%s2", invalid_socket_mem);
1019 rte_snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1021 if (num_sockets + 1 - i > 1) {
1022 rte_snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
1023 rte_snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1027 /* construct a valid socket mask with 2 megs on each existing socket */
1028 char valid_socket_mem[SOCKET_MEM_STRLEN];
1030 rte_snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
1032 /* add one extra socket */
1033 for (i = 0; i < num_sockets; i++) {
1034 rte_snprintf(buf, sizeof(buf), "%s2", valid_socket_mem);
1035 rte_snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1037 if (num_sockets - i > 1) {
1038 rte_snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
1039 rte_snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1043 /* invalid --socket-mem flag (with extra socket) */
1044 const char *argv9[] = {prgname, "-c", "10", "-n", "2",
1045 "--file-prefix=" memtest, invalid_socket_mem};
1047 /* valid --socket-mem flag */
1048 const char *argv10[] = {prgname, "-c", "10", "-n", "2",
1049 "--file-prefix=" memtest, valid_socket_mem};
1051 if (launch_proc(argv0) != 0) {
1052 printf("Error - secondary process failed with valid -m flag !\n");
1056 #ifdef RTE_EXEC_ENV_BSDAPP
1057 /* no other tests are applicable to BSD */
1061 if (launch_proc(argv1) != 0) {
1062 printf("Error - process failed with valid -m flag!\n");
1065 #ifdef RTE_LIBRTE_XEN_DOM0
1068 if (launch_proc(argv2) == 0) {
1069 printf("Error - process run ok with invalid (zero) --socket-mem!\n");
1073 if (launch_proc(argv3) == 0) {
1074 printf("Error - process run ok with invalid "
1075 "(incomplete) --socket-mem!\n");
1079 if (launch_proc(argv4) == 0) {
1080 printf("Error - process run ok with invalid "
1081 "(mixed with invalid input) --socket-mem!\n");
1085 if (launch_proc(argv5) == 0) {
1086 printf("Error - process run ok with invalid "
1087 "(mixed with invalid input with a numeric value as "
1088 "last character) --socket-mem!\n");
1092 if (launch_proc(argv6) == 0) {
1093 printf("Error - process run ok with invalid "
1094 "(with empty socket) --socket-mem!\n");
1098 if (launch_proc(argv7) == 0) {
1099 printf("Error - process run ok with invalid (null) --socket-mem!\n");
1103 if (launch_proc(argv8) == 0) {
1104 printf("Error - process run ok with --socket-mem and -m specified!\n");
1108 if (launch_proc(argv9) == 0) {
1109 printf("Error - process run ok with extra socket in --socket-mem!\n");
1113 if (launch_proc(argv10) != 0) {
1114 printf("Error - process failed with valid --socket-mem!\n");
1122 test_eal_flags(void)
1126 ret = test_missing_c_flag();
1128 printf("Error in test_missing_c_flag()\n");
1132 ret = test_missing_n_flag();
1134 printf("Error in test_missing_n_flag()\n");
1138 ret = test_no_hpet_flag();
1140 printf("Error in test_no_hpet_flag()\n");
1144 ret = test_no_huge_flag();
1146 printf("Error in test_no_huge_flag()\n");
1150 ret = test_whitelist_flag();
1152 printf("Error in test_invalid_whitelist_flag()\n");
1156 ret = test_invalid_b_flag();
1158 printf("Error in test_invalid_b_flag()\n");
1162 ret = test_invalid_r_flag();
1164 printf("Error in test_invalid_r_flag()\n");
1168 ret = test_memory_flags();
1170 printf("Error in test_memory_flags()\n");
1174 ret = test_file_prefix();
1176 printf("Error in test_file_prefix()\n");
1180 #ifdef RTE_LIBRTE_XEN_DOM0
1181 ret = test_dom0_misc_flags();
1183 ret = test_misc_flags();
1186 printf("Error in test_misc_flags()");
1194 /* Baremetal version
1195 * Multiprocess not applicable, so just return 0 always
1198 test_eal_flags(void)
1200 printf("Multi-process not possible for baremetal, cannot test EAL flags\n");