test/eal: set memory channel config only in dedicated test
[dpdk.git] / app / test / test_eal_flags.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdio.h>
7
8 #include "test.h"
9
10 #include <string.h>
11 #include <stdarg.h>
12 #include <libgen.h>
13 #include <stdlib.h>
14 #include <errno.h>
15 #include <unistd.h>
16 #include <dirent.h>
17 #include <sys/wait.h>
18 #include <sys/file.h>
19 #include <limits.h>
20 #include <fcntl.h>
21
22 #include <rte_per_lcore.h>
23 #include <rte_debug.h>
24 #include <rte_string_fns.h>
25
26 #include "process.h"
27
28 #define DEFAULT_MEM_SIZE "18"
29 #define mp_flag "--proc-type=secondary"
30 #define no_hpet "--no-hpet"
31 #define no_huge "--no-huge"
32 #define no_shconf "--no-shconf"
33 #define pci_whitelist "--pci-whitelist"
34 #define vdev "--vdev"
35 #define memtest "memtest"
36 #define memtest1 "memtest1"
37 #define memtest2 "memtest2"
38 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 20)
39 #define launch_proc(ARGV) process_dup(ARGV, \
40                 sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
41
42 enum hugepage_action {
43         HUGEPAGE_CHECK_EXISTS = 0,
44         HUGEPAGE_CHECK_LOCKED,
45         HUGEPAGE_DELETE,
46         HUGEPAGE_INVALID
47 };
48
49 /* if string contains a hugepage path */
50 static int
51 get_hugepage_path(char * src, int src_len, char * dst, int dst_len)
52 {
53 #define NUM_TOKENS 4
54         char *tokens[NUM_TOKENS];
55
56         /* if we couldn't properly split the string */
57         if (rte_strsplit(src, src_len, tokens, NUM_TOKENS, ' ') < NUM_TOKENS)
58                 return 0;
59
60         if (strncmp(tokens[2], "hugetlbfs", sizeof("hugetlbfs")) == 0) {
61                 strlcpy(dst, tokens[1], dst_len);
62                 return 1;
63         }
64         return 0;
65 }
66
67 /*
68  * Cycles through hugepage directories and looks for hugepage
69  * files associated with a given prefix. Depending on value of
70  * action, the hugepages are checked if they exist, checked if
71  * they can be locked, or are simply deleted.
72  *
73  * Returns 1 if it finds at least one hugepage matching the action
74  * Returns 0 if no matching hugepages were found
75  * Returns -1 if it encounters an error
76  */
77 static int
78 process_hugefiles(const char * prefix, enum hugepage_action action)
79 {
80         FILE * hugedir_handle = NULL;
81         DIR * hugepage_dir = NULL;
82         struct dirent *dirent = NULL;
83
84         char hugefile_prefix[PATH_MAX] = {0};
85         char hugedir[PATH_MAX] = {0};
86         char line[PATH_MAX] = {0};
87
88         int fd, lck_result, result = 0;
89
90         const int prefix_len = snprintf(hugefile_prefix,
91                         sizeof(hugefile_prefix), "%smap_", prefix);
92         if (prefix_len <= 0 || prefix_len >= (int)sizeof(hugefile_prefix)
93                         || prefix_len >= (int)sizeof(dirent->d_name)) {
94                 printf("Error creating hugefile filename prefix\n");
95                 return -1;
96         }
97
98         /* get hugetlbfs mountpoints from /proc/mounts */
99         hugedir_handle = fopen("/proc/mounts", "r");
100
101         if (hugedir_handle == NULL) {
102                 printf("Error parsing /proc/mounts!\n");
103                 return -1;
104         }
105
106         /* read and parse script output */
107         while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
108
109                 /* check if we have a hugepage filesystem path */
110                 if (!get_hugepage_path(line, sizeof(line), hugedir, sizeof(hugedir)))
111                         continue;
112
113                 /* check if directory exists */
114                 if ((hugepage_dir = opendir(hugedir)) == NULL) {
115                         fclose(hugedir_handle);
116                         printf("Error reading %s: %s\n", hugedir, strerror(errno));
117                         return -1;
118                 }
119
120                 while ((dirent = readdir(hugepage_dir)) != NULL) {
121                         if (memcmp(dirent->d_name, hugefile_prefix, prefix_len) != 0)
122                                 continue;
123
124                         switch (action) {
125                         case HUGEPAGE_CHECK_EXISTS:
126                                 {
127                                         /* file exists, return */
128                                         result = 1;
129                                         goto end;
130                                 }
131                                 break;
132                         case HUGEPAGE_DELETE:
133                                 {
134                                         char file_path[PATH_MAX] = {0};
135
136                                         snprintf(file_path, sizeof(file_path),
137                                                 "%s/%s", hugedir, dirent->d_name);
138
139                                         /* remove file */
140                                         if (remove(file_path) < 0) {
141                                                 printf("Error deleting %s - %s!\n",
142                                                                 dirent->d_name, strerror(errno));
143                                                 closedir(hugepage_dir);
144                                                 result = -1;
145                                                 goto end;
146                                         }
147                                         result = 1;
148                                 }
149                                 break;
150                         case HUGEPAGE_CHECK_LOCKED:
151                                 {
152                                         /* try and lock the file */
153                                         fd = openat(dirfd(hugepage_dir), dirent->d_name, O_RDONLY);
154
155                                         /* this shouldn't happen */
156                                         if (fd == -1) {
157                                                 printf("Error opening %s - %s!\n",
158                                                                 dirent->d_name, strerror(errno));
159                                                 closedir(hugepage_dir);
160                                                 result = -1;
161                                                 goto end;
162                                         }
163
164                                         /* non-blocking lock */
165                                         lck_result = flock(fd, LOCK_EX | LOCK_NB);
166
167                                         /* if lock succeeds, there's something wrong */
168                                         if (lck_result != -1) {
169                                                 result = 0;
170
171                                                 /* unlock the resulting lock */
172                                                 flock(fd, LOCK_UN);
173                                                 close(fd);
174                                                 closedir(hugepage_dir);
175                                                 goto end;
176                                         }
177                                         result = 1;
178                                         close(fd);
179                                 }
180                                 break;
181                                 /* shouldn't happen */
182                         default:
183                                 goto end;
184                         } /* switch */
185
186                 } /* read hugepage directory */
187                 closedir(hugepage_dir);
188         } /* read /proc/mounts */
189 end:
190         fclose(hugedir_handle);
191         return result;
192 }
193
194 #ifdef RTE_EXEC_ENV_LINUX
195 /*
196  * count the number of "node*" files in /sys/devices/system/node/
197  */
198 static int
199 get_number_of_sockets(void)
200 {
201         struct dirent *dirent = NULL;
202         const char * nodedir = "/sys/devices/system/node/";
203         DIR * dir = NULL;
204         int result = 0;
205
206         /* check if directory exists */
207         if ((dir = opendir(nodedir)) == NULL) {
208                 /* if errno==ENOENT this means we don't have NUMA support */
209                 if (errno == ENOENT) {
210                         printf("No NUMA nodes detected: assuming 1 available socket\n");
211                         return 1;
212                 }
213                 printf("Error opening %s: %s\n", nodedir, strerror(errno));
214                 return -1;
215         }
216
217         while ((dirent = readdir(dir)) != NULL)
218                 if (strncmp(dirent->d_name, "node", sizeof("node") - 1) == 0)
219                         result++;
220
221         closedir(dir);
222         return result;
223 }
224 #endif
225
226 /*
227  * Test that the app doesn't run with invalid whitelist option.
228  * Final tests ensures it does run with valid options as sanity check (one
229  * test for with Domain+BDF, second for just with BDF)
230  */
231 static int
232 test_whitelist_flag(void)
233 {
234         unsigned i;
235 #ifdef RTE_EXEC_ENV_FREEBSD
236         /* BSD target doesn't support prefixes at this point */
237         const char * prefix = "";
238 #else
239         char prefix[PATH_MAX], tmp[PATH_MAX];
240         if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
241                 printf("Error - unable to get current prefix!\n");
242                 return -1;
243         }
244         snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
245 #endif
246
247         const char *wlinval[][11] = {
248                 {prgname, prefix, mp_flag, "-c", "1",
249                                 pci_whitelist, "error", "", ""},
250                 {prgname, prefix, mp_flag, "-c", "1",
251                                 pci_whitelist, "0:0:0", "", ""},
252                 {prgname, prefix, mp_flag, "-c", "1",
253                                 pci_whitelist, "0:error:0.1", "", ""},
254                 {prgname, prefix, mp_flag, "-c", "1",
255                                 pci_whitelist, "0:0:0.1error", "", ""},
256                 {prgname, prefix, mp_flag, "-c", "1",
257                                 pci_whitelist, "error0:0:0.1", "", ""},
258                 {prgname, prefix, mp_flag, "-c", "1",
259                                 pci_whitelist, "0:0:0.1.2", "", ""},
260         };
261         /* Test with valid whitelist option */
262         const char *wlval1[] = {prgname, prefix, mp_flag, "-c", "1",
263                         pci_whitelist, "00FF:09:0B.3"};
264         const char *wlval2[] = {prgname, prefix, mp_flag, "-c", "1",
265                         pci_whitelist, "09:0B.3", pci_whitelist, "0a:0b.1"};
266         const char *wlval3[] = {prgname, prefix, mp_flag, "-c", "1",
267                         pci_whitelist, "09:0B.3,type=test",
268                         pci_whitelist, "08:00.1,type=normal",
269         };
270
271         for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
272                 if (launch_proc(wlinval[i]) == 0) {
273                         printf("Error - process did run ok with invalid "
274                             "whitelist parameter\n");
275                         return -1;
276                 }
277         }
278         if (launch_proc(wlval1) != 0 ) {
279                 printf("Error - process did not run ok with valid whitelist\n");
280                 return -1;
281         }
282         if (launch_proc(wlval2) != 0 ) {
283                 printf("Error - process did not run ok with valid whitelist value set\n");
284                 return -1;
285         }
286         if (launch_proc(wlval3) != 0 ) {
287                 printf("Error - process did not run ok with valid whitelist + args\n");
288                 return -1;
289         }
290
291         return 0;
292 }
293
294 /*
295  * Test that the app doesn't run with invalid blacklist option.
296  * Final test ensures it does run with valid options as sanity check
297  */
298 static int
299 test_invalid_b_flag(void)
300 {
301 #ifdef RTE_EXEC_ENV_FREEBSD
302         /* BSD target doesn't support prefixes at this point */
303         const char * prefix = "";
304 #else
305         char prefix[PATH_MAX], tmp[PATH_MAX];
306         if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
307                 printf("Error - unable to get current prefix!\n");
308                 return -1;
309         }
310         snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
311 #endif
312
313         const char *blinval[][9] = {
314                 {prgname, prefix, mp_flag, "-c", "1", "-b", "error"},
315                 {prgname, prefix, mp_flag, "-c", "1", "-b", "0:0:0"},
316                 {prgname, prefix, mp_flag, "-c", "1", "-b", "0:error:0.1"},
317                 {prgname, prefix, mp_flag, "-c", "1", "-b", "0:0:0.1error"},
318                 {prgname, prefix, mp_flag, "-c", "1", "-b", "error0:0:0.1"},
319                 {prgname, prefix, mp_flag, "-c", "1", "-b", "0:0:0.1.2"},
320         };
321         /* Test with valid blacklist option */
322         const char *blval[] = {prgname, prefix, mp_flag, "-c", "1",
323                                "-b", "FF:09:0B.3"};
324
325         int i;
326
327         for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
328                 if (launch_proc(blinval[i]) == 0) {
329                         printf("Error - process did run ok with invalid "
330                             "blacklist parameter\n");
331                         return -1;
332                 }
333         }
334         if (launch_proc(blval) != 0) {
335                 printf("Error - process did not run ok with valid blacklist value\n");
336                 return -1;
337         }
338         return 0;
339 }
340
341 /*
342  *  Test that the app doesn't run with invalid vdev option.
343  *  Final test ensures it does run with valid options as sanity check
344  */
345 #ifdef RTE_LIBRTE_PMD_RING
346 static int
347 test_invalid_vdev_flag(void)
348 {
349 #ifdef RTE_EXEC_ENV_FREEBSD
350         /* BSD target doesn't support prefixes at this point, and we also need to
351          * run another primary process here */
352         const char * prefix = no_shconf;
353 #else
354         const char * prefix = "--file-prefix=vdev";
355 #endif
356
357         /* Test with invalid vdev option */
358         const char *vdevinval[] = {prgname, prefix, no_huge,
359                                 "-c", "1", vdev, "eth_dummy"};
360
361         /* Test with valid vdev option */
362         const char *vdevval1[] = {prgname, prefix, no_huge,
363         "-c", "1", vdev, "net_ring0"};
364
365         const char *vdevval2[] = {prgname, prefix, no_huge,
366         "-c", "1", vdev, "net_ring0,args=test"};
367
368         const char *vdevval3[] = {prgname, prefix, no_huge,
369         "-c", "1", vdev, "net_ring0,nodeaction=r1:0:CREATE"};
370
371         if (launch_proc(vdevinval) == 0) {
372                 printf("Error - process did run ok with invalid "
373                         "vdev parameter\n");
374                 return -1;
375         }
376
377         if (launch_proc(vdevval1) != 0) {
378                 printf("Error - process did not run ok with valid vdev value\n");
379                 return -1;
380         }
381
382         if (launch_proc(vdevval2) != 0) {
383                 printf("Error - process did not run ok with valid vdev value,"
384                         "with dummy args\n");
385                 return -1;
386         }
387
388         if (launch_proc(vdevval3) != 0) {
389                 printf("Error - process did not run ok with valid vdev value,"
390                         "with valid args\n");
391                 return -1;
392         }
393         return 0;
394 }
395 #endif
396
397 /*
398  * Test that the app doesn't run with invalid -r option.
399  */
400 static int
401 test_invalid_r_flag(void)
402 {
403 #ifdef RTE_EXEC_ENV_FREEBSD
404         /* BSD target doesn't support prefixes at this point */
405         const char * prefix = "";
406 #else
407         char prefix[PATH_MAX], tmp[PATH_MAX];
408         if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
409                 printf("Error - unable to get current prefix!\n");
410                 return -1;
411         }
412         snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
413 #endif
414
415         const char *rinval[][9] = {
416                         {prgname, prefix, mp_flag, "-c", "1", "-r", "error"},
417                         {prgname, prefix, mp_flag, "-c", "1", "-r", "0"},
418                         {prgname, prefix, mp_flag, "-c", "1", "-r", "-1"},
419                         {prgname, prefix, mp_flag, "-c", "1", "-r", "17"},
420         };
421         /* Test with valid blacklist option */
422         const char *rval[] = {prgname, prefix, mp_flag, "-c", "1", "-r", "16"};
423
424         int i;
425
426         for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
427                 if (launch_proc(rinval[i]) == 0) {
428                         printf("Error - process did run ok with invalid "
429                             "-r (rank) parameter\n");
430                         return -1;
431                 }
432         }
433         if (launch_proc(rval) != 0) {
434                 printf("Error - process did not run ok with valid -r (rank) value\n");
435                 return -1;
436         }
437         return 0;
438 }
439
440 /*
441  * Test that the app doesn't run without the coremask/corelist flags. In all cases
442  * should give an error and fail to run
443  */
444 static int
445 test_missing_c_flag(void)
446 {
447 #ifdef RTE_EXEC_ENV_FREEBSD
448         /* BSD target doesn't support prefixes at this point */
449         const char * prefix = "";
450 #else
451         char prefix[PATH_MAX], tmp[PATH_MAX];
452         if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
453                 printf("Error - unable to get current prefix!\n");
454                 return -1;
455         }
456         snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
457 #endif
458
459         /* -c flag but no coremask value */
460         const char *argv1[] = { prgname, prefix, mp_flag, "-c"};
461         /* No -c, -l or --lcores flag at all */
462         const char *argv2[] = { prgname, prefix, mp_flag};
463         /* bad coremask value */
464         const char *argv3[] = { prgname, prefix, mp_flag,
465                                 "-c", "error" };
466         /* sanity check of tests - valid coremask value */
467         const char *argv4[] = { prgname, prefix, mp_flag,
468                                 "-c", "1" };
469         /* -l flag but no corelist value */
470         const char *argv5[] = { prgname, prefix, mp_flag,
471                                 "-l"};
472         const char *argv6[] = { prgname, prefix, mp_flag,
473                                 "-l", " " };
474         /* bad corelist values */
475         const char *argv7[] = { prgname, prefix, mp_flag,
476                                 "-l", "error" };
477         const char *argv8[] = { prgname, prefix, mp_flag,
478                                 "-l", "1-" };
479         const char *argv9[] = { prgname, prefix, mp_flag,
480                                 "-l", "1," };
481         const char *argv10[] = { prgname, prefix, mp_flag,
482                                  "-l", "1#2" };
483         /* core number is negative value */
484         const char * const argv11[] = { prgname, prefix, mp_flag,
485                                 "-l", "-5" };
486         const char * const argv12[] = { prgname, prefix, mp_flag,
487                                 "-l", "-5-7" };
488         /* core number is maximum value */
489         const char * const argv13[] = { prgname, prefix, mp_flag,
490                                 "-l", RTE_STR(RTE_MAX_LCORE) };
491         const char * const argv14[] = { prgname, prefix, mp_flag,
492                                 "-l", "1-"RTE_STR(RTE_MAX_LCORE) };
493         /* sanity check test - valid corelist value */
494         const char * const argv15[] = { prgname, prefix, mp_flag,
495                                  "-l", "1-2,3" };
496
497         /* --lcores flag but no lcores value */
498         const char * const argv16[] = { prgname, prefix, mp_flag,
499                                  "--lcores" };
500         const char * const argv17[] = { prgname, prefix, mp_flag,
501                                  "--lcores", " " };
502         /* bad lcores value */
503         const char * const argv18[] = { prgname, prefix, mp_flag,
504                                  "--lcores", "1-3-5" };
505         const char * const argv19[] = { prgname, prefix, mp_flag,
506                                  "--lcores", "0-1,,2" };
507         const char * const argv20[] = { prgname, prefix, mp_flag,
508                                  "--lcores", "0-,1" };
509         const char * const argv21[] = { prgname, prefix, mp_flag,
510                                  "--lcores", "(0-,2-4)" };
511         const char * const argv22[] = { prgname, prefix, mp_flag,
512                                  "--lcores", "(-1,2)" };
513         const char * const argv23[] = { prgname, prefix, mp_flag,
514                                  "--lcores", "(2-4)@(2-4-6)" };
515         const char * const argv24[] = { prgname, prefix, mp_flag,
516                                  "--lcores", "(a,2)" };
517         const char * const argv25[] = { prgname, prefix, mp_flag,
518                                  "--lcores", "1-3@(1,3)" };
519         const char * const argv26[] = { prgname, prefix, mp_flag,
520                                  "--lcores", "3@((1,3)" };
521         const char * const argv27[] = { prgname, prefix, mp_flag,
522                                  "--lcores", "(4-7)=(1,3)" };
523         const char * const argv28[] = { prgname, prefix, mp_flag,
524                                  "--lcores", "[4-7]@(1,3)" };
525         /* sanity check of tests - valid lcores value */
526         const char * const argv29[] = { prgname, prefix, mp_flag,
527                                  "--lcores",
528                                  "0-1,2@(5-7),(3-5)@(0,2),(0,6),7"};
529
530         if (launch_proc(argv2) != 0) {
531                 printf("Error - "
532                        "process did not run ok when missing -c flag\n");
533                 return -1;
534         }
535
536         if (launch_proc(argv1) == 0
537                         || launch_proc(argv3) == 0) {
538                 printf("Error - "
539                        "process ran without error with invalid -c flag\n");
540                 return -1;
541         }
542         if (launch_proc(argv4) != 0) {
543                 printf("Error - "
544                        "process did not run ok with valid coremask value\n");
545                 return -1;
546         }
547
548         /* start -l test */
549         if (launch_proc(argv5) == 0
550                         || launch_proc(argv6) == 0
551                         || launch_proc(argv7) == 0
552                         || launch_proc(argv8) == 0
553                         || launch_proc(argv9) == 0
554                         || launch_proc(argv10) == 0
555                         || launch_proc(argv11) == 0
556                         || launch_proc(argv12) == 0
557                         || launch_proc(argv13) == 0
558                         || launch_proc(argv14) == 0) {
559                 printf("Error - "
560                        "process ran without error with invalid -l flag\n");
561                 return -1;
562         }
563         if (launch_proc(argv15) != 0) {
564                 printf("Error - "
565                        "process did not run ok with valid corelist value\n");
566                 return -1;
567         }
568
569         /* start --lcores tests */
570         if (launch_proc(argv16) == 0 || launch_proc(argv17) == 0 ||
571             launch_proc(argv18) == 0 || launch_proc(argv19) == 0 ||
572             launch_proc(argv20) == 0 || launch_proc(argv21) == 0 ||
573             launch_proc(argv22) == 0 || launch_proc(argv23) == 0 ||
574             launch_proc(argv24) == 0 || launch_proc(argv25) == 0 ||
575             launch_proc(argv26) == 0 || launch_proc(argv27) == 0 ||
576             launch_proc(argv28) == 0) {
577                 printf("Error - "
578                        "process ran without error with invalid --lcore flag\n");
579                 return -1;
580         }
581
582         if (launch_proc(argv29) != 0) {
583                 printf("Error - "
584                        "process did not run ok with valid corelist value\n");
585                 return -1;
586         }
587
588         return 0;
589 }
590
591 /*
592  * Test --master-lcore option with matching coremask
593  */
594 static int
595 test_master_lcore_flag(void)
596 {
597 #ifdef RTE_EXEC_ENV_FREEBSD
598         /* BSD target doesn't support prefixes at this point */
599         const char *prefix = "";
600 #else
601         char prefix[PATH_MAX], tmp[PATH_MAX];
602         if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
603                 printf("Error - unable to get current prefix!\n");
604                 return -1;
605         }
606         snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
607 #endif
608
609         /* --master-lcore flag but no value */
610         const char *argv1[] = { prgname, prefix, mp_flag,
611                                 "-c", "3", "--master-lcore"};
612         /* --master-lcore flag with invalid value */
613         const char *argv2[] = { prgname, prefix, mp_flag,
614                                 "-c", "3", "--master-lcore", "-1"};
615         const char *argv3[] = { prgname, prefix, mp_flag,
616                                 "-c", "3", "--master-lcore", "X"};
617         /* master lcore not in coremask */
618         const char *argv4[] = { prgname, prefix, mp_flag,
619                                 "-c", "3", "--master-lcore", "2"};
620         /* valid value */
621         const char *argv5[] = { prgname, prefix, mp_flag,
622                                 "-c", "3", "--master-lcore", "1"};
623         /* valid value set before coremask */
624         const char *argv6[] = { prgname, prefix, mp_flag,
625                                 "--master-lcore", "1", "-c", "3"};
626
627         if (launch_proc(argv1) == 0
628                         || launch_proc(argv2) == 0
629                         || launch_proc(argv3) == 0
630                         || launch_proc(argv4) == 0) {
631                 printf("Error - process ran without error with wrong --master-lcore\n");
632                 return -1;
633         }
634         if (launch_proc(argv5) != 0
635                         || launch_proc(argv6) != 0) {
636                 printf("Error - process did not run ok with valid --master-lcore\n");
637                 return -1;
638         }
639         return 0;
640 }
641
642 /*
643  * Test that the app doesn't run with invalid -n flag option.
644  * Final test ensures it does run with valid options as sanity check
645  * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
646  * flags.
647  */
648 static int
649 test_invalid_n_flag(void)
650 {
651 #ifdef RTE_EXEC_ENV_FREEBSD
652         /* BSD target doesn't support prefixes at this point */
653         const char * prefix = "";
654 #else
655         char prefix[PATH_MAX], tmp[PATH_MAX];
656         if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
657                 printf("Error - unable to get current prefix!\n");
658                 return -1;
659         }
660         snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
661 #endif
662
663         /* -n flag but no value */
664         const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"};
665         /* bad numeric value */
666         const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" };
667         /* zero is invalid */
668         const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "0" };
669         /* sanity test - check with good value */
670         const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" };
671         /* sanity test - check with no -n flag */
672         const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"};
673
674         if (launch_proc(argv1) == 0
675                         || launch_proc(argv2) == 0
676                         || launch_proc(argv3) == 0) {
677                 printf("Error - process ran without error when"
678                        "invalid -n flag\n");
679                 return -1;
680         }
681         if (launch_proc(argv4) != 0) {
682                 printf("Error - process did not run ok with valid num-channel value\n");
683                 return -1;
684         }
685         if (launch_proc(argv5) != 0) {
686                 printf("Error - process did not run ok without -n flag\n");
687                 return -1;
688         }
689
690         return 0;
691 }
692
693 /*
694  * Test that the app runs with HPET, and without HPET
695  */
696 static int
697 test_no_hpet_flag(void)
698 {
699         char prefix[PATH_MAX] = "";
700
701 #ifdef RTE_EXEC_ENV_FREEBSD
702         return 0;
703 #else
704         char tmp[PATH_MAX];
705         if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
706                 printf("Error - unable to get current prefix!\n");
707                 return -1;
708         }
709         snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
710 #endif
711
712         /* With --no-hpet */
713         const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1"};
714         /* Without --no-hpet */
715         const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1"};
716
717         if (launch_proc(argv1) != 0) {
718                 printf("Error - process did not run ok with --no-hpet flag\n");
719                 return -1;
720         }
721         if (launch_proc(argv2) != 0) {
722                 printf("Error - process did not run ok without --no-hpet flag\n");
723                 return -1;
724         }
725         return 0;
726 }
727
728 /*
729  * Test that the app runs with --no-huge and doesn't run when --socket-mem are
730  * specified with --no-huge.
731  */
732 static int
733 test_no_huge_flag(void)
734 {
735 #ifdef RTE_EXEC_ENV_FREEBSD
736         /* BSD target doesn't support prefixes at this point, and we also need to
737          * run another primary process here */
738         const char * prefix = no_shconf;
739 #else
740         const char * prefix = "--file-prefix=nohuge";
741 #endif
742
743         /* With --no-huge */
744         const char *argv1[] = {prgname, prefix, no_huge, "-c", "1"};
745         /* With --no-huge and -m */
746         const char *argv2[] = {prgname, prefix, no_huge, "-c", "1",
747                         "-m", DEFAULT_MEM_SIZE};
748
749         /* With --no-huge and --socket-mem */
750         const char *argv3[] = {prgname, prefix, no_huge, "-c", "1",
751                         "--socket-mem=" DEFAULT_MEM_SIZE};
752         /* With --no-huge, -m and --socket-mem */
753         const char *argv4[] = {prgname, prefix, no_huge, "-c", "1",
754                         "-m", DEFAULT_MEM_SIZE, "--socket-mem=" DEFAULT_MEM_SIZE};
755         if (launch_proc(argv1) != 0) {
756                 printf("Error - process did not run ok with --no-huge flag\n");
757                 return -1;
758         }
759         if (launch_proc(argv2) != 0) {
760                 printf("Error - process did not run ok with --no-huge and -m flags\n");
761                 return -1;
762         }
763 #ifdef RTE_EXEC_ENV_FREEBSD
764         /* BSD target does not support NUMA, hence no --socket-mem tests */
765         return 0;
766 #endif
767
768         if (launch_proc(argv3) == 0) {
769                 printf("Error - process run ok with --no-huge and --socket-mem "
770                                 "flags\n");
771                 return -1;
772         }
773         if (launch_proc(argv4) == 0) {
774                 printf("Error - process run ok with --no-huge, -m and "
775                                 "--socket-mem flags\n");
776                 return -1;
777         }
778         return 0;
779 }
780
781 static int
782 test_misc_flags(void)
783 {
784         char hugepath[PATH_MAX] = {0};
785 #ifdef RTE_EXEC_ENV_FREEBSD
786         /* BSD target doesn't support prefixes at this point */
787         const char * prefix = "";
788         const char * nosh_prefix = "";
789 #else
790         char prefix[PATH_MAX], tmp[PATH_MAX];
791         const char * nosh_prefix = "--file-prefix=noshconf";
792         FILE * hugedir_handle = NULL;
793         char line[PATH_MAX] = {0};
794         unsigned i, isempty = 1;
795         if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
796                 printf("Error - unable to get current prefix!\n");
797                 return -1;
798         }
799         snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
800
801         /*
802          * get first valid hugepage path
803          */
804
805         /* get hugetlbfs mountpoints from /proc/mounts */
806         hugedir_handle = fopen("/proc/mounts", "r");
807
808         if (hugedir_handle == NULL) {
809                 printf("Error opening /proc/mounts!\n");
810                 return -1;
811         }
812
813         /* read /proc/mounts */
814         while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
815
816                 /* find first valid hugepath */
817                 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
818                         break;
819         }
820
821         fclose(hugedir_handle);
822
823         /* check if path is not empty */
824         for (i = 0; i < sizeof(hugepath); i++)
825                 if (hugepath[i] != '\0')
826                         isempty = 0;
827
828         if (isempty) {
829                 printf("No mounted hugepage dir found!\n");
830                 return -1;
831         }
832 #endif
833
834
835         /* check that some general flags don't prevent things from working.
836          * All cases, apart from the first, app should run.
837          * No further testing of output done.
838          */
839         /* sanity check - failure with invalid option */
840         const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
841
842         /* With --no-pci */
843         const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
844         /* With -v */
845         const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
846         /* With valid --syslog */
847         const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
848                         "--syslog", "syslog"};
849         /* With empty --syslog (should fail) */
850         const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
851         /* With invalid --syslog */
852         const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
853         /* With no-sh-conf, also use no-huge to ensure this test runs on BSD */
854         const char *argv6[] = {prgname, "-c", "1", "-m", DEFAULT_MEM_SIZE,
855                         no_shconf, nosh_prefix, no_huge};
856
857         /* With --huge-dir */
858         const char *argv7[] = {prgname, "-c", "1", "-m", DEFAULT_MEM_SIZE,
859                         "--file-prefix=hugedir", "--huge-dir", hugepath};
860         /* With empty --huge-dir (should fail) */
861         const char *argv8[] = {prgname, "-c", "1", "-m", DEFAULT_MEM_SIZE,
862                         "--file-prefix=hugedir", "--huge-dir"};
863         /* With invalid --huge-dir */
864         const char *argv9[] = {prgname, "-c", "1", "-m", DEFAULT_MEM_SIZE,
865                         "--file-prefix=hugedir", "--huge-dir", "invalid"};
866         /* Secondary process with invalid --huge-dir (should run as flag has no
867          * effect on secondary processes) */
868         const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
869
870         /* try running with base-virtaddr param */
871         const char *argv11[] = {prgname, "--file-prefix=virtaddr",
872                         "-c", "1", "--base-virtaddr=0x12345678"};
873
874         /* try running with --vfio-intr INTx flag */
875         const char *argv12[] = {prgname, "--file-prefix=intr",
876                         "-c", "1", "--vfio-intr=legacy"};
877
878         /* try running with --vfio-intr MSI flag */
879         const char *argv13[] = {prgname, "--file-prefix=intr",
880                         "-c", "1", "--vfio-intr=msi"};
881
882         /* try running with --vfio-intr MSI-X flag */
883         const char *argv14[] = {prgname, "--file-prefix=intr",
884                         "-c", "1", "--vfio-intr=msix"};
885
886         /* try running with --vfio-intr invalid flag */
887         const char *argv15[] = {prgname, "--file-prefix=intr",
888                         "-c", "1", "--vfio-intr=invalid"};
889
890         /* run all tests also applicable to FreeBSD first */
891
892         if (launch_proc(argv0) == 0) {
893                 printf("Error - process ran ok with invalid flag\n");
894                 return -1;
895         }
896         if (launch_proc(argv1) != 0) {
897                 printf("Error - process did not run ok with --no-pci flag\n");
898                 return -1;
899         }
900         if (launch_proc(argv2) != 0) {
901                 printf("Error - process did not run ok with -v flag\n");
902                 return -1;
903         }
904         if (launch_proc(argv6) != 0) {
905                 printf("Error - process did not run ok with --no-shconf flag\n");
906                 return -1;
907         }
908
909 #ifdef RTE_EXEC_ENV_FREEBSD
910         /* no more tests to be done on FreeBSD */
911         return 0;
912 #endif
913
914         if (launch_proc(argv3) != 0) {
915                 printf("Error - process did not run ok with --syslog flag\n");
916                 return -1;
917         }
918         if (launch_proc(argv4) == 0) {
919                 printf("Error - process run ok with empty --syslog flag\n");
920                 return -1;
921         }
922         if (launch_proc(argv5) == 0) {
923                 printf("Error - process run ok with invalid --syslog flag\n");
924                 return -1;
925         }
926         if (launch_proc(argv7) != 0) {
927                 printf("Error - process did not run ok with --huge-dir flag\n");
928                 return -1;
929         }
930         if (launch_proc(argv8) == 0) {
931                 printf("Error - process run ok with empty --huge-dir flag\n");
932                 return -1;
933         }
934         if (launch_proc(argv9) == 0) {
935                 printf("Error - process run ok with invalid --huge-dir flag\n");
936                 return -1;
937         }
938         if (launch_proc(argv10) != 0) {
939                 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
940                 return -1;
941         }
942         if (launch_proc(argv11) != 0) {
943                 printf("Error - process did not run ok with --base-virtaddr parameter\n");
944                 return -1;
945         }
946         if (launch_proc(argv12) != 0) {
947                 printf("Error - process did not run ok with "
948                                 "--vfio-intr INTx parameter\n");
949                 return -1;
950         }
951         if (launch_proc(argv13) != 0) {
952                 printf("Error - process did not run ok with "
953                                 "--vfio-intr MSI parameter\n");
954                 return -1;
955         }
956         if (launch_proc(argv14) != 0) {
957                 printf("Error - process did not run ok with "
958                                 "--vfio-intr MSI-X parameter\n");
959                 return -1;
960         }
961         if (launch_proc(argv15) == 0) {
962                 printf("Error - process run ok with "
963                                 "--vfio-intr invalid parameter\n");
964                 return -1;
965         }
966         return 0;
967 }
968
969 static int
970 test_file_prefix(void)
971 {
972         /*
973          * 1. check if current process hugefiles are locked
974          * 2. try to run secondary process without a corresponding primary process
975          * (while failing to run, it will also remove any unused hugepage files)
976          * 3. check if current process hugefiles are still in place and are locked
977          * 4. run a primary process with memtest1 prefix in default and legacy
978          *    mem mode
979          * 5. check if memtest1 hugefiles are created in case of legacy mem
980          *    mode, and deleted in case of default mem mode
981          * 6. run a primary process with memtest2 prefix in default and legacy
982          *    mem modes
983          * 7. check that memtest2 hugefiles are present in the hugedir after a
984          *    run in legacy mode, and not present at all after run in default
985          *    mem mode
986          */
987         char prefix[PATH_MAX] = "";
988
989 #ifdef RTE_EXEC_ENV_FREEBSD
990         return 0;
991 #else
992         if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
993                 printf("Error - unable to get current prefix!\n");
994                 return -1;
995         }
996 #endif
997
998         /* this should fail unless the test itself is run with "memtest" prefix */
999         const char *argv0[] = {prgname, mp_flag, "-c", "1", "-m",
1000                         DEFAULT_MEM_SIZE, "--file-prefix=" memtest };
1001
1002         /* primary process with memtest1 and default mem mode */
1003         const char *argv1[] = {prgname, "-c", "1", "-m",
1004                         DEFAULT_MEM_SIZE, "--file-prefix=" memtest1 };
1005
1006         /* primary process with memtest1 and legacy mem mode */
1007         const char *argv2[] = {prgname, "-c", "1", "-m",
1008                         DEFAULT_MEM_SIZE, "--file-prefix=" memtest1,
1009                         "--legacy-mem" };
1010
1011         /* primary process with memtest2 and legacy mem mode */
1012         const char *argv3[] = {prgname, "-c", "1", "-m",
1013                         DEFAULT_MEM_SIZE, "--file-prefix=" memtest2,
1014                         "--legacy-mem" };
1015
1016         /* primary process with memtest2 and default mem mode */
1017         const char *argv4[] = {prgname, "-c", "1", "-m",
1018                         DEFAULT_MEM_SIZE, "--file-prefix=" memtest2 };
1019
1020         /* check if files for current prefix are present */
1021         if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1022                 printf("Error - hugepage files for %s were not created!\n", prefix);
1023                 return -1;
1024         }
1025
1026         /* checks if files for current prefix are locked */
1027         if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1028                 printf("Error - hugepages for current process aren't locked!\n");
1029                 return -1;
1030         }
1031
1032         /* check if files for secondary process are present */
1033         if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
1034                 /* check if they are not locked */
1035                 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
1036                         printf("Error - hugepages for current process are locked!\n");
1037                         return -1;
1038                 }
1039                 /* they aren't locked, delete them */
1040                 else {
1041                         if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
1042                                 printf("Error - deleting hugepages failed!\n");
1043                                 return -1;
1044                         }
1045                 }
1046         }
1047
1048         if (launch_proc(argv0) == 0) {
1049                 printf("Error - secondary process ran ok without primary process\n");
1050                 return -1;
1051         }
1052
1053         /* check if files for current prefix are present */
1054         if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1055                 printf("Error - hugepage files for %s were not created!\n", prefix);
1056                 return -1;
1057         }
1058
1059         /* checks if files for current prefix are locked */
1060         if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1061                 printf("Error - hugepages for current process aren't locked!\n");
1062                 return -1;
1063         }
1064
1065         /* we're running this process in default memory mode, which means it
1066          * should clean up after itself on exit and leave no hugepages behind.
1067          */
1068         if (launch_proc(argv1) != 0) {
1069                 printf("Error - failed to run with --file-prefix=%s\n",
1070                                 memtest1);
1071                 return -1;
1072         }
1073
1074         /* check if memtest1_map0 is present */
1075         if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1076                 printf("Error - hugepage files for %s were not deleted!\n",
1077                                 memtest1);
1078                 return -1;
1079         }
1080
1081         /* now, we're running a process under the same prefix, but with legacy
1082          * mem mode - this should leave behind hugepage files.
1083          */
1084         if (launch_proc(argv2) != 0) {
1085                 printf("Error - failed to run with --file-prefix=%s\n",
1086                                 memtest1);
1087                 return -1;
1088         }
1089
1090         /* check if memtest1_map0 is present */
1091         if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
1092                 printf("Error - hugepage files for %s were not created!\n",
1093                                 memtest1);
1094                 return -1;
1095         }
1096
1097         if (launch_proc(argv3) != 0) {
1098                 printf("Error - failed to run with --file-prefix=%s\n",
1099                                 memtest2);
1100                 return -1;
1101         }
1102
1103         /* check if hugefiles for memtest2 are present */
1104         if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
1105                 printf("Error - hugepage files for %s were not created!\n",
1106                                 memtest2);
1107                 return -1;
1108         }
1109
1110         /* check if hugefiles for memtest1 are present */
1111         if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1112                 printf("Error - hugepage files for %s were not deleted!\n",
1113                                 memtest1);
1114                 return -1;
1115         }
1116
1117         /* this process will run in default mem mode, so it should not leave any
1118          * hugepage files behind.
1119          */
1120         if (launch_proc(argv4) != 0) {
1121                 printf("Error - failed to run with --file-prefix=%s\n",
1122                                 memtest2);
1123                 return -1;
1124         }
1125
1126         /* check if hugefiles for memtest2 are present */
1127         if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 0) {
1128                 printf("Error - hugepage files for %s were not deleted!\n",
1129                                 memtest2);
1130                 return -1;
1131         }
1132
1133         /* check if hugefiles for memtest1 are present */
1134         if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1135                 printf("Error - hugepage files for %s were not deleted!\n",
1136                                 memtest1);
1137                 return -1;
1138         }
1139
1140         return 0;
1141 }
1142
1143 /*
1144  * Tests for correct handling of -m and --socket-mem flags
1145  */
1146 static int
1147 test_memory_flags(void)
1148 {
1149 #ifdef RTE_EXEC_ENV_FREEBSD
1150         /* BSD target doesn't support prefixes at this point */
1151         const char * prefix = "";
1152 #else
1153         char prefix[PATH_MAX], tmp[PATH_MAX];
1154         if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
1155                 printf("Error - unable to get current prefix!\n");
1156                 return -1;
1157         }
1158         snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
1159 #endif
1160
1161         /* valid -m flag and mp flag */
1162         const char *argv0[] = {prgname, prefix, mp_flag, "-c", "10",
1163                         "-m", DEFAULT_MEM_SIZE};
1164
1165         /* valid -m flag */
1166         const char *argv1[] = {prgname, "-c", "10",
1167                         "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE};
1168
1169         /* valid (zero) --socket-mem flag */
1170         const char *argv2[] = {prgname, "-c", "10",
1171                         "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
1172
1173         /* invalid (incomplete) --socket-mem flag */
1174         const char *argv3[] = {prgname, "-c", "10",
1175                         "--file-prefix=" memtest, "--socket-mem=2,2,"};
1176
1177         /* invalid (mixed with invalid data) --socket-mem flag */
1178         const char *argv4[] = {prgname, "-c", "10",
1179                         "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
1180
1181         /* invalid (with numeric value as last character) --socket-mem flag */
1182         const char *argv5[] = {prgname, "-c", "10",
1183                         "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
1184
1185         /* invalid (with empty socket) --socket-mem flag */
1186         const char *argv6[] = {prgname, "-c", "10",
1187                         "--file-prefix=" memtest, "--socket-mem=2,,2"};
1188
1189         /* invalid (null) --socket-mem flag */
1190         const char *argv7[] = {prgname, "-c", "10",
1191                         "--file-prefix=" memtest, "--socket-mem="};
1192
1193         /* valid --socket-mem specified together with -m flag */
1194         const char *argv8[] = {prgname, "-c", "10",
1195                         "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE, "--socket-mem=2,2"};
1196
1197         /* construct an invalid socket mask with 2 megs on each socket plus
1198          * extra 2 megs on socket that doesn't exist on current system */
1199         char invalid_socket_mem[SOCKET_MEM_STRLEN];
1200         char buf[SOCKET_MEM_STRLEN];    /* to avoid copying string onto itself */
1201
1202 #ifdef RTE_EXEC_ENV_FREEBSD
1203         int i, num_sockets = 1;
1204 #else
1205         int i, num_sockets = RTE_MIN(get_number_of_sockets(),
1206                         RTE_MAX_NUMA_NODES);
1207 #endif
1208
1209         if (num_sockets <= 0) {
1210                 printf("Error - cannot get number of sockets!\n");
1211                 return -1;
1212         }
1213
1214         snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
1215
1216         /* add one extra socket */
1217         for (i = 0; i < num_sockets + 1; i++) {
1218                 snprintf(buf, sizeof(buf), "%s%s", invalid_socket_mem, DEFAULT_MEM_SIZE);
1219                 strlcpy(invalid_socket_mem, buf, sizeof(invalid_socket_mem));
1220
1221                 if (num_sockets + 1 - i > 1) {
1222                         snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
1223                         strlcpy(invalid_socket_mem, buf,
1224                                 sizeof(invalid_socket_mem));
1225                 }
1226         }
1227
1228         /* construct a valid socket mask with 2 megs on each existing socket */
1229         char valid_socket_mem[SOCKET_MEM_STRLEN];
1230
1231         snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
1232
1233         /* add one extra socket */
1234         for (i = 0; i < num_sockets; i++) {
1235                 snprintf(buf, sizeof(buf), "%s%s", valid_socket_mem, DEFAULT_MEM_SIZE);
1236                 strlcpy(valid_socket_mem, buf, sizeof(valid_socket_mem));
1237
1238                 if (num_sockets - i > 1) {
1239                         snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
1240                         strlcpy(valid_socket_mem, buf,
1241                                 sizeof(valid_socket_mem));
1242                 }
1243         }
1244
1245         /* invalid --socket-mem flag (with extra socket) */
1246         const char *argv9[] = {prgname, "-c", "10",
1247                         "--file-prefix=" memtest, invalid_socket_mem};
1248
1249         /* valid --socket-mem flag */
1250         const char *argv10[] = {prgname, "-c", "10",
1251                         "--file-prefix=" memtest, valid_socket_mem};
1252
1253         if (launch_proc(argv0) != 0) {
1254                 printf("Error - secondary process failed with valid -m flag !\n");
1255                 return -1;
1256         }
1257
1258 #ifdef RTE_EXEC_ENV_FREEBSD
1259         /* no other tests are applicable to BSD */
1260         return 0;
1261 #endif
1262
1263         if (launch_proc(argv1) != 0) {
1264                 printf("Error - process failed with valid -m flag!\n");
1265                 return -1;
1266         }
1267         if (launch_proc(argv2) != 0) {
1268                 printf("Error - process failed with valid (zero) --socket-mem!\n");
1269                 return -1;
1270         }
1271
1272         if (launch_proc(argv3) == 0) {
1273                 printf("Error - process run ok with invalid "
1274                                 "(incomplete) --socket-mem!\n");
1275                 return -1;
1276         }
1277
1278         if (launch_proc(argv4) == 0) {
1279                 printf("Error - process run ok with invalid "
1280                                 "(mixed with invalid input) --socket-mem!\n");
1281                 return -1;
1282         }
1283
1284         if (launch_proc(argv5) == 0) {
1285                 printf("Error - process run ok with invalid "
1286                                 "(mixed with invalid input with a numeric value as "
1287                                 "last character) --socket-mem!\n");
1288                 return -1;
1289         }
1290
1291         if (launch_proc(argv6) == 0) {
1292                 printf("Error - process run ok with invalid "
1293                                 "(with empty socket) --socket-mem!\n");
1294                 return -1;
1295         }
1296
1297         if (launch_proc(argv7) == 0) {
1298                 printf("Error - process run ok with invalid (null) --socket-mem!\n");
1299                 return -1;
1300         }
1301
1302         if (launch_proc(argv8) == 0) {
1303                 printf("Error - process run ok with --socket-mem and -m specified!\n");
1304                 return -1;
1305         }
1306
1307         if (launch_proc(argv9) == 0) {
1308                 printf("Error - process run ok with extra socket in --socket-mem!\n");
1309                 return -1;
1310         }
1311
1312         if (launch_proc(argv10) != 0) {
1313                 printf("Error - process failed with valid --socket-mem!\n");
1314                 return -1;
1315         }
1316
1317         return 0;
1318 }
1319
1320 static int
1321 test_eal_flags(void)
1322 {
1323         int ret = 0;
1324
1325         ret = test_missing_c_flag();
1326         if (ret < 0) {
1327                 printf("Error in test_missing_c_flag()\n");
1328                 return ret;
1329         }
1330
1331         ret = test_master_lcore_flag();
1332         if (ret < 0) {
1333                 printf("Error in test_master_lcore_flag()\n");
1334                 return ret;
1335         }
1336
1337         ret = test_invalid_n_flag();
1338         if (ret < 0) {
1339                 printf("Error in test_invalid_n_flag()\n");
1340                 return ret;
1341         }
1342
1343         ret = test_no_hpet_flag();
1344         if (ret < 0) {
1345                 printf("Error in test_no_hpet_flag()\n");
1346                 return ret;
1347         }
1348
1349         ret = test_no_huge_flag();
1350         if (ret < 0) {
1351                 printf("Error in test_no_huge_flag()\n");
1352                 return ret;
1353         }
1354
1355         ret = test_whitelist_flag();
1356         if (ret < 0) {
1357                 printf("Error in test_invalid_whitelist_flag()\n");
1358                 return ret;
1359         }
1360
1361         ret = test_invalid_b_flag();
1362         if (ret < 0) {
1363                 printf("Error in test_invalid_b_flag()\n");
1364                 return ret;
1365         }
1366
1367 #ifdef RTE_LIBRTE_PMD_RING
1368         ret = test_invalid_vdev_flag();
1369         if (ret < 0) {
1370                 printf("Error in test_invalid_vdev_flag()\n");
1371                 return ret;
1372         }
1373 #endif
1374         ret = test_invalid_r_flag();
1375         if (ret < 0) {
1376                 printf("Error in test_invalid_r_flag()\n");
1377                 return ret;
1378         }
1379
1380         ret = test_memory_flags();
1381         if (ret < 0) {
1382                 printf("Error in test_memory_flags()\n");
1383                 return ret;
1384         }
1385
1386         ret = test_file_prefix();
1387         if (ret < 0) {
1388                 printf("Error in test_file_prefix()\n");
1389                 return ret;
1390         }
1391
1392         ret = test_misc_flags();
1393         if (ret < 0) {
1394                 printf("Error in test_misc_flags()");
1395                 return ret;
1396         }
1397
1398         return ret;
1399 }
1400
1401 REGISTER_TEST_COMMAND(eal_flags_autotest, test_eal_flags);