[ovs-dev] [PATCH] datapath-windows: Add macros in Debug.h

Samuel Ghinet sghinet at cloudbasesolutions.com
Wed Aug 6 13:11:11 UTC 2014


Add macros in Debug.h

Checks that:
a) make the code shorter for functions that return BOOLEAN or OVS_ERROR, by hiding the
repetitive work.
b) on debug mode, do ASSERT, while on release mode can do an, e.g. "return X;" instead, for the failure case.
c) by using OVS_CHECK, we can choose via OVS_USE_ASSERTS, if we want asserts enabled or disabled.

Signed-off-by: Samuel Ghinet <sghinet at cloudbasesolutions.com>
---
 datapath-windows/ovsext/Core/Debug.h | 59 ++++++++++++++++++++++++++++++++++++
 datapath-windows/ovsext/precomp.h    |  1 +
 2 files changed, 60 insertions(+)

diff --git a/datapath-windows/ovsext/Core/Debug.h b/datapath-windows/ovsext/Core/Debug.h
index 3705d1e..27a40ca 100644
--- a/datapath-windows/ovsext/Core/Debug.h
+++ b/datapath-windows/ovsext/Core/Debug.h
@@ -69,6 +69,65 @@ VOID OvsLog(UINT32 level, UINT32 flag, CHAR *funcName,
 #define OVS_LOG_WARN(_format, ...) \
    OvsLog(OVS_DBG_WARN, OVS_DBG_MOD, __FUNCTION__, __LINE__, _format, __VA_ARGS__)

+#ifdef DBG
+
+#undef OVS_USE_ASSERTS
+#define OVS_USE_ASSERTS                1
+
+#else
+
+#endif //DBG
+
+//OVS_USE_ASSERTS is not #define-d on release mode
+#if OVS_USE_ASSERTS
+#define OVS_CHECK(x) ASSERT(x)
+#define OVS_CHECK_OR(x, expr) { if (!(x)) { ASSERT(0); expr; } }
+#define OVS_CHECK_BREAK(x) { if (!(x)) { ASSERT(0); break; } }
+#define OVS_CHECK_RET(x, value) { if (!(x)) { ASSERT(0); return value; } }
+#define OVS_CHECK_GC(x) { if (!(x)) { ASSERT(0); goto Cleanup; } }
+#else
+#define OVS_CHECK(x)
+#define OVS_CHECK_OR(x, expr) { if (!(x)) expr; }
+#define OVS_CHECK_BREAK(x) { if (!(x)) break; }
+#define OVS_CHECK_RET(x, value) { if (!(x)) return value; }
+#define OVS_CHECK_GC(x) { if (!(x)) goto Cleanup; }
+#endif //OVS_USE_ASSERTS
+
+//on failure, return FALSE
+#define OVS_EXPECT(expr)    OVS_CHECK_RET(expr, FALSE)
+
+#define OVS_CHECK_E(expr)                       \
+{                                               \
+    error = (expr);                             \
+    if (error != OVS_ERROR_NOERROR)             \
+    {                                           \
+    OVS_CHECK(__UNEXPECTED__);                  \
+    goto Cleanup;                               \
+    }                                           \
+}
+
+//check boolean expr, on failure, set ok = FALSE and goto Cleanup
+#define OVS_CHECK_B(expr)                       \
+{                                               \
+    if (!(expr))                                \
+    {                                           \
+    ok = FALSE;                                 \
+    OVS_CHECK(__UNEXPECTED__);                  \
+    goto Cleanup;                               \
+    }                                           \
+}
+
+//check boolean expr, and use OVS_ERROR
+#define OVS_CHECK_B_E(expr, errorVal)           \
+{                                               \
+    if (!(expr))                                \
+    {                                           \
+    error = errorVal;                           \
+    OVS_CHECK(__UNEXPECTED__);                  \
+    goto Cleanup;                               \
+    }                                           \
+}
+
 #if DBG
 #define OVS_VERIFY_IRQL(_x)  \
     if (KeGetCurrentIrql() != (KIRQL)_x) { \
diff --git a/datapath-windows/ovsext/precomp.h b/datapath-windows/ovsext/precomp.h
index f54df0e..529d7de 100644
--- a/datapath-windows/ovsext/precomp.h
+++ b/datapath-windows/ovsext/precomp.h
@@ -21,6 +21,7 @@
 #include <ntstrsafe.h>
 #include <Strsafe.h>

+#include "Core/Debug.h"
 #include "Core/Types.h"
 #include "Core/Util.h"
 #include "OpenFlow/Pub.h"
--
1.8.3.msysgit.0





More information about the dev mailing list