aboutsummaryrefslogtreecommitdiff
path: root/helper
diff options
context:
space:
mode:
authorPetri Savolainen <petri.savolainen@nokia.com>2019-08-16 17:25:26 +0300
committerPetri Savolainen <petri.savolainen@nokia.com>2019-08-20 14:33:59 +0300
commitca17284c6b3990d30c78900c9968d88feabe02fa (patch)
tree21dd3f5b78151916f375e04c698c17a2e0b93c81 /helper
parenta891fc391967841e472d06437fa613a64ad3b08a (diff)
helper: debug: add ODPH_ASSERT macro
Added assert macro to be used by test applications. Signed-off-by: Petri Savolainen <petri.savolainen@nokia.com> Reviewed-by: Matias Elo <matias.elo@nokia.com>
Diffstat (limited to 'helper')
-rw-r--r--helper/include/odph_debug.h28
1 files changed, 23 insertions, 5 deletions
diff --git a/helper/include/odph_debug.h b/helper/include/odph_debug.h
index d08918be0..c99936f4b 100644
--- a/helper/include/odph_debug.h
+++ b/helper/include/odph_debug.h
@@ -1,16 +1,19 @@
/* Copyright (c) 2015-2018, Linaro Limited
+ * Copyright (c) 2019, Nokia
+ *
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
+
/**
* @file
*
- * HELPER debug
+ * Helper debug
*/
-#ifndef HELPER_DEBUG_H_
-#define HELPER_DEBUG_H_
+#ifndef ODPH_DEBUG_H_
+#define ODPH_DEBUG_H_
#include <stdio.h>
#include <stdlib.h>
@@ -20,13 +23,28 @@ extern "C" {
#endif
/**
+ * Assert macro for applications and helper code
+ *
+ * No code is generated when ODPH_DEBUG=0. Prints error message and aborts when
+ * ODPH_DEBUG=1 and 'cond' is false.
+ */
+#define ODPH_ASSERT(cond) \
+ do { \
+ if ((ODPH_DEBUG == 1) && (!(cond))) { \
+ fprintf(stderr, "%s:%d:%s(): %s\n", __FILE__, __LINE__,\
+ __func__, #cond); \
+ abort(); \
+ } \
+ } while (0)
+
+/**
* log level.
*/
-typedef enum HELPER_log_level {
+typedef enum odph_log_level {
ODPH_LOG_DBG,
ODPH_LOG_ERR,
ODPH_LOG_ABORT
-} HELPER_log_level_e;
+} odph_log_level_e;
/**
* default LOG macro.