summaryrefslogtreecommitdiffstats
path: root/lib/common/tests/utils
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 13:39:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 13:39:29 +0000
commitb41961d74fe7ff2d4d4abaca92454e87c561e49f (patch)
treeb34e3826a7b649dafdbd05081140c990c96d736d /lib/common/tests/utils
parentReleasing progress-linux version 2.1.7-1~progress7.99u1. (diff)
downloadpacemaker-b41961d74fe7ff2d4d4abaca92454e87c561e49f.tar.xz
pacemaker-b41961d74fe7ff2d4d4abaca92454e87c561e49f.zip
Merging upstream version 2.1.8~rc1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/common/tests/utils')
-rw-r--r--lib/common/tests/utils/Makefile.am11
-rw-r--r--lib/common/tests/utils/compare_version_test.c5
-rw-r--r--lib/common/tests/utils/crm_meta_name_test.c41
-rw-r--r--lib/common/tests/utils/crm_meta_value_test.c56
-rw-r--r--lib/common/tests/utils/pcmk__realloc_test.c69
-rw-r--r--lib/common/tests/utils/pcmk_hostname_test.c56
6 files changed, 76 insertions, 162 deletions
diff --git a/lib/common/tests/utils/Makefile.am b/lib/common/tests/utils/Makefile.am
index f028ce4..fb9d5c3 100644
--- a/lib/common/tests/utils/Makefile.am
+++ b/lib/common/tests/utils/Makefile.am
@@ -1,5 +1,5 @@
#
-# Copyright 2020-2023 the Pacemaker project contributors
+# Copyright 2020-2024 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
@@ -12,8 +12,6 @@ include $(top_srcdir)/mk/unittest.mk
# Add "_test" to the end of all test program names to simplify .gitignore.
check_PROGRAMS = compare_version_test \
- crm_meta_name_test \
- crm_meta_value_test \
crm_user_lookup_test \
pcmk_daemon_user_test \
pcmk_str_is_infinity_test \
@@ -21,10 +19,7 @@ check_PROGRAMS = compare_version_test \
pcmk__fail_attr_name_test \
pcmk__failcount_name_test \
pcmk__getpid_s_test \
- pcmk__lastfailure_name_test
-
-if WRAPPABLE_UNAME
-check_PROGRAMS += pcmk_hostname_test
-endif
+ pcmk__lastfailure_name_test \
+ pcmk__realloc_test
TESTS = $(check_PROGRAMS)
diff --git a/lib/common/tests/utils/compare_version_test.c b/lib/common/tests/utils/compare_version_test.c
index 35ebb63..d191f4a 100644
--- a/lib/common/tests/utils/compare_version_test.c
+++ b/lib/common/tests/utils/compare_version_test.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2022 the Pacemaker project contributors
+ * Copyright 2022-2023 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -46,6 +46,9 @@ shorter_versions(void **state)
{
assert_int_equal(compare_version("1.0", "1.0.1"), -1);
assert_int_equal(compare_version("1.0.1", "1.0"), 1);
+ assert_int_equal(compare_version("1.0", "1"), 0);
+ assert_int_equal(compare_version("1", "1.2"), -1);
+ assert_int_equal(compare_version("1.2", "1"), 1);
}
PCMK__UNIT_TEST(NULL, NULL,
diff --git a/lib/common/tests/utils/crm_meta_name_test.c b/lib/common/tests/utils/crm_meta_name_test.c
deleted file mode 100644
index 06fecc5..0000000
--- a/lib/common/tests/utils/crm_meta_name_test.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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/msg_xml.h>
-
-static void
-empty_params(void **state)
-{
- assert_null(crm_meta_name(NULL));
-}
-
-static void
-standard_usage(void **state)
-{
- char *s = NULL;
-
- s = crm_meta_name(XML_RSC_ATTR_NOTIFY);
- assert_string_equal(s, "CRM_meta_notify");
- free(s);
-
- s = crm_meta_name(XML_RSC_ATTR_STICKINESS);
- assert_string_equal(s, "CRM_meta_resource_stickiness");
- free(s);
-
- s = crm_meta_name("blah");
- assert_string_equal(s, "CRM_meta_blah");
- free(s);
-}
-
-PCMK__UNIT_TEST(NULL, NULL,
- cmocka_unit_test(empty_params),
- cmocka_unit_test(standard_usage))
diff --git a/lib/common/tests/utils/crm_meta_value_test.c b/lib/common/tests/utils/crm_meta_value_test.c
deleted file mode 100644
index 0bde5c6..0000000
--- a/lib/common/tests/utils/crm_meta_value_test.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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/msg_xml.h>
-
-#include <glib.h>
-
-static void
-empty_params(void **state)
-{
- GHashTable *tbl = pcmk__strkey_table(free, free);
-
- assert_null(crm_meta_value(NULL, NULL));
- assert_null(crm_meta_value(tbl, NULL));
-
- g_hash_table_destroy(tbl);
-}
-
-static void
-key_not_in_table(void **state)
-{
- GHashTable *tbl = pcmk__strkey_table(free, free);
-
- assert_null(crm_meta_value(tbl, XML_RSC_ATTR_NOTIFY));
- assert_null(crm_meta_value(tbl, XML_RSC_ATTR_STICKINESS));
-
- g_hash_table_destroy(tbl);
-}
-
-static void
-key_in_table(void **state)
-{
- GHashTable *tbl = pcmk__strkey_table(free, free);
-
- g_hash_table_insert(tbl, crm_meta_name(XML_RSC_ATTR_NOTIFY), strdup("1"));
- g_hash_table_insert(tbl, crm_meta_name(XML_RSC_ATTR_STICKINESS), strdup("2"));
-
- assert_string_equal(crm_meta_value(tbl, XML_RSC_ATTR_NOTIFY), "1");
- assert_string_equal(crm_meta_value(tbl, XML_RSC_ATTR_STICKINESS), "2");
-
- g_hash_table_destroy(tbl);
-}
-
-PCMK__UNIT_TEST(NULL, NULL,
- cmocka_unit_test(empty_params),
- cmocka_unit_test(key_not_in_table),
- cmocka_unit_test(key_in_table))
diff --git a/lib/common/tests/utils/pcmk__realloc_test.c b/lib/common/tests/utils/pcmk__realloc_test.c
new file mode 100644
index 0000000..62d51df
--- /dev/null
+++ b/lib/common/tests/utils/pcmk__realloc_test.c
@@ -0,0 +1,69 @@
+/*
+ * 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 <crm/common/unittest_internal.h>
+
+#include "mock_private.h"
+
+static void
+bad_size(void **state)
+{
+ char *ptr = NULL;
+
+ pcmk__assert_asserts(pcmk__realloc(ptr, 0));
+}
+
+static void
+realloc_fails(void **state)
+{
+ char *ptr = NULL;
+
+ pcmk__assert_aborts(
+ {
+ pcmk__mock_realloc = true; // realloc() will return NULL
+ expect_any(__wrap_realloc, ptr);
+ expect_value(__wrap_realloc, size, 1000);
+ pcmk__realloc(ptr, 1000);
+ pcmk__mock_realloc = false; // Use real realloc()
+ }
+ );
+}
+
+static void
+realloc_succeeds(void **state)
+{
+ char *ptr = NULL;
+
+ /* We can't really test that the resulting pointer is the size we asked
+ * for - it might be larger if that's what the memory allocator decides
+ * to do. And anyway, testing realloc isn't really the point. All we
+ * want to do here is make sure the function works when given good input.
+ */
+
+ /* Allocate new memory */
+ ptr = pcmk__realloc(ptr, 1000);
+ assert_non_null(ptr);
+
+ /* Grow previously allocated memory */
+ ptr = pcmk__realloc(ptr, 2000);
+ assert_non_null(ptr);
+
+ /* Shrink previously allocated memory */
+ ptr = pcmk__realloc(ptr, 500);
+ assert_non_null(ptr);
+
+ free(ptr);
+}
+
+PCMK__UNIT_TEST(NULL, NULL,
+ cmocka_unit_test(bad_size),
+ cmocka_unit_test(realloc_fails),
+ cmocka_unit_test(realloc_succeeds))
diff --git a/lib/common/tests/utils/pcmk_hostname_test.c b/lib/common/tests/utils/pcmk_hostname_test.c
deleted file mode 100644
index 7329486..0000000
--- a/lib/common/tests/utils/pcmk_hostname_test.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2021 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 "mock_private.h"
-
-#include <sys/utsname.h>
-
-static void
-uname_succeeded_test(void **state)
-{
- char *retval;
-
- // Set uname() return value and buf parameter node name
- pcmk__mock_uname = true;
-
- expect_any(__wrap_uname, buf);
- will_return(__wrap_uname, 0);
- will_return(__wrap_uname, "somename");
-
- retval = pcmk_hostname();
- assert_non_null(retval);
- assert_string_equal("somename", retval);
-
- free(retval);
-
- pcmk__mock_uname = false;
-}
-
-static void
-uname_failed_test(void **state)
-{
- // Set uname() return value and buf parameter node name
- pcmk__mock_uname = true;
-
- expect_any(__wrap_uname, buf);
- will_return(__wrap_uname, -1);
- will_return(__wrap_uname, NULL);
-
- assert_null(pcmk_hostname());
-
- pcmk__mock_uname = false;
-}
-
-PCMK__UNIT_TEST(NULL, NULL,
- cmocka_unit_test(uname_succeeded_test),
- cmocka_unit_test(uname_failed_test))