summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLyude <lyude@redhat.com>2017-02-07 12:50:47 -0500
committerLyude <lyude@redhat.com>2017-02-07 15:43:25 -0500
commitbcd7ed6142a497c979862bc3c67fed52ef966c3d (patch)
tree285d665a236a1d35a0ba6cd0507aec3963ec63fa /lib
parentf63e070b469d96be2bf470eae63a16b4a9e9cc0d (diff)
igt/core: Return condition result from igt_warn_on*()
This allows us to be a little more flexible with how we use igt_warn_on() and igt_warn_on_f() by allowing us to write statements like this: if (igt_warn_on(scary_condition)) { /* some error handling... */ } Signed-off-by: Lyude <lyude@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/igt_core.h25
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/igt_core.h b/lib/igt_core.h
index b669de3e..51b98d82 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -828,12 +828,16 @@ extern enum igt_log_level igt_log_level;
* Should be used everywhere where a test checks results to decide about
* printing warnings. This is useful to streamline the test logic since it
* allows for a more flat code control flow, similar to igt_assert()
+ *
+ * This macro also returns the value of @condition.
*/
-#define igt_warn_on(condition) do {\
- if (condition) \
- igt_warn("Warning on condition %s in fucntion %s, file %s:%i\n", \
+#define igt_warn_on(condition) ({ \
+ typeof(condition) ret__ = (condition); \
+ if (ret__) \
+ igt_warn("Warning on condition %s in function %s, file %s:%i\n", \
#condition, __func__, __FILE__, __LINE__); \
- } while (0)
+ ret__; \
+ })
/**
* igt_warn_on_f:
@@ -850,15 +854,18 @@ extern enum igt_log_level igt_log_level;
*
* In addition to the plain igt_warn_on_f() helper this allows to print
* additional information (again as warnings) to help debugging test failures.
+ *
+ * It also returns the value of @condition.
*/
-#define igt_warn_on_f(condition, f...) do {\
- if (condition) {\
- igt_warn("Warning on condition %s in fucntion %s, file %s:%i\n", \
+#define igt_warn_on_f(condition, f...) ({ \
+ typeof(condition) ret__ = (condition); \
+ if (ret__) {\
+ igt_warn("Warning on condition %s in function %s, file %s:%i\n", \
#condition, __func__, __FILE__, __LINE__); \
igt_warn(f); \
} \
- } while (0)
-
+ ret__; \
+ })
void igt_set_timeout(unsigned int seconds,
const char *op);