diff options
author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2016-06-10 10:03:04 -0300 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2016-06-13 13:37:24 -0300 |
commit | b39b6e0c902f0bf5f99d593b8f5953943777c610 (patch) | |
tree | 89b6ee282879468ec64b432b2f402d4985cb4f2f /nptl/tst-cancel4_1.c | |
parent | 2c41b52901331f5c761015af786a3976e225d779 (diff) | |
download | glibc-b39b6e0c902f0bf5f99d593b8f5953943777c610.zip glibc-b39b6e0c902f0bf5f99d593b8f5953943777c610.tar.gz glibc-b39b6e0c902f0bf5f99d593b8f5953943777c610.tar.bz2 |
nptl: Add sendmmsg and recvmmsg cancellation tests
This patch adds cancellation tests for both sendmmsg and recvmmsg
syscalls. Since for some system configuration (x86_64/i686 on
older kernels and non-Linux platforms), the tests are added as
two independent that report as unsupported if the syscall is not
presented.
Both new tests uses the already tst-cancel4.c code, which as moved
to a common tst-cancel4-common{.c,h} files.
Tested on x86_64 and i686.
* nptl/Makefile (test): Add tst-cancel4_1 and tst-cancel4_2.
* nptl/tst-cancel4-common.c: New file.
* nptl/tst-cancel4-common.h: Likewise.
* nptl/tst-cancel4.c: Move common definitions to
tst-cancel4-common.{c,h} file.
* nptl/tst-cancel4_1.c: New test.
* nptl/tst-cancel4_2.c: New test.
Diffstat (limited to 'nptl/tst-cancel4_1.c')
-rw-r--r-- | nptl/tst-cancel4_1.c | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/nptl/tst-cancel4_1.c b/nptl/tst-cancel4_1.c new file mode 100644 index 0000000..68296ec --- /dev/null +++ b/nptl/tst-cancel4_1.c @@ -0,0 +1,127 @@ +/* Check sendmmsg cancellation. + + Copyright (C) 2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <sys/ipc.h> +#include <sys/msg.h> +#include <unistd.h> +#include <errno.h> +#include <pthread.h> + +#include "tst-cancel4-common.h" + +static void * +tf_sendmmsg (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which sendmmsg() + // blocks we can enable this test to run in both rounds. + abort (); + + struct sockaddr_un sun; + + tempfd = socket (AF_UNIX, SOCK_DGRAM, 0); + if (tempfd == -1) + { + printf ("%s: first socket call failed\n", __FUNCTION__); + exit (1); + } + + int tries = 0; + do + { + if (++tries > 10) + { + printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__); + } + + strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-7-XXXXXX"); + if (mktemp (sun.sun_path) == NULL) + { + printf ("%s: cannot generate temp file name\n", __FUNCTION__); + exit (1); + } + + sun.sun_family = AF_UNIX; + } + while (bind (tempfd, (struct sockaddr *) &sun, + offsetof (struct sockaddr_un, sun_path) + + strlen (sun.sun_path) + 1) != 0); + tempfname = strdup (sun.sun_path); + + tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0); + if (tempfd2 == -1) + { + printf ("%s: second socket call failed\n", __FUNCTION__); + exit (1); + } + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + pthread_cleanup_push (cl, NULL); + + char mem[1]; + struct iovec iov[1]; + iov[0].iov_base = mem; + iov[0].iov_len = 1; + + struct mmsghdr mm; + mm.msg_hdr.msg_name = &sun; + mm.msg_hdr.msg_namelen = (offsetof (struct sockaddr_un, sun_path) + + strlen (sun.sun_path) + 1); + mm.msg_hdr.msg_iov = iov; + mm.msg_hdr.msg_iovlen = 1; + mm.msg_hdr.msg_control = NULL; + mm.msg_hdr.msg_controllen = 0; + + ssize_t ret = sendmmsg (tempfd2, &mm, 1, 0); + if (ret == -1 && errno == ENOSYS) + exit (77); + + pthread_cleanup_pop (0); + + printf ("%s: sendmmsg returned\n", __FUNCTION__); + + exit (1); +} + +struct cancel_tests tests[] = +{ + ADD_TEST (sendmmsg, 2, 1), +}; +#define ntest_tf (sizeof (tests) / sizeof (tests[0])) + +#include "tst-cancel4-common.c" |