[igt-dev] [RFC PATCH i-g-t 1/2] lib/core: Add igt_debug_on* variants

Petri Latvala petri.latvala at intel.com
Tue Aug 10 08:44:43 UTC 2021


On Mon, Aug 09, 2021 at 09:10:19PM +0200, Janusz Krzysztofik wrote:
> 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 at linux.intel.com>


This looks lovely.

Only thing I didn't like was that one double negative if statement
with if (!igt_debug_on(!cond)) but meh...

Series is

Acked-by: Petri Latvala <petri.latvala at intel.com>


> ---
>  lib/igt_core.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 52 insertions(+)
> 
> diff --git a/lib/igt_core.h b/lib/igt_core.h
> index 6075d1539..8d433fc16 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);
>  
> -- 
> 2.25.1
> 


More information about the igt-dev mailing list