LCOV - code coverage report
Current view: top level - app/test - test_eal_flags.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 353 502 70.3 %
Date: 2025-02-01 18:54:23 Functions: 28 28 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 195 388 50.3 %

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

Generated by: LCOV version 1.14