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