tests: robustify unix-yy.test
Implement additional synchronization between parent and child processes to guarantee that the child starts closing connected socket only after exiting of the parent's accept() syscall. This guarantee seems to be necessary to reliably receive UNIX_DIAG_PEER messages from NETLINK_SOCK_DIAG interface. * tests/net-accept-connect.c: Implement additional synchronization between parent and child processes. * tests/unix-yy-connect.awk: Update.
This commit is contained in:
parent
59f63d3106
commit
da66e25779
@ -1,12 +1,21 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
|
|
||||||
int main(int ac, const char **av)
|
static void
|
||||||
|
handler(int sig)
|
||||||
|
{
|
||||||
|
assert(close(1) == 0);
|
||||||
|
_exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int ac, const char **av)
|
||||||
{
|
{
|
||||||
struct sockaddr_un addr = {
|
struct sockaddr_un addr = {
|
||||||
.sun_family = AF_UNIX,
|
.sun_family = AF_UNIX,
|
||||||
@ -40,16 +49,24 @@ int main(int ac, const char **av)
|
|||||||
if (pid) {
|
if (pid) {
|
||||||
assert(accept(0, (struct sockaddr *) &addr, &len) == 1);
|
assert(accept(0, (struct sockaddr *) &addr, &len) == 1);
|
||||||
assert(close(0) == 0);
|
assert(close(0) == 0);
|
||||||
|
assert(kill(pid, SIGUSR1) == 0);
|
||||||
int status;
|
int status;
|
||||||
assert(waitpid(pid, &status, 0) == pid);
|
assert(waitpid(pid, &status, 0) == pid);
|
||||||
assert(status == 0);
|
assert(status == 0);
|
||||||
assert(close(1) == 0);
|
assert(close(1) == 0);
|
||||||
} else {
|
} else {
|
||||||
|
sigset_t set;
|
||||||
|
sigemptyset(&set);
|
||||||
|
sigaddset(&set, SIGUSR1);
|
||||||
|
|
||||||
|
assert(sigprocmask(SIG_BLOCK, &set, NULL) == 0);
|
||||||
|
assert(signal(SIGUSR1, handler) != SIG_ERR);
|
||||||
assert(socket(PF_LOCAL, SOCK_STREAM, 0) == 1);
|
assert(socket(PF_LOCAL, SOCK_STREAM, 0) == 1);
|
||||||
assert(close(0) == 0);
|
assert(close(0) == 0);
|
||||||
assert(connect(1, (struct sockaddr *) &addr, len) == 0);
|
assert(connect(1, (struct sockaddr *) &addr, len) == 0);
|
||||||
assert(close(1) == 0);
|
assert(sigprocmask(SIG_UNBLOCK, &set, NULL) == 0);
|
||||||
return 0;
|
assert(pause() == 99);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink(av[1]);
|
unlink(av[1]);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
BEGIN {
|
BEGIN {
|
||||||
lines = 5
|
lines = 6
|
||||||
fail = 0
|
fail = 0
|
||||||
addrlen = length(addr) + 3
|
addrlen = length(addr) + 3
|
||||||
|
|
||||||
@ -20,7 +20,9 @@ NR == 3 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NR == 4 {
|
NR == 4 && /^--- SIGUSR1 / {next}
|
||||||
|
|
||||||
|
NR == 5 {
|
||||||
if (inode != "" && r_close_connected != "" && match($0, r_close_connected, a) && a[1] == inode) {
|
if (inode != "" && r_close_connected != "" && match($0, r_close_connected, a) && a[1] == inode) {
|
||||||
next
|
next
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user