[Piglit] [PATCH 1/2] util/log: Add function piglit_logd()
Chad Versace
chad.versace at linux.intel.com
Mon Jun 30 17:11:14 PDT 2014
The function logs a debug message if environment variable
PIGLIT_DEBUG is "1" or "true".
Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
tests/util/piglit-log.c | 37 +++++++++++++++++++++++++++++++++++++
tests/util/piglit-log.h | 6 ++++++
2 files changed, 43 insertions(+)
diff --git a/tests/util/piglit-log.c b/tests/util/piglit-log.c
index 1cf9b10..99d13d3 100644
--- a/tests/util/piglit-log.c
+++ b/tests/util/piglit-log.c
@@ -115,3 +115,40 @@ piglit_logi(const char *fmt, ...)
piglit_log_tagv("info", fmt, ap);
va_end(ap);
}
+
+void
+piglit_logd(const char *fmt, ...)
+{
+ static bool once = true;
+ static bool debug = false;
+ va_list ap;
+
+ if (once) {
+ const char *env;
+
+ once = false;
+ env = getenv("PIGLIT_DEBUG");
+
+ if (env == NULL
+ || streq(env, "")
+ || streq(env, "0")
+ || streq(env, "false")) {
+ debug = false;
+ } else if (streq(env, "1")
+ || streq(env, "true")) {
+ debug = true;
+ } else {
+ piglit_loge("PIGLIT_DEBUG has invalid value: "
+ "%s\n", env);
+ abort();
+ }
+ }
+
+ if (!debug) {
+ return;
+ }
+
+ va_start(ap, fmt);
+ piglit_log_tagv("debug", fmt, ap);
+ va_end(ap);
+}
diff --git a/tests/util/piglit-log.h b/tests/util/piglit-log.h
index d52ccd9..c431ea0 100644
--- a/tests/util/piglit-log.h
+++ b/tests/util/piglit-log.h
@@ -64,6 +64,12 @@ piglit_loge(const char *fmt, ...);
void
piglit_logi(const char *fmt, ...);
+/**
+ * Log a debug message if environment variable PIGLIT_DEBUG is "1" or "true".
+ */
+void
+piglit_logd(const char *fmt, ...);
+
#ifdef __cplusplus
} /* end extern "C" */
#endif
--
2.0.0
More information about the Piglit
mailing list