diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 07:45:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 07:45:40 +0000 |
commit | 07d7f4cfa4b10de87a31b68191036ff446add675 (patch) | |
tree | 7162524d8aaf1aef62d2f4fa51f595ed113981ff /include/crm/common/unittest_internal.h | |
parent | Adding upstream version 2.1.6. (diff) | |
download | pacemaker-07d7f4cfa4b10de87a31b68191036ff446add675.tar.xz pacemaker-07d7f4cfa4b10de87a31b68191036ff446add675.zip |
Adding upstream version 2.1.7.upstream/2.1.7
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'include/crm/common/unittest_internal.h')
-rw-r--r-- | include/crm/common/unittest_internal.h | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/include/crm/common/unittest_internal.h b/include/crm/common/unittest_internal.h index b8f78cf..1fc8501 100644 --- a/include/crm/common/unittest_internal.h +++ b/include/crm/common/unittest_internal.h @@ -1,5 +1,5 @@ /* - * Copyright 2022 the Pacemaker project contributors + * Copyright 2022-2023 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -65,6 +65,44 @@ } \ } while (0); +/*! + * \internal + * \brief Assert that a statement exits with the expected exit status. + * + * \param[in] stmt Statement to execute; can be an expression. + * \param[in] rc The expected exit status. + * + * This functions just like \c pcmk__assert_asserts, except that it tests for + * an expected exit status. Abnormal termination or incorrect exit status is + * treated as a failure of the test. + * + * In the event that stmt does not exit at all, the special code \c CRM_EX_NONE + * will be returned. It is expected that this code is not used anywhere, thus + * always causing an error. + */ +#define pcmk__assert_exits(rc, stmt) \ + 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); + /* Generate the main function of most unit test files. Typically, group_setup * and group_teardown will be NULL. The rest of the arguments are a list of * calls to cmocka_unit_test or cmocka_unit_test_setup_teardown to run the |