mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] selftests/kcmp: exit with non-zero code in a fail case (v2)
@ 2015-03-13 15:55 Andrey Vagin
  2015-03-13 16:07 ` Shuah Khan
  0 siblings, 1 reply; 3+ messages in thread
From: Andrey Vagin @ 2015-03-13 15:55 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrey Vagin, Michael Ellerman, Shuah Khan, Cyrill Gorcunov

Currently this test always returs zero code and a child process returns
non-zero code only if the last testcase failed.

v2: don't forget to return smth from ksft_exit()

Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
---
 tools/testing/selftests/kcmp/kcmp_test.c | 16 ++++++++++------
 tools/testing/selftests/kselftest.h      | 18 ++++++++++++++++++
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/kcmp/kcmp_test.c b/tools/testing/selftests/kcmp/kcmp_test.c
index a5a4da8..42a40c6 100644
--- a/tools/testing/selftests/kcmp/kcmp_test.c
+++ b/tools/testing/selftests/kcmp/kcmp_test.c
@@ -97,13 +97,17 @@ int main(int argc, char **argv)
 
 		ksft_print_cnts();
 
-		if (ret)
-			ksft_exit_fail();
-		else
-			ksft_exit_pass();
+		return ksft_exit();
+	}
+
+	status = -1;
+	if (waitpid(pid2, &status, 0) != pid2) {
+		perror("Unable to wait the child\n");
+		return ksft_exit_fail();
 	}
 
-	waitpid(pid2, &status, P_ALL);
+	if (WIFEXITED(status))
+		return WEXITSTATUS(status);
 
-	return ksft_exit_pass();
+	return ksft_exit_fail();
 }
diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
index 572c888..f23e56c 100644
--- a/tools/testing/selftests/kselftest.h
+++ b/tools/testing/selftests/kselftest.h
@@ -59,4 +59,22 @@ static inline int ksft_exit_skip(void)
 	exit(4);
 }
 
+static inline int ksft_exit(void)
+{
+	/* in order of disruptiveness from bad to good */
+	if (ksft_cnt.ksft_fail)
+		return ksft_exit_fail();
+	if (ksft_cnt.ksft_xpass)
+		return ksft_exit_xpass();
+	if (ksft_cnt.ksft_xskip)
+		return ksft_exit_skip();
+	if (ksft_cnt.ksft_xfail)
+		return ksft_exit_xfail();
+	if (ksft_cnt.ksft_pass)
+		return ksft_exit_pass();
+
+	/* A test must do something */
+	return ksft_exit_fail();
+}
+
 #endif /* __KSELFTEST_H */
-- 
2.1.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests/kcmp: exit with non-zero code in a fail case (v2)
  2015-03-13 15:55 [PATCH] selftests/kcmp: exit with non-zero code in a fail case (v2) Andrey Vagin
@ 2015-03-13 16:07 ` Shuah Khan
  2015-03-13 16:28   ` [PATCH v2] selftests/kcmp: exit with non-zero code in a fail case Andrey Vagin
  0 siblings, 1 reply; 3+ messages in thread
From: Shuah Khan @ 2015-03-13 16:07 UTC (permalink / raw)
  To: Andrey Vagin, linux-kernel; +Cc: Michael Ellerman, Cyrill Gorcunov, Shuah Khan

On 03/13/2015 09:55 AM, Andrey Vagin wrote:
> Currently this test always returs zero code and a child process returns
> non-zero code only if the last testcase failed.
> 
> v2: don't forget to return smth from ksft_exit()

Please check patch subject. It is phrased:
[PATCH v2] selftests/kcmp: exit with non-zero code in a fail case

Could you please resend. I don't want v2 ending up in the commit.

-- Shuah

> 
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Shuah Khan <shuahkh@osg.samsung.com>
> Cc: Cyrill Gorcunov <gorcunov@openvz.org>
> Signed-off-by: Andrey Vagin <avagin@openvz.org>
> ---
>  tools/testing/selftests/kcmp/kcmp_test.c | 16 ++++++++++------
>  tools/testing/selftests/kselftest.h      | 18 ++++++++++++++++++
>  2 files changed, 28 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/testing/selftests/kcmp/kcmp_test.c b/tools/testing/selftests/kcmp/kcmp_test.c
> index a5a4da8..42a40c6 100644
> --- a/tools/testing/selftests/kcmp/kcmp_test.c
> +++ b/tools/testing/selftests/kcmp/kcmp_test.c
> @@ -97,13 +97,17 @@ int main(int argc, char **argv)
>  
>  		ksft_print_cnts();
>  
> -		if (ret)
> -			ksft_exit_fail();
> -		else
> -			ksft_exit_pass();
> +		return ksft_exit();
> +	}
> +
> +	status = -1;
> +	if (waitpid(pid2, &status, 0) != pid2) {
> +		perror("Unable to wait the child\n");
> +		return ksft_exit_fail();
>  	}
>  
> -	waitpid(pid2, &status, P_ALL);
> +	if (WIFEXITED(status))
> +		return WEXITSTATUS(status);
>  
> -	return ksft_exit_pass();
> +	return ksft_exit_fail();
>  }
> diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
> index 572c888..f23e56c 100644
> --- a/tools/testing/selftests/kselftest.h
> +++ b/tools/testing/selftests/kselftest.h
> @@ -59,4 +59,22 @@ static inline int ksft_exit_skip(void)
>  	exit(4);
>  }
>  
> +static inline int ksft_exit(void)
> +{
> +	/* in order of disruptiveness from bad to good */
> +	if (ksft_cnt.ksft_fail)
> +		return ksft_exit_fail();
> +	if (ksft_cnt.ksft_xpass)
> +		return ksft_exit_xpass();
> +	if (ksft_cnt.ksft_xskip)
> +		return ksft_exit_skip();
> +	if (ksft_cnt.ksft_xfail)
> +		return ksft_exit_xfail();
> +	if (ksft_cnt.ksft_pass)
> +		return ksft_exit_pass();
> +
> +	/* A test must do something */
> +	return ksft_exit_fail();
> +}
> +
>  #endif /* __KSELFTEST_H */
> 


-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2] selftests/kcmp: exit with non-zero code in a fail case
  2015-03-13 16:07 ` Shuah Khan
