summaryrefslogtreecommitdiffstats
path: root/lib/cluster/tests/cpg
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 13:39:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 13:39:28 +0000
commit7332b914bff2786ff70ccace103fc9ebdfb61a23 (patch)
tree3a8a60c4edba014c7e350be41839e3edbf2a315f /lib/cluster/tests/cpg
parentAdding debian version 2.1.7-1. (diff)
downloadpacemaker-7332b914bff2786ff70ccace103fc9ebdfb61a23.tar.xz
pacemaker-7332b914bff2786ff70ccace103fc9ebdfb61a23.zip
Merging upstream version 2.1.8~rc1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/cluster/tests/cpg')
-rw-r--r--lib/cluster/tests/cpg/Makefile.am19
-rw-r--r--lib/cluster/tests/cpg/pcmk_cpg_set_confchg_fn_test.c98
-rw-r--r--lib/cluster/tests/cpg/pcmk_cpg_set_deliver_fn_test.c94
3 files changed, 211 insertions, 0 deletions
diff --git a/lib/cluster/tests/cpg/Makefile.am b/lib/cluster/tests/cpg/Makefile.am
new file mode 100644
index 0000000..625f943
--- /dev/null
+++ b/lib/cluster/tests/cpg/Makefile.am
@@ -0,0 +1,19 @@
+#
+# Copyright 2024 the Pacemaker project contributors
+#
+# The version control history for this file may have further details.
+#
+# This source code is licensed under the GNU General Public License version 2
+# or later (GPLv2+) WITHOUT ANY WARRANTY.
+#
+
+include $(top_srcdir)/mk/tap.mk
+include $(top_srcdir)/mk/unittest.mk
+
+LDADD += $(top_builddir)/lib/cluster/libcrmcluster.la
+
+# Add "_test" to the end of all test program names to simplify .gitignore.
+check_PROGRAMS = pcmk_cpg_set_confchg_fn_test \
+ pcmk_cpg_set_deliver_fn_test
+
+TESTS = $(check_PROGRAMS)
diff --git a/lib/cluster/tests/cpg/pcmk_cpg_set_confchg_fn_test.c b/lib/cluster/tests/cpg/pcmk_cpg_set_confchg_fn_test.c
new file mode 100644
index 0000000..b9e1b6b
--- /dev/null
+++ b/lib/cluster/tests/cpg/pcmk_cpg_set_confchg_fn_test.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2024 the Pacemaker project contributors
+ *
+ * The version control history for this file may have further details.
+ *
+ * This source code is licensed under the GNU General Public License version 2
+ * or later (GPLv2+) WITHOUT ANY WARRANTY.
+ */
+
+#include <crm_internal.h>
+
+#include <stdint.h> // uint32_t
+#include <sys/types.h> // size_t
+
+#include <crm/cluster.h> // pcmk_cluster_t, etc.
+#include <crm/common/unittest_internal.h>
+
+#if SUPPORT_COROSYNC
+#include <corosync/cpg.h> // cpg_handle_t, struct cpg_name
+
+static void
+confchg_fn1(cpg_handle_t handle, const struct cpg_name *group_name,
+ const struct cpg_address *member_list, size_t member_list_entries,
+ const struct cpg_address *left_list, size_t left_list_entries,
+ const struct cpg_address *joined_list, size_t joined_list_entries)
+{
+ return;
+}
+
+static void
+confchg_fn2(cpg_handle_t handle, const struct cpg_name *group_name,
+ const struct cpg_address *member_list, size_t member_list_entries,
+ const struct cpg_address *left_list, size_t left_list_entries,
+ const struct cpg_address *joined_list, size_t joined_list_entries)
+{
+ return;
+}
+
+static void
+null_cluster(void **state)
+{
+ assert_int_equal(pcmk_cpg_set_confchg_fn(NULL, NULL), EINVAL);
+ assert_int_equal(pcmk_cpg_set_confchg_fn(NULL, confchg_fn1), EINVAL);
+}
+
+static void
+null_fn(void **state)
+{
+ pcmk_cluster_t cluster = {
+ .cpg = {
+ .cpg_confchg_fn = NULL,
+ },
+ };
+
+ assert_int_equal(pcmk_cpg_set_confchg_fn(&cluster, NULL), pcmk_rc_ok);
+ assert_ptr_equal(cluster.cpg.cpg_confchg_fn, NULL);
+
+ cluster.cpg.cpg_confchg_fn = confchg_fn1;
+ assert_int_equal(pcmk_cpg_set_confchg_fn(&cluster, NULL), pcmk_rc_ok);
+ assert_ptr_equal(cluster.cpg.cpg_confchg_fn, NULL);
+}
+
+static void
+previous_fn_null(void **state)
+{
+ pcmk_cluster_t cluster = {
+ .cpg = {
+ .cpg_confchg_fn = NULL,
+ },
+ };
+
+ assert_int_equal(pcmk_cpg_set_confchg_fn(&cluster, confchg_fn1),
+ pcmk_rc_ok);
+ assert_ptr_equal(cluster.cpg.cpg_confchg_fn, confchg_fn1);
+}
+
+static void
+previous_fn_nonnull(void **state)
+{
+ pcmk_cluster_t cluster = {
+ .cpg = {
+ .cpg_confchg_fn = confchg_fn2,
+ },
+ };
+
+ assert_int_equal(pcmk_cpg_set_confchg_fn(&cluster, confchg_fn1),
+ pcmk_rc_ok);
+ assert_ptr_equal(cluster.cpg.cpg_confchg_fn, confchg_fn1);
+}
+
+PCMK__UNIT_TEST(NULL, NULL,
+ cmocka_unit_test(null_cluster),
+ cmocka_unit_test(null_fn),
+ cmocka_unit_test(previous_fn_null),
+ cmocka_unit_test(previous_fn_nonnull))
+#else
+PCMK__UNIT_TEST(NULL, NULL)
+#endif // SUPPORT_COROSYNC
diff --git a/lib/cluster/tests/cpg/pcmk_cpg_set_deliver_fn_test.c b/lib/cluster/tests/cpg/pcmk_cpg_set_deliver_fn_test.c
new file mode 100644
index 0000000..f682def
--- /dev/null
+++ b/lib/cluster/tests/cpg/pcmk_cpg_set_deliver_fn_test.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2024 the Pacemaker project contributors
+ *
+ * The version control history for this file may have further details.
+ *
+ * This source code is licensed under the GNU General Public License version 2
+ * or later (GPLv2+) WITHOUT ANY WARRANTY.
+ */
+
+#include <crm_internal.h>
+
+#include <stdint.h> // uint32_t
+#include <sys/types.h> // size_t
+
+#include <crm/cluster.h> // pcmk_cluster_t, etc.
+#include <crm/common/unittest_internal.h>
+
+#if SUPPORT_COROSYNC
+#include <corosync/cpg.h> // cpg_handle_t, struct cpg_name
+
+static void
+deliver_fn1(cpg_handle_t handle, const struct cpg_name *group_name,
+ uint32_t nodeid, uint32_t pid, void *msg, size_t msg_len)
+{
+ return;
+}
+
+static void
+deliver_fn2(cpg_handle_t handle, const struct cpg_name *group_name,
+ uint32_t nodeid, uint32_t pid, void *msg, size_t msg_len)
+{
+ return;
+}
+
+static void
+null_cluster(void **state)
+{
+ assert_int_equal(pcmk_cpg_set_deliver_fn(NULL, NULL), EINVAL);
+ assert_int_equal(pcmk_cpg_set_deliver_fn(NULL, deliver_fn1), EINVAL);
+}
+
+static void
+null_fn(void **state)
+{
+ pcmk_cluster_t cluster = {
+ .cpg = {
+ .cpg_deliver_fn = NULL,
+ },
+ };
+
+ assert_int_equal(pcmk_cpg_set_deliver_fn(&cluster, NULL), pcmk_rc_ok);
+ assert_ptr_equal(cluster.cpg.cpg_deliver_fn, NULL);
+
+ cluster.cpg.cpg_deliver_fn = deliver_fn1;
+ assert_int_equal(pcmk_cpg_set_deliver_fn(&cluster, NULL), pcmk_rc_ok);
+ assert_ptr_equal(cluster.cpg.cpg_deliver_fn, NULL);
+}
+
+static void
+previous_fn_null(void **state)
+{
+ pcmk_cluster_t cluster = {
+ .cpg = {
+ .cpg_deliver_fn = NULL,
+ },
+ };
+
+ assert_int_equal(pcmk_cpg_set_deliver_fn(&cluster, deliver_fn1),
+ pcmk_rc_ok);
+ assert_ptr_equal(cluster.cpg.cpg_deliver_fn, deliver_fn1);
+}
+
+static void
+previous_fn_nonnull(void **state)
+{
+ pcmk_cluster_t cluster = {
+ .cpg = {
+ .cpg_deliver_fn = deliver_fn2,
+ },
+ };
+
+ assert_int_equal(pcmk_cpg_set_deliver_fn(&cluster, deliver_fn1),
+ pcmk_rc_ok);
+ assert_ptr_equal(cluster.cpg.cpg_deliver_fn, deliver_fn1);
+}
+
+PCMK__UNIT_TEST(NULL, NULL,
+ cmocka_unit_test(null_cluster),
+ cmocka_unit_test(null_fn),
+ cmocka_unit_test(previous_fn_null),
+ cmocka_unit_test(previous_fn_nonnull))
+#else
+PCMK__UNIT_TEST(NULL, NULL)
+#endif // SUPPORT_COROSYNC