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 : 10 : event_cb(uint64_t idx, const struct spdk_notify_event *event, void *ctx)
14 : : {
15 : 10 : const struct spdk_notify_event **_event = ctx;
16 : :
17 [ + - ]: 10 : *_event = event;
18 : 10 : return 0;
19 : 2 : }
20 : :
21 : : static void
22 : 5 : notify(void)
23 : : {
24 : 1 : struct spdk_notify_type *n1, *n2;
25 : 4 : const struct spdk_notify_event *event;
26 : 1 : const char *name;
27 : 1 : uint64_t cnt;
28 : :
29 : 5 : n1 = spdk_notify_type_register("one");
30 : 5 : n2 = spdk_notify_type_register("two");
31 : :
32 : 5 : name = spdk_notify_type_get_name(n1);
33 [ + + + - ]: 5 : CU_ASSERT(strcmp(name, "one") == 0);
34 : :
35 : 5 : name = spdk_notify_type_get_name(n2);
36 [ + + + - ]: 5 : CU_ASSERT(strcmp(name, "two") == 0);
37 : :
38 : :
39 : 5 : spdk_notify_send("one", "one_context");
40 : 5 : spdk_notify_send("two", "two_context");
41 : :
42 : 5 : event = NULL;
43 : 5 : cnt = spdk_notify_foreach_event(0, 1, event_cb, &event);
44 [ + + # # ]: 5 : SPDK_CU_ASSERT_FATAL(cnt == 1);
45 [ + + # # ]: 5 : SPDK_CU_ASSERT_FATAL(event != NULL);
46 [ + + + - : 5 : CU_ASSERT(strcmp(event->type, "one") == 0);
+ - ]
47 [ + + + - : 5 : CU_ASSERT(strcmp(event->ctx, "one_context") == 0);
+ - ]
48 : :
49 : 5 : event = NULL;
50 : 5 : cnt = spdk_notify_foreach_event(1, 1, event_cb, &event);
51 [ + + # # ]: 5 : SPDK_CU_ASSERT_FATAL(cnt == 1);
52 [ + + # # ]: 5 : SPDK_CU_ASSERT_FATAL(event != NULL);
53 [ + + + - : 5 : CU_ASSERT(strcmp(event->type, "two") == 0);
+ - ]
54 [ + + + - : 5 : CU_ASSERT(strcmp(event->ctx, "two_context") == 0);
+ - ]
55 : :
56 : : /* This event should not exist yet */
57 : 5 : event = NULL;
58 : 5 : cnt = spdk_notify_foreach_event(2, 1, event_cb, &event);
59 : 5 : CU_ASSERT(cnt == 0);
60 : 5 : CU_ASSERT(event == NULL);
61 : :
62 [ + + # # ]: 5 : SPDK_CU_ASSERT_FATAL(event == NULL);
63 : 5 : }
64 : :
65 : : int
66 : 5 : main(int argc, char **argv)
67 : : {
68 : 5 : CU_pSuite suite = NULL;
69 : 1 : unsigned int num_failures;
70 : :
71 : 5 : CU_initialize_registry();
72 : :
73 : 5 : suite = CU_add_suite("app_suite", NULL, NULL);
74 : 5 : CU_ADD_TEST(suite, notify);
75 : :
76 : 5 : num_failures = spdk_ut_run_tests(argc, argv, NULL);
77 : 5 : CU_cleanup_registry();
78 : :
79 : 6 : return num_failures;
80 : 1 : }
|