From patchwork Tue Jun 14 15:42:28 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: 635403 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 3rTYnZ1qGHz9t12 for ; Wed, 15 Jun 2016 01:42:58 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=JCWoZxOP; 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=Mf39uddL5Si+L61WAvzhjhUs+3jHaYD66E4TOed12KiEK/L7s2Byb AtVC4KuPlpRxy5w6KAwL8NWSZVLDap6zFFxu38TO1jnpSslz8gk1OyO1sytsEQLN cG+kV5V5QnB++2MNtIEafZ1XdQbnYAZPfIEAz6+F5uC8Uh4rwJPvAY= 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=aPx2yANZ1ILA8L9edbh4bZG3OEs=; b=JCWoZxOPJWVvhQyPcJDQ1dBtMb4Z JSn26Oz5vtebgrQPiEQ4ABLmKYmnQLsnkD8JYvMxc6L/1BE9CsiLnd7baefXY6hL VDhJflNSKKOtUwl3vTvX6E6epsRTUPw4Mvj7vN9oVIABIWOgVbVSijL/lLmUSimY +KhOUGmuOmdvWJQ= Received: (qmail 94084 invoked by alias); 14 Jun 2016 15:42:50 -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 93604 invoked by uid 89); 14 Jun 2016 15:42:50 -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=Named, cnt, bsd, xxx X-HELO: mail-yw0-f173.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=enPX6TdpC506G4/TSPVjSLJVFpUDz6Ui+YUJNOqgNCU=; b=GIk4M41QexQQ4Ujoaz8hJ31gF4XFPsanEsZ8xKH4cyICdNHtDOa+8JrDsijuIjQwKm Fr1eOZt5LraSgtvIi+j25k6AVHtlXzJVoRgZCudZw3Zxw0v3KbWSwHkqfjBSbSr4rEDW xcmywV9xCp5/QUshjcvcsxTjHebp3VpJzefZY+BkK+roPQQcHMPxZ+3MaiFheIbDpiRM 4qWVyDCzwdMNY4EXmmUQyE7jXz8FYyJO6Kz+jsN3QgrVKQwb6PJH3gXxV2eTqPHKioDm Q8gChBlUDGksD1YDp37ECWPr8B9vjOowEGJDW/JoSDx51ujd6lUQ5cEkGEV5O9tTJOBV uKog== X-Gm-Message-State: ALyK8tLRdwQm+ZkN/KoS/L/8GMNUcQomobN0XEcBtWTWv9mV6JlavXKwZf+GsLGoU2bcOASF X-Received: by 10.13.204.137 with SMTP id o131mr2339726ywd.168.1465918957514; Tue, 14 Jun 2016 08:42:37 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] nptl: Add more coverage in tst-cancel4 Date: Tue, 14 Jun 2016 12:42:28 -0300 Message-Id: <1465918948-13371-1-git-send-email-adhemerval.zanella@linaro.org> This patch adds early cancel test for open syscall through a FIFO (thus makign subsequent call to open block until the other end is also opened). It also cleanup the sigpause tests by using sigpause along with SIGINT instead of __xpg_sigpause and SIGCANCEL. Since the idea is just to test the cancellation handling there is no need to expose internal glibc implementation details to the test through pthreadP.h inclusion. Tested x86_64. * nptl/tst-cancel4-common.c (do_test): Add temporary fifo creation. * nptl/tst-cancel4-common.h (fifoname): New variable. (fifofd): Likewise. (cl_fifo): New function. * nptl/tst-cancel4.c (tf_sigpause): Replace SIGCANCEL usage by SIGINT. (tf_open): Add early cancel test. --- ChangeLog | 10 ++++++++++ nptl/tst-cancel4-common.c | 6 ++++++ nptl/tst-cancel4-common.h | 16 ++++++++++++++++ nptl/tst-cancel4.c | 40 ++++++++++++++++++++-------------------- 4 files changed, 52 insertions(+), 20 deletions(-) diff --git a/nptl/tst-cancel4-common.c b/nptl/tst-cancel4-common.c index f235d53..cab99c4 100644 --- a/nptl/tst-cancel4-common.c +++ b/nptl/tst-cancel4-common.c @@ -44,6 +44,12 @@ do_test (void) } setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val)); + if (mktemp (fifoname) == NULL) + { + printf ("%s: cannot generate temp file name\n", __FUNCTION__); + exit (1); + } + int result = 0; size_t cnt; for (cnt = 0; cnt < ntest_tf; ++cnt) diff --git a/nptl/tst-cancel4-common.h b/nptl/tst-cancel4-common.h index e1683c4..06ed0dc 100644 --- a/nptl/tst-cancel4-common.h +++ b/nptl/tst-cancel4-common.h @@ -67,6 +67,22 @@ cl (void *arg) ++cl_called; } +/* Named pipe used to check for blocking open. It should be closed + after the cancellation handling. */ +static char fifoname[] = "/tmp/tst-cancel4-fifo-XXXXXX"; +static int fifofd; + +static void +__attribute__ ((used)) +cl_fifo (void *arg) +{ + ++cl_called; + + unlink (fifoname); + close (fifofd); + fifofd = -1; +} + struct cancel_tests { const char *name; diff --git a/nptl/tst-cancel4.c b/nptl/tst-cancel4.c index 4221af4..c1fac1b 100644 --- a/nptl/tst-cancel4.c +++ b/nptl/tst-cancel4.c @@ -36,8 +36,6 @@ #include #include -#include "pthreadP.h" - /* Since STREAMS are not supported in the standard Linux kernel and there we don't advertise STREAMS as supported is no need to test @@ -67,6 +65,7 @@ #include "tst-cancel4-common.h" + #ifndef IPC_ADDVAL # define IPC_ADDVAL 0 #endif @@ -734,13 +733,7 @@ tf_sigpause (void *arg) pthread_cleanup_push (cl, NULL); -#ifdef SIGCANCEL - /* Just for fun block the cancellation signal. We need to use - __xpg_sigpause since otherwise we will get the BSD version. */ - __xpg_sigpause (SIGCANCEL); -#else - pause (); -#endif + sigpause (sigmask (SIGINT)); pthread_cleanup_pop (0); @@ -1348,27 +1341,34 @@ static void * tf_open (void *arg) { if (arg == NULL) - // XXX If somebody can provide a portable test case in which open() - // blocks we can enable this test to run in both rounds. - abort (); - - int r = pthread_barrier_wait (&b2); - if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) { - printf ("%s: barrier_wait failed\n", __FUNCTION__); - exit (1); + fifofd = mkfifo (fifoname, S_IWUSR | S_IRUSR); + if (fifofd == -1) + { + printf ("%s: mkfifo failed\n", __FUNCTION__); + exit (1); + } + } + else + { + 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); + int 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); + pthread_cleanup_push (cl_fifo, NULL); - open ("Makefile", O_RDONLY); + open (arg ? "Makefile" : fifoname, O_RDONLY); pthread_cleanup_pop (0);