diff --git a/INSTALL.md b/INSTALL.md index 3592d8c071..fc31a49c49 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,80 +1,81 @@ # How to Install Pacemaker ## Build Dependencies | Version | Fedora-based | Suse-based | Debian-based | |:---------------:|:------------------:|:------------------:|:--------------:| | 1.13 or later | automake | automake | automake | | 2.64 or later | autoconf | autoconf | autoconf | | | libtool | libtool | libtool | | | libtool-ltdl-devel | | libltdl-dev | | | libuuid-devel | libuuid-devel | uuid-dev | | 0.27 or later | pkgconfig | pkgconfig | pkg-config | | 2.42.0 or later | glib2-devel | glib2-devel | libglib2.0-dev | | | libxml2-devel | libxml2-devel | libxml2-dev | | | libxslt-devel | libxslt-devel | libxslt-dev | | | bzip2-devel | libbz2-devel | libbz2-dev | | 0.17.0 or later | libqb-devel | libqb-devel | libqb-dev | | 3.4 or later | python3 | python3 | python3 | Also: GNU make ### Cluster Stack Dependencies *Only corosync is currently supported* | Version | Fedora-based | Suse-based | Debian-based | |:---------------:|:------------------:|:------------------:|:--------------:| | 2.0.0 or later | corosynclib | libcorosync | corosync | | 2.0.0 or later | corosynclib-devel | libcorosync-devel | | | | | | libcfg-dev | | | | | libcpg-dev | | | | | libcmap-dev | | | | | libquorum-dev | ### Optional Build Dependencies | Feature Enabled | Version | Fedora-based | Suse-based | Debian-based | |:-----------------------------------------------:|:--------------:|:-----------------------:|:-----------------------:|:-----------------------:| | Pacemaker Remote and encrypted remote CIB admin | 2.12.0 or later| gnutls-devel | libgnutls-devel | libgnutls-dev | | encrypted remote CIB admin | | pam-devel | pam-devel | libpam0g-dev | | interactive crm_mon | | ncurses-devel | ncurses-devel | ncurses-dev | | systemd support | | systemd-devel | systemd-devel | libsystemd-dev | | systemd/upstart resource support | | dbus-devel | dbus-devel | libdbus-1-dev | | Linux-HA style fencing agents | | cluster-glue-libs-devel | libglue-devel | cluster-glue-dev | | documentation | | asciidoc or asciidoctor | asciidoc or asciidoctor | asciidoc or asciidoctor | | documentation | | help2man | help2man | help2man | | documentation | | inkscape | inkscape | inkscape | | documentation | | docbook-style-xsl | docbook-xsl-stylesheets | docbook-xsl | | documentation | | python3-sphinx | python3-sphinx | python3-sphinx | | documentation (PDF) | | latexmk texlive texlive-capt-of texlive-collection-xetex texlive-fncychap texlive-framed texlive-multirow texlive-needspace texlive-tabulary texlive-titlesec texlive-threeparttable texlive-upquote texlive-wrapfig texlive-xetex | texlive texlive-latex | texlive texlive-latex-extra | | RPM packages via "make rpm" | 4.11 or later | rpm | rpm | (n/a) | +| unit tests | | libcmocka-devel | libcmocka-devel | libcmocka-dev | ## Optional testing dependencies * procps and psmisc (if running cts-exec, cts-fencing, or CTS) * valgrind (if running CTS valgrind tests) * python3-systemd (if using CTS on cluster nodes running systemd) * rsync (if running CTS container tests) * libvirt-daemon-driver-lxc (if running CTS container tests) * libvirt-daemon-lxc (if running CTS container tests) * libvirt-login-shell (if running CTS container tests) * nmap (if not specifying an IP address base) * oprofile (if running CTS profiling tests) * dlm (to log DLM debugging info after CTS tests) * xmllint (to validate tool output in cts-cli) ## Simple install $ make && sudo make install If GNU make is not your default make, use "gmake" instead. ## Detailed install First, browse the build options that are available: $ ./autogen.sh $ ./configure --help Re-run ./configure with any options you want, then proceed with the simple method. diff --git a/lib/common/tests/agents/Makefile.am b/lib/common/tests/agents/Makefile.am index 40cb5f7776..64687335fc 100644 --- a/lib/common/tests/agents/Makefile.am +++ b/lib/common/tests/agents/Makefile.am @@ -1,29 +1,29 @@ # # Copyright 2020 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. # AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include -LDADD = $(top_builddir)/lib/common/libcrmcommon.la +LDADD = $(top_builddir)/lib/common/libcrmcommon.la -lcmocka include $(top_srcdir)/mk/glib-tap.mk # Add each test program here. Each test should be written as a little standalone # program using the glib unit testing functions. See the documentation for more # information. # # https://developer.gnome.org/glib/unstable/glib-Testing.html # # Add "_test" to the end of all test program names to simplify .gitignore. test_programs = pcmk_stonith_param_test # If any extra data needs to be added to the source distribution, add it to the # following list. dist_test_data = # If any extra data needs to be used by tests but should not be added to the # source distribution, add it to the following list. test_data = diff --git a/lib/common/tests/agents/pcmk_stonith_param_test.c b/lib/common/tests/agents/pcmk_stonith_param_test.c index ee82b855ab..f1dce83633 100644 --- a/lib/common/tests/agents/pcmk_stonith_param_test.c +++ b/lib/common/tests/agents/pcmk_stonith_param_test.c @@ -1,59 +1,62 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include - -#include - #include +#include +#include +#include +#include +#include + static void -is_stonith_param(void) +is_stonith_param(void **state) { - g_assert_false(pcmk_stonith_param(NULL)); - g_assert_false(pcmk_stonith_param("")); - g_assert_false(pcmk_stonith_param("unrecognized")); - g_assert_false(pcmk_stonith_param("pcmk_unrecognized")); - g_assert_false(pcmk_stonith_param("x" PCMK_STONITH_ACTION_LIMIT)); - g_assert_false(pcmk_stonith_param(PCMK_STONITH_ACTION_LIMIT "x")); - - g_assert_true(pcmk_stonith_param(PCMK_STONITH_ACTION_LIMIT)); - g_assert_true(pcmk_stonith_param(PCMK_STONITH_DELAY_BASE)); - g_assert_true(pcmk_stonith_param(PCMK_STONITH_DELAY_MAX)); - g_assert_true(pcmk_stonith_param(PCMK_STONITH_HOST_ARGUMENT)); - g_assert_true(pcmk_stonith_param(PCMK_STONITH_HOST_CHECK)); - g_assert_true(pcmk_stonith_param(PCMK_STONITH_HOST_LIST)); - g_assert_true(pcmk_stonith_param(PCMK_STONITH_HOST_MAP)); - g_assert_true(pcmk_stonith_param(PCMK_STONITH_PROVIDES)); - g_assert_true(pcmk_stonith_param(PCMK_STONITH_STONITH_TIMEOUT)); + 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) +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. */ - g_assert_false(pcmk_stonith_param("pcmk_on_unrecognized")); - g_assert_true(pcmk_stonith_param("pcmk_on_action")); - g_assert_true(pcmk_stonith_param("pcmk_on_timeout")); - g_assert_true(pcmk_stonith_param("pcmk_on_retries")); + 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")); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); + const struct CMUnitTest tests[] = { + cmocka_unit_test(is_stonith_param), + cmocka_unit_test(is_stonith_action_param), + }; - g_test_add_func("/common/utils/parse_op_key/is_stonith_param", - is_stonith_param); - g_test_add_func("/common/utils/parse_op_key/is_stonith_action_param", - is_stonith_action_param); - return g_test_run(); + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/cmdline/Makefile.am b/lib/common/tests/cmdline/Makefile.am index e69ef2126f..d6dec1fc54 100644 --- a/lib/common/tests/cmdline/Makefile.am +++ b/lib/common/tests/cmdline/Makefile.am @@ -1,29 +1,29 @@ # -# Copyright 2020 the Pacemaker project contributors +# 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. # AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include -LDADD = $(top_builddir)/lib/common/libcrmcommon.la +LDADD = $(top_builddir)/lib/common/libcrmcommon.la -lcmocka include $(top_srcdir)/mk/glib-tap.mk # Add each test program here. Each test should be written as a little standalone # program using the glib unit testing functions. See the documentation for more # information. # # https://developer.gnome.org/glib/unstable/glib-Testing.html # # Add "_test" to the end of all test program names to simplify .gitignore. test_programs = pcmk__cmdline_preproc_test # If any extra data needs to be added to the source distribution, add it to the # following list. dist_test_data = # If any extra data needs to be used by tests but should not be added to the # source distribution, add it to the following list. test_data = diff --git a/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c b/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c index edc564008c..d2608511e5 100644 --- a/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c +++ b/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c @@ -1,157 +1,166 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include #include +#include +#include +#include +#include +#include +#include + #define LISTS_EQ(a, b) { \ - g_assert_cmpint(g_strv_length((gchar **) (a)), ==, g_strv_length((gchar **) (b))); \ + assert_int_equal(g_strv_length((gchar **) (a)), g_strv_length((gchar **) (b))); \ for (int i = 0; i < g_strv_length((a)); i++) { \ - g_assert_cmpstr((a)[i], ==, (b)[i]); \ + assert_string_equal((a)[i], (b)[i]); \ } \ } static void -empty_input(void) { - g_assert_null(pcmk__cmdline_preproc(NULL, "")); +empty_input(void **state) { + assert_null(pcmk__cmdline_preproc(NULL, "")); } static void -no_specials(void) { +no_specials(void **state) { const char *argv[] = { "-a", "-b", "-c", "-d", NULL }; const gchar *expected[] = { "-a", "-b", "-c", "-d", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL); LISTS_EQ(processed, expected); g_strfreev(processed); processed = pcmk__cmdline_preproc((char **) argv, ""); LISTS_EQ(processed, expected); g_strfreev(processed); } static void -single_dash(void) { +single_dash(void **state) { const char *argv[] = { "-", NULL }; const gchar *expected[] = { "-", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL); LISTS_EQ(processed, expected); g_strfreev(processed); } static void -double_dash(void) { +double_dash(void **state) { const char *argv[] = { "-a", "--", "-bc", NULL }; const gchar *expected[] = { "-a", "--", "-bc", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL); LISTS_EQ(processed, expected); g_strfreev(processed); } static void -special_args(void) { +special_args(void **state) { const char *argv[] = { "-aX", "-Fval", NULL }; const gchar *expected[] = { "-a", "X", "-F", "val", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, "aF"); LISTS_EQ(processed, expected); g_strfreev(processed); } static void -special_arg_at_end(void) { +special_arg_at_end(void **state) { const char *argv[] = { "-a", NULL }; const gchar *expected[] = { "-a", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, "a"); LISTS_EQ(processed, expected); g_strfreev(processed); } static void -long_arg(void) { +long_arg(void **state) { const char *argv[] = { "--blah=foo", NULL }; const gchar *expected[] = { "--blah=foo", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL); LISTS_EQ(processed, expected); g_strfreev(processed); } static void -negative_score(void) { +negative_score(void **state) { const char *argv[] = { "-v", "-1000", NULL }; const gchar *expected[] = { "-v", "-1000", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, "v"); LISTS_EQ(processed, expected); g_strfreev(processed); } static void -negative_score_2(void) { +negative_score_2(void **state) { const char *argv[] = { "-1i3", NULL }; const gchar *expected[] = { "-1", "-i", "-3", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL); LISTS_EQ(processed, expected); g_strfreev(processed); } static void -string_arg_with_dash(void) { +string_arg_with_dash(void **state) { const char *argv[] = { "-n", "crm_mon_options", "-v", "--opt1 --opt2", NULL }; const gchar *expected[] = { "-n", "crm_mon_options", "-v", "--opt1 --opt2", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, "v"); LISTS_EQ(processed, expected); g_strfreev(processed); } static void -string_arg_with_dash_2(void) { +string_arg_with_dash_2(void **state) { const char *argv[] = { "-n", "crm_mon_options", "-v", "-1i3", NULL }; const gchar *expected[] = { "-n", "crm_mon_options", "-v", "-1i3", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, "v"); LISTS_EQ(processed, expected); g_strfreev(processed); } static void -string_arg_with_dash_3(void) { +string_arg_with_dash_3(void **state) { const char *argv[] = { "-abc", "-1i3", NULL }; const gchar *expected[] = { "-a", "-b", "-c", "-1i3", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, "c"); LISTS_EQ(processed, expected); g_strfreev(processed); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); - - g_test_add_func("/common/cmdline/preproc/empty_input", empty_input); - g_test_add_func("/common/cmdline/preproc/no_specials", no_specials); - g_test_add_func("/common/cmdline/preproc/single_dash", single_dash); - g_test_add_func("/common/cmdline/preproc/double_dash", double_dash); - g_test_add_func("/common/cmdline/preproc/special_args", special_args); - g_test_add_func("/common/cmdline/preproc/special_arg_at_end", special_arg_at_end); - g_test_add_func("/common/cmdline/preproc/long_arg", long_arg); - g_test_add_func("/common/cmdline/preproc/negative_score", negative_score); - g_test_add_func("/common/cmdline/preproc/negative_score_2", negative_score_2); - g_test_add_func("/common/cmdline/preproc/string_arg_with_dash", string_arg_with_dash); - g_test_add_func("/common/cmdline/preproc/string_arg_with_dash_2", string_arg_with_dash_2); - g_test_add_func("/common/cmdline/preproc/string_arg_with_dash_3", string_arg_with_dash_3); - return g_test_run(); + const struct CMUnitTest tests[] = { + cmocka_unit_test(empty_input), + cmocka_unit_test(no_specials), + cmocka_unit_test(single_dash), + cmocka_unit_test(double_dash), + cmocka_unit_test(special_args), + cmocka_unit_test(special_arg_at_end), + cmocka_unit_test(long_arg), + cmocka_unit_test(negative_score), + cmocka_unit_test(negative_score_2), + cmocka_unit_test(string_arg_with_dash), + cmocka_unit_test(string_arg_with_dash_2), + cmocka_unit_test(string_arg_with_dash_3), + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/flags/Makefile.am b/lib/common/tests/flags/Makefile.am index 086d4e26fa..066385ae51 100644 --- a/lib/common/tests/flags/Makefile.am +++ b/lib/common/tests/flags/Makefile.am @@ -1,32 +1,32 @@ # -# Copyright 2020 the Pacemaker project contributors +# 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. # AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include -LDADD = $(top_builddir)/lib/common/libcrmcommon.la +LDADD = $(top_builddir)/lib/common/libcrmcommon.la -lcmocka include $(top_srcdir)/mk/glib-tap.mk # Add each test program here. Each test should be written as a little standalone # program using the glib unit testing functions. See the documentation for more # information. # # https://developer.gnome.org/glib/unstable/glib-Testing.html # # Add "_test" to the end of all test program names to simplify .gitignore. test_programs = pcmk__clear_flags_as_test \ pcmk__set_flags_as_test \ pcmk_all_flags_set_test \ pcmk_any_flags_set_test # If any extra data needs to be added to the source distribution, add it to the # following list. dist_test_data = # If any extra data needs to be used by tests but should not be added to the # source distribution, add it to the following list. test_data = diff --git a/lib/common/tests/flags/pcmk__clear_flags_as_test.c b/lib/common/tests/flags/pcmk__clear_flags_as_test.c index a476adf3dd..8a1fa1358c 100644 --- a/lib/common/tests/flags/pcmk__clear_flags_as_test.c +++ b/lib/common/tests/flags/pcmk__clear_flags_as_test.c @@ -1,45 +1,53 @@ /* - * Copyright 2020 the Pacemaker project contributors + * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include +#include +#include +#include +#include +#include + static void -clear_none(void) { - g_assert_cmphex(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", - "test", 0x0f0, 0x00f, NULL), ==, 0x0f0); - g_assert_cmphex(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", - "test", 0x0f0, 0xf0f, NULL), ==, 0x0f0); +clear_none(void **state) { + assert_int_equal(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", + "test", 0x0f0, 0x00f, NULL), 0x0f0); + assert_int_equal(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", + "test", 0x0f0, 0xf0f, NULL), 0x0f0); } static void -clear_some(void) { - g_assert_cmphex(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", - "test", 0x0f0, 0x020, NULL), ==, 0x0d0); - g_assert_cmphex(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", - "test", 0x0f0, 0x030, NULL), ==, 0x0c0); +clear_some(void **state) { + assert_int_equal(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", + "test", 0x0f0, 0x020, NULL), 0x0d0); + assert_int_equal(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", + "test", 0x0f0, 0x030, NULL), 0x0c0); } static void -clear_all(void) { - g_assert_cmphex(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", - "test", 0x0f0, 0x0f0, NULL), ==, 0x000); - g_assert_cmphex(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", - "test", 0x0f0, 0xfff, NULL), ==, 0x000); +clear_all(void **state) { + assert_int_equal(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", + "test", 0x0f0, 0x0f0, NULL), 0x000); + assert_int_equal(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", + "test", 0x0f0, 0xfff, NULL), 0x000); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); + const struct CMUnitTest tests[] = { + cmocka_unit_test(clear_none), + cmocka_unit_test(clear_some), + cmocka_unit_test(clear_all), + }; - g_test_add_func("/common/flags/clear/clear_none", clear_none); - g_test_add_func("/common/flags/clear/clear_some", clear_some); - g_test_add_func("/common/flags/clear/clear_all", clear_all); - return g_test_run(); + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/flags/pcmk__set_flags_as_test.c b/lib/common/tests/flags/pcmk__set_flags_as_test.c index 9a8292cfe8..1a927bbf7b 100644 --- a/lib/common/tests/flags/pcmk__set_flags_as_test.c +++ b/lib/common/tests/flags/pcmk__set_flags_as_test.c @@ -1,29 +1,37 @@ /* - * Copyright 2020 the Pacemaker project contributors + * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include +#include +#include +#include +#include +#include + static void -set_flags(void) { - g_assert_cmphex(pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE, "Test", - "test", 0x0f0, 0x00f, NULL), ==, 0x0ff); - g_assert_cmphex(pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE, "Test", - "test", 0x0f0, 0xf0f, NULL), ==, 0xfff); - g_assert_cmphex(pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE, "Test", - "test", 0x0f0, 0xfff, NULL), ==, 0xfff); +set_flags(void **state) { + assert_int_equal(pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE, "Test", + "test", 0x0f0, 0x00f, NULL), 0x0ff); + assert_int_equal(pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE, "Test", + "test", 0x0f0, 0xf0f, NULL), 0xfff); + assert_int_equal(pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE, "Test", + "test", 0x0f0, 0xfff, NULL), 0xfff); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); + const struct CMUnitTest tests[] = { + cmocka_unit_test(set_flags), + }; - g_test_add_func("/common/flags/set/set_flags", set_flags); - return g_test_run(); + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/flags/pcmk_all_flags_set_test.c b/lib/common/tests/flags/pcmk_all_flags_set_test.c index ebe175d7da..4596ad9490 100644 --- a/lib/common/tests/flags/pcmk_all_flags_set_test.c +++ b/lib/common/tests/flags/pcmk_all_flags_set_test.c @@ -1,39 +1,45 @@ /* - * Copyright 2020 the Pacemaker project contributors + * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ -#include -#include #include +#include +#include +#include +#include +#include + static void -all_set(void) { - g_assert_false(pcmk_all_flags_set(0x000, 0x003)); - g_assert_true(pcmk_all_flags_set(0x00f, 0x003)); - g_assert_false(pcmk_all_flags_set(0x00f, 0x010)); - g_assert_false(pcmk_all_flags_set(0x00f, 0x011)); - g_assert_true(pcmk_all_flags_set(0x000, 0x000)); - g_assert_true(pcmk_all_flags_set(0x00f, 0x000)); +all_set(void **state) { + assert_false(pcmk_all_flags_set(0x000, 0x003)); + assert_true(pcmk_all_flags_set(0x00f, 0x003)); + assert_false(pcmk_all_flags_set(0x00f, 0x010)); + assert_false(pcmk_all_flags_set(0x00f, 0x011)); + assert_true(pcmk_all_flags_set(0x000, 0x000)); + assert_true(pcmk_all_flags_set(0x00f, 0x000)); } static void -one_is_set(void) { +one_is_set(void **state) { // pcmk_is_set() is a simple macro alias for pcmk_all_flags_set() - g_assert_true(pcmk_is_set(0x00f, 0x001)); - g_assert_false(pcmk_is_set(0x00f, 0x010)); + assert_true(pcmk_is_set(0x00f, 0x001)); + assert_false(pcmk_is_set(0x00f, 0x010)); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); + const struct CMUnitTest tests[] = { + cmocka_unit_test(all_set), + cmocka_unit_test(one_is_set), + }; - g_test_add_func("/common/flags/all_set/all_set", all_set); - g_test_add_func("/common/flags/all_set/is_set", one_is_set); - return g_test_run(); + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/flags/pcmk_any_flags_set_test.c b/lib/common/tests/flags/pcmk_any_flags_set_test.c index d465d0d626..1d3407dc84 100644 --- a/lib/common/tests/flags/pcmk_any_flags_set_test.c +++ b/lib/common/tests/flags/pcmk_any_flags_set_test.c @@ -1,32 +1,38 @@ /* - * Copyright 2020 the Pacemaker project contributors + * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ -#include -#include #include +#include +#include +#include +#include +#include + static void -any_set(void) { - g_assert_false(pcmk_any_flags_set(0x000, 0x000)); - g_assert_false(pcmk_any_flags_set(0x000, 0x001)); - g_assert_true(pcmk_any_flags_set(0x00f, 0x001)); - g_assert_false(pcmk_any_flags_set(0x00f, 0x010)); - g_assert_true(pcmk_any_flags_set(0x00f, 0x011)); - g_assert_false(pcmk_any_flags_set(0x000, 0x000)); - g_assert_false(pcmk_any_flags_set(0x00f, 0x000)); +any_set(void **state) { + assert_false(pcmk_any_flags_set(0x000, 0x000)); + assert_false(pcmk_any_flags_set(0x000, 0x001)); + assert_true(pcmk_any_flags_set(0x00f, 0x001)); + assert_false(pcmk_any_flags_set(0x00f, 0x010)); + assert_true(pcmk_any_flags_set(0x00f, 0x011)); + assert_false(pcmk_any_flags_set(0x000, 0x000)); + assert_false(pcmk_any_flags_set(0x00f, 0x000)); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); + const struct CMUnitTest tests[] = { + cmocka_unit_test(any_set), + }; - g_test_add_func("/common/flags/any_set/any_set", any_set); - return g_test_run(); + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/io/Makefile.am b/lib/common/tests/io/Makefile.am index 6760a1d9c9..8f934f1bc6 100644 --- a/lib/common/tests/io/Makefile.am +++ b/lib/common/tests/io/Makefile.am @@ -1,30 +1,30 @@ # # 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. # AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include -LDADD = $(top_builddir)/lib/common/libcrmcommon.la +LDADD = $(top_builddir)/lib/common/libcrmcommon.la -lcmocka include $(top_srcdir)/mk/glib-tap.mk # Add each test program here. Each test should be written as a little standalone # program using the glib unit testing functions. See the documentation for more # information. # # https://developer.gnome.org/glib/unstable/glib-Testing.html # # Add "_test" to the end of all test program names to simplify .gitignore. test_programs = \ pcmk__full_path_test # If any extra data needs to be added to the source distribution, add it to the # following list. dist_test_data = # If any extra data needs to be used by tests but should not be added to the # source distribution, add it to the following list. test_data = diff --git a/lib/common/tests/io/pcmk__full_path_test.c b/lib/common/tests/io/pcmk__full_path_test.c index 03b3d13838..47333e4d85 100644 --- a/lib/common/tests/io/pcmk__full_path_test.c +++ b/lib/common/tests/io/pcmk__full_path_test.c @@ -1,41 +1,47 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ -#include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include + static void -full_path(void) +full_path(void **state) { char *path = NULL; path = pcmk__full_path("file", "/dir"); - g_assert_cmpint(strcmp(path, "/dir/file"), ==, 0); + assert_int_equal(strcmp(path, "/dir/file"), 0); free(path); path = pcmk__full_path("/full/path", "/dir"); - g_assert_cmpint(strcmp(path, "/full/path"), ==, 0); + assert_int_equal(strcmp(path, "/full/path"), 0); free(path); path = pcmk__full_path("../relative/path", "/dir"); - g_assert_cmpint(strcmp(path, "/dir/../relative/path"), ==, 0); + assert_int_equal(strcmp(path, "/dir/../relative/path"), 0); free(path); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); - - g_test_add_func("/common/io/full_path/full_path", full_path); + const struct CMUnitTest tests[] = { + cmocka_unit_test(full_path), + }; - return g_test_run(); + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/iso8601/Makefile.am b/lib/common/tests/iso8601/Makefile.am index fe1db22d06..b1b86c8417 100644 --- a/lib/common/tests/iso8601/Makefile.am +++ b/lib/common/tests/iso8601/Makefile.am @@ -1,29 +1,29 @@ # # 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. # AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include -LDADD = $(top_builddir)/lib/common/libcrmcommon.la +LDADD = $(top_builddir)/lib/common/libcrmcommon.la -lcmocka include $(top_srcdir)/mk/glib-tap.mk # Add each test program here. Each test should be written as a little standalone # program using the glib unit testing functions. See the documentation for more # information. # # https://developer.gnome.org/glib/unstable/glib-Testing.html # # Add "_test" to the end of all test program names to simplify .gitignore. test_programs = pcmk__readable_interval_test # If any extra data needs to be added to the source distribution, add it to the # following list. dist_test_data = # If any extra data needs to be used by tests but should not be added to the # source distribution, add it to the following list. test_data = diff --git a/lib/common/tests/iso8601/pcmk__readable_interval_test.c b/lib/common/tests/iso8601/pcmk__readable_interval_test.c index 45ad9f10c5..cf0ffafb7b 100644 --- a/lib/common/tests/iso8601/pcmk__readable_interval_test.c +++ b/lib/common/tests/iso8601/pcmk__readable_interval_test.c @@ -1,34 +1,40 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include #include +#include +#include +#include +#include +#include #include static void -readable_interval(void) +readable_interval(void **state) { - g_assert_cmpint(strcmp(pcmk__readable_interval(0), "0s"), ==, 0); - g_assert_cmpint(strcmp(pcmk__readable_interval(30000), "30s"), ==, 0); - g_assert_cmpint(strcmp(pcmk__readable_interval(150000), "2m30s"), ==, 0); - g_assert_cmpint(strcmp(pcmk__readable_interval(3333), "3.333s"), ==, 0); - g_assert_cmpint(strcmp(pcmk__readable_interval(UINT_MAX), "49d17h2m47.295s"), ==, 0); + assert_string_equal(pcmk__readable_interval(0), "0s"); + assert_string_equal(pcmk__readable_interval(30000), "30s"); + assert_string_equal(pcmk__readable_interval(150000), "2m30s"); + assert_string_equal(pcmk__readable_interval(3333), "3.333s"); + assert_string_equal(pcmk__readable_interval(UINT_MAX), "49d17h2m47.295s"); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); + const struct CMUnitTest tests[] = { + cmocka_unit_test(readable_interval), + }; - g_test_add_func("/common/utils/pcmk__readable_interval/readable_interval", - readable_interval); - return g_test_run(); + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/operations/Makefile.am b/lib/common/tests/operations/Makefile.am index cd5884b2bd..4c8ae56cfc 100644 --- a/lib/common/tests/operations/Makefile.am +++ b/lib/common/tests/operations/Makefile.am @@ -1,29 +1,29 @@ # # Copyright 2020 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. # AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include -LDADD = $(top_builddir)/lib/common/libcrmcommon.la +LDADD = $(top_builddir)/lib/common/libcrmcommon.la -lcmocka include $(top_srcdir)/mk/glib-tap.mk # Add each test program here. Each test should be written as a little standalone # program using the glib unit testing functions. See the documentation for more # information. # # https://developer.gnome.org/glib/unstable/glib-Testing.html # # Add "_test" to the end of all test program names to simplify .gitignore. test_programs = parse_op_key_test # If any extra data needs to be added to the source distribution, add it to the # following list. dist_test_data = # If any extra data needs to be used by tests but should not be added to the # source distribution, add it to the following list. test_data = diff --git a/lib/common/tests/operations/parse_op_key_test.c b/lib/common/tests/operations/parse_op_key_test.c index 857431af1b..daac346e12 100644 --- a/lib/common/tests/operations/parse_op_key_test.c +++ b/lib/common/tests/operations/parse_op_key_test.c @@ -1,228 +1,234 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include -#include #include +#include +#include +#include +#include +#include +#include static void -basic(void) +basic(void **state) { char *rsc = NULL; char *ty = NULL; guint ms = 0; - g_assert_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, &ms)); - g_assert_cmpstr(rsc, ==, "Fencing"); - g_assert_cmpstr(ty, ==, "monitor"); - g_assert_cmpint(ms, ==, 60000); + 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); } static void -colon_in_rsc(void) +colon_in_rsc(void **state) { char *rsc = NULL; char *ty = NULL; guint ms = 0; - g_assert_true(parse_op_key("ClusterIP:0_start_0", &rsc, &ty, &ms)); - g_assert_cmpstr(rsc, ==, "ClusterIP:0"); - g_assert_cmpstr(ty, ==, "start"); - g_assert_cmpint(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); - g_assert_true(parse_op_key("imagestoreclone:1_post_notify_stop_0", &rsc, &ty, &ms)); - g_assert_cmpstr(rsc, ==, "imagestoreclone:1"); - g_assert_cmpstr(ty, ==, "post_notify_stop"); - g_assert_cmpint(ms, ==, 0); + 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) +dashes_in_rsc(void **state) { char *rsc = NULL; char *ty = NULL; guint ms = 0; - g_assert_true(parse_op_key("httpd-bundle-0_monitor_30000", &rsc, &ty, &ms)); - g_assert_cmpstr(rsc, ==, "httpd-bundle-0"); - g_assert_cmpstr(ty, ==, "monitor"); - g_assert_cmpint(ms, ==, 30000); + 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); - g_assert_true(parse_op_key("httpd-bundle-ip-192.168.122.132_start_0", &rsc, &ty, &ms)); - g_assert_cmpstr(rsc, ==, "httpd-bundle-ip-192.168.122.132"); - g_assert_cmpstr(ty, ==, "start"); - g_assert_cmpint(ms, ==, 0); + 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) +migrate_to_from(void **state) { char *rsc = NULL; char *ty = NULL; guint ms = 0; - g_assert_true(parse_op_key("vm_migrate_from_0", &rsc, &ty, &ms)); - g_assert_cmpstr(rsc, ==, "vm"); - g_assert_cmpstr(ty, ==, "migrate_from"); - g_assert_cmpint(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); - g_assert_true(parse_op_key("vm_migrate_to_0", &rsc, &ty, &ms)); - g_assert_cmpstr(rsc, ==, "vm"); - g_assert_cmpstr(ty, ==, "migrate_to"); - g_assert_cmpint(ms, ==, 0); + 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); - g_assert_true(parse_op_key("vm_idcc_devel_migrate_to_0", &rsc, &ty, &ms)); - g_assert_cmpstr(rsc, ==, "vm_idcc_devel"); - g_assert_cmpstr(ty, ==, "migrate_to"); - g_assert_cmpint(ms, ==, 0); + 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) +pre_post(void **state) { char *rsc = NULL; char *ty = NULL; guint ms = 0; - g_assert_true(parse_op_key("rsc_drbd_7788:1_post_notify_start_0", &rsc, &ty, &ms)); - g_assert_cmpstr(rsc, ==, "rsc_drbd_7788:1"); - g_assert_cmpstr(ty, ==, "post_notify_start"); - g_assert_cmpint(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); - g_assert_true(parse_op_key("rabbitmq-bundle-clone_pre_notify_stop_0", &rsc, &ty, &ms)); - g_assert_cmpstr(rsc, ==, "rabbitmq-bundle-clone"); - g_assert_cmpstr(ty, ==, "pre_notify_stop"); - g_assert_cmpint(ms, ==, 0); + 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); - g_assert_true(parse_op_key("post_notify_start_0", &rsc, &ty, &ms)); - g_assert_cmpstr(rsc, ==, "post_notify"); - g_assert_cmpstr(ty, ==, "start"); - g_assert_cmpint(ms, ==, 0); + 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); } static void -skip_rsc(void) +skip_rsc(void **state) { char *ty = NULL; guint ms = 0; - g_assert_true(parse_op_key("Fencing_monitor_60000", NULL, &ty, &ms)); - g_assert_cmpstr(ty, ==, "monitor"); - g_assert_cmpint(ms, ==, 60000); + 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) +skip_ty(void **state) { char *rsc = NULL; guint ms = 0; - g_assert_true(parse_op_key("Fencing_monitor_60000", &rsc, NULL, &ms)); - g_assert_cmpstr(rsc, ==, "Fencing"); - g_assert_cmpint(ms, ==, 60000); + 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) +skip_ms(void **state) { char *rsc = NULL; char *ty = NULL; - g_assert_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, NULL)); - g_assert_cmpstr(rsc, ==, "Fencing"); - g_assert_cmpstr(ty, ==, "monitor"); + 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) +empty_input(void **state) { char *rsc = NULL; char *ty = NULL; guint ms = 0; - g_assert_false(parse_op_key("", &rsc, &ty, &ms)); - g_assert_null(rsc); - g_assert_null(ty); - g_assert_cmpint(ms, ==, 0); + assert_false(parse_op_key("", &rsc, &ty, &ms)); + assert_null(rsc); + assert_null(ty); + assert_int_equal(ms, 0); - g_assert_false(parse_op_key(NULL, &rsc, &ty, &ms)); - g_assert_null(rsc); - g_assert_null(ty); - g_assert_cmpint(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) +malformed_input(void **state) { char *rsc = NULL; char *ty = NULL; guint ms = 0; - g_assert_false(parse_op_key("httpd-bundle-0", &rsc, &ty, &ms)); - g_assert_null(rsc); - g_assert_null(ty); - g_assert_cmpint(ms, ==, 0); + assert_false(parse_op_key("httpd-bundle-0", &rsc, &ty, &ms)); + assert_null(rsc); + assert_null(ty); + assert_int_equal(ms, 0); - g_assert_false(parse_op_key("httpd-bundle-0_monitor", &rsc, &ty, &ms)); - g_assert_null(rsc); - g_assert_null(ty); - g_assert_cmpint(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); - g_assert_false(parse_op_key("httpd-bundle-0_30000", &rsc, &ty, &ms)); - g_assert_null(rsc); - g_assert_null(ty); - g_assert_cmpint(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); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); - - g_test_add_func("/common/utils/parse_op_key/basic", basic); - g_test_add_func("/common/utils/parse_op_key/colon_in_rsc", colon_in_rsc); - g_test_add_func("/common/utils/parse_op_key/dashes_in_rsc", dashes_in_rsc); - g_test_add_func("/common/utils/parse_op_key/migrate_to_from", migrate_to_from); - g_test_add_func("/common/utils/parse_op_key/pre_post", pre_post); - - g_test_add_func("/common/utils/parse_op_key/skip_rsc", skip_rsc); - g_test_add_func("/common/utils/parse_op_key/skip_ty", skip_ty); - g_test_add_func("/common/utils/parse_op_key/skip_ms", skip_ms); - - g_test_add_func("/common/utils/parse_op_key/empty_input", empty_input); - g_test_add_func("/common/utils/parse_op_key/malformed_input", malformed_input); - - return g_test_run(); + const struct CMUnitTest tests[] = { + cmocka_unit_test(basic), + 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), + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/results/Makefile.am b/lib/common/tests/results/Makefile.am index 1ac0488c4a..6c78691e4a 100644 --- a/lib/common/tests/results/Makefile.am +++ b/lib/common/tests/results/Makefile.am @@ -1,30 +1,30 @@ # # 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. # AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include -LDADD = $(top_builddir)/lib/common/libcrmcommon.la +LDADD = $(top_builddir)/lib/common/libcrmcommon.la -lcmocka include $(top_srcdir)/mk/glib-tap.mk # Add each test program here. Each test should be written as a little standalone # program using the glib unit testing functions. See the documentation for more # information. # # https://developer.gnome.org/glib/unstable/glib-Testing.html # # Add "_test" to the end of all test program names to simplify .gitignore. test_programs = pcmk__results_test # If any extra data needs to be added to the source distribution, add it to the # following list. dist_test_data = # If any extra data needs to be used by tests but should not be added to the # source distribution, add it to the following list. test_data = diff --git a/lib/common/tests/results/pcmk__results_test.c b/lib/common/tests/results/pcmk__results_test.c index 8e3f8053b5..57a520c501 100644 --- a/lib/common/tests/results/pcmk__results_test.c +++ b/lib/common/tests/results/pcmk__results_test.c @@ -1,65 +1,71 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include -#include -#include +#include +#include +#include +#include +#include + #include #include static void -test_for_pcmk_rc_name(void) { - g_assert_cmpint(pcmk__strcmp(pcmk_rc_name(pcmk_rc_error-1), "pcmk_rc_unknown_format", pcmk__str_none), ==, 0); - g_assert_cmpint(pcmk__strcmp(pcmk_rc_name(pcmk_rc_ok), "pcmk_rc_ok", pcmk__str_none), ==, 0); - g_assert_cmpint(pcmk__strcmp(pcmk_rc_name(pcmk_rc_ok), "pcmk_rc_ok", pcmk__str_none), ==, 0); - g_assert_cmpint(pcmk__strcmp(pcmk_rc_name(-7777777), "Unknown", pcmk__str_none), ==, 0); +test_for_pcmk_rc_name(void **state) { + assert_string_equal(pcmk_rc_name(pcmk_rc_error-1), "pcmk_rc_unknown_format"); + assert_string_equal(pcmk_rc_name(pcmk_rc_ok), "pcmk_rc_ok"); + assert_string_equal(pcmk_rc_name(pcmk_rc_ok), "pcmk_rc_ok"); + assert_string_equal(pcmk_rc_name(-7777777), "Unknown"); } static void -test_for_pcmk_rc_str(void) { - g_assert_cmpint(pcmk__strcmp(pcmk_rc_str(pcmk_rc_error-1), "Unknown output format", pcmk__str_none), ==, 0); - g_assert_cmpint(pcmk__strcmp(pcmk_rc_str(pcmk_rc_ok), "OK", pcmk__str_none), ==, 0); - g_assert_cmpint(pcmk__strcmp(pcmk_rc_str(-1), "Unknown error", pcmk__str_none), ==, 0); +test_for_pcmk_rc_str(void **state) { + assert_string_equal(pcmk_rc_str(pcmk_rc_error-1), "Unknown output format"); + assert_string_equal(pcmk_rc_str(pcmk_rc_ok), "OK"); + assert_string_equal(pcmk_rc_str(-1), "Unknown error"); } static void -test_for_crm_exit_name(void) { - g_assert_cmpint(pcmk__strcmp(crm_exit_name(CRM_EX_OK), "CRM_EX_OK", pcmk__str_none), ==, 0); +test_for_crm_exit_name(void **state) { + assert_string_equal(crm_exit_name(CRM_EX_OK), "CRM_EX_OK"); } static void -test_for_crm_exit_str(void) { - g_assert_cmpint(pcmk__strcmp(crm_exit_str(CRM_EX_OK), "OK", pcmk__str_none), ==, 0); - g_assert_cmpint(pcmk__strcmp(crm_exit_str(129), "Interrupted by signal", pcmk__str_none), ==, 0); - g_assert_cmpint(pcmk__strcmp(crm_exit_str(-7777777), "Unknown exit status", pcmk__str_none), ==, 0); +test_for_crm_exit_str(void **state) { + assert_string_equal(crm_exit_str(CRM_EX_OK), "OK"); + assert_string_equal(crm_exit_str(129), "Interrupted by signal"); + assert_string_equal(crm_exit_str(-7777777), "Unknown exit status"); } static void -test_for_pcmk_rc2exitc(void) { - g_assert_cmpint(pcmk_rc2exitc(pcmk_rc_ok), ==, CRM_EX_OK); - g_assert_cmpint(pcmk_rc2exitc(-7777777), ==, CRM_EX_ERROR); +test_for_pcmk_rc2exitc(void **state) { + assert_int_equal(pcmk_rc2exitc(pcmk_rc_ok), CRM_EX_OK); + assert_int_equal(pcmk_rc2exitc(-7777777), CRM_EX_ERROR); } static void -test_for_bz2_strerror(void) { - g_assert_cmpint(pcmk__strcmp(bz2_strerror(BZ_STREAM_END), "Ok", pcmk__str_none), ==, 0); +test_for_bz2_strerror(void **state) { + assert_string_equal(bz2_strerror(BZ_STREAM_END), "Ok"); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); - g_test_add_func("/common/results/test_for_pcmk_rc_name", test_for_pcmk_rc_name); - g_test_add_func("/common/results/test_for_pcmk_rc_str", test_for_pcmk_rc_str); - g_test_add_func("/common/results/test_for_crm_exit_name", test_for_crm_exit_name); - g_test_add_func("/common/results/test_for_crm_exit_str", test_for_crm_exit_str); - g_test_add_func("/common/results/test_for_pcmk_rc2exitc", test_for_pcmk_rc2exitc); - g_test_add_func("/common/results/test_for_bz2_strerror", test_for_bz2_strerror); + const struct CMUnitTest tests[] = { + 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), + }; - return g_test_run(); + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/strings/Makefile.am b/lib/common/tests/strings/Makefile.am index bd6cb7a076..6d3243664d 100644 --- a/lib/common/tests/strings/Makefile.am +++ b/lib/common/tests/strings/Makefile.am @@ -1,42 +1,42 @@ # # 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. # AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include -LDADD = $(top_builddir)/lib/common/libcrmcommon.la +LDADD = $(top_builddir)/lib/common/libcrmcommon.la -lcmocka include $(top_srcdir)/mk/glib-tap.mk # Add each test program here. Each test should be written as a little standalone # program using the glib unit testing functions. See the documentation for more # information. # # https://developer.gnome.org/glib/unstable/glib-Testing.html # # Add "_test" to the end of all test program names to simplify .gitignore. test_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__ends_with_test \ pcmk__parse_ll_range_test \ pcmk__scan_double_test \ pcmk__starts_with_test \ pcmk__str_any_of_test \ pcmk__str_in_list_test \ pcmk__strcmp_test # If any extra data needs to be added to the source distribution, add it to the # following list. dist_test_data = # If any extra data needs to be used by tests but should not be added to the # source distribution, add it to the following list. test_data = diff --git a/lib/common/tests/strings/crm_get_msec_test.c b/lib/common/tests/strings/crm_get_msec_test.c index ea9fe616ea..ad6b43bb0f 100644 --- a/lib/common/tests/strings/crm_get_msec_test.c +++ b/lib/common/tests/strings/crm_get_msec_test.c @@ -1,54 +1,62 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include +#include +#include +#include +#include +#include + static void -bad_input(void) { - g_assert_cmpint(crm_get_msec(NULL), ==, PCMK__PARSE_INT_DEFAULT); - g_assert_cmpint(crm_get_msec(" "), ==, PCMK__PARSE_INT_DEFAULT); - g_assert_cmpint(crm_get_msec("abcxyz"), ==, PCMK__PARSE_INT_DEFAULT); - g_assert_cmpint(crm_get_msec("100xs"), ==, PCMK__PARSE_INT_DEFAULT); - g_assert_cmpint(crm_get_msec(" 100 xs "), ==, PCMK__PARSE_INT_DEFAULT); - g_assert_cmpint(crm_get_msec("-100ms"), ==, PCMK__PARSE_INT_DEFAULT); +bad_input(void **state) { + assert_int_equal(crm_get_msec(NULL), PCMK__PARSE_INT_DEFAULT); + assert_int_equal(crm_get_msec(" "), PCMK__PARSE_INT_DEFAULT); + assert_int_equal(crm_get_msec("abcxyz"), PCMK__PARSE_INT_DEFAULT); + assert_int_equal(crm_get_msec("100xs"), PCMK__PARSE_INT_DEFAULT); + assert_int_equal(crm_get_msec(" 100 xs "), PCMK__PARSE_INT_DEFAULT); + assert_int_equal(crm_get_msec("-100ms"), PCMK__PARSE_INT_DEFAULT); } static void -good_input(void) { - g_assert_cmpint(crm_get_msec("100"), ==, 100000); - g_assert_cmpint(crm_get_msec(" 100 "), ==, 100000); - g_assert_cmpint(crm_get_msec("\t100\n"), ==, 100000); - - g_assert_cmpint(crm_get_msec("100ms"), ==, 100); - g_assert_cmpint(crm_get_msec("100 MSEC"), ==, 100); - g_assert_cmpint(crm_get_msec("1000US"), ==, 1); - g_assert_cmpint(crm_get_msec("1000usec"), ==, 1); - g_assert_cmpint(crm_get_msec("12s"), ==, 12000); - g_assert_cmpint(crm_get_msec("12 sec"), ==, 12000); - g_assert_cmpint(crm_get_msec("1m"), ==, 60000); - g_assert_cmpint(crm_get_msec("13 min"), ==, 780000); - g_assert_cmpint(crm_get_msec("2\th"), ==, 7200000); - g_assert_cmpint(crm_get_msec("1 hr"), ==, 3600000); +good_input(void **state) { + assert_int_equal(crm_get_msec("100"), 100000); + assert_int_equal(crm_get_msec(" 100 "), 100000); + assert_int_equal(crm_get_msec("\t100\n"), 100000); + + assert_int_equal(crm_get_msec("100ms"), 100); + assert_int_equal(crm_get_msec("100 MSEC"), 100); + assert_int_equal(crm_get_msec("1000US"), 1); + assert_int_equal(crm_get_msec("1000usec"), 1); + assert_int_equal(crm_get_msec("12s"), 12000); + assert_int_equal(crm_get_msec("12 sec"), 12000); + assert_int_equal(crm_get_msec("1m"), 60000); + assert_int_equal(crm_get_msec("13 min"), 780000); + assert_int_equal(crm_get_msec("2\th"), 7200000); + assert_int_equal(crm_get_msec("1 hr"), 3600000); } static void -overflow(void) { - g_assert_cmpint(crm_get_msec("9223372036854775807s"), ==, LLONG_MAX); +overflow(void **state) { + assert_int_equal(crm_get_msec("9223372036854775807s"), LLONG_MAX); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); + const struct CMUnitTest tests[] = { + cmocka_unit_test(bad_input), + cmocka_unit_test(good_input), + cmocka_unit_test(overflow), + }; - g_test_add_func("/common/strings/get_msec/bad_input", bad_input); - g_test_add_func("/common/strings/get_msec/good_input", good_input); - g_test_add_func("/common/strings/get_msec/overflow", overflow); - return g_test_run(); + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/strings/crm_is_true_test.c b/lib/common/tests/strings/crm_is_true_test.c index 20def0d9b7..b1d5c9cab7 100644 --- a/lib/common/tests/strings/crm_is_true_test.c +++ b/lib/common/tests/strings/crm_is_true_test.c @@ -1,61 +1,69 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include +#include +#include +#include +#include +#include + static void -bad_input(void) { - g_assert_false(crm_is_true(NULL)); +bad_input(void **state) { + assert_false(crm_is_true(NULL)); } static void -is_true(void) { - g_assert_true(crm_is_true("true")); - g_assert_true(crm_is_true("TrUe")); - g_assert_true(crm_is_true("on")); - g_assert_true(crm_is_true("ON")); - g_assert_true(crm_is_true("yes")); - g_assert_true(crm_is_true("yES")); - g_assert_true(crm_is_true("y")); - g_assert_true(crm_is_true("Y")); - g_assert_true(crm_is_true("1")); +is_true(void **state) { + assert_true(crm_is_true("true")); + assert_true(crm_is_true("TrUe")); + assert_true(crm_is_true("on")); + assert_true(crm_is_true("ON")); + assert_true(crm_is_true("yes")); + assert_true(crm_is_true("yES")); + assert_true(crm_is_true("y")); + assert_true(crm_is_true("Y")); + assert_true(crm_is_true("1")); } static void -is_false(void) { - g_assert_false(crm_is_true("false")); - g_assert_false(crm_is_true("fAlSe")); - g_assert_false(crm_is_true("off")); - g_assert_false(crm_is_true("OFF")); - g_assert_false(crm_is_true("no")); - g_assert_false(crm_is_true("No")); - g_assert_false(crm_is_true("n")); - g_assert_false(crm_is_true("N")); - g_assert_false(crm_is_true("0")); - - g_assert_false(crm_is_true("")); - g_assert_false(crm_is_true("blahblah")); - - g_assert_false(crm_is_true("truedat")); - g_assert_false(crm_is_true("onnn")); - g_assert_false(crm_is_true("yep")); - g_assert_false(crm_is_true("Y!")); - g_assert_false(crm_is_true("100")); +is_false(void **state) { + assert_false(crm_is_true("false")); + assert_false(crm_is_true("fAlSe")); + assert_false(crm_is_true("off")); + assert_false(crm_is_true("OFF")); + assert_false(crm_is_true("no")); + assert_false(crm_is_true("No")); + assert_false(crm_is_true("n")); + assert_false(crm_is_true("N")); + assert_false(crm_is_true("0")); + + assert_false(crm_is_true("")); + assert_false(crm_is_true("blahblah")); + + assert_false(crm_is_true("truedat")); + assert_false(crm_is_true("onnn")); + assert_false(crm_is_true("yep")); + assert_false(crm_is_true("Y!")); + assert_false(crm_is_true("100")); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); + const struct CMUnitTest tests[] = { + cmocka_unit_test(bad_input), + cmocka_unit_test(is_true), + cmocka_unit_test(is_false), + }; - g_test_add_func("/common/strings/crm_is_true/bad_input", bad_input); - g_test_add_func("/common/strings/crm_is_true/is_true", is_true); - g_test_add_func("/common/strings/crm_is_true/is_false", is_false); - return g_test_run(); + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/strings/crm_str_to_boolean_test.c b/lib/common/tests/strings/crm_str_to_boolean_test.c index 03b799f9d9..6e9748aa91 100644 --- a/lib/common/tests/strings/crm_str_to_boolean_test.c +++ b/lib/common/tests/strings/crm_str_to_boolean_test.c @@ -1,96 +1,104 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include +#include +#include +#include +#include +#include + static void -bad_input(void) { - g_assert_cmpint(crm_str_to_boolean(NULL, NULL), ==, -1); - g_assert_cmpint(crm_str_to_boolean("", NULL), ==, -1); - g_assert_cmpint(crm_str_to_boolean("blahblah", NULL), ==, -1); +bad_input(void **state) { + assert_int_equal(crm_str_to_boolean(NULL, NULL), -1); + assert_int_equal(crm_str_to_boolean("", NULL), -1); + assert_int_equal(crm_str_to_boolean("blahblah", NULL), -1); } static void -is_true(void) { +is_true(void **state) { int ret; - g_assert_cmpint(crm_str_to_boolean("true", &ret), ==, 1); - g_assert_true(ret); - g_assert_cmpint(crm_str_to_boolean("TrUe", &ret), ==, 1); - g_assert_true(ret); - g_assert_cmpint(crm_str_to_boolean("on", &ret), ==, 1); - g_assert_true(ret); - g_assert_cmpint(crm_str_to_boolean("ON", &ret), ==, 1); - g_assert_true(ret); - g_assert_cmpint(crm_str_to_boolean("yes", &ret), ==, 1); - g_assert_true(ret); - g_assert_cmpint(crm_str_to_boolean("yES", &ret), ==, 1); - g_assert_true(ret); - g_assert_cmpint(crm_str_to_boolean("y", &ret), ==, 1); - g_assert_true(ret); - g_assert_cmpint(crm_str_to_boolean("Y", &ret), ==, 1); - g_assert_true(ret); - g_assert_cmpint(crm_str_to_boolean("1", &ret), ==, 1); - g_assert_true(ret); + assert_int_equal(crm_str_to_boolean("true", &ret), 1); + assert_true(ret); + assert_int_equal(crm_str_to_boolean("TrUe", &ret), 1); + assert_true(ret); + assert_int_equal(crm_str_to_boolean("on", &ret), 1); + assert_true(ret); + assert_int_equal(crm_str_to_boolean("ON", &ret), 1); + assert_true(ret); + assert_int_equal(crm_str_to_boolean("yes", &ret), 1); + assert_true(ret); + assert_int_equal(crm_str_to_boolean("yES", &ret), 1); + assert_true(ret); + assert_int_equal(crm_str_to_boolean("y", &ret), 1); + assert_true(ret); + assert_int_equal(crm_str_to_boolean("Y", &ret), 1); + assert_true(ret); + assert_int_equal(crm_str_to_boolean("1", &ret), 1); + assert_true(ret); } static void -is_not_true(void) { - g_assert_cmpint(crm_str_to_boolean("truedat", NULL), ==, -1); - g_assert_cmpint(crm_str_to_boolean("onnn", NULL), ==, -1); - g_assert_cmpint(crm_str_to_boolean("yep", NULL), ==, -1); - g_assert_cmpint(crm_str_to_boolean("Y!", NULL), ==, -1); - g_assert_cmpint(crm_str_to_boolean("100", NULL), ==, -1); +is_not_true(void **state) { + assert_int_equal(crm_str_to_boolean("truedat", NULL), -1); + assert_int_equal(crm_str_to_boolean("onnn", NULL), -1); + assert_int_equal(crm_str_to_boolean("yep", NULL), -1); + assert_int_equal(crm_str_to_boolean("Y!", NULL), -1); + assert_int_equal(crm_str_to_boolean("100", NULL), -1); } static void -is_false(void) { +is_false(void **state) { int ret; - g_assert_cmpint(crm_str_to_boolean("false", &ret), ==, 1); - g_assert_false(ret); - g_assert_cmpint(crm_str_to_boolean("fAlSe", &ret), ==, 1); - g_assert_false(ret); - g_assert_cmpint(crm_str_to_boolean("off", &ret), ==, 1); - g_assert_false(ret); - g_assert_cmpint(crm_str_to_boolean("OFF", &ret), ==, 1); - g_assert_false(ret); - g_assert_cmpint(crm_str_to_boolean("no", &ret), ==, 1); - g_assert_false(ret); - g_assert_cmpint(crm_str_to_boolean("No", &ret), ==, 1); - g_assert_false(ret); - g_assert_cmpint(crm_str_to_boolean("n", &ret), ==, 1); - g_assert_false(ret); - g_assert_cmpint(crm_str_to_boolean("N", &ret), ==, 1); - g_assert_false(ret); - g_assert_cmpint(crm_str_to_boolean("0", &ret), ==, 1); - g_assert_false(ret); + assert_int_equal(crm_str_to_boolean("false", &ret), 1); + assert_false(ret); + assert_int_equal(crm_str_to_boolean("fAlSe", &ret), 1); + assert_false(ret); + assert_int_equal(crm_str_to_boolean("off", &ret), 1); + assert_false(ret); + assert_int_equal(crm_str_to_boolean("OFF", &ret), 1); + assert_false(ret); + assert_int_equal(crm_str_to_boolean("no", &ret), 1); + assert_false(ret); + assert_int_equal(crm_str_to_boolean("No", &ret), 1); + assert_false(ret); + assert_int_equal(crm_str_to_boolean("n", &ret), 1); + assert_false(ret); + assert_int_equal(crm_str_to_boolean("N", &ret), 1); + assert_false(ret); + assert_int_equal(crm_str_to_boolean("0", &ret), 1); + assert_false(ret); } static void -is_not_false(void) { - g_assert_cmpint(crm_str_to_boolean("falseee", NULL), ==, -1); - g_assert_cmpint(crm_str_to_boolean("of", NULL), ==, -1); - g_assert_cmpint(crm_str_to_boolean("nope", NULL), ==, -1); - g_assert_cmpint(crm_str_to_boolean("N!", NULL), ==, -1); - g_assert_cmpint(crm_str_to_boolean("000", NULL), ==, -1); +is_not_false(void **state) { + assert_int_equal(crm_str_to_boolean("falseee", NULL), -1); + assert_int_equal(crm_str_to_boolean("of", NULL), -1); + assert_int_equal(crm_str_to_boolean("nope", NULL), -1); + assert_int_equal(crm_str_to_boolean("N!", NULL), -1); + assert_int_equal(crm_str_to_boolean("000", NULL), -1); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); + const struct CMUnitTest tests[] = { + cmocka_unit_test(bad_input), + cmocka_unit_test(is_true), + cmocka_unit_test(is_not_true), + cmocka_unit_test(is_false), + cmocka_unit_test(is_not_false), + }; - g_test_add_func("/common/strings/crm_str_to_boolean/bad_input", bad_input); - g_test_add_func("/common/strings/crm_str_to_boolean/is_true", is_true); - g_test_add_func("/common/strings/crm_str_to_boolean/is_not_true", is_not_true); - g_test_add_func("/common/strings/crm_str_to_boolean/is_false", is_false); - g_test_add_func("/common/strings/crm_str_to_boolean/is_not_false", is_not_false); - return g_test_run(); + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/strings/pcmk__add_word_test.c b/lib/common/tests/strings/pcmk__add_word_test.c index 600e8e8dd5..50f2599c5e 100644 --- a/lib/common/tests/strings/pcmk__add_word_test.c +++ b/lib/common/tests/strings/pcmk__add_word_test.c @@ -1,104 +1,108 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ -#include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include + static void -add_words(void) +add_words(void **state) { char *list = NULL; size_t list_len = 0; pcmk__add_word(&list, &list_len, "hello"); pcmk__add_word(&list, &list_len, "world"); - g_assert_cmpint(strcmp(list, "hello world"), ==, 0); + assert_int_equal(strcmp(list, "hello world"), 0); free(list); } static void -add_with_no_len(void) +add_with_no_len(void **state) { char *list = NULL; pcmk__add_word(&list, NULL, "hello"); pcmk__add_word(&list, NULL, "world"); - g_assert_cmpint(strcmp(list, "hello world"), ==, 0); + assert_int_equal(strcmp(list, "hello world"), 0); free(list); } static void -add_nothing(void) +add_nothing(void **state) { char *list = NULL; pcmk__add_word(&list, NULL, "hello"); pcmk__add_word(&list, NULL, NULL); pcmk__add_word(&list, NULL, ""); - g_assert_cmpint(strcmp(list, "hello"), ==, 0); + assert_int_equal(strcmp(list, "hello"), 0); free(list); } static void -add_with_null(void) +add_with_null(void **state) { char *list = NULL; size_t list_len = 0; pcmk__add_separated_word(&list, &list_len, "hello", NULL); pcmk__add_separated_word(&list, &list_len, "world", NULL); pcmk__add_separated_word(&list, &list_len, "I am a unit test", NULL); - g_assert_cmpint(strcmp(list, "hello world I am a unit test"), ==, 0); + assert_int_equal(strcmp(list, "hello world I am a unit test"), 0); free(list); } static void -add_with_comma(void) +add_with_comma(void **state) { char *list = NULL; size_t list_len = 0; pcmk__add_separated_word(&list, &list_len, "hello", ","); pcmk__add_separated_word(&list, &list_len, "world", ","); pcmk__add_separated_word(&list, &list_len, "I am a unit test", ","); - g_assert_cmpint(strcmp(list, "hello,world,I am a unit test"), ==, 0); + assert_int_equal(strcmp(list, "hello,world,I am a unit test"), 0); free(list); } static void -add_with_comma_and_space(void) +add_with_comma_and_space(void **state) { char *list = NULL; size_t list_len = 0; pcmk__add_separated_word(&list, &list_len, "hello", ", "); pcmk__add_separated_word(&list, &list_len, "world", ", "); pcmk__add_separated_word(&list, &list_len, "I am a unit test", ", "); - g_assert_cmpint(strcmp(list, "hello, world, I am a unit test"), ==, 0); + assert_int_equal(strcmp(list, "hello, world, I am a unit test"), 0); free(list); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); - - g_test_add_func("/common/strings/add_word/add_words", add_words); - g_test_add_func("/common/strings/add_word/add_with_no_len", - add_with_no_len); - g_test_add_func("/common/strings/add_word/add_nothing", add_nothing); - g_test_add_func("/common/strings/add_word/add_with_null", add_with_null); - g_test_add_func("/common/strings/add_word/add_with_comma", add_with_comma); - g_test_add_func("/common/strings/add_word/add_with_comma_and_space", - add_with_comma_and_space); - - return g_test_run(); + const struct CMUnitTest tests[] = { + cmocka_unit_test(add_words), + cmocka_unit_test(add_with_no_len), + cmocka_unit_test(add_nothing), + cmocka_unit_test(add_with_null), + cmocka_unit_test(add_with_comma), + cmocka_unit_test(add_with_comma_and_space), + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/strings/pcmk__btoa_test.c b/lib/common/tests/strings/pcmk__btoa_test.c index 240cb3aa7e..10261f5623 100644 --- a/lib/common/tests/strings/pcmk__btoa_test.c +++ b/lib/common/tests/strings/pcmk__btoa_test.c @@ -1,26 +1,34 @@ /* - * Copyright 2020 the Pacemaker project contributors + * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include +#include +#include +#include +#include +#include + static void -btoa(void) { - g_assert_cmpstr(pcmk__btoa(false), ==, "false"); - g_assert_cmpstr(pcmk__btoa(true), ==, "true"); - g_assert_cmpstr(pcmk__btoa(1 == 0), ==, "false"); +btoa(void **state) { + assert_string_equal(pcmk__btoa(false), "false"); + assert_string_equal(pcmk__btoa(true), "true"); + assert_string_equal(pcmk__btoa(1 == 0), "false"); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); + const struct CMUnitTest tests[] = { + cmocka_unit_test(btoa), + }; - g_test_add_func("/common/strings/btoa/btoa", btoa); - return g_test_run(); + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/strings/pcmk__char_in_any_str_test.c b/lib/common/tests/strings/pcmk__char_in_any_str_test.c index 11159ccad9..cd469af990 100644 --- a/lib/common/tests/strings/pcmk__char_in_any_str_test.c +++ b/lib/common/tests/strings/pcmk__char_in_any_str_test.c @@ -1,55 +1,58 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include -#include -#include -#include +#include +#include +#include +#include +#include static void -empty_list(void) +empty_list(void **state) { - g_assert_false(pcmk__char_in_any_str('x', NULL)); - g_assert_false(pcmk__char_in_any_str('\0', NULL)); + assert_false(pcmk__char_in_any_str('x', NULL)); + assert_false(pcmk__char_in_any_str('\0', NULL)); } static void -null_char(void) +null_char(void **state) { - g_assert_true(pcmk__char_in_any_str('\0', "xxx", "yyy", NULL)); - g_assert_true(pcmk__char_in_any_str('\0', "", NULL)); + assert_true(pcmk__char_in_any_str('\0', "xxx", "yyy", NULL)); + assert_true(pcmk__char_in_any_str('\0', "", NULL)); } static void -in_list(void) +in_list(void **state) { - g_assert_true(pcmk__char_in_any_str('x', "aaa", "bbb", "xxx", NULL)); + assert_true(pcmk__char_in_any_str('x', "aaa", "bbb", "xxx", NULL)); } static void -not_in_list(void) +not_in_list(void **state) { - g_assert_false(pcmk__char_in_any_str('x', "aaa", "bbb", NULL)); - g_assert_false(pcmk__char_in_any_str('A', "aaa", "bbb", NULL)); - g_assert_false(pcmk__char_in_any_str('x', "", NULL)); + assert_false(pcmk__char_in_any_str('x', "aaa", "bbb", NULL)); + assert_false(pcmk__char_in_any_str('A', "aaa", "bbb", NULL)); + assert_false(pcmk__char_in_any_str('x', "", NULL)); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); - - g_test_add_func("/common/strings/char_in_any_str/empty_list", empty_list); - g_test_add_func("/common/strings/char_in_any_str/null_char", null_char); - g_test_add_func("/common/strings/char_in_any_str/in", in_list); - g_test_add_func("/common/strings/char_in_any_str/not_in", not_in_list); - - return g_test_run(); + const struct CMUnitTest tests[] = { + cmocka_unit_test(empty_list), + cmocka_unit_test(null_char), + cmocka_unit_test(in_list), + cmocka_unit_test(not_in_list), + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/strings/pcmk__ends_with_test.c b/lib/common/tests/strings/pcmk__ends_with_test.c index 09085a181a..00a08445aa 100644 --- a/lib/common/tests/strings/pcmk__ends_with_test.c +++ b/lib/common/tests/strings/pcmk__ends_with_test.c @@ -1,61 +1,69 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include +#include +#include +#include +#include +#include + static void -bad_input(void) { - g_assert_false(pcmk__ends_with(NULL, "xyz")); - - g_assert_true(pcmk__ends_with(NULL, NULL)); - g_assert_true(pcmk__ends_with(NULL, "")); - g_assert_true(pcmk__ends_with("", NULL)); - g_assert_true(pcmk__ends_with("", "")); - g_assert_true(pcmk__ends_with("abc", NULL)); - g_assert_true(pcmk__ends_with("abc", "")); +bad_input(void **state) { + assert_false(pcmk__ends_with(NULL, "xyz")); + + assert_true(pcmk__ends_with(NULL, NULL)); + assert_true(pcmk__ends_with(NULL, "")); + assert_true(pcmk__ends_with("", NULL)); + assert_true(pcmk__ends_with("", "")); + assert_true(pcmk__ends_with("abc", NULL)); + assert_true(pcmk__ends_with("abc", "")); } static void -ends_with(void) { - g_assert_true(pcmk__ends_with("abc", "abc")); - g_assert_true(pcmk__ends_with("abc", "bc")); - g_assert_true(pcmk__ends_with("abc", "c")); - g_assert_true(pcmk__ends_with("abcbc", "bc")); - - g_assert_false(pcmk__ends_with("abc", "def")); - g_assert_false(pcmk__ends_with("abc", "defg")); - g_assert_false(pcmk__ends_with("abc", "bcd")); - g_assert_false(pcmk__ends_with("abc", "ab")); - - g_assert_false(pcmk__ends_with("abc", "BC")); +ends_with(void **state) { + assert_true(pcmk__ends_with("abc", "abc")); + assert_true(pcmk__ends_with("abc", "bc")); + assert_true(pcmk__ends_with("abc", "c")); + assert_true(pcmk__ends_with("abcbc", "bc")); + + assert_false(pcmk__ends_with("abc", "def")); + assert_false(pcmk__ends_with("abc", "defg")); + assert_false(pcmk__ends_with("abc", "bcd")); + assert_false(pcmk__ends_with("abc", "ab")); + + assert_false(pcmk__ends_with("abc", "BC")); } static void -ends_with_ext(void) { - g_assert_true(pcmk__ends_with_ext("ab.c", ".c")); - g_assert_true(pcmk__ends_with_ext("ab.cb.c", ".c")); +ends_with_ext(void **state) { + assert_true(pcmk__ends_with_ext("ab.c", ".c")); + assert_true(pcmk__ends_with_ext("ab.cb.c", ".c")); - g_assert_false(pcmk__ends_with_ext("ab.c", ".def")); - g_assert_false(pcmk__ends_with_ext("ab.c", ".defg")); - g_assert_false(pcmk__ends_with_ext("ab.c", ".cd")); - g_assert_false(pcmk__ends_with_ext("ab.c", "ab")); + assert_false(pcmk__ends_with_ext("ab.c", ".def")); + assert_false(pcmk__ends_with_ext("ab.c", ".defg")); + assert_false(pcmk__ends_with_ext("ab.c", ".cd")); + assert_false(pcmk__ends_with_ext("ab.c", "ab")); - g_assert_false(pcmk__ends_with_ext("ab.c", ".C")); + assert_false(pcmk__ends_with_ext("ab.c", ".C")); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); + const struct CMUnitTest tests[] = { + cmocka_unit_test(bad_input), + cmocka_unit_test(ends_with), + cmocka_unit_test(ends_with_ext), + }; - g_test_add_func("/common/strings/ends_with/bad_input", bad_input); - g_test_add_func("/common/strings/ends_with/ends_with", ends_with); - g_test_add_func("/common/strings/ends_with/ends_with_ext", ends_with_ext); - return g_test_run(); + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/strings/pcmk__parse_ll_range_test.c b/lib/common/tests/strings/pcmk__parse_ll_range_test.c index 19049fea18..a4f91aef19 100644 --- a/lib/common/tests/strings/pcmk__parse_ll_range_test.c +++ b/lib/common/tests/strings/pcmk__parse_ll_range_test.c @@ -1,109 +1,106 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include -#include +#include +#include +#include +#include +#include static void -empty_input_string(void) +empty_input_string(void **state) { long long start, end; - g_assert_cmpint(pcmk__parse_ll_range(NULL, &start, &end), ==, - pcmk_rc_unknown_format); - g_assert_cmpint(pcmk__parse_ll_range("", &start, &end), ==, - pcmk_rc_unknown_format); + assert_int_equal(pcmk__parse_ll_range(NULL, &start, &end), pcmk_rc_unknown_format); + assert_int_equal(pcmk__parse_ll_range("", &start, &end), pcmk_rc_unknown_format); } static void -missing_separator(void) +missing_separator(void **state) { long long start, end; - g_assert_cmpint(pcmk__parse_ll_range("1234", &start, &end), ==, pcmk_rc_ok); - g_assert_cmpint(start, ==, 1234); - g_assert_cmpint(end, ==, 1234); + assert_int_equal(pcmk__parse_ll_range("1234", &start, &end), pcmk_rc_ok); + assert_int_equal(start, 1234); + assert_int_equal(end, 1234); } static void -only_separator(void) +only_separator(void **state) { long long start, end; - g_assert_cmpint(pcmk__parse_ll_range("-", &start, &end), ==, - pcmk_rc_unknown_format); - g_assert_cmpint(start, ==, PCMK__PARSE_INT_DEFAULT); - g_assert_cmpint(end, ==, PCMK__PARSE_INT_DEFAULT); + assert_int_equal(pcmk__parse_ll_range("-", &start, &end), pcmk_rc_unknown_format); + assert_int_equal(start, PCMK__PARSE_INT_DEFAULT); + assert_int_equal(end, PCMK__PARSE_INT_DEFAULT); } static void -no_range_end(void) +no_range_end(void **state) { long long start, end; - g_assert_cmpint(pcmk__parse_ll_range("2000-", &start, &end), ==, - pcmk_rc_ok); - g_assert_cmpint(start, ==, 2000); - g_assert_cmpint(end, ==, PCMK__PARSE_INT_DEFAULT); + assert_int_equal(pcmk__parse_ll_range("2000-", &start, &end), pcmk_rc_ok); + assert_int_equal(start, 2000); + assert_int_equal(end, PCMK__PARSE_INT_DEFAULT); } static void -no_range_start(void) +no_range_start(void **state) { long long start, end; - g_assert_cmpint(pcmk__parse_ll_range("-2020", &start, &end), ==, - pcmk_rc_ok); - g_assert_cmpint(start, ==, PCMK__PARSE_INT_DEFAULT); - g_assert_cmpint(end, ==, 2020); + assert_int_equal(pcmk__parse_ll_range("-2020", &start, &end), pcmk_rc_ok); + assert_int_equal(start, PCMK__PARSE_INT_DEFAULT); + assert_int_equal(end, 2020); } static void -range_start_and_end(void) +range_start_and_end(void **state) { long long start, end; - g_assert_cmpint(pcmk__parse_ll_range("2000-2020", &start, &end), ==, - pcmk_rc_ok); - g_assert_cmpint(start, ==, 2000); - g_assert_cmpint(end, ==, 2020); + assert_int_equal(pcmk__parse_ll_range("2000-2020", &start, &end), pcmk_rc_ok); + assert_int_equal(start, 2000); + assert_int_equal(end, 2020); } static void -garbage(void) +garbage(void **state) { long long start, end; - g_assert_cmpint(pcmk__parse_ll_range("2000x-", &start, &end), ==, - pcmk_rc_unknown_format); - g_assert_cmpint(start, ==, PCMK__PARSE_INT_DEFAULT); - g_assert_cmpint(end, ==, PCMK__PARSE_INT_DEFAULT); + assert_int_equal(pcmk__parse_ll_range("2000x-", &start, &end), pcmk_rc_unknown_format); + assert_int_equal(start, PCMK__PARSE_INT_DEFAULT); + assert_int_equal(end, PCMK__PARSE_INT_DEFAULT); - g_assert_cmpint(pcmk__parse_ll_range("-x2000", &start, &end), ==, - pcmk_rc_unknown_format); - g_assert_cmpint(start, ==, PCMK__PARSE_INT_DEFAULT); - g_assert_cmpint(end, ==, PCMK__PARSE_INT_DEFAULT); + assert_int_equal(pcmk__parse_ll_range("-x2000", &start, &end), pcmk_rc_unknown_format); + assert_int_equal(start, PCMK__PARSE_INT_DEFAULT); + assert_int_equal(end, PCMK__PARSE_INT_DEFAULT); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); - - g_test_add_func("/common/strings/range/empty", empty_input_string); - g_test_add_func("/common/strings/range/no_sep", missing_separator); - g_test_add_func("/common/strings/range/only_sep", only_separator); - g_test_add_func("/common/strings/range/no_end", no_range_end); - g_test_add_func("/common/strings/range/no_start", no_range_start); - g_test_add_func("/common/strings/range/start_and_end", range_start_and_end); - - g_test_add_func("/common/strings/range/garbage", garbage); - - return g_test_run(); + const struct CMUnitTest tests[] = { + cmocka_unit_test(empty_input_string), + cmocka_unit_test(missing_separator), + cmocka_unit_test(only_separator), + cmocka_unit_test(no_range_end), + cmocka_unit_test(no_range_start), + cmocka_unit_test(range_start_and_end), + + cmocka_unit_test(garbage), + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/strings/pcmk__scan_double_test.c b/lib/common/tests/strings/pcmk__scan_double_test.c index 3d0d0f160d..eb9c7a9bad 100644 --- a/lib/common/tests/strings/pcmk__scan_double_test.c +++ b/lib/common/tests/strings/pcmk__scan_double_test.c @@ -1,169 +1,156 @@ /* * Copyright 2004-2021 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include +#include +#include +#include +#include +#include + #include // DBL_MAX, etc. #include // fabs() -#include // Ensure plenty of characters for %f display #define LOCAL_BUF_SIZE 2 * DBL_MAX_10_EXP -/* - * Avoids compiler warnings for floating-point equality checks. - * Use for comparing numbers (e.g., 1.0 == 1.0), not expression values. - */ -#define ASSERT_DBL_EQ(d1, d2) g_assert_cmpfloat(fabs(d1 - d2), \ - <, DBL_EPSILON); - static void -empty_input_string(void) +empty_input_string(void **state) { double result; // Without default_text - g_assert_cmpint(pcmk__scan_double(NULL, &result, NULL, NULL), ==, EINVAL); - ASSERT_DBL_EQ(result, PCMK__PARSE_DBL_DEFAULT); + assert_int_equal(pcmk__scan_double(NULL, &result, NULL, NULL), EINVAL); + assert_float_equal(result, PCMK__PARSE_DBL_DEFAULT, DBL_EPSILON); - g_assert_cmpint(pcmk__scan_double("", &result, NULL, NULL), ==, EINVAL); - ASSERT_DBL_EQ(result, PCMK__PARSE_DBL_DEFAULT); + assert_int_equal(pcmk__scan_double("", &result, NULL, NULL), EINVAL); + assert_float_equal(result, PCMK__PARSE_DBL_DEFAULT, DBL_EPSILON); // With default_text - g_assert_cmpint(pcmk__scan_double(NULL, &result, "2.0", NULL), ==, - pcmk_rc_ok); - ASSERT_DBL_EQ(result, 2.0); + assert_int_equal(pcmk__scan_double(NULL, &result, "2.0", NULL), pcmk_rc_ok); + assert_float_equal(result, 2.0, DBL_EPSILON); - g_assert_cmpint(pcmk__scan_double("", &result, "2.0", NULL), ==, EINVAL); - ASSERT_DBL_EQ(result, PCMK__PARSE_DBL_DEFAULT); + assert_int_equal(pcmk__scan_double("", &result, "2.0", NULL), EINVAL); + assert_float_equal(result, PCMK__PARSE_DBL_DEFAULT, DBL_EPSILON); } static void -bad_input_string(void) +bad_input_string(void **state) { double result; // Without default text - g_assert_cmpint(pcmk__scan_double("asdf", &result, NULL, NULL), ==, EINVAL); - ASSERT_DBL_EQ(result, PCMK__PARSE_DBL_DEFAULT); + assert_int_equal(pcmk__scan_double("asdf", &result, NULL, NULL), EINVAL); + assert_float_equal(result, PCMK__PARSE_DBL_DEFAULT, DBL_EPSILON); - g_assert_cmpint(pcmk__scan_double("as2.0", &result, NULL, NULL), ==, - EINVAL); - ASSERT_DBL_EQ(result, PCMK__PARSE_DBL_DEFAULT); + assert_int_equal(pcmk__scan_double("as2.0", &result, NULL, NULL), EINVAL); + assert_float_equal(result, PCMK__PARSE_DBL_DEFAULT, DBL_EPSILON); // With default text (not used) - g_assert_cmpint(pcmk__scan_double("asdf", &result, "2.0", NULL), ==, - EINVAL); - ASSERT_DBL_EQ(result, PCMK__PARSE_DBL_DEFAULT); + assert_int_equal(pcmk__scan_double("asdf", &result, "2.0", NULL), EINVAL); + assert_float_equal(result, PCMK__PARSE_DBL_DEFAULT, DBL_EPSILON); - g_assert_cmpint(pcmk__scan_double("as2.0", &result, "2.0", NULL), ==, - EINVAL); - ASSERT_DBL_EQ(result, PCMK__PARSE_DBL_DEFAULT); + assert_int_equal(pcmk__scan_double("as2.0", &result, "2.0", NULL), EINVAL); + assert_float_equal(result, PCMK__PARSE_DBL_DEFAULT, DBL_EPSILON); } static void -trailing_chars(void) +trailing_chars(void **state) { double result; - g_assert_cmpint(pcmk__scan_double("2.0asdf", &result, NULL, NULL), ==, - pcmk_rc_ok); - ASSERT_DBL_EQ(result, 2.0); + assert_int_equal(pcmk__scan_double("2.0asdf", &result, NULL, NULL), pcmk_rc_ok); + assert_float_equal(result, 2.0, DBL_EPSILON); } static void -typical_case(void) +typical_case(void **state) { char str[LOCAL_BUF_SIZE]; double result; - g_assert_cmpint(pcmk__scan_double("0.0", &result, NULL, NULL), ==, - pcmk_rc_ok); - ASSERT_DBL_EQ(result, 0.0); + assert_int_equal(pcmk__scan_double("0.0", &result, NULL, NULL), pcmk_rc_ok); + assert_float_equal(result, 0.0, DBL_EPSILON); - g_assert_cmpint(pcmk__scan_double("1.0", &result, NULL, NULL), ==, - pcmk_rc_ok); - ASSERT_DBL_EQ(result, 1.0); + assert_int_equal(pcmk__scan_double("1.0", &result, NULL, NULL), pcmk_rc_ok); + assert_float_equal(result, 1.0, DBL_EPSILON); - g_assert_cmpint(pcmk__scan_double("-1.0", &result, NULL, NULL), ==, - pcmk_rc_ok); - ASSERT_DBL_EQ(result, -1.0); + assert_int_equal(pcmk__scan_double("-1.0", &result, NULL, NULL), pcmk_rc_ok); + assert_float_equal(result, -1.0, DBL_EPSILON); snprintf(str, LOCAL_BUF_SIZE, "%f", DBL_MAX); - g_assert_cmpint(pcmk__scan_double(str, &result, NULL, NULL), ==, - pcmk_rc_ok); - ASSERT_DBL_EQ(result, DBL_MAX); + assert_int_equal(pcmk__scan_double(str, &result, NULL, NULL), pcmk_rc_ok); + assert_float_equal(result, DBL_MAX, DBL_EPSILON); snprintf(str, LOCAL_BUF_SIZE, "%f", -DBL_MAX); - g_assert_cmpint(pcmk__scan_double(str, &result, NULL, NULL), ==, - pcmk_rc_ok); - ASSERT_DBL_EQ(result, -DBL_MAX); + assert_int_equal(pcmk__scan_double(str, &result, NULL, NULL), pcmk_rc_ok); + assert_float_equal(result, -DBL_MAX, DBL_EPSILON); } static void -double_overflow(void) +double_overflow(void **state) { char str[LOCAL_BUF_SIZE]; double result; /* * 1e(DBL_MAX_10_EXP + 1) produces an inf value - * Can't use ASSERT_DBL_EQ() because (inf - inf) == NaN + * Can't use assert_float_equal() because (inf - inf) == NaN */ snprintf(str, LOCAL_BUF_SIZE, "1e%d", DBL_MAX_10_EXP + 1); - g_assert_cmpint(pcmk__scan_double(str, &result, NULL, NULL), ==, EOVERFLOW); - g_assert_cmpfloat(result, >, DBL_MAX); + assert_int_equal(pcmk__scan_double(str, &result, NULL, NULL), EOVERFLOW); + assert_true(result > DBL_MAX); snprintf(str, LOCAL_BUF_SIZE, "-1e%d", DBL_MAX_10_EXP + 1); - g_assert_cmpint(pcmk__scan_double(str, &result, NULL, NULL), ==, EOVERFLOW); - g_assert_cmpfloat(result, <, -DBL_MAX); + assert_int_equal(pcmk__scan_double(str, &result, NULL, NULL), EOVERFLOW); + assert_true(result < -DBL_MAX); } static void -double_underflow(void) +double_underflow(void **state) { char str[LOCAL_BUF_SIZE]; double result; /* * 1e(DBL_MIN_10_EXP - 1) produces a denormalized value (between 0 * and DBL_MIN) * * C99/C11: result will be **no greater than** DBL_MIN */ snprintf(str, LOCAL_BUF_SIZE, "1e%d", DBL_MIN_10_EXP - 1); - g_assert_cmpint(pcmk__scan_double(str, &result, NULL, NULL), ==, - pcmk_rc_underflow); - g_assert_cmpfloat(result, >=, 0.0); - g_assert_cmpfloat(result, <=, DBL_MIN); + assert_int_equal(pcmk__scan_double(str, &result, NULL, NULL), pcmk_rc_underflow); + assert_true(result >= 0.0); + assert_true(result <= DBL_MIN); snprintf(str, LOCAL_BUF_SIZE, "-1e%d", DBL_MIN_10_EXP - 1); - g_assert_cmpint(pcmk__scan_double(str, &result, NULL, NULL), ==, - pcmk_rc_underflow); - g_assert_cmpfloat(result, <=, 0.0); - g_assert_cmpfloat(result, >=, -DBL_MIN); + assert_int_equal(pcmk__scan_double(str, &result, NULL, NULL), pcmk_rc_underflow); + assert_true(result <= 0.0); + assert_true(result >= -DBL_MIN); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); - - // Test for input string issues - g_test_add_func("/common/strings/double/empty_input", empty_input_string); - g_test_add_func("/common/strings/double/bad_input", bad_input_string); - g_test_add_func("/common/strings/double/trailing_chars", trailing_chars); - - // Test for numeric issues - g_test_add_func("/common/strings/double/typical", typical_case); - g_test_add_func("/common/strings/double/overflow", double_overflow); - g_test_add_func("/common/strings/double/underflow", double_underflow); - - return g_test_run(); + const struct CMUnitTest tests[] = { + // Test for input string issues + cmocka_unit_test(empty_input_string), + cmocka_unit_test(bad_input_string), + cmocka_unit_test(trailing_chars), + + // Test for numeric issues + cmocka_unit_test(typical_case), + cmocka_unit_test(double_overflow), + cmocka_unit_test(double_underflow), + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/strings/pcmk__starts_with_test.c b/lib/common/tests/strings/pcmk__starts_with_test.c index 01b17aa3db..f6427dd8e7 100644 --- a/lib/common/tests/strings/pcmk__starts_with_test.c +++ b/lib/common/tests/strings/pcmk__starts_with_test.c @@ -1,39 +1,47 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include +#include +#include +#include +#include +#include + static void -bad_input(void) { - g_assert_false(pcmk__starts_with(NULL, "x")); - g_assert_false(pcmk__starts_with("abc", NULL)); +bad_input(void **state) { + assert_false(pcmk__starts_with(NULL, "x")); + assert_false(pcmk__starts_with("abc", NULL)); } static void -starts_with(void) { - g_assert_true(pcmk__starts_with("abc", "a")); - g_assert_true(pcmk__starts_with("abc", "ab")); - g_assert_true(pcmk__starts_with("abc", "abc")); +starts_with(void **state) { + assert_true(pcmk__starts_with("abc", "a")); + assert_true(pcmk__starts_with("abc", "ab")); + assert_true(pcmk__starts_with("abc", "abc")); - g_assert_false(pcmk__starts_with("abc", "A")); - g_assert_false(pcmk__starts_with("abc", "bc")); + assert_false(pcmk__starts_with("abc", "A")); + assert_false(pcmk__starts_with("abc", "bc")); - g_assert_false(pcmk__starts_with("", "x")); - g_assert_true(pcmk__starts_with("xyz", "")); + assert_false(pcmk__starts_with("", "x")); + assert_true(pcmk__starts_with("xyz", "")); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); + const struct CMUnitTest tests[] = { + cmocka_unit_test(bad_input), + cmocka_unit_test(starts_with), + }; - g_test_add_func("/common/strings/starts_with/bad_input", bad_input); - g_test_add_func("/common/strings/starts_with/starts_with", starts_with); - return g_test_run(); + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/strings/pcmk__str_any_of_test.c b/lib/common/tests/strings/pcmk__str_any_of_test.c index 61340d7f8c..ee5b1ab8d8 100644 --- a/lib/common/tests/strings/pcmk__str_any_of_test.c +++ b/lib/common/tests/strings/pcmk__str_any_of_test.c @@ -1,56 +1,59 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include -#include -#include -#include +#include +#include +#include +#include +#include static void -empty_input_list(void) { - g_assert_false(pcmk__strcase_any_of("xxx", NULL)); - g_assert_false(pcmk__str_any_of("xxx", NULL)); - g_assert_false(pcmk__strcase_any_of("", NULL)); - g_assert_false(pcmk__str_any_of("", NULL)); +empty_input_list(void **state) { + assert_false(pcmk__strcase_any_of("xxx", NULL)); + assert_false(pcmk__str_any_of("xxx", NULL)); + assert_false(pcmk__strcase_any_of("", NULL)); + assert_false(pcmk__str_any_of("", NULL)); } static void -empty_string(void) { - g_assert_false(pcmk__strcase_any_of("", "xxx", "yyy", NULL)); - g_assert_false(pcmk__str_any_of("", "xxx", "yyy", NULL)); - g_assert_false(pcmk__strcase_any_of(NULL, "xxx", "yyy", NULL)); - g_assert_false(pcmk__str_any_of(NULL, "xxx", "yyy", NULL)); +empty_string(void **state) { + assert_false(pcmk__strcase_any_of("", "xxx", "yyy", NULL)); + assert_false(pcmk__str_any_of("", "xxx", "yyy", NULL)); + assert_false(pcmk__strcase_any_of(NULL, "xxx", "yyy", NULL)); + assert_false(pcmk__str_any_of(NULL, "xxx", "yyy", NULL)); } static void -in_list(void) { - g_assert_true(pcmk__strcase_any_of("xxx", "aaa", "bbb", "xxx", NULL)); - g_assert_true(pcmk__str_any_of("xxx", "aaa", "bbb", "xxx", NULL)); - g_assert_true(pcmk__strcase_any_of("XXX", "aaa", "bbb", "xxx", NULL)); +in_list(void **state) { + assert_true(pcmk__strcase_any_of("xxx", "aaa", "bbb", "xxx", NULL)); + assert_true(pcmk__str_any_of("xxx", "aaa", "bbb", "xxx", NULL)); + assert_true(pcmk__strcase_any_of("XXX", "aaa", "bbb", "xxx", NULL)); } static void -not_in_list(void) { - g_assert_false(pcmk__strcase_any_of("xxx", "aaa", "bbb", NULL)); - g_assert_false(pcmk__str_any_of("xxx", "aaa", "bbb", NULL)); - g_assert_false(pcmk__str_any_of("AAA", "aaa", "bbb", NULL)); +not_in_list(void **state) { + assert_false(pcmk__strcase_any_of("xxx", "aaa", "bbb", NULL)); + assert_false(pcmk__str_any_of("xxx", "aaa", "bbb", NULL)); + assert_false(pcmk__str_any_of("AAA", "aaa", "bbb", NULL)); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); - - g_test_add_func("/common/strings/any_of/empty_list", empty_input_list); - g_test_add_func("/common/strings/any_of/empty_string", empty_string); - g_test_add_func("/common/strings/any_of/in", in_list); - g_test_add_func("/common/strings/any_of/not_in", not_in_list); - - return g_test_run(); + const struct CMUnitTest tests[] = { + cmocka_unit_test(empty_input_list), + cmocka_unit_test(empty_string), + cmocka_unit_test(in_list), + cmocka_unit_test(not_in_list), + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/strings/pcmk__str_in_list_test.c b/lib/common/tests/strings/pcmk__str_in_list_test.c index f34ac1f2c0..8d3367f559 100644 --- a/lib/common/tests/strings/pcmk__str_in_list_test.c +++ b/lib/common/tests/strings/pcmk__str_in_list_test.c @@ -1,113 +1,118 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include -#include -#include #include +#include +#include +#include +#include +#include + static void -empty_input_list(void) { - g_assert_false(pcmk__str_in_list(NULL, NULL, pcmk__str_none)); - g_assert_false(pcmk__str_in_list(NULL, NULL, pcmk__str_null_matches)); - g_assert_false(pcmk__str_in_list("xxx", NULL, pcmk__str_none)); - g_assert_false(pcmk__str_in_list("", NULL, pcmk__str_none)); +empty_input_list(void **state) { + assert_false(pcmk__str_in_list(NULL, NULL, pcmk__str_none)); + assert_false(pcmk__str_in_list(NULL, NULL, pcmk__str_null_matches)); + assert_false(pcmk__str_in_list("xxx", NULL, pcmk__str_none)); + assert_false(pcmk__str_in_list("", NULL, pcmk__str_none)); } static void -empty_string(void) { +empty_string(void **state) { GList *list = NULL; list = g_list_prepend(list, (gpointer) "xxx"); - g_assert_false(pcmk__str_in_list(NULL, list, pcmk__str_none)); - g_assert_true(pcmk__str_in_list(NULL, list, pcmk__str_null_matches)); - g_assert_false(pcmk__str_in_list("", list, pcmk__str_none)); - g_assert_false(pcmk__str_in_list("", list, pcmk__str_null_matches)); + assert_false(pcmk__str_in_list(NULL, list, pcmk__str_none)); + assert_true(pcmk__str_in_list(NULL, list, pcmk__str_null_matches)); + assert_false(pcmk__str_in_list("", list, pcmk__str_none)); + assert_false(pcmk__str_in_list("", list, pcmk__str_null_matches)); g_list_free(list); } static void -star_matches(void) { +star_matches(void **state) { GList *list = NULL; list = g_list_prepend(list, (gpointer) "*"); list = g_list_append(list, (gpointer) "more"); - g_assert_true(pcmk__str_in_list("xxx", list, pcmk__str_star_matches)); - g_assert_true(pcmk__str_in_list("yyy", list, pcmk__str_star_matches)); - g_assert_true(pcmk__str_in_list("XXX", list, pcmk__str_star_matches|pcmk__str_casei)); - g_assert_true(pcmk__str_in_list("", list, pcmk__str_star_matches)); + assert_true(pcmk__str_in_list("xxx", list, pcmk__str_star_matches)); + assert_true(pcmk__str_in_list("yyy", list, pcmk__str_star_matches)); + assert_true(pcmk__str_in_list("XXX", list, pcmk__str_star_matches|pcmk__str_casei)); + assert_true(pcmk__str_in_list("", list, pcmk__str_star_matches)); g_list_free(list); } static void -star_doesnt_match(void) { +star_doesnt_match(void **state) { GList *list = NULL; list = g_list_prepend(list, (gpointer) "*"); - g_assert_false(pcmk__str_in_list("xxx", list, pcmk__str_none)); - g_assert_false(pcmk__str_in_list("yyy", list, pcmk__str_none)); - g_assert_false(pcmk__str_in_list("XXX", list, pcmk__str_casei)); - g_assert_false(pcmk__str_in_list("", list, pcmk__str_none)); - g_assert_false(pcmk__str_in_list(NULL, list, pcmk__str_star_matches)); + assert_false(pcmk__str_in_list("xxx", list, pcmk__str_none)); + assert_false(pcmk__str_in_list("yyy", list, pcmk__str_none)); + assert_false(pcmk__str_in_list("XXX", list, pcmk__str_casei)); + assert_false(pcmk__str_in_list("", list, pcmk__str_none)); + assert_false(pcmk__str_in_list(NULL, list, pcmk__str_star_matches)); g_list_free(list); } static void -in_list(void) { +in_list(void **state) { GList *list = NULL; list = g_list_prepend(list, (gpointer) "xxx"); list = g_list_prepend(list, (gpointer) "yyy"); list = g_list_prepend(list, (gpointer) "zzz"); - g_assert_true(pcmk__str_in_list("xxx", list, pcmk__str_none)); - g_assert_true(pcmk__str_in_list("XXX", list, pcmk__str_casei)); - g_assert_true(pcmk__str_in_list("yyy", list, pcmk__str_none)); - g_assert_true(pcmk__str_in_list("YYY", list, pcmk__str_casei)); - g_assert_true(pcmk__str_in_list("zzz", list, pcmk__str_none)); - g_assert_true(pcmk__str_in_list("ZZZ", list, pcmk__str_casei)); + assert_true(pcmk__str_in_list("xxx", list, pcmk__str_none)); + assert_true(pcmk__str_in_list("XXX", list, pcmk__str_casei)); + assert_true(pcmk__str_in_list("yyy", list, pcmk__str_none)); + assert_true(pcmk__str_in_list("YYY", list, pcmk__str_casei)); + assert_true(pcmk__str_in_list("zzz", list, pcmk__str_none)); + assert_true(pcmk__str_in_list("ZZZ", list, pcmk__str_casei)); g_list_free(list); } static void -not_in_list(void) { +not_in_list(void **state) { GList *list = NULL; list = g_list_prepend(list, (gpointer) "xxx"); list = g_list_prepend(list, (gpointer) "yyy"); - g_assert_false(pcmk__str_in_list("xx", list, pcmk__str_none)); - g_assert_false(pcmk__str_in_list("XXX", list, pcmk__str_none)); - g_assert_false(pcmk__str_in_list("zzz", list, pcmk__str_none)); - g_assert_false(pcmk__str_in_list("zzz", list, pcmk__str_casei)); + assert_false(pcmk__str_in_list("xx", list, pcmk__str_none)); + assert_false(pcmk__str_in_list("XXX", list, pcmk__str_none)); + assert_false(pcmk__str_in_list("zzz", list, pcmk__str_none)); + assert_false(pcmk__str_in_list("zzz", list, pcmk__str_casei)); g_list_free(list); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); - - g_test_add_func("/common/strings/in_list/empty_list", empty_input_list); - g_test_add_func("/common/strings/in_list/empty_string", empty_string); - g_test_add_func("/common/strings/in_list/star_matches", star_matches); - g_test_add_func("/common/strings/in_list/star_doesnt_match", star_doesnt_match); - g_test_add_func("/common/strings/in_list/in", in_list); - g_test_add_func("/common/strings/in_list/not_in", not_in_list); - - return g_test_run(); + const struct CMUnitTest tests[] = { + cmocka_unit_test(empty_input_list), + cmocka_unit_test(empty_string), + cmocka_unit_test(star_matches), + cmocka_unit_test(star_doesnt_match), + cmocka_unit_test(in_list), + cmocka_unit_test(not_in_list), + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/strings/pcmk__strcmp_test.c b/lib/common/tests/strings/pcmk__strcmp_test.c index 85790eced0..100e183f64 100644 --- a/lib/common/tests/strings/pcmk__strcmp_test.c +++ b/lib/common/tests/strings/pcmk__strcmp_test.c @@ -1,87 +1,90 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include -#include -#include -#include +#include +#include +#include +#include +#include static void -same_pointer(void) { +same_pointer(void **state) { const char *s1 = "abcd"; const char *s2 = "wxyz"; - g_assert_cmpint(pcmk__strcmp(s1, s1, pcmk__str_none), ==, 0); - g_assert_true(pcmk__str_eq(s1, s1, pcmk__str_none)); - g_assert_cmpint(pcmk__strcmp(s1, s2, pcmk__str_none), !=, 0); - g_assert_false(pcmk__str_eq(s1, s2, pcmk__str_none)); - g_assert_cmpint(pcmk__strcmp(NULL, NULL, pcmk__str_none), ==, 0); + assert_int_equal(pcmk__strcmp(s1, s1, pcmk__str_none), 0); + assert_true(pcmk__str_eq(s1, s1, pcmk__str_none)); + assert_int_not_equal(pcmk__strcmp(s1, s2, pcmk__str_none), 0); + assert_false(pcmk__str_eq(s1, s2, pcmk__str_none)); + assert_int_equal(pcmk__strcmp(NULL, NULL, pcmk__str_none), 0); } static void -one_is_null(void) { +one_is_null(void **state) { const char *s1 = "abcd"; - g_assert_cmpint(pcmk__strcmp(s1, NULL, pcmk__str_null_matches), ==, 0); - g_assert_true(pcmk__str_eq(s1, NULL, pcmk__str_null_matches)); - g_assert_cmpint(pcmk__strcmp(NULL, s1, pcmk__str_null_matches), ==, 0); - g_assert_cmpint(pcmk__strcmp(s1, NULL, pcmk__str_none), >, 0); - g_assert_false(pcmk__str_eq(s1, NULL, pcmk__str_none)); - g_assert_cmpint(pcmk__strcmp(NULL, s1, pcmk__str_none), <, 0); + assert_int_equal(pcmk__strcmp(s1, NULL, pcmk__str_null_matches), 0); + assert_true(pcmk__str_eq(s1, NULL, pcmk__str_null_matches)); + assert_int_equal(pcmk__strcmp(NULL, s1, pcmk__str_null_matches), 0); + assert_in_range(pcmk__strcmp(s1, NULL, pcmk__str_none), 1, 255); + assert_false(pcmk__str_eq(s1, NULL, pcmk__str_none)); + assert_in_range(pcmk__strcmp(NULL, s1, pcmk__str_none), -255, -1); } static void -case_matters(void) { +case_matters(void **state) { const char *s1 = "abcd"; const char *s2 = "ABCD"; - g_assert_cmpint(pcmk__strcmp(s1, s2, pcmk__str_none), >, 0); - g_assert_false(pcmk__str_eq(s1, s2, pcmk__str_none)); - g_assert_cmpint(pcmk__strcmp(s2, s1, pcmk__str_none), <, 0); + assert_in_range(pcmk__strcmp(s1, s2, pcmk__str_none), 1, 255); + assert_false(pcmk__str_eq(s1, s2, pcmk__str_none)); + assert_in_range(pcmk__strcmp(s2, s1, pcmk__str_none), -255, -1); } static void -case_insensitive(void) { +case_insensitive(void **state) { const char *s1 = "abcd"; const char *s2 = "ABCD"; - g_assert_cmpint(pcmk__strcmp(s1, s2, pcmk__str_casei), ==, 0); - g_assert_true(pcmk__str_eq(s1, s2, pcmk__str_casei)); + assert_int_equal(pcmk__strcmp(s1, s2, pcmk__str_casei), 0); + assert_true(pcmk__str_eq(s1, s2, pcmk__str_casei)); } static void -regex(void) { +regex(void **state) { const char *s1 = "abcd"; const char *s2 = "ABCD"; - g_assert_cmpint(pcmk__strcmp(NULL, "a..d", pcmk__str_regex), ==, 1); - g_assert_cmpint(pcmk__strcmp(s1, NULL, pcmk__str_regex), ==, 1); - g_assert_cmpint(pcmk__strcmp(s1, "a..d", pcmk__str_regex), ==, 0); - g_assert_true(pcmk__str_eq(s1, "a..d", pcmk__str_regex)); - g_assert_cmpint(pcmk__strcmp(s1, "xxyy", pcmk__str_regex), !=, 0); - g_assert_false(pcmk__str_eq(s1, "xxyy", pcmk__str_regex)); - g_assert_cmpint(pcmk__strcmp(s2, "a..d", pcmk__str_regex|pcmk__str_casei), ==, 0); - g_assert_true(pcmk__str_eq(s2, "a..d", pcmk__str_regex|pcmk__str_casei)); - g_assert_cmpint(pcmk__strcmp(s2, "a..d", pcmk__str_regex), !=, 0); - g_assert_false(pcmk__str_eq(s2, "a..d", pcmk__str_regex)); - g_assert_cmpint(pcmk__strcmp(s2, "*ab", pcmk__str_regex), ==, 1); + assert_int_equal(pcmk__strcmp(NULL, "a..d", pcmk__str_regex), 1); + assert_int_equal(pcmk__strcmp(s1, NULL, pcmk__str_regex), 1); + assert_int_equal(pcmk__strcmp(s1, "a..d", pcmk__str_regex), 0); + assert_true(pcmk__str_eq(s1, "a..d", pcmk__str_regex)); + assert_int_not_equal(pcmk__strcmp(s1, "xxyy", pcmk__str_regex), 0); + assert_false(pcmk__str_eq(s1, "xxyy", pcmk__str_regex)); + assert_int_equal(pcmk__strcmp(s2, "a..d", pcmk__str_regex|pcmk__str_casei), 0); + assert_true(pcmk__str_eq(s2, "a..d", pcmk__str_regex|pcmk__str_casei)); + assert_int_not_equal(pcmk__strcmp(s2, "a..d", pcmk__str_regex), 0); + assert_false(pcmk__str_eq(s2, "a..d", pcmk__str_regex)); + assert_int_equal(pcmk__strcmp(s2, "*ab", pcmk__str_regex), 1); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); + const struct CMUnitTest tests[] = { + cmocka_unit_test(same_pointer), + cmocka_unit_test(one_is_null), + cmocka_unit_test(case_matters), + cmocka_unit_test(case_insensitive), + cmocka_unit_test(regex), + }; - g_test_add_func("/common/strings/strcmp/same_pointer", same_pointer); - g_test_add_func("/common/strings/strcmp/one_is_null", one_is_null); - g_test_add_func("/common/strings/strcmp/case_matters", case_matters); - g_test_add_func("/common/strings/strcmp/case_insensitive", case_insensitive); - g_test_add_func("/common/strings/strcmp/regex", regex); - - return g_test_run(); + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/utils/Makefile.am b/lib/common/tests/utils/Makefile.am index ae30b77303..0b7f20247e 100644 --- a/lib/common/tests/utils/Makefile.am +++ b/lib/common/tests/utils/Makefile.am @@ -1,30 +1,30 @@ # -# Copyright 2020 the Pacemaker project contributors +# 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. # AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include -LDADD = $(top_builddir)/lib/common/libcrmcommon.la +LDADD = $(top_builddir)/lib/common/libcrmcommon.la -lcmocka include $(top_srcdir)/mk/glib-tap.mk # Add each test program here. Each test should be written as a little standalone # program using the glib unit testing functions. See the documentation for more # information. # # https://developer.gnome.org/glib/unstable/glib-Testing.html # # Add "_test" to the end of all test program names to simplify .gitignore. test_programs = pcmk_str_is_infinity_test \ pcmk_str_is_minus_infinity_test # If any extra data needs to be added to the source distribution, add it to the # following list. dist_test_data = # If any extra data needs to be used by tests but should not be added to the # source distribution, add it to the following list. test_data = diff --git a/lib/common/tests/utils/pcmk_str_is_infinity_test.c b/lib/common/tests/utils/pcmk_str_is_infinity_test.c index 1e012d9671..750f36f431 100644 --- a/lib/common/tests/utils/pcmk_str_is_infinity_test.c +++ b/lib/common/tests/utils/pcmk_str_is_infinity_test.c @@ -1,65 +1,68 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include -#include -#include -#include +#include +#include +#include +#include +#include static void -uppercase_str_passes(void) +uppercase_str_passes(void **state) { - g_assert_true(pcmk_str_is_infinity("INFINITY")); - g_assert_true(pcmk_str_is_infinity("+INFINITY")); + assert_true(pcmk_str_is_infinity("INFINITY")); + assert_true(pcmk_str_is_infinity("+INFINITY")); } static void -mixed_case_str_fails(void) +mixed_case_str_fails(void **state) { - g_assert_false(pcmk_str_is_infinity("infinity")); - g_assert_false(pcmk_str_is_infinity("+infinity")); - g_assert_false(pcmk_str_is_infinity("Infinity")); - g_assert_false(pcmk_str_is_infinity("+Infinity")); + assert_false(pcmk_str_is_infinity("infinity")); + assert_false(pcmk_str_is_infinity("+infinity")); + assert_false(pcmk_str_is_infinity("Infinity")); + assert_false(pcmk_str_is_infinity("+Infinity")); } static void -added_whitespace_fails(void) +added_whitespace_fails(void **state) { - g_assert_false(pcmk_str_is_infinity(" INFINITY")); - g_assert_false(pcmk_str_is_infinity("INFINITY ")); - g_assert_false(pcmk_str_is_infinity(" INFINITY ")); - g_assert_false(pcmk_str_is_infinity("+ INFINITY")); + assert_false(pcmk_str_is_infinity(" INFINITY")); + assert_false(pcmk_str_is_infinity("INFINITY ")); + assert_false(pcmk_str_is_infinity(" INFINITY ")); + assert_false(pcmk_str_is_infinity("+ INFINITY")); } static void -empty_str_fails(void) +empty_str_fails(void **state) { - g_assert_false(pcmk_str_is_infinity(NULL)); - g_assert_false(pcmk_str_is_infinity("")); + assert_false(pcmk_str_is_infinity(NULL)); + assert_false(pcmk_str_is_infinity("")); } static void -minus_infinity_fails(void) +minus_infinity_fails(void **state) { - g_assert_false(pcmk_str_is_infinity("-INFINITY")); + assert_false(pcmk_str_is_infinity("-INFINITY")); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); + const struct CMUnitTest tests[] = { + cmocka_unit_test(uppercase_str_passes), + cmocka_unit_test(mixed_case_str_fails), + cmocka_unit_test(added_whitespace_fails), + cmocka_unit_test(empty_str_fails), + cmocka_unit_test(minus_infinity_fails), + }; - g_test_add_func("/common/utils/infinity/uppercase", uppercase_str_passes); - g_test_add_func("/common/utils/infinity/mixed_case", mixed_case_str_fails); - g_test_add_func("/common/utils/infinity/whitespace", added_whitespace_fails); - g_test_add_func("/common/utils/infinity/empty", empty_str_fails); - g_test_add_func("/common/utils/infinity/minus_infinity", minus_infinity_fails); - - return g_test_run(); + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/utils/pcmk_str_is_minus_infinity_test.c b/lib/common/tests/utils/pcmk_str_is_minus_infinity_test.c index 9daf1100e0..f321ad4b04 100644 --- a/lib/common/tests/utils/pcmk_str_is_minus_infinity_test.c +++ b/lib/common/tests/utils/pcmk_str_is_minus_infinity_test.c @@ -1,62 +1,65 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include -#include -#include -#include +#include +#include +#include +#include +#include static void -uppercase_str_passes(void) +uppercase_str_passes(void **state) { - g_assert_true(pcmk_str_is_minus_infinity("-INFINITY")); + assert_true(pcmk_str_is_minus_infinity("-INFINITY")); } static void -mixed_case_str_fails(void) +mixed_case_str_fails(void **state) { - g_assert_false(pcmk_str_is_minus_infinity("-infinity")); - g_assert_false(pcmk_str_is_minus_infinity("-Infinity")); + assert_false(pcmk_str_is_minus_infinity("-infinity")); + assert_false(pcmk_str_is_minus_infinity("-Infinity")); } static void -added_whitespace_fails(void) +added_whitespace_fails(void **state) { - g_assert_false(pcmk_str_is_minus_infinity(" -INFINITY")); - g_assert_false(pcmk_str_is_minus_infinity("-INFINITY ")); - g_assert_false(pcmk_str_is_minus_infinity(" -INFINITY ")); - g_assert_false(pcmk_str_is_minus_infinity("- INFINITY")); + assert_false(pcmk_str_is_minus_infinity(" -INFINITY")); + assert_false(pcmk_str_is_minus_infinity("-INFINITY ")); + assert_false(pcmk_str_is_minus_infinity(" -INFINITY ")); + assert_false(pcmk_str_is_minus_infinity("- INFINITY")); } static void -empty_str_fails(void) +empty_str_fails(void **state) { - g_assert_false(pcmk_str_is_minus_infinity(NULL)); - g_assert_false(pcmk_str_is_minus_infinity("")); + assert_false(pcmk_str_is_minus_infinity(NULL)); + assert_false(pcmk_str_is_minus_infinity("")); } static void -infinity_fails(void) +infinity_fails(void **state) { - g_assert_false(pcmk_str_is_minus_infinity("INFINITY")); + assert_false(pcmk_str_is_minus_infinity("INFINITY")); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); + const struct CMUnitTest tests[] = { + cmocka_unit_test(uppercase_str_passes), + cmocka_unit_test(mixed_case_str_fails), + cmocka_unit_test(added_whitespace_fails), + cmocka_unit_test(empty_str_fails), + cmocka_unit_test(infinity_fails), + }; - g_test_add_func("/common/utils/minus_infinity/uppercase", uppercase_str_passes); - g_test_add_func("/common/utils/minus_infinity/mixed_case", mixed_case_str_fails); - g_test_add_func("/common/utils/minus_infinity/whitespace", added_whitespace_fails); - g_test_add_func("/common/utils/minus_infinity/empty", empty_str_fails); - g_test_add_func("/common/utils/minus_infinity/infinity", infinity_fails); - - return g_test_run(); + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/xpath/Makefile.am b/lib/common/tests/xpath/Makefile.am index 7a53683b24..7e8e7a0baa 100644 --- a/lib/common/tests/xpath/Makefile.am +++ b/lib/common/tests/xpath/Makefile.am @@ -1,29 +1,29 @@ # # 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. # AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include -LDADD = $(top_builddir)/lib/common/libcrmcommon.la +LDADD = $(top_builddir)/lib/common/libcrmcommon.la -lcmocka include $(top_srcdir)/mk/glib-tap.mk # Add each test program here. Each test should be written as a little standalone # program using the glib unit testing functions. See the documentation for more # information. # # https://developer.gnome.org/glib/unstable/glib-Testing.html # # Add "_test" to the end of all test program names to simplify .gitignore. test_programs = pcmk__xpath_node_id_test # If any extra data needs to be added to the source distribution, add it to the # following list. dist_test_data = # If any extra data needs to be used by tests but should not be added to the # source distribution, add it to the following list. test_data = diff --git a/lib/common/tests/xpath/pcmk__xpath_node_id_test.c b/lib/common/tests/xpath/pcmk__xpath_node_id_test.c index c7176daf6c..718f92db7b 100644 --- a/lib/common/tests/xpath/pcmk__xpath_node_id_test.c +++ b/lib/common/tests/xpath/pcmk__xpath_node_id_test.c @@ -1,50 +1,60 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include #include +#include +#include +#include +#include +#include +#include +#include + static void -empty_input(void) { - g_assert_null(pcmk__xpath_node_id(NULL, "lrm")); - g_assert_null(pcmk__xpath_node_id("", "lrm")); - g_assert_null(pcmk__xpath_node_id("/blah/blah", NULL)); - g_assert_null(pcmk__xpath_node_id("/blah/blah", "")); - g_assert_null(pcmk__xpath_node_id(NULL, NULL)); +empty_input(void **state) { + assert_null(pcmk__xpath_node_id(NULL, "lrm")); + assert_null(pcmk__xpath_node_id("", "lrm")); + assert_null(pcmk__xpath_node_id("/blah/blah", NULL)); + assert_null(pcmk__xpath_node_id("/blah/blah", "")); + assert_null(pcmk__xpath_node_id(NULL, NULL)); } static void -not_present(void) { - g_assert_null(pcmk__xpath_node_id("/some/xpath/string[@id='xyz']", "lrm")); - g_assert_null(pcmk__xpath_node_id("/some/xpath/containing[@id='lrm']", "lrm")); +not_present(void **state) { + assert_null(pcmk__xpath_node_id("/some/xpath/string[@id='xyz']", "lrm")); + assert_null(pcmk__xpath_node_id("/some/xpath/containing[@id='lrm']", "lrm")); } static void -present(void) { +present(void **state) { char *s = NULL; s = pcmk__xpath_node_id("/some/xpath/containing/lrm[@id='xyz']", "lrm"); - g_assert_cmpint(strcmp(s, "xyz"), ==, 0); + assert_int_equal(strcmp(s, "xyz"), 0); free(s); s = pcmk__xpath_node_id("/some/other/lrm[@id='xyz']/xpath", "lrm"); - g_assert_cmpint(strcmp(s, "xyz"), ==, 0); + assert_int_equal(strcmp(s, "xyz"), 0); free(s); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); - - g_test_add_func("/common/xpath/node_id/empty_input", empty_input); - g_test_add_func("/common/xpath/node_id/not_present", not_present); - g_test_add_func("/common/xpath/node_id/present", present); - return g_test_run(); + const struct CMUnitTest tests[] = { + cmocka_unit_test(empty_input), + cmocka_unit_test(not_present), + cmocka_unit_test(present), + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/pengine/tests/rules/Makefile.am b/lib/pengine/tests/rules/Makefile.am index 9195f8dad1..677bed34fc 100644 --- a/lib/pengine/tests/rules/Makefile.am +++ b/lib/pengine/tests/rules/Makefile.am @@ -1,30 +1,31 @@ # -# Copyright 2020 the Pacemaker project contributors +# 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. # AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include LDADD = $(top_builddir)/lib/common/libcrmcommon.la \ - $(top_builddir)/lib/pengine/libpe_rules.la + $(top_builddir)/lib/pengine/libpe_rules.la \ + -lcmocka include $(top_srcdir)/mk/glib-tap.mk # Add each test program here. Each test should be written as a little standalone # program using the glib unit testing functions. See the documentation for more # information. # # https://developer.gnome.org/glib/unstable/glib-Testing.html # # Add "_test" to the end of all test program names to simplify .gitignore. test_programs = pe_cron_range_satisfied_test # If any extra data needs to be added to the source distribution, add it to the # following list. dist_test_data = # If any extra data needs to be used by tests but should not be added to the # source distribution, add it to the following list. test_data = diff --git a/lib/pengine/tests/rules/pe_cron_range_satisfied_test.c b/lib/pengine/tests/rules/pe_cron_range_satisfied_test.c index 9c56c0e777..4494d09639 100644 --- a/lib/pengine/tests/rules/pe_cron_range_satisfied_test.c +++ b/lib/pengine/tests/rules/pe_cron_range_satisfied_test.c @@ -1,133 +1,141 @@ /* * 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 Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include #include #include +#include +#include +#include +#include +#include + static void run_one_test(const char *t, const char *x, int expected) { crm_time_t *tm = crm_time_new(t); xmlNodePtr xml = string2xml(x); - g_assert_cmpint(pe_cron_range_satisfied(tm, xml), ==, expected); + assert_int_equal(pe_cron_range_satisfied(tm, xml), expected); crm_time_free(tm); free_xml(xml); } static void -no_time_given(void) { - g_assert_cmpint(pe_cron_range_satisfied(NULL, NULL), ==, pcmk_rc_op_unsatisfied); +no_time_given(void **state) { + assert_int_equal(pe_cron_range_satisfied(NULL, NULL), pcmk_rc_op_unsatisfied); } static void -any_time_satisfies_empty_spec(void) { +any_time_satisfies_empty_spec(void **state) { crm_time_t *tm = crm_time_new(NULL); - g_assert_cmpint(pe_cron_range_satisfied(tm, NULL), ==, pcmk_rc_ok); + assert_int_equal(pe_cron_range_satisfied(tm, NULL), pcmk_rc_ok); crm_time_free(tm); } static void -time_satisfies_year_spec(void) { +time_satisfies_year_spec(void **state) { run_one_test("2020-01-01", "", pcmk_rc_ok); } static void -time_after_year_spec(void) { +time_after_year_spec(void **state) { run_one_test("2020-01-01", "", pcmk_rc_after_range); } static void -time_satisfies_year_range(void) { +time_satisfies_year_range(void **state) { run_one_test("2020-01-01", "", pcmk_rc_ok); } static void -time_before_year_range(void) { +time_before_year_range(void **state) { run_one_test("2000-01-01", "", pcmk_rc_before_range); } static void -time_after_year_range(void) { +time_after_year_range(void **state) { run_one_test("2020-01-01", "", pcmk_rc_after_range); } static void -range_without_start_year_passes(void) { +range_without_start_year_passes(void **state) { run_one_test("2010-01-01", "", pcmk_rc_ok); } static void -range_without_end_year_passes(void) { +range_without_end_year_passes(void **state) { run_one_test("2010-01-01", "", pcmk_rc_ok); run_one_test("2000-10-01", "", pcmk_rc_ok); } static void -yeardays_satisfies(void) { +yeardays_satisfies(void **state) { run_one_test("2020-01-30", "", pcmk_rc_ok); } static void -time_after_yeardays_spec(void) { +time_after_yeardays_spec(void **state) { run_one_test("2020-02-15", "", pcmk_rc_after_range); } static void -yeardays_feb_29_satisfies(void) { +yeardays_feb_29_satisfies(void **state) { run_one_test("2016-02-29", "", pcmk_rc_ok); } static void -exact_ymd_satisfies(void) { +exact_ymd_satisfies(void **state) { run_one_test("2001-12-31", "", pcmk_rc_ok); } static void -range_in_month_satisfies(void) { +range_in_month_satisfies(void **state) { run_one_test("2001-06-10", "", pcmk_rc_ok); } static void -exact_ymd_after_range(void) { +exact_ymd_after_range(void **state) { run_one_test("2001-12-31", "", pcmk_rc_after_range); } static void -time_after_monthdays_range(void) { +time_after_monthdays_range(void **state) { run_one_test("2001-06-10", "", pcmk_rc_before_range); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); - - g_test_add_func("/pengine/rules/cron_range/no_time_given", no_time_given); - g_test_add_func("/pengine/rules/cron_range/empty_spec", any_time_satisfies_empty_spec); - g_test_add_func("/pengine/rules/cron_range/year/time_satisfies", time_satisfies_year_spec); - g_test_add_func("/pengine/rules/cron_range/year/time_after", time_after_year_spec); - g_test_add_func("/pengine/rules/cron_range/range/time_satisfies_year", time_satisfies_year_range); - g_test_add_func("/pengine/rules/cron_range/range/time_before_year", time_before_year_range); - g_test_add_func("/pengine/rules/cron_range/range/time_after_year", time_after_year_range); - g_test_add_func("/pengine/rules/cron_range/range/no_start_year_passes", range_without_start_year_passes); - g_test_add_func("/pengine/rules/cron_range/range/no_end_year_passes", range_without_end_year_passes); - - g_test_add_func("/pengine/rules/cron_range/yeardays/satisfies", yeardays_satisfies); - g_test_add_func("/pengine/rules/cron_range/yeardays/time_after", time_after_yeardays_spec); - g_test_add_func("/pengine/rules/cron_range/yeardays/feb_29_sasitfies", yeardays_feb_29_satisfies); - - g_test_add_func("/pengine/rules/cron_range/exact/ymd_satisfies", exact_ymd_satisfies); - g_test_add_func("/pengine/rules/cron_range/range/in_month_satisfies", range_in_month_satisfies); - g_test_add_func("/pengine/rules/cron_range/exact/ymd_after_range", exact_ymd_after_range); - g_test_add_func("/pengine/rules/cron_range/range/in_month_after", time_after_monthdays_range); - return g_test_run(); + const struct CMUnitTest tests[] = { + cmocka_unit_test(no_time_given), + cmocka_unit_test(any_time_satisfies_empty_spec), + cmocka_unit_test(time_satisfies_year_spec), + cmocka_unit_test(time_after_year_spec), + cmocka_unit_test(time_satisfies_year_range), + cmocka_unit_test(time_before_year_range), + cmocka_unit_test(time_after_year_range), + cmocka_unit_test(range_without_start_year_passes), + cmocka_unit_test(range_without_end_year_passes), + + cmocka_unit_test(yeardays_satisfies), + cmocka_unit_test(time_after_yeardays_spec), + cmocka_unit_test(yeardays_feb_29_satisfies), + + cmocka_unit_test(exact_ymd_satisfies), + cmocka_unit_test(range_in_month_satisfies), + cmocka_unit_test(exact_ymd_after_range), + cmocka_unit_test(time_after_monthdays_range), + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/rpm/pacemaker.spec.in b/rpm/pacemaker.spec.in index 0c569b9ca5..a2e48bf06f 100644 --- a/rpm/pacemaker.spec.in +++ b/rpm/pacemaker.spec.in @@ -1,916 +1,919 @@ # User-configurable globals and defines to control package behavior # (these should not test {with X} values, which are declared later) ## User and group to use for nonprivileged services %global uname hacluster %global gname haclient ## Where to install Pacemaker documentation %if 0%{?suse_version} > 0 %global pcmk_docdir %{_docdir}/%{name}-%{version} %else %if 0%{?rhel} > 7 %global pcmk_docdir %{_docdir}/%{name}-doc %else %global pcmk_docdir %{_docdir}/%{name} %endif %endif ## GitHub entity that distributes source (for ease of using a fork) %global github_owner ClusterLabs ## Where bug reports should be submitted ## Leave bug_url undefined to use ClusterLabs default, others define it here ## What to use as the OCF resource agent root directory %global ocf_root %{_prefix}/lib/ocf ## Upstream pacemaker version, and its package version (specversion ## can be incremented to build packages reliably considered "newer" ## than previously built packages with the same pcmkversion) %global pcmkversion X.Y.Z %global specversion 1 ## Upstream commit (full commit ID, abbreviated commit ID, or tag) to build %global commit HEAD ## Since git v2.11, the extent of abbreviation is autoscaled by default ## (used to be constant of 7), so we need to convey it for non-tags, too. %if (0%{?fedora} >= 26) || (0%{?rhel} >= 9) %global commit_abbrev 9 %else %global commit_abbrev 7 %endif # Define conditionals so that "rpmbuild --with " and # "rpmbuild --without " can enable and disable specific features ## Add option to enable support for stonith/external fencing agents %bcond_with stonithd ## Add option for whether to support storing sensitive information outside CIB %if (0%{?fedora} && 0%{?fedora} <= 33) || (0%{?rhel} && 0%{?rhel} <= 8) %bcond_with cibsecrets %else %bcond_without cibsecrets %endif ## Add option to create binaries suitable for use with profiling tools %bcond_with profiling ## Add option to create binaries with coverage analysis %bcond_with coverage ## Add option to skip (or enable, on RHEL) generating documentation ## (the build tools aren't available everywhere) %if 0%{?rhel} %bcond_with doc %else %bcond_without doc %endif ## Add option to default to start-up synchronization with SBD. ## ## If enabled, SBD *MUST* be built to default similarly, otherwise data ## corruption could occur. Building both Pacemaker and SBD to default ## to synchronization improves safety, without requiring higher-level tools ## to be aware of the setting or requiring users to modify configurations ## after upgrading to versions that support synchronization. %if 0%{?rhel} && 0%{?rhel} > 8 %bcond_without sbd_sync %else %bcond_with sbd_sync %endif ## Add option to prefix package version with "0." ## (so later "official" packages will be considered updates) %bcond_with pre_release ## Add option to ship Upstart job files %bcond_with upstart_job ## Add option to turn off hardening of libraries and daemon executables %bcond_without hardening ## Add option to enable (or disable, on RHEL 8) links for legacy daemon names %if 0%{?rhel} && 0%{?rhel} <= 8 %bcond_without legacy_links %else %bcond_with legacy_links %endif # Define globals for convenient use later ## Workaround to use parentheses in other globals %global lparen ( %global rparen ) ## Whether this is a tagged release (final or release candidate) %define tag_release %(c=%{commit}; case ${c} in Pacemaker-*%{rparen} echo 1 ;; *%{rparen} echo 0 ;; esac) ## Portion of export/dist tarball name after "pacemaker-", and release version %if 0%{tag_release} %define archive_version %(c=%{commit}; echo ${c:10}) %define archive_github_url %{commit}#/%{name}-%{archive_version}.tar.gz %define pcmk_release %(c=%{commit}; case $c in *-rc[[:digit:]]*%{rparen} echo 0.%{specversion}.${c: -3} ;; *%{rparen} echo %{specversion} ;; esac) %else %define archive_version %(c=%{commit}; echo ${c:0:%{commit_abbrev}}) %define archive_github_url %{archive_version}#/%{name}-%{archive_version}.tar.gz %if %{with pre_release} %define pcmk_release 0.%{specversion}.%{archive_version}.git %else %define pcmk_release %{specversion}.%{archive_version}.git %endif %endif ## Whether this platform defaults to using systemd as an init system ## (needs to be evaluated prior to BuildRequires being enumerated and ## installed as it's intended to conditionally select some of these, and ## for that there are only few indicators with varying reliability: ## - presence of systemd-defined macros (when building in a full-fledged ## environment, which is not the case with ordinary mock-based builds) ## - systemd-aware rpm as manifested with the presence of particular ## macro (rpm itself will trivially always be present when building) ## - existence of /usr/lib/os-release file, which is something heavily ## propagated by systemd project ## - when not good enough, there's always a possibility to check ## particular distro-specific macros (incl. version comparison) %define systemd_native (%{?_unitdir:1}%{!?_unitdir:0}%{nil \ } || %{?__transaction_systemd_inhibit:1}%{!?__transaction_systemd_inhibit:0}%{nil \ } || %(test -f /usr/lib/os-release; test $? -ne 0; echo $?)) %if 0%{?fedora} > 20 || 0%{?rhel} > 7 ## Base GnuTLS cipher priorities (presumably only the initial, required keyword) ## overridable with "rpmbuild --define 'pcmk_gnutls_priorities PRIORITY-SPEC'" %define gnutls_priorities %{?pcmk_gnutls_priorities}%{!?pcmk_gnutls_priorities:@SYSTEM} %endif %if 0%{?fedora} > 22 || 0%{?rhel} > 7 %global supports_recommends 1 %endif ## Different distros name certain packages differently ## (note: corosync libraries also differ, but all provide corosync-devel) %if 0%{?suse_version} > 0 %global pkgname_bzip2_devel libbz2-devel %global pkgname_docbook_xsl docbook-xsl-stylesheets %global pkgname_gnutls_devel libgnutls-devel %global pkgname_shadow_utils shadow %global pkgname_procps procps %global pkgname_glue_libs libglue %global pkgname_pcmk_libs lib%{name}3 %global hacluster_id 90 %else %global pkgname_libtool_devel libtool-ltdl-devel %global pkgname_libtool_devel_arch libtool-ltdl-devel%{?_isa} %global pkgname_bzip2_devel bzip2-devel %global pkgname_docbook_xsl docbook-style-xsl %global pkgname_gnutls_devel gnutls-devel %global pkgname_shadow_utils shadow-utils %global pkgname_procps procps-ng %global pkgname_glue_libs cluster-glue-libs %global pkgname_pcmk_libs %{name}-libs %global hacluster_id 189 %endif ## Distro-specific configuration choices ### Use 2.0-style output when other distro packages don't support current output %if 0%{?fedora} || ( 0%{?rhel} && 0%{?rhel} <= 8 ) %global compat20 --enable-compat-2.0 %endif ### Default concurrent-fencing to true when distro prefers that %if 0%{?rhel} >= 7 %global concurrent_fencing --with-concurrent-fencing-default=true %endif ### Default resource-stickiness to 1 when distro prefers that %if 0%{?fedora} >= 35 || 0%{?rhel} >= 9 %global resource_stickiness --with-resource-stickiness-default=1 %endif # Python-related definitions ## Turn off auto-compilation of Python files outside Python specific paths, ## so there's no risk that unexpected "__python" macro gets picked to do the ## RPM-native byte-compiling there (only "{_datadir}/pacemaker/tests" affected) ## -- distro-dependent tricks or automake's fallback to be applied there %if %{defined _python_bytecompile_extra} %global _python_bytecompile_extra 0 %else ### the statement effectively means no RPM-native byte-compiling will occur at ### all, so distro-dependent tricks for Python-specific packages to be applied %global __os_install_post %(echo '%{__os_install_post}' | { sed -e 's!/usr/lib[^[:space:]]*/brp-python-bytecompile[[:space:]].*$!!g'; }) %endif ## Prefer Python 3 definitions explicitly, in case 2 is also available %if %{defined __python3} %global python_name python3 %global python_path %{__python3} %define python_site %{?python3_sitelib}%{!?python3_sitelib:%( %{python_path} -c 'from distutils.sysconfig import get_python_lib as gpl; print(gpl(1))' 2>/dev/null)} %else %if %{defined python_version} %global python_name python%(echo %{python_version} | cut -d'.' -f1) %define python_path %{?__python}%{!?__python:/usr/bin/%{python_name}} %else %global python_name python %global python_path %{?__python}%{!?__python:/usr/bin/python%{?python_pkgversion}} %endif %define python_site %{?python_sitelib}%{!?python_sitelib:%( %{python_name} -c 'from distutils.sysconfig import get_python_lib as gpl; print(gpl(1))' 2>/dev/null)} %endif # Keep sane profiling data if requested %if %{with profiling} ## Disable -debuginfo package and stripping binaries/libraries %define debug_package %{nil} %endif Name: pacemaker Summary: Scalable High-Availability cluster resource manager Version: %{pcmkversion} Release: %{pcmk_release}%{?dist} %if %{defined _unitdir} License: GPLv2+ and LGPLv2+ %else # initscript is Revised BSD License: GPLv2+ and LGPLv2+ and BSD %endif Url: https://www.clusterlabs.org/ # Example: https://codeload.github.com/ClusterLabs/pacemaker/tar.gz/e91769e # will download pacemaker-e91769e.tar.gz # # The ending part starting with '#' is ignored by github but necessary for # rpmbuild to know what the tar archive name is. (The downloaded file will be # named correctly only for commit IDs, not tagged releases.) # # You can use "spectool -s 0 pacemaker.spec" (rpmdevtools) to show final URL. Source0: https://codeload.github.com/%{github_owner}/%{name}/tar.gz/%{archive_github_url} Requires: resource-agents Requires: %{pkgname_pcmk_libs}%{?_isa} = %{version}-%{release} Requires: %{name}-cluster-libs%{?_isa} = %{version}-%{release} Requires: %{name}-cli = %{version}-%{release} %if !%{defined _unitdir} Requires: %{pkgname_procps} Requires: psmisc %endif %{?systemd_requires} Requires: %{python_path} BuildRequires: %{python_name}-devel # Pacemaker requires a minimum libqb functionality Requires: libqb >= 0.17.0 BuildRequires: libqb-devel >= 0.17.0 # Required basic build tools BuildRequires: autoconf BuildRequires: automake BuildRequires: coreutils BuildRequires: findutils BuildRequires: gcc BuildRequires: grep BuildRequires: libtool %if %{defined pkgname_libtool_devel} BuildRequires: %{?pkgname_libtool_devel} %endif BuildRequires: make BuildRequires: pkgconfig BuildRequires: sed # Required for core functionality BuildRequires: pkgconfig(glib-2.0) >= 2.42 BuildRequires: libxml2-devel BuildRequires: libxslt-devel BuildRequires: libuuid-devel BuildRequires: %{pkgname_bzip2_devel} # Enables optional functionality BuildRequires: pkgconfig(dbus-1) BuildRequires: %{pkgname_docbook_xsl} BuildRequires: %{pkgname_gnutls_devel} BuildRequires: help2man BuildRequires: ncurses-devel BuildRequires: pam-devel +# Required for "make check" +BuildRequires: libcmocka-devel + %if %{systemd_native} BuildRequires: pkgconfig(systemd) %endif Requires: corosync >= 2.0.0 BuildRequires: corosync-devel >= 2.0.0 %if %{with stonithd} BuildRequires: %{pkgname_glue_libs}-devel %endif %if %{with doc} BuildRequires: asciidoc BuildRequires: inkscape BuildRequires: %{python_name}-sphinx %endif Provides: pcmk-cluster-manager = %{version}-%{release} Provides: pcmk-cluster-manager%{?_isa} = %{version}-%{release} # Bundled bits ## Pacemaker uses the crypto/md5-buffer module from gnulib %if 0%{?fedora} || 0%{?rhel} Provides: bundled(gnulib) %endif %description Pacemaker is an advanced, scalable High-Availability cluster resource manager. It supports more than 16 node clusters with significant capabilities for managing resources and dependencies. It will run scripts at initialization, when machines go up or down, when related resources fail and can be configured to periodically check resource health. Available rpmbuild rebuild options: --with(out) : cibsecrets coverage doc hardening pre_release profiling stonithd upstart_job %package cli License: GPLv2+ and LGPLv2+ Summary: Command line tools for controlling Pacemaker clusters Requires: %{pkgname_pcmk_libs}%{?_isa} = %{version}-%{release} %if 0%{?supports_recommends} Recommends: pcmk-cluster-manager = %{version}-%{release} # For crm_report Recommends: tar Recommends: bzip2 %endif Requires: perl-TimeDate Requires: %{pkgname_procps} Requires: psmisc Requires(post):coreutils %description cli Pacemaker is an advanced, scalable High-Availability cluster resource manager. The %{name}-cli package contains command line tools that can be used to query and control the cluster from machines that may, or may not, be part of the cluster. %package -n %{pkgname_pcmk_libs} License: GPLv2+ and LGPLv2+ Summary: Core Pacemaker libraries Requires(pre): %{pkgname_shadow_utils} Requires: %{name}-schemas = %{version}-%{release} # sbd 1.4.0+ supports the libpe_status API for pe_working_set_t Conflicts: sbd < 1.4.0 %description -n %{pkgname_pcmk_libs} Pacemaker is an advanced, scalable High-Availability cluster resource manager. The %{pkgname_pcmk_libs} package contains shared libraries needed for cluster nodes and those just running the CLI tools. %package cluster-libs License: GPLv2+ and LGPLv2+ Summary: Cluster Libraries used by Pacemaker Requires: %{pkgname_pcmk_libs}%{?_isa} = %{version}-%{release} %description cluster-libs Pacemaker is an advanced, scalable High-Availability cluster resource manager. The %{name}-cluster-libs package contains cluster-aware shared libraries needed for nodes that will form part of the cluster nodes. %package remote %if %{defined _unitdir} License: GPLv2+ and LGPLv2+ %else # initscript is Revised BSD License: GPLv2+ and LGPLv2+ and BSD %endif Summary: Pacemaker remote executor daemon for non-cluster nodes Requires: %{pkgname_pcmk_libs}%{?_isa} = %{version}-%{release} Requires: %{name}-cli = %{version}-%{release} Requires: resource-agents %if !%{defined _unitdir} Requires: %{pkgname_procps} %endif # -remote can be fully independent of systemd %{?systemd_ordering}%{!?systemd_ordering:%{?systemd_requires}} Provides: pcmk-cluster-manager = %{version}-%{release} Provides: pcmk-cluster-manager%{?_isa} = %{version}-%{release} %description remote Pacemaker is an advanced, scalable High-Availability cluster resource manager. The %{name}-remote package contains the Pacemaker Remote daemon which is capable of extending pacemaker functionality to remote nodes not running the full corosync/cluster stack. %package -n %{pkgname_pcmk_libs}-devel License: GPLv2+ and LGPLv2+ Summary: Pacemaker development package Requires: %{pkgname_pcmk_libs}%{?_isa} = %{version}-%{release} Requires: %{name}-cluster-libs%{?_isa} = %{version}-%{release} Requires: %{pkgname_bzip2_devel}%{?_isa} Requires: corosync-devel >= 2.0.0 Requires: glib2-devel%{?_isa} Requires: libqb-devel%{?_isa} %if %{defined pkgname_libtool_devel_arch} Requires: %{?pkgname_libtool_devel_arch} %endif Requires: libuuid-devel%{?_isa} Requires: libxml2-devel%{?_isa} Requires: libxslt-devel%{?_isa} %description -n %{pkgname_pcmk_libs}-devel Pacemaker is an advanced, scalable High-Availability cluster resource manager. The %{pkgname_pcmk_libs}-devel package contains headers and shared libraries for developing tools for Pacemaker. %package cts License: GPLv2+ and LGPLv2+ Summary: Test framework for cluster-related technologies like Pacemaker Requires: %{python_path} Requires: %{pkgname_pcmk_libs} = %{version}-%{release} Requires: %{name}-cli = %{version}-%{release} Requires: %{pkgname_procps} Requires: psmisc BuildArch: noarch # systemd Python bindings are a separate package in some distros %if %{defined systemd_requires} %if 0%{?fedora} > 22 || 0%{?rhel} > 7 Requires: %{python_name}-systemd %endif %endif %description cts Test framework for cluster-related technologies like Pacemaker %package doc License: CC-BY-SA-4.0 Summary: Documentation for Pacemaker BuildArch: noarch %description doc Documentation for Pacemaker. Pacemaker is an advanced, scalable High-Availability cluster resource manager. %package schemas License: GPLv2+ Summary: Schemas and upgrade stylesheets for Pacemaker BuildArch: noarch %description schemas Schemas and upgrade stylesheets for Pacemaker Pacemaker is an advanced, scalable High-Availability cluster resource manager. %prep %setup -q -n %{name}-%{archive_version} %build export systemdsystemunitdir=%{?_unitdir}%{!?_unitdir:no} %if %{with hardening} # prefer distro-provided hardening flags in case they are defined # through _hardening_{c,ld}flags macros, configure script will # use its own defaults otherwise; if such hardenings are completely # undesired, rpmbuild using "--without hardening" # (or "--define '_without_hardening 1'") export CFLAGS_HARDENED_EXE="%{?_hardening_cflags}" export CFLAGS_HARDENED_LIB="%{?_hardening_cflags}" export LDFLAGS_HARDENED_EXE="%{?_hardening_ldflags}" export LDFLAGS_HARDENED_LIB="%{?_hardening_ldflags}" %endif ./autogen.sh %{configure} \ PYTHON=%{python_path} \ %{!?with_hardening: --disable-hardening} \ %{?with_legacy_links: --enable-legacy-links} \ %{?with_profiling: --with-profiling} \ %{?with_coverage: --with-coverage} \ %{?with_cibsecrets: --with-cibsecrets} \ %{?with_sbd_sync: --with-sbd-sync-default="true"} \ %{?gnutls_priorities: --with-gnutls-priorities="%{gnutls_priorities}"} \ %{?bug_url: --with-bug-url=%{bug_url}} \ %{?ocf_root: --with-ocfdir=%{ocf_root}} \ %{?concurrent_fencing} \ %{?resource_stickiness} \ %{?compat20} \ --disable-static \ --with-initdir=%{_initrddir} \ --with-runstatedir=%{_rundir} \ --localstatedir=%{_var} \ --with-version=%{version}-%{release} %if 0%{?suse_version} >= 1200 # Fedora handles rpath removal automagically sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool %endif make %{_smp_mflags} V=1 %check make %{_smp_mflags} check { cts/cts-scheduler --run load-stopped-loop \ && cts/cts-cli \ && touch .CHECKED } 2>&1 | sed 's/[fF]ail/faiil/g' # prevent false positives in rpmlint [ -f .CHECKED ] && rm -f -- .CHECKED exit $? # TODO remove when rpm<4.14 compatibility irrelevant %install # skip automake-native Python byte-compilation, since RPM-native one (possibly # distro-confined to Python-specific directories, which is currently the only # relevant place, anyway) assures proper intrinsic alignment with wider system # (such as with py_byte_compile macro, which is concurrent Fedora/EL specific) make install \ DESTDIR=%{buildroot} V=1 docdir=%{pcmk_docdir} \ %{?_python_bytecompile_extra:%{?py_byte_compile:am__py_compile=true}} %if %{with upstart_job} mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/init install -m 644 pacemakerd/pacemaker.upstart ${RPM_BUILD_ROOT}%{_sysconfdir}/init/pacemaker.conf install -m 644 pacemakerd/pacemaker.combined.upstart ${RPM_BUILD_ROOT}%{_sysconfdir}/init/pacemaker.combined.conf install -m 644 tools/crm_mon.upstart ${RPM_BUILD_ROOT}%{_sysconfdir}/init/crm_mon.conf %endif %if %{defined _unitdir} mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/lib/rpm-state/%{name} %endif # Don't package libtool archives find %{buildroot} -name '*.la' -type f -print0 | xargs -0 rm -f # For now, don't package the servicelog-related binaries built only for # ppc64le when certain dependencies are installed. If they get more exercise by # advanced users, we can reconsider. rm -f %{buildroot}/%{_sbindir}/notifyServicelogEvent rm -f %{buildroot}/%{_sbindir}/ipmiservicelogd # Don't ship init scripts for systemd based platforms %if %{defined _unitdir} rm -f %{buildroot}/%{_initrddir}/pacemaker rm -f %{buildroot}/%{_initrddir}/pacemaker_remote %endif # Byte-compile Python sources where suitable and the distro procedures known %if %{defined py_byte_compile} %{py_byte_compile %{python_path} %{buildroot}%{_datadir}/pacemaker/tests} %if !%{defined _python_bytecompile_extra} %{py_byte_compile %{python_path} %{buildroot}%{python_site}/cts} %endif %endif %if %{with coverage} GCOV_BASE=%{buildroot}/%{_var}/lib/pacemaker/gcov mkdir -p $GCOV_BASE find . -name '*.gcno' -type f | while read F ; do D=`dirname $F` mkdir -p ${GCOV_BASE}/$D cp $F ${GCOV_BASE}/$D done %endif %post %if %{defined _unitdir} %systemd_post pacemaker.service %else /sbin/chkconfig --add pacemaker || : %endif %preun %if %{defined _unitdir} %systemd_preun pacemaker.service %else /sbin/service pacemaker stop >/dev/null 2>&1 || : if [ "$1" -eq 0 ]; then # Package removal, not upgrade /sbin/chkconfig --del pacemaker || : fi %endif %postun %if %{defined _unitdir} %systemd_postun_with_restart pacemaker.service %endif %pre remote %if %{defined _unitdir} # Stop the service before anything is touched, and remember to restart # it as one of the last actions (compared to using systemd_postun_with_restart, # this avoids suicide when sbd is in use) systemctl --quiet is-active pacemaker_remote if [ $? -eq 0 ] ; then mkdir -p %{_localstatedir}/lib/rpm-state/%{name} touch %{_localstatedir}/lib/rpm-state/%{name}/restart_pacemaker_remote systemctl stop pacemaker_remote >/dev/null 2>&1 else rm -f %{_localstatedir}/lib/rpm-state/%{name}/restart_pacemaker_remote fi %endif %post remote %if %{defined _unitdir} %systemd_post pacemaker_remote.service %else /sbin/chkconfig --add pacemaker_remote || : %endif %preun remote %if %{defined _unitdir} %systemd_preun pacemaker_remote.service %else /sbin/service pacemaker_remote stop >/dev/null 2>&1 || : if [ "$1" -eq 0 ]; then # Package removal, not upgrade /sbin/chkconfig --del pacemaker_remote || : fi %endif %postun remote %if %{defined _unitdir} # This next line is a no-op, because we stopped the service earlier, but # we leave it here because it allows us to revert to the standard behavior # in the future if desired %systemd_postun_with_restart pacemaker_remote.service # Explicitly take care of removing the flag-file(s) upon final removal if [ "$1" -eq 0 ] ; then rm -f %{_localstatedir}/lib/rpm-state/%{name}/restart_pacemaker_remote fi %endif %posttrans remote %if %{defined _unitdir} if [ -e %{_localstatedir}/lib/rpm-state/%{name}/restart_pacemaker_remote ] ; then systemctl start pacemaker_remote >/dev/null 2>&1 rm -f %{_localstatedir}/lib/rpm-state/%{name}/restart_pacemaker_remote fi %endif %post cli %if %{defined _unitdir} %systemd_post crm_mon.service %endif if [ "$1" -eq 2 ]; then # Package upgrade, not initial install: # Move any pre-2.0 logs to new location to ensure they get rotated { mv -fbS.rpmsave %{_var}/log/pacemaker.log* %{_var}/log/pacemaker \ || mv -f %{_var}/log/pacemaker.log* %{_var}/log/pacemaker } >/dev/null 2>/dev/null || : fi %preun cli %if %{defined _unitdir} %systemd_preun crm_mon.service %endif %postun cli %if %{defined _unitdir} %systemd_postun_with_restart crm_mon.service %endif %pre -n %{pkgname_pcmk_libs} getent group %{gname} >/dev/null || groupadd -r %{gname} -g %{hacluster_id} getent passwd %{uname} >/dev/null || useradd -r -g %{gname} -u %{hacluster_id} -s /sbin/nologin -c "cluster user" %{uname} exit 0 %if %{defined ldconfig_scriptlets} %ldconfig_scriptlets -n %{pkgname_pcmk_libs} %ldconfig_scriptlets cluster-libs %else %post -n %{pkgname_pcmk_libs} -p /sbin/ldconfig %postun -n %{pkgname_pcmk_libs} -p /sbin/ldconfig %post cluster-libs -p /sbin/ldconfig %postun cluster-libs -p /sbin/ldconfig %endif %files ########################################################### %config(noreplace) %{_sysconfdir}/sysconfig/pacemaker %{_sbindir}/pacemakerd %if %{defined _unitdir} %{_unitdir}/pacemaker.service %else %{_initrddir}/pacemaker %endif %exclude %{_libexecdir}/pacemaker/cts-log-watcher %exclude %{_libexecdir}/pacemaker/cts-support %exclude %{_sbindir}/pacemaker-remoted %exclude %{_sbindir}/pacemaker_remoted %{_libexecdir}/pacemaker/* %{_sbindir}/crm_attribute %{_sbindir}/crm_master %{_sbindir}/fence_legacy %{_sbindir}/fence_watchdog %doc %{_mandir}/man7/pacemaker-controld.* %doc %{_mandir}/man7/pacemaker-schedulerd.* %doc %{_mandir}/man7/pacemaker-fenced.* %doc %{_mandir}/man7/ocf_pacemaker_controld.* %doc %{_mandir}/man7/ocf_pacemaker_o2cb.* %doc %{_mandir}/man7/ocf_pacemaker_remote.* %doc %{_mandir}/man8/crm_attribute.* %doc %{_mandir}/man8/crm_master.* %doc %{_mandir}/man8/fence_legacy.* %doc %{_mandir}/man8/fence_watchdog.* %doc %{_mandir}/man8/pacemakerd.* %doc %{_datadir}/pacemaker/alerts %license licenses/GPLv2 %doc COPYING %doc ChangeLog %dir %attr (750, %{uname}, %{gname}) %{_var}/lib/pacemaker/cib %dir %attr (750, %{uname}, %{gname}) %{_var}/lib/pacemaker/pengine %{ocf_root}/resource.d/pacemaker/controld %{ocf_root}/resource.d/pacemaker/o2cb %{ocf_root}/resource.d/pacemaker/remote %if %{with upstart_job} %config(noreplace) %{_sysconfdir}/init/pacemaker.conf %config(noreplace) %{_sysconfdir}/init/pacemaker.combined.conf %endif %files cli %dir %attr (750, root, %{gname}) %{_sysconfdir}/pacemaker %config(noreplace) %{_sysconfdir}/logrotate.d/pacemaker %config(noreplace) %{_sysconfdir}/sysconfig/crm_mon %if %{defined _unitdir} %{_unitdir}/crm_mon.service %endif %if %{with upstart_job} %config(noreplace) %{_sysconfdir}/init/crm_mon.conf %endif %{_sbindir}/attrd_updater %{_sbindir}/cibadmin %if %{with cibsecrets} %{_sbindir}/cibsecret %endif %{_sbindir}/crm_diff %{_sbindir}/crm_error %{_sbindir}/crm_failcount %{_sbindir}/crm_mon %{_sbindir}/crm_node %{_sbindir}/crm_resource %{_sbindir}/crm_rule %{_sbindir}/crm_standby %{_sbindir}/crm_verify %{_sbindir}/crmadmin %{_sbindir}/iso8601 %{_sbindir}/crm_shadow %{_sbindir}/crm_simulate %{_sbindir}/crm_report %{_sbindir}/crm_ticket %{_sbindir}/stonith_admin # "dirname" is owned by -schemas, which is a prerequisite %{_datadir}/pacemaker/report.collector %{_datadir}/pacemaker/report.common # XXX "dirname" is not owned by any prerequisite %{_datadir}/snmp/mibs/PCMK-MIB.txt %exclude %{ocf_root}/resource.d/pacemaker/controld %exclude %{ocf_root}/resource.d/pacemaker/o2cb %exclude %{ocf_root}/resource.d/pacemaker/remote %dir %{ocf_root} %dir %{ocf_root}/resource.d %{ocf_root}/resource.d/pacemaker %doc %{_mandir}/man7/* %exclude %{_mandir}/man7/pacemaker-controld.* %exclude %{_mandir}/man7/pacemaker-schedulerd.* %exclude %{_mandir}/man7/pacemaker-fenced.* %exclude %{_mandir}/man7/ocf_pacemaker_controld.* %exclude %{_mandir}/man7/ocf_pacemaker_o2cb.* %exclude %{_mandir}/man7/ocf_pacemaker_remote.* %doc %{_mandir}/man8/* %exclude %{_mandir}/man8/crm_attribute.* %exclude %{_mandir}/man8/crm_master.* %exclude %{_mandir}/man8/fence_legacy.* %exclude %{_mandir}/man8/fence_watchdog.* %exclude %{_mandir}/man8/pacemakerd.* %exclude %{_mandir}/man8/pacemaker-remoted.* %license licenses/GPLv2 %doc COPYING %doc ChangeLog %dir %attr (750, %{uname}, %{gname}) %{_var}/lib/pacemaker %dir %attr (750, %{uname}, %{gname}) %{_var}/lib/pacemaker/blackbox %dir %attr (750, %{uname}, %{gname}) %{_var}/lib/pacemaker/cores %dir %attr (770, %{uname}, %{gname}) %{_var}/log/pacemaker %dir %attr (770, %{uname}, %{gname}) %{_var}/log/pacemaker/bundles %files -n %{pkgname_pcmk_libs} %{_libdir}/libcib.so.* %{_libdir}/liblrmd.so.* %{_libdir}/libcrmservice.so.* %{_libdir}/libcrmcommon.so.* %{_libdir}/libpe_status.so.* %{_libdir}/libpe_rules.so.* %{_libdir}/libpacemaker.so.* %{_libdir}/libstonithd.so.* %license licenses/LGPLv2.1 %doc COPYING %doc ChangeLog %files cluster-libs %{_libdir}/libcrmcluster.so.* %license licenses/LGPLv2.1 %doc COPYING %doc ChangeLog %files remote %config(noreplace) %{_sysconfdir}/sysconfig/pacemaker %if %{defined _unitdir} # state directory is shared between the subpackets # let rpm take care of removing it once it isn't # referenced anymore and empty %ghost %dir %{_localstatedir}/lib/rpm-state/%{name} %{_unitdir}/pacemaker_remote.service %else %{_initrddir}/pacemaker_remote %endif %{_sbindir}/pacemaker-remoted %{_sbindir}/pacemaker_remoted %{_mandir}/man8/pacemaker-remoted.* %license licenses/GPLv2 %doc COPYING %doc ChangeLog %files doc %doc %{pcmk_docdir} %license licenses/CC-BY-SA-4.0 %files cts %{python_site}/cts %{_datadir}/pacemaker/tests %{_libexecdir}/pacemaker/cts-log-watcher %{_libexecdir}/pacemaker/cts-support %license licenses/GPLv2 %doc COPYING %doc ChangeLog %files -n %{pkgname_pcmk_libs}-devel %{_includedir}/pacemaker %{_libdir}/*.so %if %{with coverage} %{_var}/lib/pacemaker/gcov %endif %{_libdir}/pkgconfig/*.pc %license licenses/LGPLv2.1 %doc COPYING %doc ChangeLog %files schemas %license licenses/GPLv2 %dir %{_datadir}/pacemaker %{_datadir}/pacemaker/*.rng %{_datadir}/pacemaker/*.xsl %{_datadir}/pacemaker/api %{_datadir}/pkgconfig/pacemaker-schemas.pc %changelog * PACKAGE_DATE ClusterLabs PACKAGE_VERSION-1 - See included ChangeLog file for details