]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/test/unit/lib/notify/notify.c/notify_ut.c
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / test / unit / lib / notify / notify.c / notify_ut.c
1 /*-
2 * BSD LICENSE
3 *
4 * Copyright (c) Intel Corporation.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include "spdk/stdinc.h"
35 #include "spdk_cunit.h"
36 #include "common/lib/test_env.c"
37 #include "unit/lib/json_mock.c"
38 #include "notify/notify.c"
39
40 static int
41 event_cb(uint64_t idx, const struct spdk_notify_event *event, void *ctx)
42 {
43 const struct spdk_notify_event **_event = ctx;
44
45 *_event = event;
46 return 0;
47 }
48
49 static void
50 notify(void)
51 {
52 struct spdk_notify_type *n1, *n2;
53 const struct spdk_notify_event *event;
54 const char *name;
55 uint64_t cnt;
56
57 n1 = spdk_notify_type_register("one");
58 n2 = spdk_notify_type_register("two");
59
60 name = spdk_notify_type_get_name(n1);
61 CU_ASSERT(strcmp(name, "one") == 0);
62
63 name = spdk_notify_type_get_name(n2);
64 CU_ASSERT(strcmp(name, "two") == 0);
65
66
67 spdk_notify_send("one", "one_context");
68 spdk_notify_send("two", "two_context");
69
70 event = NULL;
71 cnt = spdk_notify_foreach_event(0, 1, event_cb, &event);
72 SPDK_CU_ASSERT_FATAL(cnt == 1);
73 SPDK_CU_ASSERT_FATAL(event != NULL);
74 CU_ASSERT(strcmp(event->type, "one") == 0);
75 CU_ASSERT(strcmp(event->ctx, "one_context") == 0);
76
77 event = NULL;
78 cnt = spdk_notify_foreach_event(1, 1, event_cb, &event);
79 SPDK_CU_ASSERT_FATAL(cnt == 1);
80 SPDK_CU_ASSERT_FATAL(event != NULL);
81 CU_ASSERT(strcmp(event->type, "two") == 0);
82 CU_ASSERT(strcmp(event->ctx, "two_context") == 0);
83
84 /* This event should not exist yet */
85 event = NULL;
86 cnt = spdk_notify_foreach_event(2, 1, event_cb, &event);
87 CU_ASSERT(cnt == 0);
88 CU_ASSERT(event == NULL);
89
90 SPDK_CU_ASSERT_FATAL(event == NULL);
91 }
92
93 int
94 main(int argc, char **argv)
95 {
96 CU_pSuite suite = NULL;
97 unsigned int num_failures;
98
99 CU_set_error_action(CUEA_ABORT);
100 CU_initialize_registry();
101
102 suite = CU_add_suite("app_suite", NULL, NULL);
103 CU_ADD_TEST(suite, notify);
104
105 CU_basic_set_mode(CU_BRM_VERBOSE);
106 CU_basic_run_tests();
107 num_failures = CU_get_number_of_failures();
108 CU_cleanup_registry();
109
110 return num_failures;
111 }