Check length of ifname before copying it into to ifreq structure.
[glibc.git] / support / check.h
blobbdcd12952af6c286cebc9ec0916abedff71b77ed
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>
24 __BEGIN_DECLS
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__)
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
38 exit status 1. */
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
43 status of 77). */
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
48 false. */
49 #define TEST_VERIFY(expr) \
50 ({ \
51 if (expr) \
52 ; \
53 else \
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) \
59 ({ \
60 if (expr) \
61 ; \
62 else \
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,
75 const char *expr);
76 void support_test_verify_exit_impl (int status, const char *file, int line,
77 const char *expr)
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 /* Internal function called by the test driver. */
90 int support_report_failure (int status)
91 __attribute__ ((weak, warn_unused_result));
93 /* Internal function used to test the failure recording framework. */
94 void support_record_failure_reset (void);
96 __END_DECLS
98 #endif /* SUPPORT_CHECK_H */