Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Commit

Permalink
[utils] Add ZJS_ASSERT macro to test assertions in debug mode
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
grgustaf committed Sep 7, 2017
1 parent 023a01a commit 50ba1a4
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/zjs_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -104,4 +113,5 @@ int zjs_get_ms(void);
#ifndef TEMP_DEVICE_NAME
#define TEMP_DEVICE_NAME ""
#endif

#endif // __zjs_common_h__

0 comments on commit 50ba1a4

Please sign in to comment.