|
YAC 3.21.0
Yet Another Coupler
|
Macros for testing code paths that are expected to abort. More...
#include <setjmp.h>#include <stdio.h>#include <string.h>#include <mpi.h>#include "ppm/core.h"#include "yac_assert.h"

Go to the source code of this file.
Macros | |
| #define | YAC_TEST_ABORT_UNHAPPY_PATH_ENABLED 1 |
| #define | YAC_TEST_ABORT_RUN_(result_var, expected_substr, ...) |
| #define | YAC_TEST_EXPECT_ABORT_SERIAL( test_failed, expected_result, expected_substr, ...) |
| #define | YAC_TEST_EXPECT_ABORT_PAR_ANY( test_failed, expected_result, expected_substr, comm, ...) |
| #define | YAC_TEST_EXPECT_ABORT_PAR_ALL( test_failed, expected_result, expected_substr, comm, ...) |
Enumerations | |
| enum | yac_test_abort_result { YAC_TEST_ABORT_NO_CALL = 1 << 0 , YAC_TEST_ABORT_EXPECTED = 1 << 1 , YAC_TEST_ABORT_UNEXPECTED = 1 << 2 } |
| enum | { YAC_TEST_ABORT_MSG_LEN = 1024 } |
Functions | ||
| struct { | ||
| jmp_buf jmp | ||
| char const * substr_ | ||
| char msg_ [YAC_TEST_ABORT_MSG_LEN] | ||
| int active_ | ||
| } | __attribute__ ((unused)) | |
Macros for testing code paths that are expected to abort.
The YAC_TEST_EXPECT_ABORT_* macros install an abort handler that longjmps back to the macro instead of terminating the process. This allows to test several unhappy paths from within a single test program and to continue testing afterwards.
Each use states the expected outcome, which is compared to the actual one. The expected outcome also determines whether the statement is executed at all: in code coverage builds the internal asserts are compiled out, and since an assert is the precondition for the code following it, a statement that is expected to abort must not be executed in such builds. Statements that are expected to complete normally (expected outcome YAC_TEST_ABORT_NO_CALL) are always executed.
Jumping out of the aborting routine skips all of its remaining code, which puts a couple of restrictions on where these macros can be used. YAC does not support being called again after the abort handler was invoked (see the remark on yac_set_abort_handler), so each use has to be checked against the routine that is expected to abort:
Definition in file test_expect_abort.h.
| #define YAC_TEST_ABORT_RUN_ | ( | result_var, | |
| expected_substr, | |||
| ... ) |
Internal execution of the statement under the test abort handler.
Definition at line 222 of file test_expect_abort.h.
| #define YAC_TEST_ABORT_UNHAPPY_PATH_ENABLED 1 |
Is 0 if statements that are expected to abort are not executed at all (code coverage builds, see above) and 1 otherwise.
Definition at line 83 of file test_expect_abort.h.
| #define YAC_TEST_EXPECT_ABORT_PAR_ALL | ( | test_failed, | |
| expected_result, | |||
| expected_substr, | |||
| comm, | |||
| ... ) |
YAC_TEST_EXPECT_ABORT_PAR_ALL( test_failed, expected_result, expected_substr, comm, call)
Like YAC_TEST_EXPECT_ABORT_PAR_ANY, but requires that every process in comm calls the abort handler:
expected_result has to be identical on all processes in comm.
The original abort handler is restored on every process before the reduce.
| test_failed | int lvalue receiving the result of the comparison |
| expected_result | expected outcome (enum yac_test_abort_result) |
| expected_substr | substring expected in the error message, or NULL to accept any abort message |
| comm | MPI communicator |
| ... | statement to execute (last argument, so that it may contain commas at bracket level zero) |
Definition at line 364 of file test_expect_abort.h.
| #define YAC_TEST_EXPECT_ABORT_PAR_ANY | ( | test_failed, | |
| expected_result, | |||
| expected_substr, | |||
| comm, | |||
| ... ) |
YAC_TEST_EXPECT_ABORT_PAR_ANY( test_failed, expected_result, expected_substr, comm, call)
Like YAC_TEST_EXPECT_ABORT_SERIAL, but combines the per-process outcomes across all processes in comm before comparing them to expected_result:
expected_result has to be identical on all processes in comm.
The original abort handler is restored on every process before the reduce.
| test_failed | int lvalue receiving the result of the comparison |
| expected_result | expected outcome (enum yac_test_abort_result) |
| expected_substr | substring expected in the error message, or NULL to accept any abort message |
| comm | MPI communicator |
| ... | statement to execute (last argument, so that it may contain commas at bracket level zero) |
Definition at line 322 of file test_expect_abort.h.
| #define YAC_TEST_EXPECT_ABORT_SERIAL | ( | test_failed, | |
| expected_result, | |||
| expected_substr, | |||
| ... ) |
YAC_TEST_EXPECT_ABORT_SERIAL( test_failed, expected_result, expected_substr, call)
Execute call under a custom abort handler and compare the outcome to expected_result:
call completes without triggering abortexpected_substrexpected_substrtest_failed is set to 0 if the outcome matches and to 1 otherwise, in which case the details of the mismatch are written to stderr. Counting the error is left to the caller.
If expected_result is not YAC_TEST_ABORT_NO_CALL and the internal asserts are compiled out, call is not executed and test_failed is set to 0.
The original abort handler is always restored afterwards.
| test_failed | int lvalue receiving the result of the comparison |
| expected_result | expected outcome (enum yac_test_abort_result) |
| expected_substr | substring expected in the error message, or NULL to accept any abort message |
| ... | statement to execute (last argument, so that it may contain commas at bracket level zero) |
Definition at line 282 of file test_expect_abort.h.
| anonymous enum |
| Enumerator | |
|---|---|
| YAC_TEST_ABORT_MSG_LEN | |
Definition at line 88 of file test_expect_abort.h.
Possible outcomes of a statement executed under the test abort handler. The parallel macros OR these values together to combine the per-process outcomes, hence each has to be a distinct single bit. The nonzero values are also passed to longjmp; YAC_TEST_ABORT_NO_CALL is never used with longjmp (it corresponds to the direct return from setjmp).
| Enumerator | |
|---|---|
| YAC_TEST_ABORT_NO_CALL | abort handler was never invoked |
| YAC_TEST_ABORT_EXPECTED | abort was called with expected message |
| YAC_TEST_ABORT_UNEXPECTED | abort was called with unexpected message |
Definition at line 70 of file test_expect_abort.h.
|
static |
| int active_ |
Definition at line 94 of file test_expect_abort.h.
| jmp_buf jmp |
Definition at line 91 of file test_expect_abort.h.
| char msg_ |
Definition at line 93 of file test_expect_abort.h.
| char const * substr_ |
Definition at line 92 of file test_expect_abort.h.