LCOV - code coverage report
Current view: top level - spdk/test/event/reactor - reactor.c (source / functions) Hit Total Coverage
Test: Combined Lines: 42 53 79.2 %
Date: 2024-07-11 07:44:42 Functions: 5 7 71.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 12 22 54.5 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2016 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                 :            : static int g_time_in_sec;
      13                 :            : static struct spdk_poller *test_end_poller;
      14                 :            : static struct spdk_poller *poller_100ms;
      15                 :            : static struct spdk_poller *poller_250ms;
      16                 :            : static struct spdk_poller *poller_500ms;
      17                 :            : static struct spdk_poller *poller_oneshot;
      18                 :            : static struct spdk_poller *poller_unregister;
      19                 :            : 
      20                 :            : static int
      21                 :         21 : test_end(void *arg)
      22                 :            : {
      23         [ -  + ]:         21 :         printf("test_end\n");
      24                 :            : 
      25                 :         21 :         spdk_poller_unregister(&test_end_poller);
      26                 :         21 :         spdk_poller_unregister(&poller_100ms);
      27                 :         21 :         spdk_poller_unregister(&poller_250ms);
      28                 :         21 :         spdk_poller_unregister(&poller_500ms);
      29                 :            : 
      30                 :         21 :         spdk_app_stop(0);
      31                 :         21 :         return -1;
      32                 :            : }
      33                 :            : 
      34                 :            : static int
      35                 :        273 : tick(void *arg)
      36                 :            : {
      37                 :        273 :         uintptr_t period = (uintptr_t)arg;
      38                 :            : 
      39         [ -  + ]:        273 :         printf("tick %" PRIu64 "\n", (uint64_t)period);
      40                 :            : 
      41                 :        273 :         return -1;
      42                 :            : }
      43                 :            : 
      44                 :            : static int
      45                 :         21 : oneshot(void *arg)
      46                 :            : {
      47         [ -  + ]:         21 :         printf("oneshot\n");
      48                 :         21 :         spdk_poller_unregister(&poller_oneshot);
      49                 :            : 
      50                 :         21 :         return -1;
      51                 :            : }
      52                 :            : 
      53                 :            : static int
      54                 :          0 : nop(void *arg)
      55                 :            : {
      56                 :          0 :         return -1;
      57                 :            : }
      58                 :            : 
      59                 :            : static void
      60                 :         21 : test_start(void *arg1)
      61                 :            : {
      62         [ -  + ]:         21 :         printf("test_start\n");
      63                 :            : 
      64                 :            :         /* Register a poller that will stop the test after the time has elapsed. */
      65                 :         21 :         test_end_poller = SPDK_POLLER_REGISTER(test_end, NULL, g_time_in_sec * 1000000ULL);
      66                 :            : 
      67                 :         21 :         poller_100ms = SPDK_POLLER_REGISTER(tick, (void *)100, 100000);
      68                 :         21 :         poller_250ms = SPDK_POLLER_REGISTER(tick, (void *)250, 250000);
      69                 :         21 :         poller_500ms = SPDK_POLLER_REGISTER(tick, (void *)500, 500000);
      70                 :         21 :         poller_oneshot = SPDK_POLLER_REGISTER(oneshot, NULL, 0);
      71                 :            : 
      72                 :         21 :         poller_unregister = SPDK_POLLER_REGISTER(nop, NULL, 0);
      73                 :         21 :         spdk_poller_unregister(&poller_unregister);
      74                 :         21 : }
      75                 :            : 
      76                 :            : static void
      77                 :          0 : usage(const char *program_name)
      78                 :            : {
      79         [ #  # ]:          0 :         printf("%s options\n", program_name);
      80         [ #  # ]:          0 :         printf("\t[-t time in seconds]\n");
      81                 :          0 : }
      82                 :            : 
      83                 :            : int
      84                 :         21 : main(int argc, char **argv)
      85                 :            : {
      86                 :         10 :         struct spdk_app_opts opts;
      87                 :            :         int op;
      88                 :         21 :         int rc = 0;
      89                 :            : 
      90                 :         21 :         spdk_app_opts_init(&opts, sizeof(opts));
      91                 :         21 :         opts.name = "reactor";
      92                 :         21 :         opts.rpc_addr = NULL;
      93                 :            : 
      94                 :         21 :         g_time_in_sec = 0;
      95                 :            : 
      96   [ +  +  +  +  :         42 :         while ((op = getopt(argc, argv, "t:")) != -1) {
                   +  + ]
      97         [ +  - ]:         21 :                 switch (op) {
      98                 :         21 :                 case 't':
      99                 :         21 :                         g_time_in_sec = spdk_strtol(optarg, 10);
     100                 :         21 :                         break;
     101                 :          0 :                 default:
     102                 :          0 :                         usage(argv[0]);
     103                 :          0 :                         exit(1);
     104                 :            :                 }
     105                 :            :         }
     106                 :            : 
     107         [ -  + ]:         21 :         if (g_time_in_sec <= 0) {
     108                 :          0 :                 usage(argv[0]);
     109                 :          0 :                 exit(1);
     110                 :            :         }
     111                 :            : 
     112                 :         21 :         rc = spdk_app_start(&opts, test_start, NULL);
     113                 :            : 
     114                 :         21 :         spdk_app_fini();
     115                 :            : 
     116                 :         21 :         return rc;
     117                 :            : }

Generated by: LCOV version 1.14