xref: /illumos-gate/usr/src/cmd/bhyve/test/tests/mevent/testlib.h (revision 251becc882939aaf03088561add2c257a7a92424)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2018 Joyent, Inc.
14  */
15 
16 #ifndef _TESTLIB_H_
17 #define	_TESTLIB_H_
18 
19 #include <assert.h>
20 #include <errno.h>
21 #include <signal.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <strings.h>
25 
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 
29 #include "mevent.h"
30 
31 #define	EXIT_PASS 0
32 #define	EXIT_FAIL 1
33 
34 #define	VERBOSE(msg)							\
35 	if (testlib_verbose) {						\
36 		(void) printf("VERBOSE %s: %s:%d %s: ", testlib_prog,	\
37 		    __FILE__, __LINE__, __func__);			\
38 		(void) printf msg;					\
39 		(void) printf("\n");					\
40 	}
41 
42 #define	FAIL_PROLOGUE() \
43 	(void) printf("FAIL %s: %s:%d: ", testlib_prog, __FILE__, __LINE__)
44 
45 #define	FAIL(msg)							\
46 	{								\
47 		FAIL_PROLOGUE();					\
48 		(void) printf msg;					\
49 		(void) printf("\n");					\
50 		exit(EXIT_FAIL);					\
51 	}
52 
53 #define	FAIL_ERRNO(msg) FAIL((msg ": %s", strerror(errno)))
54 
55 #define	PASS()								\
56 	{								\
57 		(void) printf("PASS %s\n", testlib_prog);		\
58 		exit(EXIT_PASS);					\
59 	}
60 
61 #define	ASSERT_CMP(msg, got, cmp, exp, nfmt)				\
62 	if (!(got cmp exp)) {						\
63 		FAIL_PROLOGUE();					\
64 		(void) printf msg;					\
65 		(void) printf(": %s=" nfmt " %s %s=" nfmt "\n",		\
66 		    #got, got, #cmp, #exp, exp);			\
67 		exit(EXIT_FAIL);					\
68 	}
69 
70 #define	ASSERT_CHAR_EQ(msg, got, exp)	ASSERT_CMP(msg, got, ==, exp, "%c")
71 #define	ASSERT_INT_EQ(msg, got, exp)	ASSERT_CMP(msg, got, ==, exp, "%d")
72 #define	ASSERT_INT_NEQ(msg, got, exp)	ASSERT_CMP(msg, got, !=, exp, "%d")
73 #define	ASSERT_INT64_EQ(msg, got, exp)	ASSERT_CMP(msg, got, ==, exp, "%ld")
74 #define	ASSERT_INT64_NEQ(msg, got, exp)	ASSERT_CMP(msg, got, !=, exp, "%ld")
75 #define	ASSERT_PTR_EQ(msg, got, exp)	ASSERT_CMP(msg, got, ==, exp, "%p")
76 #define	ASSERT_PTR_NEQ(msg, got, exp)	ASSERT_CMP(msg, got, !=, exp, "%p")
77 
78 #define	ASSERT_STR_EQ(msg, got, exp)					\
79 	if (strcmp(got, exp) != 0) {					\
80 		FAIL_PROLOGUE();					\
81 		(void) printf msg;					\
82 		(void) printf(": %s='%s' != %s='%s'\n",			\
83 		    #got, got, #exp, exp);				\
84 		exit(EXIT_FAIL);					\
85 	}
86 
87 extern const char	*testlib_prog;
88 extern boolean_t	testlib_verbose;
89 
90 extern void start_test(const char *, uint32_t);
91 extern void start_event_thread(void);
92 extern void test_mevent_count_lists(int *, int *, int *);
93 extern void set_mevent_file_poll_interval_ms(int);
94 
95 #endif /* _TESTLIB_H_ */
96