On Thu, Aug 07, 2025 at 08:00:42PM +0800, Wake Liu wrote: > The futex tests `futex_wait.c` and `futex_waitv.c` rely on the `shmget()` > syscall, which may not be available if the kernel is built without > System V IPC support (CONFIG_SYSVIPC=n). This can lead to test > failures on such systems. > > This patch modifies the tests to check for `shmget()` support at > runtime by calling it and checking for an `ENOSYS` error. If `shmget()` > is not supported, the tests are skipped with a clear message, > improving the user experience and preventing false negatives. > > This approach is more robust than relying on compile-time checks and > ensures that the tests run only when the required kernel features are > present. > > Signed-off-by: Wake Liu <wa...@google.com> > --- > .../selftests/futex/functional/futex_wait.c | 49 +++++++------ > .../selftests/futex/functional/futex_waitv.c | 73 ++++++++++++------- > 2 files changed, 73 insertions(+), 49 deletions(-) > > diff --git a/tools/testing/selftests/futex/functional/futex_wait.c > b/tools/testing/selftests/futex/functional/futex_wait.c > index 685140d9b93d..17a465313a59 100644 > --- a/tools/testing/selftests/futex/functional/futex_wait.c > +++ b/tools/testing/selftests/futex/functional/futex_wait.c > @@ -48,7 +48,7 @@ static void *waiterfn(void *arg) > int main(int argc, char *argv[]) > { > int res, ret = RET_PASS, fd, c, shm_id; > - u_int32_t f_private = 0, *shared_data; > + u_int32_t f_private = 0, *shared_data = NULL; > unsigned int flags = FUTEX_PRIVATE_FLAG; > pthread_t waiter; > void *shm; > @@ -96,32 +96,35 @@ int main(int argc, char *argv[]) > /* Testing an anon page shared memory */ > shm_id = shmget(IPC_PRIVATE, 4096, IPC_CREAT | 0666); > if (shm_id < 0) { > - perror("shmget"); > - exit(1); > - } > - > - shared_data = shmat(shm_id, NULL, 0); > + if (errno == ENOSYS) { > + ksft_test_result_skip("Kernel does not support System V > shared memory\n"); > + } else { > + ksft_test_result_fail("shmget() failed with error: > %s\n", strerror(errno)); > + ret = RET_FAIL;
kselftest.h is already keeping track of the failure status. Just call ksft_finished() at the end. Also the whole perror()/exit(1) pattern doesn't really make sense in a kselftest. > + } > + } else { > + shared_data = shmat(shm_id, NULL, 0); (...)