Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 code before calling perror.

[adam@wowsignal.io: fix remaining instances of errno mishandling]
Link: https://lkml.kernel.org/r/20220706141602.10159-1-adam@wowsignal.io
Link: https://lkml.kernel.org/r/20220704173351.19595-1-adam@wowsignal.io
Fixes: 33776141b812 ("selftests: vm: add process_mrelease tests")
Signed-off-by: Adam Sindelar <adam@wowsignal.io>
Reviewed-by: David Vernet <void@manifault.com>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Adam Sindelar and committed by
akpm
3b8e7f5c d6e103a7

+11 -5
+11 -5
tools/testing/selftests/vm/mrelease_test.c
··· 62 62 /* The process_mrelease calls in this test are expected to fail */ 63 63 static void run_negative_tests(int pidfd) 64 64 { 65 + int res; 65 66 /* Test invalid flags. Expect to fail with EINVAL error code. */ 66 67 if (!syscall(__NR_process_mrelease, pidfd, (unsigned int)-1) || 67 68 errno != EINVAL) { 69 + res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); 68 70 perror("process_mrelease with wrong flags"); 69 - exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); 71 + exit(res); 70 72 } 71 73 /* 72 74 * Test reaping while process is alive with no pending SIGKILL. 73 75 * Expect to fail with EINVAL error code. 74 76 */ 75 77 if (!syscall(__NR_process_mrelease, pidfd, 0) || errno != EINVAL) { 78 + res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); 76 79 perror("process_mrelease on a live process"); 77 - exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); 80 + exit(res); 78 81 } 79 82 } 80 83 ··· 103 100 104 101 /* Test a wrong pidfd */ 105 102 if (!syscall(__NR_process_mrelease, -1, 0) || errno != EBADF) { 103 + res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); 106 104 perror("process_mrelease with wrong pidfd"); 107 - exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); 105 + exit(res); 108 106 } 109 107 110 108 /* Start the test with 1MB child memory allocation */ ··· 160 156 run_negative_tests(pidfd); 161 157 162 158 if (kill(pid, SIGKILL)) { 159 + res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); 163 160 perror("kill"); 164 - exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); 161 + exit(res); 165 162 } 166 163 167 164 success = (syscall(__NR_process_mrelease, pidfd, 0) == 0); ··· 177 172 if (errno == ESRCH) { 178 173 retry = (size <= MAX_SIZE_MB); 179 174 } else { 175 + res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); 180 176 perror("process_mrelease"); 181 177 waitpid(pid, NULL, 0); 182 - exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); 178 + exit(res); 183 179 } 184 180 } 185 181