[RFC 14/19] ktf: Internal debugging facilities

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Utilities for convenient and runtime enabled/disabled
printk debugging mainly intended for debugging ktf itself and subtle
early issues with execution/running of tests.

ktf_debug.h:     User mode debug function definitions

Signed-off-by: Knut Omang <knut.omang@xxxxxxxxxx>
---
 tools/testing/selftests/ktf/lib/ktf_debug.cc | 20 +++++++-
 tools/testing/selftests/ktf/lib/ktf_debug.h  | 59 +++++++++++++++++++++-
 2 files changed, 79 insertions(+)
 create mode 100644 tools/testing/selftests/ktf/lib/ktf_debug.cc
 create mode 100644 tools/testing/selftests/ktf/lib/ktf_debug.h

diff --git a/tools/testing/selftests/ktf/lib/ktf_debug.cc b/tools/testing/selftests/ktf/lib/ktf_debug.cc
new file mode 100644
index 0000000..18ff443
--- /dev/null
+++ b/tools/testing/selftests/ktf/lib/ktf_debug.cc
@@ -0,0 +1,20 @@
+/* Copyright (c) 2012 Oracle Corporation. All rights reserved
+ *
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
+#include "ktf_debug.h"
+#include <stdlib.h>
+
+unsigned long ktf_debug_mask = 0;
+
+
+void ktf_debug_init()
+{
+  ktf_debug_mask = 0;
+  char* dbg_mask_str = getenv("KTF_DEBUG_MASK");
+  if (dbg_mask_str) {
+    ktf_debug_mask = strtol(dbg_mask_str, NULL, 0);
+    log(KTF_INFO_V, "debug mask set to 0x%lx\n", ktf_debug_mask);
+  }
+}
diff --git a/tools/testing/selftests/ktf/lib/ktf_debug.h b/tools/testing/selftests/ktf/lib/ktf_debug.h
new file mode 100644
index 0000000..dc761a4
--- /dev/null
+++ b/tools/testing/selftests/ktf/lib/ktf_debug.h
@@ -0,0 +1,59 @@
+/* Copyright (c) 2012 Oracle Corporation. All rights reserved
+ *    Author: Knut Omang <knut.omang@xxxxxxxxxx>
+ *
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ * ktf_debug.h: User mode debug function definitions
+ * - intended for test debugging.
+ *
+ * Enabled by setting bits in the environment variable KTF_DEBUG_MASK
+ */
+
+#ifndef _KTF_DEBUG_H
+#define _KTF_DEBUG_H
+#include <time.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+
+extern unsigned long ktf_debug_mask;
+
+
+#define KTF_ERR             0x1
+#define KTF_WARN            0x2
+#define KTF_INFO            0x4
+#define KTF_INFO_V        0x100
+#define KTF_MR           0x2000
+#define KTF_DEBUG       0x10000
+#define KTF_POLL        0x20000
+#define KTF_EVENT       0x40000
+#define KTF_DEBUG_V   0x1000000
+#define KTF_DUMP      0x2000000
+
+/* Call this to initialize the debug logic from
+ * environment KTF_DEBUG_MASK
+ */
+void ktf_debug_init();
+
+#define log(level, format, arg...)		\
+do {\
+  if (level & ktf_debug_mask) {\
+    char _tm[30]; \
+    time_t _tv = time(NULL);\
+    ctime_r(&_tv,_tm);\
+    _tm[24] = '\0';\
+    fprintf(stderr, "%s [%ld] %s: " format, \
+            _tm, (long unsigned int) pthread_self(), __func__, ## arg);     \
+  }\
+} while (0)
+
+#define logs(class, stmt_list) \
+  do {							    \
+    if (ktf_debug_mask & class) { \
+      stmt_list;  \
+    }   \
+  } while (0)
+
+#endif
-- 
git-series 0.9.1



[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux