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