• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2012 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial
14  * portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 #ifndef _TEST_RUNNER_H_
26 #define _TEST_RUNNER_H_
27 
28 #ifdef NDEBUG
29 #error "Tests must not be built with NDEBUG defined, they rely on assert()."
30 #endif
31 
32 #include <unistd.h>
33 
34 struct test {
35 	const char *name;
36 	void (*run)(void);
37 	int must_fail;
38 } __attribute__ ((aligned (16)));
39 
40 #define TEST(name)							\
41 	static void name(void);						\
42 									\
43 	const struct test test##name					\
44 		 __attribute__ ((used, section ("test_section"))) = {	\
45 		#name, name, 0						\
46 	};								\
47 									\
48 	static void name(void)
49 
50 #define FAIL_TEST(name)							\
51 	static void name(void);						\
52 									\
53 	const struct test test##name					\
54 		 __attribute__ ((used, section ("test_section"))) = {	\
55 		#name, name, 1						\
56 	};								\
57 									\
58 	static void name(void)
59 
60 int
61 count_open_fds(void);
62 
63 void
64 exec_fd_leak_check(int nr_expected_fds); /* never returns */
65 
66 void
67 check_fd_leaks(int supposed_fds);
68 
69 /*
70  * set/reset the timeout in seconds. The timeout starts
71  * at the point of invoking this function
72  */
73 void
74 test_set_timeout(unsigned int);
75 
76 /* test-runner uses alarm() and SIGALRM, so we can not
77  * use usleep and sleep functions in tests (see 'man usleep'
78  * or 'man sleep', respectively). Following functions are safe
79  * to use in tests */
80 void
81 test_usleep(useconds_t);
82 
83 void
84 test_sleep(unsigned int);
85 
86 void
87 test_disable_coredumps(void);
88 
89 #define DISABLE_LEAK_CHECKS				\
90 	do {						\
91 		extern int fd_leak_check_enabled;	\
92 		fd_leak_check_enabled = 0;		\
93 	} while (0);
94 
95 #endif
96