diff options
author | Chad Versace <chad.versace@linux.intel.com> | 2014-06-30 13:52:25 -0700 |
---|---|---|
committer | Chad Versace <chad.versace@linux.intel.com> | 2014-06-30 18:03:01 -0700 |
commit | 383c69f66bc48a3bc07e8de4c29a3f08c8f0214c (patch) | |
tree | 8b9ce19df66b54068ac6224c68f3cd59e8ce5dd2 | |
parent | c9bd3185bd026fa3534d5dbac85dd3670ce32500 (diff) |
util/log: Add function piglit_logd()
The function logs a debug message if environment variable
PIGLIT_DEBUG is "1" or "true".
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
-rw-r--r-- | tests/util/piglit-log.c | 37 | ||||
-rw-r--r-- | tests/util/piglit-log.h | 6 |
2 files changed, 43 insertions, 0 deletions
diff --git a/tests/util/piglit-log.c b/tests/util/piglit-log.c index 1cf9b10dd..99d13d360 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 d52ccd935..c431ea06b 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 |