LCOV - code coverage report
Current view: top level - spdk/test/unit/lib/notify/notify.c - notify_ut.c (source / functions) Hit Total Coverage
Test: Combined Lines: 40 40 100.0 %
Date: 2024-07-10 18:23:29 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 11 22 50.0 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2019 Intel Corporation.
       3                 :            :  *   All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "spdk/stdinc.h"
       7                 :            : #include "spdk_internal/cunit.h"
       8                 :            : #include "common/lib/test_env.c"
       9                 :            : #include "unit/lib/json_mock.c"
      10                 :            : #include "notify/notify.c"
      11                 :            : 
      12                 :            : static int
      13                 :         12 : event_cb(uint64_t idx, const struct spdk_notify_event *event, void *ctx)
      14                 :            : {
      15                 :         12 :         const struct spdk_notify_event **_event = ctx;
      16                 :            : 
      17                 :         12 :         *_event = event;
      18                 :         12 :         return 0;
      19                 :            : }
      20                 :            : 
      21                 :            : static void
      22                 :          6 : notify(void)
      23                 :            : {
      24                 :            :         struct spdk_notify_type *n1, *n2;
      25                 :          5 :         const struct spdk_notify_event *event;
      26                 :            :         const char *name;
      27                 :            :         uint64_t cnt;
      28                 :            : 
      29                 :          6 :         n1 = spdk_notify_type_register("one");
      30                 :          6 :         n2 = spdk_notify_type_register("two");
      31                 :            : 
      32                 :          6 :         name = spdk_notify_type_get_name(n1);
      33         [ -  + ]:          6 :         CU_ASSERT(strcmp(name, "one") == 0);
      34                 :            : 
      35                 :          6 :         name = spdk_notify_type_get_name(n2);
      36         [ -  + ]:          6 :         CU_ASSERT(strcmp(name, "two") == 0);
      37                 :            : 
      38                 :            : 
      39                 :          6 :         spdk_notify_send("one", "one_context");
      40                 :          6 :         spdk_notify_send("two", "two_context");
      41                 :            : 
      42                 :          6 :         event = NULL;
      43                 :          6 :         cnt = spdk_notify_foreach_event(0, 1, event_cb, &event);
      44         [ -  + ]:          6 :         SPDK_CU_ASSERT_FATAL(cnt == 1);
      45         [ -  + ]:          6 :         SPDK_CU_ASSERT_FATAL(event != NULL);
      46         [ -  + ]:          6 :         CU_ASSERT(strcmp(event->type, "one") == 0);
      47         [ -  + ]:          6 :         CU_ASSERT(strcmp(event->ctx, "one_context") == 0);
      48                 :            : 
      49                 :          6 :         event = NULL;
      50                 :          6 :         cnt = spdk_notify_foreach_event(1, 1, event_cb, &event);
      51         [ -  + ]:          6 :         SPDK_CU_ASSERT_FATAL(cnt == 1);
      52         [ -  + ]:          6 :         SPDK_CU_ASSERT_FATAL(event != NULL);
      53         [ -  + ]:          6 :         CU_ASSERT(strcmp(event->type, "two") == 0);
      54         [ -  + ]:          6 :         CU_ASSERT(strcmp(event->ctx, "two_context") == 0);
      55                 :            : 
      56                 :            :         /* This event should not exist yet */
      57                 :          6 :         event = NULL;
      58                 :          6 :         cnt = spdk_notify_foreach_event(2, 1, event_cb, &event);
      59                 :          6 :         CU_ASSERT(cnt == 0);
      60                 :          6 :         CU_ASSERT(event == NULL);
      61                 :            : 
      62         [ -  + ]:          6 :         SPDK_CU_ASSERT_FATAL(event == NULL);
      63                 :          6 : }
      64                 :            : 
      65                 :            : int
      66                 :          6 : main(int argc, char **argv)
      67                 :            : {
      68                 :          6 :         CU_pSuite suite = NULL;
      69                 :            :         unsigned int num_failures;
      70                 :            : 
      71                 :          6 :         CU_initialize_registry();
      72                 :            : 
      73                 :          6 :         suite = CU_add_suite("app_suite", NULL, NULL);
      74                 :          6 :         CU_ADD_TEST(suite, notify);
      75                 :            : 
      76                 :          6 :         num_failures = spdk_ut_run_tests(argc, argv, NULL);
      77                 :          6 :         CU_cleanup_registry();
      78                 :            : 
      79                 :          6 :         return num_failures;
      80                 :            : }

Generated by: LCOV version 1.14