pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
Macros
unittest_internal.h File Reference
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <setjmp.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <cmocka.h>
Include dependency graph for unittest_internal.h:

Go to the source code of this file.

Macros

#define pcmk__assert_asserts(stmt)
 
#define pcmk__assert_exits(rc, stmt)
 
#define PCMK__UNIT_TEST(group_setup, group_teardown, ...)
 

Macro Definition Documentation

◆ pcmk__assert_asserts

#define pcmk__assert_asserts (   stmt)
Value:
do { \
pid_t p = fork(); \
if (p == 0) { \
struct rlimit cores = { 0, 0 }; \
setrlimit(RLIMIT_CORE, &cores); \
stmt; \
_exit(0); \
} else if (p > 0) { \
int wstatus = 0; \
if (waitpid(p, &wstatus, 0) == -1) { \
fail_msg("waitpid failed"); \
} \
if (!(WIFSIGNALED(wstatus) && WTERMSIG(wstatus) == SIGABRT)) { \
fail_msg("statement terminated in child without asserting"); \
} \
} else { \
fail_msg("unable to fork for assert test"); \
} \
} while (0);

Definition at line 47 of file unittest_internal.h.

◆ pcmk__assert_exits

#define pcmk__assert_exits (   rc,
  stmt 
)
Value:
do { \
pid_t p = fork(); \
if (p == 0) { \
struct rlimit cores = { 0, 0 }; \
setrlimit(RLIMIT_CORE, &cores); \
stmt; \
_exit(CRM_EX_NONE); \
} else if (p > 0) { \
int wstatus = 0; \
if (waitpid(p, &wstatus, 0) == -1) { \
fail_msg("waitpid failed"); \
} \
if (!WIFEXITED(wstatus)) { \
fail_msg("statement terminated abnormally"); \
} else if (WEXITSTATUS(wstatus) != rc) { \
fail_msg("statement exited with %d, not expected %d", WEXITSTATUS(wstatus), rc); \
} \
} else { \
fail_msg("unable to fork for assert test"); \
} \
} while (0);
No exit status available.
Definition: results.h:303

Definition at line 83 of file unittest_internal.h.

◆ PCMK__UNIT_TEST

#define PCMK__UNIT_TEST (   group_setup,
  group_teardown,
  ... 
)
Value:
int \
main(int argc, char **argv) \
{ \
const struct CMUnitTest t[] = { \
__VA_ARGS__ \
}; \
cmocka_set_message_output(CM_OUTPUT_TAP); \
return cmocka_run_group_tests(t, group_setup, group_teardown); \
}

Definition at line 111 of file unittest_internal.h.