sanity.h revision 275988
1236769Sobrien/* Copyright (c) 2008 The NetBSD Foundation, Inc.
2236769Sobrien * All rights reserved.
3236769Sobrien *
4236769Sobrien * Redistribution and use in source and binary forms, with or without
5236769Sobrien * modification, are permitted provided that the following conditions
6236769Sobrien * are met:
7236769Sobrien * 1. Redistributions of source code must retain the above copyright
8236769Sobrien *    notice, this list of conditions and the following disclaimer.
9236769Sobrien * 2. Redistributions in binary form must reproduce the above copyright
10236769Sobrien *    notice, this list of conditions and the following disclaimer in the
11236769Sobrien *    documentation and/or other materials provided with the distribution.
12236769Sobrien *
13236769Sobrien * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14236769Sobrien * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15236769Sobrien * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16236769Sobrien * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17236769Sobrien * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18236769Sobrien * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19236769Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20236769Sobrien * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21236769Sobrien * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22236769Sobrien * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23236769Sobrien * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24236769Sobrien * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  */
25236769Sobrien
26236769Sobrien#if !defined(ATF_C_DETAIL_SANITY_H)
27236769Sobrien#define ATF_C_DETAIL_SANITY_H
28236769Sobrien
29236769Sobrienvoid atf_sanity_inv(const char *, int, const char *);
30236769Sobrienvoid atf_sanity_pre(const char *, int, const char *);
31236769Sobrienvoid atf_sanity_post(const char *, int, const char *);
32236769Sobrien
33236769Sobrien#if !defined(NDEBUG)
34236769Sobrien
35236769Sobrien#define INV(x) \
36236769Sobrien    do { \
37236769Sobrien        if (!(x)) \
38236769Sobrien            atf_sanity_inv(__FILE__, __LINE__, #x); \
39236769Sobrien    } while (0)
40236769Sobrien#define PRE(x) \
41236769Sobrien    do { \
42236769Sobrien        if (!(x)) \
43236769Sobrien            atf_sanity_pre(__FILE__, __LINE__, #x); \
44236769Sobrien    } while (0)
45236769Sobrien#define POST(x) \
46236769Sobrien    do { \
47236769Sobrien        if (!(x)) \
48236769Sobrien            atf_sanity_post(__FILE__, __LINE__, #x); \
49236769Sobrien    } while (0)
50236769Sobrien
51236769Sobrien#else /* defined(NDEBUG) */
52236769Sobrien
53236769Sobrien#define INV(x) \
54236769Sobrien    do { \
55236769Sobrien    } while (0)
56236769Sobrien
57236769Sobrien#define PRE(x) \
58236769Sobrien    do { \
59236769Sobrien    } while (0)
60236769Sobrien
61236769Sobrien#define POST(x) \
62291978Ssjg    do { \
63291978Ssjg    } while (0)
64291978Ssjg
65291978Ssjg#endif /* !defined(NDEBUG) */
66291978Ssjg
67291978Ssjg#define UNREACHABLE INV(0)
68236769Sobrien
69236769Sobrien#endif /* !defined(ATF_C_DETAIL_SANITY_H) */
70236769Sobrien