summaryrefslogtreecommitdiff
path: root/lib/igt_core.h
diff options
context:
space:
mode:
authorJanusz Krzysztofik <janusz.krzysztofik@linux.intel.com>2021-07-22 19:15:39 +0200
committerJanusz Krzysztofik <janusz.krzysztofik@linux.intel.com>2021-08-10 11:52:57 +0200
commit022a2d326229d66f196ab0d68a02a81c74e72299 (patch)
treead84bd4c1b7f4f10b93fb64719bc573a070c5b7d /lib/igt_core.h
parent7ed112d82c228e755fa773253a25f407bb20965b (diff)
lib/core: Add igt_debug_on* variants
If a test calls a function which can return a failure, only the fact that the function failed can be reported to the caller, with no details on what actually failed inside. It could be helpful if functions which perform several steps or iterations emitted debug messages with failure details. To simplify coding and avoid code duplication in functions, igt_debug variants similar to igt_warn_on and friends could be useful. Add them. Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com> Acked-by: Petri Latvala <petri.latvala@intel.com>
Diffstat (limited to 'lib/igt_core.h')
-rw-r--r--lib/igt_core.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/igt_core.h b/lib/igt_core.h
index 6075d153..8d433fc1 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -1274,6 +1274,58 @@ extern enum igt_log_level igt_log_level;
ret__; \
})
+/**
+ * igt_debug_on:
+ * @condition: condition to test
+ *
+ * Print a IGT_LOG_DEBUG level message if a condition is met.
+ *
+ * Should be used when something fails in a function that doesn't perform
+ * a long jump in that case, and either performs several operations that
+ * can fail that way or doesn't return unambiguous error codes on failures.
+ * This is useful to streamline the test logic since it allows for
+ * replacing open conding with function calls without loosing ability to
+ * provide debug output with failure details.
+ *
+ * This macro also returns the value of @condition.
+ */
+#define igt_debug_on(condition) ({ \
+ typeof(condition) ret__ = (condition); \
+ if (ret__) \
+ igt_debug("Condition %s occurred in function %s, file %s:%i\n", \
+ #condition, __func__, __FILE__, __LINE__); \
+ ret__; \
+ })
+
+/**
+ * igt_debug_on_f:
+ * @condition: condition to test
+ * @...: format string and optional arguments
+ *
+ * Print a IGT_LOG_DEBUG level message if a condition is met.
+ *
+ * Should be used when something fails in a function that doesn't perform
+ * a long jump in that case, and performs one or more operations in a
+ * loop, each time with different values of parameters. This is useful
+ * to streamline the test logic since it allows for replacing open conding
+ * with function calls without loosing ability to provide debug output
+ * with failure details.
+ *
+ * In addition to the plain igt_debug_on() helper this allows to print
+ * additional debug information to help debugging operation failures.
+ *
+ * It also returns the value of @condition.
+ */
+#define igt_debug_on_f(condition, f...) ({ \
+ typeof(condition) ret__ = (condition); \
+ if (ret__) {\
+ igt_debug("condition %s occurred in function %s, file %s:%i\n", \
+ #condition, __func__, __FILE__, __LINE__); \
+ igt_debug(f); \
+ } \
+ ret__; \
+ })
+
void igt_set_timeout(unsigned int seconds,
const char *op);