diff --git a/lib/pengine/tests/status/Makefile.am b/lib/pengine/tests/status/Makefile.am index f5db95c1d4..6adc9dfbc4 100644 --- a/lib/pengine/tests/status/Makefile.am +++ b/lib/pengine/tests/status/Makefile.am @@ -1,20 +1,24 @@ # # Copyright 2022 the Pacemaker project contributors # # The version control history for this file may have further details. # # This source code is licensed under the GNU General Public License version 2 # or later (GPLv2+) WITHOUT ANY WARRANTY. # -AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include +AM_CPPFLAGS = -I$(top_srcdir)/include \ + -I$(top_builddir)/include \ + -I$(top_srcdir)/lib/common LDADD = $(top_builddir)/lib/common/libcrmcommon_test.la \ $(top_builddir)/lib/pengine/libpe_status_test.la +AM_LDFLAGS = $(LDFLAGS_WRAP) include $(top_srcdir)/mk/tap.mk # Add "_test" to the end of all test program names to simplify .gitignore. check_PROGRAMS = pe_find_node_any_test \ pe_find_node_id_test \ - pe_find_node_test + pe_find_node_test \ + pe_new_working_set_test TESTS = $(check_PROGRAMS) diff --git a/lib/pengine/tests/status/pe_new_working_set_test.c b/lib/pengine/tests/status/pe_new_working_set_test.c new file mode 100644 index 0000000000..c2065b740b --- /dev/null +++ b/lib/pengine/tests/status/pe_new_working_set_test.c @@ -0,0 +1,54 @@ +/* + * Copyright 2022 the Pacemaker project contributors + * + * The version control history for this file may have further details. + * + * This source code is licensed under the GNU Lesser General Public License + * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + */ + +#include +#include "mock_private.h" + +#include +#include +#include +#include +#include + +#include + +static void +calloc_fails(void **state) { + pcmk__mock_calloc = true; // calloc() will return NULL + + assert_null(pe_new_working_set()); + + pcmk__mock_calloc = false; // Use real calloc() +} + +static void +calloc_succeeds(void **state) { + pe_working_set_t *data_set = pe_new_working_set(); + + /* Nothing else to test about this function, as all it does is call + * set_working_set_defaults which is also a public function and should + * get its own unit test. + */ + assert_non_null(data_set); + + /* Avoid calling pe_free_working_set here so we don't artificially + * inflate the coverage numbers. + */ + free(data_set); +} + +int main(int argc, char **argv) { + const struct CMUnitTest tests[] = { + cmocka_unit_test(calloc_fails), + cmocka_unit_test(calloc_succeeds), + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + return cmocka_run_group_tests(tests, NULL, NULL); +}