LCOV - code coverage report
Current view: top level - spdk/test/event/app_repeat - app_repeat.c (source / functions) Hit Total Coverage
Test: Combined Lines: 26 35 74.3 %
Date: 2024-07-15 21:23:26 Functions: 4 5 80.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 8 20 40.0 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2020 Intel Corporation.
       3                 :            :  *   All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "spdk/stdinc.h"
       7                 :            : 
       8                 :            : #include "spdk/event.h"
       9                 :            : #include "spdk/string.h"
      10                 :            : #include "spdk/thread.h"
      11                 :            : 
      12                 :            : struct spdk_app_opts g_opts = {};
      13                 :            : static const char g_app_repeat_get_opts_string[] = "t:";
      14                 :            : static int g_repeat_times = 2;
      15                 :            : 
      16                 :            : static void
      17                 :          0 : app_repeat_usage(void)
      18                 :            : {
      19         [ #  # ]:          0 :         printf(" -t <num>                  number of times to repeat calling spdk_app_start/stop\n");
      20                 :          0 : }
      21                 :            : 
      22                 :            : static int
      23                 :         19 : app_repeat_parse_arg(int ch, char *arg)
      24                 :            : {
      25         [ +  - ]:         19 :         switch (ch) {
      26                 :         19 :         case 't':
      27                 :         19 :                 g_repeat_times = spdk_strtol(arg, 0);
      28         [ -  + ]:         19 :                 if (g_repeat_times < 2) {
      29                 :          0 :                         return -EINVAL;
      30                 :            :                 }
      31                 :         19 :                 break;
      32                 :          0 :         default:
      33                 :          0 :                 return -EINVAL;
      34                 :            :         }
      35                 :         19 :         return 0;
      36                 :            : }
      37                 :            : 
      38                 :            : static void
      39                 :         76 : app_repeat_started(void *arg1)
      40                 :            : {
      41                 :         76 :         int index = *(int *)arg1;
      42                 :            : 
      43         [ -  + ]:         76 :         printf("spdk_app_start is called in Round %d.\n", index);
      44                 :         76 : }
      45                 :            : 
      46                 :            : static void
      47                 :         76 : _app_repeat_shutdown_cb(void)
      48                 :            : {
      49         [ -  + ]:         76 :         printf("Shutdown signal received, stop current app iteration\n");
      50                 :         76 :         spdk_app_stop(0);
      51                 :         76 : }
      52                 :            : 
      53                 :            : int
      54                 :         19 : main(int argc, char **argv)
      55                 :            : {
      56                 :            :         int rc;
      57                 :          8 :         int i;
      58                 :            : 
      59                 :         19 :         spdk_app_opts_init(&g_opts, sizeof(g_opts));
      60                 :         19 :         g_opts.name = "app_repeat";
      61                 :         19 :         g_opts.shutdown_cb = _app_repeat_shutdown_cb;
      62         [ -  + ]:         19 :         if ((rc = spdk_app_parse_args(argc, argv, &g_opts, g_app_repeat_get_opts_string,
      63                 :            :                                       NULL, app_repeat_parse_arg, app_repeat_usage)) !=
      64                 :            :             SPDK_APP_PARSE_ARGS_SUCCESS) {
      65                 :          0 :                 return rc;
      66                 :            :         }
      67                 :            : 
      68         [ +  + ]:         95 :         for (i = 0; i < g_repeat_times; i++) {
      69                 :         76 :                 rc = spdk_app_start(&g_opts, app_repeat_started, &i);
      70                 :         76 :                 spdk_app_fini();
      71                 :            : 
      72         [ -  + ]:         76 :                 if (rc) {
      73   [ #  #  #  # ]:          0 :                         fprintf(stderr, "Failed to call spdk_app_start in Round %d.\n", i);
      74                 :          0 :                         break;
      75                 :            :                 }
      76                 :            :         }
      77                 :            : 
      78                 :         19 :         return rc;
      79                 :            : }

Generated by: LCOV version 1.14