pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
pcmk_new_scheduler_test.c
Go to the documentation of this file.
1/*
2 * Copyright 2022-2024 the Pacemaker project contributors
3 *
4 * The version control history for this file may have further details.
5 *
6 * This source code is licensed under the GNU General Public License version 2
7 * or later (GPLv2+) WITHOUT ANY WARRANTY.
8 */
9
10#include <crm_internal.h>
11
14
15#include "mock_private.h"
16
17static void
18calloc_fails(void **state)
19{
20 pcmk__mock_calloc = true; // calloc() will return NULL
21
22 expect_value(__wrap_calloc, nmemb, 1);
23 expect_value(__wrap_calloc, size, sizeof(pcmk_scheduler_t));
24 assert_null(pcmk_new_scheduler());
25
26 pcmk__mock_calloc = false; // Use real calloc()
27}
28
29static void
30calloc_succeeds(void **state)
31{
33
34 /* We only need to test that the allocated memory is non-NULL, as all the
35 * function does otherwise is call pcmk__set_scheduler_defaults(), which
36 * should have its own unit test.
37 */
38 assert_non_null(scheduler);
39 assert_non_null(scheduler->priv);
40
41 free(scheduler->priv);
42 free(scheduler);
43}
44
45PCMK__UNIT_TEST(NULL, NULL,
46 cmocka_unit_test(calloc_fails),
47 cmocka_unit_test(calloc_succeeds))
uint32_t size
Definition cpg.c:4
bool pcmk__mock_calloc
Definition mock.c:89
void * __wrap_calloc(size_t nmemb, size_t size)
Definition mock.c:92
pcmk_scheduler_t * scheduler
pcmk_scheduler_t * pcmk_new_scheduler(void)
Create a new object to hold scheduler data.
Definition scheduler.c:32
pcmk__scheduler_private_t * priv
Definition scheduler.h:99
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)