From patchwork Fri Jun 10 15:05:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 633788 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rR59T6TPYz9sBl for ; Sat, 11 Jun 2016 01:06:37 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=Bo2ut/r1; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=k+x8zAxboTCs2tNVpiVYbMb4DzGkvyaLXNSxWHmcvdDb+M2bqFywM P5uC8/a5c8czsnCLijkat7E12y0d3kHuzh+Z2wVME+x1qKPSgWnVrU5oi0fz81GD LKwQ32thhZBCsS7/ICkhBR3C2Grg/XeX+CX+CfGGutlt0o+A4Gq7xw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; s=default; bh=sWZsxi9a13RzbiObHO+dBMS+IU8=; b=Bo2ut/r1Q+lNGuy3+1DAsM/XFUfd 0iyaOCuvhWmpDORqVnOnkPSwcCYWMF4y6wELv5uqZKpjlxncBjN9Yut2wxl52ASY pqzyg8QrT+bZfWHnibSI+KXNX3qVqyWxhRLeLAjyHDUf6X8y8LMGseEnIig7KitB /Yc8RraLGHwt2tc= Received: (qmail 117865 invoked by alias); 10 Jun 2016 15:06:29 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 116882 invoked by uid 89); 10 Jun 2016 15:06:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=unsuccessful, xxx, shortly X-HELO: mail-yw0-f180.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=qqCl8tu8Ojdak6nvyHwf/jHwyt2BKDYw673tRBBsVO0=; b=gJXDU+N3iVGXxEt3lu+dWJdVij7VG8kCDpaB6sSV1vKvxut/7PGXRbpkrwCyStlSWl G9NEBSwWCkpfgS+HjpAiPfjUEoYlDZjd28Ay9wb44lPMr10flkohUAFK46dID1U2/dPy 0EDZtsvWc45gc7LTzRNWwJUY5wLBcrK9O1nG3BwIjNLcBXMBynVs5LVTwwsxO5uyTZFB XIKNxvS5uD8Y/VNzcsLIlHp/3hKy9GqmpGAEXmQRnZnyPBVvBTaJazuZlgOz0Rid1/ZF J7SJ1Ba4/zLZuvS+8R9KU99Y05V+A3bQboUmhDupX8LsVYNoRodAvzMfV9BIemnAADQ1 dm4w== X-Gm-Message-State: ALyK8tIXPFvslp2sjZ1tjXzbLtpz0rq3WW1eNT/DmjWArc9vghOtW4BBWkkt86S6FIkyf8TV X-Received: by 10.37.116.130 with SMTP id p124mr1200088ybc.5.1465571176440; Fri, 10 Jun 2016 08:06:16 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] nptl: Add sendmmsg and recvmmsg cancellation tests Date: Fri, 10 Jun 2016 12:05:55 -0300 Message-Id: <1465571155-18996-1-git-send-email-adhemerval.zanella@linaro.org> 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(+) 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),