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