diff options
Diffstat (limited to 'lib/pengine/tests')
-rw-r--r-- | lib/pengine/tests/Makefile.am | 6 | ||||
-rw-r--r-- | lib/pengine/tests/native/native_find_rsc_test.c | 14 | ||||
-rw-r--r-- | lib/pengine/tests/native/pe_base_name_eq_test.c | 6 | ||||
-rw-r--r-- | lib/pengine/tests/rules/Makefile.am | 18 | ||||
-rw-r--r-- | lib/pengine/tests/rules/pe_cron_range_satisfied_test.c | 165 | ||||
-rw-r--r-- | lib/pengine/tests/status/Makefile.am | 3 | ||||
-rw-r--r-- | lib/pengine/tests/status/pe_find_node_any_test.c | 10 | ||||
-rw-r--r-- | lib/pengine/tests/status/pe_find_node_id_test.c | 10 | ||||
-rw-r--r-- | lib/pengine/tests/status/pe_find_node_test.c | 51 | ||||
-rw-r--r-- | lib/pengine/tests/status/set_working_set_defaults_test.c | 7 |
10 files changed, 28 insertions, 262 deletions
diff --git a/lib/pengine/tests/Makefile.am b/lib/pengine/tests/Makefile.am index 48ec5b4..52a0ff6 100644 --- a/lib/pengine/tests/Makefile.am +++ b/lib/pengine/tests/Makefile.am @@ -1,14 +1,14 @@ # -# 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. # # This source code is licensed under the GNU General Public License version 2 # or later (GPLv2+) WITHOUT ANY WARRANTY. # +MAINTAINERCLEANFILES = Makefile.in -SUBDIRS = rules \ - native \ +SUBDIRS = native \ status \ unpack \ utils diff --git a/lib/pengine/tests/native/native_find_rsc_test.c b/lib/pengine/tests/native/native_find_rsc_test.c index b85ca24..ac1337d 100644 --- a/lib/pengine/tests/native/native_find_rsc_test.c +++ b/lib/pengine/tests/native/native_find_rsc_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the Pacemaker project contributors + * Copyright 2022-2024 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -30,7 +30,7 @@ setup(void **state) { crm_xml_init(); path = crm_strdup_printf("%s/crm_mon.xml", getenv("PCMK_CTS_CLI_DIR")); - input = filename2xml(path); + input = pcmk__xml_read(path); free(path); if (input == NULL) { @@ -43,16 +43,16 @@ setup(void **state) { return 1; } - pe__set_working_set_flags(scheduler, + pcmk__set_scheduler_flags(scheduler, pcmk_sched_no_counts|pcmk_sched_no_compat); scheduler->input = input; cluster_status(scheduler); /* Get references to the cluster nodes so we don't have to find them repeatedly. */ - cluster01 = pe_find_node(scheduler->nodes, "cluster01"); - cluster02 = pe_find_node(scheduler->nodes, "cluster02"); - httpd_bundle_0 = pe_find_node(scheduler->nodes, "httpd-bundle-0"); + cluster01 = pcmk_find_node(scheduler, "cluster01"); + cluster02 = pcmk_find_node(scheduler, "cluster02"); + httpd_bundle_0 = pcmk_find_node(scheduler, "httpd-bundle-0"); /* Get references to several resources we use frequently. */ for (GList *iter = scheduler->resources; iter != NULL; iter = iter->next) { @@ -539,7 +539,7 @@ bundle_rsc(void **state) { } static bool -bundle_first_replica(pe__bundle_replica_t *replica, void *user_data) +bundle_first_replica(pcmk__bundle_replica_t *replica, void *user_data) { pcmk_resource_t *ip_0 = replica->ip; pcmk_resource_t *child_0 = replica->child; diff --git a/lib/pengine/tests/native/pe_base_name_eq_test.c b/lib/pengine/tests/native/pe_base_name_eq_test.c index cb3c908..68112bb 100644 --- a/lib/pengine/tests/native/pe_base_name_eq_test.c +++ b/lib/pengine/tests/native/pe_base_name_eq_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the Pacemaker project contributors + * Copyright 2022-2024 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -29,7 +29,7 @@ setup(void **state) { crm_xml_init(); path = crm_strdup_printf("%s/crm_mon.xml", getenv("PCMK_CTS_CLI_DIR")); - input = filename2xml(path); + input = pcmk__xml_read(path); free(path); if (input == NULL) { @@ -42,7 +42,7 @@ setup(void **state) { return 1; } - pe__set_working_set_flags(scheduler, + pcmk__set_scheduler_flags(scheduler, pcmk_sched_no_counts|pcmk_sched_no_compat); scheduler->input = input; diff --git a/lib/pengine/tests/rules/Makefile.am b/lib/pengine/tests/rules/Makefile.am deleted file mode 100644 index 261ec16..0000000 --- a/lib/pengine/tests/rules/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -# -# Copyright 2020-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 $(top_srcdir)/mk/tap.mk -include $(top_srcdir)/mk/unittest.mk - -LDADD += $(top_builddir)/lib/pengine/libpe_rules_test.la - -# Add "_test" to the end of all test program names to simplify .gitignore. -check_PROGRAMS = pe_cron_range_satisfied_test - -TESTS = $(check_PROGRAMS) diff --git a/lib/pengine/tests/rules/pe_cron_range_satisfied_test.c b/lib/pengine/tests/rules/pe_cron_range_satisfied_test.c deleted file mode 100644 index a8ba6cf..0000000 --- a/lib/pengine/tests/rules/pe_cron_range_satisfied_test.c +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright 2020-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 <glib.h> - -#include <crm/msg_xml.h> -#include <crm/common/unittest_internal.h> -#include <crm/common/xml.h> -#include <crm/pengine/rules_internal.h> - -static void -run_one_test(const char *t, const char *x, int expected) { - crm_time_t *tm = crm_time_new(t); - xmlNodePtr xml = string2xml(x); - - assert_int_equal(pe_cron_range_satisfied(tm, xml), expected); - - crm_time_free(tm); - free_xml(xml); -} - -static void -no_time_given(void **state) { - assert_int_equal(pe_cron_range_satisfied(NULL, NULL), pcmk_rc_op_unsatisfied); -} - -static void -any_time_satisfies_empty_spec(void **state) { - crm_time_t *tm = crm_time_new(NULL); - - assert_int_equal(pe_cron_range_satisfied(tm, NULL), pcmk_rc_ok); - - crm_time_free(tm); -} - -static void -time_satisfies_year_spec(void **state) { - run_one_test("2020-01-01", - "<date_spec " XML_ATTR_ID "='spec' years='2020'/>", - pcmk_rc_ok); -} - -static void -time_after_year_spec(void **state) { - run_one_test("2020-01-01", - "<date_spec " XML_ATTR_ID "='spec' years='2019'/>", - pcmk_rc_after_range); -} - -static void -time_satisfies_year_range(void **state) { - run_one_test("2020-01-01", - "<date_spec " XML_ATTR_ID "='spec' years='2010-2030'/>", - pcmk_rc_ok); -} - -static void -time_before_year_range(void **state) { - run_one_test("2000-01-01", - "<date_spec " XML_ATTR_ID "='spec' years='2010-2030'/>", - pcmk_rc_before_range); -} - -static void -time_after_year_range(void **state) { - run_one_test("2020-01-01", - "<date_spec " XML_ATTR_ID "='spec' years='2010-2015'/>", - pcmk_rc_after_range); -} - -static void -range_without_start_year_passes(void **state) { - run_one_test("2010-01-01", - "<date_spec " XML_ATTR_ID "='spec' years='-2020'/>", - pcmk_rc_ok); -} - -static void -range_without_end_year_passes(void **state) { - run_one_test("2010-01-01", - "<date_spec " XML_ATTR_ID "='spec' years='2000-'/>", - pcmk_rc_ok); - run_one_test("2000-10-01", - "<date_spec " XML_ATTR_ID "='spec' years='2000-'/>", - pcmk_rc_ok); -} - -static void -yeardays_satisfies(void **state) { - run_one_test("2020-01-30", - "<date_spec " XML_ATTR_ID "='spec' yeardays='30'/>", - pcmk_rc_ok); -} - -static void -time_after_yeardays_spec(void **state) { - run_one_test("2020-02-15", - "<date_spec " XML_ATTR_ID "='spec' yeardays='40'/>", - pcmk_rc_after_range); -} - -static void -yeardays_feb_29_satisfies(void **state) { - run_one_test("2016-02-29", - "<date_spec " XML_ATTR_ID "='spec' yeardays='60'/>", - pcmk_rc_ok); -} - -static void -exact_ymd_satisfies(void **state) { - run_one_test("2001-12-31", - "<date_spec " XML_ATTR_ID "='spec' years='2001' months='12' " - "monthdays='31'/>", - pcmk_rc_ok); -} - -static void -range_in_month_satisfies(void **state) { - run_one_test("2001-06-10", - "<date_spec " XML_ATTR_ID "='spec' years='2001' months='6' " - "monthdays='1-10'/>", - pcmk_rc_ok); -} - -static void -exact_ymd_after_range(void **state) { - run_one_test("2001-12-31", - "<date_spec " XML_ATTR_ID "='spec' years='2001' months='12' " - "monthdays='30'/>", - pcmk_rc_after_range); -} - -static void -time_after_monthdays_range(void **state) { - run_one_test("2001-06-10", - "<date_spec " XML_ATTR_ID "='spec' years='2001' months='6' " - "monthdays='11-15'/>", - pcmk_rc_before_range); -} - -PCMK__UNIT_TEST(NULL, NULL, - cmocka_unit_test(no_time_given), - cmocka_unit_test(any_time_satisfies_empty_spec), - cmocka_unit_test(time_satisfies_year_spec), - cmocka_unit_test(time_after_year_spec), - cmocka_unit_test(time_satisfies_year_range), - cmocka_unit_test(time_before_year_range), - cmocka_unit_test(time_after_year_range), - cmocka_unit_test(range_without_start_year_passes), - cmocka_unit_test(range_without_end_year_passes), - cmocka_unit_test(yeardays_satisfies), - cmocka_unit_test(time_after_yeardays_spec), - cmocka_unit_test(yeardays_feb_29_satisfies), - cmocka_unit_test(exact_ymd_satisfies), - cmocka_unit_test(range_in_month_satisfies), - cmocka_unit_test(exact_ymd_after_range), - cmocka_unit_test(time_after_monthdays_range)) diff --git a/lib/pengine/tests/status/Makefile.am b/lib/pengine/tests/status/Makefile.am index c7ddb70..f91d150 100644 --- a/lib/pengine/tests/status/Makefile.am +++ b/lib/pengine/tests/status/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2022-2023 the Pacemaker project contributors +# Copyright 2022-2024 the Pacemaker project contributors # # The version control history for this file may have further details. # @@ -15,7 +15,6 @@ 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 diff --git a/lib/pengine/tests/status/pe_find_node_any_test.c b/lib/pengine/tests/status/pe_find_node_any_test.c index 5f5a27e..bbe046b 100644 --- a/lib/pengine/tests/status/pe_find_node_any_test.c +++ b/lib/pengine/tests/status/pe_find_node_any_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the Pacemaker project contributors + * Copyright 2022-2024 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -24,13 +24,13 @@ static void non_null_list(void **state) { GList *nodes = NULL; - pcmk_node_t *a = calloc(1, sizeof(pcmk_node_t)); - pcmk_node_t *b = calloc(1, sizeof(pcmk_node_t)); + pcmk_node_t *a = pcmk__assert_alloc(1, sizeof(pcmk_node_t)); + pcmk_node_t *b = pcmk__assert_alloc(1, sizeof(pcmk_node_t)); - a->details = calloc(1, sizeof(struct pe_node_shared_s)); + a->details = pcmk__assert_alloc(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 = pcmk__assert_alloc(1, sizeof(struct pe_node_shared_s)); b->details->uname = "cluster2"; b->details->id = "id2"; diff --git a/lib/pengine/tests/status/pe_find_node_id_test.c b/lib/pengine/tests/status/pe_find_node_id_test.c index c6b8773..694d760 100644 --- a/lib/pengine/tests/status/pe_find_node_id_test.c +++ b/lib/pengine/tests/status/pe_find_node_id_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the Pacemaker project contributors + * Copyright 2022-2024 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -22,12 +22,12 @@ static void non_null_list(void **state) { GList *nodes = NULL; - pcmk_node_t *a = calloc(1, sizeof(pcmk_node_t)); - pcmk_node_t *b = calloc(1, sizeof(pcmk_node_t)); + pcmk_node_t *a = pcmk__assert_alloc(1, sizeof(pcmk_node_t)); + pcmk_node_t *b = pcmk__assert_alloc(1, sizeof(pcmk_node_t)); - a->details = calloc(1, sizeof(struct pe_node_shared_s)); + a->details = pcmk__assert_alloc(1, sizeof(struct pe_node_shared_s)); a->details->id = "id1"; - b->details = calloc(1, sizeof(struct pe_node_shared_s)); + b->details = pcmk__assert_alloc(1, sizeof(struct pe_node_shared_s)); b->details->id = "id2"; nodes = g_list_append(nodes, a); diff --git a/lib/pengine/tests/status/pe_find_node_test.c b/lib/pengine/tests/status/pe_find_node_test.c deleted file mode 100644 index 305ddc9..0000000 --- a/lib/pengine/tests/status/pe_find_node_test.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2022-2023 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; - - pcmk_node_t *a = calloc(1, sizeof(pcmk_node_t)); - pcmk_node_t *b = calloc(1, sizeof(pcmk_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/set_working_set_defaults_test.c b/lib/pengine/tests/status/set_working_set_defaults_test.c index 7045a33..546cd8a 100644 --- a/lib/pengine/tests/status/set_working_set_defaults_test.c +++ b/lib/pengine/tests/status/set_working_set_defaults_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2023 the Pacemaker project contributors + * Copyright 2024 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -20,7 +20,8 @@ static void check_defaults(void **state) { uint32_t flags; - pcmk_scheduler_t *scheduler = calloc(1, sizeof(pcmk_scheduler_t)); + pcmk_scheduler_t *scheduler = pcmk__assert_alloc(1, + sizeof(pcmk_scheduler_t)); set_working_set_defaults(scheduler); @@ -28,7 +29,7 @@ check_defaults(void **state) { |pcmk_sched_stop_removed_resources |pcmk_sched_cancel_removed_actions; - if (!strcmp(PCMK__CONCURRENT_FENCING_DEFAULT, "true")) { + if (!strcmp(PCMK__CONCURRENT_FENCING_DEFAULT, PCMK_VALUE_TRUE)) { flags |= pcmk_sched_concurrent_fencing; } |