aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Bramley <jacob.bramley@arm.com>2017-04-10 17:40:20 +0100
committerJacob Bramley <jacob.bramley@arm.com>2017-04-11 08:50:34 +0000
commit8e2049ccc3ab27d51eb54572d0b2874a95ff8c92 (patch)
tree89f57da6729262eb06d4e0d8ffdfc08c0f78f2be
parent5370ffe7b2a8a84052dde6ce5b9cc8d8d6b66a6f (diff)
Fix VIXL_ASSERT in negative testing mode.
The actual fix is to define `VIXL_ASSERT` in terms of `VIXL_CHECK` (rather than `assert`). After this change, I also had to fix `VIXL_CHECK` to avoid problems with conditions that look like printf placeholders. I also added a negative test to check that VIXL_ASSERT throws as it should (in debug mode). Change-Id: I1f2b9bb9f86f5549ede910986b64cedad6d78de3
-rw-r--r--src/globals-vixl.h19
-rw-r--r--test/test-aborts.cc1
2 files changed, 11 insertions, 9 deletions
diff --git a/src/globals-vixl.h b/src/globals-vixl.h
index 5474a431..beada9eb 100644
--- a/src/globals-vixl.h
+++ b/src/globals-vixl.h
@@ -116,19 +116,20 @@ const int kBitsPerByte = 8;
printf("%sin %s, line %i\n", (msg), __FILE__, __LINE__); \
abort(); \
} while (false)
-#define VIXL_CHECK(condition) \
- do { \
- if (!(condition)) { \
- printf("Assertion failed (" #condition ")\nin %s, line %i\n", \
- __FILE__, \
- __LINE__); \
- abort(); \
- } \
+#define VIXL_CHECK(condition) \
+ do { \
+ if (!(condition)) { \
+ printf("Assertion failed (%s)\nin %s, line %i\n", \
+ #condition, \
+ __FILE__, \
+ __LINE__); \
+ abort(); \
+ } \
} while (false)
#define VIXL_THROW_IN_NEGATIVE_TESTING_MODE(error)
#endif
#ifdef VIXL_DEBUG
-#define VIXL_ASSERT(condition) assert(condition)
+#define VIXL_ASSERT(condition) VIXL_CHECK(condition)
#define VIXL_UNIMPLEMENTED() \
do { \
VIXL_ABORT_WITH_MSG("UNIMPLEMENTED "); \
diff --git a/test/test-aborts.cc b/test/test-aborts.cc
index e0c39cfc..e02fa11f 100644
--- a/test/test-aborts.cc
+++ b/test/test-aborts.cc
@@ -63,6 +63,7 @@ TEST(check_expression, VIXL_CHECK(1 == 2), "Assertion failed (1 == 2)\nin ")
#ifdef VIXL_DEBUG
TEST(unimplemented, VIXL_UNIMPLEMENTED(), "UNIMPLEMENTED in ")
TEST(unreachable, VIXL_UNREACHABLE(), "UNREACHABLE in ")
+TEST(assert, VIXL_ASSERT(false), "Assertion failed (false)\nin ")
#endif
} // namespace vixl