summaryrefslogtreecommitdiffstats
path: root/lib/pengine/tests/status
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 06:53:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 06:53:20 +0000
commite5a812082ae033afb1eed82c0f2df3d0f6bdc93f (patch)
treea6716c9275b4b413f6c9194798b34b91affb3cc7 /lib/pengine/tests/status
parentInitial commit. (diff)
downloadpacemaker-e5a812082ae033afb1eed82c0f2df3d0f6bdc93f.tar.xz
pacemaker-e5a812082ae033afb1eed82c0f2df3d0f6bdc93f.zip
Adding upstream version 2.1.6.upstream/2.1.6
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/pengine/tests/status')
-rw-r--r--lib/pengine/tests/status/Makefile.am22
-rw-r--r--lib/pengine/tests/status/pe_find_node_any_test.c62
-rw-r--r--lib/pengine/tests/status/pe_find_node_id_test.c51
-rw-r--r--lib/pengine/tests/status/pe_find_node_test.c51
-rw-r--r--lib/pengine/tests/status/pe_new_working_set_test.c46
-rw-r--r--lib/pengine/tests/status/set_working_set_defaults_test.c46
6 files changed, 278 insertions, 0 deletions
diff --git a/lib/pengine/tests/status/Makefile.am b/lib/pengine/tests/status/Makefile.am
new file mode 100644
index 0000000..3f95496
--- /dev/null
+++ b/lib/pengine/tests/status/Makefile.am
@@ -0,0 +1,22 @@
+#
+# Copyright 2022 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/pengine/libpe_status_test.la
+
+# Add "_test" to the end of all test program names to simplify .gitignore.
+check_PROGRAMS = pe_find_node_any_test \
+ pe_find_node_id_test \
+ pe_find_node_test \
+ pe_new_working_set_test \
+ set_working_set_defaults_test
+
+TESTS = $(check_PROGRAMS)
diff --git a/lib/pengine/tests/status/pe_find_node_any_test.c b/lib/pengine/tests/status/pe_find_node_any_test.c
new file mode 100644
index 0000000..b911424
--- /dev/null
+++ b/lib/pengine/tests/status/pe_find_node_any_test.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2022 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 <crm/common/unittest_internal.h>
+#include <crm/pengine/internal.h>
+
+static void
+empty_list(void **state) {
+ assert_null(pe_find_node_any(NULL, NULL, NULL));
+ assert_null(pe_find_node_any(NULL, NULL, "cluster1"));
+ assert_null(pe_find_node_any(NULL, "id1", NULL));
+ assert_null(pe_find_node_any(NULL, "id1", "cluster1"));
+}
+
+static void
+non_null_list(void **state) {
+ GList *nodes = NULL;
+
+ pe_node_t *a = calloc(1, sizeof(pe_node_t));
+ pe_node_t *b = calloc(1, sizeof(pe_node_t));
+
+ a->details = calloc(1, sizeof(struct pe_node_shared_s));
+ a->details->uname = "cluster1";
+ a->details->id = "id1";
+ b->details = calloc(1, sizeof(struct pe_node_shared_s));
+ b->details->uname = "cluster2";
+ b->details->id = "id2";
+
+ nodes = g_list_append(nodes, a);
+ nodes = g_list_append(nodes, b);
+
+ assert_ptr_equal(b, pe_find_node_any(nodes, "id2", NULL));
+ assert_ptr_equal(b, pe_find_node_any(nodes, "ID2", NULL));
+
+ assert_ptr_equal(a, pe_find_node_any(nodes, "xyz", "cluster1"));
+ assert_ptr_equal(a, pe_find_node_any(nodes, NULL, "cluster1"));
+
+ assert_null(pe_find_node_any(nodes, "id10", NULL));
+ assert_null(pe_find_node_any(nodes, "nodeid1", NULL));
+ assert_null(pe_find_node_any(nodes, NULL, "cluster10"));
+ assert_null(pe_find_node_any(nodes, NULL, "nodecluster1"));
+ assert_null(pe_find_node_any(nodes, "id3", "cluster3"));
+ assert_null(pe_find_node_any(nodes, NULL, NULL));
+
+ free(a->details);
+ free(a);
+ free(b->details);
+ free(b);
+ g_list_free(nodes);
+}
+
+PCMK__UNIT_TEST(NULL, NULL,
+ cmocka_unit_test(empty_list),
+ cmocka_unit_test(non_null_list))
diff --git a/lib/pengine/tests/status/pe_find_node_id_test.c b/lib/pengine/tests/status/pe_find_node_id_test.c
new file mode 100644
index 0000000..832a40a
--- /dev/null
+++ b/lib/pengine/tests/status/pe_find_node_id_test.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2022 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 <crm/common/unittest_internal.h>
+#include <crm/pengine/internal.h>
+
+static void
+empty_list(void **state) {
+ assert_null(pe_find_node_id(NULL, NULL));
+ assert_null(pe_find_node_id(NULL, "id1"));
+}
+
+static void
+non_null_list(void **state) {
+ GList *nodes = NULL;
+
+ pe_node_t *a = calloc(1, sizeof(pe_node_t));
+ pe_node_t *b = calloc(1, sizeof(pe_node_t));
+
+ a->details = calloc(1, sizeof(struct pe_node_shared_s));
+ a->details->id = "id1";
+ b->details = calloc(1, sizeof(struct pe_node_shared_s));
+ b->details->id = "id2";
+
+ nodes = g_list_append(nodes, a);
+ nodes = g_list_append(nodes, b);
+
+ assert_ptr_equal(a, pe_find_node_id(nodes, "id1"));
+ assert_null(pe_find_node_id(nodes, "id10"));
+ assert_null(pe_find_node_id(nodes, "nodeid1"));
+ assert_ptr_equal(b, pe_find_node_id(nodes, "ID2"));
+ assert_null(pe_find_node_id(nodes, "xyz"));
+
+ free(a->details);
+ free(a);
+ free(b->details);
+ free(b);
+ g_list_free(nodes);
+}
+
+PCMK__UNIT_TEST(NULL, NULL,
+ cmocka_unit_test(empty_list),
+ cmocka_unit_test(non_null_list))
diff --git a/lib/pengine/tests/status/pe_find_node_test.c b/lib/pengine/tests/status/pe_find_node_test.c
new file mode 100644
index 0000000..7c7ea30
--- /dev/null
+++ b/lib/pengine/tests/status/pe_find_node_test.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2022 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 <crm/common/unittest_internal.h>
+#include <crm/pengine/internal.h>
+
+static void
+empty_list(void **state) {
+ assert_null(pe_find_node(NULL, NULL));
+ assert_null(pe_find_node(NULL, "cluster1"));
+}
+
+static void
+non_null_list(void **state) {
+ GList *nodes = NULL;
+
+ pe_node_t *a = calloc(1, sizeof(pe_node_t));
+ pe_node_t *b = calloc(1, sizeof(pe_node_t));
+
+ a->details = calloc(1, sizeof(struct pe_node_shared_s));
+ a->details->uname = "cluster1";
+ b->details = calloc(1, sizeof(struct pe_node_shared_s));
+ b->details->uname = "cluster2";
+
+ nodes = g_list_append(nodes, a);
+ nodes = g_list_append(nodes, b);
+
+ assert_ptr_equal(a, pe_find_node(nodes, "cluster1"));
+ assert_null(pe_find_node(nodes, "cluster10"));
+ assert_null(pe_find_node(nodes, "nodecluster1"));
+ assert_ptr_equal(b, pe_find_node(nodes, "CLUSTER2"));
+ assert_null(pe_find_node(nodes, "xyz"));
+
+ free(a->details);
+ free(a);
+ free(b->details);
+ free(b);
+ g_list_free(nodes);
+}
+
+PCMK__UNIT_TEST(NULL, NULL,
+ cmocka_unit_test(empty_list),
+ cmocka_unit_test(non_null_list))
diff --git a/lib/pengine/tests/status/pe_new_working_set_test.c b/lib/pengine/tests/status/pe_new_working_set_test.c
new file mode 100644
index 0000000..cf2df4f
--- /dev/null
+++ b/lib/pengine/tests/status/pe_new_working_set_test.c
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2022 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 <crm/common/unittest_internal.h>
+#include <crm/pengine/internal.h>
+
+#include "mock_private.h"
+
+static void
+calloc_fails(void **state) {
+ pcmk__mock_calloc = true; // calloc() will return NULL
+
+ expect_value(__wrap_calloc, nmemb, 1);
+ expect_value(__wrap_calloc, size, sizeof(pe_working_set_t));
+ assert_null(pe_new_working_set());
+
+ pcmk__mock_calloc = false; // Use real calloc()
+}
+
+static void
+calloc_succeeds(void **state) {
+ pe_working_set_t *data_set = pe_new_working_set();
+
+ /* Nothing else to test about this function, as all it does is call
+ * set_working_set_defaults which is also a public function and should
+ * get its own unit test.
+ */
+ assert_non_null(data_set);
+
+ /* Avoid calling pe_free_working_set here so we don't artificially
+ * inflate the coverage numbers.
+ */
+ free(data_set);
+}
+
+PCMK__UNIT_TEST(NULL, NULL,
+ cmocka_unit_test(calloc_fails),
+ cmocka_unit_test(calloc_succeeds))
diff --git a/lib/pengine/tests/status/set_working_set_defaults_test.c b/lib/pengine/tests/status/set_working_set_defaults_test.c
new file mode 100644
index 0000000..c822278
--- /dev/null
+++ b/lib/pengine/tests/status/set_working_set_defaults_test.c
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2022 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 <crm/common/unittest_internal.h>
+#include <crm/pengine/internal.h>
+#include <crm/pengine/pe_types.h>
+#include <crm/pengine/status.h>
+
+#include "mock_private.h"
+
+static void
+check_defaults(void **state) {
+ uint32_t flags;
+ pe_working_set_t *data_set = calloc(1, sizeof(pe_working_set_t));
+
+ set_working_set_defaults(data_set);
+
+ flags = pe_flag_stop_rsc_orphans|pe_flag_symmetric_cluster|pe_flag_stop_action_orphans;
+
+ if (!strcmp(PCMK__CONCURRENT_FENCING_DEFAULT, "true")) {
+ flags |= pe_flag_concurrent_fencing;
+ }
+
+
+ assert_null(data_set->priv);
+ assert_int_equal(data_set->order_id, 1);
+ assert_int_equal(data_set->action_id, 1);
+ assert_int_equal(data_set->no_quorum_policy, no_quorum_stop);
+ assert_int_equal(data_set->flags, flags);
+
+ /* Avoid calling pe_free_working_set here so we don't artificially
+ * inflate the coverage numbers.
+ */
+ free(data_set);
+}
+
+PCMK__UNIT_TEST(NULL, NULL,
+ cmocka_unit_test(check_defaults))