* [PATCH] selftests/kcmp: exit with non-zero code in a fail case
@ 2015-03-13 9:27 Andrey Vagin
2015-03-13 10:37 ` Michael Ellerman
0 siblings, 1 reply; 3+ messages in thread
From: Andrey Vagin @ 2015-03-13 9:27 UTC (permalink / raw)
To: linux-kernel; +Cc: Andrey Vagin, 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.
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 | 12 ++++++++++++
2 files changed, 22 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..a0ec8b8 100644
--- a/tools/testing/selftests/kselftest.h
+++ b/tools/testing/selftests/kselftest.h
@@ -58,5 +58,17 @@ static inline int ksft_exit_skip(void)
{
exit(4);
}
+static inline int ksft_exit(void)
+{
+ 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();
+ ksft_exit_pass();
+}
#endif /* __KSELFTEST_H */
--
2.1.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests/kcmp: exit with non-zero code in a fail case
2015-03-13 9:27 [PATCH] selftests/kcmp: exit with non-zero code in a fail case Andrey Vagin
@ 2015-03-13 10:37 ` Michael Ellerman
2015-03-13 11:06 ` Andrey Wagin
0 siblings, 1 reply; 3+ messages in thread
From: Michael Ellerman @ 2015-03-13 10:37 UTC (permalink / raw)
To: Andrey Vagin; +Cc: linux-kernel, Shuah Khan, Cyrill Gorcunov
On Fri, 2015-03-13 at 12:27 +0300, Andrey Vagin wrote:
> diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
> index 572c888..a0ec8b8 100644
> --- a/tools/testing/selftests/kselftest.h
> +++ b/tools/testing/selftests/kselftest.h
> @@ -58,5 +58,17 @@ static inline int ksft_exit_skip(void)
> {
> exit(4);
> }
> +static inline int ksft_exit(void)
> +{
> + 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();
> + ksft_exit_pass();
> +}
This function claims to return 'int', but doesn't. So do all the others.
It could be as simple as:
static inline void ksft_exit(void)
{
if (ksft_cnt.ksft_fail)
exit(1);
if (ksft_cnt.ksft_xpass)
exit(3);
if (ksft_cnt.ksft_xskip)
exit(4);
if (ksft_cnt.ksft_xfail)
exit(2);
exit(0);
}
cheers
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests/kcmp: exit with non-zero code in a fail case
2015-03-13 10:37 ` Michael Ellerman
@ 2015-03-13 11:06 ` Andrey Wagin
0 siblings, 0 replies; 3+ messages in thread
From: Andrey Wagin @ 2015-03-13 11:06 UTC (permalink / raw)
To: Michael Ellerman; +Cc: LKML, Shuah Khan, Cyrill Gorcunov
2015-03-13 13:37 GMT+03:00 Michael Ellerman <mpe@ellerman.id.au>:
> On Fri, 2015-03-13 at 12:27 +0300, Andrey Vagin wrote:
>> diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
>> index 572c888..a0ec8b8 100644
>> --- a/tools/testing/selftests/kselftest.h
>> +++ b/tools/testing/selftests/kselftest.h
>> @@ -58,5 +58,17 @@ static inline int ksft_exit_skip(void)
>> {
>> exit(4);
>> }
>> +static inline int ksft_exit(void)
>> +{
>> + 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();
>> + ksft_exit_pass();
>> +}
>
> This function claims to return 'int', but doesn't. So do all the others.
I agree with this. I haven't seen any warning, because exit() never
returns back.
>
> It could be as simple as:
I think it isn't a good idea. In my version we can be sure that
ksft_exit_fail() and ksft_exit() return the same code in a fail case.
>
> static inline void ksft_exit(void)
> {
> if (ksft_cnt.ksft_fail)
> exit(1);
>
> if (ksft_cnt.ksft_xpass)
> exit(3);
>
> if (ksft_cnt.ksft_xskip)
> exit(4);
>
> if (ksft_cnt.ksft_xfail)
> exit(2);
>
> exit(0);
> }
>
> cheers
>
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-03-13 11:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-13 9:27 [PATCH] selftests/kcmp: exit with non-zero code in a fail case Andrey Vagin
2015-03-13 10:37 ` Michael Ellerman
2015-03-13 11:06 ` Andrey Wagin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.