pacemaker
2.1.2-ada5c3b36
Scalable High-Availability cluster resource manager
lib
common
mock.c
Go to the documentation of this file.
1
/*
2
* Copyright 2021 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 Lesser General Public License
7
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8
*/
9
10
#include <stdlib.h>
11
#include <sys/utsname.h>
12
13
#include "
mock_private.h
"
14
15
/* This file is only used when running "make check". It is built into
16
* libcrmcommon_test.a, not into libcrmcommon.so. It is used to support
17
* constructing mock versions of library functions for unit testing.
18
*
19
* Each unit test will only ever want to use a mocked version of one or two
20
* library functions. However, we need to mark all the mocked functions as
21
* wrapped (with -Wl,--wrap= in the LDFLAGS) in libcrmcommon_test.a so that
22
* all those unit tests can share the same special test library. The unit
23
* test then defines its own wrapped function. Because a unit test won't
24
* define every single wrapped function, there will be undefined references
25
* at link time.
26
*
27
* This file takes care of those undefined references. It defines a
28
* wrapped version of every function that simply calls the real libc
29
* version. These wrapped versions are defined with a weak attribute,
30
* which means the unit tests can define another wrapped version for
31
* unit testing that will override the version defined here.
32
*
33
* IN SUMMARY:
34
*
35
* - Define two functions for each function listed in WRAPPED in mock.mk.
36
* One function is a weakly defined __wrap_X function that just calls
37
* __real_X.
38
* - Add a __real_X and __wrap_X function prototype for each function to
39
* mock_private.h.
40
* - Each unit test defines its own __wrap_X for whatever function it's
41
* mocking that overrides the version here.
42
*/
43
44
char
*
__attribute__
((weak))
45
__wrap_getenv
(
const
char
*
name
) {
46
return
__real_getenv
(
name
);
47
}
48
49
int
__attribute__
((weak))
50
__wrap_uname
(
struct
utsname *buf) {
51
return
__real_uname
(buf);
52
}
__wrap_uname
int __wrap_uname(struct utsname *buf)
Definition:
pcmk_hostname_test.c:24
mock_private.h
__real_getenv
char * __real_getenv(const char *name)
__real_uname
int __real_uname(struct utsname *buf)
__wrap_getenv
char * __wrap_getenv(const char *name)
Definition:
pcmk__get_tmpdir_test.c:25
__attribute__
char * __attribute__((weak))
Definition:
mock.c:44
name
char * name
Definition:
pcmk_fence.c:31
Generated on Wed Nov 24 2021 11:15:07 for pacemaker by
1.8.14