• 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__ ((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__ ((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 int
67 get_current_alloc_num(void);
68 
69 void
70 check_leaks(int supposed_allocs, int supposed_fds);
71 
72 /*
73  * set/reset the timeout in seconds. The timeout starts
74  * at the point of invoking this function
75  */
76 void
77 test_set_timeout(unsigned int);
78 
79 /* test-runner uses alarm() and SIGALRM, so we can not
80  * use usleep and sleep functions in tests (see 'man usleep'
81  * or 'man sleep', respectively). Following functions are safe
82  * to use in tests */
83 void
84 test_usleep(useconds_t);
85 
86 void
87 test_sleep(unsigned int);
88 
89 #define DISABLE_LEAK_CHECKS			\
90 	do {					\
91 		extern int leak_check_enabled;	\
92 		leak_check_enabled = 0;		\
93 	} while (0);
94 
95 #endif
96