xref: /freebsd/contrib/atf/atf-c/detail/sanity.h (revision 8f0ea33f2bbf3a6aa80235f0a02fa5f2780c2b17)
1*0677dfd1SJulio Merino /* Copyright (c) 2008 The NetBSD Foundation, Inc.
2c243e490SMarcel Moolenaar  * All rights reserved.
3c243e490SMarcel Moolenaar  *
4c243e490SMarcel Moolenaar  * Redistribution and use in source and binary forms, with or without
5c243e490SMarcel Moolenaar  * modification, are permitted provided that the following conditions
6c243e490SMarcel Moolenaar  * are met:
7c243e490SMarcel Moolenaar  * 1. Redistributions of source code must retain the above copyright
8c243e490SMarcel Moolenaar  *    notice, this list of conditions and the following disclaimer.
9c243e490SMarcel Moolenaar  * 2. Redistributions in binary form must reproduce the above copyright
10c243e490SMarcel Moolenaar  *    notice, this list of conditions and the following disclaimer in the
11c243e490SMarcel Moolenaar  *    documentation and/or other materials provided with the distribution.
12c243e490SMarcel Moolenaar  *
13c243e490SMarcel Moolenaar  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14c243e490SMarcel Moolenaar  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15c243e490SMarcel Moolenaar  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16c243e490SMarcel Moolenaar  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17c243e490SMarcel Moolenaar  * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18c243e490SMarcel Moolenaar  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19c243e490SMarcel Moolenaar  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20c243e490SMarcel Moolenaar  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21c243e490SMarcel Moolenaar  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22c243e490SMarcel Moolenaar  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23c243e490SMarcel Moolenaar  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24*0677dfd1SJulio Merino  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  */
25c243e490SMarcel Moolenaar 
26*0677dfd1SJulio Merino #if !defined(ATF_C_DETAIL_SANITY_H)
27*0677dfd1SJulio Merino #define ATF_C_DETAIL_SANITY_H
28c243e490SMarcel Moolenaar 
29c243e490SMarcel Moolenaar void atf_sanity_inv(const char *, int, const char *);
30c243e490SMarcel Moolenaar void atf_sanity_pre(const char *, int, const char *);
31c243e490SMarcel Moolenaar void atf_sanity_post(const char *, int, const char *);
32c243e490SMarcel Moolenaar 
33c243e490SMarcel Moolenaar #if !defined(NDEBUG)
34c243e490SMarcel Moolenaar 
35c243e490SMarcel Moolenaar #define INV(x) \
36c243e490SMarcel Moolenaar     do { \
37c243e490SMarcel Moolenaar         if (!(x)) \
38c243e490SMarcel Moolenaar             atf_sanity_inv(__FILE__, __LINE__, #x); \
39c243e490SMarcel Moolenaar     } while (0)
40c243e490SMarcel Moolenaar #define PRE(x) \
41c243e490SMarcel Moolenaar     do { \
42c243e490SMarcel Moolenaar         if (!(x)) \
43c243e490SMarcel Moolenaar             atf_sanity_pre(__FILE__, __LINE__, #x); \
44c243e490SMarcel Moolenaar     } while (0)
45c243e490SMarcel Moolenaar #define POST(x) \
46c243e490SMarcel Moolenaar     do { \
47c243e490SMarcel Moolenaar         if (!(x)) \
48c243e490SMarcel Moolenaar             atf_sanity_post(__FILE__, __LINE__, #x); \
49c243e490SMarcel Moolenaar     } while (0)
50c243e490SMarcel Moolenaar 
51c243e490SMarcel Moolenaar #else /* defined(NDEBUG) */
52c243e490SMarcel Moolenaar 
53c243e490SMarcel Moolenaar #define INV(x) \
54c243e490SMarcel Moolenaar     do { \
55c243e490SMarcel Moolenaar     } while (0)
56c243e490SMarcel Moolenaar 
57c243e490SMarcel Moolenaar #define PRE(x) \
58c243e490SMarcel Moolenaar     do { \
59c243e490SMarcel Moolenaar     } while (0)
60c243e490SMarcel Moolenaar 
61c243e490SMarcel Moolenaar #define POST(x) \
62c243e490SMarcel Moolenaar     do { \
63c243e490SMarcel Moolenaar     } while (0)
64c243e490SMarcel Moolenaar 
65c243e490SMarcel Moolenaar #endif /* !defined(NDEBUG) */
66c243e490SMarcel Moolenaar 
67c243e490SMarcel Moolenaar #define UNREACHABLE INV(0)
68c243e490SMarcel Moolenaar 
69*0677dfd1SJulio Merino #endif /* !defined(ATF_C_DETAIL_SANITY_H) */
70