selftests/coredump: Fix "socket_detect_userspace_client" test failure

The coredump.socket_detect_userspace_client test occasionally fails:
    #  RUN           coredump.socket_detect_userspace_client ...
    # stackdump_test.c:500:socket_detect_userspace_client:Expected 0 (0) != WIFEXITED(status) (0)
    # socket_detect_userspace_client: Test terminated by assertion
    #          FAIL  coredump.socket_detect_userspace_client
    not ok 3 coredump.socket_detect_userspace_client

because there is no guarantee that client's write() happens before server's
close(). The client gets terminated SIGPIPE, and thus the test fails.

Add a read() to server to make sure server's close() doesn't happen before
client's write().

Fixes: 7b6724fe9a ("selftests/coredump: add tests for AF_UNIX coredumps")
Signed-off-by: Nam Cao <namcao@linutronix.de>
Link: https://lore.kernel.org/20250620110252.1640391-1-namcao@linutronix.de
Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
Nam Cao 2025-06-20 13:02:52 +02:00 committed by Christian Brauner
parent e04c78d86a
commit 6a68d28066
No known key found for this signature in database
GPG Key ID: 91C61BC06578DCA2

View File

@ -461,10 +461,15 @@ TEST_F(coredump, socket_detect_userspace_client)
_exit(EXIT_FAILURE);
}
ret = read(fd_coredump, &c, 1);
close(fd_coredump);
close(fd_server);
close(fd_peer_pidfd);
close(fd_core_file);
if (ret < 1)
_exit(EXIT_FAILURE);
_exit(EXIT_SUCCESS);
}
self->pid_coredump_server = pid_coredump_server;