L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
assert.h
Go to the documentation of this file.
1/*****************************************************************************/
9/*
10 * (c) 2009 Author(s)
11 * economic rights: Technische Universität Dresden (Germany)
12 * This file is part of TUD:OS and distributed under the terms of the
13 * GNU Lesser General Public License 2.1.
14 * Please see the COPYING-LGPL-2.1 file for details.
15 */
16
17/*****************************************************************************/
18#pragma once
19
20#ifdef NDEBUG
21
22#define DO_NOTHING do {} while (0)
23#define ASSERT_ASSERT(x) DO_NOTHING
24#define ASSERT_VALID(c) DO_NOTHING
25#define ASSERT_EQUAL(a,b) DO_NOTHING
26#define ASSERT_NOT_EQUAL(a,b) DO_NOTHING
27#define ASSERT_LOWER_EQ(a,b) DO_NOTHING
28#define ASSERT_GREATER_EQ(a,b) DO_NOTHING
29#define ASSERT_BETWEEN(a,b,c) DO_NOTHING
30#define ASSERT_IPC_OK(i) DO_NOTHING
31#define ASSERT_OK(e) do { (void)e; } while (0)
32#define ASSERT_NOT_NULL(p) DO_NOTHING
33#ifndef assert
34#define assert(cond) DO_NOTHING
35#endif
36
37#else // NDEBUG
38
39#ifndef ASSERT_PRINTF
40#include <stdio.h>
41#define ASSERT_PRINTF printf
42#endif
43#ifndef ASSERT_ASSERT
44#include <assert.h>
45#define ASSERT_ASSERT(x) assert(x)
46#endif
47
48#define ASSERT_VALID(cap) \
49 do { \
50 typeof(cap) _cap = cap; \
51 if (l4_is_invalid_cap(_cap)) { \
52 ASSERT_PRINTF("%s: Cap invalid.\n", __func__); \
53 ASSERT_ASSERT(!l4_is_invalid_cap(_cap)); \
54 } \
55 } while (0)
56
57
58#define ASSERT_EQUAL(a, b) \
59 do { \
60 typeof(a) _a = a; \
61 typeof(b) _b = b; \
62 if (_a != _b) { \
63 ASSERT_PRINTF("%s:\n", __func__); \
64 ASSERT_PRINTF(" "#a" (%lx) != "#b" (%lx)\n", (unsigned long)_a, (unsigned long)_b); \
65 ASSERT_ASSERT(_a == _b); \
66 } \
67 } while (0)
68
69
70#define ASSERT_NOT_EQUAL(a, b) \
71 do { \
72 typeof(a) _a = a; \
73 typeof(b) _b = b; \
74 if (_a == _b) { \
75 ASSERT_PRINTF("%s:\n", __func__); \
76 ASSERT_PRINTF(" "#a" (%lx) == "#b" (%lx)\n", (unsigned long)_a, (unsigned long)_b); \
77 ASSERT_ASSERT(_a != _b); \
78 } \
79 } while (0)
80
81
82#define ASSERT_LOWER_EQ(val, max) \
83 do { \
84 typeof(val) _val = val; \
85 typeof(max) _max = max; \
86 if (_val > _max) { \
87 ASSERT_PRINTF("%s:\n", __func__); \
88 ASSERT_PRINTF(" "#val" (%lx) > "#max" (%lx)\n", (unsigned long)_val, (unsigned long)_max); \
89 ASSERT_ASSERT(_val <= _max); \
90 } \
91 } while (0)
92
93
94#define ASSERT_GREATER_EQ(val, min) \
95 do { \
96 typeof(val) _val = val; \
97 typeof(min) _min = min; \
98 if (_val < _min) { \
99 ASSERT_PRINTF("%s:\n", __func__); \
100 ASSERT_PRINTF(" "#val" (%lx) < "#min" (%lx)\n", (unsigned long)_val, (unsigned long)_min); \
101 ASSERT_ASSERT(_val >= _min); \
102 } \
103 } while (0)
104
105
106#define ASSERT_BETWEEN(val, min, max) \
107 ASSERT_LOWER_EQ((val), (max)); \
108 ASSERT_GREATER_EQ((val), (min));
109
110
111#define ASSERT_IPC_OK(msgtag) \
112 do { \
113 int _r = l4_ipc_error(msgtag, l4_utcb()); \
114 if (_r) { \
115 ASSERT_PRINTF("%s: IPC Error: %lx\n", __func__, _r); \
116 ASSERT_ASSERT(_r == 0); \
117 } \
118 } while (0)
119
120#define ASSERT_OK(val) ASSERT_EQUAL((val), 0)
121#define ASSERT_NOT_NULL(ptr) ASSERT_NOT_EQUAL((ptr), (void *)0)
122
123#endif // NDEBUG
Some useful assert-style macros.