pacemaker  2.1.8-3980678f03
Scalable High-Availability cluster resource manager
pcmk_cpg_set_confchg_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 
21 static void
22 confchg_fn1(cpg_handle_t handle, const struct cpg_name *group_name,
23  const struct cpg_address *member_list, size_t member_list_entries,
24  const struct cpg_address *left_list, size_t left_list_entries,
25  const struct cpg_address *joined_list, size_t joined_list_entries)
26 {
27  return;
28 }
29 
30 static void
31 confchg_fn2(cpg_handle_t handle, const struct cpg_name *group_name,
32  const struct cpg_address *member_list, size_t member_list_entries,
33  const struct cpg_address *left_list, size_t left_list_entries,
34  const struct cpg_address *joined_list, size_t joined_list_entries)
35 {
36  return;
37 }
38 
39 static void
40 null_cluster(void **state)
41 {
42  assert_int_equal(pcmk_cpg_set_confchg_fn(NULL, NULL), EINVAL);
43  assert_int_equal(pcmk_cpg_set_confchg_fn(NULL, confchg_fn1), EINVAL);
44 }
45 
46 static void
47 null_fn(void **state)
48 {
49  pcmk_cluster_t cluster = {
50  .cpg = {
51  .cpg_confchg_fn = NULL,
52  },
53  };
54 
55  assert_int_equal(pcmk_cpg_set_confchg_fn(&cluster, NULL), pcmk_rc_ok);
56  assert_ptr_equal(cluster.cpg.cpg_confchg_fn, NULL);
57 
58  cluster.cpg.cpg_confchg_fn = confchg_fn1;
59  assert_int_equal(pcmk_cpg_set_confchg_fn(&cluster, NULL), pcmk_rc_ok);
60  assert_ptr_equal(cluster.cpg.cpg_confchg_fn, NULL);
61 }
62 
63 static void
64 previous_fn_null(void **state)
65 {
66  pcmk_cluster_t cluster = {
67  .cpg = {
68  .cpg_confchg_fn = NULL,
69  },
70  };
71 
72  assert_int_equal(pcmk_cpg_set_confchg_fn(&cluster, confchg_fn1),
73  pcmk_rc_ok);
74  assert_ptr_equal(cluster.cpg.cpg_confchg_fn, confchg_fn1);
75 }
76 
77 static void
78 previous_fn_nonnull(void **state)
79 {
80  pcmk_cluster_t cluster = {
81  .cpg = {
82  .cpg_confchg_fn = confchg_fn2,
83  },
84  };
85 
86  assert_int_equal(pcmk_cpg_set_confchg_fn(&cluster, confchg_fn1),
87  pcmk_rc_ok);
88  assert_ptr_equal(cluster.cpg.cpg_confchg_fn, confchg_fn1);
89 }
90 
91 PCMK__UNIT_TEST(NULL, NULL,
92  cmocka_unit_test(null_cluster),
93  cmocka_unit_test(null_fn),
94  cmocka_unit_test(previous_fn_null),
95  cmocka_unit_test(previous_fn_nonnull))
96 #else
97 PCMK__UNIT_TEST(NULL, NULL)
98 #endif // SUPPORT_COROSYNC
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
int pcmk_cpg_set_confchg_fn(pcmk_cluster_t *cluster, cpg_confchg_fn_t fn)
Set the CPG config change callback function for a cluster object.
Definition: cpg.c:812