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.
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.
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.
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/>. */
19 #ifndef SUPPORT_CHECK_H
20 #define SUPPORT_CHECK_H
22 #include <sys/cdefs.h>
26 /* Record a test failure, print the failure message to standard output
28 #define FAIL_RET(...) \
29 return support_print_failure_impl (__FILE__, __LINE__, __VA_ARGS__)
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__)
37 /* Record a test failure, print the failure message and terminate with
39 #define FAIL_EXIT1(...) \
40 support_exit_failure_impl (1, __FILE__, __LINE__, __VA_ARGS__)
42 /* Print failure message and terminate with as unsupported test (exit
44 #define FAIL_UNSUPPORTED(...) \
45 support_exit_failure_impl (77, __FILE__, __LINE__, __VA_ARGS__)
47 /* Record a test failure (but continue executing) if EXPR evaluates to
49 #define TEST_VERIFY(expr) \
54 support_test_verify_impl (__FILE__, __LINE__, #expr); \
57 /* Record a test failure and exit if EXPR evaluates to false. */
58 #define TEST_VERIFY_EXIT(expr) \
63 support_test_verify_exit_impl \
64 (1, __FILE__, __LINE__, #expr); \
67 int support_print_failure_impl (const char *file
, int line
,
68 const char *format
, ...)
69 __attribute__ ((nonnull (1), format (printf
, 3, 4)));
70 void support_exit_failure_impl (int exit_status
,
71 const char *file
, int line
,
72 const char *format
, ...)
73 __attribute__ ((noreturn
, nonnull (2), format (printf
, 4, 5)));
74 void support_test_verify_impl (const char *file
, int line
,
76 void support_test_verify_exit_impl (int status
, const char *file
, int line
,
78 __attribute__ ((noreturn
));
80 /* Record a test failure. This function returns and does not
81 terminate the process. The failure counter is stored in a shared
82 memory mapping, so that failures reported in child processes are
83 visible to the parent process and test driver. This function
84 depends on initialization by an ELF constructor, so it can only be
85 invoked after the test driver has run. Note that this function
86 does not support reporting failures from a DSO. */
87 void support_record_failure (void);
89 /* Compare the two integers LEFT and RIGHT and report failure if they
91 #define TEST_COMPARE(left, right) \
93 /* + applies the integer promotions, for bitfield support. */ \
94 typedef __typeof__ (+ (left)) __left_type; \
95 typedef __typeof__ (+ (right)) __right_type; \
96 __left_type __left_value = (left); \
97 __right_type __right_value = (right); \
98 /* Prevent use with floating-point and boolean types. */ \
99 _Static_assert ((__left_type) 1.0 == (__left_type) 1.5, \
100 "left value has floating-point type"); \
101 _Static_assert ((__right_type) 1.0 == (__right_type) 1.5, \
102 "right value has floating-point type"); \
103 /* Prevent accidental use with larger-than-long long types. */ \
104 _Static_assert (sizeof (__left_value) <= sizeof (long long), \
105 "left value fits into long long"); \
106 _Static_assert (sizeof (__right_value) <= sizeof (long long), \
107 "right value fits into long long"); \
108 /* Make sure that integer conversions does not alter the sign. */ \
111 __left_is_unsigned = (__left_type) -1 > 0, \
112 __right_is_unsigned = (__right_type) -1 > 0, \
113 __unsigned_left_converts_to_wider = (__left_is_unsigned \
114 && (sizeof (__left_value) \
115 < sizeof (__right_value))), \
116 __unsigned_right_converts_to_wider = (__right_is_unsigned \
117 && (sizeof (__right_value) \
118 < sizeof (__left_value))) \
120 _Static_assert (__left_is_unsigned == __right_is_unsigned \
121 || __unsigned_left_converts_to_wider \
122 || __unsigned_right_converts_to_wider, \
123 "integer conversions may alter sign of operands"); \
124 /* Compare the value. */ \
125 if (__left_value != __right_value) \
126 /* Pass the sign for printing the correct value. */ \
127 support_test_compare_failure \
128 (__FILE__, __LINE__, \
129 #left, __left_value, __left_value < 0, sizeof (__left_type), \
130 #right, __right_value, __right_value < 0, sizeof (__right_type)); \
133 /* Internal implementation of TEST_COMPARE. LEFT_NEGATIVE and
134 RIGHT_NEGATIVE are used to store the sign separately, so that both
135 unsigned long long and long long arguments fit into LEFT_VALUE and
136 RIGHT_VALUE, and the function can still print the original value.
137 LEFT_SIZE and RIGHT_SIZE specify the size of the argument in bytes,
138 for hexadecimal formatting. */
139 void support_test_compare_failure (const char *file
, int line
,
140 const char *left_expr
,
141 long long left_value
,
144 const char *right_expr
,
145 long long right_value
,
150 /* Internal function called by the test driver. */
151 int support_report_failure (int status
)
152 __attribute__ ((weak
, warn_unused_result
));
154 /* Internal function used to test the failure recording framework. */
155 void support_record_failure_reset (void);
159 #endif /* SUPPORT_CHECK_H */