]> 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 19:04:46 +0000 (11:04 -0800)
(cherry picked from commit cb913177ae744c729717aa29ae54aa8656c9737e)

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

index c78b7e5420d719cd40c75a97d97d1b674ef702e2..3137fbfc4bb9700523d2455ed47b2a6eddf8bc11 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <stdarg.h>
 #include <stddef.h>
+#include <stdlib.h>
 #include <setjmp.h>
 #include <string.h>
 
index 61ebb9190ab0ac1da0d1a785277910f864118b14..f358dbf4f3803e6bda9bb348f4d8f945704bdad2 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 fb06f850fd6c5f7ca0d0898a2f1c5557e7c1b6a7..60280c43eab3a6c23bd099321c086c57a5598edc 100644 (file)
@@ -16,6 +16,7 @@
 #include <errno.h>
 #include <stdio.h>
 #include <inttypes.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include <isc/net.h>
index d2959055dfedd4ee5c1f172567ebf0e3f0f4ab2e..baf99a0932088cc7a2d3a95c47216319c25ca743 100644 (file)
@@ -16,6 +16,7 @@
 #include <stdarg.h>
 #include <stddef.h>
 #include <setjmp.h>
+#include <stdlib.h>
 #include <string.h>
 
 #define UNIT_TESTING
index 8465ca0880fabd657081462e13252afbd32e2bd6..b8e9d13e729f56a7c6fb669986963129b2131242 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <stdarg.h>
 #include <stddef.h>
+#include <stdlib.h>
 #include <setjmp.h>
 
 #include <stdbool.h>
index ea6dc7114263a35ab5e70eabd2b51c17360796dc..ff2a7b264cc558582c7fde82480bc07fdb821750 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <stdarg.h>
 #include <stddef.h>
+#include <stdlib.h>
 #include <setjmp.h>
 #include <string.h>
 
index 1eae03ef721d72beb5efe319e10eaef4583ea85d..c0e70f740345f047f584fa4ee1fd0b40eee4016c 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <stdarg.h>
 #include <stddef.h>
+#include <stdlib.h>
 #include <setjmp.h>
 #include <string.h>