diff options
Diffstat (limited to 'lib/common/tests/scheduler')
-rw-r--r-- | lib/common/tests/scheduler/Makefile.am | 19 | ||||
-rw-r--r-- | lib/common/tests/scheduler/pcmk_get_dc_test.c | 47 | ||||
-rw-r--r-- | lib/common/tests/scheduler/pcmk_get_no_quorum_policy_test.c | 34 | ||||
-rw-r--r-- | lib/common/tests/scheduler/pcmk_has_quorum_test.c | 36 | ||||
-rw-r--r-- | lib/common/tests/scheduler/pcmk_set_scheduler_cib_test.c | 71 |
5 files changed, 207 insertions, 0 deletions
diff --git a/lib/common/tests/scheduler/Makefile.am b/lib/common/tests/scheduler/Makefile.am new file mode 100644 index 0000000..6d5f4f8 --- /dev/null +++ b/lib/common/tests/scheduler/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 + +# Add "_test" to the end of all test program names to simplify .gitignore. +check_PROGRAMS = pcmk_get_dc_test \ + pcmk_get_no_quorum_policy_test \ + pcmk_has_quorum_test \ + pcmk_set_scheduler_cib_test + +TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/scheduler/pcmk_get_dc_test.c b/lib/common/tests/scheduler/pcmk_get_dc_test.c new file mode 100644 index 0000000..5d9d459 --- /dev/null +++ b/lib/common/tests/scheduler/pcmk_get_dc_test.c @@ -0,0 +1,47 @@ +/* + * 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/scheduler.h> +#include <crm/common/unittest_internal.h> + +static void +null_scheduler(void **state) +{ + assert_null(pcmk_get_dc(NULL)); +} + +static void +null_dc(void **state) +{ + pcmk_scheduler_t scheduler = { + .dc_node = NULL, + }; + + assert_null(pcmk_get_dc(&scheduler)); +} + +static void +valid_dc(void **state) +{ + pcmk_node_t dc = { + .weight = 1, + }; + pcmk_scheduler_t scheduler = { + .dc_node = &dc, + }; + + assert_ptr_equal(&dc, pcmk_get_dc(&scheduler)); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(null_scheduler), + cmocka_unit_test(null_dc), + cmocka_unit_test(valid_dc)) diff --git a/lib/common/tests/scheduler/pcmk_get_no_quorum_policy_test.c b/lib/common/tests/scheduler/pcmk_get_no_quorum_policy_test.c new file mode 100644 index 0000000..61c97e6 --- /dev/null +++ b/lib/common/tests/scheduler/pcmk_get_no_quorum_policy_test.c @@ -0,0 +1,34 @@ +/* + * 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/scheduler.h> +#include <crm/common/unittest_internal.h> + +static void +null_scheduler(void **state) +{ + assert_int_equal(pcmk_get_no_quorum_policy(NULL), pcmk_no_quorum_stop); +} + +static void +valid_no_quorum_policy(void **state) +{ + pcmk_scheduler_t scheduler = { + .no_quorum_policy = pcmk_no_quorum_fence, + }; + + assert_int_equal(pcmk_get_no_quorum_policy(&scheduler), + pcmk_no_quorum_fence); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(null_scheduler), + cmocka_unit_test(valid_no_quorum_policy)) diff --git a/lib/common/tests/scheduler/pcmk_has_quorum_test.c b/lib/common/tests/scheduler/pcmk_has_quorum_test.c new file mode 100644 index 0000000..51903df --- /dev/null +++ b/lib/common/tests/scheduler/pcmk_has_quorum_test.c @@ -0,0 +1,36 @@ +/* + * 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/scheduler.h> +#include <crm/common/unittest_internal.h> + +static void +null_scheduler(void **state) +{ + assert_false(pcmk_has_quorum(NULL)); +} + +static void +valid_scheduler(void **state) +{ + pcmk_scheduler_t scheduler = { + .flags = pcmk_sched_quorate, + }; + + assert_true(pcmk_has_quorum(&scheduler)); + + scheduler.flags = pcmk_sched_none; + assert_false(pcmk_has_quorum(&scheduler)); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(null_scheduler), + cmocka_unit_test(valid_scheduler)) diff --git a/lib/common/tests/scheduler/pcmk_set_scheduler_cib_test.c b/lib/common/tests/scheduler/pcmk_set_scheduler_cib_test.c new file mode 100644 index 0000000..71e690b --- /dev/null +++ b/lib/common/tests/scheduler/pcmk_set_scheduler_cib_test.c @@ -0,0 +1,71 @@ +/* + * 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/scheduler.h> +#include <crm/common/unittest_internal.h> + +static void +null_scheduler(void **state) +{ + xmlNode *cib = pcmk__xe_create(NULL, "test"); + + assert_int_equal(pcmk_set_scheduler_cib(NULL, NULL), EINVAL); + assert_int_equal(pcmk_set_scheduler_cib(NULL, cib), EINVAL); + + free_xml(cib); +} + +static void +null_cib(void **state) +{ + pcmk_scheduler_t scheduler = { + .input = NULL, + }; + + assert_int_equal(pcmk_set_scheduler_cib(&scheduler, NULL), pcmk_rc_ok); + assert_null(scheduler.input); +} + +static void +previous_cib_null(void **state) +{ + pcmk_scheduler_t scheduler = { + .input = NULL, + }; + xmlNode *cib = pcmk__xe_create(NULL, "test"); + + assert_int_equal(pcmk_set_scheduler_cib(&scheduler, cib), pcmk_rc_ok); + assert_ptr_equal(scheduler.input, cib); + + free_xml(cib); +} + +static void +previous_cib_nonnull(void **state) +{ + xmlNode *old_cib = pcmk__xe_create(NULL, "old"); + xmlNode *new_cib = pcmk__xe_create(NULL, "new"); + pcmk_scheduler_t scheduler = { + .input = old_cib, + }; + + assert_int_equal(pcmk_set_scheduler_cib(&scheduler, new_cib), pcmk_rc_ok); + assert_ptr_equal(scheduler.input, new_cib); + + free_xml(old_cib); + free_xml(new_cib); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(null_scheduler), + cmocka_unit_test(null_cib), + cmocka_unit_test(previous_cib_null), + cmocka_unit_test(previous_cib_nonnull)) |