diff options
Diffstat (limited to 'lib/common/tests')
38 files changed, 426 insertions, 144 deletions
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/operations/Makefile.am b/lib/common/tests/actions/Makefile.am index 4687e1b..6890b84 100644 --- a/lib/common/tests/operations/Makefile.am +++ b/lib/common/tests/actions/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,12 +11,12 @@ 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 +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/actions/copy_in_properties_test.c index 7882551..7882551 100644 --- a/lib/common/tests/operations/copy_in_properties_test.c +++ b/lib/common/tests/actions/copy_in_properties_test.c diff --git a/lib/common/tests/operations/expand_plus_plus_test.c b/lib/common/tests/actions/expand_plus_plus_test.c index 41471f9..41471f9 100644 --- a/lib/common/tests/operations/expand_plus_plus_test.c +++ b/lib/common/tests/actions/expand_plus_plus_test.c diff --git a/lib/common/tests/operations/fix_plus_plus_recursive_test.c b/lib/common/tests/actions/fix_plus_plus_recursive_test.c index b3c7cc2..b3c7cc2 100644 --- a/lib/common/tests/operations/fix_plus_plus_recursive_test.c +++ b/lib/common/tests/actions/fix_plus_plus_recursive_test.c diff --git a/lib/common/tests/operations/parse_op_key_test.c b/lib/common/tests/actions/parse_op_key_test.c index 1b1bfff..1b1bfff 100644 --- a/lib/common/tests/operations/parse_op_key_test.c +++ b/lib/common/tests/actions/parse_op_key_test.c diff --git a/lib/common/tests/operations/pcmk_is_probe_test.c b/lib/common/tests/actions/pcmk_is_probe_test.c index 4a65e3f..4a65e3f 100644 --- a/lib/common/tests/operations/pcmk_is_probe_test.c +++ b/lib/common/tests/actions/pcmk_is_probe_test.c diff --git a/lib/common/tests/operations/pcmk_xe_is_probe_test.c b/lib/common/tests/actions/pcmk_xe_is_probe_test.c index 62b21d9..62b21d9 100644 --- a/lib/common/tests/operations/pcmk_xe_is_probe_test.c +++ b/lib/common/tests/actions/pcmk_xe_is_probe_test.c diff --git a/lib/common/tests/operations/pcmk_xe_mask_probe_failure_test.c b/lib/common/tests/actions/pcmk_xe_mask_probe_failure_test.c index 9e38019..9e38019 100644 --- a/lib/common/tests/operations/pcmk_xe_mask_probe_failure_test.c +++ b/lib/common/tests/actions/pcmk_xe_mask_probe_failure_test.c 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. * @@ -112,6 +112,16 @@ negative_score_2(void **state) { } 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 }; const gchar *expected[] = { "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 <crm_internal.h> + +#include <crm/common/unittest_internal.h> +#include <crm/common/cmdline_internal.h> + +#include "mock_private.h" + +#include <glib.h> + +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/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_<option>" and not "HA_<option>" + pcmk__mock_setenv = true; + + expect_string(__wrap_setenv, name, "PCMK_env_var"); + 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", false); + + pcmk__mock_setenv = false; + + // Make sure we clear both "PCMK_<option>" and "HA_<option>" + pcmk__mock_unsetenv = true; + + expect_string(__wrap_unsetenv, name, "PCMK_env_var"); + 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, false); pcmk__mock_unsetenv = false; } @@ -151,4 +177,5 @@ PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(input_too_long_for_both), cmocka_unit_test(input_too_long_for_pcmk), cmocka_unit_test(valid_inputs_set), - cmocka_unit_test(valid_inputs_unset)) + cmocka_unit_test(valid_inputs_unset), + cmocka_unit_test(disable_compat)) diff --git a/lib/common/tests/output/Makefile.am b/lib/common/tests/output/Makefile.am index 6ac7b5f..30f1494 100644 --- a/lib/common/tests/output/Makefile.am +++ b/lib/common/tests/output/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,14 +11,14 @@ 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__call_message_test \ - pcmk__output_and_clear_error_test \ - pcmk__output_free_test \ - pcmk__output_new_test \ - pcmk__register_format_test \ - pcmk__register_formats_test \ - pcmk__register_message_test \ - pcmk__register_messages_test \ - pcmk__unregister_formats_test +check_PROGRAMS = pcmk__call_message_test \ + pcmk__output_and_clear_error_test \ + pcmk__output_free_test \ + pcmk__output_new_test \ + pcmk__register_format_test \ + pcmk__register_formats_test \ + pcmk__register_message_test \ + pcmk__register_messages_test \ + pcmk__unregister_formats_test TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/output/pcmk__output_new_test.c b/lib/common/tests/output/pcmk__output_new_test.c index de4268c..a05d9a7 100644 --- a/lib/common/tests/output/pcmk__output_new_test.c +++ b/lib/common/tests/output/pcmk__output_new_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. * @@ -95,9 +95,15 @@ fopen_fails(void **state) { pcmk__output_t *out = NULL; pcmk__mock_fopen = true; +#if defined(HAVE_FOPEN64) && defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64) && (SIZEOF_LONG < 8) + expect_string(__wrap_fopen64, pathname, "destfile"); + expect_string(__wrap_fopen64, mode, "w"); + will_return(__wrap_fopen64, EPERM); +#else expect_string(__wrap_fopen, pathname, "destfile"); expect_string(__wrap_fopen, mode, "w"); will_return(__wrap_fopen, EPERM); +#endif assert_int_equal(pcmk__output_new(&out, "text", "destfile", NULL), EPERM); diff --git a/lib/common/tests/results/Makefile.am b/lib/common/tests/results/Makefile.am index 8d51d12..a7d5663 100644 --- a/lib/common/tests/results/Makefile.am +++ b/lib/common/tests/results/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,6 +11,6 @@ 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__results_test +check_PROGRAMS = pcmk__results_test TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/results/pcmk__results_test.c b/lib/common/tests/results/pcmk__results_test.c index 53665d1..016eb7f 100644 --- a/lib/common/tests/results/pcmk__results_test.c +++ b/lib/common/tests/results/pcmk__results_test.c @@ -47,15 +47,9 @@ test_for_pcmk_rc2exitc(void **state) { assert_int_equal(pcmk_rc2exitc(-7777777), CRM_EX_ERROR); } -static void -test_for_bz2_strerror(void **state) { - assert_string_equal(bz2_strerror(BZ_STREAM_END), "Ok"); -} - PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(test_for_pcmk_rc_name), cmocka_unit_test(test_for_pcmk_rc_str), cmocka_unit_test(test_for_crm_exit_name), cmocka_unit_test(test_for_crm_exit_str), - cmocka_unit_test(test_for_pcmk_rc2exitc), - cmocka_unit_test(test_for_bz2_strerror)) + cmocka_unit_test(test_for_pcmk_rc2exitc)) diff --git a/lib/common/tests/scores/Makefile.am b/lib/common/tests/scores/Makefile.am index 66ca073..cb96155 100644 --- a/lib/common/tests/scores/Makefile.am +++ b/lib/common/tests/scores/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,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 = \ - char2score_test \ - pcmk__add_scores_test \ - pcmk_readable_score_test +check_PROGRAMS = char2score_test \ + pcmk__add_scores_test \ + pcmk_readable_score_test TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/scores/pcmk__add_scores_test.c b/lib/common/tests/scores/pcmk__add_scores_test.c index 85ac232..1309659 100644 --- a/lib/common/tests/scores/pcmk__add_scores_test.c +++ b/lib/common/tests/scores/pcmk__add_scores_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. * @@ -53,6 +53,8 @@ result_infinite(void **state) assert_int_equal(pcmk__add_scores(INT_MAX, INT_MAX), CRM_SCORE_INFINITY); assert_int_equal(pcmk__add_scores(INT_MIN, INT_MIN), -CRM_SCORE_INFINITY); assert_int_equal(pcmk__add_scores(2000000, 50), CRM_SCORE_INFINITY); + assert_int_equal(pcmk__add_scores(CRM_SCORE_INFINITY/2, CRM_SCORE_INFINITY/2), CRM_SCORE_INFINITY); + assert_int_equal(pcmk__add_scores(-CRM_SCORE_INFINITY/2, -CRM_SCORE_INFINITY/2), -CRM_SCORE_INFINITY); assert_int_equal(pcmk__add_scores(-4000000, 50), -CRM_SCORE_INFINITY); } diff --git a/lib/common/tests/strings/Makefile.am b/lib/common/tests/strings/Makefile.am index 9abb8e9..e66af0d 100644 --- a/lib/common/tests/strings/Makefile.am +++ b/lib/common/tests/strings/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,31 +11,31 @@ 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_get_msec_test \ - crm_is_true_test \ - crm_str_to_boolean_test \ - pcmk__add_word_test \ - pcmk__btoa_test \ - pcmk__char_in_any_str_test \ - pcmk__compress_test \ - pcmk__ends_with_test \ - pcmk__g_strcat_test \ - pcmk__guint_from_hash_test \ - pcmk__numeric_strcasecmp_test \ - pcmk__parse_ll_range_test \ - pcmk__s_test \ - pcmk__scan_double_test \ - pcmk__scan_min_int_test \ - pcmk__scan_port_test \ - pcmk__starts_with_test \ - pcmk__str_any_of_test \ - pcmk__str_in_list_test \ - pcmk__str_table_dup_test \ - pcmk__str_update_test \ - pcmk__strcmp_test \ - pcmk__strkey_table_test \ - pcmk__strikey_table_test \ - pcmk__trim_test +check_PROGRAMS = crm_get_msec_test \ + crm_is_true_test \ + crm_str_to_boolean_test \ + pcmk__add_word_test \ + pcmk__btoa_test \ + pcmk__char_in_any_str_test \ + pcmk__compress_test \ + pcmk__ends_with_test \ + pcmk__g_strcat_test \ + pcmk__guint_from_hash_test \ + pcmk__numeric_strcasecmp_test \ + pcmk__parse_ll_range_test \ + pcmk__s_test \ + pcmk__scan_double_test \ + pcmk__scan_ll_test \ + pcmk__scan_min_int_test \ + pcmk__scan_port_test \ + pcmk__starts_with_test \ + pcmk__str_any_of_test \ + pcmk__str_in_list_test \ + pcmk__str_table_dup_test \ + pcmk__str_update_test \ + pcmk__strcmp_test \ + pcmk__strkey_table_test \ + pcmk__strikey_table_test \ + pcmk__trim_test TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/strings/pcmk__compress_test.c b/lib/common/tests/strings/pcmk__compress_test.c index 7480937..7b59d9d 100644 --- a/lib/common/tests/strings/pcmk__compress_test.c +++ b/lib/common/tests/strings/pcmk__compress_test.c @@ -33,7 +33,7 @@ max_too_small(void **state) char *result = calloc(1024, sizeof(char)); unsigned int len; - assert_int_equal(pcmk__compress(SIMPLE_DATA, 40, 10, &result, &len), pcmk_rc_error); + assert_int_equal(pcmk__compress(SIMPLE_DATA, 40, 10, &result, &len), EFBIG); } static void diff --git a/lib/common/tests/strings/pcmk__guint_from_hash_test.c b/lib/common/tests/strings/pcmk__guint_from_hash_test.c index e2b4762..225c5b3 100644 --- a/lib/common/tests/strings/pcmk__guint_from_hash_test.c +++ b/lib/common/tests/strings/pcmk__guint_from_hash_test.c @@ -59,6 +59,7 @@ conversion_errors(void **state) g_hash_table_insert(tbl, strdup("negative"), strdup("-3")); g_hash_table_insert(tbl, strdup("toobig"), strdup("20000000000000000")); + g_hash_table_insert(tbl, strdup("baddata"), strdup("asdf")); assert_int_equal(pcmk__guint_from_hash(tbl, "negative", 456, &result), ERANGE); assert_int_equal(result, 456); @@ -66,6 +67,9 @@ conversion_errors(void **state) assert_int_equal(pcmk__guint_from_hash(tbl, "toobig", 456, &result), ERANGE); assert_int_equal(result, 456); + assert_int_equal(pcmk__guint_from_hash(tbl, "baddata", 456, &result), EINVAL); + assert_int_equal(result, 456); + g_hash_table_destroy(tbl); } diff --git a/lib/common/tests/strings/pcmk__scan_ll_test.c b/lib/common/tests/strings/pcmk__scan_ll_test.c new file mode 100644 index 0000000..645ecb4 --- /dev/null +++ b/lib/common/tests/strings/pcmk__scan_ll_test.c @@ -0,0 +1,64 @@ +/* + * 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 <crm_internal.h> + +#include <crm/common/unittest_internal.h> + +static void +empty_input_string(void **state) +{ + long long result; + + assert_int_equal(pcmk__scan_ll(NULL, &result, 47), pcmk_rc_ok); + assert_int_equal(result, 47); +} + +static void +bad_input_string(void **state) +{ + long long result; + + assert_int_equal(pcmk__scan_ll("asdf", &result, 47), EINVAL); + assert_int_equal(result, 47); + assert_int_equal(pcmk__scan_ll("as12", &result, 47), EINVAL); + assert_int_equal(result, 47); +} + +static void +trailing_chars(void **state) +{ + long long result; + + assert_int_equal(pcmk__scan_ll("12as", &result, 47), pcmk_rc_ok); + assert_int_equal(result, 12); +} + +static void +no_result_variable(void **state) +{ + assert_int_equal(pcmk__scan_ll("1234", NULL, 47), pcmk_rc_ok); + assert_int_equal(pcmk__scan_ll("asdf", NULL, 47), EINVAL); +} + +static void +typical_case(void **state) +{ + long long result; + + assert_int_equal(pcmk__scan_ll("1234", &result, 47), pcmk_rc_ok); + assert_int_equal(result, 1234); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(empty_input_string), + cmocka_unit_test(bad_input_string), + cmocka_unit_test(trailing_chars), + cmocka_unit_test(no_result_variable), + cmocka_unit_test(typical_case)) diff --git a/lib/common/tests/utils/Makefile.am b/lib/common/tests/utils/Makefile.am index edccf09..f028ce4 100644 --- a/lib/common/tests/utils/Makefile.am +++ b/lib/common/tests/utils/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,15 +11,17 @@ 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 = \ - compare_version_test \ - crm_meta_name_test \ - crm_meta_value_test \ - crm_user_lookup_test \ - pcmk_daemon_user_test \ - pcmk_str_is_infinity_test \ - pcmk_str_is_minus_infinity_test \ - pcmk__getpid_s_test +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 \ + pcmk_str_is_minus_infinity_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 diff --git a/lib/common/tests/utils/pcmk__fail_attr_name_test.c b/lib/common/tests/utils/pcmk__fail_attr_name_test.c new file mode 100644 index 0000000..c6c25fc --- /dev/null +++ b/lib/common/tests/utils/pcmk__fail_attr_name_test.c @@ -0,0 +1,36 @@ +/* + * 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 <crm_internal.h> + +#include <crm/common/unittest_internal.h> + +static void +null_arguments(void **state) +{ + assert_null(pcmk__fail_attr_name(NULL, NULL, NULL, 30000)); + assert_null(pcmk__fail_attr_name(NULL, "myrsc", "monitor", 30000)); + assert_null(pcmk__fail_attr_name("xyz", NULL, "monitor", 30000)); + assert_null(pcmk__fail_attr_name("xyz", "myrsc", NULL, 30000)); +} + +static void +standard_usage(void **state) +{ + char *s = NULL; + + assert_string_equal(pcmk__fail_attr_name("xyz", "myrsc", "monitor", 30000), + "xyz-myrsc#monitor_30000"); + + free(s); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(null_arguments), + cmocka_unit_test(standard_usage)) diff --git a/lib/common/tests/utils/pcmk__failcount_name_test.c b/lib/common/tests/utils/pcmk__failcount_name_test.c new file mode 100644 index 0000000..a801f4d --- /dev/null +++ b/lib/common/tests/utils/pcmk__failcount_name_test.c @@ -0,0 +1,35 @@ +/* + * 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 <crm_internal.h> + +#include <crm/common/unittest_internal.h> + +static void +null_arguments(void **state) +{ + assert_null(pcmk__failcount_name(NULL, NULL, 30000)); + assert_null(pcmk__failcount_name("myrsc", NULL, 30000)); + assert_null(pcmk__failcount_name(NULL, "monitor", 30000)); +} + +static void +standard_usage(void **state) +{ + char *s = NULL; + + assert_string_equal(pcmk__failcount_name("myrsc", "monitor", 30000), + "fail-count-myrsc#monitor_30000"); + + free(s); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(null_arguments), + cmocka_unit_test(standard_usage)) diff --git a/lib/common/tests/utils/pcmk__lastfailure_name_test.c b/lib/common/tests/utils/pcmk__lastfailure_name_test.c new file mode 100644 index 0000000..eab01f2 --- /dev/null +++ b/lib/common/tests/utils/pcmk__lastfailure_name_test.c @@ -0,0 +1,35 @@ +/* + * 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 <crm_internal.h> + +#include <crm/common/unittest_internal.h> + +static void +null_arguments(void **state) +{ + assert_null(pcmk__lastfailure_name(NULL, NULL, 30000)); + assert_null(pcmk__lastfailure_name("myrsc", NULL, 30000)); + assert_null(pcmk__lastfailure_name(NULL, "monitor", 30000)); +} + +static void +standard_usage(void **state) +{ + char *s = NULL; + + assert_string_equal(pcmk__lastfailure_name("myrsc", "monitor", 30000), + "last-failure-myrsc#monitor_30000"); + + free(s); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(null_arguments), + cmocka_unit_test(standard_usage)) diff --git a/lib/common/tests/xml/Makefile.am b/lib/common/tests/xml/Makefile.am index 0ccdcc3..465c950 100644 --- a/lib/common/tests/xml/Makefile.am +++ b/lib/common/tests/xml/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,7 +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__xe_foreach_child_test \ - pcmk__xe_match_test +check_PROGRAMS = pcmk__xe_foreach_child_test \ + pcmk__xe_match_test TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/xml/pcmk__xe_foreach_child_test.c b/lib/common/tests/xml/pcmk__xe_foreach_child_test.c index 9bcba87..ffb9171 100644 --- a/lib/common/tests/xml/pcmk__xe_foreach_child_test.c +++ b/lib/common/tests/xml/pcmk__xe_foreach_child_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. * @@ -14,7 +14,7 @@ static int compare_name_handler(xmlNode *xml, void *userdata) { function_called(); - assert_string_equal((char *) userdata, crm_element_name(xml)); + assert_string_equal((char *) userdata, (const char *) xml->name); return pcmk_rc_ok; } @@ -140,7 +140,8 @@ const char *str3 = static int any_of_handler(xmlNode *xml, void *userdata) { function_called(); - assert_true(pcmk__str_any_of(crm_element_name(xml), "node1", "node2", "node3", NULL)); + assert_true(pcmk__str_any_of((const char *) xml->name, + "node1", "node2", "node3", NULL)); return pcmk_rc_ok; } @@ -160,7 +161,7 @@ any_of_test(void **state) { static int stops_on_first_handler(xmlNode *xml, void *userdata) { function_called(); - if (pcmk__str_eq(crm_element_name(xml), "node1", pcmk__str_none)) { + if (pcmk__xe_is(xml, "node1")) { return pcmk_rc_error; } else { return pcmk_rc_ok; @@ -170,7 +171,7 @@ static int stops_on_first_handler(xmlNode *xml, void *userdata) { static int stops_on_second_handler(xmlNode *xml, void *userdata) { function_called(); - if (pcmk__str_eq(crm_element_name(xml), "node2", pcmk__str_none)) { + if (pcmk__xe_is(xml, "node2")) { return pcmk_rc_error; } else { return pcmk_rc_ok; @@ -180,7 +181,7 @@ static int stops_on_second_handler(xmlNode *xml, void *userdata) { static int stops_on_third_handler(xmlNode *xml, void *userdata) { function_called(); - if (pcmk__str_eq(crm_element_name(xml), "node3", pcmk__str_none)) { + if (pcmk__xe_is(xml, "node3")) { return pcmk_rc_error; } else { return pcmk_rc_ok; diff --git a/lib/common/tests/xpath/Makefile.am b/lib/common/tests/xpath/Makefile.am index 94abeee..d4c504b 100644 --- a/lib/common/tests/xpath/Makefile.am +++ b/lib/common/tests/xpath/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,6 +11,6 @@ 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__xpath_node_id_test +check_PROGRAMS = pcmk__xpath_node_id_test TESTS = $(check_PROGRAMS) |