Re: [PATCH v5 1/7] tst_kvercmp: Factor out error handling

Cyril Hrubis <[email protected]>
Newsgroups gmane.linux.ltp
Message-ID <[email protected]>
Hi!
> -int tst_parse_kver(const char *str_kver, int *v1, int *v2, int *v3)
> +static int tst_parse_kver_(const char *str_kver, int *v1, int *v2, int *v3)
>  {
>  	const char *str = str_kver;
>  
> @@ -81,17 +81,28 @@ int tst_parse_kver(const char *str_kver, int *v1, int *v2, int *v3)
>  	return 0;
>  }

As I said this is changed into static function hence the tst_ prefix
should be dropped.

> -int tst_kvcmp(const char *cur_kver, int r1, int r2, int r3)
> +int tst_parse_kver(const char *str_kver, int *v1, int *v2, int *v3)
>  {
> -	int a1, a2, a3;
> -	int testver, currver;
> +	int rc;
> +
> +	rc = tst_parse_kver_(str_kver, v1, v2, v3);
>  
> -	if (tst_parse_kver(cur_kver, &a1, &a2, &a3)) {
> +	if (rc) {
>  		tst_resm(TWARN,
>  			 "Invalid kernel version %s, expected %%d.%%d.%%d",
> -		         cur_kver);
> +		         str_kver);
>  	}
>  
> +	return rc;
> +}
> +
> +int tst_kvcmp(const char *cur_kver, int r1, int r2, int r3)
> +{
> +	int a1, a2, a3;
> +	int testver, currver;
> +
> +	tst_parse_kver(cur_kver, &a1, &a2, &a3);
> +
>  	testver = (r1 << 20) + (r2 << 10) + r3;
>  	currver = (a1 << 20) + (a2 << 10) + a3;
>  
> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index 9c5f2617fe..a147521e9d 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -1067,11 +1067,7 @@ static bool check_kver(const char *min_kver, const int brk_nosupp)
>  	char *msg;
>  	int v1, v2, v3;
>  
> -	if (tst_parse_kver(min_kver, &v1, &v2, &v3)) {
> -		tst_res(TWARN,
> -			"Invalid kernel version %s, expected %%d.%%d.%%d",
> -			min_kver);
> -	}
> +	tst_parse_kver(min_kver, &v1, &v2, &v3);
>  
>  	if (tst_kvercmp(v1, v2, v3) < 0) {
>  		msg = "The test requires kernel %s or newer";
> -- 
> 2.55.0
> 

-- 
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.