14c87aefeSPatrick Mooney /*
24c87aefeSPatrick Mooney  * This file and its contents are supplied under the terms of the
34c87aefeSPatrick Mooney  * Common Development and Distribution License ("CDDL"), version 1.0.
44c87aefeSPatrick Mooney  * You may only use this file in accordance with the terms of version
54c87aefeSPatrick Mooney  * 1.0 of the CDDL.
64c87aefeSPatrick Mooney  *
74c87aefeSPatrick Mooney  * A full copy of the text of the CDDL should have accompanied this
84c87aefeSPatrick Mooney  * source.  A copy of the CDDL is also available via the Internet at
94c87aefeSPatrick Mooney  * http://www.illumos.org/license/CDDL.
104c87aefeSPatrick Mooney  */
114c87aefeSPatrick Mooney 
124c87aefeSPatrick Mooney /*
134c87aefeSPatrick Mooney  * Copyright 2018 Joyent, Inc.
144c87aefeSPatrick Mooney  */
154c87aefeSPatrick Mooney 
164c87aefeSPatrick Mooney #ifndef _TESTLIB_H_
174c87aefeSPatrick Mooney #define	_TESTLIB_H_
184c87aefeSPatrick Mooney 
194c87aefeSPatrick Mooney #include <assert.h>
204c87aefeSPatrick Mooney #include <errno.h>
214c87aefeSPatrick Mooney #include <signal.h>
224c87aefeSPatrick Mooney #include <stdio.h>
234c87aefeSPatrick Mooney #include <stdlib.h>
244c87aefeSPatrick Mooney #include <strings.h>
254c87aefeSPatrick Mooney 
264c87aefeSPatrick Mooney #include <sys/types.h>
274c87aefeSPatrick Mooney #include <sys/stat.h>
284c87aefeSPatrick Mooney 
294c87aefeSPatrick Mooney #include "mevent.h"
304c87aefeSPatrick Mooney 
314c87aefeSPatrick Mooney #define	EXIT_PASS 0
324c87aefeSPatrick Mooney #define	EXIT_FAIL 1
334c87aefeSPatrick Mooney 
344c87aefeSPatrick Mooney #define	VERBOSE(msg)							\
354c87aefeSPatrick Mooney 	if (testlib_verbose) {						\
364c87aefeSPatrick Mooney 		(void) printf("VERBOSE %s: %s:%d %s: ", testlib_prog,	\
374c87aefeSPatrick Mooney 		    __FILE__, __LINE__, __func__);			\
384c87aefeSPatrick Mooney 		(void) printf msg;					\
394c87aefeSPatrick Mooney 		(void) printf("\n");					\
404c87aefeSPatrick Mooney 	}
414c87aefeSPatrick Mooney 
424c87aefeSPatrick Mooney #define	FAIL_PROLOGUE() \
434c87aefeSPatrick Mooney 	(void) printf("FAIL %s: %s:%d: ", testlib_prog, __FILE__, __LINE__)
444c87aefeSPatrick Mooney 
454c87aefeSPatrick Mooney #define	FAIL(msg)							\
464c87aefeSPatrick Mooney 	{								\
474c87aefeSPatrick Mooney 		FAIL_PROLOGUE();					\
484c87aefeSPatrick Mooney 		(void) printf msg;					\
494c87aefeSPatrick Mooney 		(void) printf("\n");					\
504c87aefeSPatrick Mooney 		exit(EXIT_FAIL);					\
514c87aefeSPatrick Mooney 	}
524c87aefeSPatrick Mooney 
534c87aefeSPatrick Mooney #define	FAIL_ERRNO(msg) FAIL((msg ": %s", strerror(errno)))
544c87aefeSPatrick Mooney 
554c87aefeSPatrick Mooney #define	PASS()								\
564c87aefeSPatrick Mooney 	{								\
574c87aefeSPatrick Mooney 		(void) printf("PASS %s\n", testlib_prog);		\
584c87aefeSPatrick Mooney 		exit(EXIT_PASS);					\
594c87aefeSPatrick Mooney 	}
604c87aefeSPatrick Mooney 
614c87aefeSPatrick Mooney #define	ASSERT_CMP(msg, got, cmp, exp, nfmt)				\
624c87aefeSPatrick Mooney 	if (!(got cmp exp)) {						\
634c87aefeSPatrick Mooney 		FAIL_PROLOGUE();					\
644c87aefeSPatrick Mooney 		(void) printf msg;					\
654c87aefeSPatrick Mooney 		(void) printf(": %s=" nfmt " %s %s=" nfmt "\n",		\
664c87aefeSPatrick Mooney 		    #got, got, #cmp, #exp, exp);			\
674c87aefeSPatrick Mooney 		exit(EXIT_FAIL);					\
684c87aefeSPatrick Mooney 	}
694c87aefeSPatrick Mooney 
704c87aefeSPatrick Mooney #define	ASSERT_CHAR_EQ(msg, got, exp)	ASSERT_CMP(msg, got, ==, exp, "%c")
714c87aefeSPatrick Mooney #define	ASSERT_INT_EQ(msg, got, exp)	ASSERT_CMP(msg, got, ==, exp, "%d")
724c87aefeSPatrick Mooney #define	ASSERT_INT_NEQ(msg, got, exp)	ASSERT_CMP(msg, got, !=, exp, "%d")
734c87aefeSPatrick Mooney #define	ASSERT_INT64_EQ(msg, got, exp)	ASSERT_CMP(msg, got, ==, exp, "%ld")
74*251becc8SAndy Fiddaman #define	ASSERT_INT64_NEQ(msg, got, exp)	ASSERT_CMP(msg, got, !=, exp, "%ld")
754c87aefeSPatrick Mooney #define	ASSERT_PTR_EQ(msg, got, exp)	ASSERT_CMP(msg, got, ==, exp, "%p")
764c87aefeSPatrick Mooney #define	ASSERT_PTR_NEQ(msg, got, exp)	ASSERT_CMP(msg, got, !=, exp, "%p")
774c87aefeSPatrick Mooney 
784c87aefeSPatrick Mooney #define	ASSERT_STR_EQ(msg, got, exp)					\
794c87aefeSPatrick Mooney 	if (strcmp(got, exp) != 0) {					\
804c87aefeSPatrick Mooney 		FAIL_PROLOGUE();					\
814c87aefeSPatrick Mooney 		(void) printf msg;					\
824c87aefeSPatrick Mooney 		(void) printf(": %s='%s' != %s='%s'\n",			\
834c87aefeSPatrick Mooney 		    #got, got, #exp, exp);				\
844c87aefeSPatrick Mooney 		exit(EXIT_FAIL);					\
854c87aefeSPatrick Mooney 	}
864c87aefeSPatrick Mooney 
874c87aefeSPatrick Mooney extern const char	*testlib_prog;
884c87aefeSPatrick Mooney extern boolean_t	testlib_verbose;
894c87aefeSPatrick Mooney 
904c87aefeSPatrick Mooney extern void start_test(const char *, uint32_t);
914c87aefeSPatrick Mooney extern void start_event_thread(void);
924c87aefeSPatrick Mooney extern void test_mevent_count_lists(int *, int *, int *);
93*251becc8SAndy Fiddaman extern void set_mevent_file_poll_interval_ms(int);
944c87aefeSPatrick Mooney 
954c87aefeSPatrick Mooney #endif /* _TESTLIB_H_ */
96