diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-03 13:39:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-03 13:39:28 +0000 |
commit | 924f5ea83e48277e014ebf0d19a27187cb93e2f7 (patch) | |
tree | 75920a275bba045f6d108204562c218a9a26ea15 /lib/cluster/tests | |
parent | Adding upstream version 2.1.7. (diff) | |
download | pacemaker-924f5ea83e48277e014ebf0d19a27187cb93e2f7.tar.xz pacemaker-924f5ea83e48277e014ebf0d19a27187cb93e2f7.zip |
Adding upstream version 2.1.8~rc1.upstream/2.1.8_rc1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/cluster/tests')
-rw-r--r-- | lib/cluster/tests/Makefile.am | 12 | ||||
-rw-r--r-- | lib/cluster/tests/cluster/Makefile.am | 18 | ||||
-rw-r--r-- | lib/cluster/tests/cluster/pcmk_cluster_set_destroy_fn_test.c | 79 | ||||
-rw-r--r-- | lib/cluster/tests/cpg/Makefile.am | 19 | ||||
-rw-r--r-- | lib/cluster/tests/cpg/pcmk_cpg_set_confchg_fn_test.c | 98 | ||||
-rw-r--r-- | lib/cluster/tests/cpg/pcmk_cpg_set_deliver_fn_test.c | 94 |
6 files changed, 320 insertions, 0 deletions
diff --git a/lib/cluster/tests/Makefile.am b/lib/cluster/tests/Makefile.am new file mode 100644 index 0000000..f4f5658 --- /dev/null +++ b/lib/cluster/tests/Makefile.am @@ -0,0 +1,12 @@ +# +# 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. +# + +SUBDIRS = \ + cluster \ + cpg diff --git a/lib/cluster/tests/cluster/Makefile.am b/lib/cluster/tests/cluster/Makefile.am new file mode 100644 index 0000000..072a4ee --- /dev/null +++ b/lib/cluster/tests/cluster/Makefile.am @@ -0,0 +1,18 @@ +# +# 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_cluster_set_destroy_fn_test + +TESTS = $(check_PROGRAMS) diff --git a/lib/cluster/tests/cluster/pcmk_cluster_set_destroy_fn_test.c b/lib/cluster/tests/cluster/pcmk_cluster_set_destroy_fn_test.c new file mode 100644 index 0000000..f6a7ac2 --- /dev/null +++ b/lib/cluster/tests/cluster/pcmk_cluster_set_destroy_fn_test.c @@ -0,0 +1,79 @@ +/* + * 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 <glib.h> // gpointer + +#include <crm/cluster.h> // pcmk_cluster_t, etc. +#include <crm/common/unittest_internal.h> + +static void +destroy_fn1(gpointer arg) +{ + return; +} + +static void +destroy_fn2(gpointer arg) +{ + return; +} + +static void +null_cluster(void **state) +{ + assert_int_equal(pcmk_cluster_set_destroy_fn(NULL, NULL), EINVAL); + assert_int_equal(pcmk_cluster_set_destroy_fn(NULL, destroy_fn1), EINVAL); +} + +static void +null_fn(void **state) +{ + pcmk_cluster_t cluster = { + .destroy = NULL, + }; + + assert_int_equal(pcmk_cluster_set_destroy_fn(&cluster, NULL), pcmk_rc_ok); + assert_ptr_equal(cluster.destroy, NULL); + + cluster.destroy = destroy_fn1; + assert_int_equal(pcmk_cluster_set_destroy_fn(&cluster, NULL), pcmk_rc_ok); + assert_ptr_equal(cluster.destroy, NULL); +} + +static void +previous_fn_null(void **state) +{ + pcmk_cluster_t cluster = { + .destroy = NULL, + }; + + assert_int_equal(pcmk_cluster_set_destroy_fn(&cluster, destroy_fn1), + pcmk_rc_ok); + assert_ptr_equal(cluster.destroy, destroy_fn1); +} + +static void +previous_fn_nonnull(void **state) +{ + pcmk_cluster_t cluster = { + .destroy = destroy_fn2, + }; + + assert_int_equal(pcmk_cluster_set_destroy_fn(&cluster, destroy_fn1), + pcmk_rc_ok); + assert_ptr_equal(cluster.destroy, destroy_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)) 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 |