From 07d7f4cfa4b10de87a31b68191036ff446add675 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 09:45:40 +0200 Subject: Adding upstream version 2.1.7. Signed-off-by: Daniel Baumann --- lib/common/tests/Makefile.am | 4 +- lib/common/tests/acl/Makefile.am | 11 +- lib/common/tests/actions/Makefile.am | 22 ++ lib/common/tests/actions/copy_in_properties_test.c | 62 +++++ lib/common/tests/actions/expand_plus_plus_test.c | 256 +++++++++++++++++++ .../tests/actions/fix_plus_plus_recursive_test.c | 47 ++++ lib/common/tests/actions/parse_op_key_test.c | 275 +++++++++++++++++++++ lib/common/tests/actions/pcmk_is_probe_test.c | 25 ++ lib/common/tests/actions/pcmk_xe_is_probe_test.c | 43 ++++ .../actions/pcmk_xe_mask_probe_failure_test.c | 150 +++++++++++ lib/common/tests/agents/Makefile.am | 12 +- .../tests/agents/crm_parse_agent_spec_test.c | 18 +- lib/common/tests/cmdline/Makefile.am | 5 +- .../tests/cmdline/pcmk__cmdline_preproc_test.c | 13 +- .../tests/cmdline/pcmk__new_common_args_test.c | 62 +++++ lib/common/tests/flags/Makefile.am | 11 +- lib/common/tests/io/Makefile.am | 7 +- lib/common/tests/lists/Makefile.am | 9 +- lib/common/tests/nvpair/Makefile.am | 8 +- lib/common/tests/operations/Makefile.am | 22 -- .../tests/operations/copy_in_properties_test.c | 62 ----- .../tests/operations/expand_plus_plus_test.c | 256 ------------------- .../operations/fix_plus_plus_recursive_test.c | 47 ---- lib/common/tests/operations/parse_op_key_test.c | 275 --------------------- lib/common/tests/operations/pcmk_is_probe_test.c | 25 -- .../tests/operations/pcmk_xe_is_probe_test.c | 43 ---- .../operations/pcmk_xe_mask_probe_failure_test.c | 150 ----------- lib/common/tests/options/Makefile.am | 9 +- .../tests/options/pcmk__set_env_option_test.c | 57 +++-- lib/common/tests/output/Makefile.am | 20 +- lib/common/tests/output/pcmk__output_new_test.c | 8 +- lib/common/tests/results/Makefile.am | 4 +- lib/common/tests/results/pcmk__results_test.c | 8 +- lib/common/tests/scores/Makefile.am | 9 +- lib/common/tests/scores/pcmk__add_scores_test.c | 4 +- lib/common/tests/strings/Makefile.am | 54 ++-- lib/common/tests/strings/pcmk__compress_test.c | 2 +- .../tests/strings/pcmk__guint_from_hash_test.c | 4 + lib/common/tests/strings/pcmk__scan_ll_test.c | 64 +++++ lib/common/tests/utils/Makefile.am | 22 +- lib/common/tests/utils/pcmk__fail_attr_name_test.c | 36 +++ lib/common/tests/utils/pcmk__failcount_name_test.c | 35 +++ .../tests/utils/pcmk__lastfailure_name_test.c | 35 +++ lib/common/tests/xml/Makefile.am | 6 +- lib/common/tests/xml/pcmk__xe_foreach_child_test.c | 13 +- lib/common/tests/xpath/Makefile.am | 4 +- 46 files changed, 1298 insertions(+), 1016 deletions(-) create mode 100644 lib/common/tests/actions/Makefile.am create mode 100644 lib/common/tests/actions/copy_in_properties_test.c create mode 100644 lib/common/tests/actions/expand_plus_plus_test.c create mode 100644 lib/common/tests/actions/fix_plus_plus_recursive_test.c create mode 100644 lib/common/tests/actions/parse_op_key_test.c create mode 100644 lib/common/tests/actions/pcmk_is_probe_test.c create mode 100644 lib/common/tests/actions/pcmk_xe_is_probe_test.c create mode 100644 lib/common/tests/actions/pcmk_xe_mask_probe_failure_test.c create mode 100644 lib/common/tests/cmdline/pcmk__new_common_args_test.c delete mode 100644 lib/common/tests/operations/Makefile.am delete mode 100644 lib/common/tests/operations/copy_in_properties_test.c delete mode 100644 lib/common/tests/operations/expand_plus_plus_test.c delete mode 100644 lib/common/tests/operations/fix_plus_plus_recursive_test.c delete mode 100644 lib/common/tests/operations/parse_op_key_test.c delete mode 100644 lib/common/tests/operations/pcmk_is_probe_test.c delete mode 100644 lib/common/tests/operations/pcmk_xe_is_probe_test.c delete mode 100644 lib/common/tests/operations/pcmk_xe_mask_probe_failure_test.c create mode 100644 lib/common/tests/strings/pcmk__scan_ll_test.c create mode 100644 lib/common/tests/utils/pcmk__fail_attr_name_test.c create mode 100644 lib/common/tests/utils/pcmk__failcount_name_test.c create mode 100644 lib/common/tests/utils/pcmk__lastfailure_name_test.c (limited to 'lib/common/tests') diff --git a/lib/common/tests/Makefile.am b/lib/common/tests/Makefile.am index b147309..c0407e5 100644 --- a/lib/common/tests/Makefile.am +++ b/lib/common/tests/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2020-2022 the Pacemaker project contributors +# Copyright 2020-2023 the Pacemaker project contributors # # The version control history for this file may have further details. # @@ -9,6 +9,7 @@ SUBDIRS = \ acl \ + actions \ agents \ cmdline \ flags \ @@ -17,7 +18,6 @@ SUBDIRS = \ iso8601 \ lists \ nvpair \ - operations \ options \ output \ results \ diff --git a/lib/common/tests/acl/Makefile.am b/lib/common/tests/acl/Makefile.am index 50408f9..19903db 100644 --- a/lib/common/tests/acl/Makefile.am +++ b/lib/common/tests/acl/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2021-2022 the Pacemaker project contributors +# Copyright 2021-2023 the Pacemaker project contributors # # The version control history for this file may have further details. # @@ -12,10 +12,9 @@ include $(top_srcdir)/mk/unittest.mk # Add "_test" to the end of all test program names to simplify .gitignore. -check_PROGRAMS = \ - pcmk__is_user_in_group_test \ - pcmk_acl_required_test \ - xml_acl_denied_test \ - xml_acl_enabled_test +check_PROGRAMS = pcmk__is_user_in_group_test \ + pcmk_acl_required_test \ + xml_acl_denied_test \ + xml_acl_enabled_test TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/actions/Makefile.am b/lib/common/tests/actions/Makefile.am new file mode 100644 index 0000000..6890b84 --- /dev/null +++ b/lib/common/tests/actions/Makefile.am @@ -0,0 +1,22 @@ +# +# Copyright 2020-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 $(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 = copy_in_properties_test \ + expand_plus_plus_test \ + fix_plus_plus_recursive_test \ + parse_op_key_test \ + pcmk_is_probe_test \ + pcmk_xe_is_probe_test \ + pcmk_xe_mask_probe_failure_test + +TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/actions/copy_in_properties_test.c b/lib/common/tests/actions/copy_in_properties_test.c new file mode 100644 index 0000000..7882551 --- /dev/null +++ b/lib/common/tests/actions/copy_in_properties_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 + +#include + +#include + +static void +target_is_NULL(void **state) +{ + xmlNode *test_xml_1 = create_xml_node(NULL, "test_xml_1"); + xmlNode *test_xml_2 = NULL; + + pcmk__xe_set_props(test_xml_1, "test_prop", "test_value", NULL); + + copy_in_properties(test_xml_2, test_xml_1); + + assert_ptr_equal(test_xml_2, NULL); +} + +static void +src_is_NULL(void **state) +{ + xmlNode *test_xml_1 = NULL; + xmlNode *test_xml_2 = create_xml_node(NULL, "test_xml_2"); + + copy_in_properties(test_xml_2, test_xml_1); + + assert_ptr_equal(test_xml_2->properties, NULL); +} + +static void +copying_is_successful(void **state) +{ + const char *xml_1_value; + const char *xml_2_value; + + xmlNode *test_xml_1 = create_xml_node(NULL, "test_xml_1"); + xmlNode *test_xml_2 = create_xml_node(NULL, "test_xml_2"); + + pcmk__xe_set_props(test_xml_1, "test_prop", "test_value", NULL); + + copy_in_properties(test_xml_2, test_xml_1); + + xml_1_value = crm_element_value(test_xml_1, "test_prop"); + xml_2_value = crm_element_value(test_xml_2, "test_prop"); + + assert_string_equal(xml_1_value, xml_2_value); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(target_is_NULL), + cmocka_unit_test(src_is_NULL), + cmocka_unit_test(copying_is_successful)) diff --git a/lib/common/tests/actions/expand_plus_plus_test.c b/lib/common/tests/actions/expand_plus_plus_test.c new file mode 100644 index 0000000..41471f9 --- /dev/null +++ b/lib/common/tests/actions/expand_plus_plus_test.c @@ -0,0 +1,256 @@ +/* + * 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 + +#include + +#include + +static void +value_is_name_plus_plus(void **state) +{ + const char *new_value; + xmlNode *test_xml = create_xml_node(NULL, "test_xml"); + crm_xml_add(test_xml, "X", "5"); + expand_plus_plus(test_xml, "X", "X++"); + new_value = crm_element_value(test_xml, "X"); + assert_string_equal(new_value, "6"); +} + +static void +value_is_name_plus_equals_integer(void **state) +{ + const char *new_value; + xmlNode *test_xml = create_xml_node(NULL, "test_xml"); + crm_xml_add(test_xml, "X", "5"); + expand_plus_plus(test_xml, "X", "X+=2"); + new_value = crm_element_value(test_xml, "X"); + assert_string_equal(new_value, "7"); +} + +// NULL input + +static void +target_is_NULL(void **state) +{ + + const char *new_value; + xmlNode *test_xml = create_xml_node(NULL, "test_xml"); + crm_xml_add(test_xml, "X", "5"); + expand_plus_plus(NULL, "X", "X++"); + new_value = crm_element_value(test_xml, "X"); + assert_string_equal(new_value, "5"); +} + +static void +name_is_NULL(void **state) +{ + const char *new_value; + xmlNode *test_xml = create_xml_node(NULL, "test_xml"); + crm_xml_add(test_xml, "X", "5"); + expand_plus_plus(test_xml, NULL, "X++"); + new_value = crm_element_value(test_xml, "X"); + assert_string_equal(new_value, "5"); +} + +static void +value_is_NULL(void **state) +{ + const char *new_value; + xmlNode *test_xml = create_xml_node(NULL, "test_xml"); + crm_xml_add(test_xml, "X", "5"); + expand_plus_plus(test_xml, "X", NULL); + new_value = crm_element_value(test_xml, "X"); + assert_string_equal(new_value, "5"); +} + +// the value input doesn't start with the name input + +static void +value_is_wrong_name(void **state) +{ + const char *new_value; + xmlNode *test_xml = create_xml_node(NULL, "test_xml"); + crm_xml_add(test_xml, "X", "5"); + expand_plus_plus(test_xml, "X", "Y++"); + new_value = crm_element_value(test_xml, "X"); + assert_string_equal(new_value, "Y++"); +} + +static void +value_is_only_an_integer(void **state) +{ + const char *new_value; + xmlNode *test_xml = create_xml_node(NULL, "test_xml"); + crm_xml_add(test_xml, "X", "5"); + expand_plus_plus(test_xml, "X", "2"); + new_value = crm_element_value(test_xml, "X"); + assert_string_equal(new_value, "2"); +} + +// non-integers + +static void +variable_is_initialized_to_be_NULL(void **state) +{ + const char *new_value; + xmlNode *test_xml = create_xml_node(NULL, "test_xml"); + crm_xml_add(test_xml, "X", NULL); + expand_plus_plus(test_xml, "X", "X++"); + new_value = crm_element_value(test_xml, "X"); + assert_string_equal(new_value, "X++"); +} + +static void +variable_is_initialized_to_be_non_numeric(void **state) +{ + const char *new_value; + xmlNode *test_xml = create_xml_node(NULL, "test_xml"); + crm_xml_add(test_xml, "X", "hello"); + expand_plus_plus(test_xml, "X", "X++"); + new_value = crm_element_value(test_xml, "X"); + assert_string_equal(new_value, "1"); +} + +static void +variable_is_initialized_to_be_non_numeric_2(void **state) +{ + const char *new_value; + xmlNode *test_xml = create_xml_node(NULL, "test_xml"); + crm_xml_add(test_xml, "X", "hello"); + expand_plus_plus(test_xml, "X", "X+=2"); + new_value = crm_element_value(test_xml, "X"); + assert_string_equal(new_value, "2"); +} + +static void +variable_is_initialized_to_be_numeric_and_decimal_point_containing(void **state) +{ + const char *new_value; + xmlNode *test_xml = create_xml_node(NULL, "test_xml"); + crm_xml_add(test_xml, "X", "5.01"); + expand_plus_plus(test_xml, "X", "X++"); + new_value = crm_element_value(test_xml, "X"); + assert_string_equal(new_value, "6"); +} + +static void +variable_is_initialized_to_be_numeric_and_decimal_point_containing_2(void **state) +{ + const char *new_value; + xmlNode *test_xml = create_xml_node(NULL, "test_xml"); + crm_xml_add(test_xml, "X", "5.50"); + expand_plus_plus(test_xml, "X", "X++"); + new_value = crm_element_value(test_xml, "X"); + assert_string_equal(new_value, "6"); +} + +static void +variable_is_initialized_to_be_numeric_and_decimal_point_containing_3(void **state) +{ + const char *new_value; + xmlNode *test_xml = create_xml_node(NULL, "test_xml"); + crm_xml_add(test_xml, "X", "5.99"); + expand_plus_plus(test_xml, "X", "X++"); + new_value = crm_element_value(test_xml, "X"); + assert_string_equal(new_value, "6"); +} + +static void +value_is_non_numeric(void **state) +{ + const char *new_value; + xmlNode *test_xml = create_xml_node(NULL, "test_xml"); + crm_xml_add(test_xml, "X", "5"); + expand_plus_plus(test_xml, "X", "X+=hello"); + new_value = crm_element_value(test_xml, "X"); + assert_string_equal(new_value, "5"); +} + +static void +value_is_numeric_and_decimal_point_containing(void **state) +{ + const char *new_value; + xmlNode *test_xml = create_xml_node(NULL, "test_xml"); + crm_xml_add(test_xml, "X", "5"); + expand_plus_plus(test_xml, "X", "X+=2.01"); + new_value = crm_element_value(test_xml, "X"); + assert_string_equal(new_value, "7"); +} + +static void +value_is_numeric_and_decimal_point_containing_2(void **state) +{ + const char *new_value; + xmlNode *test_xml = create_xml_node(NULL, "test_xml"); + crm_xml_add(test_xml, "X", "5"); + expand_plus_plus(test_xml, "X", "X+=1.50"); + new_value = crm_element_value(test_xml, "X"); + assert_string_equal(new_value, "6"); +} + +static void +value_is_numeric_and_decimal_point_containing_3(void **state) +{ + const char *new_value; + xmlNode *test_xml = create_xml_node(NULL, "test_xml"); + crm_xml_add(test_xml, "X", "5"); + expand_plus_plus(test_xml, "X", "X+=1.99"); + new_value = crm_element_value(test_xml, "X"); + assert_string_equal(new_value, "6"); +} + +// undefined input + +static void +name_is_undefined(void **state) +{ + const char *new_value; + xmlNode *test_xml = create_xml_node(NULL, "test_xml"); + crm_xml_add(test_xml, "Y", "5"); + expand_plus_plus(test_xml, "X", "X++"); + new_value = crm_element_value(test_xml, "X"); + assert_string_equal(new_value, "X++"); +} + +// large input + +static void +assignment_result_is_too_large(void **state) +{ + const char *new_value; + xmlNode *test_xml = create_xml_node(NULL, "test_xml"); + crm_xml_add(test_xml, "X", "5"); + expand_plus_plus(test_xml, "X", "X+=100000000000"); + new_value = crm_element_value(test_xml, "X"); + printf("assignment result is too large %s\n", new_value); + assert_string_equal(new_value, "1000000"); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(value_is_name_plus_plus), + cmocka_unit_test(value_is_name_plus_equals_integer), + cmocka_unit_test(target_is_NULL), + cmocka_unit_test(name_is_NULL), + cmocka_unit_test(value_is_NULL), + cmocka_unit_test(value_is_wrong_name), + cmocka_unit_test(value_is_only_an_integer), + cmocka_unit_test(variable_is_initialized_to_be_NULL), + cmocka_unit_test(variable_is_initialized_to_be_non_numeric), + cmocka_unit_test(variable_is_initialized_to_be_non_numeric_2), + cmocka_unit_test(variable_is_initialized_to_be_numeric_and_decimal_point_containing), + cmocka_unit_test(variable_is_initialized_to_be_numeric_and_decimal_point_containing_2), + cmocka_unit_test(variable_is_initialized_to_be_numeric_and_decimal_point_containing_3), + cmocka_unit_test(value_is_non_numeric), + cmocka_unit_test(value_is_numeric_and_decimal_point_containing), + cmocka_unit_test(value_is_numeric_and_decimal_point_containing_2), + cmocka_unit_test(value_is_numeric_and_decimal_point_containing_3), + cmocka_unit_test(name_is_undefined), + cmocka_unit_test(assignment_result_is_too_large)) diff --git a/lib/common/tests/actions/fix_plus_plus_recursive_test.c b/lib/common/tests/actions/fix_plus_plus_recursive_test.c new file mode 100644 index 0000000..b3c7cc2 --- /dev/null +++ b/lib/common/tests/actions/fix_plus_plus_recursive_test.c @@ -0,0 +1,47 @@ +/* + * 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 + +#include + +#include + +static void +element_nodes(void **state) +{ + const char *new_value_root; + const char *new_value_child; + const char *new_value_grandchild; + + xmlNode *test_xml_root = create_xml_node(NULL, "test_xml_root"); + xmlNode *test_xml_child = create_xml_node(test_xml_root, "test_xml_child"); + xmlNode *test_xml_grandchild = create_xml_node(test_xml_child, "test_xml_grandchild"); + xmlNode *test_xml_text = pcmk_create_xml_text_node(test_xml_root, "text_xml_text", "content"); + xmlNode *test_xml_comment = string2xml(""); + + crm_xml_add(test_xml_root, "X", "5"); + crm_xml_add(test_xml_child, "X", "X++"); + crm_xml_add(test_xml_grandchild, "X", "X+=2"); + crm_xml_add(test_xml_text, "X", "X++"); + + fix_plus_plus_recursive(test_xml_root); + fix_plus_plus_recursive(test_xml_comment); + + new_value_root = crm_element_value(test_xml_root, "X"); + new_value_child = crm_element_value(test_xml_child, "X"); + new_value_grandchild = crm_element_value(test_xml_grandchild, "X"); + + assert_string_equal(new_value_root, "5"); + assert_string_equal(new_value_child, "1"); + assert_string_equal(new_value_grandchild, "2"); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(element_nodes)) diff --git a/lib/common/tests/actions/parse_op_key_test.c b/lib/common/tests/actions/parse_op_key_test.c new file mode 100644 index 0000000..1b1bfff --- /dev/null +++ b/lib/common/tests/actions/parse_op_key_test.c @@ -0,0 +1,275 @@ +/* + * Copyright 2020-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 + +#include + +#include + +static void +basic(void **state) +{ + char *rsc = NULL; + char *ty = NULL; + guint ms = 0; + + assert_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, &ms)); + assert_string_equal(rsc, "Fencing"); + assert_string_equal(ty, "monitor"); + assert_int_equal(ms, 60000); + free(rsc); + free(ty); + + // Single-character resource name + assert_true(parse_op_key("R_monitor_100000", &rsc, &ty, &ms)); + assert_string_equal(rsc, "R"); + assert_string_equal(ty, "monitor"); + assert_int_equal(ms, 100000); + free(rsc); + free(ty); + + // Single-character action name + assert_true(parse_op_key("R_A_0", &rsc, &ty, &ms)); + assert_string_equal(rsc, "R"); + assert_string_equal(ty, "A"); + assert_int_equal(ms, 0); + free(rsc); + free(ty); +} + +static void +rsc_just_underbars(void **state) +{ + char *rsc = NULL; + char *ty = NULL; + guint ms = 0; + + assert_true(parse_op_key("__monitor_1000", &rsc, &ty, &ms)); + assert_string_equal(rsc, "_"); + assert_string_equal(ty, "monitor"); + assert_int_equal(ms, 1000); + free(rsc); + free(ty); + + assert_true(parse_op_key("___migrate_from_0", &rsc, &ty, &ms)); + assert_string_equal(rsc, "__"); + assert_string_equal(ty, "migrate_from"); + assert_int_equal(ms, 0); + free(rsc); + free(ty); + + assert_true(parse_op_key("____pre_notify_stop_0", &rsc, &ty, &ms)); + assert_string_equal(rsc, "___"); + assert_string_equal(ty, "pre_notify_stop"); + assert_int_equal(ms, 0); + free(rsc); + free(ty); +} + +static void +colon_in_rsc(void **state) +{ + char *rsc = NULL; + char *ty = NULL; + guint ms = 0; + + assert_true(parse_op_key("ClusterIP:0_start_0", &rsc, &ty, &ms)); + assert_string_equal(rsc, "ClusterIP:0"); + assert_string_equal(ty, "start"); + assert_int_equal(ms, 0); + free(rsc); + free(ty); + + assert_true(parse_op_key("imagestoreclone:1_post_notify_stop_0", &rsc, &ty, &ms)); + assert_string_equal(rsc, "imagestoreclone:1"); + assert_string_equal(ty, "post_notify_stop"); + assert_int_equal(ms, 0); + free(rsc); + free(ty); +} + +static void +dashes_in_rsc(void **state) +{ + char *rsc = NULL; + char *ty = NULL; + guint ms = 0; + + assert_true(parse_op_key("httpd-bundle-0_monitor_30000", &rsc, &ty, &ms)); + assert_string_equal(rsc, "httpd-bundle-0"); + assert_string_equal(ty, "monitor"); + assert_int_equal(ms, 30000); + free(rsc); + free(ty); + + assert_true(parse_op_key("httpd-bundle-ip-192.168.122.132_start_0", &rsc, &ty, &ms)); + assert_string_equal(rsc, "httpd-bundle-ip-192.168.122.132"); + assert_string_equal(ty, "start"); + assert_int_equal(ms, 0); + free(rsc); + free(ty); +} + +static void +migrate_to_from(void **state) +{ + char *rsc = NULL; + char *ty = NULL; + guint ms = 0; + + assert_true(parse_op_key("vm_migrate_from_0", &rsc, &ty, &ms)); + assert_string_equal(rsc, "vm"); + assert_string_equal(ty, "migrate_from"); + assert_int_equal(ms, 0); + free(rsc); + free(ty); + + assert_true(parse_op_key("vm_migrate_to_0", &rsc, &ty, &ms)); + assert_string_equal(rsc, "vm"); + assert_string_equal(ty, "migrate_to"); + assert_int_equal(ms, 0); + free(rsc); + free(ty); + + assert_true(parse_op_key("vm_idcc_devel_migrate_to_0", &rsc, &ty, &ms)); + assert_string_equal(rsc, "vm_idcc_devel"); + assert_string_equal(ty, "migrate_to"); + assert_int_equal(ms, 0); + free(rsc); + free(ty); +} + +static void +pre_post(void **state) +{ + char *rsc = NULL; + char *ty = NULL; + guint ms = 0; + + assert_true(parse_op_key("rsc_drbd_7788:1_post_notify_start_0", &rsc, &ty, &ms)); + assert_string_equal(rsc, "rsc_drbd_7788:1"); + assert_string_equal(ty, "post_notify_start"); + assert_int_equal(ms, 0); + free(rsc); + free(ty); + + assert_true(parse_op_key("rabbitmq-bundle-clone_pre_notify_stop_0", &rsc, &ty, &ms)); + assert_string_equal(rsc, "rabbitmq-bundle-clone"); + assert_string_equal(ty, "pre_notify_stop"); + assert_int_equal(ms, 0); + free(rsc); + free(ty); + + assert_true(parse_op_key("post_notify_start_0", &rsc, &ty, &ms)); + assert_string_equal(rsc, "post_notify"); + assert_string_equal(ty, "start"); + assert_int_equal(ms, 0); + free(rsc); + free(ty); + + assert_true(parse_op_key("r_confirmed-post_notify_start_0", + &rsc, &ty, &ms)); + assert_string_equal(rsc, "r"); + assert_string_equal(ty, "confirmed-post_notify_start"); + assert_int_equal(ms, 0); + free(rsc); + free(ty); +} + +static void +skip_rsc(void **state) +{ + char *ty = NULL; + guint ms = 0; + + assert_true(parse_op_key("Fencing_monitor_60000", NULL, &ty, &ms)); + assert_string_equal(ty, "monitor"); + assert_int_equal(ms, 60000); + free(ty); +} + +static void +skip_ty(void **state) +{ + char *rsc = NULL; + guint ms = 0; + + assert_true(parse_op_key("Fencing_monitor_60000", &rsc, NULL, &ms)); + assert_string_equal(rsc, "Fencing"); + assert_int_equal(ms, 60000); + free(rsc); +} + +static void +skip_ms(void **state) +{ + char *rsc = NULL; + char *ty = NULL; + + assert_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, NULL)); + assert_string_equal(rsc, "Fencing"); + assert_string_equal(ty, "monitor"); + free(rsc); + free(ty); +} + +static void +empty_input(void **state) +{ + char *rsc = NULL; + char *ty = NULL; + guint ms = 0; + + assert_false(parse_op_key("", &rsc, &ty, &ms)); + assert_null(rsc); + assert_null(ty); + assert_int_equal(ms, 0); + + assert_false(parse_op_key(NULL, &rsc, &ty, &ms)); + assert_null(rsc); + assert_null(ty); + assert_int_equal(ms, 0); +} + +static void +malformed_input(void **state) +{ + char *rsc = NULL; + char *ty = NULL; + guint ms = 0; + + assert_false(parse_op_key("httpd-bundle-0", &rsc, &ty, &ms)); + assert_null(rsc); + assert_null(ty); + assert_int_equal(ms, 0); + + assert_false(parse_op_key("httpd-bundle-0_monitor", &rsc, &ty, &ms)); + assert_null(rsc); + assert_null(ty); + assert_int_equal(ms, 0); + + assert_false(parse_op_key("httpd-bundle-0_30000", &rsc, &ty, &ms)); + assert_null(rsc); + assert_null(ty); + assert_int_equal(ms, 0); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(basic), + cmocka_unit_test(rsc_just_underbars), + cmocka_unit_test(colon_in_rsc), + cmocka_unit_test(dashes_in_rsc), + cmocka_unit_test(migrate_to_from), + cmocka_unit_test(pre_post), + cmocka_unit_test(skip_rsc), + cmocka_unit_test(skip_ty), + cmocka_unit_test(skip_ms), + cmocka_unit_test(empty_input), + cmocka_unit_test(malformed_input)) diff --git a/lib/common/tests/actions/pcmk_is_probe_test.c b/lib/common/tests/actions/pcmk_is_probe_test.c new file mode 100644 index 0000000..4a65e3f --- /dev/null +++ b/lib/common/tests/actions/pcmk_is_probe_test.c @@ -0,0 +1,25 @@ +/* + * 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 + +#include + +static void +is_probe_test(void **state) +{ + assert_false(pcmk_is_probe(NULL, 0)); + assert_false(pcmk_is_probe("", 0)); + assert_false(pcmk_is_probe("blahblah", 0)); + assert_false(pcmk_is_probe("monitor", 1)); + assert_true(pcmk_is_probe("monitor", 0)); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(is_probe_test)) diff --git a/lib/common/tests/actions/pcmk_xe_is_probe_test.c b/lib/common/tests/actions/pcmk_xe_is_probe_test.c new file mode 100644 index 0000000..62b21d9 --- /dev/null +++ b/lib/common/tests/actions/pcmk_xe_is_probe_test.c @@ -0,0 +1,43 @@ +/* + * 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 + +#include + +static void +op_is_probe_test(void **state) +{ + xmlNode *node = NULL; + + assert_false(pcmk_xe_is_probe(NULL)); + + node = string2xml(""); + assert_false(pcmk_xe_is_probe(node)); + free_xml(node); + + node = string2xml(""); + assert_false(pcmk_xe_is_probe(node)); + free_xml(node); + + node = string2xml(""); + assert_false(pcmk_xe_is_probe(node)); + free_xml(node); + + node = string2xml(""); + assert_false(pcmk_xe_is_probe(node)); + free_xml(node); + + node = string2xml(""); + assert_true(pcmk_xe_is_probe(node)); + free_xml(node); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(op_is_probe_test)) diff --git a/lib/common/tests/actions/pcmk_xe_mask_probe_failure_test.c b/lib/common/tests/actions/pcmk_xe_mask_probe_failure_test.c new file mode 100644 index 0000000..9e38019 --- /dev/null +++ b/lib/common/tests/actions/pcmk_xe_mask_probe_failure_test.c @@ -0,0 +1,150 @@ +/* + * 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 + +#include + +static void +op_is_not_probe_test(void **state) { + xmlNode *node = NULL; + + /* Not worth testing this thoroughly since it's just a duplicate of whether + * pcmk_op_is_probe works or not. + */ + + node = string2xml(""); + assert_false(pcmk_xe_mask_probe_failure(node)); + free_xml(node); +} + +static void +op_does_not_have_right_values_test(void **state) { + xmlNode *node = NULL; + + node = string2xml(""); + assert_false(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + node = string2xml(""); + assert_false(pcmk_xe_mask_probe_failure(node)); + free_xml(node); +} + +static void +check_values_test(void **state) { + xmlNode *node = NULL; + + /* PCMK_EXEC_NOT_SUPPORTED */ + node = string2xml(""); + assert_false(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + node = string2xml(""); + assert_true(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + /* PCMK_EXEC_DONE */ + node = string2xml(""); + assert_false(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + node = string2xml(""); + assert_true(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + node = string2xml(""); + assert_true(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + node = string2xml(""); + assert_false(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + node = string2xml(""); + assert_false(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + /* PCMK_EXEC_NOT_INSTALLED */ + node = string2xml(""); + assert_true(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + node = string2xml(""); + assert_true(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + /* PCMK_EXEC_ERROR */ + node = string2xml(""); + assert_false(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + node = string2xml(""); + assert_true(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + node = string2xml(""); + assert_true(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + node = string2xml(""); + assert_false(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + node = string2xml(""); + assert_false(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + /* PCMK_EXEC_ERROR_HARD */ + node = string2xml(""); + assert_false(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + node = string2xml(""); + assert_true(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + node = string2xml(""); + assert_true(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + node = string2xml(""); + assert_false(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + node = string2xml(""); + assert_false(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + /* PCMK_EXEC_ERROR_FATAL */ + node = string2xml(""); + assert_false(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + node = string2xml(""); + assert_true(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + node = string2xml(""); + assert_true(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + node = string2xml(""); + assert_false(pcmk_xe_mask_probe_failure(node)); + free_xml(node); + + node = string2xml(""); + assert_false(pcmk_xe_mask_probe_failure(node)); + free_xml(node); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(op_is_not_probe_test), + cmocka_unit_test(op_does_not_have_right_values_test), + cmocka_unit_test(check_values_test)) diff --git a/lib/common/tests/agents/Makefile.am b/lib/common/tests/agents/Makefile.am index 7a54b7d..b3837d7 100644 --- a/lib/common/tests/agents/Makefile.am +++ b/lib/common/tests/agents/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2020-2022 the Pacemaker project contributors +# Copyright 2020-2023 the Pacemaker project contributors # # The version control history for this file may have further details. # @@ -11,10 +11,10 @@ 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 = crm_generate_ra_key_test \ - crm_parse_agent_spec_test \ - pcmk__effective_rc_test \ - pcmk_get_ra_caps_test \ - pcmk_stonith_param_test +check_PROGRAMS = crm_generate_ra_key_test \ + crm_parse_agent_spec_test \ + pcmk__effective_rc_test \ + pcmk_get_ra_caps_test \ + pcmk_stonith_param_test TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/agents/crm_parse_agent_spec_test.c b/lib/common/tests/agents/crm_parse_agent_spec_test.c index cfd75f0..1d44459 100644 --- a/lib/common/tests/agents/crm_parse_agent_spec_test.c +++ b/lib/common/tests/agents/crm_parse_agent_spec_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. * @@ -22,14 +22,22 @@ all_params_null(void **state) { static void no_prov_or_type(void **state) { - assert_int_equal(crm_parse_agent_spec("ocf", NULL, NULL, NULL), -EINVAL); - assert_int_equal(crm_parse_agent_spec("ocf:", NULL, NULL, NULL), -EINVAL); - assert_int_equal(crm_parse_agent_spec("ocf::", NULL, NULL, NULL), -EINVAL); + char *std = NULL; + char *prov = NULL; + char *ty = NULL; + + assert_int_equal(crm_parse_agent_spec("ocf", &std, &prov, &ty), -EINVAL); + assert_int_equal(crm_parse_agent_spec("ocf:", &std, &prov, &ty), -EINVAL); + assert_int_equal(crm_parse_agent_spec("ocf::", &std, &prov, &ty), -EINVAL); } static void no_type(void **state) { - assert_int_equal(crm_parse_agent_spec("ocf:pacemaker:", NULL, NULL, NULL), -EINVAL); + char *std = NULL; + char *prov = NULL; + char *ty = NULL; + + assert_int_equal(crm_parse_agent_spec("ocf:pacemaker:", &std, &prov, &ty), -EINVAL); } static void diff --git a/lib/common/tests/cmdline/Makefile.am b/lib/common/tests/cmdline/Makefile.am index d781ed5..792425b 100644 --- a/lib/common/tests/cmdline/Makefile.am +++ b/lib/common/tests/cmdline/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2020-2022 the Pacemaker project contributors +# Copyright 2020-2023 the Pacemaker project contributors # # The version control history for this file may have further details. # @@ -12,6 +12,7 @@ include $(top_srcdir)/mk/unittest.mk # Add "_test" to the end of all test program names to simplify .gitignore. check_PROGRAMS = pcmk__cmdline_preproc_test \ - pcmk__quote_cmdline_test + pcmk__new_common_args_test \ + pcmk__quote_cmdline_test TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c b/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c index 863fbb9..299fec6 100644 --- a/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c +++ b/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2020-2022 the Pacemaker project contributors + * Copyright 2020-2023 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -111,6 +111,16 @@ negative_score_2(void **state) { g_strfreev(processed); } +static void +negative_score_3(void **state) { + const char *argv[] = { "crm_attribute", "-p", "-v", "-INFINITY", NULL }; + const gchar *expected[] = { "crm_attribute", "-p", "-v", "-INFINITY", NULL }; + + gchar **processed = pcmk__cmdline_preproc((char **) argv, "pv"); + LISTS_EQ(processed, expected); + g_strfreev(processed); +} + static void string_arg_with_dash(void **state) { const char *argv[] = { "crm_mon", "-n", "crm_mon_options", "-v", "--opt1 --opt2", NULL }; @@ -151,6 +161,7 @@ PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(long_arg), cmocka_unit_test(negative_score), cmocka_unit_test(negative_score_2), + cmocka_unit_test(negative_score_3), cmocka_unit_test(string_arg_with_dash), cmocka_unit_test(string_arg_with_dash_2), cmocka_unit_test(string_arg_with_dash_3)) diff --git a/lib/common/tests/cmdline/pcmk__new_common_args_test.c b/lib/common/tests/cmdline/pcmk__new_common_args_test.c new file mode 100644 index 0000000..6b70465 --- /dev/null +++ b/lib/common/tests/cmdline/pcmk__new_common_args_test.c @@ -0,0 +1,62 @@ +/* + * Copyright 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 + +#include +#include + +#include "mock_private.h" + +#include + +static void +calloc_fails(void **state) +{ + pcmk__assert_exits(CRM_EX_OSERR, + { + pcmk__mock_calloc = true; // calloc() will return NULL + expect_value(__wrap_calloc, nmemb, 1); + expect_value(__wrap_calloc, size, sizeof(pcmk__common_args_t)); + pcmk__new_common_args("boring summary"); + pcmk__mock_calloc = false; // Use real calloc() + } + ); +} + +static void +strdup_fails(void **state) +{ + pcmk__assert_exits(CRM_EX_OSERR, + { + pcmk__mock_strdup = true; // strdup() will return NULL + expect_string(__wrap_strdup, s, "boring summary"); + pcmk__new_common_args("boring summary"); + pcmk__mock_strdup = false; // Use the real strdup() + } + ); +} + +static void +success(void **state) +{ + pcmk__common_args_t *args = pcmk__new_common_args("boring summary"); + assert_string_equal(args->summary, "boring summary"); + assert_null(args->output_as_descr); + assert_false(args->version); + assert_false(args->quiet); + assert_int_equal(args->verbosity, 0); + assert_null(args->output_ty); + assert_null(args->output_dest); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(calloc_fails), + cmocka_unit_test(strdup_fails), + cmocka_unit_test(success)) diff --git a/lib/common/tests/flags/Makefile.am b/lib/common/tests/flags/Makefile.am index 16d8ffb..22a101a 100644 --- a/lib/common/tests/flags/Makefile.am +++ b/lib/common/tests/flags/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2020-2022 the Pacemaker project contributors +# Copyright 2020-2023 the Pacemaker project contributors # # The version control history for this file may have further details. # @@ -11,10 +11,9 @@ 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__clear_flags_as_test \ - pcmk__set_flags_as_test \ - pcmk_all_flags_set_test \ - pcmk_any_flags_set_test +check_PROGRAMS = pcmk__clear_flags_as_test \ + pcmk__set_flags_as_test \ + pcmk_all_flags_set_test \ + pcmk_any_flags_set_test TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/io/Makefile.am b/lib/common/tests/io/Makefile.am index c26482c..f7519d8 100644 --- a/lib/common/tests/io/Makefile.am +++ b/lib/common/tests/io/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2020-2022 the Pacemaker project contributors +# Copyright 2020-2023 the Pacemaker project contributors # # The version control history for this file may have further details. # @@ -11,8 +11,7 @@ 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__full_path_test \ - pcmk__get_tmpdir_test +check_PROGRAMS = pcmk__full_path_test \ + pcmk__get_tmpdir_test TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/lists/Makefile.am b/lib/common/tests/lists/Makefile.am index ae0c0b6..0fa1e15 100644 --- a/lib/common/tests/lists/Makefile.am +++ b/lib/common/tests/lists/Makefile.am @@ -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. # @@ -12,9 +12,8 @@ include $(top_srcdir)/mk/unittest.mk # Add "_test" to the end of all test program names to simplify .gitignore. -check_PROGRAMS = \ - pcmk__list_of_1_test \ - pcmk__list_of_multiple_test \ - pcmk__subtract_lists_test +check_PROGRAMS = pcmk__list_of_1_test \ + pcmk__list_of_multiple_test \ + pcmk__subtract_lists_test TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/nvpair/Makefile.am b/lib/common/tests/nvpair/Makefile.am index 7acaba3..7f406bd 100644 --- a/lib/common/tests/nvpair/Makefile.am +++ b/lib/common/tests/nvpair/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2021-2022 the Pacemaker project contributors +# Copyright 2021-2023 the Pacemaker project contributors # # The version control history for this file may have further details. # @@ -11,8 +11,8 @@ 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__xe_attr_is_true_test \ - pcmk__xe_get_bool_attr_test \ - pcmk__xe_set_bool_attr_test +check_PROGRAMS = pcmk__xe_attr_is_true_test \ + pcmk__xe_get_bool_attr_test \ + pcmk__xe_set_bool_attr_test TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/operations/Makefile.am b/lib/common/tests/operations/Makefile.am deleted file mode 100644 index 4687e1b..0000000 --- a/lib/common/tests/operations/Makefile.am +++ /dev/null @@ -1,22 +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 $(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 = copy_in_properties_test \ - expand_plus_plus_test \ - fix_plus_plus_recursive_test \ - parse_op_key_test \ - pcmk_is_probe_test \ - pcmk_xe_is_probe_test \ - pcmk_xe_mask_probe_failure_test - -TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/operations/copy_in_properties_test.c b/lib/common/tests/operations/copy_in_properties_test.c deleted file mode 100644 index 7882551..0000000 --- a/lib/common/tests/operations/copy_in_properties_test.c +++ /dev/null @@ -1,62 +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 - -#include - -#include - -static void -target_is_NULL(void **state) -{ - xmlNode *test_xml_1 = create_xml_node(NULL, "test_xml_1"); - xmlNode *test_xml_2 = NULL; - - pcmk__xe_set_props(test_xml_1, "test_prop", "test_value", NULL); - - copy_in_properties(test_xml_2, test_xml_1); - - assert_ptr_equal(test_xml_2, NULL); -} - -static void -src_is_NULL(void **state) -{ - xmlNode *test_xml_1 = NULL; - xmlNode *test_xml_2 = create_xml_node(NULL, "test_xml_2"); - - copy_in_properties(test_xml_2, test_xml_1); - - assert_ptr_equal(test_xml_2->properties, NULL); -} - -static void -copying_is_successful(void **state) -{ - const char *xml_1_value; - const char *xml_2_value; - - xmlNode *test_xml_1 = create_xml_node(NULL, "test_xml_1"); - xmlNode *test_xml_2 = create_xml_node(NULL, "test_xml_2"); - - pcmk__xe_set_props(test_xml_1, "test_prop", "test_value", NULL); - - copy_in_properties(test_xml_2, test_xml_1); - - xml_1_value = crm_element_value(test_xml_1, "test_prop"); - xml_2_value = crm_element_value(test_xml_2, "test_prop"); - - assert_string_equal(xml_1_value, xml_2_value); -} - -PCMK__UNIT_TEST(NULL, NULL, - cmocka_unit_test(target_is_NULL), - cmocka_unit_test(src_is_NULL), - cmocka_unit_test(copying_is_successful)) diff --git a/lib/common/tests/operations/expand_plus_plus_test.c b/lib/common/tests/operations/expand_plus_plus_test.c deleted file mode 100644 index 41471f9..0000000 --- a/lib/common/tests/operations/expand_plus_plus_test.c +++ /dev/null @@ -1,256 +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 - -#include - -#include - -static void -value_is_name_plus_plus(void **state) -{ - const char *new_value; - xmlNode *test_xml = create_xml_node(NULL, "test_xml"); - crm_xml_add(test_xml, "X", "5"); - expand_plus_plus(test_xml, "X", "X++"); - new_value = crm_element_value(test_xml, "X"); - assert_string_equal(new_value, "6"); -} - -static void -value_is_name_plus_equals_integer(void **state) -{ - const char *new_value; - xmlNode *test_xml = create_xml_node(NULL, "test_xml"); - crm_xml_add(test_xml, "X", "5"); - expand_plus_plus(test_xml, "X", "X+=2"); - new_value = crm_element_value(test_xml, "X"); - assert_string_equal(new_value, "7"); -} - -// NULL input - -static void -target_is_NULL(void **state) -{ - - const char *new_value; - xmlNode *test_xml = create_xml_node(NULL, "test_xml"); - crm_xml_add(test_xml, "X", "5"); - expand_plus_plus(NULL, "X", "X++"); - new_value = crm_element_value(test_xml, "X"); - assert_string_equal(new_value, "5"); -} - -static void -name_is_NULL(void **state) -{ - const char *new_value; - xmlNode *test_xml = create_xml_node(NULL, "test_xml"); - crm_xml_add(test_xml, "X", "5"); - expand_plus_plus(test_xml, NULL, "X++"); - new_value = crm_element_value(test_xml, "X"); - assert_string_equal(new_value, "5"); -} - -static void -value_is_NULL(void **state) -{ - const char *new_value; - xmlNode *test_xml = create_xml_node(NULL, "test_xml"); - crm_xml_add(test_xml, "X", "5"); - expand_plus_plus(test_xml, "X", NULL); - new_value = crm_element_value(test_xml, "X"); - assert_string_equal(new_value, "5"); -} - -// the value input doesn't start with the name input - -static void -value_is_wrong_name(void **state) -{ - const char *new_value; - xmlNode *test_xml = create_xml_node(NULL, "test_xml"); - crm_xml_add(test_xml, "X", "5"); - expand_plus_plus(test_xml, "X", "Y++"); - new_value = crm_element_value(test_xml, "X"); - assert_string_equal(new_value, "Y++"); -} - -static void -value_is_only_an_integer(void **state) -{ - const char *new_value; - xmlNode *test_xml = create_xml_node(NULL, "test_xml"); - crm_xml_add(test_xml, "X", "5"); - expand_plus_plus(test_xml, "X", "2"); - new_value = crm_element_value(test_xml, "X"); - assert_string_equal(new_value, "2"); -} - -// non-integers - -static void -variable_is_initialized_to_be_NULL(void **state) -{ - const char *new_value; - xmlNode *test_xml = create_xml_node(NULL, "test_xml"); - crm_xml_add(test_xml, "X", NULL); - expand_plus_plus(test_xml, "X", "X++"); - new_value = crm_element_value(test_xml, "X"); - assert_string_equal(new_value, "X++"); -} - -static void -variable_is_initialized_to_be_non_numeric(void **state) -{ - const char *new_value; - xmlNode *test_xml = create_xml_node(NULL, "test_xml"); - crm_xml_add(test_xml, "X", "hello"); - expand_plus_plus(test_xml, "X", "X++"); - new_value = crm_element_value(test_xml, "X"); - assert_string_equal(new_value, "1"); -} - -static void -variable_is_initialized_to_be_non_numeric_2(void **state) -{ - const char *new_value; - xmlNode *test_xml = create_xml_node(NULL, "test_xml"); - crm_xml_add(test_xml, "X", "hello"); - expand_plus_plus(test_xml, "X", "X+=2"); - new_value = crm_element_value(test_xml, "X"); - assert_string_equal(new_value, "2"); -} - -static void -variable_is_initialized_to_be_numeric_and_decimal_point_containing(void **state) -{ - const char *new_value; - xmlNode *test_xml = create_xml_node(NULL, "test_xml"); - crm_xml_add(test_xml, "X", "5.01"); - expand_plus_plus(test_xml, "X", "X++"); - new_value = crm_element_value(test_xml, "X"); - assert_string_equal(new_value, "6"); -} - -static void -variable_is_initialized_to_be_numeric_and_decimal_point_containing_2(void **state) -{ - const char *new_value; - xmlNode *test_xml = create_xml_node(NULL, "test_xml"); - crm_xml_add(test_xml, "X", "5.50"); - expand_plus_plus(test_xml, "X", "X++"); - new_value = crm_element_value(test_xml, "X"); - assert_string_equal(new_value, "6"); -} - -static void -variable_is_initialized_to_be_numeric_and_decimal_point_containing_3(void **state) -{ - const char *new_value; - xmlNode *test_xml = create_xml_node(NULL, "test_xml"); - crm_xml_add(test_xml, "X", "5.99"); - expand_plus_plus(test_xml, "X", "X++"); - new_value = crm_element_value(test_xml, "X"); - assert_string_equal(new_value, "6"); -} - -static void -value_is_non_numeric(void **state) -{ - const char *new_value; - xmlNode *test_xml = create_xml_node(NULL, "test_xml"); - crm_xml_add(test_xml, "X", "5"); - expand_plus_plus(test_xml, "X", "X+=hello"); - new_value = crm_element_value(test_xml, "X"); - assert_string_equal(new_value, "5"); -} - -static void -value_is_numeric_and_decimal_point_containing(void **state) -{ - const char *new_value; - xmlNode *test_xml = create_xml_node(NULL, "test_xml"); - crm_xml_add(test_xml, "X", "5"); - expand_plus_plus(test_xml, "X", "X+=2.01"); - new_value = crm_element_value(test_xml, "X"); - assert_string_equal(new_value, "7"); -} - -static void -value_is_numeric_and_decimal_point_containing_2(void **state) -{ - const char *new_value; - xmlNode *test_xml = create_xml_node(NULL, "test_xml"); - crm_xml_add(test_xml, "X", "5"); - expand_plus_plus(test_xml, "X", "X+=1.50"); - new_value = crm_element_value(test_xml, "X"); - assert_string_equal(new_value, "6"); -} - -static void -value_is_numeric_and_decimal_point_containing_3(void **state) -{ - const char *new_value; - xmlNode *test_xml = create_xml_node(NULL, "test_xml"); - crm_xml_add(test_xml, "X", "5"); - expand_plus_plus(test_xml, "X", "X+=1.99"); - new_value = crm_element_value(test_xml, "X"); - assert_string_equal(new_value, "6"); -} - -// undefined input - -static void -name_is_undefined(void **state) -{ - const char *new_value; - xmlNode *test_xml = create_xml_node(NULL, "test_xml"); - crm_xml_add(test_xml, "Y", "5"); - expand_plus_plus(test_xml, "X", "X++"); - new_value = crm_element_value(test_xml, "X"); - assert_string_equal(new_value, "X++"); -} - -// large input - -static void -assignment_result_is_too_large(void **state) -{ - const char *new_value; - xmlNode *test_xml = create_xml_node(NULL, "test_xml"); - crm_xml_add(test_xml, "X", "5"); - expand_plus_plus(test_xml, "X", "X+=100000000000"); - new_value = crm_element_value(test_xml, "X"); - printf("assignment result is too large %s\n", new_value); - assert_string_equal(new_value, "1000000"); -} - -PCMK__UNIT_TEST(NULL, NULL, - cmocka_unit_test(value_is_name_plus_plus), - cmocka_unit_test(value_is_name_plus_equals_integer), - cmocka_unit_test(target_is_NULL), - cmocka_unit_test(name_is_NULL), - cmocka_unit_test(value_is_NULL), - cmocka_unit_test(value_is_wrong_name), - cmocka_unit_test(value_is_only_an_integer), - cmocka_unit_test(variable_is_initialized_to_be_NULL), - cmocka_unit_test(variable_is_initialized_to_be_non_numeric), - cmocka_unit_test(variable_is_initialized_to_be_non_numeric_2), - cmocka_unit_test(variable_is_initialized_to_be_numeric_and_decimal_point_containing), - cmocka_unit_test(variable_is_initialized_to_be_numeric_and_decimal_point_containing_2), - cmocka_unit_test(variable_is_initialized_to_be_numeric_and_decimal_point_containing_3), - cmocka_unit_test(value_is_non_numeric), - cmocka_unit_test(value_is_numeric_and_decimal_point_containing), - cmocka_unit_test(value_is_numeric_and_decimal_point_containing_2), - cmocka_unit_test(value_is_numeric_and_decimal_point_containing_3), - cmocka_unit_test(name_is_undefined), - cmocka_unit_test(assignment_result_is_too_large)) diff --git a/lib/common/tests/operations/fix_plus_plus_recursive_test.c b/lib/common/tests/operations/fix_plus_plus_recursive_test.c deleted file mode 100644 index b3c7cc2..0000000 --- a/lib/common/tests/operations/fix_plus_plus_recursive_test.c +++ /dev/null @@ -1,47 +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 - -#include - -#include - -static void -element_nodes(void **state) -{ - const char *new_value_root; - const char *new_value_child; - const char *new_value_grandchild; - - xmlNode *test_xml_root = create_xml_node(NULL, "test_xml_root"); - xmlNode *test_xml_child = create_xml_node(test_xml_root, "test_xml_child"); - xmlNode *test_xml_grandchild = create_xml_node(test_xml_child, "test_xml_grandchild"); - xmlNode *test_xml_text = pcmk_create_xml_text_node(test_xml_root, "text_xml_text", "content"); - xmlNode *test_xml_comment = string2xml(""); - - crm_xml_add(test_xml_root, "X", "5"); - crm_xml_add(test_xml_child, "X", "X++"); - crm_xml_add(test_xml_grandchild, "X", "X+=2"); - crm_xml_add(test_xml_text, "X", "X++"); - - fix_plus_plus_recursive(test_xml_root); - fix_plus_plus_recursive(test_xml_comment); - - new_value_root = crm_element_value(test_xml_root, "X"); - new_value_child = crm_element_value(test_xml_child, "X"); - new_value_grandchild = crm_element_value(test_xml_grandchild, "X"); - - assert_string_equal(new_value_root, "5"); - assert_string_equal(new_value_child, "1"); - assert_string_equal(new_value_grandchild, "2"); -} - -PCMK__UNIT_TEST(NULL, NULL, - cmocka_unit_test(element_nodes)) diff --git a/lib/common/tests/operations/parse_op_key_test.c b/lib/common/tests/operations/parse_op_key_test.c deleted file mode 100644 index 1b1bfff..0000000 --- a/lib/common/tests/operations/parse_op_key_test.c +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright 2020-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 - -#include - -#include - -static void -basic(void **state) -{ - char *rsc = NULL; - char *ty = NULL; - guint ms = 0; - - assert_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, &ms)); - assert_string_equal(rsc, "Fencing"); - assert_string_equal(ty, "monitor"); - assert_int_equal(ms, 60000); - free(rsc); - free(ty); - - // Single-character resource name - assert_true(parse_op_key("R_monitor_100000", &rsc, &ty, &ms)); - assert_string_equal(rsc, "R"); - assert_string_equal(ty, "monitor"); - assert_int_equal(ms, 100000); - free(rsc); - free(ty); - - // Single-character action name - assert_true(parse_op_key("R_A_0", &rsc, &ty, &ms)); - assert_string_equal(rsc, "R"); - assert_string_equal(ty, "A"); - assert_int_equal(ms, 0); - free(rsc); - free(ty); -} - -static void -rsc_just_underbars(void **state) -{ - char *rsc = NULL; - char *ty = NULL; - guint ms = 0; - - assert_true(parse_op_key("__monitor_1000", &rsc, &ty, &ms)); - assert_string_equal(rsc, "_"); - assert_string_equal(ty, "monitor"); - assert_int_equal(ms, 1000); - free(rsc); - free(ty); - - assert_true(parse_op_key("___migrate_from_0", &rsc, &ty, &ms)); - assert_string_equal(rsc, "__"); - assert_string_equal(ty, "migrate_from"); - assert_int_equal(ms, 0); - free(rsc); - free(ty); - - assert_true(parse_op_key("____pre_notify_stop_0", &rsc, &ty, &ms)); - assert_string_equal(rsc, "___"); - assert_string_equal(ty, "pre_notify_stop"); - assert_int_equal(ms, 0); - free(rsc); - free(ty); -} - -static void -colon_in_rsc(void **state) -{ - char *rsc = NULL; - char *ty = NULL; - guint ms = 0; - - assert_true(parse_op_key("ClusterIP:0_start_0", &rsc, &ty, &ms)); - assert_string_equal(rsc, "ClusterIP:0"); - assert_string_equal(ty, "start"); - assert_int_equal(ms, 0); - free(rsc); - free(ty); - - assert_true(parse_op_key("imagestoreclone:1_post_notify_stop_0", &rsc, &ty, &ms)); - assert_string_equal(rsc, "imagestoreclone:1"); - assert_string_equal(ty, "post_notify_stop"); - assert_int_equal(ms, 0); - free(rsc); - free(ty); -} - -static void -dashes_in_rsc(void **state) -{ - char *rsc = NULL; - char *ty = NULL; - guint ms = 0; - - assert_true(parse_op_key("httpd-bundle-0_monitor_30000", &rsc, &ty, &ms)); - assert_string_equal(rsc, "httpd-bundle-0"); - assert_string_equal(ty, "monitor"); - assert_int_equal(ms, 30000); - free(rsc); - free(ty); - - assert_true(parse_op_key("httpd-bundle-ip-192.168.122.132_start_0", &rsc, &ty, &ms)); - assert_string_equal(rsc, "httpd-bundle-ip-192.168.122.132"); - assert_string_equal(ty, "start"); - assert_int_equal(ms, 0); - free(rsc); - free(ty); -} - -static void -migrate_to_from(void **state) -{ - char *rsc = NULL; - char *ty = NULL; - guint ms = 0; - - assert_true(parse_op_key("vm_migrate_from_0", &rsc, &ty, &ms)); - assert_string_equal(rsc, "vm"); - assert_string_equal(ty, "migrate_from"); - assert_int_equal(ms, 0); - free(rsc); - free(ty); - - assert_true(parse_op_key("vm_migrate_to_0", &rsc, &ty, &ms)); - assert_string_equal(rsc, "vm"); - assert_string_equal(ty, "migrate_to"); - assert_int_equal(ms, 0); - free(rsc); - free(ty); - - assert_true(parse_op_key("vm_idcc_devel_migrate_to_0", &rsc, &ty, &ms)); - assert_string_equal(rsc, "vm_idcc_devel"); - assert_string_equal(ty, "migrate_to"); - assert_int_equal(ms, 0); - free(rsc); - free(ty); -} - -static void -pre_post(void **state) -{ - char *rsc = NULL; - char *ty = NULL; - guint ms = 0; - - assert_true(parse_op_key("rsc_drbd_7788:1_post_notify_start_0", &rsc, &ty, &ms)); - assert_string_equal(rsc, "rsc_drbd_7788:1"); - assert_string_equal(ty, "post_notify_start"); - assert_int_equal(ms, 0); - free(rsc); - free(ty); - - assert_true(parse_op_key("rabbitmq-bundle-clone_pre_notify_stop_0", &rsc, &ty, &ms)); - assert_string_equal(rsc, "rabbitmq-bundle-clone"); - assert_string_equal(ty, "pre_notify_stop"); - assert_int_equal(ms, 0); - free(rsc); - free(ty); - - assert_true(parse_op_key("post_notify_start_0", &rsc, &ty, &ms)); - assert_string_equal(rsc, "post_notify"); - assert_string_equal(ty, "start"); - assert_int_equal(ms, 0); - free(rsc); - free(ty); - - assert_true(parse_op_key("r_confirmed-post_notify_start_0", - &rsc, &ty, &ms)); - assert_string_equal(rsc, "r"); - assert_string_equal(ty, "confirmed-post_notify_start"); - assert_int_equal(ms, 0); - free(rsc); - free(ty); -} - -static void -skip_rsc(void **state) -{ - char *ty = NULL; - guint ms = 0; - - assert_true(parse_op_key("Fencing_monitor_60000", NULL, &ty, &ms)); - assert_string_equal(ty, "monitor"); - assert_int_equal(ms, 60000); - free(ty); -} - -static void -skip_ty(void **state) -{ - char *rsc = NULL; - guint ms = 0; - - assert_true(parse_op_key("Fencing_monitor_60000", &rsc, NULL, &ms)); - assert_string_equal(rsc, "Fencing"); - assert_int_equal(ms, 60000); - free(rsc); -} - -static void -skip_ms(void **state) -{ - char *rsc = NULL; - char *ty = NULL; - - assert_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, NULL)); - assert_string_equal(rsc, "Fencing"); - assert_string_equal(ty, "monitor"); - free(rsc); - free(ty); -} - -static void -empty_input(void **state) -{ - char *rsc = NULL; - char *ty = NULL; - guint ms = 0; - - assert_false(parse_op_key("", &rsc, &ty, &ms)); - assert_null(rsc); - assert_null(ty); - assert_int_equal(ms, 0); - - assert_false(parse_op_key(NULL, &rsc, &ty, &ms)); - assert_null(rsc); - assert_null(ty); - assert_int_equal(ms, 0); -} - -static void -malformed_input(void **state) -{ - char *rsc = NULL; - char *ty = NULL; - guint ms = 0; - - assert_false(parse_op_key("httpd-bundle-0", &rsc, &ty, &ms)); - assert_null(rsc); - assert_null(ty); - assert_int_equal(ms, 0); - - assert_false(parse_op_key("httpd-bundle-0_monitor", &rsc, &ty, &ms)); - assert_null(rsc); - assert_null(ty); - assert_int_equal(ms, 0); - - assert_false(parse_op_key("httpd-bundle-0_30000", &rsc, &ty, &ms)); - assert_null(rsc); - assert_null(ty); - assert_int_equal(ms, 0); -} - -PCMK__UNIT_TEST(NULL, NULL, - cmocka_unit_test(basic), - cmocka_unit_test(rsc_just_underbars), - cmocka_unit_test(colon_in_rsc), - cmocka_unit_test(dashes_in_rsc), - cmocka_unit_test(migrate_to_from), - cmocka_unit_test(pre_post), - cmocka_unit_test(skip_rsc), - cmocka_unit_test(skip_ty), - cmocka_unit_test(skip_ms), - cmocka_unit_test(empty_input), - cmocka_unit_test(malformed_input)) diff --git a/lib/common/tests/operations/pcmk_is_probe_test.c b/lib/common/tests/operations/pcmk_is_probe_test.c deleted file mode 100644 index 4a65e3f..0000000 --- a/lib/common/tests/operations/pcmk_is_probe_test.c +++ /dev/null @@ -1,25 +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 - -#include - -static void -is_probe_test(void **state) -{ - assert_false(pcmk_is_probe(NULL, 0)); - assert_false(pcmk_is_probe("", 0)); - assert_false(pcmk_is_probe("blahblah", 0)); - assert_false(pcmk_is_probe("monitor", 1)); - assert_true(pcmk_is_probe("monitor", 0)); -} - -PCMK__UNIT_TEST(NULL, NULL, - cmocka_unit_test(is_probe_test)) diff --git a/lib/common/tests/operations/pcmk_xe_is_probe_test.c b/lib/common/tests/operations/pcmk_xe_is_probe_test.c deleted file mode 100644 index 62b21d9..0000000 --- a/lib/common/tests/operations/pcmk_xe_is_probe_test.c +++ /dev/null @@ -1,43 +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 - -#include - -static void -op_is_probe_test(void **state) -{ - xmlNode *node = NULL; - - assert_false(pcmk_xe_is_probe(NULL)); - - node = string2xml(""); - assert_false(pcmk_xe_is_probe(node)); - free_xml(node); - - node = string2xml(""); - assert_false(pcmk_xe_is_probe(node)); - free_xml(node); - - node = string2xml(""); - assert_false(pcmk_xe_is_probe(node)); - free_xml(node); - - node = string2xml(""); - assert_false(pcmk_xe_is_probe(node)); - free_xml(node); - - node = string2xml(""); - assert_true(pcmk_xe_is_probe(node)); - free_xml(node); -} - -PCMK__UNIT_TEST(NULL, NULL, - cmocka_unit_test(op_is_probe_test)) diff --git a/lib/common/tests/operations/pcmk_xe_mask_probe_failure_test.c b/lib/common/tests/operations/pcmk_xe_mask_probe_failure_test.c deleted file mode 100644 index 9e38019..0000000 --- a/lib/common/tests/operations/pcmk_xe_mask_probe_failure_test.c +++ /dev/null @@ -1,150 +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 - -#include - -static void -op_is_not_probe_test(void **state) { - xmlNode *node = NULL; - - /* Not worth testing this thoroughly since it's just a duplicate of whether - * pcmk_op_is_probe works or not. - */ - - node = string2xml(""); - assert_false(pcmk_xe_mask_probe_failure(node)); - free_xml(node); -} - -static void -op_does_not_have_right_values_test(void **state) { - xmlNode *node = NULL; - - node = string2xml(""); - assert_false(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - node = string2xml(""); - assert_false(pcmk_xe_mask_probe_failure(node)); - free_xml(node); -} - -static void -check_values_test(void **state) { - xmlNode *node = NULL; - - /* PCMK_EXEC_NOT_SUPPORTED */ - node = string2xml(""); - assert_false(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - node = string2xml(""); - assert_true(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - /* PCMK_EXEC_DONE */ - node = string2xml(""); - assert_false(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - node = string2xml(""); - assert_true(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - node = string2xml(""); - assert_true(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - node = string2xml(""); - assert_false(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - node = string2xml(""); - assert_false(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - /* PCMK_EXEC_NOT_INSTALLED */ - node = string2xml(""); - assert_true(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - node = string2xml(""); - assert_true(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - /* PCMK_EXEC_ERROR */ - node = string2xml(""); - assert_false(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - node = string2xml(""); - assert_true(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - node = string2xml(""); - assert_true(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - node = string2xml(""); - assert_false(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - node = string2xml(""); - assert_false(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - /* PCMK_EXEC_ERROR_HARD */ - node = string2xml(""); - assert_false(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - node = string2xml(""); - assert_true(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - node = string2xml(""); - assert_true(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - node = string2xml(""); - assert_false(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - node = string2xml(""); - assert_false(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - /* PCMK_EXEC_ERROR_FATAL */ - node = string2xml(""); - assert_false(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - node = string2xml(""); - assert_true(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - node = string2xml(""); - assert_true(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - node = string2xml(""); - assert_false(pcmk_xe_mask_probe_failure(node)); - free_xml(node); - - node = string2xml(""); - assert_false(pcmk_xe_mask_probe_failure(node)); - free_xml(node); -} - -PCMK__UNIT_TEST(NULL, NULL, - cmocka_unit_test(op_is_not_probe_test), - cmocka_unit_test(op_does_not_have_right_values_test), - cmocka_unit_test(check_values_test)) diff --git a/lib/common/tests/options/Makefile.am b/lib/common/tests/options/Makefile.am index 9a5fa98..cc1008e 100644 --- a/lib/common/tests/options/Makefile.am +++ b/lib/common/tests/options/Makefile.am @@ -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. # @@ -11,9 +11,8 @@ 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__env_option_test \ - pcmk__set_env_option_test \ - pcmk__env_option_enabled_test +check_PROGRAMS = pcmk__env_option_test \ + pcmk__set_env_option_test \ + pcmk__env_option_enabled_test TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/options/pcmk__set_env_option_test.c b/lib/common/tests/options/pcmk__set_env_option_test.c index 753bf74..22fd795 100644 --- a/lib/common/tests/options/pcmk__set_env_option_test.c +++ b/lib/common/tests/options/pcmk__set_env_option_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. * @@ -20,18 +20,18 @@ bad_input_string(void **state) // Never call setenv() pcmk__mock_setenv = true; - pcmk__set_env_option(NULL, "new_value"); - pcmk__set_env_option("", "new_value"); - pcmk__set_env_option("name=val", "new_value"); + pcmk__set_env_option(NULL, "new_value", true); + pcmk__set_env_option("", "new_value", true); + pcmk__set_env_option("name=val", "new_value", true); pcmk__mock_setenv = false; // Never call unsetenv() pcmk__mock_unsetenv = true; - pcmk__set_env_option(NULL, NULL); - pcmk__set_env_option("", NULL); - pcmk__set_env_option("name=val", NULL); + pcmk__set_env_option(NULL, NULL, true); + pcmk__set_env_option("", NULL, true); + pcmk__set_env_option("name=val", NULL, true); pcmk__mock_unsetenv = false; } @@ -53,11 +53,11 @@ input_too_long_for_both(void **state) // Never call setenv() or unsetenv() pcmk__mock_setenv = true; - pcmk__set_env_option(long_opt, "new_value"); + pcmk__set_env_option(long_opt, "new_value", true); pcmk__mock_setenv = false; pcmk__mock_unsetenv = true; - pcmk__set_env_option(long_opt, NULL); + pcmk__set_env_option(long_opt, NULL, true); pcmk__mock_unsetenv = false; } @@ -87,7 +87,7 @@ input_too_long_for_pcmk(void **state) expect_string(__wrap_setenv, value, "new_value"); expect_value(__wrap_setenv, overwrite, 1); will_return(__wrap_setenv, 0); - pcmk__set_env_option(long_opt, "new_value"); + pcmk__set_env_option(long_opt, "new_value", true); pcmk__mock_setenv = false; @@ -96,7 +96,7 @@ input_too_long_for_pcmk(void **state) expect_string(__wrap_unsetenv, name, buf); will_return(__wrap_unsetenv, 0); - pcmk__set_env_option(long_opt, NULL); + pcmk__set_env_option(long_opt, NULL, true); pcmk__mock_unsetenv = false; } @@ -115,7 +115,7 @@ valid_inputs_set(void **state) expect_string(__wrap_setenv, value, "new_value"); expect_value(__wrap_setenv, overwrite, 1); will_return(__wrap_setenv, 0); - pcmk__set_env_option("env_var", "new_value"); + pcmk__set_env_option("env_var", "new_value", true); // Empty string is also a valid value expect_string(__wrap_setenv, name, "PCMK_env_var"); @@ -126,7 +126,7 @@ valid_inputs_set(void **state) expect_string(__wrap_setenv, value, ""); expect_value(__wrap_setenv, overwrite, 1); will_return(__wrap_setenv, 0); - pcmk__set_env_option("env_var", ""); + pcmk__set_env_option("env_var", "", true); pcmk__mock_setenv = false; } @@ -141,7 +141,33 @@ valid_inputs_unset(void **state) will_return(__wrap_unsetenv, 0); expect_string(__wrap_unsetenv, name, "HA_env_var"); will_return(__wrap_unsetenv, 0); - pcmk__set_env_option("env_var", NULL); + pcmk__set_env_option("env_var", NULL, true); + + pcmk__mock_unsetenv = false; +} + +static void +disable_compat(void **state) +{ + // Make sure we set only "PCMK_