Re: [PATCH 1/2] kselftest: make ksft_* output functions variadic

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06/27/2017 11:29 AM, Paul Elder wrote:
> Make the ksft_* output functions variadic to allow string formatting
> directly in these functions.
> 
> Signed-off-by: Paul Elder <paul.elder@xxxxxxxx>
> ---
>  tools/testing/selftests/kselftest.h | 58 ++++++++++++++++++++++++++++++-------
>  1 file changed, 47 insertions(+), 11 deletions(-)
> 
> diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
> index be01f2d15472..b156e601f478 100644
> --- a/tools/testing/selftests/kselftest.h
> +++ b/tools/testing/selftests/kselftest.h
> @@ -12,6 +12,7 @@
>  
>  #include <stdlib.h>
>  #include <unistd.h>
> +#include <stdarg.h>
>  
>  /* define kselftest exit codes */
>  #define KSFT_PASS  0
> @@ -54,22 +55,43 @@ static inline void ksft_print_cnts(void)
>  	printf("1..%d\n", ksft_test_num());
>  }
>  
> -static inline void ksft_test_result_pass(const char *msg)
> +static inline void ksft_test_result_pass(const char *msg, ...)
>  {
> +	va_list args;
> +
>  	ksft_cnt.ksft_pass++;
> -	printf("ok %d %s\n", ksft_test_num(), msg);
> +
> +	va_start(args, msg);
> +	printf("ok %d ", ksft_test_num());
> +	vprintf(msg, args);
> +	printf("\n");

Same comment on newline from 2/2 patch. Applies to all newlines in this
patch.
My concern with appending newline here is that we will end up with two.
Users will have to know to not add the newline - it is a general practice
to add it, so users will have to remember to not add it.

> +	va_end(args);
>  }
>  
> -static inline void ksft_test_result_fail(const char *msg)
> +static inline void ksft_test_result_fail(const char *msg, ...)
>  {
> +	va_list args;
> +
>  	ksft_cnt.ksft_fail++;
> -	printf("not ok %d %s\n", ksft_test_num(), msg);
> +
> +	va_start(args, msg);
> +	printf("not ok %d ", ksft_test_num());
> +	vprintf(msg, args);
> +	printf("\n");
> +	va_end(args);
>  }
>  
>  static inline void ksft_test_result_skip(const char *msg)
>  {
> +	va_list args;
> +
>  	ksft_cnt.ksft_xskip++;
> -	printf("ok %d # skip %s\n", ksft_test_num(), msg);
> +
> +	va_start(args, msg);
> +	printf("ok %d # skip ", ksft_test_num());
> +	vprintf(msg, args);
> +	printf("\n");
> +	va_end(args);
>  }
>  
>  static inline int ksft_exit_pass(void)
> @@ -85,9 +107,16 @@ static inline int ksft_exit_fail(void)
>  	exit(KSFT_FAIL);
>  }
>  
> -static inline int ksft_exit_fail_msg(const char *msg)
> +static inline int ksft_exit_fail_msg(const char *msg, ...)
>  {
> -	printf("Bail out! %s\n", msg);
> +	va_list args;
> +
> +	va_start(args, msg);
> +	printf("Bail out! ");
> +	vprintf(msg, args);
> +	printf("\n");
> +	va_end(args);
> +
>  	ksft_print_cnts();
>  	exit(KSFT_FAIL);
>  }
> @@ -104,12 +133,19 @@ static inline int ksft_exit_xpass(void)
>  	exit(KSFT_XPASS);
>  }
>  
> -static inline int ksft_exit_skip(const char *msg)
> +static inline int ksft_exit_skip(const char *msg, ...)
>  {
> -	if (msg)
> -		printf("1..%d # Skipped: %s\n", ksft_test_num(), msg);
> -	else
> +	if (msg) {
> +		va_list args;
> +
> +		va_start(args, msg);
> +		printf("1..%d # Skipped: ", ksft_test_num());
> +		vprintf(msg, args);
> +		printf("\n");
> +		va_end(args);
> +	} else {
>  		ksft_print_cnts();
> +	}
>  	exit(KSFT_SKIP);
>  }
>  
> 

thanks,
-- Shuah
--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux