]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/test/test/test_eal_flags.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright(c) 2014 6WIND S.A.
21 #include <rte_debug.h>
22 #include <rte_string_fns.h>
26 #define DEFAULT_MEM_SIZE "18"
27 #define mp_flag "--proc-type=secondary"
28 #define no_hpet "--no-hpet"
29 #define no_huge "--no-huge"
30 #define no_shconf "--no-shconf"
31 #define pci_whitelist "--pci-whitelist"
33 #define memtest "memtest"
34 #define memtest1 "memtest1"
35 #define memtest2 "memtest2"
36 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 20)
37 #define launch_proc(ARGV) process_dup(ARGV, \
38 sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
40 enum hugepage_action
{
41 HUGEPAGE_CHECK_EXISTS
= 0,
42 HUGEPAGE_CHECK_LOCKED
,
47 /* if string contains a hugepage path */
49 get_hugepage_path(char * src
, int src_len
, char * dst
, int dst_len
)
52 char *tokens
[NUM_TOKENS
];
54 /* if we couldn't properly split the string */
55 if (rte_strsplit(src
, src_len
, tokens
, NUM_TOKENS
, ' ') < NUM_TOKENS
)
58 if (strncmp(tokens
[2], "hugetlbfs", sizeof("hugetlbfs")) == 0) {
59 snprintf(dst
, dst_len
, "%s", tokens
[1]);
66 * Cycles through hugepage directories and looks for hugepage
67 * files associated with a given prefix. Depending on value of
68 * action, the hugepages are checked if they exist, checked if
69 * they can be locked, or are simply deleted.
71 * Returns 1 if it finds at least one hugepage matching the action
72 * Returns 0 if no matching hugepages were found
73 * Returns -1 if it encounters an error
76 process_hugefiles(const char * prefix
, enum hugepage_action action
)
78 FILE * hugedir_handle
= NULL
;
79 DIR * hugepage_dir
= NULL
;
80 struct dirent
*dirent
= NULL
;
82 char hugefile_prefix
[PATH_MAX
] = {0};
83 char hugedir
[PATH_MAX
] = {0};
84 char line
[PATH_MAX
] = {0};
86 int fd
, lck_result
, result
= 0;
88 const int prefix_len
= snprintf(hugefile_prefix
,
89 sizeof(hugefile_prefix
), "%smap_", prefix
);
90 if (prefix_len
<= 0 || prefix_len
>= (int)sizeof(hugefile_prefix
)
91 || prefix_len
>= (int)sizeof(dirent
->d_name
)) {
92 printf("Error creating hugefile filename prefix\n");
96 /* get hugetlbfs mountpoints from /proc/mounts */
97 hugedir_handle
= fopen("/proc/mounts", "r");
99 if (hugedir_handle
== NULL
) {
100 printf("Error parsing /proc/mounts!\n");
104 /* read and parse script output */
105 while (fgets(line
, sizeof(line
), hugedir_handle
) != NULL
) {
107 /* check if we have a hugepage filesystem path */
108 if (!get_hugepage_path(line
, sizeof(line
), hugedir
, sizeof(hugedir
)))
111 /* check if directory exists */
112 if ((hugepage_dir
= opendir(hugedir
)) == NULL
) {
113 fclose(hugedir_handle
);
114 printf("Error reading %s: %s\n", hugedir
, strerror(errno
));
118 while ((dirent
= readdir(hugepage_dir
)) != NULL
) {
119 if (memcmp(dirent
->d_name
, hugefile_prefix
, prefix_len
) != 0)
123 case HUGEPAGE_CHECK_EXISTS
:
125 /* file exists, return */
130 case HUGEPAGE_DELETE
:
132 char file_path
[PATH_MAX
] = {0};
134 snprintf(file_path
, sizeof(file_path
),
135 "%s/%s", hugedir
, dirent
->d_name
);
138 if (remove(file_path
) < 0) {
139 printf("Error deleting %s - %s!\n",
140 dirent
->d_name
, strerror(errno
));
141 closedir(hugepage_dir
);
148 case HUGEPAGE_CHECK_LOCKED
:
150 /* try and lock the file */
151 fd
= openat(dirfd(hugepage_dir
), dirent
->d_name
, O_RDONLY
);
153 /* this shouldn't happen */
155 printf("Error opening %s - %s!\n",
156 dirent
->d_name
, strerror(errno
));
157 closedir(hugepage_dir
);
162 /* non-blocking lock */
163 lck_result
= flock(fd
, LOCK_EX
| LOCK_NB
);
165 /* if lock succeeds, there's something wrong */
166 if (lck_result
!= -1) {
169 /* unlock the resulting lock */
172 closedir(hugepage_dir
);
179 /* shouldn't happen */
184 } /* read hugepage directory */
185 closedir(hugepage_dir
);
186 } /* read /proc/mounts */
188 fclose(hugedir_handle
);
192 #ifdef RTE_EXEC_ENV_LINUXAPP
194 * count the number of "node*" files in /sys/devices/system/node/
197 get_number_of_sockets(void)
199 struct dirent
*dirent
= NULL
;
200 const char * nodedir
= "/sys/devices/system/node/";
204 /* check if directory exists */
205 if ((dir
= opendir(nodedir
)) == NULL
) {
206 /* if errno==ENOENT this means we don't have NUMA support */
207 if (errno
== ENOENT
) {
208 printf("No NUMA nodes detected: assuming 1 available socket\n");
211 printf("Error opening %s: %s\n", nodedir
, strerror(errno
));
215 while ((dirent
= readdir(dir
)) != NULL
)
216 if (strncmp(dirent
->d_name
, "node", sizeof("node") - 1) == 0)
225 * Test that the app doesn't run with invalid whitelist option.
226 * Final tests ensures it does run with valid options as sanity check (one
227 * test for with Domain+BDF, second for just with BDF)
230 test_whitelist_flag(void)
233 #ifdef RTE_EXEC_ENV_BSDAPP
234 /* BSD target doesn't support prefixes at this point */
235 const char * prefix
= "";
237 char prefix
[PATH_MAX
], tmp
[PATH_MAX
];
238 if (get_current_prefix(tmp
, sizeof(tmp
)) == NULL
) {
239 printf("Error - unable to get current prefix!\n");
242 snprintf(prefix
, sizeof(prefix
), "--file-prefix=%s", tmp
);
245 const char *wlinval
[][11] = {
246 {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1",
247 pci_whitelist
, "error", "", ""},
248 {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1",
249 pci_whitelist
, "0:0:0", "", ""},
250 {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1",
251 pci_whitelist
, "0:error:0.1", "", ""},
252 {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1",
253 pci_whitelist
, "0:0:0.1error", "", ""},
254 {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1",
255 pci_whitelist
, "error0:0:0.1", "", ""},
256 {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1",
257 pci_whitelist
, "0:0:0.1.2", "", ""},
259 /* Test with valid whitelist option */
260 const char *wlval1
[] = {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1",
261 pci_whitelist
, "00FF:09:0B.3"};
262 const char *wlval2
[] = {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1",
263 pci_whitelist
, "09:0B.3", pci_whitelist
, "0a:0b.1"};
264 const char *wlval3
[] = {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1",
265 pci_whitelist
, "09:0B.3,type=test",
266 pci_whitelist
, "08:00.1,type=normal",
269 for (i
= 0; i
< sizeof(wlinval
) / sizeof(wlinval
[0]); i
++) {
270 if (launch_proc(wlinval
[i
]) == 0) {
271 printf("Error - process did run ok with invalid "
272 "whitelist parameter\n");
276 if (launch_proc(wlval1
) != 0 ) {
277 printf("Error - process did not run ok with valid whitelist\n");
280 if (launch_proc(wlval2
) != 0 ) {
281 printf("Error - process did not run ok with valid whitelist value set\n");
284 if (launch_proc(wlval3
) != 0 ) {
285 printf("Error - process did not run ok with valid whitelist + args\n");
293 * Test that the app doesn't run with invalid blacklist option.
294 * Final test ensures it does run with valid options as sanity check
297 test_invalid_b_flag(void)
299 #ifdef RTE_EXEC_ENV_BSDAPP
300 /* BSD target doesn't support prefixes at this point */
301 const char * prefix
= "";
303 char prefix
[PATH_MAX
], tmp
[PATH_MAX
];
304 if (get_current_prefix(tmp
, sizeof(tmp
)) == NULL
) {
305 printf("Error - unable to get current prefix!\n");
308 snprintf(prefix
, sizeof(prefix
), "--file-prefix=%s", tmp
);
311 const char *blinval
[][9] = {
312 {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1", "-b", "error"},
313 {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1", "-b", "0:0:0"},
314 {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1", "-b", "0:error:0.1"},
315 {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1", "-b", "0:0:0.1error"},
316 {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1", "-b", "error0:0:0.1"},
317 {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1", "-b", "0:0:0.1.2"},
319 /* Test with valid blacklist option */
320 const char *blval
[] = {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1", "-b", "FF:09:0B.3"};
324 for (i
= 0; i
!= sizeof (blinval
) / sizeof (blinval
[0]); i
++) {
325 if (launch_proc(blinval
[i
]) == 0) {
326 printf("Error - process did run ok with invalid "
327 "blacklist parameter\n");
331 if (launch_proc(blval
) != 0) {
332 printf("Error - process did not run ok with valid blacklist value\n");
339 * Test that the app doesn't run with invalid vdev option.
340 * Final test ensures it does run with valid options as sanity check
342 #ifdef RTE_LIBRTE_PMD_RING
344 test_invalid_vdev_flag(void)
346 #ifdef RTE_EXEC_ENV_BSDAPP
347 /* BSD target doesn't support prefixes at this point, and we also need to
348 * run another primary process here */
349 const char * prefix
= no_shconf
;
351 const char * prefix
= "--file-prefix=vdev";
354 /* Test with invalid vdev option */
355 const char *vdevinval
[] = {prgname
, prefix
, no_huge
, "-n", "1",
356 "-c", "1", vdev
, "eth_dummy"};
358 /* Test with valid vdev option */
359 const char *vdevval1
[] = {prgname
, prefix
, no_huge
, "-n", "1",
360 "-c", "1", vdev
, "net_ring0"};
362 const char *vdevval2
[] = {prgname
, prefix
, no_huge
, "-n", "1",
363 "-c", "1", vdev
, "net_ring0,args=test"};
365 const char *vdevval3
[] = {prgname
, prefix
, no_huge
, "-n", "1",
366 "-c", "1", vdev
, "net_ring0,nodeaction=r1:0:CREATE"};
368 if (launch_proc(vdevinval
) == 0) {
369 printf("Error - process did run ok with invalid "
374 if (launch_proc(vdevval1
) != 0) {
375 printf("Error - process did not run ok with valid vdev value\n");
379 if (launch_proc(vdevval2
) != 0) {
380 printf("Error - process did not run ok with valid vdev value,"
381 "with dummy args\n");
385 if (launch_proc(vdevval3
) != 0) {
386 printf("Error - process did not run ok with valid vdev value,"
387 "with valid args\n");
395 * Test that the app doesn't run with invalid -r option.
398 test_invalid_r_flag(void)
400 #ifdef RTE_EXEC_ENV_BSDAPP
401 /* BSD target doesn't support prefixes at this point */
402 const char * prefix
= "";
404 char prefix
[PATH_MAX
], tmp
[PATH_MAX
];
405 if (get_current_prefix(tmp
, sizeof(tmp
)) == NULL
) {
406 printf("Error - unable to get current prefix!\n");
409 snprintf(prefix
, sizeof(prefix
), "--file-prefix=%s", tmp
);
412 const char *rinval
[][9] = {
413 {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1", "-r", "error"},
414 {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1", "-r", "0"},
415 {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1", "-r", "-1"},
416 {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1", "-r", "17"},
418 /* Test with valid blacklist option */
419 const char *rval
[] = {prgname
, prefix
, mp_flag
, "-n", "1", "-c", "1", "-r", "16"};
423 for (i
= 0; i
!= sizeof (rinval
) / sizeof (rinval
[0]); i
++) {
424 if (launch_proc(rinval
[i
]) == 0) {
425 printf("Error - process did run ok with invalid "
426 "-r (rank) parameter\n");
430 if (launch_proc(rval
) != 0) {
431 printf("Error - process did not run ok with valid -r (rank) value\n");
438 * Test that the app doesn't run without the coremask/corelist flags. In all cases
439 * should give an error and fail to run
442 test_missing_c_flag(void)
444 #ifdef RTE_EXEC_ENV_BSDAPP
445 /* BSD target doesn't support prefixes at this point */
446 const char * prefix
= "";
448 char prefix
[PATH_MAX
], tmp
[PATH_MAX
];
449 if (get_current_prefix(tmp
, sizeof(tmp
)) == NULL
) {
450 printf("Error - unable to get current prefix!\n");
453 snprintf(prefix
, sizeof(prefix
), "--file-prefix=%s", tmp
);
456 /* -c flag but no coremask value */
457 const char *argv1
[] = { prgname
, prefix
, mp_flag
, "-n", "3", "-c"};
458 /* No -c, -l or --lcores flag at all */
459 const char *argv2
[] = { prgname
, prefix
, mp_flag
, "-n", "3"};
460 /* bad coremask value */
461 const char *argv3
[] = { prgname
, prefix
, mp_flag
,
462 "-n", "3", "-c", "error" };
463 /* sanity check of tests - valid coremask value */
464 const char *argv4
[] = { prgname
, prefix
, mp_flag
,
465 "-n", "3", "-c", "1" };
466 /* -l flag but no corelist value */
467 const char *argv5
[] = { prgname
, prefix
, mp_flag
,
469 const char *argv6
[] = { prgname
, prefix
, mp_flag
,
470 "-n", "3", "-l", " " };
471 /* bad corelist values */
472 const char *argv7
[] = { prgname
, prefix
, mp_flag
,
473 "-n", "3", "-l", "error" };
474 const char *argv8
[] = { prgname
, prefix
, mp_flag
,
475 "-n", "3", "-l", "1-" };
476 const char *argv9
[] = { prgname
, prefix
, mp_flag
,
477 "-n", "3", "-l", "1," };
478 const char *argv10
[] = { prgname
, prefix
, mp_flag
,
479 "-n", "3", "-l", "1#2" };
480 /* sanity check test - valid corelist value */
481 const char *argv11
[] = { prgname
, prefix
, mp_flag
,
482 "-n", "3", "-l", "1-2,3" };
484 /* --lcores flag but no lcores value */
485 const char *argv12
[] = { prgname
, prefix
, mp_flag
,
486 "-n", "3", "--lcores" };
487 const char *argv13
[] = { prgname
, prefix
, mp_flag
,
488 "-n", "3", "--lcores", " " };
489 /* bad lcores value */
490 const char *argv14
[] = { prgname
, prefix
, mp_flag
,
491 "-n", "3", "--lcores", "1-3-5" };
492 const char *argv15
[] = { prgname
, prefix
, mp_flag
,
493 "-n", "3", "--lcores", "0-1,,2" };
494 const char *argv16
[] = { prgname
, prefix
, mp_flag
,
495 "-n", "3", "--lcores", "0-,1" };
496 const char *argv17
[] = { prgname
, prefix
, mp_flag
,
497 "-n", "3", "--lcores", "(0-,2-4)" };
498 const char *argv18
[] = { prgname
, prefix
, mp_flag
,
499 "-n", "3", "--lcores", "(-1,2)" };
500 const char *argv19
[] = { prgname
, prefix
, mp_flag
,
501 "-n", "3", "--lcores", "(2-4)@(2-4-6)" };
502 const char *argv20
[] = { prgname
, prefix
, mp_flag
,
503 "-n", "3", "--lcores", "(a,2)" };
504 const char *argv21
[] = { prgname
, prefix
, mp_flag
,
505 "-n", "3", "--lcores", "1-3@(1,3)" };
506 const char *argv22
[] = { prgname
, prefix
, mp_flag
,
507 "-n", "3", "--lcores", "3@((1,3)" };
508 const char *argv23
[] = { prgname
, prefix
, mp_flag
,
509 "-n", "3", "--lcores", "(4-7)=(1,3)" };
510 const char *argv24
[] = { prgname
, prefix
, mp_flag
,
511 "-n", "3", "--lcores", "[4-7]@(1,3)" };
512 /* sanity check of tests - valid lcores value */
513 const char *argv25
[] = { prgname
, prefix
, mp_flag
,
514 "-n", "3", "--lcores",
515 "0-1,2@(5-7),(3-5)@(0,2),(0,6),7"};
517 if (launch_proc(argv2
) != 0) {
519 "process did not run ok when missing -c flag\n");
523 if (launch_proc(argv1
) == 0
524 || launch_proc(argv3
) == 0) {
526 "process ran without error with invalid -c flag\n");
529 if (launch_proc(argv4
) != 0) {
531 "process did not run ok with valid coremask value\n");
536 if (launch_proc(argv5
) == 0
537 || launch_proc(argv6
) == 0
538 || launch_proc(argv7
) == 0
539 || launch_proc(argv8
) == 0
540 || launch_proc(argv9
) == 0
541 || launch_proc(argv10
) == 0) {
543 "process ran without error with invalid -l flag\n");
546 if (launch_proc(argv11
) != 0) {
548 "process did not run ok with valid corelist value\n");
552 /* start --lcores tests */
553 if (launch_proc(argv12
) == 0 || launch_proc(argv13
) == 0 ||
554 launch_proc(argv14
) == 0 || launch_proc(argv15
) == 0 ||
555 launch_proc(argv16
) == 0 || launch_proc(argv17
) == 0 ||
556 launch_proc(argv18
) == 0 || launch_proc(argv19
) == 0 ||
557 launch_proc(argv20
) == 0 || launch_proc(argv21
) == 0 ||
558 launch_proc(argv21
) == 0 || launch_proc(argv22
) == 0 ||
559 launch_proc(argv23
) == 0 || launch_proc(argv24
) == 0) {
561 "process ran without error with invalid --lcore flag\n");
565 if (launch_proc(argv25
) != 0) {
567 "process did not run ok with valid corelist value\n");
575 * Test --master-lcore option with matching coremask
578 test_master_lcore_flag(void)
580 #ifdef RTE_EXEC_ENV_BSDAPP
581 /* BSD target doesn't support prefixes at this point */
582 const char *prefix
= "";
584 char prefix
[PATH_MAX
], tmp
[PATH_MAX
];
585 if (get_current_prefix(tmp
, sizeof(tmp
)) == NULL
) {
586 printf("Error - unable to get current prefix!\n");
589 snprintf(prefix
, sizeof(prefix
), "--file-prefix=%s", tmp
);
592 /* --master-lcore flag but no value */
593 const char *argv1
[] = { prgname
, prefix
, mp_flag
, "-n", "1", "-c", "3", "--master-lcore"};
594 /* --master-lcore flag with invalid value */
595 const char *argv2
[] = { prgname
, prefix
, mp_flag
, "-n", "1", "-c", "3", "--master-lcore", "-1"};
596 const char *argv3
[] = { prgname
, prefix
, mp_flag
, "-n", "1", "-c", "3", "--master-lcore", "X"};
597 /* master lcore not in coremask */
598 const char *argv4
[] = { prgname
, prefix
, mp_flag
, "-n", "1", "-c", "3", "--master-lcore", "2"};
600 const char *argv5
[] = { prgname
, prefix
, mp_flag
, "-n", "1", "-c", "3", "--master-lcore", "1"};
601 /* valid value set before coremask */
602 const char *argv6
[] = { prgname
, prefix
, mp_flag
, "-n", "1", "--master-lcore", "1", "-c", "3"};
604 if (launch_proc(argv1
) == 0
605 || launch_proc(argv2
) == 0
606 || launch_proc(argv3
) == 0
607 || launch_proc(argv4
) == 0) {
608 printf("Error - process ran without error with wrong --master-lcore\n");
611 if (launch_proc(argv5
) != 0
612 || launch_proc(argv6
) != 0) {
613 printf("Error - process did not run ok with valid --master-lcore\n");
620 * Test that the app doesn't run with invalid -n flag option.
621 * Final test ensures it does run with valid options as sanity check
622 * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
626 test_invalid_n_flag(void)
628 #ifdef RTE_EXEC_ENV_BSDAPP
629 /* BSD target doesn't support prefixes at this point */
630 const char * prefix
= "";
632 char prefix
[PATH_MAX
], tmp
[PATH_MAX
];
633 if (get_current_prefix(tmp
, sizeof(tmp
)) == NULL
) {
634 printf("Error - unable to get current prefix!\n");
637 snprintf(prefix
, sizeof(prefix
), "--file-prefix=%s", tmp
);
640 /* -n flag but no value */
641 const char *argv1
[] = { prgname
, prefix
, no_huge
, no_shconf
, "-c", "1", "-n"};
642 /* bad numeric value */
643 const char *argv2
[] = { prgname
, prefix
, no_huge
, no_shconf
, "-c", "1", "-n", "e" };
644 /* zero is invalid */
645 const char *argv3
[] = { prgname
, prefix
, no_huge
, no_shconf
, "-c", "1", "-n", "0" };
646 /* sanity test - check with good value */
647 const char *argv4
[] = { prgname
, prefix
, no_huge
, no_shconf
, "-c", "1", "-n", "2" };
648 /* sanity test - check with no -n flag */
649 const char *argv5
[] = { prgname
, prefix
, no_huge
, no_shconf
, "-c", "1"};
651 if (launch_proc(argv1
) == 0
652 || launch_proc(argv2
) == 0
653 || launch_proc(argv3
) == 0) {
654 printf("Error - process ran without error when"
655 "invalid -n flag\n");
658 if (launch_proc(argv4
) != 0) {
659 printf("Error - process did not run ok with valid num-channel value\n");
662 if (launch_proc(argv5
) != 0) {
663 printf("Error - process did not run ok without -n flag\n");
671 * Test that the app runs with HPET, and without HPET
674 test_no_hpet_flag(void)
676 char prefix
[PATH_MAX
] = "";
678 #ifdef RTE_EXEC_ENV_BSDAPP
682 if (get_current_prefix(tmp
, sizeof(tmp
)) == NULL
) {
683 printf("Error - unable to get current prefix!\n");
686 snprintf(prefix
, sizeof(prefix
), "--file-prefix=%s", tmp
);
690 const char *argv1
[] = {prgname
, prefix
, mp_flag
, no_hpet
, "-c", "1", "-n", "2"};
691 /* Without --no-hpet */
692 const char *argv2
[] = {prgname
, prefix
, mp_flag
, "-c", "1", "-n", "2"};
694 if (launch_proc(argv1
) != 0) {
695 printf("Error - process did not run ok with --no-hpet flag\n");
698 if (launch_proc(argv2
) != 0) {
699 printf("Error - process did not run ok without --no-hpet flag\n");
706 * Test that the app runs with --no-huge and doesn't run when --socket-mem are
707 * specified with --no-huge.
710 test_no_huge_flag(void)
712 #ifdef RTE_EXEC_ENV_BSDAPP
713 /* BSD target doesn't support prefixes at this point, and we also need to
714 * run another primary process here */
715 const char * prefix
= no_shconf
;
717 const char * prefix
= "--file-prefix=nohuge";
721 const char *argv1
[] = {prgname
, prefix
, no_huge
, "-c", "1", "-n", "2"};
722 /* With --no-huge and -m */
723 const char *argv2
[] = {prgname
, prefix
, no_huge
, "-c", "1", "-n", "2",
724 "-m", DEFAULT_MEM_SIZE
};
726 /* With --no-huge and --socket-mem */
727 const char *argv3
[] = {prgname
, prefix
, no_huge
, "-c", "1", "-n", "2",
728 "--socket-mem=" DEFAULT_MEM_SIZE
};
729 /* With --no-huge, -m and --socket-mem */
730 const char *argv4
[] = {prgname
, prefix
, no_huge
, "-c", "1", "-n", "2",
731 "-m", DEFAULT_MEM_SIZE
, "--socket-mem=" DEFAULT_MEM_SIZE
};
732 if (launch_proc(argv1
) != 0) {
733 printf("Error - process did not run ok with --no-huge flag\n");
736 if (launch_proc(argv2
) != 0) {
737 printf("Error - process did not run ok with --no-huge and -m flags\n");
740 #ifdef RTE_EXEC_ENV_BSDAPP
741 /* BSD target does not support NUMA, hence no --socket-mem tests */
745 if (launch_proc(argv3
) == 0) {
746 printf("Error - process run ok with --no-huge and --socket-mem "
750 if (launch_proc(argv4
) == 0) {
751 printf("Error - process run ok with --no-huge, -m and "
752 "--socket-mem flags\n");
759 test_misc_flags(void)
761 char hugepath
[PATH_MAX
] = {0};
762 #ifdef RTE_EXEC_ENV_BSDAPP
763 /* BSD target doesn't support prefixes at this point */
764 const char * prefix
= "";
765 const char * nosh_prefix
= "";
767 char prefix
[PATH_MAX
], tmp
[PATH_MAX
];
768 const char * nosh_prefix
= "--file-prefix=noshconf";
769 FILE * hugedir_handle
= NULL
;
770 char line
[PATH_MAX
] = {0};
771 unsigned i
, isempty
= 1;
772 if (get_current_prefix(tmp
, sizeof(tmp
)) == NULL
) {
773 printf("Error - unable to get current prefix!\n");
776 snprintf(prefix
, sizeof(prefix
), "--file-prefix=%s", tmp
);
779 * get first valid hugepage path
782 /* get hugetlbfs mountpoints from /proc/mounts */
783 hugedir_handle
= fopen("/proc/mounts", "r");
785 if (hugedir_handle
== NULL
) {
786 printf("Error opening /proc/mounts!\n");
790 /* read /proc/mounts */
791 while (fgets(line
, sizeof(line
), hugedir_handle
) != NULL
) {
793 /* find first valid hugepath */
794 if (get_hugepage_path(line
, sizeof(line
), hugepath
, sizeof(hugepath
)))
798 fclose(hugedir_handle
);
800 /* check if path is not empty */
801 for (i
= 0; i
< sizeof(hugepath
); i
++)
802 if (hugepath
[i
] != '\0')
806 printf("No mounted hugepage dir found!\n");
812 /* check that some general flags don't prevent things from working.
813 * All cases, apart from the first, app should run.
814 * No further testing of output done.
816 /* sanity check - failure with invalid option */
817 const char *argv0
[] = {prgname
, prefix
, mp_flag
, "-c", "1", "--invalid-opt"};
820 const char *argv1
[] = {prgname
, prefix
, mp_flag
, "-c", "1", "--no-pci"};
822 const char *argv2
[] = {prgname
, prefix
, mp_flag
, "-c", "1", "-v"};
823 /* With valid --syslog */
824 const char *argv3
[] = {prgname
, prefix
, mp_flag
, "-c", "1",
825 "--syslog", "syslog"};
826 /* With empty --syslog (should fail) */
827 const char *argv4
[] = {prgname
, prefix
, mp_flag
, "-c", "1", "--syslog"};
828 /* With invalid --syslog */
829 const char *argv5
[] = {prgname
, prefix
, mp_flag
, "-c", "1", "--syslog", "error"};
830 /* With no-sh-conf, also use no-huge to ensure this test runs on BSD */
831 const char *argv6
[] = {prgname
, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE
,
832 no_shconf
, nosh_prefix
, no_huge
};
834 /* With --huge-dir */
835 const char *argv7
[] = {prgname
, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE
,
836 "--file-prefix=hugedir", "--huge-dir", hugepath
};
837 /* With empty --huge-dir (should fail) */
838 const char *argv8
[] = {prgname
, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE
,
839 "--file-prefix=hugedir", "--huge-dir"};
840 /* With invalid --huge-dir */
841 const char *argv9
[] = {prgname
, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE
,
842 "--file-prefix=hugedir", "--huge-dir", "invalid"};
843 /* Secondary process with invalid --huge-dir (should run as flag has no
844 * effect on secondary processes) */
845 const char *argv10
[] = {prgname
, prefix
, mp_flag
, "-c", "1", "--huge-dir", "invalid"};
847 /* try running with base-virtaddr param */
848 const char *argv11
[] = {prgname
, "--file-prefix=virtaddr",
849 "-c", "1", "-n", "2", "--base-virtaddr=0x12345678"};
851 /* try running with --vfio-intr INTx flag */
852 const char *argv12
[] = {prgname
, "--file-prefix=intr",
853 "-c", "1", "-n", "2", "--vfio-intr=legacy"};
855 /* try running with --vfio-intr MSI flag */
856 const char *argv13
[] = {prgname
, "--file-prefix=intr",
857 "-c", "1", "-n", "2", "--vfio-intr=msi"};
859 /* try running with --vfio-intr MSI-X flag */
860 const char *argv14
[] = {prgname
, "--file-prefix=intr",
861 "-c", "1", "-n", "2", "--vfio-intr=msix"};
863 /* try running with --vfio-intr invalid flag */
864 const char *argv15
[] = {prgname
, "--file-prefix=intr",
865 "-c", "1", "-n", "2", "--vfio-intr=invalid"};
867 /* run all tests also applicable to FreeBSD first */
869 if (launch_proc(argv0
) == 0) {
870 printf("Error - process ran ok with invalid flag\n");
873 if (launch_proc(argv1
) != 0) {
874 printf("Error - process did not run ok with --no-pci flag\n");
877 if (launch_proc(argv2
) != 0) {
878 printf("Error - process did not run ok with -v flag\n");
881 if (launch_proc(argv6
) != 0) {
882 printf("Error - process did not run ok with --no-shconf flag\n");
886 #ifdef RTE_EXEC_ENV_BSDAPP
887 /* no more tests to be done on FreeBSD */
891 if (launch_proc(argv3
) != 0) {
892 printf("Error - process did not run ok with --syslog flag\n");
895 if (launch_proc(argv4
) == 0) {
896 printf("Error - process run ok with empty --syslog flag\n");
899 if (launch_proc(argv5
) == 0) {
900 printf("Error - process run ok with invalid --syslog flag\n");
903 if (launch_proc(argv7
) != 0) {
904 printf("Error - process did not run ok with --huge-dir flag\n");
907 if (launch_proc(argv8
) == 0) {
908 printf("Error - process run ok with empty --huge-dir flag\n");
911 if (launch_proc(argv9
) == 0) {
912 printf("Error - process run ok with invalid --huge-dir flag\n");
915 if (launch_proc(argv10
) != 0) {
916 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
919 if (launch_proc(argv11
) != 0) {
920 printf("Error - process did not run ok with --base-virtaddr parameter\n");
923 if (launch_proc(argv12
) != 0) {
924 printf("Error - process did not run ok with "
925 "--vfio-intr INTx parameter\n");
928 if (launch_proc(argv13
) != 0) {
929 printf("Error - process did not run ok with "
930 "--vfio-intr MSI parameter\n");
933 if (launch_proc(argv14
) != 0) {
934 printf("Error - process did not run ok with "
935 "--vfio-intr MSI-X parameter\n");
938 if (launch_proc(argv15
) == 0) {
939 printf("Error - process run ok with "
940 "--vfio-intr invalid parameter\n");
947 test_file_prefix(void)
950 * 1. check if current process hugefiles are locked
951 * 2. try to run secondary process without a corresponding primary process
952 * (while failing to run, it will also remove any unused hugepage files)
953 * 3. check if current process hugefiles are still in place and are locked
954 * 4. run a primary process with memtest1 prefix
955 * 5. check if memtest1 hugefiles are created
956 * 6. run a primary process with memtest2 prefix
957 * 7. check that only memtest2 hugefiles are present in the hugedir
959 char prefix
[PATH_MAX
] = "";
961 #ifdef RTE_EXEC_ENV_BSDAPP
964 if (get_current_prefix(prefix
, sizeof(prefix
)) == NULL
) {
965 printf("Error - unable to get current prefix!\n");
970 /* this should fail unless the test itself is run with "memtest" prefix */
971 const char *argv0
[] = {prgname
, mp_flag
, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE
,
972 "--file-prefix=" memtest
};
974 /* primary process with memtest1 */
975 const char *argv1
[] = {prgname
, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE
,
976 "--file-prefix=" memtest1
};
978 /* primary process with memtest2 */
979 const char *argv2
[] = {prgname
, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE
,
980 "--file-prefix=" memtest2
};
982 /* check if files for current prefix are present */
983 if (process_hugefiles(prefix
, HUGEPAGE_CHECK_EXISTS
) != 1) {
984 printf("Error - hugepage files for %s were not created!\n", prefix
);
988 /* checks if files for current prefix are locked */
989 if (process_hugefiles(prefix
, HUGEPAGE_CHECK_LOCKED
) != 1) {
990 printf("Error - hugepages for current process aren't locked!\n");
994 /* check if files for secondary process are present */
995 if (process_hugefiles(memtest
, HUGEPAGE_CHECK_EXISTS
) == 1) {
996 /* check if they are not locked */
997 if (process_hugefiles(memtest
, HUGEPAGE_CHECK_LOCKED
) == 1) {
998 printf("Error - hugepages for current process are locked!\n");
1001 /* they aren't locked, delete them */
1003 if (process_hugefiles(memtest
, HUGEPAGE_DELETE
) != 1) {
1004 printf("Error - deleting hugepages failed!\n");
1010 if (launch_proc(argv0
) == 0) {
1011 printf("Error - secondary process ran ok without primary process\n");
1015 /* check if files for current prefix are present */
1016 if (process_hugefiles(prefix
, HUGEPAGE_CHECK_EXISTS
) != 1) {
1017 printf("Error - hugepage files for %s were not created!\n", prefix
);
1021 /* checks if files for current prefix are locked */
1022 if (process_hugefiles(prefix
, HUGEPAGE_CHECK_LOCKED
) != 1) {
1023 printf("Error - hugepages for current process aren't locked!\n");
1027 if (launch_proc(argv1
) != 0) {
1028 printf("Error - failed to run with --file-prefix=%s\n", memtest
);
1032 /* check if memtest1_map0 is present */
1033 if (process_hugefiles(memtest1
, HUGEPAGE_CHECK_EXISTS
) != 1) {
1034 printf("Error - hugepage files for %s were not created!\n", memtest1
);
1038 if (launch_proc(argv2
) != 0) {
1039 printf("Error - failed to run with --file-prefix=%s\n", memtest2
);
1043 /* check if hugefiles for memtest2 are present */
1044 if (process_hugefiles(memtest2
, HUGEPAGE_CHECK_EXISTS
) != 1) {
1045 printf("Error - hugepage files for %s were not created!\n", memtest2
);
1049 /* check if hugefiles for memtest1 are present */
1050 if (process_hugefiles(memtest1
, HUGEPAGE_CHECK_EXISTS
) != 0) {
1051 printf("Error - hugepage files for %s were not deleted!\n", memtest1
);
1059 * Tests for correct handling of -m and --socket-mem flags
1062 test_memory_flags(void)
1064 #ifdef RTE_EXEC_ENV_BSDAPP
1065 /* BSD target doesn't support prefixes at this point */
1066 const char * prefix
= "";
1068 char prefix
[PATH_MAX
], tmp
[PATH_MAX
];
1069 if (get_current_prefix(tmp
, sizeof(tmp
)) == NULL
) {
1070 printf("Error - unable to get current prefix!\n");
1073 snprintf(prefix
, sizeof(prefix
), "--file-prefix=%s", tmp
);
1076 /* valid -m flag and mp flag */
1077 const char *argv0
[] = {prgname
, prefix
, mp_flag
, "-c", "10",
1078 "-n", "2", "-m", DEFAULT_MEM_SIZE
};
1081 const char *argv1
[] = {prgname
, "-c", "10", "-n", "2",
1082 "--file-prefix=" memtest
, "-m", DEFAULT_MEM_SIZE
};
1084 /* invalid (zero) --socket-mem flag */
1085 const char *argv2
[] = {prgname
, "-c", "10", "-n", "2",
1086 "--file-prefix=" memtest
, "--socket-mem=0,0,0,0"};
1088 /* invalid (incomplete) --socket-mem flag */
1089 const char *argv3
[] = {prgname
, "-c", "10", "-n", "2",
1090 "--file-prefix=" memtest
, "--socket-mem=2,2,"};
1092 /* invalid (mixed with invalid data) --socket-mem flag */
1093 const char *argv4
[] = {prgname
, "-c", "10", "-n", "2",
1094 "--file-prefix=" memtest
, "--socket-mem=2,2,Fred"};
1096 /* invalid (with numeric value as last character) --socket-mem flag */
1097 const char *argv5
[] = {prgname
, "-c", "10", "-n", "2",
1098 "--file-prefix=" memtest
, "--socket-mem=2,2,Fred0"};
1100 /* invalid (with empty socket) --socket-mem flag */
1101 const char *argv6
[] = {prgname
, "-c", "10", "-n", "2",
1102 "--file-prefix=" memtest
, "--socket-mem=2,,2"};
1104 /* invalid (null) --socket-mem flag */
1105 const char *argv7
[] = {prgname
, "-c", "10", "-n", "2",
1106 "--file-prefix=" memtest
, "--socket-mem="};
1108 /* valid --socket-mem specified together with -m flag */
1109 const char *argv8
[] = {prgname
, "-c", "10", "-n", "2",
1110 "--file-prefix=" memtest
, "-m", DEFAULT_MEM_SIZE
, "--socket-mem=2,2"};
1112 /* construct an invalid socket mask with 2 megs on each socket plus
1113 * extra 2 megs on socket that doesn't exist on current system */
1114 char invalid_socket_mem
[SOCKET_MEM_STRLEN
];
1115 char buf
[SOCKET_MEM_STRLEN
]; /* to avoid copying string onto itself */
1117 #ifdef RTE_EXEC_ENV_BSDAPP
1118 int i
, num_sockets
= 1;
1120 int i
, num_sockets
= RTE_MIN(get_number_of_sockets(),
1121 RTE_MAX_NUMA_NODES
);
1124 if (num_sockets
<= 0) {
1125 printf("Error - cannot get number of sockets!\n");
1129 snprintf(invalid_socket_mem
, sizeof(invalid_socket_mem
), "--socket-mem=");
1131 /* add one extra socket */
1132 for (i
= 0; i
< num_sockets
+ 1; i
++) {
1133 snprintf(buf
, sizeof(buf
), "%s%s", invalid_socket_mem
, DEFAULT_MEM_SIZE
);
1134 strlcpy(invalid_socket_mem
, buf
, sizeof(invalid_socket_mem
));
1136 if (num_sockets
+ 1 - i
> 1) {
1137 snprintf(buf
, sizeof(buf
), "%s,", invalid_socket_mem
);
1138 strlcpy(invalid_socket_mem
, buf
,
1139 sizeof(invalid_socket_mem
));
1143 /* construct a valid socket mask with 2 megs on each existing socket */
1144 char valid_socket_mem
[SOCKET_MEM_STRLEN
];
1146 snprintf(valid_socket_mem
, sizeof(valid_socket_mem
), "--socket-mem=");
1148 /* add one extra socket */
1149 for (i
= 0; i
< num_sockets
; i
++) {
1150 snprintf(buf
, sizeof(buf
), "%s%s", valid_socket_mem
, DEFAULT_MEM_SIZE
);
1151 strlcpy(valid_socket_mem
, buf
, sizeof(valid_socket_mem
));
1153 if (num_sockets
- i
> 1) {
1154 snprintf(buf
, sizeof(buf
), "%s,", valid_socket_mem
);
1155 strlcpy(valid_socket_mem
, buf
,
1156 sizeof(valid_socket_mem
));
1160 /* invalid --socket-mem flag (with extra socket) */
1161 const char *argv9
[] = {prgname
, "-c", "10", "-n", "2",
1162 "--file-prefix=" memtest
, invalid_socket_mem
};
1164 /* valid --socket-mem flag */
1165 const char *argv10
[] = {prgname
, "-c", "10", "-n", "2",
1166 "--file-prefix=" memtest
, valid_socket_mem
};
1168 if (launch_proc(argv0
) != 0) {
1169 printf("Error - secondary process failed with valid -m flag !\n");
1173 #ifdef RTE_EXEC_ENV_BSDAPP
1174 /* no other tests are applicable to BSD */
1178 if (launch_proc(argv1
) != 0) {
1179 printf("Error - process failed with valid -m flag!\n");
1182 if (launch_proc(argv2
) == 0) {
1183 printf("Error - process run ok with invalid (zero) --socket-mem!\n");
1187 if (launch_proc(argv3
) == 0) {
1188 printf("Error - process run ok with invalid "
1189 "(incomplete) --socket-mem!\n");
1193 if (launch_proc(argv4
) == 0) {
1194 printf("Error - process run ok with invalid "
1195 "(mixed with invalid input) --socket-mem!\n");
1199 if (launch_proc(argv5
) == 0) {
1200 printf("Error - process run ok with invalid "
1201 "(mixed with invalid input with a numeric value as "
1202 "last character) --socket-mem!\n");
1206 if (launch_proc(argv6
) == 0) {
1207 printf("Error - process run ok with invalid "
1208 "(with empty socket) --socket-mem!\n");
1212 if (launch_proc(argv7
) == 0) {
1213 printf("Error - process run ok with invalid (null) --socket-mem!\n");
1217 if (launch_proc(argv8
) == 0) {
1218 printf("Error - process run ok with --socket-mem and -m specified!\n");
1222 if (launch_proc(argv9
) == 0) {
1223 printf("Error - process run ok with extra socket in --socket-mem!\n");
1227 if (launch_proc(argv10
) != 0) {
1228 printf("Error - process failed with valid --socket-mem!\n");
1236 test_eal_flags(void)
1240 ret
= test_missing_c_flag();
1242 printf("Error in test_missing_c_flag()\n");
1246 ret
= test_master_lcore_flag();
1248 printf("Error in test_master_lcore_flag()\n");
1252 ret
= test_invalid_n_flag();
1254 printf("Error in test_invalid_n_flag()\n");
1258 ret
= test_no_hpet_flag();
1260 printf("Error in test_no_hpet_flag()\n");
1264 ret
= test_no_huge_flag();
1266 printf("Error in test_no_huge_flag()\n");
1270 ret
= test_whitelist_flag();
1272 printf("Error in test_invalid_whitelist_flag()\n");
1276 ret
= test_invalid_b_flag();
1278 printf("Error in test_invalid_b_flag()\n");
1282 #ifdef RTE_LIBRTE_PMD_RING
1283 ret
= test_invalid_vdev_flag();
1285 printf("Error in test_invalid_vdev_flag()\n");
1289 ret
= test_invalid_r_flag();
1291 printf("Error in test_invalid_r_flag()\n");
1295 ret
= test_memory_flags();
1297 printf("Error in test_memory_flags()\n");
1301 ret
= test_file_prefix();
1303 printf("Error in test_file_prefix()\n");
1307 ret
= test_misc_flags();
1309 printf("Error in test_misc_flags()");
1316 REGISTER_TEST_COMMAND(eal_flags_autotest
, test_eal_flags
);