LCOV - code coverage report
Current view: top level - app/test - test_mp_secondary.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 46 55 83.6 %
Date: 2025-03-01 20:23:48 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 15 28 53.6 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2010-2014 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdio.h>
       6                 :            : 
       7                 :            : #include "test.h"
       8                 :            : 
       9                 :            : #include <stdint.h>
      10                 :            : #include <stdlib.h>
      11                 :            : #include <stdarg.h>
      12                 :            : #include <inttypes.h>
      13                 :            : #include <sys/queue.h>
      14                 :            : #include <errno.h>
      15                 :            : #include <string.h>
      16                 :            : #include <unistd.h>
      17                 :            : 
      18                 :            : #ifdef RTE_EXEC_ENV_WINDOWS
      19                 :            : int
      20                 :            : test_mp_secondary(void)
      21                 :            : {
      22                 :            :         printf("mp_secondary not supported on Windows, skipping test\n");
      23                 :            :         return TEST_SKIPPED;
      24                 :            : }
      25                 :            : #else
      26                 :            : 
      27                 :            : #include <sys/wait.h>
      28                 :            : #include <libgen.h>
      29                 :            : #include <dirent.h>
      30                 :            : #include <limits.h>
      31                 :            : 
      32                 :            : #include <rte_common.h>
      33                 :            : #include <rte_memory.h>
      34                 :            : #include <rte_memzone.h>
      35                 :            : #include <rte_eal.h>
      36                 :            : #include <rte_launch.h>
      37                 :            : #include <rte_per_lcore.h>
      38                 :            : #include <rte_lcore.h>
      39                 :            : #include <rte_errno.h>
      40                 :            : #include <rte_branch_prediction.h>
      41                 :            : #include <rte_ring.h>
      42                 :            : #include <rte_debug.h>
      43                 :            : #include <rte_log.h>
      44                 :            : #include <rte_mempool.h>
      45                 :            : 
      46                 :            : #ifdef RTE_LIB_HASH
      47                 :            : #include <rte_hash.h>
      48                 :            : #include <rte_fbk_hash.h>
      49                 :            : #endif /* RTE_LIB_HASH */
      50                 :            : 
      51                 :            : #ifdef RTE_LIB_LPM
      52                 :            : #include <rte_lpm.h>
      53                 :            : #endif /* RTE_LIB_LPM */
      54                 :            : 
      55                 :            : #include <rte_string_fns.h>
      56                 :            : 
      57                 :            : #include "process.h"
      58                 :            : 
      59                 :            : #define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)
      60                 :            : 
      61                 :            : /*
      62                 :            :  * This function is called in the primary i.e. main test, to spawn off secondary
      63                 :            :  * processes to run actual mp tests. Uses fork() and exec pair
      64                 :            :  */
      65                 :            : static int
      66                 :          1 : run_secondary_instances(void)
      67                 :            : {
      68                 :            :         int ret = 0;
      69                 :            :         char coremask[10];
      70                 :            : 
      71                 :            : #ifdef RTE_EXEC_ENV_LINUX
      72                 :          1 :         char tmp[PATH_MAX] = {0};
      73                 :          1 :         char prefix[PATH_MAX] = {0};
      74                 :            : 
      75                 :          1 :         get_current_prefix(tmp, sizeof(tmp));
      76                 :            : 
      77                 :            :         snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
      78                 :            : #else
      79                 :            :         const char *prefix = "";
      80                 :            : #endif
      81                 :            : 
      82                 :            :         /* good case, using secondary */
      83                 :          1 :         const char *argv1[] = {
      84                 :            :                         prgname, "-c", coremask, "--proc-type=secondary",
      85                 :            :                         prefix
      86                 :            :         };
      87                 :            :         /* good case, using auto */
      88                 :          1 :         const char *argv2[] = {
      89                 :            :                         prgname, "-c", coremask, "--proc-type=auto",
      90                 :            :                         prefix
      91                 :            :         };
      92                 :            :         /* bad case, using invalid type */
      93                 :          1 :         const char *argv3[] = {
      94                 :            :                         prgname, "-c", coremask, "--proc-type=ERROR",
      95                 :            :                         prefix
      96                 :            :         };
      97                 :            : #ifdef RTE_EXEC_ENV_LINUX
      98                 :            :         /* bad case, using invalid file prefix */
      99                 :          1 :         const char *argv4[]  = {
     100                 :            :                         prgname, "-c", coremask, "--proc-type=secondary",
     101                 :            :                                         "--file-prefix=ERROR"
     102                 :            :         };
     103                 :            : #endif
     104                 :            : 
     105                 :          1 :         snprintf(coremask, sizeof(coremask), "%x", \
     106                 :          1 :                         (1 << rte_get_main_lcore()));
     107                 :            : 
     108                 :          1 :         ret |= launch_proc(argv1);
     109                 :            :         printf("### Testing rte_mp_disable() reject:\n");
     110         [ -  + ]:          1 :         if (rte_mp_disable()) {
     111                 :            :                 printf("Error: rte_mp_disable() has been accepted\n");
     112                 :            :                 ret |= -1;
     113                 :            :         } else {
     114                 :            :                 printf("# Checked rte_mp_disable() is refused\n");
     115                 :            :         }
     116                 :          1 :         ret |= launch_proc(argv2);
     117                 :            : 
     118                 :          1 :         ret |= !(launch_proc(argv3));
     119                 :            : #ifdef RTE_EXEC_ENV_LINUX
     120                 :          1 :         ret |= !(launch_proc(argv4));
     121                 :            : #endif
     122                 :            : 
     123                 :          1 :         return ret;
     124                 :            : }
     125                 :            : 
     126                 :            : /*
     127                 :            :  * This function is run in the secondary instance to test that creation of
     128                 :            :  * objects fails in a secondary
     129                 :            :  */
     130                 :            : static int
     131                 :          2 : run_object_creation_tests(void)
     132                 :            : {
     133                 :            :         const unsigned flags = 0;
     134                 :            :         const unsigned size = 1024;
     135                 :            :         const unsigned elt_size = 64;
     136                 :            :         const unsigned cache_size = 64;
     137                 :            :         const unsigned priv_data_size = 32;
     138                 :            : 
     139                 :            :         printf("### Testing object creation - expect lots of mz reserve errors!\n");
     140                 :            : 
     141                 :          2 :         rte_errno = 0;
     142         [ +  + ]:          2 :         if ((rte_memzone_reserve("test_mz", size, rte_socket_id(),
     143         [ -  + ]:          1 :                                  flags) == NULL) &&
     144                 :          1 :             (rte_memzone_lookup("test_mz") == NULL)) {
     145                 :            :                 printf("Error: unexpected return value from rte_memzone_reserve\n");
     146                 :          0 :                 return -1;
     147                 :            :         }
     148                 :            :         printf("# Checked rte_memzone_reserve() OK\n");
     149                 :            : 
     150                 :          2 :         rte_errno = 0;
     151         [ +  + ]:          2 :         if ((rte_ring_create(
     152         [ -  + ]:          3 :                      "test_ring", size, rte_socket_id(), flags) == NULL) &&
     153                 :          1 :                     (rte_ring_lookup("test_ring") == NULL)){
     154                 :            :                 printf("Error: unexpected return value from rte_ring_create()\n");
     155                 :          0 :                 return -1;
     156                 :            :         }
     157                 :            :         printf("# Checked rte_ring_create() OK\n");
     158                 :            : 
     159                 :          2 :         rte_errno = 0;
     160         [ +  + ]:          2 :         if ((rte_mempool_create("test_mp", size, elt_size, cache_size,
     161                 :            :                                 priv_data_size, NULL, NULL, NULL, NULL,
     162         [ -  + ]:          3 :                                 rte_socket_id(), flags) == NULL) &&
     163                 :          1 :              (rte_mempool_lookup("test_mp") == NULL)){
     164                 :            :                 printf("Error: unexpected return value from rte_mempool_create()\n");
     165                 :          0 :                 return -1;
     166                 :            :         }
     167                 :            :         printf("# Checked rte_mempool_create() OK\n");
     168                 :            : 
     169                 :            : #ifdef RTE_LIB_HASH
     170                 :          2 :         const struct rte_hash_parameters hash_params = { .name = "test_mp_hash" };
     171                 :          2 :         rte_errno=0;
     172   [ -  +  -  - ]:          2 :         if ((rte_hash_create(&hash_params) != NULL) &&
     173                 :          0 :             (rte_hash_find_existing(hash_params.name) == NULL)){
     174                 :            :                 printf("Error: unexpected return value from rte_hash_create()\n");
     175                 :          0 :                 return -1;
     176                 :            :         }
     177                 :            :         printf("# Checked rte_hash_create() OK\n");
     178                 :            : 
     179                 :          2 :         const struct rte_fbk_hash_params fbk_params = { .name = "test_fbk_mp_hash" };
     180                 :          2 :         rte_errno=0;
     181   [ -  +  -  - ]:          2 :         if ((rte_fbk_hash_create(&fbk_params) != NULL) &&
     182                 :          0 :             (rte_fbk_hash_find_existing(fbk_params.name) == NULL)){
     183                 :            :                 printf("Error: unexpected return value from rte_fbk_hash_create()\n");
     184                 :          0 :                 return -1;
     185                 :            :         }
     186                 :            :         printf("# Checked rte_fbk_hash_create() OK\n");
     187                 :            : #endif
     188                 :            : 
     189                 :            : #ifdef RTE_LIB_LPM
     190                 :          2 :         rte_errno=0;
     191                 :            :         struct rte_lpm_config config;
     192                 :            : 
     193                 :          2 :         config.max_rules = rte_socket_id();
     194                 :          2 :         config.number_tbl8s = 256;
     195                 :          2 :         config.flags = 0;
     196   [ -  +  -  - ]:          2 :         if ((rte_lpm_create("test_lpm", size, &config) != NULL) &&
     197                 :          0 :             (rte_lpm_find_existing("test_lpm") == NULL)){
     198                 :            :                 printf("Error: unexpected return value from rte_lpm_create()\n");
     199                 :          0 :                 return -1;
     200                 :            :         }
     201                 :            :         printf("# Checked rte_lpm_create() OK\n");
     202                 :            : #endif
     203                 :            : 
     204                 :          2 :         return 0;
     205                 :            : }
     206                 :            : 
     207                 :            : /* if called in a primary process, just spawns off a secondary process to
     208                 :            :  * run validation tests - which brings us right back here again...
     209                 :            :  * if called in a secondary process, this runs a series of API tests to check
     210                 :            :  * how things run in a secondary instance.
     211                 :            :  */
     212                 :            : int
     213                 :          3 : test_mp_secondary(void)
     214                 :            : {
     215         [ +  + ]:          3 :         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
     216                 :          1 :                 return run_secondary_instances();
     217                 :            :         }
     218                 :            : 
     219                 :            :         printf("IN SECONDARY PROCESS\n");
     220                 :            : 
     221                 :          2 :         return run_object_creation_tests();
     222                 :            : }
     223                 :            : 
     224                 :            : #endif /* !RTE_EXEC_ENV_WINDOWS */
     225                 :            : 
     226                 :        252 : REGISTER_FAST_TEST(multiprocess_autotest, false, false, test_mp_secondary);

Generated by: LCOV version 1.14