improve clang / cmocka integration

(cherry picked from commit cb913177ae)
This commit is contained in:
Mark Andrews 2019-02-20 11:13:17 +11:00 committed by Evan Hunt
parent ae383b7b52
commit 2671666ef8
7 changed files with 22 additions and 5 deletions

View file

@ -15,6 +15,7 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <setjmp.h>
#include <string.h>

View file

@ -220,15 +220,26 @@
#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

View file

@ -16,6 +16,7 @@
#include <errno.h>
#include <stdio.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <isc/net.h>

View file

@ -16,6 +16,7 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
#define UNIT_TESTING

View file

@ -15,6 +15,7 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <setjmp.h>
#include <stdbool.h>

View file

@ -15,6 +15,7 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <setjmp.h>
#include <string.h>

View file

@ -15,6 +15,7 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <setjmp.h>
#include <string.h>