@ 2015-03-13 16:28   ` Andrey Vagin
  0 siblings, 0 replies; 3+ messages in thread
From: Andrey Vagin @ 2015-03-13 16:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrey Vagin, Michael Ellerman, Shuah Khan, Cyrill Gorcunov

Currently this test always returs zero code and a child process returns
non-zero code only if the last testcase failed.

v2: don't forget to return smth from ksft_exit()

Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
---
 tools/testing/selftests/kcmp/kcmp_test.c | 16 ++++++++++------
 tools/testing/selftests/kselftest.h      | 18 ++++++++++++++++++
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/kcmp/kcmp_test.c b/tools/testing/selftests/kcmp/kcmp_test.c
index a5a4da8..42a40c6 100644
--- a/tools/testing/selftests/kcmp/kcmp_test.c
+++ b/tools/testing/selftests/kcmp/kcmp_test.c
@@ -97,13 +97,17 @@ int main(int argc, char **argv)
 
 		ksft_print_cnts();
 
-		if (ret)
-			ksft_exit_fail();
-		else
-			ksft_exit_pass();
+		return ksft_exit();
+	}
+
+	status = -1;
+	if (waitpid(pid2, &status, 0) != pid2) {
+		perror("Unable to wait the child\n");
+		return ksft_exit_fail();
 	}
 
-	waitpid(pid2, &status, P_ALL);
+	if (WIFEXITED(status))
+		return WEXITSTATUS(status);
 
-	return ksft_exit_pass();
+	return ksft_exit_fail();
 }
diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
index 572c888..f23e56c 100644
--- a/tools/testing/selftests/kselftest.h
+++ b/tools/testing/selftests/kselftest.h
@@ -59,4 +59,22 @@ static inline int ksft_exit_skip(void)
 	exit(4);
 }
 
+static inline int ksft_exit(void)
+{
+	/* in order of disruptiveness from bad to good */
+	if (ksft_cnt.ksft_fail)
+		return ksft_exit_fail();
+	if (ksft_cnt.ksft_xpass)
+		return ksft_exit_xpass();
+	if (ksft_cnt.ksft_xskip)
+		return ksft_exit_skip();
+	if (ksft_cnt.ksft_xfail)
+		return ksft_exit_xfail();
+	if (ksft_cnt.ksft_pass)
+		return ksft_exit_pass();
+
+	/* A test must do something */
+	return ksft_exit_fail();
+}
+
 #endif /* __KSELFTEST_H */
-- 
2.1.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-03-13 16:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-13 15:55 [PATCH] selftests/kcmp: exit with non-zero code in a fail case (v2) Andrey Vagin
2015-03-13 16:07 ` Shuah Khan
2015-03-13 16:28   ` [PATCH v2] selftests/kcmp: exit with non-zero code in a fail case Andrey Vagin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome