From ce24c052de30fc19341685a3eb38485b2e9587e8 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 4 Jan 2019 17:46:35 +0200 Subject: libcamera: log: Add an ASSERT macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ASSERT() macro is similar to the assert() macro defined by the C standard, but uses the libcamera logging infrastructure. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Kieran Bingham --- src/libcamera/log.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/libcamera/log.cpp') diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp index a5823c64..6785d371 100644 --- a/src/libcamera/log.cpp +++ b/src/libcamera/log.cpp @@ -48,6 +48,22 @@ namespace libcamera { * terminates immediately after printing the message. */ +/** + * \def ASSERT(condition) + * \brief Abort program execution if assertion fails + * + * If \a condition is false, ASSERT() logs an error message with the Fatal log + * level and aborts program execution. + * + * If the macro NDEBUG is defined before including log.h, ASSERT() generates no + * code. + * + * Using conditions that have side effects with ASSERT() is not recommended, as + * these effects would depend on whether NDEBUG is defined or not. Similarly, + * ASSERT() should not be used to check for errors that can occur under normal + * conditions as those checks would then be removed when compiling with NDEBUG. + */ + static const char *log_severity_name(LogSeverity severity) { static const char * const names[] = { -- cgit v1.2.1