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