4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #include_next <assert.h>
29 #ifndef _LIBSPL_ASSERT_H
30 #define _LIBSPL_ASSERT_H
36 /* Set to non-zero to avoid abort()ing on an assertion failure */
37 extern int libspl_assert_ok;
39 /* printf version of libspl_assert */
40 extern void libspl_assertf(const char *file, const char *func, int line,
41 const char *format, ...);
44 libspl_assert(const char *buf, const char *file, const char *func, int line)
46 libspl_assertf(file, func, line, "%s", buf);
54 #define VERIFY(cond) \
55 (void) ((!(cond)) && \
56 libspl_assert(#cond, __FILE__, __FUNCTION__, __LINE__))
57 #define verify(cond) \
58 (void) ((!(cond)) && \
59 libspl_assert(#cond, __FILE__, __FUNCTION__, __LINE__))
61 #define VERIFY3B(LEFT, OP, RIGHT) \
63 const boolean_t __left = (boolean_t)(LEFT); \
64 const boolean_t __right = (boolean_t)(RIGHT); \
65 if (!(__left OP __right)) \
66 libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
67 "%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \
68 (u_longlong_t)__left, #OP, (u_longlong_t)__right); \
71 #define VERIFY3S(LEFT, OP, RIGHT) \
73 const int64_t __left = (int64_t)(LEFT); \
74 const int64_t __right = (int64_t)(RIGHT); \
75 if (!(__left OP __right)) \
76 libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
77 "%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \
78 (u_longlong_t)__left, #OP, (u_longlong_t)__right); \
81 #define VERIFY3U(LEFT, OP, RIGHT) \
83 const uint64_t __left = (uint64_t)(LEFT); \
84 const uint64_t __right = (uint64_t)(RIGHT); \
85 if (!(__left OP __right)) \
86 libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
87 "%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \
88 (u_longlong_t)__left, #OP, (u_longlong_t)__right); \
91 #define VERIFY3P(LEFT, OP, RIGHT) \
93 const uintptr_t __left = (uintptr_t)(LEFT); \
94 const uintptr_t __right = (uintptr_t)(RIGHT); \
95 if (!(__left OP __right)) \
96 libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
97 "%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \
98 (u_longlong_t)__left, #OP, (u_longlong_t)__right); \
101 #define VERIFY0(LEFT) \
103 const uint64_t __left = (uint64_t)(LEFT); \
104 if (!(__left == 0)) \
105 libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
106 "%s == 0 (0x%llx == 0)", #LEFT, \
107 (u_longlong_t)__left); \
115 #define ASSERT3B(x, y, z) \
116 ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z)))
117 #define ASSERT3S(x, y, z) \
118 ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z)))
119 #define ASSERT3U(x, y, z) \
120 ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z)))
121 #define ASSERT3P(x, y, z) \
122 ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z)))
123 #define ASSERT0(x) ((void) sizeof ((uintptr_t)(x)))
124 #define ASSERT(x) ((void) sizeof ((uintptr_t)(x)))
125 #define assert(x) ((void) sizeof ((uintptr_t)(x)))
126 #define IMPLY(A, B) \
127 ((void) sizeof ((uintptr_t)(A)), (void) sizeof ((uintptr_t)(B)))
128 #define EQUIV(A, B) \
129 ((void) sizeof ((uintptr_t)(A)), (void) sizeof ((uintptr_t)(B)))
131 #define ASSERT3B VERIFY3B
132 #define ASSERT3S VERIFY3S
133 #define ASSERT3U VERIFY3U
134 #define ASSERT3P VERIFY3P
135 #define ASSERT0 VERIFY0
136 #define ASSERT VERIFY
137 #define assert VERIFY
138 #define IMPLY(A, B) \
139 ((void)(((!(A)) || (B)) || \
140 libspl_assert("(" #A ") implies (" #B ")", \
141 __FILE__, __FUNCTION__, __LINE__)))
142 #define EQUIV(A, B) \
143 ((void)((!!(A) == !!(B)) || \
144 libspl_assert("(" #A ") is equivalent to (" #B ")", \
145 __FILE__, __FUNCTION__, __LINE__)))
149 #endif /* _LIBSPL_ASSERT_H */