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