Phoenix
Object-oriented orthogonally persistent operating system
|
00001 /* 00002 * /phoenix/include/debug.h 00003 * 00004 * This file is a part of Phoenix operating system. 00005 * Copyright (c) 2011-2012, Artyom Lebedev <artyom.lebedev@gmail.com> 00006 * All rights reserved. 00007 * See COPYING file for copyright details. 00008 */ 00009 00010 #ifndef DEBUG_H_ 00011 #define DEBUG_H_ 00012 00016 namespace {} 00017 00018 #define _ASSERT(x) do { \ 00019 if (UNLIKELY(!(x))) { \ 00020 FAULT("Assertion failed: '%s'", __STR(x)); \ 00021 } \ 00022 } while (false) 00023 00032 #ifdef DEBUG 00033 #define ASSERT(x) _ASSERT(x) 00034 #else /* DEBUG */ 00035 #define ASSERT(x) 00036 #endif /* DEBUG */ 00037 00044 #define ENSURE(x) _ASSERT(x) 00045 00049 #define NOT_REACHED() FAULT("Unreachable code reached") 00050 00054 #define FAULT(msg, ...) __Fault(__FILE__, __LINE__, msg, ## __VA_ARGS__) 00055 00064 void __Fault(const char *file, int line, const char *msg, ...) 00065 __FORMAT(printf, 3, 4) __NORETURN; 00066 00067 #ifdef MODULE_TESTS 00068 00074 #define MODULE_TEST(funcName, ...) do { \ 00075 if (!funcName(__VA_ARGS__)) { \ 00076 FAULT("Module test failed: " __STR(funcName)); \ 00077 } \ 00078 } while (false) 00079 00080 #else /* MODULE_TESTS */ 00081 00082 #define MODULE_TEST(funcName, ...) 00083 00084 #endif /* MODULE_TESTS */ 00085 00086 #endif /* DEBUG_H_ */