LCOV - code coverage report
Current view: top level - app/test - test_debug.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 36 51 70.6 %
Date: 2025-11-01 17:50:34 Functions: 6 7 85.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 17 30 56.7 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2010-2014 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include "test.h"
       6                 :            : 
       7                 :            : #include <stdio.h>
       8                 :            : #include <stdint.h>
       9                 :            : 
      10                 :            : #ifdef RTE_EXEC_ENV_WINDOWS
      11                 :            : int
      12                 :            : test_panic(void)
      13                 :            : {
      14                 :            :         printf("debug not supported on Windows, skipping test\n");
      15                 :            :         return TEST_SKIPPED;
      16                 :            : }
      17                 :            : int
      18                 :            : test_exit(void)
      19                 :            : {
      20                 :            :         printf("debug not supported on Windows, skipping test\n");
      21                 :            :         return TEST_SKIPPED;
      22                 :            : }
      23                 :            : static int
      24                 :            : test_debug(void)
      25                 :            : {
      26                 :            :         printf("debug not supported on Windows, skipping test\n");
      27                 :            :         return TEST_SKIPPED;
      28                 :            : }
      29                 :            : 
      30                 :            : #else
      31                 :            : 
      32                 :            : #include <sys/resource.h>
      33                 :            : #include <sys/time.h>
      34                 :            : #include <sys/wait.h>
      35                 :            : #include <unistd.h>
      36                 :            : 
      37                 :            : #include <rte_debug.h>
      38                 :            : #include <rte_common.h>
      39                 :            : #include <rte_eal.h>
      40                 :            : #include <rte_lcore.h>
      41                 :            : 
      42                 :            : #include "process.h"
      43                 :            : 
      44                 :            : /*
      45                 :            :  * Debug test
      46                 :            :  * ==========
      47                 :            :  */
      48                 :            : 
      49                 :            : static const char *test_args[7];
      50                 :            : 
      51                 :            : int
      52                 :          1 : test_panic(void)
      53                 :            : {
      54                 :            :         int status;
      55                 :            : 
      56         [ -  + ]:          1 :         if (getenv(RECURSIVE_ENV_VAR) != NULL) {
      57                 :            :                 struct rlimit rl;
      58                 :            : 
      59                 :            :                 /* No need to generate a coredump when panicking. */
      60                 :          0 :                 rl.rlim_cur = rl.rlim_max = 0;
      61                 :          0 :                 setrlimit(RLIMIT_CORE, &rl);
      62                 :          0 :                 rte_panic("Test Debug\n");
      63                 :            :         }
      64                 :          1 :         status = process_dup(test_args, RTE_DIM(test_args), "test_panic");
      65         [ -  + ]:          1 :         if(status == 0){
      66                 :            :                 printf("Child process terminated normally!\n");
      67                 :          0 :                 return -1;
      68                 :            :         } else
      69                 :            :                 printf("Child process terminated as expected - Test passed!\n");
      70                 :            : 
      71                 :          1 :         return 0;
      72                 :            : }
      73                 :            : 
      74                 :            : static int
      75                 :          5 : test_exit_val(int exit_val)
      76                 :            : {
      77                 :            :         char buf[5];
      78                 :            :         int status;
      79                 :            : 
      80                 :            :         sprintf(buf, "%d", exit_val);
      81         [ -  + ]:          5 :         if (setenv("TEST_DEBUG_EXIT_VAL", buf, 1) == -1)
      82                 :          0 :                 rte_panic("Failed to set exit value in env\n");
      83                 :          5 :         status = process_dup(test_args, RTE_DIM(test_args), "test_exit");
      84                 :            :         printf("Child process status: %d\n", status);
      85   [ +  -  -  + ]:          5 :         if(!WIFEXITED(status) || WEXITSTATUS(status) != (uint8_t)exit_val){
      86                 :            :                 printf("Child process terminated with incorrect status (expected = %d)!\n",
      87                 :            :                                 exit_val);
      88                 :          0 :                 return -1;
      89                 :            :         }
      90                 :            :         return 0;
      91                 :            : }
      92                 :            : 
      93                 :            : int
      94                 :          6 : test_exit(void)
      95                 :            : {
      96                 :          6 :         int test_vals[] = { 0, 1, 2, 255, -1 };
      97                 :            :         unsigned i;
      98                 :            : 
      99         [ +  + ]:          6 :         if (getenv(RECURSIVE_ENV_VAR) != NULL) {
     100                 :            :                 int exit_val;
     101                 :            : 
     102         [ -  + ]:          5 :                 if (!getenv("TEST_DEBUG_EXIT_VAL"))
     103                 :          0 :                         rte_panic("No exit value set in env\n");
     104                 :            : 
     105                 :          5 :                 exit_val = strtol(getenv("TEST_DEBUG_EXIT_VAL"), NULL, 0);
     106                 :          5 :                 rte_exit(exit_val, __func__);
     107                 :            :         }
     108                 :            : 
     109         [ +  + ]:          6 :         for (i = 0; i < RTE_DIM(test_vals); i++) {
     110         [ +  - ]:          5 :                 if (test_exit_val(test_vals[i]) < 0)
     111                 :            :                         return -1;
     112                 :            :         }
     113                 :            :         printf("%s Passed\n", __func__);
     114                 :          1 :         return 0;
     115                 :            : }
     116                 :            : 
     117                 :            : static void
     118                 :          0 : dummy_app_usage(const char *progname)
     119                 :            : {
     120                 :            :         RTE_SET_USED(progname);
     121                 :          0 : }
     122                 :            : 
     123                 :            : static int
     124                 :          1 : test_usage(void)
     125                 :            : {
     126         [ -  + ]:          1 :         if (rte_set_application_usage_hook(dummy_app_usage) != NULL) {
     127                 :            :                 printf("Non-NULL value returned for initial usage hook\n");
     128                 :          0 :                 return -1;
     129                 :            :         }
     130         [ -  + ]:          1 :         if (rte_set_application_usage_hook(NULL) != dummy_app_usage) {
     131                 :            :                 printf("Incorrect value returned for application usage hook\n");
     132                 :          0 :                 return -1;
     133                 :            :         }
     134                 :            :         return 0;
     135                 :            : }
     136                 :            : 
     137                 :            : static int
     138                 :          1 : test_debug(void)
     139                 :            : {
     140                 :            : #ifdef RTE_EXEC_ENV_FREEBSD
     141                 :            :         /* BSD target doesn't support prefixes at this point, and we also need to
     142                 :            :          * run another primary process here.
     143                 :            :          */
     144                 :            :         const char * prefix = "--no-shconf";
     145                 :            : #else
     146                 :            :         const char * prefix = "--file-prefix=debug";
     147                 :            : #endif
     148                 :            :         char core[10];
     149                 :            : 
     150                 :          1 :         sprintf(core, "%d", rte_get_main_lcore());
     151                 :            : 
     152                 :          1 :         test_args[0] = prgname;
     153                 :          1 :         test_args[1] = prefix;
     154                 :          1 :         test_args[2] = "-l";
     155                 :          1 :         test_args[3] = core;
     156                 :            : 
     157         [ -  + ]:          1 :         if (rte_eal_has_hugepages()) {
     158                 :          0 :                 test_args[4] = "";
     159                 :          0 :                 test_args[5] = "";
     160                 :          0 :                 test_args[6] = "";
     161                 :            :         } else {
     162                 :          1 :                 test_args[4] = "--no-huge";
     163                 :          1 :                 test_args[5] = "-m";
     164                 :          1 :                 test_args[6] = "2048";
     165                 :            :         }
     166                 :            : 
     167                 :          1 :         rte_dump_stack();
     168         [ +  - ]:          1 :         if (test_panic() < 0)
     169                 :            :                 return -1;
     170         [ +  - ]:          1 :         if (test_exit() < 0)
     171                 :            :                 return -1;
     172         [ -  + ]:          1 :         if (test_usage() < 0)
     173                 :          0 :                 return -1;
     174                 :            :         return 0;
     175                 :            : }
     176                 :            : 
     177                 :            : #endif /* !RTE_EXEC_ENV_WINDOWS */
     178                 :            : 
     179                 :        253 : REGISTER_FAST_TEST(debug_autotest, true, true, test_debug);

Generated by: LCOV version 1.14