Module: xenomai-3
Branch: master
Commit: 1acbab8e1d89063e4ff2bac52b9b62e9eef7d209
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=1acbab8e1d89063e4ff2bac52b9b62e9eef7d209

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sat Jun 20 10:45:21 2015 +0200

lib/smokey: add warning and assertion helpers

---

 include/smokey/smokey.h |   23 +++++++++++++++++++++++
 lib/smokey/helpers.c    |   15 +++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/include/smokey/smokey.h b/include/smokey/smokey.h
index e759806..d8aa9d8 100644
--- a/include/smokey/smokey.h
+++ b/include/smokey/smokey.h
@@ -97,6 +97,26 @@ struct smokey_test {
 #define SMOKEY_ARG_BOOL(__plugin, __arg)   (!!SMOKEY_ARG_INT(__plugin, __arg))
 #define SMOKEY_ARG_STRING(__plugin, __arg) (SMOKEY_ARG(__plugin, 
__arg)->u.s_val)
 
+#define smokey_check_errno(__expr)                                     \
+       ({                                                              \
+               int __ret = (__expr);                                   \
+               if (__ret < 0) {                                        \
+                       __ret = -errno;                                 \
+                       smokey_warning(__FILE__, __LINE__, "%s: %s\n",  \
+                                      #__expr, strerror(errno));       \
+               }                                                       \
+               __ret;                                                  \
+       })
+
+#define smokey_assert(__expr)                                          \
+       ({                                                              \
+               int __ret = (__expr);                                   \
+               if (!__ret)                                             \
+                       smokey_warning(__FILE__, __LINE__,              \
+                                      "assertion failed: %s\n", #__expr); \
+               __ret;                                                  \
+       })
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -117,6 +137,9 @@ int smokey_parse_args(struct smokey_test *t,
 
 void smokey_note(const char *fmt, ...);
 
+void smokey_warning(const char *file, int lineno,
+                   const char *fmt, ...);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/smokey/helpers.c b/lib/smokey/helpers.c
index 21b0084..53ff879 100644
--- a/lib/smokey/helpers.c
+++ b/lib/smokey/helpers.c
@@ -129,3 +129,18 @@ void smokey_note(const char *fmt, ...)
 
        va_end(ap);
 }
+
+void smokey_warning(const char *file, int lineno,
+                   const char *fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+
+       if (smokey_verbose_mode) {
+               __RT(fprintf(stderr, "%s:%d, ", basename(file), lineno));
+               __RT(vfprintf(stderr, fmt, ap));
+       }
+
+       va_end(ap);
+}


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to