summaryrefslogtreecommitdiff
path: root/lib/drmtest.c
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2014-02-12 15:19:15 +0100
committerDaniel Vetter <daniel.vetter@ffwll.ch>2014-02-13 14:41:40 +0100
commiteebdf7f9204686f5d937d6a3084056fb86c6e7de (patch)
tree6ef9dd8a801aa80a666bb5859a9596d4c1aaa283 /lib/drmtest.c
parent60a24a22ba4c7df46ebae0e99f0aa09604a6fb25 (diff)
lib: (somewhat) structured logging support
Apparently there's a bit a need for more verbose output in testcases, mostly for debugging purposes. At least gem_reset_stats and pm_rps have a verbose mode. On top of that we're currently not taking advantage of piglit's "warn" state all that much. But I think it might be useful for testcases which are notorious for some kinds of spurious failures, like e.g. the really nasty timing checks in kms_flip. If we demote some of them to just warnings we could run the overall tests more often. Hence this patchs adds a new igt_log function with the three levels DEBUG, INFO and WARN. Plus a bunch of convenience helpers to keep the test code tidy. The level can be set through an enviroment vairable IGT_LOG_LEVEL with info being the default. Also tests can look at the selected log level in case they want to run costly debug functions only when needed. Comments highly welcome, I plan to roll this out over tests which can use it (not all, imo that's too much churn) once we've settled on the interfaces/semantics. Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'lib/drmtest.c')
-rw-r--r--lib/drmtest.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/drmtest.c b/lib/drmtest.c
index 46227c35..9f6e701f 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -937,6 +937,25 @@ out:
return ret;
}
+enum igt_log_level igt_log_level = IGT_LOG_INFO;
+
+static void common_init(void)
+{
+ char *env = getenv("IGT_LOG_LEVEL");
+
+ if (!env)
+ return;
+
+ if (strcmp(env, "debug") == 0)
+ igt_log_level = IGT_LOG_DEBUG;
+ else if (strcmp(env, "info") == 0)
+ igt_log_level = IGT_LOG_INFO;
+ else if (strcmp(env, "warn") == 0)
+ igt_log_level = IGT_LOG_WARN;
+ else if (strcmp(env, "none") == 0)
+ igt_log_level = IGT_LOG_NONE;
+}
+
void igt_subtest_init(int argc, char **argv)
{
int ret;
@@ -951,11 +970,15 @@ void igt_subtest_init(int argc, char **argv)
/* reset opt parsing */
optind = 1;
+
+ common_init();
}
void igt_simple_init(void)
{
print_version();
+
+ common_init();
}
/*
@@ -1387,6 +1410,24 @@ void igt_skip_on_simulation(void)
igt_require(!igt_run_in_simulation());
}
+void igt_log(enum igt_log_level level, const char *format, ...)
+{
+ va_list args;
+
+ assert(format);
+
+ if (igt_log_level > level)
+ return;
+
+ va_start(args, format);
+ if (level == IGT_LOG_WARN) {
+ fflush(stdout);
+ vfprintf(stderr, format, args);
+ } else
+ vprintf(format, args);
+ va_end(args);
+}
+
bool drmtest_dump_aub(void)
{
static int dump_aub = -1;