summaryrefslogtreecommitdiff
path: root/lib/drmtest.c
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2013-09-19 16:37:07 +0200
committerDaniel Vetter <daniel.vetter@ffwll.ch>2013-09-19 19:40:32 +0200
commite5cdd62624342180a16630b4f6b1d604f6e6e581 (patch)
tree71edb7e9e1853e4c3edcc22d16c066c0d5609a61 /lib/drmtest.c
parentb3525129535c6e8e3588f63960e2296d598f6e9a (diff)
lib/drmtest: igt_assert|require with format strings
v2: Add a comment about the pitfalls around va_list handling. Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'lib/drmtest.c')
-rw-r--r--lib/drmtest.c43
1 files changed, 38 insertions, 5 deletions
diff --git a/lib/drmtest.c b/lib/drmtest.c
index 3d89047a..7c3c0af7 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -876,11 +876,34 @@ void igt_skip(const char *f, ...)
}
void __igt_skip_check(const char *file, const int line,
- const char *func, const char *check)
+ const char *func, const char *check,
+ const char *f, ...)
{
- igt_skip("Test requirement not met in function %s, file %s:%i:\n"
- "Test requirement: (%s)\n",
- func, file, line, check);
+ va_list args;
+
+ if (f) {
+ char buf[4096];
+ int length;
+
+ /*
+ * Important: va_list argument lists can't be used twice, so we
+ * can't first do an vsnprintf call to size the temporary
+ * storage correctly. Pick the easy solution with a static
+ * buffer and an asssert.
+ */
+ va_start(args, f);
+ length = vsnprintf(buf, sizeof(buf), f, args);
+ assert(length < sizeof(buf) - 1);
+ va_end(args);
+
+ igt_skip("Test requirement not met in function %s, file %s:%i:\n"
+ "Test requirement: (%s)\n%s",
+ func, file, line, check, buf);
+ } else {
+ igt_skip("Test requirement not met in function %s, file %s:%i:\n"
+ "Test requirement: (%s)\n",
+ func, file, line, check);
+ }
}
void igt_success(void)
@@ -927,11 +950,21 @@ static bool run_under_gdb(void)
}
void __igt_fail_assert(int exitcode, const char *file,
- const int line, const char *func, const char *assertion)
+ const int line, const char *func, const char *assertion,
+ const char *f, ...)
{
+ va_list args;
+
printf("Test assertion failure function %s, file %s:%i:\n"
"Failed assertion: %s\n",
func, file, line, assertion);
+
+ if (f) {
+ va_start(args, f);
+ vprintf(f, args);
+ va_end(args);
+ }
+
if (run_under_gdb())
abort();
igt_fail(exitcode);