diff mbox

nptl: Add sendmmsg and recvmmsg cancellation tests

Message ID 1465571155-18996-1-git-send-email-adhemerval.zanella@linaro.org
State New
Headers show

Commit Message

Adhemerval Zanella Netto June 10, 2016, 3:05 p.m. UTC
This patch adds cancellation tests for both sendmmsg and recvmmsg
syscalls.

Tested on x86_64.  I will commit it shortly if noone opposes it.

	* nptl/tst-cancel4.c (tf_recvmmsg): Add test.
	(tf_sendmmsg): Add test.
---
 ChangeLog          |   3 +
 nptl/tst-cancel4.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 174 insertions(+)

-- 
2.7.4

Comments

Adhemerval Zanella Netto June 10, 2016, 5:46 p.m. UTC | #1
> On Jun 10, 2016, at 14:04, Joseph Myers <joseph@codesourcery.com> wrote:

> 

>> On Fri, 10 Jun 2016, Adhemerval Zanella wrote:

>> 

>> This patch adds cancellation tests for both sendmmsg and recvmmsg

>> syscalls.

> 

> Will these work if those fail with ENOSYS (old kernels, or non-Linux ports 

> using NPTL)


Right, I think best approach the to not fail for ENOSYS with a print saying it is not supported I the system. I will change that.

> -- 

> Joseph S. Myers

> joseph@codesourcery.com
Adhemerval Zanella Netto June 10, 2016, 6:17 p.m. UTC | #2
On 10/06/2016 14:54, Carlos O'Donell wrote:
> On 06/10/2016 01:46 PM, Adhemerval Zanella wrote:

>>

>>

>>> On Jun 10, 2016, at 14:04, Joseph Myers <joseph@codesourcery.com> wrote:

>>>

>>>> On Fri, 10 Jun 2016, Adhemerval Zanella wrote:

>>>>

>>>> This patch adds cancellation tests for both sendmmsg and recvmmsg

>>>> syscalls.

>>>

>>> Will these work if those fail with ENOSYS (old kernels, or non-Linux ports 

>>> using NPTL)

>>

>> Right, I think best approach the to not fail for ENOSYS with a print

>> saying it is not supported I the system. I will change that.

> 

> If the only thing being tested is skipped then you should exit(77)

> to indicate UNSUPPORTED.

> 


In this case the syscalls tests is used along with some other cancellable
interfaces.  Should I create an specific test just to indicate it?
diff mbox

Patch

diff --git a/nptl/tst-cancel4.c b/nptl/tst-cancel4.c
index 60f7ead..c31d739 100644
--- a/nptl/tst-cancel4.c
+++ b/nptl/tst-cancel4.c
@@ -1393,6 +1393,89 @@  tf_recvmsg (void *arg)
 
 
 static void *
+tf_recvmmsg (void *arg)
+{
+  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-5-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);
+    }
+
+  if (arg != NULL)
+    {
+      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[70];
+  struct iovec iov[1];
+  iov[0].iov_base = mem;
+  iov[0].iov_len = arg == NULL ? sizeof (mem) : 0;
+
+  struct mmsghdr mm;
+  mm.msg_hdr.msg_name = &sun;
+  mm.msg_hdr.msg_namelen = sizeof (sun);
+  mm.msg_hdr.msg_iov = iov;
+  mm.msg_hdr.msg_iovlen = 1;
+  mm.msg_hdr.msg_control = NULL;
+  mm.msg_hdr.msg_controllen = 0;
+
+  recvmmsg (tempfd2, &mm, 1, 0, NULL);
+
+  pthread_cleanup_pop (0);
+
+  printf ("%s: recvmmsg returned\n", __FUNCTION__);
+
+  exit (1);
+}
+
+static void *
 tf_open (void *arg)
 {
   if (arg == NULL)
@@ -1937,6 +2020,92 @@  tf_sendmsg (void *arg)
 
 
 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;
+
+  sendmmsg (tempfd2, &mm, 1, 0);
+
+  pthread_cleanup_pop (0);
+
+  printf ("%s: sendmmsg returned\n", __FUNCTION__);
+
+  exit (1);
+}
+
+
+static void *
 tf_creat (void *arg)
 {
   if (arg == NULL)
@@ -2230,6 +2399,7 @@  static struct
   ADD_TEST (recv, 2, 0),
   ADD_TEST (recvfrom, 2, 0),
   ADD_TEST (recvmsg, 2, 0),
+  ADD_TEST (recvmmsg, 2, 0),
   ADD_TEST (preadv, 2, 1),
   ADD_TEST (pwritev, 2, 1),
   ADD_TEST (open, 2, 1),
@@ -2241,6 +2411,7 @@  static struct
   ADD_TEST (msync, 2, 1),
   ADD_TEST (sendto, 2, 1),
   ADD_TEST (sendmsg, 2, 1),
+  ADD_TEST (sendmmsg, 2, 1),
   ADD_TEST (creat, 2, 1),
   ADD_TEST (connect, 2, 1),
   ADD_TEST (tcdrain, 2, 1),