4 * Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <cmdline_parse.h>
39 #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);
221 * count the number of "node*" files in /sys/devices/system/node/
224 get_number_of_sockets(void)
226 struct dirent *dirent = NULL;
227 const char * nodedir = "/sys/devices/system/node/";
231 /* check if directory exists */
232 if ((dir = opendir(nodedir)) == NULL) {
233 /* if errno==ENOENT this means we don't have NUMA support */
234 if (errno == ENOENT) {
235 printf("No NUMA nodes detected: assuming 1 available socket\n");
238 printf("Error opening %s: %s\n", nodedir, strerror(errno));
242 while ((dirent = readdir(dir)) != NULL)
243 if (strncmp(dirent->d_name, "node", sizeof("node") - 1) == 0)
251 get_current_prefix(char * prefix, int size)
253 char path[PATH_MAX] = {0};
254 char buf[PATH_MAX] = {0};
256 /* get file for config (fd is always 3) */
257 rte_snprintf(path, sizeof(path), "/proc/self/fd/%d", 3);
259 /* return NULL on error */
260 if (readlink(path, buf, sizeof(buf)) == -1)
263 /* get the basename */
264 rte_snprintf(buf, sizeof(buf), "%s", basename(buf));
266 /* copy string all the way from second char up to start of _config */
267 rte_snprintf(prefix, size, "%.*s",
268 strnlen(buf, sizeof(buf)) - sizeof("_config"), &buf[1]);
273 /* extra function prototypes for internal eal function to test in whitelist
274 * ICC 12 doesn't approve of this practice, so temporarily disable warnings for it */
275 #ifdef __INTEL_COMPILER
276 #pragma warning disable 1419
278 extern int eal_dev_whitelist_exists(void);
279 extern int eal_dev_whitelist_add_entry(const char *);
280 extern int eal_dev_whitelist_parse(void);
281 extern int eal_dev_is_whitelisted(const char *);
282 extern void eal_dev_whitelist_clear(void);
283 #ifdef __INTEL_COMPILER
284 #pragma warning enable 1419
288 * Test that the app doesn't run with invalid whitelist option.
289 * Final tests ensures it does run with valid options as sanity check (one
290 * test for with Domain+BDF, second for just with BDF)
293 test_whitelist_flag(void)
296 char prefix[PATH_MAX], tmp[PATH_MAX];
297 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
298 printf("Error - unable to get current prefix!\n");
301 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
303 const char *wlinval[][11] = {
304 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
305 use_device, "error", "", ""},
306 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
307 use_device, "0:0:0", "", ""},
308 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
309 use_device, "0:error:0.1", "", ""},
310 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
311 use_device, "0:0:0.1error", "", ""},
312 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
313 use_device, "error0:0:0.1", "", ""},
314 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
315 use_device, "0:0:0.1.2", "", ""},
316 {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
317 use_device, "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x",
318 use_device, "y,z,1,2,3,4,5,6,7,8,9,0"},
320 /* Test with valid whitelist option */
321 const char *wlval1[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
322 use_device, "00FF:09:0B.3"};
323 const char *wlval2[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
324 use_device, "09:0B.3,0a:0b.1"};
325 const char *wlval3[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1",
326 use_device, "09:0B.3;type=test,08:00.1;type=normal"};
328 for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
329 if (launch_proc(wlinval[i]) == 0) {
330 printf("Error - process did run ok with invalid "
331 "whitelist parameter\n");
335 if (launch_proc(wlval1) != 0 ) {
336 printf("Error - process did not run ok with valid whitelist\n");
339 if (launch_proc(wlval2) != 0 ) {
340 printf("Error - process did not run ok with valid whitelist value set\n");
343 if (launch_proc(wlval3) != 0 ) {
344 printf("Error - process did not run ok with valid whitelist + args\n");
348 /* extra-sanity checks of whitelists - to be run only if no whitelist */
349 if (eal_dev_whitelist_exists())
352 /* check that whitelist_parse returns error without whitelist */
353 if (eal_dev_whitelist_parse() != -1) {
354 printf("ERROR: calling whitelist parse without a whitelist doesn't "
355 "return an error\n");
358 if (!eal_dev_is_whitelisted("adevice")) {
359 printf("Whitelist lookup does not return true if no whitelist\n");
362 eal_dev_whitelist_add_entry("0000:00:00.0");
363 eal_dev_whitelist_parse();
364 if (eal_dev_is_whitelisted("adevice")) {
365 printf("Whitelist lookup does not return false for unlisted dev\n");
368 if (!eal_dev_is_whitelisted("0000:00:00.0")) {
369 printf("Whitelist lookup does not return true for whitelisted dev\n");
372 eal_dev_whitelist_clear();
378 * Test that the app doesn't run with invalid blacklist option.
379 * Final test ensures it does run with valid options as sanity check
382 test_invalid_b_flag(void)
384 char prefix[PATH_MAX], tmp[PATH_MAX];
385 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
386 printf("Error - unable to get current prefix!\n");
389 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
391 const char *blinval[][9] = {
392 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error"},
393 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0"},
394 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:error:0.1"},
395 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1error"},
396 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error0:0:0.1"},
397 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1.2"},
399 /* Test with valid blacklist option */
400 const char *blval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
404 for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
405 if (launch_proc(blinval[i]) == 0) {
406 printf("Error - process did run ok with invalid "
407 "blacklist parameter\n");
411 if (launch_proc(blval) != 0) {
412 printf("Error - process did not run ok with valid blacklist value\n");
420 * Test that the app doesn't run with invalid -r option.
423 test_invalid_r_flag(void)
425 char prefix[PATH_MAX], tmp[PATH_MAX];
426 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
427 printf("Error - unable to get current prefix!\n");
430 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
432 const char *rinval[][9] = {
433 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "error"},
434 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "0"},
435 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "-1"},
436 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "17"},
438 /* Test with valid blacklist option */
439 const char *rval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
443 for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
444 if (launch_proc(rinval[i]) == 0) {
445 printf("Error - process did run ok with invalid "
446 "-r (rank) parameter\n");
450 if (launch_proc(rval) != 0) {
451 printf("Error - process did not run ok with valid -r (rank) value\n");
458 * Test that the app doesn't run without the coremask flag. In all cases
459 * should give an error and fail to run
462 test_missing_c_flag(void)
464 char prefix[PATH_MAX], tmp[PATH_MAX];
465 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
466 printf("Error - unable to get current prefix!\n");
469 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
471 /* -c flag but no coremask value */
472 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "3", "-c"};
473 /* No -c flag at all */
474 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "3"};
475 /* bad coremask value */
476 const char *argv3[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "error" };
477 /* sanity check of tests - valid coremask value */
478 const char *argv4[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "1" };
480 if (launch_proc(argv1) == 0
481 || launch_proc(argv2) == 0
482 || launch_proc(argv3) == 0) {
483 printf("Error - process ran without error when missing -c flag\n");
486 if (launch_proc(argv4) != 0) {
487 printf("Error - process did not run ok with valid coremask value\n");
494 * Test that the app doesn't run without the -n flag. In all cases
495 * should give an error and fail to run.
496 * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
500 test_missing_n_flag(void)
502 char prefix[PATH_MAX], tmp[PATH_MAX];
503 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
504 printf("Error - unable to get current prefix!\n");
507 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
509 /* -n flag but no value */
510 const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"};
511 /* No -n flag at all */
512 const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"};
513 /* bad numeric value */
514 const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" };
515 /* out-of-range value */
516 const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "9" };
517 /* sanity test - check with good value */
518 const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" };
520 if (launch_proc(argv1) == 0
521 || launch_proc(argv2) == 0
522 || launch_proc(argv3) == 0
523 || launch_proc(argv4) == 0) {
524 printf("Error - process ran without error when missing -n flag\n");
527 if (launch_proc(argv5) != 0) {
528 printf("Error - process did not run ok with valid num-channel value\n");
535 * Test that the app runs with HPET, and without HPET
538 test_no_hpet_flag(void)
540 char prefix[PATH_MAX], tmp[PATH_MAX];
541 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
542 printf("Error - unable to get current prefix!\n");
545 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
548 const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"};
549 /* Without --no-hpet */
550 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-n", "2"};
552 if (launch_proc(argv1) != 0) {
553 printf("Error - process did not run ok with --no-hpet flag\n");
556 if (launch_proc(argv2) != 0) {
557 printf("Error - process did not run ok without --no-hpet flag\n");
564 * Test that the app runs with --no-huge and doesn't run when either
565 * -m or --socket-mem are specified with --no-huge.
568 test_no_huge_flag(void)
570 char prefix[PATH_MAX], tmp[PATH_MAX];
571 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
572 printf("Error - unable to get current prefix!\n");
575 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
578 const char *argv1[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
579 "--file-prefix=nohuge"};
580 /* With --no-huge and -m */
581 const char *argv2[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2", "-m", "2",
582 "--file-prefix=nohuge"};
583 /* With --no-huge and --socket-mem */
584 const char *argv3[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
585 "--socket-mem=2", "--file-prefix=nohuge"};
586 /* With --no-huge, -m and --socket-mem */
587 const char *argv4[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
588 "-m", "2", "--socket-mem=2", "--file-prefix=nohuge"};
590 if (launch_proc(argv1) != 0) {
591 printf("Error - process did not run ok with --no-huge flag\n");
594 if (launch_proc(argv2) == 0) {
595 printf("Error - process run ok with --no-huge and -m flags\n");
598 if (launch_proc(argv3) == 0) {
599 printf("Error - process run ok with --no-huge and --socket-mem "
603 if (launch_proc(argv4) == 0) {
604 printf("Error - process run ok with --no-huge, -m and "
605 "--socket-mem flags\n");
612 test_misc_flags(void)
614 FILE * hugedir_handle = NULL;
615 char line[PATH_MAX] = {0};
616 char hugepath[PATH_MAX] = {0};
617 char prefix[PATH_MAX], tmp[PATH_MAX];
618 unsigned i, isempty = 1;
620 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
621 printf("Error - unable to get current prefix!\n");
624 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
627 * get first valid hugepage path
630 /* get hugetlbfs mountpoints from /proc/mounts */
631 hugedir_handle = fopen("/proc/mounts", "r");
633 if (hugedir_handle == NULL) {
634 printf("Error opening /proc/mounts!\n");
638 /* read /proc/mounts */
639 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
641 /* find first valid hugepath */
642 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
646 fclose(hugedir_handle);
648 /* check if path is not empty */
649 for (i = 0; i < sizeof(hugepath); i++)
650 if (hugepath[i] != '\0')
654 printf("No mounted hugepage dir found!\n");
659 /* check that some general flags don't prevent things from working.
660 * All cases, apart from the first, app should run.
661 * No futher testing of output done.
663 /* sanity check - failure with invalid option */
664 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
667 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
669 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
670 /* With valid --syslog */
671 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
672 "--syslog", "syslog"};
673 /* With empty --syslog (should fail) */
674 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
675 /* With invalid --syslog */
676 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
677 /* With no-sh-conf */
678 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
679 "--no-shconf", "--file-prefix=noshconf" };
680 /* With --huge-dir */
681 const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
682 "--file-prefix=hugedir", "--huge-dir", hugepath};
683 /* With empty --huge-dir (should fail) */
684 const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
685 "--file-prefix=hugedir", "--huge-dir"};
686 /* With invalid --huge-dir */
687 const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
688 "--file-prefix=hugedir", "--huge-dir", "invalid"};
689 /* Secondary process with invalid --huge-dir (should run as flag has no
690 * effect on secondary processes) */
691 const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
694 if (launch_proc(argv0) == 0) {
695 printf("Error - process ran ok with invalid flag\n");
698 if (launch_proc(argv1) != 0) {
699 printf("Error - process did not run ok with --no-pci flag\n");
702 if (launch_proc(argv2) != 0) {
703 printf("Error - process did not run ok with -v flag\n");
706 if (launch_proc(argv3) != 0) {
707 printf("Error - process did not run ok with --syslog flag\n");
710 if (launch_proc(argv4) == 0) {
711 printf("Error - process run ok with empty --syslog flag\n");
714 if (launch_proc(argv5) == 0) {
715 printf("Error - process run ok with invalid --syslog flag\n");
718 if (launch_proc(argv6) != 0) {
719 printf("Error - process did not run ok with --no-shconf flag\n");
722 if (launch_proc(argv7) != 0) {
723 printf("Error - process did not run ok with --huge-dir flag\n");
726 if (launch_proc(argv8) == 0) {
727 printf("Error - process run ok with empty --huge-dir flag\n");
730 if (launch_proc(argv9) == 0) {
731 printf("Error - process run ok with invalid --huge-dir flag\n");
734 if (launch_proc(argv10) != 0) {
735 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
742 test_file_prefix(void)
745 * 1. check if current process hugefiles are locked
746 * 2. try to run secondary process without a corresponding primary process
747 * (while failing to run, it will also remove any unused hugepage files)
748 * 3. check if current process hugefiles are still in place and are locked
749 * 4. run a primary process with memtest1 prefix
750 * 5. check if memtest1 hugefiles are created
751 * 6. run a primary process with memtest2 prefix
752 * 7. check that only memtest2 hugefiles are present in the hugedir
755 /* this should fail unless the test itself is run with "memtest" prefix */
756 const char *argv0[] = {prgname, mp_flag, "-c", "1", "-n", "2", "-m", "2",
757 "--file-prefix=" memtest };
759 /* primary process with memtest1 */
760 const char *argv1[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
761 "--file-prefix=" memtest1 };
763 /* primary process with memtest2 */
764 const char *argv2[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
765 "--file-prefix=" memtest2 };
768 if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
769 printf("Error - unable to get current prefix!\n");
773 /* check if files for current prefix are present */
774 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
775 printf("Error - hugepage files for %s were not created!\n", prefix);
779 /* checks if files for current prefix are locked */
780 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
781 printf("Error - hugepages for current process aren't locked!\n");
785 /* check if files for secondary process are present */
786 if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
787 /* check if they are not locked */
788 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
789 printf("Error - hugepages for current process are locked!\n");
792 /* they aren't locked, delete them */
794 if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
795 printf("Error - deleting hugepages failed!\n");
801 if (launch_proc(argv0) == 0) {
802 printf("Error - secondary process ran ok without primary process\n");
806 /* check if files for current prefix are present */
807 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
808 printf("Error - hugepage files for %s were not created!\n", prefix);
812 /* checks if files for current prefix are locked */
813 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
814 printf("Error - hugepages for current process aren't locked!\n");
818 if (launch_proc(argv1) != 0) {
819 printf("Error - failed to run with --file-prefix=%s\n", memtest);
823 /* check if memtest1_map0 is present */
824 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
825 printf("Error - hugepage files for %s were not created!\n", memtest1);
829 if (launch_proc(argv2) != 0) {
830 printf("Error - failed to run with --file-prefix=%s\n", memtest2);
834 /* check if hugefiles for memtest2 are present */
835 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
836 printf("Error - hugepage files for %s were not created!\n", memtest2);
840 /* check if hugefiles for memtest1 are present */
841 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
842 printf("Error - hugepage files for %s were not deleted!\n", memtest1);
850 * Tests for correct handling of -m and --socket-mem flags
853 test_memory_flags(void)
855 char prefix[PATH_MAX], tmp[PATH_MAX];
856 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
857 printf("Error - unable to get current prefix!\n");
860 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
863 const char *argv0[] = {prgname, "-c", "10", "-n", "2",
864 "--file-prefix=" memtest, "-m", "2"};
866 /* valid -m flag and mp flag */
867 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "10",
868 "-n", "2", "-m", "2"};
870 /* invalid (zero) --socket-mem flag */
871 const char *argv2[] = {prgname, "-c", "10", "-n", "2",
872 "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
874 /* invalid (incomplete) --socket-mem flag */
875 const char *argv3[] = {prgname, "-c", "10", "-n", "2",
876 "--file-prefix=" memtest, "--socket-mem=2,2,"};
878 /* invalid (mixed with invalid data) --socket-mem flag */
879 const char *argv4[] = {prgname, "-c", "10", "-n", "2",
880 "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
882 /* invalid (with numeric value as last character) --socket-mem flag */
883 const char *argv5[] = {prgname, "-c", "10", "-n", "2",
884 "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
886 /* invalid (with empty socket) --socket-mem flag */
887 const char *argv6[] = {prgname, "-c", "10", "-n", "2",
888 "--file-prefix=" memtest, "--socket-mem=2,,2"};
890 /* invalid (null) --socket-mem flag */
891 const char *argv7[] = {prgname, "-c", "10", "-n", "2",
892 "--file-prefix=" memtest, "--socket-mem="};
894 /* valid --socket-mem specified together with -m flag */
895 const char *argv8[] = {prgname, "-c", "10", "-n", "2",
896 "--file-prefix=" memtest, "-m", "2", "--socket-mem=2,2"};
898 /* construct an invalid socket mask with 2 megs on each socket plus
899 * extra 2 megs on socket that doesn't exist on current system */
900 char invalid_socket_mem[SOCKET_MEM_STRLEN];
901 char buf[SOCKET_MEM_STRLEN]; /* to avoid copying string onto itself */
902 int i, num_sockets = get_number_of_sockets();
904 if (num_sockets <= 0 || num_sockets > RTE_MAX_NUMA_NODES) {
905 printf("Error - cannot get number of sockets!\n");
909 rte_snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
911 /* add one extra socket */
912 for (i = 0; i < num_sockets + 1; i++) {
913 rte_snprintf(buf, sizeof(buf), "%s2", invalid_socket_mem);
914 rte_snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
916 if (num_sockets + 1 - i > 1) {
917 rte_snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
918 rte_snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
922 /* construct a valid socket mask with 2 megs on each existing socket */
923 char valid_socket_mem[SOCKET_MEM_STRLEN];
925 rte_snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
927 /* add one extra socket */
928 for (i = 0; i < num_sockets; i++) {
929 rte_snprintf(buf, sizeof(buf), "%s2", valid_socket_mem);
930 rte_snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
932 if (num_sockets - i > 1) {
933 rte_snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
934 rte_snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
938 /* invalid --socket-mem flag (with extra socket) */
939 const char *argv9[] = {prgname, "-c", "10", "-n", "2",
940 "--file-prefix=" memtest, invalid_socket_mem};
942 /* valid --socket-mem flag */
943 const char *argv10[] = {prgname, "-c", "10", "-n", "2",
944 "--file-prefix=" memtest, valid_socket_mem};
946 if (launch_proc(argv0) != 0) {
947 printf("Error - process failed with valid -m flag!\n");
951 if (launch_proc(argv1) != 0) {
952 printf("Error - secondary process failed with valid -m flag !\n");
956 if (launch_proc(argv2) == 0) {
957 printf("Error - process run ok with invalid (zero) --socket-mem!\n");
961 if (launch_proc(argv3) == 0) {
962 printf("Error - process run ok with invalid "
963 "(incomplete) --socket-mem!\n");
967 if (launch_proc(argv4) == 0) {
968 printf("Error - process run ok with invalid "
969 "(mixed with invalid input) --socket-mem!\n");
973 if (launch_proc(argv5) == 0) {
974 printf("Error - process run ok with invalid "
975 "(mixed with invalid input with a numeric value as "
976 "last character) --socket-mem!\n");
980 if (launch_proc(argv6) == 0) {
981 printf("Error - process run ok with invalid "
982 "(with empty socket) --socket-mem!\n");
986 if (launch_proc(argv7) == 0) {
987 printf("Error - process run ok with invalid (null) --socket-mem!\n");
991 if (launch_proc(argv8) == 0) {
992 printf("Error - process run ok with --socket-mem and -m specified!\n");
996 if (launch_proc(argv9) == 0) {
997 printf("Error - process run ok with extra socket in --socket-mem!\n");
1001 if (launch_proc(argv10) != 0) {
1002 printf("Error - process failed with valid --socket-mem!\n");
1010 test_eal_flags(void)
1014 ret = test_missing_c_flag();
1016 printf("Error in test_missing_c_flag()\n");
1020 ret = test_missing_n_flag();
1022 printf("Error in test_missing_n_flag()\n");
1026 ret = test_no_hpet_flag();
1028 printf("Error in test_no_hpet_flag()\n");
1032 ret = test_no_huge_flag();
1034 printf("Error in test_no_huge_flag()\n");
1038 ret = test_whitelist_flag();
1040 printf("Error in test_invalid_whitelist_flag()\n");
1044 ret = test_invalid_b_flag();
1046 printf("Error in test_invalid_b_flag()\n");
1050 ret = test_invalid_r_flag();
1052 printf("Error in test_invalid_r_flag()\n");
1056 ret = test_memory_flags();
1058 printf("Error in test_memory_flags()\n");
1062 ret = test_file_prefix();
1064 printf("Error in test_file_prefix()\n");
1068 ret = test_misc_flags();
1070 printf("Error in test_misc_flags()");
1078 /* Baremetal version
1079 * Multiprocess not applicable, so just return 0 always
1082 test_eal_flags(void)
1084 printf("Multi-process not possible for baremetal, cannot test EAL flags\n");