]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/test/unit/lib/notify/notify.c/notify_ut.c
4 * Copyright (c) Intel Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
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"
41 event_cb(uint64_t idx
, const struct spdk_notify_event
*event
, void *ctx
)
43 const struct spdk_notify_event
**_event
= ctx
;
52 struct spdk_notify_type
*n1
, *n2
;
53 const struct spdk_notify_event
*event
;
57 n1
= spdk_notify_type_register("one");
58 n2
= spdk_notify_type_register("two");
60 name
= spdk_notify_type_get_name(n1
);
61 CU_ASSERT(strcmp(name
, "one") == 0);
63 name
= spdk_notify_type_get_name(n2
);
64 CU_ASSERT(strcmp(name
, "two") == 0);
67 spdk_notify_send("one", "one_context");
68 spdk_notify_send("two", "two_context");
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);
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);
84 /* This event should not exist yet */
86 cnt
= spdk_notify_foreach_event(2, 1, event_cb
, &event
);
88 CU_ASSERT(event
== NULL
);
90 SPDK_CU_ASSERT_FATAL(event
== NULL
);
94 main(int argc
, char **argv
)
96 CU_pSuite suite
= NULL
;
97 unsigned int num_failures
;
99 CU_set_error_action(CUEA_ABORT
);
100 CU_initialize_registry();
102 suite
= CU_add_suite("app_suite", NULL
, NULL
);
103 CU_ADD_TEST(suite
, notify
);
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();