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 memtest "memtest"
61 #define memtest1 "memtest1"
62 #define memtest2 "memtest2"
63 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 10)
64 #define launch_proc(ARGV) process_dup(ARGV, \
65 sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
67 enum hugepage_action {
68 HUGEPAGE_CHECK_EXISTS = 0,
69 HUGEPAGE_CHECK_LOCKED,
74 /* if string contains a hugepage path */
76 get_hugepage_path(char * src, int src_len, char * dst, int dst_len)
79 char *tokens[NUM_TOKENS];
81 /* if we couldn't properly split the string */
82 if (rte_strsplit(src, src_len, tokens, NUM_TOKENS, ' ') < NUM_TOKENS)
85 if (strncmp(tokens[2], "hugetlbfs", sizeof("hugetlbfs")) == 0) {
86 rte_snprintf(dst, dst_len, "%s", tokens[1]);
93 * Cycles through hugepage directories and looks for hugepage
94 * files associated with a given prefix. Depending on value of
95 * action, the hugepages are checked if they exist, checked if
96 * they can be locked, or are simply deleted.
98 * Returns 1 if it finds at least one hugepage matching the action
99 * Returns 0 if no matching hugepages were found
100 * Returns -1 if it encounters an error
103 process_hugefiles(const char * prefix, enum hugepage_action action)
105 FILE * hugedir_handle = NULL;
106 DIR * hugepage_dir = NULL;
107 struct dirent *dirent = NULL;
109 char hugefile_prefix[PATH_MAX] = {0};
110 char hugedir[PATH_MAX] = {0};
111 char line[PATH_MAX] = {0};
113 int fd, lck_result, result = 0;
115 const int prefix_len = rte_snprintf(hugefile_prefix,
116 sizeof(hugefile_prefix), "%smap_", prefix);
117 if (prefix_len <= 0 || prefix_len >= (int)sizeof(hugefile_prefix)
118 || prefix_len >= (int)sizeof(dirent->d_name)) {
119 printf("Error creating hugefile filename prefix\n");
123 /* get hugetlbfs mountpoints from /proc/mounts */
124 hugedir_handle = fopen("/proc/mounts", "r");
126 if (hugedir_handle == NULL) {
127 printf("Error parsing /proc/mounts!\n");
131 /* read and parse script output */
132 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
134 /* check if we have a hugepage filesystem path */
135 if (!get_hugepage_path(line, sizeof(line), hugedir, sizeof(hugedir)))
138 /* check if directory exists */
139 if ((hugepage_dir = opendir(hugedir)) == NULL) {
140 fclose(hugedir_handle);
141 printf("Error reading %s: %s\n", hugedir, strerror(errno));
145 while ((dirent = readdir(hugepage_dir)) != NULL) {
146 if (memcmp(dirent->d_name, hugefile_prefix, prefix_len) != 0)
150 case HUGEPAGE_CHECK_EXISTS:
152 /* file exists, return */
157 case HUGEPAGE_DELETE:
159 char file_path[PATH_MAX] = {0};
161 rte_snprintf(file_path, sizeof(file_path),
162 "%s/%s", hugedir, dirent->d_name);
165 if (remove(file_path) < 0) {
166 printf("Error deleting %s - %s!\n",
167 dirent->d_name, strerror(errno));
168 closedir(hugepage_dir);
175 case HUGEPAGE_CHECK_LOCKED:
177 /* try and lock the file */
178 fd = openat(dirfd(hugepage_dir), dirent->d_name, O_RDONLY);
180 /* this shouldn't happen */
182 printf("Error opening %s - %s!\n",
183 dirent->d_name, strerror(errno));
184 closedir(hugepage_dir);
189 /* non-blocking lock */
190 lck_result = flock(fd, LOCK_EX | LOCK_NB);
192 /* if lock succeeds, there's something wrong */
193 if (lck_result != -1) {
196 /* unlock the resulting lock */
199 closedir(hugepage_dir);
206 /* shouldn't happen */
211 } /* read hugepage directory */
212 closedir(hugepage_dir);
213 } /* read /proc/mounts */
215 fclose(hugedir_handle);
220 * count the number of "node*" files in /sys/devices/system/node/
223 get_number_of_sockets(void)
225 struct dirent *dirent = NULL;
226 const char * nodedir = "/sys/devices/system/node/";
230 /* check if directory exists */
231 if ((dir = opendir(nodedir)) == NULL) {
232 /* if errno==ENOENT this means we don't have NUMA support */
233 if (errno == ENOENT) {
234 printf("No NUMA nodes detected: assuming 1 available socket\n");
237 printf("Error opening %s: %s\n", nodedir, strerror(errno));
241 while ((dirent = readdir(dir)) != NULL)
242 if (strncmp(dirent->d_name, "node", sizeof("node") - 1) == 0)
250 get_current_prefix(char * prefix, int size)
252 char path[PATH_MAX] = {0};
253 char buf[PATH_MAX] = {0};
255 /* get file for config (fd is always 3) */
256 rte_snprintf(path, sizeof(path), "/proc/self/fd/%d", 3);
258 /* return NULL on error */
259 if (readlink(path, buf, sizeof(buf)) == -1)
262 /* get the basename */
263 rte_snprintf(buf, sizeof(buf), "%s", basename(buf));
265 /* copy string all the way from second char up to start of _config */
266 rte_snprintf(prefix, size, "%.*s",
267 strnlen(buf, sizeof(buf)) - sizeof("_config"), &buf[1]);
273 * Test that the app doesn't run without invalid blacklist option.
274 * Final test ensures it does run with valid options as sanity check
277 test_invalid_b_flag(void)
279 char prefix[PATH_MAX], tmp[PATH_MAX];
280 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
281 printf("Error - unable to get current prefix!\n");
284 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
286 const char *blinval[][9] = {
287 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error"},
288 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0"},
289 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:error:0.1"},
290 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1error"},
291 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "error0:0:0.1"},
292 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "0:0:0.1.2"},
294 /* Test with valid blacklist option */
295 const char *blval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
299 for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
300 if (launch_proc(blinval[i]) == 0) {
301 printf("Error - process did run ok with invalid "
302 "blacklist parameter\n");
306 if (launch_proc(blval) != 0) {
307 printf("Error - process did not run ok with valid blacklist value\n");
315 * Test that the app doesn't run with invalid -r option.
318 test_invalid_r_flag(void)
320 char prefix[PATH_MAX], tmp[PATH_MAX];
321 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
322 printf("Error - unable to get current prefix!\n");
325 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
327 const char *rinval[][9] = {
328 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "error"},
329 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "0"},
330 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "-1"},
331 {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "17"},
333 /* Test with valid blacklist option */
334 const char *rval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "16"};
338 for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
339 if (launch_proc(rinval[i]) == 0) {
340 printf("Error - process did run ok with invalid "
341 "-r (rank) parameter\n");
345 if (launch_proc(rval) != 0) {
346 printf("Error - process did not run ok with valid -r (rank) value\n");
353 * Test that the app doesn't run without the coremask flag. In all cases
354 * should give an error and fail to run
357 test_missing_c_flag(void)
359 char prefix[PATH_MAX], tmp[PATH_MAX];
360 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
361 printf("Error - unable to get current prefix!\n");
364 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
366 /* -c flag but no coremask value */
367 const char *argv1[] = { prgname, prefix, mp_flag, "-n", "3", "-c"};
368 /* No -c flag at all */
369 const char *argv2[] = { prgname, prefix, mp_flag, "-n", "3"};
370 /* bad coremask value */
371 const char *argv3[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "error" };
372 /* sanity check of tests - valid coremask value */
373 const char *argv4[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "1" };
375 if (launch_proc(argv1) == 0
376 || launch_proc(argv2) == 0
377 || launch_proc(argv3) == 0) {
378 printf("Error - process ran without error when missing -c flag\n");
381 if (launch_proc(argv4) != 0) {
382 printf("Error - process did not run ok with valid coremask value\n");
389 * Test that the app doesn't run without the -n flag. In all cases
390 * should give an error and fail to run.
391 * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
395 test_missing_n_flag(void)
397 char prefix[PATH_MAX], tmp[PATH_MAX];
398 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
399 printf("Error - unable to get current prefix!\n");
402 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
404 /* -n flag but no value */
405 const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"};
406 /* No -n flag at all */
407 const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"};
408 /* bad numeric value */
409 const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" };
410 /* out-of-range value */
411 const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "9" };
412 /* sanity test - check with good value */
413 const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" };
415 if (launch_proc(argv1) == 0
416 || launch_proc(argv2) == 0
417 || launch_proc(argv3) == 0
418 || launch_proc(argv4) == 0) {
419 printf("Error - process ran without error when missing -n flag\n");
422 if (launch_proc(argv5) != 0) {
423 printf("Error - process did not run ok with valid num-channel value\n");
430 * Test that the app runs with HPET, and without HPET
433 test_no_hpet_flag(void)
435 char prefix[PATH_MAX], tmp[PATH_MAX];
436 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
437 printf("Error - unable to get current prefix!\n");
440 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
443 const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"};
444 /* Without --no-hpet */
445 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-n", "2"};
447 if (launch_proc(argv1) != 0) {
448 printf("Error - process did not run ok with --no-hpet flag\n");
451 if (launch_proc(argv2) != 0) {
452 printf("Error - process did not run ok without --no-hpet flag\n");
459 * Test that the app runs with --no-huge and doesn't run when either
460 * -m or --socket-mem are specified with --no-huge.
463 test_no_huge_flag(void)
465 char prefix[PATH_MAX], tmp[PATH_MAX];
466 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
467 printf("Error - unable to get current prefix!\n");
470 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
473 const char *argv1[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
474 "--file-prefix=nohuge"};
475 /* With --no-huge and -m */
476 const char *argv2[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2", "-m", "2",
477 "--file-prefix=nohuge"};
478 /* With --no-huge and --socket-mem */
479 const char *argv3[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
480 "--socket-mem=2", "--file-prefix=nohuge"};
481 /* With --no-huge, -m and --socket-mem */
482 const char *argv4[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
483 "-m", "2", "--socket-mem=2", "--file-prefix=nohuge"};
485 if (launch_proc(argv1) != 0) {
486 printf("Error - process did not run ok with --no-huge flag\n");
489 if (launch_proc(argv2) == 0) {
490 printf("Error - process run ok with --no-huge and -m flags\n");
493 if (launch_proc(argv3) == 0) {
494 printf("Error - process run ok with --no-huge and --socket-mem "
498 if (launch_proc(argv4) == 0) {
499 printf("Error - process run ok with --no-huge, -m and "
500 "--socket-mem flags\n");
507 test_misc_flags(void)
509 FILE * hugedir_handle = NULL;
510 char line[PATH_MAX] = {0};
511 char hugepath[PATH_MAX] = {0};
512 char prefix[PATH_MAX], tmp[PATH_MAX];
513 unsigned i, isempty = 1;
515 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
516 printf("Error - unable to get current prefix!\n");
519 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
522 * get first valid hugepage path
525 /* get hugetlbfs mountpoints from /proc/mounts */
526 hugedir_handle = fopen("/proc/mounts", "r");
528 if (hugedir_handle == NULL) {
529 printf("Error opening /proc/mounts!\n");
533 /* read /proc/mounts */
534 while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
536 /* find first valid hugepath */
537 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
541 fclose(hugedir_handle);
543 /* check if path is not empty */
544 for (i = 0; i < sizeof(hugepath); i++)
545 if (hugepath[i] != '\0')
549 printf("No mounted hugepage dir found!\n");
554 /* check that some general flags don't prevent things from working.
555 * All cases, apart from the first, app should run.
556 * No futher testing of output done.
558 /* sanity check - failure with invalid option */
559 const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
562 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
564 const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
565 /* With valid --syslog */
566 const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
567 "--syslog", "syslog"};
568 /* With empty --syslog (should fail) */
569 const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
570 /* With invalid --syslog */
571 const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
572 /* With no-sh-conf */
573 const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
574 "--no-shconf", "--file-prefix=noshconf" };
575 /* With --huge-dir */
576 const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
577 "--file-prefix=hugedir", "--huge-dir", hugepath};
578 /* With empty --huge-dir (should fail) */
579 const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
580 "--file-prefix=hugedir", "--huge-dir"};
581 /* With invalid --huge-dir */
582 const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
583 "--file-prefix=hugedir", "--huge-dir", "invalid"};
584 /* Secondary process with invalid --huge-dir (should run as flag has no
585 * effect on secondary processes) */
586 const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
589 if (launch_proc(argv0) == 0) {
590 printf("Error - process ran ok with invalid flag\n");
593 if (launch_proc(argv1) != 0) {
594 printf("Error - process did not run ok with --no-pci flag\n");
597 if (launch_proc(argv2) != 0) {
598 printf("Error - process did not run ok with -v flag\n");
601 if (launch_proc(argv3) != 0) {
602 printf("Error - process did not run ok with --syslog flag\n");
605 if (launch_proc(argv4) == 0) {
606 printf("Error - process run ok with empty --syslog flag\n");
609 if (launch_proc(argv5) == 0) {
610 printf("Error - process run ok with invalid --syslog flag\n");
613 if (launch_proc(argv6) != 0) {
614 printf("Error - process did not run ok with --no-shconf flag\n");
617 if (launch_proc(argv7) != 0) {
618 printf("Error - process did not run ok with --huge-dir flag\n");
621 if (launch_proc(argv8) == 0) {
622 printf("Error - process run ok with empty --huge-dir flag\n");
625 if (launch_proc(argv9) == 0) {
626 printf("Error - process run ok with invalid --huge-dir flag\n");
629 if (launch_proc(argv10) != 0) {
630 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
637 test_file_prefix(void)
640 * 1. check if current process hugefiles are locked
641 * 2. try to run secondary process without a corresponding primary process
642 * (while failing to run, it will also remove any unused hugepage files)
643 * 3. check if current process hugefiles are still in place and are locked
644 * 4. run a primary process with memtest1 prefix
645 * 5. check if memtest1 hugefiles are created
646 * 6. run a primary process with memtest2 prefix
647 * 7. check that only memtest2 hugefiles are present in the hugedir
650 /* this should fail unless the test itself is run with "memtest" prefix */
651 const char *argv0[] = {prgname, mp_flag, "-c", "1", "-n", "2", "-m", "2",
652 "--file-prefix=" memtest };
654 /* primary process with memtest1 */
655 const char *argv1[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
656 "--file-prefix=" memtest1 };
658 /* primary process with memtest2 */
659 const char *argv2[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
660 "--file-prefix=" memtest2 };
663 if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
664 printf("Error - unable to get current prefix!\n");
668 /* check if files for current prefix are present */
669 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
670 printf("Error - hugepage files for %s were not created!\n", prefix);
674 /* checks if files for current prefix are locked */
675 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
676 printf("Error - hugepages for current process aren't locked!\n");
680 /* check if files for secondary process are present */
681 if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
682 /* check if they are not locked */
683 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
684 printf("Error - hugepages for current process are locked!\n");
687 /* they aren't locked, delete them */
689 if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
690 printf("Error - deleting hugepages failed!\n");
696 if (launch_proc(argv0) == 0) {
697 printf("Error - secondary process ran ok without primary process\n");
701 /* check if files for current prefix are present */
702 if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
703 printf("Error - hugepage files for %s were not created!\n", prefix);
707 /* checks if files for current prefix are locked */
708 if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
709 printf("Error - hugepages for current process aren't locked!\n");
713 if (launch_proc(argv1) != 0) {
714 printf("Error - failed to run with --file-prefix=%s\n", memtest);
718 /* check if memtest1_map0 is present */
719 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
720 printf("Error - hugepage files for %s were not created!\n", memtest1);
724 if (launch_proc(argv2) != 0) {
725 printf("Error - failed to run with --file-prefix=%s\n", memtest2);
729 /* check if hugefiles for memtest2 are present */
730 if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
731 printf("Error - hugepage files for %s were not created!\n", memtest2);
735 /* check if hugefiles for memtest1 are present */
736 if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
737 printf("Error - hugepage files for %s were not deleted!\n", memtest1);
745 * Tests for correct handling of -m and --socket-mem flags
748 test_memory_flags(void)
750 char prefix[PATH_MAX], tmp[PATH_MAX];
751 if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
752 printf("Error - unable to get current prefix!\n");
755 rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
758 const char *argv0[] = {prgname, "-c", "10", "-n", "2",
759 "--file-prefix=" memtest, "-m", "2"};
761 /* valid -m flag and mp flag */
762 const char *argv1[] = {prgname, prefix, mp_flag, "-c", "10",
763 "-n", "2", "-m", "2"};
765 /* invalid (zero) --socket-mem flag */
766 const char *argv2[] = {prgname, "-c", "10", "-n", "2",
767 "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
769 /* invalid (incomplete) --socket-mem flag */
770 const char *argv3[] = {prgname, "-c", "10", "-n", "2",
771 "--file-prefix=" memtest, "--socket-mem=2,2,"};
773 /* invalid (mixed with invalid data) --socket-mem flag */
774 const char *argv4[] = {prgname, "-c", "10", "-n", "2",
775 "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
777 /* invalid (with numeric value as last character) --socket-mem flag */
778 const char *argv5[] = {prgname, "-c", "10", "-n", "2",
779 "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
781 /* invalid (with empty socket) --socket-mem flag */
782 const char *argv6[] = {prgname, "-c", "10", "-n", "2",
783 "--file-prefix=" memtest, "--socket-mem=2,,2"};
785 /* invalid (null) --socket-mem flag */
786 const char *argv7[] = {prgname, "-c", "10", "-n", "2",
787 "--file-prefix=" memtest, "--socket-mem="};
789 /* valid --socket-mem specified together with -m flag */
790 const char *argv8[] = {prgname, "-c", "10", "-n", "2",
791 "--file-prefix=" memtest, "-m", "2", "--socket-mem=2,2"};
793 /* construct an invalid socket mask with 2 megs on each socket plus
794 * extra 2 megs on socket that doesn't exist on current system */
795 char invalid_socket_mem[SOCKET_MEM_STRLEN];
796 char buf[SOCKET_MEM_STRLEN]; /* to avoid copying string onto itself */
797 int i, num_sockets = get_number_of_sockets();
799 if (num_sockets <= 0 || num_sockets > RTE_MAX_NUMA_NODES) {
800 printf("Error - cannot get number of sockets!\n");
804 rte_snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
806 /* add one extra socket */
807 for (i = 0; i < num_sockets + 1; i++) {
808 rte_snprintf(buf, sizeof(buf), "%s2", invalid_socket_mem);
809 rte_snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
811 if (num_sockets + 1 - i > 1) {
812 rte_snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
813 rte_snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
817 /* construct a valid socket mask with 2 megs on each existing socket */
818 char valid_socket_mem[SOCKET_MEM_STRLEN];
820 rte_snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
822 /* add one extra socket */
823 for (i = 0; i < num_sockets; i++) {
824 rte_snprintf(buf, sizeof(buf), "%s2", valid_socket_mem);
825 rte_snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
827 if (num_sockets - i > 1) {
828 rte_snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
829 rte_snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
833 /* invalid --socket-mem flag (with extra socket) */
834 const char *argv9[] = {prgname, "-c", "10", "-n", "2",
835 "--file-prefix=" memtest, invalid_socket_mem};
837 /* valid --socket-mem flag */
838 const char *argv10[] = {prgname, "-c", "10", "-n", "2",
839 "--file-prefix=" memtest, valid_socket_mem};
841 if (launch_proc(argv0) != 0) {
842 printf("Error - process failed with valid -m flag!\n");
846 if (launch_proc(argv1) != 0) {
847 printf("Error - secondary process failed with valid -m flag !\n");
851 if (launch_proc(argv2) == 0) {
852 printf("Error - process run ok with invalid (zero) --socket-mem!\n");
856 if (launch_proc(argv3) == 0) {
857 printf("Error - process run ok with invalid "
858 "(incomplete) --socket-mem!\n");
862 if (launch_proc(argv4) == 0) {
863 printf("Error - process run ok with invalid "
864 "(mixed with invalid input) --socket-mem!\n");
868 if (launch_proc(argv5) == 0) {
869 printf("Error - process run ok with invalid "
870 "(mixed with invalid input with a numeric value as "
871 "last character) --socket-mem!\n");
875 if (launch_proc(argv6) == 0) {
876 printf("Error - process run ok with invalid "
877 "(with empty socket) --socket-mem!\n");
881 if (launch_proc(argv7) == 0) {
882 printf("Error - process run ok with invalid (null) --socket-mem!\n");
886 if (launch_proc(argv8) == 0) {
887 printf("Error - process run ok with --socket-mem and -m specified!\n");
891 if (launch_proc(argv9) == 0) {
892 printf("Error - process run ok with extra socket in --socket-mem!\n");
896 if (launch_proc(argv10) != 0) {
897 printf("Error - process failed with valid --socket-mem!\n");
909 ret = test_missing_c_flag();
911 printf("Error in test_missing_c_flag()\n");
915 ret = test_missing_n_flag();
917 printf("Error in test_missing_n_flag()\n");
921 ret = test_no_hpet_flag();
923 printf("Error in test_no_hpet_flag()\n");
927 ret = test_no_huge_flag();
929 printf("Error in test_no_huge_flag()\n");
933 ret = test_invalid_b_flag();
935 printf("Error in test_invalid_b_flag()\n");
939 ret = test_invalid_r_flag();
941 printf("Error in test_invalid_r_flag()\n");
945 ret = test_memory_flags();
947 printf("Error in test_memory_flags()\n");
951 ret = test_file_prefix();
953 printf("Error in test_file_prefix()\n");
957 ret = test_misc_flags();
959 printf("Error in test_misc_flags()");
968 * Multiprocess not applicable, so just return 0 always
973 printf("Multi-process not possible for baremetal, cannot test EAL flags\n");