diff options
author | Simon Glass <sjg@chromium.org> | 2011-06-16 13:11:41 -0700 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2011-08-29 10:39:31 -0700 |
commit | fea2a094904aa9fd76ae423339927dcd2e058049 (patch) | |
tree | d99fb80e4567509f238fe67d66694f03be58ca42 /include/common.h | |
parent | 84d9e903f1b6d9c48e3615fd4bb5b2eee3ff79a4 (diff) |
Add assert() for debug assertions
assert() is like BUG_ON() but compiles to nothing unless DEBUG is defined.
This is useful when a condition is an error but a board reset is unlikely
to fix it, so it is better to soldier on in hope. Assertion failures should
be caught during development/test.
It turns out that assert() is defined separately in a few places in U-Boot
with various meanings.
Build errors exposed by this change (and defining DEBUG) are also fixed in
this commit.
BUG=chromium-os:11623
TEST=build U-Boot for seaboard
Change-Id: I27500491d2328405694bfd65ab991d42d9641927
Reviewed-on: http://gerrit.chromium.org/gerrit/2777
Tested-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Anton Staaf <robotboy@chromium.org>
Diffstat (limited to 'include/common.h')
-rw-r--r-- | include/common.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/include/common.h b/include/common.h index 934c007c35..c037b36191 100644 --- a/include/common.h +++ b/include/common.h @@ -119,9 +119,22 @@ typedef volatile unsigned char vu_char; #ifdef DEBUG #define debug(fmt,args...) printf (fmt ,##args) #define debugX(level,fmt,args...) if (DEBUG>=level) printf(fmt,##args); + +/* + * An assertion is run-time check done in debug mode only. If DEBUG is not + * defined then it is skipped. It does not BUG or halt U-Boot, but tries to + * continue execution in any case. It is hoped that all failing assertions + * are found before release, and after release it is hoped that they don't + * matter, but in any case cannot be fixed with a reset (which will just do + * the same again). + */ +#define assert(x) \ + ({ if (!(x)) printf("Assertion failure '%s' %s line %d\n", \ + #x, __FILE__, __LINE__); }) #else #define debug(fmt,args...) #define debugX(level,fmt,args...) +#define assert(x) #endif /* DEBUG */ #define error(fmt, args...) do { \ |