app/test: fix memory needs
[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 or -l 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, "-n", "3", "-c", "error" };
519         /* sanity check of tests - valid coremask value */
520         const char *argv4[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "1" };
521         /* -l flag but no corelist value */
522         const char *argv5[] = { prgname, prefix, mp_flag, "-n", "3", "-l"};
523         const char *argv6[] = { prgname, prefix, mp_flag, "-n", "3", "-l", " " };
524         /* bad corelist values */
525         const char *argv7[] = { prgname, prefix, mp_flag, "-n", "3", "-l", "error" };
526         const char *argv8[] = { prgname, prefix, mp_flag, "-n", "3", "-l", "1-" };
527         const char *argv9[] = { prgname, prefix, mp_flag, "-n", "3", "-l", "1," };
528         const char *argv10[] = { prgname, prefix, mp_flag, "-n", "3", "-l", "1#2" };
529         /* sanity check test - valid corelist value */
530         const char *argv11[] = { prgname, prefix, mp_flag, "-n", "3", "-l", "1-2,3" };
531
532         if (launch_proc(argv1) == 0
533                         || launch_proc(argv2) == 0
534                         || launch_proc(argv3) == 0) {
535                 printf("Error - process ran without error when missing -c flag\n");
536                 return -1;
537         }
538         if (launch_proc(argv4) != 0) {
539                 printf("Error - process did not run ok with valid coremask value\n");
540                 return -1;
541         }
542
543         if (launch_proc(argv5) == 0
544                         || launch_proc(argv6) == 0
545                         || launch_proc(argv7) == 0
546                         || launch_proc(argv8) == 0
547                         || launch_proc(argv9) == 0
548                         || launch_proc(argv10) == 0) {
549                 printf("Error - process ran without error with invalid -l flag\n");
550                 return -1;
551         }
552         if (launch_proc(argv11) != 0) {
553                 printf("Error - process did not run ok with valid corelist value\n");
554                 return -1;
555         }
556         return 0;
557 }
558
559 /*
560  * Test --master-lcore option with matching coremask
561  */
562 static int
563 test_master_lcore_flag(void)
564 {
565 #ifdef RTE_EXEC_ENV_BSDAPP
566         /* BSD target doesn't support prefixes at this point */
567         const char *prefix = "";
568 #else
569         char prefix[PATH_MAX], tmp[PATH_MAX];
570         if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
571                 printf("Error - unable to get current prefix!\n");
572                 return -1;
573         }
574         snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
575 #endif
576
577         /* --master-lcore flag but no value */
578         const char *argv1[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore"};
579         /* --master-lcore flag with invalid value */
580         const char *argv2[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "-1"};
581         const char *argv3[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "X"};
582         /* master lcore not in coremask */
583         const char *argv4[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "2"};
584         /* valid value */
585         const char *argv5[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "1"};
586         /* valid value set before coremask */
587         const char *argv6[] = { prgname, prefix, mp_flag, "-n", "1", "--master-lcore", "1", "-c", "3"};
588
589         if (launch_proc(argv1) == 0
590                         || launch_proc(argv2) == 0
591                         || launch_proc(argv3) == 0
592                         || launch_proc(argv4) == 0) {
593                 printf("Error - process ran without error with wrong --master-lcore\n");
594                 return -1;
595         }
596         if (launch_proc(argv5) != 0
597                         || launch_proc(argv6) != 0) {
598                 printf("Error - process did not run ok with valid --master-lcore\n");
599                 return -1;
600         }
601         return 0;
602 }
603
604 /*
605  * Test that the app doesn't run without the -n flag. In all cases
606  * should give an error and fail to run.
607  * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf
608  * flags.
609  */
610 static int
611 test_missing_n_flag(void)
612 {
613 #ifdef RTE_EXEC_ENV_BSDAPP
614         /* BSD target doesn't support prefixes at this point */
615         const char * prefix = "";
616 #else
617         char prefix[PATH_MAX], tmp[PATH_MAX];
618         if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
619                 printf("Error - unable to get current prefix!\n");
620                 return -1;
621         }
622         snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
623 #endif
624
625         /* -n flag but no value */
626         const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"};
627         /* No -n flag at all */
628         const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"};
629         /* bad numeric value */
630         const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" };
631         /* out-of-range value */
632         const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "9" };
633         /* sanity test - check with good value */
634         const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" };
635
636         if (launch_proc(argv1) == 0
637                         || launch_proc(argv2) == 0
638                         || launch_proc(argv3) == 0
639                         || launch_proc(argv4) == 0) {
640                 printf("Error - process ran without error when missing -n flag\n");
641                 return -1;
642         }
643         if (launch_proc(argv5) != 0) {
644                 printf("Error - process did not run ok with valid num-channel value\n");
645                 return -1;
646         }
647         return 0;
648 }
649
650 /*
651  * Test that the app runs with HPET, and without HPET
652  */
653 static int
654 test_no_hpet_flag(void)
655 {
656         char prefix[PATH_MAX], tmp[PATH_MAX];
657
658 #ifdef RTE_EXEC_ENV_BSDAPP
659         return 0;
660 #endif
661         if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
662                 printf("Error - unable to get current prefix!\n");
663                 return -1;
664         }
665         snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
666
667         /* With --no-hpet */
668         const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"};
669         /* Without --no-hpet */
670         const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-n", "2"};
671
672         if (launch_proc(argv1) != 0) {
673                 printf("Error - process did not run ok with --no-hpet flag\n");
674                 return -1;
675         }
676         if (launch_proc(argv2) != 0) {
677                 printf("Error - process did not run ok without --no-hpet flag\n");
678                 return -1;
679         }
680         return 0;
681 }
682
683 /*
684  * Test that the app runs with --no-huge and doesn't run when either
685  * -m or --socket-mem are specified with --no-huge.
686  */
687 static int
688 test_no_huge_flag(void)
689 {
690 #ifdef RTE_EXEC_ENV_BSDAPP
691         /* BSD target doesn't support prefixes at this point, and we also need to
692          * run another primary process here */
693         const char * prefix = no_shconf;
694 #else
695         const char * prefix = "--file-prefix=nohuge";
696 #endif
697
698         /* With --no-huge */
699         const char *argv1[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2"};
700         /* With --no-huge and -m */
701         const char *argv2[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
702                         "-m", DEFAULT_MEM_SIZE};
703
704         /* With --no-huge and --socket-mem */
705         const char *argv3[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
706                         "--socket-mem=" DEFAULT_MEM_SIZE};
707         /* With --no-huge, -m and --socket-mem */
708         const char *argv4[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2",
709                         "-m", DEFAULT_MEM_SIZE, "--socket-mem=" DEFAULT_MEM_SIZE};
710         if (launch_proc(argv1) != 0) {
711                 printf("Error - process did not run ok with --no-huge flag\n");
712                 return -1;
713         }
714         if (launch_proc(argv2) == 0) {
715                 printf("Error - process run ok with --no-huge and -m flags\n");
716                 return -1;
717         }
718 #ifdef RTE_EXEC_ENV_BSDAPP
719         /* BSD target does not support NUMA, hence no --socket-mem tests */
720         return 0;
721 #endif
722
723         if (launch_proc(argv3) == 0) {
724                 printf("Error - process run ok with --no-huge and --socket-mem "
725                                 "flags\n");
726                 return -1;
727         }
728         if (launch_proc(argv4) == 0) {
729                 printf("Error - process run ok with --no-huge, -m and "
730                                 "--socket-mem flags\n");
731                 return -1;
732         }
733         return 0;
734 }
735
736 #ifdef RTE_LIBRTE_XEN_DOM0
737 static int
738 test_dom0_misc_flags(void)
739 {
740         char prefix[PATH_MAX], tmp[PATH_MAX];
741
742         if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
743                 printf("Error - unable to get current prefix!\n");
744                 return -1;
745         }
746         snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
747
748         /* check that some general flags don't prevent things from working.
749          * All cases, apart from the first, app should run.
750          * No futher testing of output done.
751          */
752         /* sanity check - failure with invalid option */
753         const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
754
755         /* With --no-pci */
756         const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
757         /* With -v */
758         const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
759         /* With valid --syslog */
760         const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
761                         "--syslog", "syslog"};
762         /* With empty --syslog (should fail) */
763         const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
764         /* With invalid --syslog */
765         const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
766         /* With no-sh-conf */
767         const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "20",
768                         "--no-shconf", "--file-prefix=noshconf" };
769
770         if (launch_proc(argv0) == 0) {
771                 printf("Error - process ran ok with invalid flag\n");
772                 return -1;
773         }
774         if (launch_proc(argv1) != 0) {
775                 printf("Error - process did not run ok with --no-pci flag\n");
776                 return -1;
777         }
778         if (launch_proc(argv2) != 0) {
779                 printf("Error - process did not run ok with -v flag\n");
780                 return -1;
781         }
782         if (launch_proc(argv3) != 0) {
783                 printf("Error - process did not run ok with --syslog flag\n");
784                 return -1;
785         }
786         if (launch_proc(argv4) == 0) {
787                 printf("Error - process run ok with empty --syslog flag\n");
788                 return -1;
789         }
790         if (launch_proc(argv5) == 0) {
791                 printf("Error - process run ok with invalid --syslog flag\n");
792                 return -1;
793         }
794         if (launch_proc(argv6) != 0) {
795                 printf("Error - process did not run ok with --no-shconf flag\n");
796                 return -1;
797         }
798
799         return 0;
800 }
801 #else
802 static int
803 test_misc_flags(void)
804 {
805         char hugepath[PATH_MAX] = {0};
806 #ifdef RTE_EXEC_ENV_BSDAPP
807         /* BSD target doesn't support prefixes at this point */
808         const char * prefix = "";
809         const char * nosh_prefix = "";
810 #else
811         char prefix[PATH_MAX], tmp[PATH_MAX];
812         const char * nosh_prefix = "--file-prefix=noshconf";
813         FILE * hugedir_handle = NULL;
814         char line[PATH_MAX] = {0};
815         unsigned i, isempty = 1;
816         if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
817                 printf("Error - unable to get current prefix!\n");
818                 return -1;
819         }
820         snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
821
822         /*
823          * get first valid hugepage path
824          */
825
826         /* get hugetlbfs mountpoints from /proc/mounts */
827         hugedir_handle = fopen("/proc/mounts", "r");
828
829         if (hugedir_handle == NULL) {
830                 printf("Error opening /proc/mounts!\n");
831                 return -1;
832         }
833
834         /* read /proc/mounts */
835         while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
836
837                 /* find first valid hugepath */
838                 if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
839                         break;
840         }
841
842         fclose(hugedir_handle);
843
844         /* check if path is not empty */
845         for (i = 0; i < sizeof(hugepath); i++)
846                 if (hugepath[i] != '\0')
847                         isempty = 0;
848
849         if (isempty) {
850                 printf("No mounted hugepage dir found!\n");
851                 return -1;
852         }
853 #endif
854
855
856         /* check that some general flags don't prevent things from working.
857          * All cases, apart from the first, app should run.
858          * No futher testing of output done.
859          */
860         /* sanity check - failure with invalid option */
861         const char *argv0[] = {prgname, prefix, mp_flag, "-c", "1", "--invalid-opt"};
862
863         /* With --no-pci */
864         const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
865         /* With -v */
866         const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
867         /* With valid --syslog */
868         const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
869                         "--syslog", "syslog"};
870         /* With empty --syslog (should fail) */
871         const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
872         /* With invalid --syslog */
873         const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
874         /* With no-sh-conf */
875         const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
876                         no_shconf, nosh_prefix };
877
878 #ifdef RTE_EXEC_ENV_BSDAPP
879         return 0;
880 #endif
881         /* With --huge-dir */
882         const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
883                         "--file-prefix=hugedir", "--huge-dir", hugepath};
884         /* With empty --huge-dir (should fail) */
885         const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
886                         "--file-prefix=hugedir", "--huge-dir"};
887         /* With invalid --huge-dir */
888         const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
889                         "--file-prefix=hugedir", "--huge-dir", "invalid"};
890         /* Secondary process with invalid --huge-dir (should run as flag has no
891          * effect on secondary processes) */
892         const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
893
894         /* try running with base-virtaddr param */
895         const char *argv11[] = {prgname, "--file-prefix=virtaddr",
896                         "-c", "1", "-n", "2", "--base-virtaddr=0x12345678"};
897
898         /* try running with --vfio-intr INTx flag */
899         const char *argv12[] = {prgname, "--file-prefix=intr",
900                         "-c", "1", "-n", "2", "--vfio-intr=legacy"};
901
902         /* try running with --vfio-intr MSI flag */
903         const char *argv13[] = {prgname, "--file-prefix=intr",
904                         "-c", "1", "-n", "2", "--vfio-intr=msi"};
905
906         /* try running with --vfio-intr MSI-X flag */
907         const char *argv14[] = {prgname, "--file-prefix=intr",
908                         "-c", "1", "-n", "2", "--vfio-intr=msix"};
909
910         /* try running with --vfio-intr invalid flag */
911         const char *argv15[] = {prgname, "--file-prefix=intr",
912                         "-c", "1", "-n", "2", "--vfio-intr=invalid"};
913
914
915         if (launch_proc(argv0) == 0) {
916                 printf("Error - process ran ok with invalid flag\n");
917                 return -1;
918         }
919         if (launch_proc(argv1) != 0) {
920                 printf("Error - process did not run ok with --no-pci flag\n");
921                 return -1;
922         }
923         if (launch_proc(argv2) != 0) {
924                 printf("Error - process did not run ok with -v flag\n");
925                 return -1;
926         }
927         if (launch_proc(argv3) != 0) {
928                 printf("Error - process did not run ok with --syslog flag\n");
929                 return -1;
930         }
931         if (launch_proc(argv4) == 0) {
932                 printf("Error - process run ok with empty --syslog flag\n");
933                 return -1;
934         }
935         if (launch_proc(argv5) == 0) {
936                 printf("Error - process run ok with invalid --syslog flag\n");
937                 return -1;
938         }
939         if (launch_proc(argv6) != 0) {
940                 printf("Error - process did not run ok with --no-shconf flag\n");
941                 return -1;
942         }
943 #ifdef RTE_EXEC_ENV_BSDAPP
944         return 0;
945 #endif
946         if (launch_proc(argv7) != 0) {
947                 printf("Error - process did not run ok with --huge-dir flag\n");
948                 return -1;
949         }
950         if (launch_proc(argv8) == 0) {
951                 printf("Error - process run ok with empty --huge-dir flag\n");
952                 return -1;
953         }
954         if (launch_proc(argv9) == 0) {
955                 printf("Error - process run ok with invalid --huge-dir flag\n");
956                 return -1;
957         }
958         if (launch_proc(argv10) != 0) {
959                 printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
960                 return -1;
961         }
962         if (launch_proc(argv11) != 0) {
963                 printf("Error - process did not run ok with --base-virtaddr parameter\n");
964                 return -1;
965         }
966         if (launch_proc(argv12) != 0) {
967                 printf("Error - process did not run ok with "
968                                 "--vfio-intr INTx parameter\n");
969                 return -1;
970         }
971         if (launch_proc(argv13) != 0) {
972                 printf("Error - process did not run ok with "
973                                 "--vfio-intr MSI parameter\n");
974                 return -1;
975         }
976         if (launch_proc(argv14) != 0) {
977                 printf("Error - process did not run ok with "
978                                 "--vfio-intr MSI-X parameter\n");
979                 return -1;
980         }
981         if (launch_proc(argv15) == 0) {
982                 printf("Error - process run ok with "
983                                 "--vfio-intr invalid parameter\n");
984                 return -1;
985         }
986         return 0;
987 }
988 #endif
989
990 static int
991 test_file_prefix(void)
992 {
993         /*
994          * 1. check if current process hugefiles are locked
995          * 2. try to run secondary process without a corresponding primary process
996          * (while failing to run, it will also remove any unused hugepage files)
997          * 3. check if current process hugefiles are still in place and are locked
998          * 4. run a primary process with memtest1 prefix
999          * 5. check if memtest1 hugefiles are created
1000          * 6. run a primary process with memtest2 prefix
1001          * 7. check that only memtest2 hugefiles are present in the hugedir
1002          */
1003
1004 #ifdef RTE_EXEC_ENV_BSDAPP
1005         return 0;
1006 #endif
1007
1008         /* this should fail unless the test itself is run with "memtest" prefix */
1009         const char *argv0[] = {prgname, mp_flag, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
1010                         "--file-prefix=" memtest };
1011
1012         /* primary process with memtest1 */
1013         const char *argv1[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
1014                                 "--file-prefix=" memtest1 };
1015
1016         /* primary process with memtest2 */
1017         const char *argv2[] = {prgname, "-c", "1", "-n", "2", "-m", DEFAULT_MEM_SIZE,
1018                                 "--file-prefix=" memtest2 };
1019
1020         char prefix[32];
1021         if (get_current_prefix(prefix, sizeof(prefix)) == NULL) {
1022                 printf("Error - unable to get current prefix!\n");
1023                 return -1;
1024         }
1025 #ifdef RTE_LIBRTE_XEN_DOM0
1026         return 0;
1027 #endif
1028
1029         /* check if files for current prefix are present */
1030         if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1031                 printf("Error - hugepage files for %s were not created!\n", prefix);
1032                 return -1;
1033         }
1034
1035         /* checks if files for current prefix are locked */
1036         if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1037                 printf("Error - hugepages for current process aren't locked!\n");
1038                 return -1;
1039         }
1040
1041         /* check if files for secondary process are present */
1042         if (process_hugefiles(memtest, HUGEPAGE_CHECK_EXISTS) == 1) {
1043                 /* check if they are not locked */
1044                 if (process_hugefiles(memtest, HUGEPAGE_CHECK_LOCKED) == 1) {
1045                         printf("Error - hugepages for current process are locked!\n");
1046                         return -1;
1047                 }
1048                 /* they aren't locked, delete them */
1049                 else {
1050                         if (process_hugefiles(memtest, HUGEPAGE_DELETE) != 1) {
1051                                 printf("Error - deleting hugepages failed!\n");
1052                                 return -1;
1053                         }
1054                 }
1055         }
1056
1057         if (launch_proc(argv0) == 0) {
1058                 printf("Error - secondary process ran ok without primary process\n");
1059                 return -1;
1060         }
1061
1062         /* check if files for current prefix are present */
1063         if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) {
1064                 printf("Error - hugepage files for %s were not created!\n", prefix);
1065                 return -1;
1066         }
1067
1068         /* checks if files for current prefix are locked */
1069         if (process_hugefiles(prefix, HUGEPAGE_CHECK_LOCKED) != 1) {
1070                 printf("Error - hugepages for current process aren't locked!\n");
1071                 return -1;
1072         }
1073
1074         if (launch_proc(argv1) != 0) {
1075                 printf("Error - failed to run with --file-prefix=%s\n", memtest);
1076                 return -1;
1077         }
1078
1079         /* check if memtest1_map0 is present */
1080         if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 1) {
1081                 printf("Error - hugepage files for %s were not created!\n", memtest1);
1082                 return -1;
1083         }
1084
1085         if (launch_proc(argv2) != 0) {
1086                 printf("Error - failed to run with --file-prefix=%s\n", memtest2);
1087                 return -1;
1088         }
1089
1090         /* check if hugefiles for memtest2 are present */
1091         if (process_hugefiles(memtest2, HUGEPAGE_CHECK_EXISTS) != 1) {
1092                 printf("Error - hugepage files for %s were not created!\n", memtest2);
1093                 return -1;
1094         }
1095
1096         /* check if hugefiles for memtest1 are present */
1097         if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) != 0) {
1098                 printf("Error - hugepage files for %s were not deleted!\n", memtest1);
1099                 return -1;
1100         }
1101
1102         return 0;
1103 }
1104
1105 /*
1106  * Tests for correct handling of -m and --socket-mem flags
1107  */
1108 static int
1109 test_memory_flags(void)
1110 {
1111 #ifdef RTE_EXEC_ENV_BSDAPP
1112         /* BSD target doesn't support prefixes at this point */
1113         const char * prefix = "";
1114 #else
1115         char prefix[PATH_MAX], tmp[PATH_MAX];
1116         if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
1117                 printf("Error - unable to get current prefix!\n");
1118                 return -1;
1119         }
1120         snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
1121 #endif
1122
1123         /* valid -m flag and mp flag */
1124         const char *argv0[] = {prgname, prefix, mp_flag, "-c", "10",
1125                         "-n", "2", "-m", DEFAULT_MEM_SIZE};
1126
1127         /* valid -m flag */
1128         const char *argv1[] = {prgname, "-c", "10", "-n", "2",
1129                         "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE};
1130
1131         /* invalid (zero) --socket-mem flag */
1132         const char *argv2[] = {prgname, "-c", "10", "-n", "2",
1133                         "--file-prefix=" memtest, "--socket-mem=0,0,0,0"};
1134
1135         /* invalid (incomplete) --socket-mem flag */
1136         const char *argv3[] = {prgname, "-c", "10", "-n", "2",
1137                         "--file-prefix=" memtest, "--socket-mem=2,2,"};
1138
1139         /* invalid (mixed with invalid data) --socket-mem flag */
1140         const char *argv4[] = {prgname, "-c", "10", "-n", "2",
1141                         "--file-prefix=" memtest, "--socket-mem=2,2,Fred"};
1142
1143         /* invalid (with numeric value as last character) --socket-mem flag */
1144         const char *argv5[] = {prgname, "-c", "10", "-n", "2",
1145                         "--file-prefix=" memtest, "--socket-mem=2,2,Fred0"};
1146
1147         /* invalid (with empty socket) --socket-mem flag */
1148         const char *argv6[] = {prgname, "-c", "10", "-n", "2",
1149                         "--file-prefix=" memtest, "--socket-mem=2,,2"};
1150
1151         /* invalid (null) --socket-mem flag */
1152         const char *argv7[] = {prgname, "-c", "10", "-n", "2",
1153                         "--file-prefix=" memtest, "--socket-mem="};
1154
1155         /* valid --socket-mem specified together with -m flag */
1156         const char *argv8[] = {prgname, "-c", "10", "-n", "2",
1157                         "--file-prefix=" memtest, "-m", DEFAULT_MEM_SIZE, "--socket-mem=2,2"};
1158
1159         /* construct an invalid socket mask with 2 megs on each socket plus
1160          * extra 2 megs on socket that doesn't exist on current system */
1161         char invalid_socket_mem[SOCKET_MEM_STRLEN];
1162         char buf[SOCKET_MEM_STRLEN];    /* to avoid copying string onto itself */
1163
1164 #ifdef RTE_EXEC_ENV_BSDAPP
1165         int i, num_sockets = 1;
1166 #else
1167         int i, num_sockets = get_number_of_sockets();
1168 #endif
1169
1170         if (num_sockets <= 0 || num_sockets > RTE_MAX_NUMA_NODES) {
1171                 printf("Error - cannot get number of sockets!\n");
1172                 return -1;
1173         }
1174
1175         snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "--socket-mem=");
1176
1177         /* add one extra socket */
1178         for (i = 0; i < num_sockets + 1; i++) {
1179                 snprintf(buf, sizeof(buf), "%s%s", invalid_socket_mem, DEFAULT_MEM_SIZE);
1180                 snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1181
1182                 if (num_sockets + 1 - i > 1) {
1183                         snprintf(buf, sizeof(buf), "%s,", invalid_socket_mem);
1184                         snprintf(invalid_socket_mem, sizeof(invalid_socket_mem), "%s", buf);
1185                 }
1186         }
1187
1188         /* construct a valid socket mask with 2 megs on each existing socket */
1189         char valid_socket_mem[SOCKET_MEM_STRLEN];
1190
1191         snprintf(valid_socket_mem, sizeof(valid_socket_mem), "--socket-mem=");
1192
1193         /* add one extra socket */
1194         for (i = 0; i < num_sockets; i++) {
1195                 snprintf(buf, sizeof(buf), "%s%s", valid_socket_mem, DEFAULT_MEM_SIZE);
1196                 snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1197
1198                 if (num_sockets - i > 1) {
1199                         snprintf(buf, sizeof(buf), "%s,", valid_socket_mem);
1200                         snprintf(valid_socket_mem, sizeof(valid_socket_mem), "%s", buf);
1201                 }
1202         }
1203
1204         /* invalid --socket-mem flag (with extra socket) */
1205         const char *argv9[] = {prgname, "-c", "10", "-n", "2",
1206                         "--file-prefix=" memtest, invalid_socket_mem};
1207
1208         /* valid --socket-mem flag */
1209         const char *argv10[] = {prgname, "-c", "10", "-n", "2",
1210                         "--file-prefix=" memtest, valid_socket_mem};
1211
1212         if (launch_proc(argv0) != 0) {
1213                 printf("Error - secondary process failed with valid -m flag !\n");
1214                 return -1;
1215         }
1216
1217 #ifdef RTE_EXEC_ENV_BSDAPP
1218         /* no other tests are applicable to BSD */
1219         return 0;
1220 #endif
1221
1222         if (launch_proc(argv1) != 0) {
1223                 printf("Error - process failed with valid -m flag!\n");
1224                 return -1;
1225         }
1226 #ifdef RTE_LIBRTE_XEN_DOM0
1227         return 0;
1228 #endif
1229         if (launch_proc(argv2) == 0) {
1230                 printf("Error - process run ok with invalid (zero) --socket-mem!\n");
1231                 return -1;
1232         }
1233
1234         if (launch_proc(argv3) == 0) {
1235                 printf("Error - process run ok with invalid "
1236                                 "(incomplete) --socket-mem!\n");
1237                 return -1;
1238         }
1239
1240         if (launch_proc(argv4) == 0) {
1241                 printf("Error - process run ok with invalid "
1242                                 "(mixed with invalid input) --socket-mem!\n");
1243                 return -1;
1244         }
1245
1246         if (launch_proc(argv5) == 0) {
1247                 printf("Error - process run ok with invalid "
1248                                 "(mixed with invalid input with a numeric value as "
1249                                 "last character) --socket-mem!\n");
1250                 return -1;
1251         }
1252
1253         if (launch_proc(argv6) == 0) {
1254                 printf("Error - process run ok with invalid "
1255                                 "(with empty socket) --socket-mem!\n");
1256                 return -1;
1257         }
1258
1259         if (launch_proc(argv7) == 0) {
1260                 printf("Error - process run ok with invalid (null) --socket-mem!\n");
1261                 return -1;
1262         }
1263
1264         if (launch_proc(argv8) == 0) {
1265                 printf("Error - process run ok with --socket-mem and -m specified!\n");
1266                 return -1;
1267         }
1268
1269         if (launch_proc(argv9) == 0) {
1270                 printf("Error - process run ok with extra socket in --socket-mem!\n");
1271                 return -1;
1272         }
1273
1274         if (launch_proc(argv10) != 0) {
1275                 printf("Error - process failed with valid --socket-mem!\n");
1276                 return -1;
1277         }
1278
1279         return 0;
1280 }
1281
1282 static int
1283 test_eal_flags(void)
1284 {
1285         int ret = 0;
1286
1287         ret = test_missing_c_flag();
1288         if (ret < 0) {
1289                 printf("Error in test_missing_c_flag()\n");
1290                 return ret;
1291         }
1292
1293         ret = test_master_lcore_flag();
1294         if (ret < 0) {
1295                 printf("Error in test_master_lcore_flag()\n");
1296                 return ret;
1297         }
1298
1299         ret = test_missing_n_flag();
1300         if (ret < 0) {
1301                 printf("Error in test_missing_n_flag()\n");
1302                 return ret;
1303         }
1304
1305         ret = test_no_hpet_flag();
1306         if (ret < 0) {
1307                 printf("Error in test_no_hpet_flag()\n");
1308                 return ret;
1309         }
1310
1311         ret = test_no_huge_flag();
1312         if (ret < 0) {
1313                 printf("Error in test_no_huge_flag()\n");
1314                 return ret;
1315         }
1316
1317         ret = test_whitelist_flag();
1318         if (ret < 0) {
1319                 printf("Error in test_invalid_whitelist_flag()\n");
1320                 return ret;
1321         }
1322
1323         ret = test_invalid_b_flag();
1324         if (ret < 0) {
1325                 printf("Error in test_invalid_b_flag()\n");
1326                 return ret;
1327         }
1328
1329 #ifdef RTE_LIBRTE_PMD_RING
1330         ret = test_invalid_vdev_flag();
1331         if (ret < 0) {
1332                 printf("Error in test_invalid_vdev_flag()\n");
1333                 return ret;
1334         }
1335 #endif
1336         ret = test_invalid_r_flag();
1337         if (ret < 0) {
1338                 printf("Error in test_invalid_r_flag()\n");
1339                 return ret;
1340         }
1341
1342         ret = test_memory_flags();
1343         if (ret < 0) {
1344                 printf("Error in test_memory_flags()\n");
1345                 return ret;
1346         }
1347
1348         ret = test_file_prefix();
1349         if (ret < 0) {
1350                 printf("Error in test_file_prefix()\n");
1351                 return ret;
1352         }
1353
1354 #ifdef RTE_LIBRTE_XEN_DOM0
1355         ret = test_dom0_misc_flags();
1356 #else
1357         ret = test_misc_flags();
1358 #endif
1359         if (ret < 0) {
1360                 printf("Error in test_misc_flags()");
1361                 return ret;
1362         }
1363
1364         return ret;
1365 }
1366
1367 static struct test_command eal_flags_cmd = {
1368         .command = "eal_flags_autotest",
1369         .callback = test_eal_flags,
1370 };
1371 REGISTER_TEST_COMMAND(eal_flags_cmd);