diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 06:53:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 06:53:20 +0000 |
commit | e5a812082ae033afb1eed82c0f2df3d0f6bdc93f (patch) | |
tree | a6716c9275b4b413f6c9194798b34b91affb3cc7 /lib/common/tests/agents | |
parent | Initial commit. (diff) | |
download | pacemaker-e5a812082ae033afb1eed82c0f2df3d0f6bdc93f.tar.xz pacemaker-e5a812082ae033afb1eed82c0f2df3d0f6bdc93f.zip |
Adding upstream version 2.1.6.upstream/2.1.6
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/common/tests/agents')
-rw-r--r-- | lib/common/tests/agents/Makefile.am | 20 | ||||
-rw-r--r-- | lib/common/tests/agents/crm_generate_ra_key_test.c | 48 | ||||
-rw-r--r-- | lib/common/tests/agents/crm_parse_agent_spec_test.c | 87 | ||||
-rw-r--r-- | lib/common/tests/agents/pcmk__effective_rc_test.c | 36 | ||||
-rw-r--r-- | lib/common/tests/agents/pcmk_get_ra_caps_test.c | 63 | ||||
-rw-r--r-- | lib/common/tests/agents/pcmk_stonith_param_test.c | 50 |
6 files changed, 304 insertions, 0 deletions
diff --git a/lib/common/tests/agents/Makefile.am b/lib/common/tests/agents/Makefile.am new file mode 100644 index 0000000..7a54b7d --- /dev/null +++ b/lib/common/tests/agents/Makefile.am @@ -0,0 +1,20 @@ +# +# 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 = 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_generate_ra_key_test.c b/lib/common/tests/agents/crm_generate_ra_key_test.c new file mode 100644 index 0000000..f71c1c2 --- /dev/null +++ b/lib/common/tests/agents/crm_generate_ra_key_test.c @@ -0,0 +1,48 @@ +/* + * Copyright 2022 the Pacemaker project contributors + * + * The version control history for this file may have further details. + * + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. + */ + +#include <crm_internal.h> + +#include <crm/common/unittest_internal.h> +#include <crm/common/agents.h> + +static void +all_params_null(void **state) { + assert_null(crm_generate_ra_key(NULL, NULL, NULL)); +} + +static void +some_params_null(void **state) { + char *retval; + + assert_null(crm_generate_ra_key("std", "prov", NULL)); + + retval = crm_generate_ra_key("std", NULL, "ty"); + assert_string_equal(retval, "std:ty"); + free(retval); + + assert_null(crm_generate_ra_key(NULL, "prov", "ty")); + assert_null(crm_generate_ra_key("std", NULL, NULL)); + assert_null(crm_generate_ra_key(NULL, "prov", NULL)); + assert_null(crm_generate_ra_key(NULL, NULL, "ty")); +} + +static void +no_params_null(void **state) { + char *retval; + + retval = crm_generate_ra_key("std", "prov", "ty"); + assert_string_equal(retval, "std:prov:ty"); + free(retval); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(all_params_null), + cmocka_unit_test(some_params_null), + cmocka_unit_test(no_params_null)) diff --git a/lib/common/tests/agents/crm_parse_agent_spec_test.c b/lib/common/tests/agents/crm_parse_agent_spec_test.c new file mode 100644 index 0000000..cfd75f0 --- /dev/null +++ b/lib/common/tests/agents/crm_parse_agent_spec_test.c @@ -0,0 +1,87 @@ +/* + * Copyright 2022 the Pacemaker project contributors + * + * The version control history for this file may have further details. + * + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. + */ + +#include <crm_internal.h> + +#include <crm/common/unittest_internal.h> +#include <crm/common/agents.h> + +static void +all_params_null(void **state) { + assert_int_equal(crm_parse_agent_spec(NULL, NULL, NULL, NULL), -EINVAL); + assert_int_equal(crm_parse_agent_spec("", NULL, NULL, NULL), -EINVAL); + assert_int_equal(crm_parse_agent_spec(":", NULL, NULL, NULL), -EINVAL); + assert_int_equal(crm_parse_agent_spec("::", NULL, NULL, NULL), -EINVAL); +} + +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); +} + +static void +no_type(void **state) { + assert_int_equal(crm_parse_agent_spec("ocf:pacemaker:", NULL, NULL, NULL), -EINVAL); +} + +static void +get_std_and_ty(void **state) { + char *std = NULL; + char *prov = NULL; + char *ty = NULL; + + assert_int_equal(crm_parse_agent_spec("stonith:fence_xvm", &std, &prov, &ty), pcmk_ok); + assert_string_equal(std, "stonith"); + assert_null(prov); + assert_string_equal(ty, "fence_xvm"); + + free(std); + free(ty); +} + +static void +get_all_values(void **state) { + char *std = NULL; + char *prov = NULL; + char *ty = NULL; + + assert_int_equal(crm_parse_agent_spec("ocf:pacemaker:ping", &std, &prov, &ty), pcmk_ok); + assert_string_equal(std, "ocf"); + assert_string_equal(prov, "pacemaker"); + assert_string_equal(ty, "ping"); + + free(std); + free(prov); + free(ty); +} + +static void +get_systemd_values(void **state) { + char *std = NULL; + char *prov = NULL; + char *ty = NULL; + + assert_int_equal(crm_parse_agent_spec("systemd:UNIT@A:B", &std, &prov, &ty), pcmk_ok); + assert_string_equal(std, "systemd"); + assert_null(prov); + assert_string_equal(ty, "UNIT@A:B"); + + free(std); + free(ty); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(all_params_null), + cmocka_unit_test(no_prov_or_type), + cmocka_unit_test(no_type), + cmocka_unit_test(get_std_and_ty), + cmocka_unit_test(get_all_values), + cmocka_unit_test(get_systemd_values)) diff --git a/lib/common/tests/agents/pcmk__effective_rc_test.c b/lib/common/tests/agents/pcmk__effective_rc_test.c new file mode 100644 index 0000000..c9bad97 --- /dev/null +++ b/lib/common/tests/agents/pcmk__effective_rc_test.c @@ -0,0 +1,36 @@ +/* + * Copyright 2022 the Pacemaker project contributors + * + * The version control history for this file may have further details. + * + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. + */ + +#include <crm_internal.h> + +#include <crm/common/unittest_internal.h> +#include <crm/common/agents.h> + +static void +pcmk__effective_rc_test(void **state) { + /* All other PCMK_OCF_* values after UNKNOWN are deprecated and no longer used, + * so probably not worth testing them. + */ + assert_int_equal(PCMK_OCF_OK, pcmk__effective_rc(PCMK_OCF_OK)); + assert_int_equal(PCMK_OCF_OK, pcmk__effective_rc(PCMK_OCF_DEGRADED)); + assert_int_equal(PCMK_OCF_RUNNING_PROMOTED, pcmk__effective_rc(PCMK_OCF_DEGRADED_PROMOTED)); + assert_int_equal(PCMK_OCF_UNKNOWN, pcmk__effective_rc(PCMK_OCF_UNKNOWN)); + + /* There's nothing that says pcmk__effective_rc is restricted to PCMK_OCF_* + * values. That's just how it's used. Let's check some values outside + * that range just to be sure. + */ + assert_int_equal(-1, pcmk__effective_rc(-1)); + assert_int_equal(255, pcmk__effective_rc(255)); + assert_int_equal(INT_MAX, pcmk__effective_rc(INT_MAX)); + assert_int_equal(INT_MIN, pcmk__effective_rc(INT_MIN)); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(pcmk__effective_rc_test)) diff --git a/lib/common/tests/agents/pcmk_get_ra_caps_test.c b/lib/common/tests/agents/pcmk_get_ra_caps_test.c new file mode 100644 index 0000000..178dce5 --- /dev/null +++ b/lib/common/tests/agents/pcmk_get_ra_caps_test.c @@ -0,0 +1,63 @@ +/* + * Copyright 2022 the Pacemaker project contributors + * + * The version control history for this file may have further details. + * + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. + */ + +#include <crm_internal.h> + +#include <crm/common/unittest_internal.h> +#include <crm/common/agents.h> + +static void +ocf_standard(void **state) { + uint32_t expected = pcmk_ra_cap_provider | pcmk_ra_cap_params | + pcmk_ra_cap_unique | pcmk_ra_cap_promotable; + + assert_int_equal(pcmk_get_ra_caps("ocf"), expected); + assert_int_equal(pcmk_get_ra_caps("OCF"), expected); +} + +static void +stonith_standard(void **state) { + uint32_t expected = pcmk_ra_cap_params | pcmk_ra_cap_unique | + pcmk_ra_cap_stdin | pcmk_ra_cap_fence_params; + + assert_int_equal(pcmk_get_ra_caps("stonith"), expected); + assert_int_equal(pcmk_get_ra_caps("StOnItH"), expected); +} + +static void +service_standard(void **state) { + assert_int_equal(pcmk_get_ra_caps("systemd"), pcmk_ra_cap_status); + assert_int_equal(pcmk_get_ra_caps("SYSTEMD"), pcmk_ra_cap_status); + assert_int_equal(pcmk_get_ra_caps("service"), pcmk_ra_cap_status); + assert_int_equal(pcmk_get_ra_caps("SeRvIcE"), pcmk_ra_cap_status); + assert_int_equal(pcmk_get_ra_caps("lsb"), pcmk_ra_cap_status); + assert_int_equal(pcmk_get_ra_caps("LSB"), pcmk_ra_cap_status); + assert_int_equal(pcmk_get_ra_caps("upstart"), pcmk_ra_cap_status); + assert_int_equal(pcmk_get_ra_caps("uPsTaRt"), pcmk_ra_cap_status); +} + +static void +nagios_standard(void **state) { + assert_int_equal(pcmk_get_ra_caps("nagios"), pcmk_ra_cap_params); + assert_int_equal(pcmk_get_ra_caps("NAGios"), pcmk_ra_cap_params); +} + +static void +unknown_standard(void **state) { + assert_int_equal(pcmk_get_ra_caps("blahblah"), pcmk_ra_cap_none); + assert_int_equal(pcmk_get_ra_caps(""), pcmk_ra_cap_none); + assert_int_equal(pcmk_get_ra_caps(NULL), pcmk_ra_cap_none); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(ocf_standard), + cmocka_unit_test(stonith_standard), + cmocka_unit_test(service_standard), + cmocka_unit_test(nagios_standard), + cmocka_unit_test(unknown_standard)) diff --git a/lib/common/tests/agents/pcmk_stonith_param_test.c b/lib/common/tests/agents/pcmk_stonith_param_test.c new file mode 100644 index 0000000..fad431e --- /dev/null +++ b/lib/common/tests/agents/pcmk_stonith_param_test.c @@ -0,0 +1,50 @@ +/* + * Copyright 2020-2021 the Pacemaker project contributors + * + * The version control history for this file may have further details. + * + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. + */ + +#include <crm_internal.h> + +#include <crm/common/unittest_internal.h> +#include <crm/common/agents.h> + +static void +is_stonith_param(void **state) +{ + assert_false(pcmk_stonith_param(NULL)); + assert_false(pcmk_stonith_param("")); + assert_false(pcmk_stonith_param("unrecognized")); + assert_false(pcmk_stonith_param("pcmk_unrecognized")); + assert_false(pcmk_stonith_param("x" PCMK_STONITH_ACTION_LIMIT)); + assert_false(pcmk_stonith_param(PCMK_STONITH_ACTION_LIMIT "x")); + + assert_true(pcmk_stonith_param(PCMK_STONITH_ACTION_LIMIT)); + assert_true(pcmk_stonith_param(PCMK_STONITH_DELAY_BASE)); + assert_true(pcmk_stonith_param(PCMK_STONITH_DELAY_MAX)); + assert_true(pcmk_stonith_param(PCMK_STONITH_HOST_ARGUMENT)); + assert_true(pcmk_stonith_param(PCMK_STONITH_HOST_CHECK)); + assert_true(pcmk_stonith_param(PCMK_STONITH_HOST_LIST)); + assert_true(pcmk_stonith_param(PCMK_STONITH_HOST_MAP)); + assert_true(pcmk_stonith_param(PCMK_STONITH_PROVIDES)); + assert_true(pcmk_stonith_param(PCMK_STONITH_STONITH_TIMEOUT)); +} + +static void +is_stonith_action_param(void **state) +{ + /* Currently, the function accepts any string not containing underbars as + * the action name, so we do not need to verify particular action names. + */ + assert_false(pcmk_stonith_param("pcmk_on_unrecognized")); + assert_true(pcmk_stonith_param("pcmk_on_action")); + assert_true(pcmk_stonith_param("pcmk_on_timeout")); + assert_true(pcmk_stonith_param("pcmk_on_retries")); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(is_stonith_param), + cmocka_unit_test(is_stonith_action_param)) |