| 1 | /* Functionality for reporting test results. |
| 2 | Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, see |
| 17 | <http://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #ifndef SUPPORT_CHECK_H |
| 20 | #define SUPPORT_CHECK_H |
| 21 | |
| 22 | #include <sys/cdefs.h> |
| 23 | |
| 24 | __BEGIN_DECLS |
| 25 | |
| 26 | /* Record a test failure, print the failure message to standard output |
| 27 | and return 1. */ |
| 28 | #define FAIL_RET(...) \ |
| 29 | return support_print_failure_impl (__FILE__, __LINE__, __VA_ARGS__) |
| 30 | |
| 31 | /* Print the failure message and terminate the process with STATUS. |
| 32 | Record a the process as failed if STATUS is neither EXIT_SUCCESS |
| 33 | nor EXIT_UNSUPPORTED. */ |
| 34 | #define FAIL_EXIT(status, ...) \ |
| 35 | support_exit_failure_impl (status, __FILE__, __LINE__, __VA_ARGS__) |
| 36 | |
| 37 | /* Record a test failure, print the failure message and terminate with |
| 38 | exit status 1. */ |
| 39 | #define FAIL_EXIT1(...) \ |
| 40 | support_exit_failure_impl (1, __FILE__, __LINE__, __VA_ARGS__) |
| 41 | |
| 42 | /* Print failure message and terminate with as unsupported test (exit |
| 43 | status of 77). */ |
| 44 | #define FAIL_UNSUPPORTED(...) \ |
| 45 | support_exit_failure_impl (77, __FILE__, __LINE__, __VA_ARGS__) |
| 46 | |
| 47 | /* Record a test failure (but continue executing) if EXPR evaluates to |
| 48 | false. */ |
| 49 | #define TEST_VERIFY(expr) \ |
| 50 | ({ \ |
| 51 | if (expr) \ |
| 52 | ; \ |
| 53 | else \ |
| 54 | support_test_verify_impl (-1, __FILE__, __LINE__, #expr); \ |
| 55 | }) |
| 56 | |
| 57 | /* Record a test failure and exit if EXPR evaluates to false. */ |
| 58 | #define TEST_VERIFY_EXIT(expr) \ |
| 59 | ({ \ |
| 60 | if (expr) \ |
| 61 | ; \ |
| 62 | else \ |
| 63 | support_test_verify_impl (1, __FILE__, __LINE__, #expr); \ |
| 64 | }) |
| 65 | |
| 66 | int support_print_failure_impl (const char *file, int line, |
| 67 | const char *format, ...) |
| 68 | __attribute__ ((nonnull (1), format (printf, 3, 4))); |
| 69 | void support_exit_failure_impl (int exit_status, |
| 70 | const char *file, int line, |
| 71 | const char *format, ...) |
| 72 | __attribute__ ((noreturn, nonnull (2), format (printf, 4, 5))); |
| 73 | void support_test_verify_impl (int status, const char *file, int line, |
| 74 | const char *expr); |
| 75 | |
| 76 | /* Record a test failure. This function returns and does not |
| 77 | terminate the process. The failure counter is stored in a shared |
| 78 | memory mapping, so that failures reported in child processes are |
| 79 | visible to the parent process and test driver. This function |
| 80 | depends on initialization by an ELF constructor, so it can only be |
| 81 | invoked after the test driver has run. Note that this function |
| 82 | does not support reporting failures from a DSO. */ |
| 83 | void support_record_failure (void); |
| 84 | |
| 85 | /* Internal function called by the test driver. */ |
| 86 | int support_report_failure (int status) |
| 87 | __attribute__ ((weak, warn_unused_result)); |
| 88 | |
| 89 | /* Internal function used to test the failure recording framework. */ |
| 90 | void support_record_failure_reset (void); |
| 91 | |
| 92 | __END_DECLS |
| 93 | |
| 94 | #endif /* SUPPORT_CHECK_H */ |
| 95 | |