aboutsummaryrefslogtreecommitdiff
path: root/src/zjs_common.h
diff options
context:
space:
mode:
authorGeoff Gustafson <geoff@linux.intel.com>2017-09-07 15:05:40 -0700
committerGeoff Gustafson <geoff@linux.intel.com>2017-09-08 10:35:50 -0700
commit39a268305de58634a4ccc283efc858338655071b (patch)
treefe23fbc126564d15fa33362f9a57730863a37ace /src/zjs_common.h
parent6d35b0986eb88f736fa57208b4a6e76b055c18e0 (diff)
[utils] Add ZJS_ASSERT macro to test assertions in debug mode
Does nothing in release mode, but in debug mode if an assertion fails it prints a message and hangs to make sure it's noticed. Signed-off-by: Geoff Gustafson <geoff@linux.intel.com>
Diffstat (limited to 'src/zjs_common.h')
-rw-r--r--src/zjs_common.h20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/zjs_common.h b/src/zjs_common.h
index 838673e..dcb43ac 100644
--- a/src/zjs_common.h
+++ b/src/zjs_common.h
@@ -48,15 +48,24 @@ int zjs_get_ms(void);
zjs_shorten_filepath(__FILE__), __LINE__, __func__); \
ZJS_PRINT
-#else
-#define DBG_PRINT(fmat...) \
- do { \
- } while (0);
+#define ZJS_ASSERT(condition, str) \
+ if (!(condition)) { \
+ ERR_PRINT("ASSERTION FAILURE: %s\n", str); \
+ do {} while (1); \
+ }
+
+#else // !DEBUG_BUILD
+
+#define DBG_PRINT(fmt...) do {} while (0);
+
#define ERR_PRINT \
ZJS_PRINT("\n%s:%d %s():\n(ERROR) ", zjs_shorten_filepath(__FILE__), \
__LINE__, __func__); \
ZJS_PRINT
-#endif
+
+#define ZJS_ASSERT(condition, str) do {} while (0);
+
+#endif // DEBUG_BUILD
// TODO: We should instead have a macro that changes in debug vs. release build,
// to save string space and instead print error codes or something for release.
@@ -104,4 +113,5 @@ int zjs_get_ms(void);
#ifndef TEMP_DEVICE_NAME
#define TEMP_DEVICE_NAME ""
#endif
+
#endif // __zjs_common_h__