Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2014 Intel Corporation.
3 : : * Copyright(c) 2014 6WIND S.A.
4 : : */
5 : :
6 : : #include <stdio.h>
7 : :
8 : : #include "test.h"
9 : :
10 : : #include <string.h>
11 : : #include <stdarg.h>
12 : :
13 : : #ifndef RTE_EXEC_ENV_LINUX
14 : : static int
15 : : test_missing_c_flag(void)
16 : : {
17 : : printf("missing_c_flag only supported on Linux, skipping test\n");
18 : : return TEST_SKIPPED;
19 : : }
20 : :
21 : : static int
22 : : test_main_lcore_flag(void)
23 : : {
24 : : printf("main_lcore_flag only supported on Linux, skipping test\n");
25 : : return TEST_SKIPPED;
26 : : }
27 : :
28 : : static int
29 : : test_invalid_n_flag(void)
30 : : {
31 : : printf("invalid_n_flag only supported on Linux, skipping test\n");
32 : : return TEST_SKIPPED;
33 : : }
34 : :
35 : : static int
36 : : test_no_hpet_flag(void)
37 : : {
38 : : printf("no_hpet_flag only supported on Linux, skipping test\n");
39 : : return TEST_SKIPPED;
40 : : }
41 : :
42 : : static int
43 : : test_no_huge_flag(void)
44 : : {
45 : : printf("no_huge_flag only supported on Linux, skipping test\n");
46 : : return TEST_SKIPPED;
47 : : }
48 : :
49 : : static int
50 : : test_allow_flag(void)
51 : : {
52 : : printf("allow_flag only supported on Linux, skipping test\n");
53 : : return TEST_SKIPPED;
54 : : }
55 : :
56 : : static int
57 : : test_invalid_b_flag(void)
58 : : {
59 : : printf("invalid_b_flag only supported on Linux, skipping test\n");
60 : : return TEST_SKIPPED;
61 : : }
62 : :
63 : : static int
64 : : test_invalid_vdev_flag(void)
65 : : {
66 : : printf("invalid_vdev_flag only supported on Linux, skipping test\n");
67 : : return TEST_SKIPPED;
68 : : }
69 : :
70 : : static int
71 : : test_invalid_r_flag(void)
72 : : {
73 : : printf("invalid_r_flag only supported on Linux, skipping test\n");
74 : : return TEST_SKIPPED;
75 : : }
76 : :
77 : : static int
78 : : test_memory_flags(void)
79 : : {
80 : : printf("memory_flags only supported on Linux, skipping test\n");
81 : : return TEST_SKIPPED;
82 : : }
83 : :
84 : : static int
85 : : test_file_prefix(void)
86 : : {
87 : : printf("file_prefix only supported on Linux, skipping test\n");
88 : : return TEST_SKIPPED;
89 : : }
90 : :
91 : : static int
92 : : test_misc_flags(void)
93 : : {
94 : : printf("misc_flags only supported on Linux, skipping test\n");
95 : : return TEST_SKIPPED;
96 : : }
97 : :
98 : : static int
99 : : test_pagesz_mem_flags(void)
100 : : {
101 : : printf("pagesz_mem_flags not supported on Windows, skipping test\n");
102 : : return TEST_SKIPPED;
103 : : }
104 : :
105 : : #else
106 : :
107 : : #include <libgen.h>
108 : : #include <stdlib.h>
109 : : #include <errno.h>
110 : : #include <unistd.h>
111 : : #include <dirent.h>
112 : : #include <sys/file.h>
113 : : #include <sys/stat.h>
114 : : #include <sys/wait.h>
115 : : #include <limits.h>
116 : : #include <fcntl.h>
117 : :
118 : : #include <rte_lcore.h>
119 : : #include <rte_debug.h>
120 : : #include <rte_string_fns.h>
121 : :
122 : : #include "process.h"
123 : :
124 : : #define DEFAULT_MEM_SIZE "18"
125 : : #define mp_flag "--proc-type=secondary"
126 : : #define no_hpet "--no-hpet"
127 : : #define no_huge "--no-huge"
128 : : #define no_shconf "--no-shconf"
129 : : #define auto_probing "--auto-probing"
130 : : #define no_auto_probing "--no-auto-probing"
131 : : #define allow "--allow"
132 : : #define vdev "--vdev"
133 : : #define no_pci "--no-pci"
134 : : #define eal_debug_logs "--log-level=lib.eal:debug"
135 : : #define bus_debug_logs "--log-level=bus.*:debug"
136 : :
137 : : #define FS_HUGETLB "hugetlbfs"
138 : :
139 : : #define memtest "memtest"
140 : : #define memtest1 "memtest1"
141 : : #define memtest2 "memtest2"
142 : : #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 20)
143 : : #define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)
144 : :
145 : : #ifdef RTE_EXEC_ENV_LINUX
146 : : #include <mntent.h>
147 : :
148 : : enum hugepage_action {
149 : : HUGEPAGE_CHECK_EXISTS = 0,
150 : : HUGEPAGE_CHECK_LOCKED,
151 : : HUGEPAGE_DELETE,
152 : : HUGEPAGE_INVALID
153 : : };
154 : :
155 : : /*
156 : : * Cycles through hugepage directories and looks for hugepage
157 : : * files associated with a given prefix. Depending on value of
158 : : * action, the hugepages are checked if they exist, checked if
159 : : * they can be locked, or are simply deleted.
160 : : *
161 : : * Returns 1 if it finds at least one hugepage matching the action
162 : : * Returns 0 if no matching hugepages were found
163 : : * Returns -1 if it encounters an error
164 : : */
165 : : static int
166 [ - + ]: 15 : process_hugefiles(const char *prefix, enum hugepage_action action)
167 : : {
168 : : const struct mntent *entry;
169 : : char hugefile_prefix[PATH_MAX];
170 : : int result = 0;
171 : :
172 : : const int prefix_len = snprintf(hugefile_prefix, sizeof(hugefile_prefix), "%smap_", prefix);
173 [ - + ]: 15 : if (prefix_len <= 0 || prefix_len >= NAME_MAX) {
174 : : printf("Error (line %d) - cannot create hugefile filename prefix\n", __LINE__);
175 : 0 : return -1;
176 : : }
177 : :
178 : : /* get hugetlbfs mountpoints from /proc/mounts */
179 : 15 : FILE *mounts = setmntent("/proc/mounts", "r");
180 [ - + ]: 15 : if (mounts == NULL) {
181 : : printf("Error (line %d) - cannot parse /proc/mounts!\n", __LINE__);
182 : 0 : return -1;
183 : : }
184 : :
185 : : /* foreach mountpoint */
186 [ + + ]: 220 : while ((entry = getmntent(mounts)) != NULL) {
187 : : DIR *hugepage_dir;
188 : : struct dirent *dirent;
189 : :
190 : : /* only want hugetlbfs filesystems */
191 [ + + ]: 210 : if (strcmp(entry->mnt_type, FS_HUGETLB) != 0)
192 : 195 : continue;
193 : :
194 : : /* check if directory exists */
195 : 15 : hugepage_dir = opendir(entry->mnt_dir);
196 [ - + ]: 15 : if (hugepage_dir == NULL) {
197 : 0 : endmntent(mounts);
198 : 0 : printf("Error (line %d) - cannot open %s: %s\n",
199 : 0 : __LINE__, entry->mnt_dir, strerror(errno));
200 : 0 : return -1;
201 : : }
202 : :
203 [ + + ]: 73 : while ((dirent = readdir(hugepage_dir)) != NULL) {
204 [ + + ]: 63 : if (memcmp(dirent->d_name, hugefile_prefix, prefix_len) != 0)
205 : 47 : continue;
206 : :
207 [ + + + - ]: 16 : switch (action) {
208 : 5 : case HUGEPAGE_CHECK_EXISTS:
209 : : {
210 : : /* file exists, return */
211 : : printf("Hugepage file %s/%s exists, matching prefix %s\n",
212 : 5 : entry->mnt_dir, dirent->d_name, hugefile_prefix);
213 : 5 : closedir(hugepage_dir);
214 : : result = 1;
215 : 5 : goto end;
216 : : }
217 : : break;
218 : 9 : case HUGEPAGE_DELETE:
219 : : {
220 : : char file_path[PATH_MAX];
221 : :
222 : : snprintf(file_path, sizeof(file_path),
223 : 9 : "%s/%s", entry->mnt_dir, dirent->d_name);
224 : :
225 : : /* remove file */
226 [ - + ]: 9 : if (remove(file_path) < 0) {
227 : 0 : printf("Error (line %d) - cannot delete %s - %s!\n",
228 : 0 : __LINE__, dirent->d_name, strerror(errno));
229 : 0 : closedir(hugepage_dir);
230 : : result = -1;
231 : 0 : goto end;
232 : : }
233 : : printf("Deleted hugepage file %s\n", file_path);
234 : : result = 1;
235 : : }
236 : 9 : break;
237 : 2 : case HUGEPAGE_CHECK_LOCKED:
238 : : {
239 : : int fd;
240 : :
241 : : /* try and lock the file */
242 : 2 : fd = openat(dirfd(hugepage_dir), dirent->d_name, O_RDONLY);
243 : :
244 : : /* this shouldn't happen */
245 [ - + ]: 2 : if (fd == -1) {
246 : 0 : printf("Error (line %d) - cannot open %s - %s!\n",
247 : 0 : __LINE__, dirent->d_name, strerror(errno));
248 : 0 : closedir(hugepage_dir);
249 : : result = -1;
250 : 0 : goto end;
251 : : }
252 : :
253 : : /* non-blocking lock */
254 [ - + ]: 2 : if (flock(fd, LOCK_EX | LOCK_NB) != -1) {
255 : : result = 0;
256 : :
257 : : /* unlock the resulting lock */
258 : 0 : flock(fd, LOCK_UN);
259 : 0 : close(fd);
260 : 0 : closedir(hugepage_dir);
261 : 0 : goto end;
262 : : }
263 : : result = 1;
264 : : printf("Hugepage file %s/%s is locked\n",
265 : 2 : entry->mnt_dir, dirent->d_name);
266 : 2 : close(fd);
267 : : }
268 : 2 : break;
269 : : /* shouldn't happen */
270 : 0 : default:
271 : 0 : goto end;
272 : : } /* switch */
273 : :
274 : : } /* read hugepage directory */
275 : 10 : closedir(hugepage_dir);
276 : : } /* read /proc/mounts */
277 : 10 : end:
278 : 15 : endmntent(mounts);
279 : 15 : return result;
280 : : }
281 : :
282 : : /*
283 : : * count the number of "node*" files in /sys/devices/system/node/
284 : : */
285 : : static int
286 : 1 : get_number_of_sockets(void)
287 : : {
288 : : struct dirent *dirent = NULL;
289 : : const char * nodedir = "/sys/devices/system/node/";
290 : : DIR * dir = NULL;
291 : : int result = 0;
292 : :
293 : : /* check if directory exists */
294 [ - + ]: 1 : if ((dir = opendir(nodedir)) == NULL) {
295 : : /* if errno==ENOENT this means we don't have NUMA support */
296 [ # # ]: 0 : if (errno == ENOENT) {
297 : : printf("No NUMA nodes detected: assuming 1 available socket\n");
298 : 0 : return 1;
299 : : }
300 : 0 : printf("Error (line %d) - cannot open %s: %s\n",
301 : : __LINE__, nodedir, strerror(errno));
302 : 0 : return -1;
303 : : }
304 : :
305 [ + + ]: 13 : while ((dirent = readdir(dir)) != NULL)
306 [ + + ]: 12 : if (strncmp(dirent->d_name, "node", sizeof("node") - 1) == 0)
307 : 2 : result++;
308 : :
309 : 1 : closedir(dir);
310 : 1 : return result;
311 : : }
312 : : #endif /* RTE_EXEC_ENV_LINUX */
313 : :
314 : : /*
315 : : * Test that the app doesn't run with invalid allow option.
316 : : * Final tests ensures it does run with valid options as sanity check (one
317 : : * test for with Domain+BDF, second for just with BDF)
318 : : */
319 : : static int
320 : 1 : test_allow_flag(void)
321 : : {
322 : : unsigned int i;
323 : 1 : const char *prefix = file_prefix_arg();
324 [ + - ]: 1 : if (prefix == NULL)
325 : : return -1;
326 : :
327 : 1 : const char *wlinval[][8] = {
328 : : {prgname, prefix, mp_flag, eal_debug_logs,
329 : : allow, "error", "", ""},
330 : : {prgname, prefix, mp_flag, eal_debug_logs,
331 : : allow, "0:0:0", "", ""},
332 : : {prgname, prefix, mp_flag, eal_debug_logs,
333 : : allow, "0:error:0.1", "", ""},
334 : : {prgname, prefix, mp_flag, eal_debug_logs,
335 : : allow, "0:0:0.1error", "", ""},
336 : : {prgname, prefix, mp_flag, eal_debug_logs,
337 : : allow, "error0:0:0.1", "", ""},
338 : : {prgname, prefix, mp_flag, eal_debug_logs,
339 : : allow, "0:0:0.1.2", "", ""},
340 : : };
341 : : /* Test with valid allow option */
342 : 1 : const char *wlval1[] = {prgname, prefix, mp_flag, eal_debug_logs,
343 : : allow, "00FF:09:0B.3"};
344 : 1 : const char *wlval2[] = {prgname, prefix, mp_flag, eal_debug_logs,
345 : : allow, "09:0B.3", allow, "0a:0b.1"};
346 : 1 : const char *wlval3[] = {prgname, prefix, mp_flag, eal_debug_logs,
347 : : allow, "09:0B.3,type=test",
348 : : allow, "08:00.1,type=normal",
349 : : };
350 : 1 : const char *wlval4[] = {prgname, prefix, mp_flag, eal_debug_logs,
351 : : no_auto_probing };
352 : 1 : const char *wlval5[] = {prgname, prefix, mp_flag, eal_debug_logs,
353 : : no_auto_probing, allow, "00FF:09:0B.3"};
354 : 1 : const char *wlval6[] = {prgname, prefix, mp_flag, eal_debug_logs,
355 : : auto_probing };
356 : 1 : const char *wlval7[] = {prgname, prefix, mp_flag, eal_debug_logs,
357 : : auto_probing, allow, "00FF:09:0B.3"};
358 : :
359 [ + + ]: 7 : for (i = 0; i < RTE_DIM(wlinval); i++) {
360 [ - + ]: 6 : if (launch_proc(wlinval[i]) == 0) {
361 : : printf("Error (line %d) - process did run ok with invalid allow parameter\n",
362 : : __LINE__);
363 : 0 : return -1;
364 : : }
365 : : }
366 [ - + ]: 1 : if (launch_proc(wlval1) != 0 ) {
367 : : printf("Error (line %d) - process did not run ok with valid allow\n", __LINE__);
368 : 0 : return -1;
369 : : }
370 [ - + ]: 1 : if (launch_proc(wlval2) != 0 ) {
371 : : printf("Error (line %d) - process did not run ok with valid allow value set\n",
372 : : __LINE__);
373 : 0 : return -1;
374 : : }
375 [ - + ]: 1 : if (launch_proc(wlval3) != 0 ) {
376 : : printf("Error (line %d) - process did not run ok with valid allow + args\n",
377 : : __LINE__);
378 : 0 : return -1;
379 : : }
380 [ - + ]: 1 : if (launch_proc(wlval4) != 0) {
381 : : printf("Error (line %d) - process did not run ok with no-auto-probing\n",
382 : : __LINE__);
383 : 0 : return -1;
384 : : }
385 [ - + ]: 1 : if (launch_proc(wlval5) != 0) {
386 : : printf("Error (line %d) - process did not run ok with no-auto-probing + allow\n",
387 : : __LINE__);
388 : 0 : return -1;
389 : : }
390 [ - + ]: 1 : if (launch_proc(wlval6) != 0) {
391 : : printf("Error (line %d) - process did not run ok with auto-probing\n",
392 : : __LINE__);
393 : 0 : return -1;
394 : : }
395 [ - + ]: 1 : if (launch_proc(wlval7) != 0) {
396 : : printf("Error (line %d) - process did not run ok with auto-probing + allow\n",
397 : : __LINE__);
398 : 0 : return -1;
399 : : }
400 : :
401 : : return 0;
402 : : }
403 : :
404 : : /*
405 : : * Test that the app doesn't run with invalid blocklist option.
406 : : * Final test ensures it does run with valid options as sanity check
407 : : */
408 : : static int
409 : 1 : test_invalid_b_flag(void)
410 : : {
411 : 1 : const char *prefix = file_prefix_arg();
412 [ + - ]: 1 : if (prefix == NULL)
413 : : return -1;
414 : :
415 : 1 : const char *blinval[][6] = {
416 : : {prgname, prefix, mp_flag, eal_debug_logs, "-b", "error"},
417 : : {prgname, prefix, mp_flag, eal_debug_logs, "-b", "0:0:0"},
418 : : {prgname, prefix, mp_flag, eal_debug_logs, "-b", "0:error:0.1"},
419 : : {prgname, prefix, mp_flag, eal_debug_logs, "-b", "0:0:0.1error"},
420 : : {prgname, prefix, mp_flag, eal_debug_logs, "-b", "error0:0:0.1"},
421 : : {prgname, prefix, mp_flag, eal_debug_logs, "-b", "0:0:0.1.2"},
422 : : };
423 : 1 : const char *blinval_probing[] =
424 : : {prgname, prefix, mp_flag, eal_debug_logs, "-b", "0:0.0", auto_probing};
425 : 1 : const char *blinval_probing_inval[] =
426 : : {prgname, prefix, mp_flag, eal_debug_logs, "-b", "0:0.0", no_auto_probing};
427 : :
428 : : /* Test with valid blocklist option */
429 : 1 : const char *blval[] = {prgname, prefix, mp_flag, eal_debug_logs,
430 : : "-b", "FF:09:0B.3"};
431 : :
432 : : int i;
433 : :
434 [ + + ]: 7 : for (i = 0; i != RTE_DIM(blinval); i++) {
435 [ - + ]: 6 : if (launch_proc(blinval[i]) == 0) {
436 : : printf("Error (line %d) - process did run ok with invalid blocklist parameter\n",
437 : : __LINE__);
438 : 0 : return -1;
439 : : }
440 : : }
441 [ - + ]: 1 : if (launch_proc(blinval_probing) != 0) {
442 : : printf("Error (line %d) - process did not run ok with blocklist and auto-probing\n",
443 : : __LINE__);
444 : 0 : return -1;
445 : : }
446 [ - + ]: 1 : if (launch_proc(blinval_probing_inval) == 0) {
447 : : printf("Error (line %d) - process did run ok with blocklist and no-auto-probing\n",
448 : : __LINE__);
449 : 0 : return -1;
450 : : }
451 [ - + ]: 1 : if (launch_proc(blval) != 0) {
452 : : printf("Error (line %d) - process did not run ok with valid blocklist value\n",
453 : : __LINE__);
454 : 0 : return -1;
455 : : }
456 : : return 0;
457 : : }
458 : :
459 : : /*
460 : : * Test that the app doesn't run with invalid vdev option.
461 : : * Final test ensures it does run with valid options as sanity check
462 : : */
463 : : static int
464 : 1 : test_invalid_vdev_flag(void)
465 : : {
466 : : #ifdef RTE_NET_RING
467 : : #ifdef RTE_EXEC_ENV_FREEBSD
468 : : /* BSD target doesn't support prefixes at this point, and we also need to
469 : : * run another primary process here */
470 : : const char * prefix = no_shconf;
471 : : #else
472 : : const char * prefix = "--file-prefix=vdev";
473 : : #endif /* !RTE_EXEC_ENV_FREEBSD */
474 : :
475 : : /* Test with invalid vdev option */
476 : 1 : const char *vdevinval[] = {prgname, prefix, no_huge, eal_debug_logs,
477 : : bus_debug_logs, no_pci, vdev, "eth_dummy"};
478 : :
479 : : /* Test with valid vdev option */
480 : 1 : const char *vdevval1[] = {prgname, prefix, no_huge, eal_debug_logs,
481 : : bus_debug_logs, no_pci, vdev, "net_ring0"};
482 : :
483 : 1 : const char *vdevval2[] = {prgname, prefix, no_huge, eal_debug_logs,
484 : : bus_debug_logs, no_pci, vdev, "net_ring0,args=test"};
485 : :
486 : 1 : const char *vdevval3[] = {prgname, prefix, no_huge, eal_debug_logs,
487 : : bus_debug_logs, no_pci, vdev, "net_ring0,nodeaction=r1:0:CREATE"};
488 : :
489 : 1 : const char *vdevval4[] = {prgname, prefix, no_huge, eal_debug_logs,
490 : : bus_debug_logs, no_auto_probing, vdev, "net_ring0"};
491 : :
492 : 1 : const char *vdevval5[] = {prgname, prefix, no_huge, eal_debug_logs,
493 : : bus_debug_logs, auto_probing, vdev, "net_ring0"};
494 : :
495 [ - + ]: 1 : if (launch_proc(vdevinval) == 0) {
496 : : printf("Error (line %d) - process did run ok with invalid vdev parameter\n",
497 : : __LINE__);
498 : 0 : return -1;
499 : : }
500 : :
501 [ - + ]: 1 : if (launch_proc(vdevval1) != 0) {
502 : : printf("Error (line %d) - process did not run ok with valid vdev value\n",
503 : : __LINE__);
504 : 0 : return -1;
505 : : }
506 : :
507 [ - + ]: 1 : if (launch_proc(vdevval2) != 0) {
508 : : printf("Error (line %d) - process did not run ok with valid vdev value with dummy args\n",
509 : : __LINE__);
510 : 0 : return -1;
511 : : }
512 : :
513 [ - + ]: 1 : if (launch_proc(vdevval3) != 0) {
514 : : printf("Error (line %d) - process did not run ok with valid vdev value with valid args\n",
515 : : __LINE__);
516 : 0 : return -1;
517 : : }
518 : :
519 [ - + ]: 1 : if (launch_proc(vdevval4) != 0) {
520 : : printf("Error (line %d) - process did not run ok with valid vdev value and no-auto-probing\n",
521 : : __LINE__);
522 : 0 : return -1;
523 : : }
524 : :
525 [ - + ]: 1 : if (launch_proc(vdevval5) != 0) {
526 : : printf("Error (line %d) - process did not run ok with valid vdev value and auto-probing\n",
527 : : __LINE__);
528 : 0 : return -1;
529 : : }
530 : : return 0;
531 : : #else
532 : : return TEST_SKIPPED;
533 : : #endif /* !RTE_NET_RING */
534 : : }
535 : :
536 : : /*
537 : : * Test that the app doesn't run with invalid -r option.
538 : : */
539 : : static int
540 : 1 : test_invalid_r_flag(void)
541 : : {
542 : 1 : const char *prefix = file_prefix_arg();
543 [ + - ]: 1 : if (prefix == NULL)
544 : : return -1;
545 : :
546 : 1 : const char *rinval[][6] = {
547 : : {prgname, prefix, mp_flag, eal_debug_logs, "-r", "error"},
548 : : {prgname, prefix, mp_flag, eal_debug_logs, "-r", "0"},
549 : : {prgname, prefix, mp_flag, eal_debug_logs, "-r", "-1"},
550 : : {prgname, prefix, mp_flag, eal_debug_logs, "-r", "17"},
551 : : };
552 : : /* Test with valid blocklist option */
553 : 1 : const char *rval[] = {prgname, prefix, mp_flag, eal_debug_logs, "-r", "16"};
554 : :
555 : : int i;
556 : :
557 [ + + ]: 5 : for (i = 0; i != RTE_DIM(rinval); i++) {
558 [ - + ]: 4 : if (launch_proc(rinval[i]) == 0) {
559 : : printf("Error (line %d) - process did run ok with invalid -r (rank) parameter\n",
560 : : __LINE__);
561 : 0 : return -1;
562 : : }
563 : : }
564 [ - + ]: 1 : if (launch_proc(rval) != 0) {
565 : : printf("Error (line %d) - process did not run ok with valid -r (rank) value\n",
566 : : __LINE__);
567 : 0 : return -1;
568 : : }
569 : : return 0;
570 : : }
571 : :
572 : : /*
573 : : * Test that the app doesn't run without the coremask/corelist flags. In all cases
574 : : * should give an error and fail to run
575 : : */
576 : : static int
577 : 1 : test_missing_c_flag(void)
578 : : {
579 : 1 : const char *prefix = file_prefix_arg();
580 [ + - ]: 1 : if (prefix == NULL)
581 : : return -1;
582 : :
583 : : /* -c flag but no coremask value */
584 : 1 : const char *argv1[] = { prgname, prefix, mp_flag, eal_debug_logs, "-c"};
585 : : /* No -c, -l or --lcores flag at all */
586 : 1 : const char *argv2[] = { prgname, prefix, mp_flag};
587 : : /* bad coremask value */
588 : 1 : const char *argv3[] = { prgname, prefix, mp_flag, eal_debug_logs,
589 : : "-c", "error" };
590 : : /* sanity check of tests - valid coremask value */
591 : 1 : const char *argv4[] = { prgname, prefix, mp_flag, eal_debug_logs,
592 : : "-c", "1" };
593 : : /* -l flag but no corelist value */
594 : 1 : const char *argv5[] = { prgname, prefix, mp_flag, eal_debug_logs,
595 : : "-l"};
596 : 1 : const char *argv6[] = { prgname, prefix, mp_flag, eal_debug_logs,
597 : : "-l", " " };
598 : : /* bad corelist values */
599 : 1 : const char *argv7[] = { prgname, prefix, mp_flag, eal_debug_logs,
600 : : "-l", "error" };
601 : 1 : const char *argv8[] = { prgname, prefix, mp_flag, eal_debug_logs,
602 : : "-l", "1-" };
603 : 1 : const char *argv9[] = { prgname, prefix, mp_flag, eal_debug_logs,
604 : : "-l", "1," };
605 : 1 : const char *argv10[] = { prgname, prefix, mp_flag, eal_debug_logs,
606 : : "-l", "1#2" };
607 : : /* core number is negative value */
608 : 1 : const char * const argv11[] = { prgname, prefix, mp_flag, eal_debug_logs,
609 : : "-l", "-5" };
610 : 1 : const char * const argv12[] = { prgname, prefix, mp_flag, eal_debug_logs,
611 : : "-l", "-5-7" };
612 : : /* core number is maximum value */
613 : 1 : const char * const argv13[] = { prgname, prefix, mp_flag, eal_debug_logs,
614 : : "-l", RTE_STR(RTE_MAX_LCORE) };
615 : 1 : const char * const argv14[] = { prgname, prefix, mp_flag, eal_debug_logs,
616 : : "-l", "1-"RTE_STR(RTE_MAX_LCORE) };
617 : : /* sanity check test - valid corelist value */
618 : 1 : const char * const argv15[] = { prgname, prefix, mp_flag, eal_debug_logs,
619 : : "-l", "1-2,3" };
620 : :
621 : : /* --lcores flag but no lcores value */
622 : 1 : const char * const argv16[] = { prgname, prefix, mp_flag, eal_debug_logs,
623 : : "--lcores" };
624 : 1 : const char * const argv17[] = { prgname, prefix, mp_flag, eal_debug_logs,
625 : : "--lcores", " " };
626 : : /* bad lcores value */
627 : 1 : const char * const argv18[] = { prgname, prefix, mp_flag, eal_debug_logs,
628 : : "--lcores", "1-3-5" };
629 : 1 : const char * const argv19[] = { prgname, prefix, mp_flag, eal_debug_logs,
630 : : "--lcores", "0-1,,2" };
631 : 1 : const char * const argv20[] = { prgname, prefix, mp_flag, eal_debug_logs,
632 : : "--lcores", "0-,1" };
633 : 1 : const char * const argv21[] = { prgname, prefix, mp_flag, eal_debug_logs,
634 : : "--lcores", "(0-,2-4)" };
635 : 1 : const char * const argv22[] = { prgname, prefix, mp_flag, eal_debug_logs,
636 : : "--lcores", "(-1,2)" };
637 : 1 : const char * const argv23[] = { prgname, prefix, mp_flag, eal_debug_logs,
638 : : "--lcores", "(2-4)@(2-4-6)" };
639 : 1 : const char * const argv24[] = { prgname, prefix, mp_flag, eal_debug_logs,
640 : : "--lcores", "(a,2)" };
641 : 1 : const char * const argv25[] = { prgname, prefix, mp_flag, eal_debug_logs,
642 : : "--lcores", "1-3@(1,3)" };
643 : 1 : const char * const argv26[] = { prgname, prefix, mp_flag, eal_debug_logs,
644 : : "--lcores", "3@((1,3)" };
645 : 1 : const char * const argv27[] = { prgname, prefix, mp_flag, eal_debug_logs,
646 : : "--lcores", "(4-7)=(1,3)" };
647 : 1 : const char * const argv28[] = { prgname, prefix, mp_flag, eal_debug_logs,
648 : : "--lcores", "[4-7]@(1,3)" };
649 : : /* sanity check of tests - valid lcores value */
650 : 1 : const char * const argv29[] = { prgname, prefix, mp_flag, eal_debug_logs,
651 : : "--lcores",
652 : : "0-1,2@(5-7),(3-5)@(0,2),(0,6),7"};
653 : : /* check an invalid cpu value >= CPU_SETSIZE */
654 : 1 : const char * const argv30[] = { prgname, prefix, mp_flag, eal_debug_logs,
655 : : "--lcores", "3@" RTE_STR(CPU_SETSIZE) };
656 : :
657 [ - + ]: 1 : if (launch_proc(argv2) != 0) {
658 : : printf("Error (line %d) - process did not run ok when missing -c flag\n",
659 : : __LINE__);
660 : 0 : return -1;
661 : : }
662 : :
663 [ + - ]: 1 : if (launch_proc(argv1) == 0
664 [ - + ]: 1 : || launch_proc(argv3) == 0) {
665 : : printf("Error (line %d) - process ran without error with invalid -c flag\n",
666 : : __LINE__);
667 : 0 : return -1;
668 : : }
669 [ - + ]: 1 : if (launch_proc(argv4) != 0) {
670 : : printf("Error (line %d) - process did not run ok with valid coremask value\n",
671 : : __LINE__);
672 : 0 : return -1;
673 : : }
674 : :
675 : : /* start -l test */
676 [ + - ]: 1 : if (launch_proc(argv5) == 0
677 [ + - ]: 1 : || launch_proc(argv6) == 0
678 [ + - ]: 1 : || launch_proc(argv7) == 0
679 [ + - ]: 1 : || launch_proc(argv8) == 0
680 [ + - ]: 1 : || launch_proc(argv9) == 0
681 [ + - ]: 1 : || launch_proc(argv10) == 0
682 [ + - ]: 1 : || launch_proc(argv11) == 0
683 [ + - ]: 1 : || launch_proc(argv12) == 0
684 [ + - ]: 1 : || launch_proc(argv13) == 0
685 [ - + ]: 1 : || launch_proc(argv14) == 0) {
686 : : printf("Error (line %d) - process ran without error with invalid -l flag\n",
687 : : __LINE__);
688 : 0 : return -1;
689 : : }
690 [ + - + - : 2 : if (rte_lcore_is_enabled(0) && rte_lcore_is_enabled(1) &&
- + ]
691 [ - - - - ]: 1 : rte_lcore_is_enabled(2) && rte_lcore_is_enabled(3) &&
692 : 0 : launch_proc(argv15) != 0) {
693 : : printf("Error (line %d) - process did not run ok with valid corelist value\n",
694 : : __LINE__);
695 : 0 : return -1;
696 : : }
697 : :
698 : : /* start --lcores tests */
699 [ + - + - : 2 : if (launch_proc(argv16) == 0 || launch_proc(argv17) == 0 ||
+ - ]
700 [ + - + - ]: 3 : launch_proc(argv18) == 0 || launch_proc(argv19) == 0 ||
701 [ + - + - ]: 3 : launch_proc(argv20) == 0 || launch_proc(argv21) == 0 ||
702 [ + - + - ]: 3 : launch_proc(argv22) == 0 || launch_proc(argv23) == 0 ||
703 [ + - + - ]: 3 : launch_proc(argv24) == 0 || launch_proc(argv25) == 0 ||
704 [ + - + - ]: 3 : launch_proc(argv26) == 0 || launch_proc(argv27) == 0 ||
705 [ - + ]: 2 : launch_proc(argv28) == 0 || launch_proc(argv30) == 0) {
706 : : printf("Error (line %d) - process ran without error with invalid --lcores flag\n",
707 : : __LINE__);
708 : 0 : return -1;
709 : : }
710 : :
711 [ + - + - : 2 : if (rte_lcore_is_enabled(0) && rte_lcore_is_enabled(1) &&
- + ]
712 [ - - - - ]: 1 : rte_lcore_is_enabled(2) && rte_lcore_is_enabled(3) &&
713 [ # # # # ]: 0 : rte_lcore_is_enabled(4) && rte_lcore_is_enabled(5) &&
714 [ # # # # ]: 0 : rte_lcore_is_enabled(6) && rte_lcore_is_enabled(7) &&
715 : 0 : launch_proc(argv29) != 0) {
716 : : printf("Error (line %d) - process did not run ok with valid corelist value\n",
717 : : __LINE__);
718 : 0 : return -1;
719 : : }
720 : :
721 : : return 0;
722 : : }
723 : :
724 : : /*
725 : : * Test --main-lcore option with matching coremask
726 : : */
727 : : static int
728 : 1 : test_main_lcore_flag(void)
729 : : {
730 : 1 : const char *prefix = file_prefix_arg();
731 [ + - ]: 1 : if (prefix == NULL)
732 : : return -1;
733 : :
734 [ + - - + ]: 1 : if (!rte_lcore_is_enabled(0) || !rte_lcore_is_enabled(1))
735 : 0 : return TEST_SKIPPED;
736 : :
737 : : /* --main-lcore flag but no value */
738 : 1 : const char *argv1[] = { prgname, prefix, mp_flag, eal_debug_logs,
739 : : "-c", "3", "--main-lcore"};
740 : : /* --main-lcore flag with invalid value */
741 : 1 : const char *argv2[] = { prgname, prefix, mp_flag, eal_debug_logs,
742 : : "-c", "3", "--main-lcore", "-1"};
743 : 1 : const char *argv3[] = { prgname, prefix, mp_flag, eal_debug_logs,
744 : : "-c", "3", "--main-lcore", "X"};
745 : : /* main lcore not in coremask */
746 : 1 : const char *argv4[] = { prgname, prefix, mp_flag, eal_debug_logs,
747 : : "-c", "3", "--main-lcore", "2"};
748 : : /* valid value */
749 : 1 : const char *argv5[] = { prgname, prefix, mp_flag, eal_debug_logs,
750 : : "-c", "3", "--main-lcore", "1"};
751 : : /* valid value set before coremask */
752 : 1 : const char *argv6[] = { prgname, prefix, mp_flag, eal_debug_logs,
753 : : "--main-lcore", "1", "-c", "3"};
754 : :
755 [ + - ]: 1 : if (launch_proc(argv1) == 0
756 [ + - ]: 1 : || launch_proc(argv2) == 0
757 [ + - ]: 1 : || launch_proc(argv3) == 0
758 [ - + ]: 1 : || launch_proc(argv4) == 0) {
759 : : printf("Error (line %d) - process ran without error with wrong --main-lcore\n",
760 : : __LINE__);
761 : 0 : return -1;
762 : : }
763 [ + - ]: 1 : if (launch_proc(argv5) != 0
764 [ - + ]: 1 : || launch_proc(argv6) != 0) {
765 : : printf("Error (line %d) - process did not run ok with valid --main-lcore\n",
766 : : __LINE__);
767 : 0 : return -1;
768 : : }
769 : : return 0;
770 : : }
771 : :
772 : : /*
773 : : * Test that the app doesn't run with invalid -n flag option.
774 : : * Final test ensures it does run with valid options as sanity check
775 : : * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
776 : : * flags.
777 : : */
778 : : static int
779 : 1 : test_invalid_n_flag(void)
780 : : {
781 : 1 : const char *prefix = file_prefix_arg();
782 [ + - ]: 1 : if (prefix == NULL)
783 : : return -1;
784 : :
785 : : /* -n flag but no value */
786 : 1 : const char *argv1[] = { prgname, prefix, no_huge, no_shconf,
787 : : "-n"};
788 : : /* bad numeric value */
789 : 1 : const char *argv2[] = { prgname, prefix, no_huge, no_shconf,
790 : : "-n", "e" };
791 : : /* zero is invalid */
792 : 1 : const char *argv3[] = { prgname, prefix, no_huge, no_shconf,
793 : : "-n", "0" };
794 : : /* sanity test - check with good value */
795 : 1 : const char *argv4[] = { prgname, prefix, no_huge, no_shconf,
796 : : "-n", "2" };
797 : : /* sanity test - check with no -n flag */
798 : 1 : const char *argv5[] = { prgname, prefix, no_huge, no_shconf};
799 : :
800 [ + - ]: 1 : if (launch_proc(argv1) == 0
801 [ + - ]: 1 : || launch_proc(argv2) == 0
802 [ - + ]: 1 : || launch_proc(argv3) == 0) {
803 : : printf("Error (line %d) - process ran without error when invalid -n flag\n",
804 : : __LINE__);
805 : 0 : return -1;
806 : : }
807 [ - + ]: 1 : if (launch_proc(argv4) != 0) {
808 : : printf("Error (line %d) - process did not run ok with valid num-channel value\n",
809 : : __LINE__);
810 : 0 : return -1;
811 : : }
812 [ - + ]: 1 : if (launch_proc(argv5) != 0) {
813 : : printf("Error (line %d) - process did not run ok without -n flag\n", __LINE__);
814 : 0 : return -1;
815 : : }
816 : :
817 : : return 0;
818 : : }
819 : :
820 : : /*
821 : : * Test that the app runs with HPET, and without HPET
822 : : */
823 : : static int
824 : 1 : test_no_hpet_flag(void)
825 : : {
826 : : #ifdef RTE_EXEC_ENV_FREEBSD
827 : : return 0;
828 : : #else
829 : 1 : const char *prefix = file_prefix_arg();
830 [ - + ]: 1 : if (prefix == NULL) {
831 : : printf("Error (line %d) - unable to get current prefix!\n", __LINE__);
832 : 0 : return -1;
833 : : }
834 : :
835 : : /* With --no-hpet */
836 : 1 : const char *argv1[] = {prgname, prefix, mp_flag, eal_debug_logs, no_hpet};
837 : : /* Without --no-hpet */
838 : 1 : const char *argv2[] = {prgname, prefix, mp_flag, eal_debug_logs};
839 : :
840 [ - + ]: 1 : if (launch_proc(argv1) != 0) {
841 : : printf("Error (line %d) - process did not run ok with --no-hpet flag\n", __LINE__);
842 : 0 : return -1;
843 : : }
844 [ - + ]: 1 : if (launch_proc(argv2) != 0) {
845 : : printf("Error (line %d) - process did not run ok without --no-hpet flag\n",
846 : : __LINE__);
847 : 0 : return -1;
848 : : }
849 : : return 0;
850 : : #endif
851 : : }
852 : :
853 : : /*
854 : : * Test that the app runs with --no-huge and doesn't run when --socket-mem are
855 : : * specified with --no-huge.
856 : : */
857 : : static int
858 : 1 : test_no_huge_flag(void)
859 : : {
860 : : #ifdef RTE_EXEC_ENV_FREEBSD
861 : : /* BSD target doesn't support prefixes at this point, and we also need to
862 : : * run another primary process here */
863 : : const char * prefix = no_shconf;
864 : : #else
865 : : const char * prefix = "--file-prefix=nohuge";
866 : : #endif
867 : :
868 : : /* With --no-huge */
869 : 1 : const char *argv1[] = {prgname, prefix, no_huge};
870 : : /* With --no-huge and -m */
871 : 1 : const char *argv2[] = {prgname, prefix, no_huge,
872 : : "-m", DEFAULT_MEM_SIZE};
873 : :
874 [ - + ]: 1 : if (launch_proc(argv1) != 0) {
875 : : printf("Error - process did not run ok with --no-huge flag\n");
876 : 0 : return -1;
877 : : }
878 [ - + ]: 1 : if (launch_proc(argv2) != 0) {
879 : : printf("Error - process did not run ok with --no-huge and -m flags\n");
880 : 0 : return -1;
881 : : }
882 : : #ifndef RTE_EXEC_ENV_FREEBSD
883 : : /* With --no-huge and --socket-mem */
884 : 1 : const char *argv3[] = {prgname, prefix, no_huge,
885 : : "--socket-mem=" DEFAULT_MEM_SIZE};
886 : : /* With --no-huge, -m and --socket-mem */
887 : 1 : const char *argv4[] = {prgname, prefix, no_huge,
888 : : "-m", DEFAULT_MEM_SIZE, "--socket-mem=" DEFAULT_MEM_SIZE};
889 : :
890 : : /* With --no-huge and --huge-worker-stack (should fail) */
891 : 1 : const char * const argv5[] = {prgname, prefix, no_huge,
892 : : "--huge-worker-stack"};
893 : : /* With --no-huge and --huge-worker-stack=512 (should fail) */
894 : 1 : const char * const argv6[] = {prgname, prefix, no_huge,
895 : : "--huge-worker-stack=512"};
896 : :
897 [ - + ]: 1 : if (launch_proc(argv3) == 0) {
898 : : printf("Error (line %d) - process run ok with --no-huge and --socket-mem flags\n",
899 : : __LINE__);
900 : 0 : return -1;
901 : : }
902 [ - + ]: 1 : if (launch_proc(argv4) == 0) {
903 : : printf("Error (line %d) - process run ok with --no-huge, -m and --socket-mem flags\n",
904 : : __LINE__);
905 : 0 : return -1;
906 : : }
907 [ - + ]: 1 : if (launch_proc(argv5) == 0) {
908 : : printf("Error (line %d) - process run ok with --no-huge and --huge-worker-stack flags\n",
909 : : __LINE__);
910 : 0 : return -1;
911 : : }
912 [ - + ]: 1 : if (launch_proc(argv6) == 0) {
913 : : printf("Error (line %d) - process run ok with --no-huge and --huge-worker-stack=size flags\n",
914 : : __LINE__);
915 : 0 : return -1;
916 : : }
917 : : #endif /* !RTE_EXEC_ENV_FREEBSD */
918 : : return 0;
919 : : }
920 : :
921 : : static int
922 : 1 : test_misc_flags(void)
923 : : {
924 : : const char *hugepath = "";
925 : : char hugepath_dir[PATH_MAX];
926 : : char hugepath_dir2[PATH_MAX];
927 : : char hugepath_dir3[PATH_MAX];
928 : : #ifdef RTE_EXEC_ENV_FREEBSD
929 : : /* BSD target doesn't support prefixes at this point */
930 : : const char * prefix = "";
931 : : const char * nosh_prefix = "";
932 : : #else
933 : 1 : const char *prefix = file_prefix_arg();
934 : : const char * nosh_prefix = "--file-prefix=noshconf";
935 : : struct mntent *entry;
936 : :
937 [ - + ]: 1 : if (prefix == NULL) {
938 : : printf("Error (line %d) - unable to get current prefix!\n", __LINE__);
939 : 0 : return -1;
940 : : }
941 : :
942 : : /*
943 : : * get first valid hugepage path
944 : : */
945 : :
946 : : /* get hugetlbfs mountpoints from /proc/mounts */
947 : 1 : FILE *mounts = setmntent("/proc/mounts", "r");
948 [ - + ]: 1 : if (mounts == NULL) {
949 : : printf("Error (line %d) - cannot open /proc/mounts!\n", __LINE__);
950 : 0 : return -1;
951 : : }
952 : :
953 : : /* foreach mount point */
954 : : hugepath = NULL;
955 [ + - ]: 10 : while ((entry = getmntent(mounts)) != NULL) {
956 : : /* only want hugetlbfs filesystems */
957 [ + + ]: 10 : if (strcmp(entry->mnt_type, FS_HUGETLB) == 0) {
958 : 1 : hugepath = strdupa(entry->mnt_dir);
959 : 1 : break;
960 : : }
961 : : }
962 : 1 : endmntent(mounts);
963 : :
964 [ - + ]: 1 : if (hugepath == NULL) {
965 : : printf("No mounted hugepage dir found!\n");
966 : 0 : return -1;
967 : : }
968 : : #endif
969 : :
970 : : snprintf(hugepath_dir, sizeof(hugepath_dir), "%s/dpdk.missing", hugepath);
971 : : snprintf(hugepath_dir2, sizeof(hugepath_dir2), "%s/dpdk.dir", hugepath);
972 : :
973 [ - + - - ]: 1 : if (mkdir(hugepath_dir2, 0700) != 0 && errno != EEXIST) {
974 : : printf("Error (line %d) - failed to mkdir(%s)\n", __LINE__, hugepath_dir2);
975 : 0 : return -1;
976 : : }
977 : :
978 : : snprintf(hugepath_dir3, sizeof(hugepath_dir3), "%s/dpdk.dir/sub", hugepath);
979 : :
980 [ - + - - ]: 1 : if (mkdir(hugepath_dir3, 0700) != 0 && errno != EEXIST) {
981 : : printf("Error (line %d) - failed to mkdir(%s)\n", __LINE__, hugepath_dir3);
982 : 0 : goto fail;
983 : : }
984 : :
985 : : /* check that some general flags don't prevent things from working.
986 : : * All cases, apart from the first, app should run.
987 : : * No further testing of output done.
988 : : */
989 : : /* sanity check - failure with invalid option */
990 : 1 : const char *argv0[] = {prgname, prefix, mp_flag, eal_debug_logs, "--invalid-opt"};
991 : :
992 : : /* With --no-pci */
993 : 1 : const char *argv1[] = {prgname, prefix, mp_flag, eal_debug_logs, "--no-pci"};
994 : : /* With -v */
995 : 1 : const char *argv2[] = {prgname, prefix, mp_flag, eal_debug_logs, "-v"};
996 : : /* With valid --syslog */
997 : 1 : const char *argv3[] = {prgname, prefix, mp_flag, eal_debug_logs, "--syslog=user"};
998 : : /* With empty --syslog (now defaults) */
999 : 1 : const char *argv4[] = {prgname, prefix, mp_flag, eal_debug_logs, "--syslog"};
1000 : : /* With invalid --syslog */
1001 : 1 : const char *argv5[] = {prgname, prefix, mp_flag, eal_debug_logs, "--syslog=invalid"};
1002 : :
1003 : : /* With no-sh-conf, also use no-huge to ensure this test runs on BSD */
1004 : 1 : const char *argv6[] = {prgname, eal_debug_logs, no_pci, "-m", DEFAULT_MEM_SIZE,
1005 : : no_shconf, nosh_prefix, no_huge};
1006 : :
1007 : : /* With --huge-dir */
1008 : 1 : const char *argv7[] = {prgname, "-m", DEFAULT_MEM_SIZE,
1009 : : eal_debug_logs, no_pci,
1010 : : "--file-prefix=hugedir", "--huge-dir", hugepath};
1011 : : /* With empty --huge-dir (should fail) */
1012 : 1 : const char *argv8[] = {prgname, "-m", DEFAULT_MEM_SIZE,
1013 : : eal_debug_logs, no_pci,
1014 : : "--file-prefix=hugedir", "--huge-dir"};
1015 : : /* With invalid --huge-dir */
1016 : 1 : const char *argv9[] = {prgname, "-m", DEFAULT_MEM_SIZE,
1017 : : eal_debug_logs, no_pci,
1018 : : "--file-prefix=hugedir", "--huge-dir", "invalid"};
1019 : : /* With invalid --huge-dir sub-directory */
1020 : 1 : const char *argv10[] = {prgname, "-m", DEFAULT_MEM_SIZE,
1021 : : eal_debug_logs, no_pci,
1022 : : "--file-prefix=hugedir", "--huge-dir", hugepath_dir};
1023 : : /* With valid --huge-dir sub-directory */
1024 : 1 : const char *argv11[] = {prgname, "-m", DEFAULT_MEM_SIZE,
1025 : : eal_debug_logs, no_pci,
1026 : : "--file-prefix=hugedir", "--huge-dir", hugepath_dir2};
1027 : : /* Secondary process with invalid --huge-dir (should run as flag has no
1028 : : * effect on secondary processes) */
1029 : 1 : const char *argv12[] = {prgname, prefix, mp_flag, eal_debug_logs,
1030 : : "--huge-dir", "invalid"};
1031 : :
1032 : : /* try running with base-virtaddr param */
1033 : 1 : const char *argv13[] = {prgname, "--file-prefix=virtaddr",
1034 : : eal_debug_logs, no_pci,
1035 : : "--base-virtaddr=0x23456789"};
1036 : :
1037 : : /* try running with --vfio-intr INTx flag */
1038 : 1 : const char *argv14[] = {prgname, "--file-prefix=intr",
1039 : : eal_debug_logs, no_pci,
1040 : : "--vfio-intr=legacy"};
1041 : :
1042 : : /* try running with --vfio-intr MSI flag */
1043 : 1 : const char *argv15[] = {prgname, "--file-prefix=intr",
1044 : : eal_debug_logs, no_pci,
1045 : : "--vfio-intr=msi"};
1046 : :
1047 : : /* try running with --vfio-intr MSI-X flag */
1048 : 1 : const char *argv16[] = {prgname, "--file-prefix=intr",
1049 : : eal_debug_logs, no_pci,
1050 : : "--vfio-intr=msix"};
1051 : :
1052 : : /* try running with --vfio-intr invalid flag */
1053 : 1 : const char *argv17[] = {prgname, "--file-prefix=intr",
1054 : : eal_debug_logs, no_pci,
1055 : : "--vfio-intr=invalid"};
1056 : :
1057 : : /* With process type as auto-detect */
1058 : 1 : const char * const argv18[] = {prgname, "--file-prefix=auto",
1059 : : eal_debug_logs, no_pci,
1060 : : "--proc-type=auto"};
1061 : :
1062 : : /* With process type as auto-detect with no-shconf */
1063 : 1 : const char * const argv19[] = {prgname, "--proc-type=auto", eal_debug_logs, no_pci,
1064 : : no_shconf, nosh_prefix, no_huge};
1065 : :
1066 : : /* With process type as --create-uio-dev flag */
1067 : 1 : const char * const argv20[] = {prgname, "--file-prefix=uiodev",
1068 : : eal_debug_logs, no_pci,
1069 : : "--create-uio-dev"};
1070 : :
1071 : : /* Try running with --huge-worker-stack flag */
1072 : 1 : const char * const argv21[] = {prgname, prefix, mp_flag, eal_debug_logs,
1073 : : "--huge-worker-stack"};
1074 : :
1075 : : /* Try running with --huge-worker-stack=512 flag */
1076 : 1 : const char * const argv22[] = {prgname, prefix, mp_flag, eal_debug_logs,
1077 : : "--huge-worker-stack=512"};
1078 : :
1079 : : /* Try running with --log-timestamp */
1080 : 1 : const char * const argv23[] = {prgname, prefix, mp_flag, eal_debug_logs,
1081 : : "--log-timestamp" };
1082 : :
1083 : : /* Try running with --log-timestamp=iso */
1084 : 1 : const char * const argv24[] = {prgname, prefix, mp_flag, eal_debug_logs,
1085 : : "--log-timestamp=iso" };
1086 : :
1087 : : /* Try running with invalid timestamp */
1088 : 1 : const char * const argv25[] = {prgname, prefix, mp_flag, eal_debug_logs,
1089 : : "--log-timestamp=invalid" };
1090 : :
1091 : : /* Try running with --log-color */
1092 : 1 : const char * const argv26[] = {prgname, prefix, mp_flag, eal_debug_logs,
1093 : : "--log-color" };
1094 : :
1095 : : /* Try running with --log-color=never */
1096 : 1 : const char * const argv27[] = {prgname, prefix, mp_flag, eal_debug_logs,
1097 : : "--log-color=never" };
1098 : :
1099 : : /* Try running with --log-color=invalid */
1100 : 1 : const char * const argv28[] = {prgname, prefix, mp_flag, eal_debug_logs,
1101 : : "--log-color=invalid" };
1102 : :
1103 : : /* run all tests also applicable to FreeBSD first */
1104 : :
1105 [ - + ]: 1 : if (launch_proc(argv0) == 0) {
1106 : : printf("Error (line %d) - process ran ok with invalid flag\n", __LINE__);
1107 : 0 : goto fail;
1108 : : }
1109 [ - + ]: 1 : if (launch_proc(argv1) != 0) {
1110 : : printf("Error (line %d) - process did not run ok with --no-pci flag\n", __LINE__);
1111 : 0 : goto fail;
1112 : : }
1113 [ - + ]: 1 : if (launch_proc(argv2) != 0) {
1114 : : printf("Error (line %d) - process did not run ok with -v flag\n", __LINE__);
1115 : 0 : goto fail;
1116 : : }
1117 [ - + ]: 1 : if (launch_proc(argv6) != 0) {
1118 : : printf("Error (line %d) - process did not run ok with --no-shconf flag\n",
1119 : : __LINE__);
1120 : 0 : goto fail;
1121 : : }
1122 : :
1123 : : #ifdef RTE_EXEC_ENV_FREEBSD
1124 : : /* no more tests to be done on FreeBSD */
1125 : : return 0;
1126 : : #endif
1127 : :
1128 [ - + ]: 1 : if (launch_proc(argv3) != 0) {
1129 : : printf("Error (line %d) - process did not run ok with --syslog=user flag\n",
1130 : : __LINE__);
1131 : 0 : goto fail;
1132 : : }
1133 [ - + ]: 1 : if (launch_proc(argv4) != 0) {
1134 : : printf("Error (line %d) - process did not run ok with --syslog flag\n", __LINE__);
1135 : 0 : goto fail;
1136 : : }
1137 [ - + ]: 1 : if (launch_proc(argv5) == 0) {
1138 : : printf("Error (line %d) - process run ok with --syslog=invalid flag\n", __LINE__);
1139 : 0 : goto fail;
1140 : : }
1141 [ - + ]: 1 : if (launch_proc(argv7) != 0) {
1142 : : printf("Error (line %d) - process did not run ok with --huge-dir flag\n",
1143 : : __LINE__);
1144 : 0 : goto fail;
1145 : : }
1146 [ - + ]: 1 : if (launch_proc(argv8) == 0) {
1147 : : printf("Error (line %d) - process run ok with empty --huge-dir flag\n", __LINE__);
1148 : 0 : goto fail;
1149 : : }
1150 [ - + ]: 1 : if (launch_proc(argv9) == 0) {
1151 : : printf("Error (line %d) - process run ok with invalid --huge-dir flag\n", __LINE__);
1152 : 0 : goto fail;
1153 : : }
1154 [ - + ]: 1 : if (launch_proc(argv10) == 0) {
1155 : : printf("Error (line %d) - process run ok with invalid --huge-dir sub-dir flag\n",
1156 : : __LINE__);
1157 : 0 : goto fail;
1158 : : }
1159 [ - + ]: 1 : if (launch_proc(argv11) != 0) {
1160 : : printf("Error (line %d) - process did not run ok with --huge-dir subdir flag\n",
1161 : : __LINE__);
1162 : 0 : goto fail;
1163 : : }
1164 [ - + ]: 1 : if (launch_proc(argv12) != 0) {
1165 : : printf("Error (line %d) - secondary process did not run ok with invalid --huge-dir flag\n",
1166 : : __LINE__);
1167 : 0 : goto fail;
1168 : : }
1169 [ - + ]: 1 : if (launch_proc(argv13) != 0) {
1170 : : printf("Error (line %d) - process did not run ok with --base-virtaddr parameter\n",
1171 : : __LINE__);
1172 : 0 : goto fail;
1173 : : }
1174 [ - + ]: 1 : if (launch_proc(argv14) != 0) {
1175 : : printf("Error (line %d) - process did not run ok with --vfio-intr INTx parameter\n",
1176 : : __LINE__);
1177 : 0 : goto fail;
1178 : : }
1179 [ - + ]: 1 : if (launch_proc(argv15) != 0) {
1180 : : printf("Error (line %d) - process did not run ok with --vfio-intr MSI parameter\n",
1181 : : __LINE__);
1182 : 0 : goto fail;
1183 : : }
1184 [ - + ]: 1 : if (launch_proc(argv16) != 0) {
1185 : : printf("Error (line %d) - process did not run ok with --vfio-intr MSI-X parameter\n",
1186 : : __LINE__);
1187 : 0 : goto fail;
1188 : : }
1189 [ - + ]: 1 : if (launch_proc(argv17) == 0) {
1190 : : printf("Error (line %d) - process run ok with --vfio-intr invalid parameter\n",
1191 : : __LINE__);
1192 : 0 : goto fail;
1193 : : }
1194 [ - + ]: 1 : if (launch_proc(argv18) != 0) {
1195 : : printf("Error (line %d) - process did not run ok with --proc-type as auto parameter\n",
1196 : : __LINE__);
1197 : 0 : goto fail;
1198 : : }
1199 [ - + ]: 1 : if (launch_proc(argv19) != 0) {
1200 : : printf("Error (line %d) - process did not run ok with --proc-type and --no-shconf parameter\n",
1201 : : __LINE__);
1202 : 0 : goto fail;
1203 : : }
1204 [ - + ]: 1 : if (launch_proc(argv20) != 0) {
1205 : : printf("Error (line %d) - process did not run ok with --create-uio-dev parameter\n",
1206 : : __LINE__);
1207 : 0 : goto fail;
1208 : : }
1209 [ - + ]: 1 : if (launch_proc(argv21) != 0) {
1210 : : printf("Error (line %d) - process did not run ok with --huge-worker-stack parameter\n",
1211 : : __LINE__);
1212 : 0 : goto fail;
1213 : : }
1214 [ - + ]: 1 : if (launch_proc(argv22) != 0) {
1215 : : printf("Error (line %d) - process did not run ok with --huge-worker-stack=size parameter\n",
1216 : : __LINE__);
1217 : 0 : goto fail;
1218 : : }
1219 [ - + ]: 1 : if (launch_proc(argv23) != 0) {
1220 : : printf("Error (line %d) - process did not run ok with --log-timestamp parameter\n",
1221 : : __LINE__);
1222 : 0 : goto fail;
1223 : : }
1224 [ - + ]: 1 : if (launch_proc(argv24) != 0) {
1225 : : printf("Error (line %d) - process did not run ok with --log-timestamp=iso parameter\n",
1226 : : __LINE__);
1227 : 0 : goto fail;
1228 : : }
1229 [ - + ]: 1 : if (launch_proc(argv25) == 0) {
1230 : : printf("Error (line %d) - process did run ok with --log-timestamp=invalid parameter\n",
1231 : : __LINE__);
1232 : 0 : goto fail;
1233 : : }
1234 [ - + ]: 1 : if (launch_proc(argv26) != 0) {
1235 : : printf("Error (line %d) - process did not run ok with --log-color parameter\n",
1236 : : __LINE__);
1237 : 0 : goto fail;
1238 : : }
1239 [ - + ]: 1 : if (launch_proc(argv27) != 0) {
1240 : : printf("Error (line %d) - process did not run ok with --log-color=never parameter\n",
1241 : : __LINE__);
1242 : 0 : goto fail;
1243 : : }
1244 [ - + ]: 1 : if (launch_proc(argv28) == 0) {
1245 : : printf("Error (line %d) - process did run ok with --log-timestamp=invalid parameter\n",
1246 : : __LINE__);
1247 : 0 : goto fail;
1248 : : }
1249 : :
1250 : 1 : rmdir(hugepath_dir3);
1251 : 1 : rmdir(hugepath_dir2);
1252 : 1 : return 0;
1253 : :
1254 : 0 : fail:
1255 : 0 : rmdir(hugepath_dir3);
1256 : 0 : rmdir(hugepath_dir2);
1257 : 0 : return -1;
1258 : : }
1259 : :
1260 : : #ifdef RTE_EXEC_ENV_FREEBSD
1261 : :
1262 : : static int
1263 : : test_file_prefix(void)
1264 : : {
1265 : : printf("file_prefix not supported on FreeBSD, skipping test\n");
1266 : : return TEST_SKIPPED;
1267 : : }
1268 : :
1269 : : #else
1270 : :
1271 : : static int
1272 : 1 : test_file_prefix(void)
1273 : : {
1274 : : /*
1275 : : * 1. check if current process hugefiles are locked
1276 : : * 2. try to run secondary process without a corresponding primary process
1277 : : * (while failing to run, it will also remove any unused hugepage files)
1278 : : * 3. check if current process hugefiles are still in place and are locked
1279 : : * 4. run a primary process with memtest1 prefix in default and legacy
1280 : : * mem mode
1281 : : * 5. check if memtest1 hugefiles are created in case of legacy mem
1282 : : * mode, and deleted in case of default mem mode
1283 : : * 6. run a primary process with memtest2 prefix in default and legacy
1284 : : * mem modes
1285 : : * 7. check that memtest2 hugefiles are present in the hugedir after a
1286 : : * run in legacy mode, and not present at all after run in default
1287 : : * mem mode
1288 : : */
1289 : : char prefix[PATH_MAX];
1290 : :
1291 : : if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
1292 : : printf("Error (line %d) - unable to get current prefix!\n", __LINE__);
1293 : : return -1;
1294 : : }
1295 : :
1296 : : /* this should fail unless the test itself is run with "memtest" prefix */
1297 : 1 : const char *argv0[] = {prgname, mp_flag, eal_debug_logs, "-m",
1298 : : DEFAULT_MEM_SIZE, "--file-prefix=" memtest };
1299 : :
1300 : : /* primary process with memtest1 and default mem mode */
1301 : 1 : const char *argv1[] = {prgname, eal_debug_logs, no_pci, "-m",
1302 : : DEFAULT_MEM_SIZE, "--file-prefix=" memtest1 };
1303 : :
1304 : : /* primary process with memtest1 and legacy mem mode */
1305 : 1 : const char *argv2[] = {prgname, eal_debug_logs, no_pci, "-m",
1306 : : DEFAULT_MEM_SIZE, "--file-prefix=" memtest1,
1307 : : "--legacy-mem" };
1308 : :
1309 : : /* primary process with memtest2 and legacy mem mode */
1310 : 1 : const char *argv3[] = {prgname, eal_debug_logs, no_pci, "-m",
1311 : : DEFAULT_MEM_SIZE, "--file-prefix=" memtest2,
1312 : : "--legacy-mem" };
1313 : :
1314 : : /* primary process with memtest2 and default mem mode */
1315 : 1 : const char *argv4[] = {prgname, eal_debug_logs, no_pci, "-m",
1316 : : DEFAULT_MEM_SIZE, "--file-prefix=" memtest2 };
1317 : :
1318 : : /* primary process with --in-memory mode */
1319 : 1 : const char * const argv5[] = {prgname, eal_debug_logs, no_pci, "-m",
1320 : : DEFAULT_MEM_SIZE, "--in-memory" };
1321 : :
1322 : : /* primary process with memtest1 and --in-memory mode */
1323 : 1 : const char * const argv6[] = {prgname, eal_debug_logs, no_pci, "-m",
1324 : : DEFAULT_MEM_SIZE, "--in-memory",
1325 : : "--file-prefix=" memtest1 };
1326 : :
1327 : : /* primary process with parent file-prefix and --in-memory mode */
1328 : 1 : const char * const argv7[] = {prgname, eal_debug_logs, no_pci, "-m",
1329 : : DEFAULT_MEM_SIZE, "--in-memory", "--file-prefix", prefix };
1330 : :
1331 : : /* primary process with memtest1 and --single-file-segments mode */
1332 : 1 : const char * const argv8[] = {prgname, eal_debug_logs, no_pci, "-m",
1333 : : DEFAULT_MEM_SIZE, "--single-file-segments",
1334 : : "--file-prefix=" memtest1 };
1335 : :
1336 : : /* primary process with memtest1 and --huge-unlink=never mode */
1337 : 1 : const char * const argv9[] = {prgname, eal_debug_logs, no_pci, "-m",
1338 : : DEFAULT_MEM_SIZE, "--huge-unlink=never",
1339 : : "--file-prefix=" memtest1 };
1340 : :
1341 : : /* check if files for current prefix are present */
1342 [ - + ]: 1 : if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1343 : : printf("Error (line %d) - hugepage files for %s were not created!\n",
1344 : : __LINE__, prefix);
1345 : 0 : return -1;
1346 : : }
1347 : :
1348 : : /* checks if files for current prefix are locked */
1349 [ - + ]: 1 : if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1350 : : printf("Error (line %d) - hugepages for current process aren't locked!\n",
1351 : : __LINE__);
1352 : 0 : return -1;
1353 : : }
1354 : :
1355 : : /* check if files for secondary process are present */
1356 [ - + ]: 1 : if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
1357 : : /* check if they are not locked */
1358 [ # # ]: 0 : if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
1359 : : printf("Error (line %d) - hugepages for current process are locked!\n",
1360 : : __LINE__);
1361 : 0 : return -1;
1362 : : }
1363 : : /* they aren't locked, delete them */
1364 : : else {
1365 [ # # ]: 0 : if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
1366 : : printf("Error (line %d) - deleting hugepages failed!\n",
1367 : : __LINE__);
1368 : 0 : return -1;
1369 : : }
1370 : : }
1371 : : }
1372 : :
1373 [ - + ]: 1 : if (launch_proc(argv0) == 0) {
1374 : : printf("Error (line %d) - secondary process ran ok without primary process\n",
1375 : : __LINE__);
1376 : 0 : return -1;
1377 : : }
1378 : :
1379 : : /* check if files for current prefix are present */
1380 [ - + ]: 1 : if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1381 : : printf("Error (line %d) - hugepage files for %s were not created!\n",
1382 : : __LINE__, prefix);
1383 : 0 : return -1;
1384 : : }
1385 : :
1386 : : /* checks if files for current prefix are locked */
1387 [ - + ]: 1 : if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1388 : : printf("Error (line %d) - hugepages for current process aren't locked!\n",
1389 : : __LINE__);
1390 : 0 : return -1;
1391 : : }
1392 : :
1393 : : /* we're running this process in default memory mode, which means it
1394 : : * should clean up after itself on exit and leave no hugepages behind.
1395 : : */
1396 [ - + ]: 1 : if (launch_proc(argv1) != 0) {
1397 : : printf("Error (line %d) - failed to run with --file-prefix=%s\n",
1398 : : __LINE__, memtest1);
1399 : 0 : return -1;
1400 : : }
1401 : :
1402 : : /* check if memtest1_map0 is present */
1403 [ - + ]: 1 : if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1404 : : printf("Error (line %d) - hugepage files for %s were not deleted!\n",
1405 : : __LINE__, memtest1);
1406 : 0 : return -1;
1407 : : }
1408 : :
1409 : : /* now, we're running a process under the same prefix, but with legacy
1410 : : * mem mode - this should leave behind hugepage files.
1411 : : */
1412 [ - + ]: 1 : if (launch_proc(argv2) != 0) {
1413 : : printf("Error (line %d) - failed to run with --file-prefix=%s\n",
1414 : : __LINE__, memtest1);
1415 : 0 : return -1;
1416 : : }
1417 : :
1418 : : /* check if memtest1_map0 is present */
1419 [ - + ]: 1 : if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
1420 : : printf("Error (line %d) - hugepage files for %s were not created!\n",
1421 : : __LINE__, memtest1);
1422 : 0 : return -1;
1423 : : }
1424 : :
1425 [ - + ]: 1 : if (launch_proc(argv3) != 0) {
1426 : : printf("Error (line %d) - failed to run with --file-prefix=%s\n",
1427 : : __LINE__, memtest2);
1428 : 0 : return -1;
1429 : : }
1430 : :
1431 : : /* check if hugefiles for memtest2 are present */
1432 [ - + ]: 1 : if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
1433 : : printf("Error (line %d) - hugepage files for %s were not created!\n",
1434 : : __LINE__, memtest2);
1435 : 0 : return -1;
1436 : : }
1437 : :
1438 : : /* check if hugefiles for memtest1 are present */
1439 [ - + ]: 1 : if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1440 : : printf("Error (line %d) - hugepage files for %s were not deleted!\n",
1441 : : __LINE__, memtest1);
1442 : 0 : return -1;
1443 : : }
1444 : :
1445 : : /* this process will run in default mem mode, so it should not leave any
1446 : : * hugepage files behind.
1447 : : */
1448 [ - + ]: 1 : if (launch_proc(argv4) != 0) {
1449 : : printf("Error (line %d) - failed to run with --file-prefix=%s\n",
1450 : : __LINE__, memtest2);
1451 : 0 : return -1;
1452 : : }
1453 : :
1454 : : /* check if hugefiles for memtest2 are present */
1455 [ - + ]: 1 : if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 0) {
1456 : : printf("Error (line %d) - hugepage files for %s were not deleted!\n",
1457 : : __LINE__, memtest2);
1458 : 0 : return -1;
1459 : : }
1460 : :
1461 : : /* check if hugefiles for memtest1 are present */
1462 [ - + ]: 1 : if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1463 : : printf("Error (line %d) - hugepage files for %s were not deleted!\n",
1464 : : __LINE__, memtest1);
1465 : 0 : return -1;
1466 : : }
1467 : :
1468 : : /* this process will run in --in-memory mode, so it should not leave any
1469 : : * hugepage files behind.
1470 : : */
1471 : :
1472 : : /* test case to check eal-options with --in-memory mode */
1473 [ - + ]: 1 : if (launch_proc(argv5) != 0) {
1474 : : printf("Error (line %d) - failed to run with --in-memory mode\n",
1475 : : __LINE__);
1476 : 0 : return -1;
1477 : : }
1478 : :
1479 : : /*test case to check eal-options with --in-memory mode with
1480 : : * custom file-prefix.
1481 : : */
1482 [ - + ]: 1 : if (launch_proc(argv6) != 0) {
1483 : : printf("Error (line %d) - failed to run with --in-memory mode\n", __LINE__);
1484 : 0 : return -1;
1485 : : }
1486 : :
1487 : : /* check if hugefiles for memtest1 are present */
1488 [ - + ]: 1 : if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1489 : : printf("Error (line %d) - hugepage files for %s were created and not deleted!\n",
1490 : : __LINE__, memtest1);
1491 : 0 : return -1;
1492 : : }
1493 : :
1494 : : /* test case to check eal-options with --in-memory mode with
1495 : : * parent file-prefix.
1496 : : */
1497 [ - + ]: 1 : if (launch_proc(argv7) != 0) {
1498 : : printf("Error (line %d) - failed to run with --file-prefix=%s\n", __LINE__, prefix);
1499 : 0 : return -1;
1500 : : }
1501 : :
1502 : : /* this process will run in --single-file-segments mode,
1503 : : * so it should not leave any hugepage files behind.
1504 : : */
1505 [ - + ]: 1 : if (launch_proc(argv8) != 0) {
1506 : : printf("Error (line %d) - failed to run with --single-file-segments mode\n",
1507 : : __LINE__);
1508 : 0 : return -1;
1509 : : }
1510 : :
1511 : : /* check if hugefiles for memtest1 are present */
1512 [ - + ]: 1 : if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1513 : : printf("Error (line %d) - hugepage files for %s were not deleted!\n",
1514 : : __LINE__, memtest1);
1515 : 0 : return -1;
1516 : : }
1517 : :
1518 : : /* this process will run with --huge-unlink,
1519 : : * so it should not remove hugepage files when it exits
1520 : : */
1521 [ - + ]: 1 : if (launch_proc(argv9) != 0) {
1522 : : printf("Error (line %d) - failed to run with --huge-unlink=never\n", __LINE__);
1523 : 0 : return -1;
1524 : : }
1525 : :
1526 : : /* check if hugefiles for memtest1 are present */
1527 [ - + ]: 1 : if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) == 0) {
1528 : : printf("Error (line %d) - hugepage files for %s were deleted!\n",
1529 : : __LINE__, memtest1);
1530 : 0 : return -1;
1531 : : }
1532 [ - + ]: 1 : if (process_hugefiles(memtest1, HUGEPAGE_DELETE) != 1) {
1533 : : printf("Error (line %d) - deleting hugepages failed!\n", __LINE__);
1534 : 0 : return -1;
1535 : : }
1536 : :
1537 : : return 0;
1538 : : }
1539 : : #endif
1540 : :
1541 : : /* This function writes in passed buf pointer a valid --socket-mem= option
1542 : : * for num_sockets then concatenates the provided suffix string.
1543 : : *
1544 : : * Example for num_sockets 4, mem "2", suffix "plop"
1545 : : * --socket-mem=2,2,2,2plop
1546 : : */
1547 : : static void
1548 [ + - ]: 7 : populate_socket_mem_param(int num_sockets, const char *mem,
1549 : : const char *suffix, char *buf, size_t buf_size)
1550 : : {
1551 : : unsigned int offset = 0;
1552 : : int written;
1553 : : int i;
1554 : :
1555 : : written = snprintf(&buf[offset], buf_size - offset, "--socket-mem=");
1556 [ + - + - ]: 7 : if (written < 0 || written + offset >= buf_size)
1557 : : return;
1558 : : offset += written;
1559 : :
1560 [ + + ]: 12 : for (i = 0; i < num_sockets - 1; i++) {
1561 [ + - ]: 5 : written = snprintf(&buf[offset], buf_size - offset,
1562 : : "%s,", mem);
1563 [ + - + - ]: 5 : if (written < 0 || written + offset >= buf_size)
1564 : : return;
1565 : : offset += written;
1566 : : }
1567 : :
1568 : 7 : written = snprintf(&buf[offset], buf_size - offset, "%s%s", mem,
1569 : : suffix);
1570 : : if (written < 0 || written + offset >= buf_size)
1571 : 7 : return;
1572 : : offset += written;
1573 : : }
1574 : :
1575 : : /*
1576 : : * Tests for correct handling of --pagesz-mem flag
1577 : : */
1578 : : static int
1579 : 1 : test_pagesz_mem_flags(void)
1580 : : {
1581 : : #ifdef RTE_EXEC_ENV_FREEBSD
1582 : : /* FreeBSD does not support --pagesz-mem */
1583 : : return 0;
1584 : : #else
1585 : : const char *in_memory = "--in-memory";
1586 : :
1587 : : /* invalid: no value */
1588 : 1 : const char * const argv0[] = {prgname, eal_debug_logs, no_pci,
1589 : : "--file-prefix=" memtest, in_memory, "--pagesz-mem="};
1590 : :
1591 : : /* invalid: no colon (missing limit) */
1592 : 1 : const char * const argv1[] = {prgname, eal_debug_logs, no_pci,
1593 : : "--file-prefix=" memtest, in_memory, "--pagesz-mem=2M"};
1594 : :
1595 : : /* invalid: colon present but limit is empty */
1596 : 1 : const char * const argv2[] = {prgname, eal_debug_logs, no_pci,
1597 : : "--file-prefix=" memtest, in_memory, "--pagesz-mem=2M:"};
1598 : :
1599 : : /* invalid: limit not aligned to page size (3M is not a multiple of 2M) */
1600 : 1 : const char * const argv3[] = {prgname, eal_debug_logs, no_pci,
1601 : : "--file-prefix=" memtest, in_memory, "--pagesz-mem=2M:3M"};
1602 : :
1603 : : /* invalid: garbage value */
1604 : 1 : const char * const argv4[] = {prgname, eal_debug_logs, no_pci,
1605 : : "--file-prefix=" memtest, in_memory, "--pagesz-mem=garbage"};
1606 : :
1607 : : /* invalid: garbage value */
1608 : 1 : const char * const argv5[] = {prgname, eal_debug_logs, no_pci,
1609 : : "--file-prefix=" memtest, in_memory, "--pagesz-mem=2M:garbage"};
1610 : :
1611 : : /* invalid: --pagesz-mem combined with --no-huge */
1612 : 1 : const char * const argv6[] = {prgname, eal_debug_logs, no_pci,
1613 : : "--file-prefix=" memtest, in_memory, no_huge, "--pagesz-mem=2M:2M"};
1614 : :
1615 : : /* valid: single well-formed aligned pair */
1616 : 1 : const char * const argv7[] = {prgname, eal_debug_logs, no_pci,
1617 : : "--file-prefix=" memtest, in_memory, "--pagesz-mem=2M:64M"};
1618 : :
1619 : : /* valid: multiple occurrences */
1620 : 1 : const char * const argv8[] = {prgname, eal_debug_logs, no_pci,
1621 : : "--file-prefix=" memtest, in_memory,
1622 : : "--pagesz-mem=2M:64M", "--pagesz-mem=1K:8K"};
1623 : :
1624 : : /* valid: fake page size set to zero (ignored but syntactically valid) */
1625 : 1 : const char * const argv9[] = {prgname, eal_debug_logs, no_pci,
1626 : : "--file-prefix=" memtest, in_memory, "--pagesz-mem=1K:0"};
1627 : :
1628 : : /* invalid: page size must be a power of two */
1629 : 1 : const char * const argv10[] = {prgname, eal_debug_logs, no_pci,
1630 : : "--file-prefix=" memtest, in_memory, "--pagesz-mem=3M:6M"};
1631 : :
1632 [ - + ]: 1 : if (launch_proc(argv0) == 0) {
1633 : : printf("Error (line %d) - process run ok with empty --pagesz-mem!\n",
1634 : : __LINE__);
1635 : 0 : return -1;
1636 : : }
1637 [ - + ]: 1 : if (launch_proc(argv1) == 0) {
1638 : : printf("Error (line %d) - process run ok with --pagesz-mem missing colon!\n",
1639 : : __LINE__);
1640 : 0 : return -1;
1641 : : }
1642 [ - + ]: 1 : if (launch_proc(argv2) == 0) {
1643 : : printf("Error (line %d) - process run ok with --pagesz-mem missing limit!\n",
1644 : : __LINE__);
1645 : 0 : return -1;
1646 : : }
1647 [ - + ]: 1 : if (launch_proc(argv3) == 0) {
1648 : : printf("Error (line %d) - process run ok with --pagesz-mem unaligned limit!\n",
1649 : : __LINE__);
1650 : 0 : return -1;
1651 : : }
1652 [ - + ]: 1 : if (launch_proc(argv4) == 0) {
1653 : : printf("Error (line %d) - process run ok with --pagesz-mem garbage value!\n",
1654 : : __LINE__);
1655 : 0 : return -1;
1656 : : }
1657 [ - + ]: 1 : if (launch_proc(argv5) == 0) {
1658 : : printf("Error (line %d) - process run ok with --pagesz-mem garbage value!\n",
1659 : : __LINE__);
1660 : 0 : return -1;
1661 : : }
1662 [ - + ]: 1 : if (launch_proc(argv6) == 0) {
1663 : : printf("Error (line %d) - process run ok with --pagesz-mem and --no-huge!\n",
1664 : : __LINE__);
1665 : 0 : return -1;
1666 : : }
1667 [ - + ]: 1 : if (launch_proc(argv7) != 0) {
1668 : : printf("Error (line %d) - process failed with valid --pagesz-mem!\n",
1669 : : __LINE__);
1670 : 0 : return -1;
1671 : : }
1672 [ - + ]: 1 : if (launch_proc(argv8) != 0) {
1673 : : printf("Error (line %d) - process failed with multiple valid --pagesz-mem!\n",
1674 : : __LINE__);
1675 : 0 : return -1;
1676 : : }
1677 [ - + ]: 1 : if (launch_proc(argv9) != 0) {
1678 : : printf("Error (line %d) - process failed with --pagesz-mem zero limit!\n",
1679 : : __LINE__);
1680 : 0 : return -1;
1681 : : }
1682 [ - + ]: 1 : if (launch_proc(argv10) == 0) {
1683 : : printf("Error (line %d) - process run ok with non-power-of-two pagesz!\n",
1684 : : __LINE__);
1685 : 0 : return -1;
1686 : : }
1687 : :
1688 : : return 0;
1689 : : #endif /* !RTE_EXEC_ENV_FREEBSD */
1690 : : }
1691 : :
1692 : : /*
1693 : : * Tests for correct handling of -m and --socket-mem flags
1694 : : */
1695 : : static int
1696 : 1 : test_memory_flags(void)
1697 : : {
1698 : 1 : const char *prefix = file_prefix_arg();
1699 [ - + ]: 1 : if (prefix == NULL) {
1700 : : printf("Error (line %d) - unable to get current prefix!\n", __LINE__);
1701 : 0 : return -1;
1702 : : }
1703 : :
1704 : : /* valid -m flag and mp flag */
1705 : 1 : const char *argv0[] = {prgname, prefix, mp_flag, eal_debug_logs,
1706 : : "-m", DEFAULT_MEM_SIZE};
1707 : :
1708 : : /* valid -m flag */
1709 : 1 : const char *argv1[] = {prgname, eal_debug_logs, no_pci,
1710 : : "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE};
1711 : :
1712 : : /* valid (zero) --socket-mem flag */
1713 : : char arg2_socket_mem[SOCKET_MEM_STRLEN];
1714 : 1 : const char *argv2[] = {prgname, eal_debug_logs, no_pci,
1715 : : "--file-prefix=" memtest, arg2_socket_mem};
1716 : :
1717 : : /* invalid (incomplete) --socket-mem flag */
1718 : : char arg3_socket_mem[SOCKET_MEM_STRLEN];
1719 : 1 : const char *argv3[] = {prgname, eal_debug_logs, no_pci,
1720 : : "--file-prefix=" memtest, arg3_socket_mem};
1721 : :
1722 : : /* invalid (mixed with invalid data) --socket-mem flag */
1723 : : char arg4_socket_mem[SOCKET_MEM_STRLEN];
1724 : 1 : const char *argv4[] = {prgname, eal_debug_logs, no_pci,
1725 : : "--file-prefix=" memtest, arg4_socket_mem};
1726 : :
1727 : : /* invalid (with numeric value as last character) --socket-mem flag */
1728 : : char arg5_socket_mem[SOCKET_MEM_STRLEN];
1729 : 1 : const char *argv5[] = {prgname, eal_debug_logs, no_pci,
1730 : : "--file-prefix=" memtest, arg5_socket_mem};
1731 : :
1732 : : /* invalid (with empty socket) --socket-mem flag */
1733 : : char arg6_socket_mem[SOCKET_MEM_STRLEN];
1734 : 1 : const char *argv6[] = {prgname, eal_debug_logs, no_pci,
1735 : : "--file-prefix=" memtest, arg6_socket_mem};
1736 : :
1737 : : /* invalid (null) --socket-mem flag */
1738 : 1 : const char *argv7[] = {prgname, eal_debug_logs, no_pci,
1739 : : "--file-prefix=" memtest, "--socket-mem="};
1740 : :
1741 : : /* valid --socket-mem specified together with -m flag */
1742 : : char arg8_socket_mem[SOCKET_MEM_STRLEN];
1743 : 1 : const char *argv8[] = {prgname, eal_debug_logs, no_pci,
1744 : : "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE,
1745 : : arg8_socket_mem};
1746 : :
1747 : : #ifdef RTE_EXEC_ENV_FREEBSD
1748 : : int num_sockets = 1;
1749 : : #else
1750 : 1 : int num_sockets = RTE_MIN(get_number_of_sockets(),
1751 : : RTE_MAX_NUMA_NODES);
1752 : : #endif
1753 : :
1754 [ - + ]: 1 : if (num_sockets <= 0) {
1755 : : printf("Error (line %d) - cannot get number of sockets!\n", __LINE__);
1756 : 0 : return -1;
1757 : : }
1758 : :
1759 : : /* invalid --socket-mem flag (with extra socket) */
1760 : : char invalid_socket_mem[SOCKET_MEM_STRLEN];
1761 : 1 : const char *argv9[] = {prgname, eal_debug_logs, no_pci,
1762 : : "--file-prefix=" memtest, invalid_socket_mem};
1763 : :
1764 : : /* valid --socket-mem flag */
1765 : : char valid_socket_mem[SOCKET_MEM_STRLEN];
1766 : 1 : const char *argv10[] = {prgname, eal_debug_logs, no_pci,
1767 : : "--file-prefix=" memtest, valid_socket_mem};
1768 : :
1769 [ - + ]: 1 : if (launch_proc(argv0) != 0) {
1770 : : printf("Error (line %d) - secondary process failed with valid -m flag !\n",
1771 : : __LINE__);
1772 : 0 : return -1;
1773 : : }
1774 : :
1775 : : #ifdef RTE_EXEC_ENV_FREEBSD
1776 : : /* no other tests are applicable to BSD */
1777 : : return 0;
1778 : : #endif
1779 : :
1780 [ - + ]: 1 : if (launch_proc(argv1) != 0) {
1781 : : printf("Error (line %d) - process failed with valid -m flag!\n", __LINE__);
1782 : 0 : return -1;
1783 : : }
1784 : :
1785 : 1 : populate_socket_mem_param(num_sockets, "0", "",
1786 : : arg2_socket_mem, sizeof(arg2_socket_mem));
1787 [ - + ]: 1 : if (launch_proc(argv2) != 0) {
1788 : : printf("Error (line %d) - process failed with valid (zero) --socket-mem!\n",
1789 : : __LINE__);
1790 : 0 : return -1;
1791 : : }
1792 : :
1793 [ + - ]: 1 : if (num_sockets > 1) {
1794 : 1 : populate_socket_mem_param(num_sockets - 1, "2", ",",
1795 : : arg3_socket_mem, sizeof(arg3_socket_mem));
1796 [ - + ]: 1 : if (launch_proc(argv3) == 0) {
1797 : : printf("Error (line %d) - process run ok with invalid (incomplete) --socket-mem!\n",
1798 : : __LINE__);
1799 : 0 : return -1;
1800 : : }
1801 : :
1802 : 1 : populate_socket_mem_param(num_sockets - 1, "2", ",Fred",
1803 : : arg4_socket_mem, sizeof(arg4_socket_mem));
1804 [ - + ]: 1 : if (launch_proc(argv4) == 0) {
1805 : : printf("Error (line %d) - process run ok with invalid (mixed with invalid input) --socket-mem!\n",
1806 : : __LINE__);
1807 : 0 : return -1;
1808 : : }
1809 : :
1810 : 1 : populate_socket_mem_param(num_sockets - 1, "2", ",Fred0",
1811 : : arg5_socket_mem, sizeof(arg5_socket_mem));
1812 [ - + ]: 1 : if (launch_proc(argv5) == 0) {
1813 : : printf("Error (line %d) - process run ok with invalid (mixed with invalid input with a numeric value as last character) --socket-mem!\n",
1814 : : __LINE__);
1815 : 0 : return -1;
1816 : : }
1817 : : }
1818 : :
1819 [ - + ]: 1 : if (num_sockets > 2) {
1820 : 0 : populate_socket_mem_param(num_sockets - 2, "2", ",,2",
1821 : : arg6_socket_mem, sizeof(arg6_socket_mem));
1822 [ # # ]: 0 : if (launch_proc(argv6) == 0) {
1823 : : printf("Error (line %d) - process run ok with invalid (with empty socket) --socket-mem!\n",
1824 : : __LINE__);
1825 : 0 : return -1;
1826 : : }
1827 : : }
1828 : :
1829 [ - + ]: 1 : if (launch_proc(argv7) == 0) {
1830 : : printf("Error (line %d) - process run ok with invalid (null) --socket-mem!\n",
1831 : : __LINE__);
1832 : 0 : return -1;
1833 : : }
1834 : :
1835 : 1 : populate_socket_mem_param(num_sockets, "2", "",
1836 : : arg8_socket_mem, sizeof(arg8_socket_mem));
1837 [ - + ]: 1 : if (launch_proc(argv8) == 0) {
1838 : : printf("Error (line %d) - process run ok with --socket-mem and -m specified!\n",
1839 : : __LINE__);
1840 : 0 : return -1;
1841 : : }
1842 : :
1843 : 1 : populate_socket_mem_param(num_sockets + 1, "2", "",
1844 : : invalid_socket_mem, sizeof(invalid_socket_mem));
1845 [ - + ]: 1 : if (launch_proc(argv9) == 0) {
1846 : : printf("Error (line %d) - process run ok with extra socket in --socket-mem!\n",
1847 : : __LINE__);
1848 : 0 : return -1;
1849 : : }
1850 : :
1851 : 1 : populate_socket_mem_param(num_sockets, "2", "",
1852 : : valid_socket_mem, sizeof(valid_socket_mem));
1853 [ - + ]: 1 : if (launch_proc(argv10) != 0) {
1854 : : printf("Error (line %d) - process failed with valid --socket-mem!\n", __LINE__);
1855 : 0 : return -1;
1856 : : }
1857 : :
1858 : : return 0;
1859 : : }
1860 : :
1861 : : #endif /* !RTE_EXEC_ENV_WINDOWS */
1862 : :
1863 : 301 : REGISTER_FAST_TEST(eal_flags_c_opt_autotest, NOHUGE_SKIP, ASAN_SKIP, test_missing_c_flag);
1864 : 301 : REGISTER_FAST_TEST(eal_flags_main_opt_autotest, NOHUGE_SKIP, ASAN_SKIP, test_main_lcore_flag);
1865 : 301 : REGISTER_FAST_TEST(eal_flags_n_opt_autotest, NOHUGE_SKIP, ASAN_SKIP, test_invalid_n_flag);
1866 : 301 : REGISTER_FAST_TEST(eal_flags_hpet_autotest, NOHUGE_SKIP, ASAN_SKIP, test_no_hpet_flag);
1867 : 301 : REGISTER_FAST_TEST(eal_flags_no_huge_autotest, NOHUGE_SKIP, ASAN_SKIP, test_no_huge_flag);
1868 : 301 : REGISTER_FAST_TEST(eal_flags_a_opt_autotest, NOHUGE_SKIP, ASAN_SKIP, test_allow_flag);
1869 : 301 : REGISTER_FAST_TEST(eal_flags_b_opt_autotest, NOHUGE_SKIP, ASAN_SKIP, test_invalid_b_flag);
1870 : 301 : REGISTER_FAST_TEST(eal_flags_vdev_opt_autotest, NOHUGE_SKIP, ASAN_SKIP, test_invalid_vdev_flag);
1871 : 301 : REGISTER_FAST_TEST(eal_flags_r_opt_autotest, NOHUGE_SKIP, ASAN_SKIP, test_invalid_r_flag);
1872 : 301 : REGISTER_FAST_TEST(eal_flags_mem_autotest, NOHUGE_SKIP, ASAN_SKIP, test_memory_flags);
1873 : 301 : REGISTER_FAST_TEST(eal_flags_pagesz_mem_autotest, NOHUGE_SKIP, ASAN_SKIP, test_pagesz_mem_flags);
1874 : 301 : REGISTER_FAST_TEST(eal_flags_file_prefix_autotest, NOHUGE_SKIP, ASAN_SKIP, test_file_prefix);
1875 : 301 : REGISTER_FAST_TEST(eal_flags_misc_autotest, NOHUGE_SKIP, ASAN_SKIP, test_misc_flags);
|