pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
pcmk_cpg_set_deliver_fn_test.c
Go to the documentation of this file.
1/*
2 * Copyright 2024 the Pacemaker project contributors
3 *
4 * The version control history for this file may have further details.
5 *
6 * This source code is licensed under the GNU General Public License version 2
7 * or later (GPLv2+) WITHOUT ANY WARRANTY.
8 */
9
10#include <crm_internal.h>
11
12#include <stdint.h> // uint32_t
13#include <sys/types.h> // size_t
14
15#include <crm/cluster.h> // pcmk_cluster_t, etc.
17
18#if SUPPORT_COROSYNC
19#include <corosync/cpg.h> // cpg_handle_t, struct cpg_name
20
21static void
22deliver_fn1(cpg_handle_t handle, const struct cpg_name *group_name,
23 uint32_t nodeid, uint32_t pid, void *msg, size_t msg_len)
24{
25 return;
26}
27
28static void
29deliver_fn2(cpg_handle_t handle, const struct cpg_name *group_name,
30 uint32_t nodeid, uint32_t pid, void *msg, size_t msg_len)
31{
32 return;
33}
34
35static void
36null_cluster(void **state)
37{
38 assert_int_equal(pcmk_cpg_set_deliver_fn(NULL, NULL), EINVAL);
39 assert_int_equal(pcmk_cpg_set_deliver_fn(NULL, deliver_fn1), EINVAL);
40}
41
42static void
43null_fn(void **state)
44{
45 pcmk_cluster_t cluster = {
46 .cpg = {
47 .cpg_deliver_fn = NULL,
48 },
49 };
50
51 assert_int_equal(pcmk_cpg_set_deliver_fn(&cluster, NULL), pcmk_rc_ok);
52 assert_ptr_equal(cluster.cpg.cpg_deliver_fn, NULL);
53
54 cluster.cpg.cpg_deliver_fn = deliver_fn1;
55 assert_int_equal(pcmk_cpg_set_deliver_fn(&cluster, NULL), pcmk_rc_ok);
56 assert_ptr_equal(cluster.cpg.cpg_deliver_fn, NULL);
57}
58
59static void
60previous_fn_null(void **state)
61{
62 pcmk_cluster_t cluster = {
63 .cpg = {
64 .cpg_deliver_fn = NULL,
65 },
66 };
67
68 assert_int_equal(pcmk_cpg_set_deliver_fn(&cluster, deliver_fn1),
70 assert_ptr_equal(cluster.cpg.cpg_deliver_fn, deliver_fn1);
71}
72
73static void
74previous_fn_nonnull(void **state)
75{
76 pcmk_cluster_t cluster = {
77 .cpg = {
78 .cpg_deliver_fn = deliver_fn2,
79 },
80 };
81
82 assert_int_equal(pcmk_cpg_set_deliver_fn(&cluster, deliver_fn1),
84 assert_ptr_equal(cluster.cpg.cpg_deliver_fn, deliver_fn1);
85}
86
87PCMK__UNIT_TEST(NULL, NULL,
88 cmocka_unit_test(null_cluster),
89 cmocka_unit_test(null_fn),
90 cmocka_unit_test(previous_fn_null),
91 cmocka_unit_test(previous_fn_nonnull))
92#else
93PCMK__UNIT_TEST(NULL, NULL)
94#endif // SUPPORT_COROSYNC
int pcmk_cpg_set_deliver_fn(pcmk_cluster_t *cluster, cpg_deliver_fn_t fn)
Set the CPG deliver callback function for a cluster object.
Definition cpg.c:744
uint32_t pid
Definition cpg.c:1
@ pcmk_rc_ok
Definition results.h:159
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)