selftests/vm: fix errno handling in mrelease_test
Subsystems (2)
PATCH v3 1/1 selftests/vm: fix errno handling in mrelease_test
mrelease_test should return KSFT_SKIP when process_mrelease is not defined, but due to a perror call consuming the errno, it returns KSFT_FAIL.
This patch decides the exit codes before calling perror.
---v1->v2: Fixed second instance in the same file v2->v3: Fixed remaining instances of errno mishandling
tools/testing/selftests/vm/mrelease_test.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
tools/testing/selftests/vm/mrelease_test.c +11 -5
@@ -62,19 +62,22 @@ static int alloc_noexit(unsigned long nr_pages, int pipefd)/* The process_mrelease calls in this test are expected to fail */ static void run_negative_tests (int pidfd) { +int res;/* Test invalid flags. Expect to fail with EINVAL error code. */ if (!syscall (__NR_process_mrelease, pidfd, (unsigned int )-1 ) || errno !=EINVAL ) { + res = (errno ==ENOSYS ?KSFT_SKIP :KSFT_FAIL );perror ("process_mrelease with wrong flags" ); -exit (errno ==ENOSYS ?KSFT_SKIP :KSFT_FAIL ); +exit (res); }/* * Test reaping while process is alive with no pending SIGKILL. * Expect to fail with EINVAL error code. */ if (!syscall (__NR_process_mrelease, pidfd,0 ) || errno !=EINVAL ) { + res = (errno ==ENOSYS ?KSFT_SKIP :KSFT_FAIL );perror ("process_mrelease on a live process" ); -exit (errno ==ENOSYS ?KSFT_SKIP :KSFT_FAIL ); +exit (res); } }
@@ -100,8 +103,9 @@ int main(void)/* Test a wrong pidfd */ if (!syscall (__NR_process_mrelease,-1 ,0 ) || errno !=EBADF ) { + res = (errno ==ENOSYS ?KSFT_SKIP :KSFT_FAIL );perror ("process_mrelease with wrong pidfd" ); -exit (errno ==ENOSYS ?KSFT_SKIP :KSFT_FAIL ); +exit (res); }/* Start the test with 1MB child memory allocation */
@@ -156,8 +160,9 @@ int main(void)run_negative_tests (pidfd);if (kill (pid,SIGKILL )) { + res = (errno ==ENOSYS ?KSFT_SKIP :KSFT_FAIL );perror ("kill" ); -exit (errno ==ENOSYS ?KSFT_SKIP :KSFT_FAIL ); +exit (res); } success = (syscall (__NR_process_mrelease, pidfd,0 ) ==0 );
@@ -172,9 +177,10 @@ int main(void)if (errno ==ESRCH ) { retry = (size <=MAX_SIZE_MB ); }else { + res = (errno ==ENOSYS ?KSFT_SKIP :KSFT_FAIL );perror ("process_mrelease" );waitpid (pid,NULL ,0 ); -exit (errno ==ENOSYS ?KSFT_SKIP :KSFT_FAIL ); +exit (res); } }
Signature · 1 line
2.35.1
Quoted 5 lines · Adam Sindelar
mrelease_testshould returnKSFT_SKIPwhenprocess_mreleaseis not defined, but due to a perror call consuming the errno, it returnsKSFT_FAIL.This patch decides the exit codes before calling perror.
As requested on the v2 version of the patch, please also include a "Fixes" line here (see [0]):
[0]: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
tools/testing/selftests/vm/mrelease_test.c
Quoted 13 lines
Signed-off-by Adam Sindelar <[email protected]>---
v1->v2: Fixed second instance in the same filev2->v3: Fixed remaining instances of errno mishandlingtools/testing/selftests/vm/mrelease_test.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)tools/testing/selftests/vm/mrelease_test.c +0
-0
[...]
Looks good otherwise, thanks.
Quoted 5 lines · David Vernet
Quoted 4 lines · Adam Sindelar
mrelease_testshould returnKSFT_SKIPwhenprocess_mreleaseis not defined, but due to a perror call consuming the errno, it returnsKSFT_FAIL.
Quoted 9 lines
Quoted 1 line
This patch decides the exit codes before calling perror.
As requested on the v2 version of the patch, please also include a "Fixes" line here (see [0]):
Fixes 33776141b812 ("selftests: vm: add process_mrelease tests")[0]: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
Done, sending shortly. Sorry, getting used to review over email.
Quoted 19 lines
tools/testing/selftests/vm/mrelease_test.c
Quoted 13 lines
Signed-off-by Adam Sindelar <[email protected]>---
v1->v2: Fixed second instance in the same filev2->v3: Fixed remaining instances of errno mishandlingtools/testing/selftests/vm/mrelease_test.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)tools/testing/selftests/vm/mrelease_test.c +0
-0[...]
Looks good otherwise, thanks.
Reviewed-by David Vernet <[email protected]>
Quoted 1 line · Adam Sindelar
Done, sending shortly. Sorry, getting used to review over email.
Thank you! And no worries at all, it can be a bit of an arcane process, and takes some getting used to.
- David