summaryrefslogtreecommitdiffstats
path: root/lib/pengine/tests/utils
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/utils
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/utils')
-rw-r--r--lib/pengine/tests/utils/Makefile.am21
-rw-r--r--lib/pengine/tests/utils/pe__cmp_node_name_test.c55
-rw-r--r--lib/pengine/tests/utils/pe__cmp_rsc_priority_test.c50
3 files changed, 126 insertions, 0 deletions
diff --git a/lib/pengine/tests/utils/Makefile.am b/lib/pengine/tests/utils/Makefile.am
new file mode 100644
index 0000000..4a3e8a2
--- /dev/null
+++ b/lib/pengine/tests/utils/Makefile.am
@@ -0,0 +1,21 @@
+#
+# 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
+
+AM_CPPFLAGS += -I$(top_srcdir)/lib/pengine
+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__cmp_node_name_test \
+ pe__cmp_rsc_priority_test
+
+TESTS = $(check_PROGRAMS)
diff --git a/lib/pengine/tests/utils/pe__cmp_node_name_test.c b/lib/pengine/tests/utils/pe__cmp_node_name_test.c
new file mode 100644
index 0000000..45d87ee
--- /dev/null
+++ b/lib/pengine/tests/utils/pe__cmp_node_name_test.c
@@ -0,0 +1,55 @@
+/*
+ * 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>
+
+struct pe_node_shared_s node1_details;
+struct pe_node_shared_s node2_details;
+
+pe_node_t node1 = {.details = &node1_details};
+pe_node_t node2 = {.details = &node2_details};
+
+static void
+nodes_equal(void **state)
+{
+ assert_int_equal(pe__cmp_node_name(NULL, NULL), 0);
+
+ node1.details->uname = "node10";
+ node2.details->uname = "node10";
+ assert_int_equal(pe__cmp_node_name(&node1, &node2), 0);
+}
+
+static void
+node1_first(void **state)
+{
+ assert_int_equal(pe__cmp_node_name(NULL, &node2), -1);
+
+ // The heavy testing is done in pcmk__numeric_strcasecmp()'s unit tests
+ node1.details->uname = "node9";
+ node2.details->uname = "node10";
+ assert_int_equal(pe__cmp_node_name(&node1, &node2), -1);
+}
+
+static void
+node2_first(void **state)
+{
+ assert_int_equal(pe__cmp_node_name(&node1, NULL), 1);
+
+ node1.details->uname = "node10";
+ node2.details->uname = "node9";
+ assert_int_equal(pe__cmp_node_name(&node1, &node2), 1);
+}
+
+PCMK__UNIT_TEST(NULL, NULL,
+ cmocka_unit_test(nodes_equal),
+ cmocka_unit_test(node1_first),
+ cmocka_unit_test(node2_first))
diff --git a/lib/pengine/tests/utils/pe__cmp_rsc_priority_test.c b/lib/pengine/tests/utils/pe__cmp_rsc_priority_test.c
new file mode 100644
index 0000000..669e7a9
--- /dev/null
+++ b/lib/pengine/tests/utils/pe__cmp_rsc_priority_test.c
@@ -0,0 +1,50 @@
+/*
+ * 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 "pe_status_private.h"
+
+pe_resource_t rsc1;
+pe_resource_t rsc2;
+
+static void
+rscs_equal(void **state)
+{
+ rsc1.priority = 0;
+ rsc2.priority = 0;
+ assert_int_equal(pe__cmp_rsc_priority(NULL, NULL), 0);
+ assert_int_equal(pe__cmp_rsc_priority(&rsc1, &rsc2), 0);
+}
+
+static void
+rsc1_first(void **state)
+{
+ rsc1.priority = 1;
+ rsc2.priority = 0;
+ assert_int_equal(pe__cmp_rsc_priority(&rsc1, NULL), -1);
+ assert_int_equal(pe__cmp_rsc_priority(&rsc1, &rsc2), -1);
+}
+
+static void
+rsc2_first(void **state)
+{
+ rsc1.priority = 0;
+ rsc2.priority = 1;
+ assert_int_equal(pe__cmp_rsc_priority(NULL, &rsc2), 1);
+ assert_int_equal(pe__cmp_rsc_priority(&rsc1, &rsc2), 1);
+}
+
+PCMK__UNIT_TEST(NULL, NULL,
+ cmocka_unit_test(rscs_equal),
+ cmocka_unit_test(rsc1_first),
+ cmocka_unit_test(rsc2_first))