]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
improve clang / cmocka integration
authorMark Andrews <marka@isc.org>
Wed, 20 Feb 2019 00:13:17 +0000 (11:13 +1100)
committerEvan Hunt <each@isc.org>
Tue, 5 Mar 2019 18:42:01 +0000 (10:42 -0800)
(cherry picked from commit cb913177ae744c729717aa29ae54aa8656c9737e)

lib/dns/tests/result_test.c
lib/isc/include/isc/util.h
lib/isc/tests/netaddr_test.c
lib/isc/tests/result_test.c
lib/isccc/tests/result_test.c

index 14d583f2ec501c3376c0b4683cda6c98ce2a5a4c..517bad381e64a013d897aa419d1fb06cea5ad716 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <stdarg.h>
 #include <stddef.h>
+#include <stdlib.h>
 #include <setjmp.h>
 #include <string.h>
 
index ed55e057271ed091bfd83a34c47939f347073494..b16b024e74ceec1c6e53b3a2ea9e8f3d63618257 100644 (file)
 #ifdef UNIT_TESTING
 extern void mock_assert(const int result, const char* const expression,
                        const char * const file, const int line);
+/*
+ *     Allow clang to determine that the following code is not reached
+ *     by calling abort() if the condition fails.  The abort() will
+ *     never be executed as mock_assert() and _assert_true() longjmp
+ *     or exit if the condition is false.
+ */
 #define REQUIRE(expression)                                            \
-       mock_assert((int)(expression), #expression, __FILE__, __LINE__)
+       ((!(expression)) ?                                              \
+       (mock_assert(0, #expression, __FILE__, __LINE__), abort()) : (void)0)
 #define ENSURE(expression)                                             \
-       mock_assert((int)(expression), #expression, __FILE__, __LINE__)
+       ((!(int)(expression)) ?                                         \
+       (mock_assert(0, #expression, __FILE__, __LINE__), abort()) : (void)0)
 #define INSIST(expression)                                             \
-       mock_assert((int)(expression), #expression, __FILE__, __LINE__)
+       ((!(expression)) ?                                              \
+       (mock_assert(0, #expression, __FILE__, __LINE__), abort()) : (void)0)
 #define INVARIANT(expression)                                          \
-       mock_assert((int)(expression), #expression, __FILE__, __LINE__)
-
+       ((!(expression)) ?                                              \
+       (mock_assert(0, #expression, __FILE__, __LINE__), abort()) : (void)0)
+#define _assert_true(c, e, f, l) \
+       ((c) ? (void)0 : (_assert_true(0, e, f, l), abort()))
 #else /* UNIT_TESTING */
 /*
  * Assertions
index 875d501e18608c21f76cce8777bde495cc7f1cbf..7b5920b6abdf50dc28e369913ab3af56c0d00b98 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <stdarg.h>
 #include <stddef.h>
+#include <stdlib.h>
 #include <setjmp.h>
 
 #include <stdbool.h>
index 38fe12491f47e95912a7fdf9a031c7c6260ab024..39f972b82c5ddfb08c7ae2f6691a4617364370d3 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <stdarg.h>
 #include <stddef.h>
+#include <stdlib.h>
 #include <setjmp.h>
 #include <string.h>
 
index 1f29d0121d17dade937c0ec7f184108c16e8ce96..a92331423a684bad6858d0340bedda4d1de557e3 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <stdarg.h>
 #include <stddef.h>
+#include <stdlib.h>
 #include <setjmp.h>
 #include <string.h>