From patchwork Thu Sep 17 20:03:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 53842 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by patches.linaro.org (Postfix) with ESMTPS id 4380922E57 for ; Thu, 17 Sep 2015 20:04:16 +0000 (UTC) Received: by wisv5 with SMTP id v5sf1424956wis.0 for ; Thu, 17 Sep 2015 13:04:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-subscribe:list-archive:list-post:list-help :sender:delivered-to:from:subject:to:message-id:date:user-agent :mime-version:content-type:content-transfer-encoding :x-original-sender:x-original-authentication-results; bh=nUXKVYxLPajk+ff6+NV/jzAjA5xSOpOolNxArx7R8zI=; b=ZEYAuGKSNL9jbKEs5WYd2D4z17PuwmpeSWz39J1H0DWvTIVYDuf0SdEm7gjb5b592Q 4VijEYdvJJ8kzEuPwVNzQmpIdH6+jETWAtnfKcyV0dqY7SzQPk/FUlQTouqRX+IMrdFW MjqOlXJ8Gf36qALLLqjzR6OnANm2RKz9nQ+M8O34sY60a2GPMgQAb/jbNczYHSL2ByB1 kqgwDVMKCAqIjCo665peIKCXtkSgD2hw6kLPQk9L1LjNq2f7LglqAUInlto2MX2EzMtQ Agwrul8XnVbiXqBcJE9jh6LEgtRp+IAF045Wl10MUcui4jyGzI6algz+lXw+8kJQBlu0 hwDw== X-Gm-Message-State: ALoCoQmO/3s/3n00C8QPj/YtRfYm4Sqjj5811qXqmfbNxbbH6cQbqtRSOh7Iog11VBnwPDmQyOt7 X-Received: by 10.112.135.104 with SMTP id pr8mr186289lbb.4.1442520255543; Thu, 17 Sep 2015 13:04:15 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.228 with SMTP id b4ls117147lak.28.gmail; Thu, 17 Sep 2015 13:04:15 -0700 (PDT) X-Received: by 10.153.4.40 with SMTP id cb8mr1234985lad.100.1442520255064; Thu, 17 Sep 2015 13:04:15 -0700 (PDT) Received: from mail-lb0-x22b.google.com (mail-lb0-x22b.google.com. [2a00:1450:4010:c04::22b]) by mx.google.com with ESMTPS id zk1si3346127lbb.30.2015.09.17.13.04.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2015 13:04:15 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::22b as permitted sender) client-ip=2a00:1450:4010:c04::22b; Received: by lbbmp1 with SMTP id mp1so15154422lbb.1 for ; Thu, 17 Sep 2015 13:04:15 -0700 (PDT) X-Received: by 10.152.37.135 with SMTP id y7mr1214970laj.106.1442520254906; Thu, 17 Sep 2015 13:04:14 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp3264700lbq; Thu, 17 Sep 2015 13:04:13 -0700 (PDT) X-Received: by 10.66.100.197 with SMTP id fa5mr1754193pab.153.1442520253421; Thu, 17 Sep 2015 13:04:13 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id wm7si7611019pab.60.2015.09.17.13.04.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2015 13:04:13 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-63258-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 102030 invoked by alias); 17 Sep 2015 20:04:03 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list 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 100267 invoked by uid 89); 17 Sep 2015 20:04:01 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL, BAYES_50, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-yk0-f175.google.com X-Received: by 10.129.95.10 with SMTP id t10mr1147276ywb.100.1442520230588; Thu, 17 Sep 2015 13:03:50 -0700 (PDT) From: Adhemerval Zanella Subject: [PATCH 01/10] nptl: Fix testcases for new pthread cancellation mechanism To: GNU C Library Message-ID: <55FB1CA6.9080401@linaro.org> Date: Thu, 17 Sep 2015 17:03:50 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 X-Original-Sender: adhemerval.zanella@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::22b as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@sourceware.org X-Google-Group-Id: 836684582541 With upcoming fix for BZ#12683, pthread cancellation does not act for: 1. If syscall is blocked but with some side effects already having taken place (e.g. a partial read or write) 2. After the syscall has returned. It is because program need to act on such cases (for instance, to avoid leak of allocated resources our handling partial read/write). This patches fixes the NPTL testcase that assumes the old behavior and also remove the tst-cancel-wrappers.sh test (which checks for symbols that does not exist anymore). It also adds some tests from Phil Blundell that stress the failure paths that should set the errno. --- 2015-09-16 Adhemerval Zanella Phil Blundell * nptl/Makefile [$(run-built-tests) = yes] (tests-special): Remove tst-cancel-wrappers.sh. * nptl/tst-cancel-wrappers.sh: Remove file. * nptl/tst-cancel2.c (tf): Add pthread_testcancel after cancellable syscall. * nptl/tst-cancel20.c (sh_body): Likewise. * nptl/tst-cancel21.c (sh_body): Likewise. (tf_body): Likewise. * nptl/tst-cancel4.c (tf_Write): Likewise. (tf_send): Likewise. (tf_open64): New test: check for open64 cancellable syscall. (tf_pread64): New test: check for pread64 cancellable syscall. (tf_pwrite64): New test: check for pwrite64 cancellable syscall. * nptl/tst-cancel26.c: New file. * nptl/tst-cancel27.c: New file. -- diff --git a/nptl/Makefile b/nptl/Makefile index aaca0a4..39e28fd 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -257,6 +257,7 @@ tests = tst-typesizes \ tst-cancel11 tst-cancel12 tst-cancel13 tst-cancel14 tst-cancel15 \ tst-cancel16 tst-cancel17 tst-cancel18 tst-cancel19 tst-cancel20 \ tst-cancel21 tst-cancel22 tst-cancel23 tst-cancel24 tst-cancel25 \ + tst-cancel26 tst-cancel27 \ tst-cancel-self tst-cancel-self-cancelstate \ tst-cancel-self-canceltype tst-cancel-self-testcancel \ tst-cleanup0 tst-cleanup1 tst-cleanup2 tst-cleanup3 tst-cleanup4 \ @@ -394,8 +395,7 @@ tests-reverse += tst-cancel5 tst-cancel23 tst-vfork1x tst-vfork2x ifeq ($(run-built-tests),yes) tests-special += $(objpfx)tst-stack3-mem.out $(objpfx)tst-oddstacklimit.out ifeq ($(build-shared),yes) -tests-special += $(objpfx)tst-tls6.out $(objpfx)tst-cleanup0-cmp.out \ - $(objpfx)tst-cancel-wrappers.out +tests-special += $(objpfx)tst-tls6.out $(objpfx)tst-cleanup0-cmp.out endif endif @@ -607,7 +607,7 @@ $(objpfx)$(multidir)/crtn.o: $(objpfx)crtn.o $(objpfx)$(multidir)/ endif generated += libpthread_nonshared.a \ - multidir.mk tst-atfork2.mtrace tst-cancel-wrappers.out \ + multidir.mk tst-atfork2.mtrace \ tst-tls6.out generated += $(objpfx)tst-atfork2.mtrace \ @@ -624,18 +624,6 @@ LDFLAGS-pthread.so += -e __nptl_main $(objpfx)pt-interp.os: $(common-objpfx)runtime-linker.h endif -ifeq ($(run-built-tests),yes) -ifeq (yes,$(build-shared)) -$(objpfx)tst-cancel-wrappers.out: tst-cancel-wrappers.sh - $(SHELL) $< '$(NM)' \ - $(common-objpfx)libc_pic.a \ - $(common-objpfx)libc.a \ - $(objpfx)libpthread_pic.a \ - $(objpfx)libpthread.a > $@; \ - $(evaluate-test) -endif -endif - tst-exec4-ARGS = $(host-test-program-cmd) $(objpfx)tst-execstack: $(libdl) diff --git a/nptl/tst-cancel-wrappers.sh b/nptl/tst-cancel-wrappers.sh deleted file mode 100644 index d492a54..0000000 --- a/nptl/tst-cancel-wrappers.sh +++ /dev/null @@ -1,92 +0,0 @@ -#! /bin/sh -# Test whether all cancelable functions are cancelable. -# Copyright (C) 2002-2015 Free Software Foundation, Inc. -# This file is part of the GNU C Library. -# Contributed by Jakub Jelinek , 2002. - -# 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 -# . - -NM="$1"; shift -while [ $# -gt 0 ]; do - ( $NM -P $1; echo 'end[end]:' ) | gawk ' BEGIN { -C["accept"]=1 -C["close"]=1 -C["connect"]=1 -C["creat"]=1 -C["fcntl"]=1 -C["fdatasync"]=1 -C["fsync"]=1 -C["msgrcv"]=1 -C["msgsnd"]=1 -C["msync"]=1 -C["nanosleep"]=1 -C["open"]=1 -C["open64"]=1 -C["pause"]=1 -C["poll"]=1 -C["pread"]=1 -C["pread64"]=1 -C["pselect"]=1 -C["pwrite"]=1 -C["pwrite64"]=1 -C["read"]=1 -C["readv"]=1 -C["recv"]=1 -C["recvfrom"]=1 -C["recvmsg"]=1 -C["select"]=1 -C["send"]=1 -C["sendmsg"]=1 -C["sendto"]=1 -C["sigpause"]=1 -C["sigsuspend"]=1 -C["sigwait"]=1 -C["sigwaitinfo"]=1 -C["tcdrain"]=1 -C["wait"]=1 -C["waitid"]=1 -C["waitpid"]=1 -C["write"]=1 -C["writev"]=1 -C["__xpg_sigpause"]=1 -} -/:$/ { - if (seen) - { - if (!seen_enable || !seen_disable) - { - printf "in '$1'(%s) %s'\''s cancellation missing\n", object, seen - ret = 1 - } - } - seen="" - seen_enable="" - seen_disable="" - object=gensub(/^.*\[(.*)\]:$/, "\\1", 1, $0) - next -} -{ - if (C[$1] && $2 ~ /^[TW]$/) - seen=$1 - else if ($1 ~ /^([.]|)__(libc|pthread)_enable_asynccancel$/ && $2 == "U") - seen_enable=1 - else if ($1 ~ /^([.]|)__(libc|pthread)_disable_asynccancel$/ && $2 == "U") - seen_disable=1 -} -END { - exit ret -}' || exit - shift -done diff --git a/nptl/tst-cancel2.c b/nptl/tst-cancel2.c index 1a74992..3d34169 100644 --- a/nptl/tst-cancel2.c +++ b/nptl/tst-cancel2.c @@ -33,6 +33,9 @@ tf (void *arg) char buf[100000]; while (write (fd[1], buf, sizeof (buf)) > 0); + /* The write can return a value higher than 0 (meaning partial write) + due the SIGCANCEL, but the thread may still pending cancellation. */ + pthread_testcancel (); return (void *) 42l; } diff --git a/nptl/tst-cancel20.c b/nptl/tst-cancel20.c index 51b558e..614708a 100644 --- a/nptl/tst-cancel20.c +++ b/nptl/tst-cancel20.c @@ -49,6 +49,9 @@ sh_body (void) puts ("read succeeded"); exit (1); } + /* The read can return a value higher than 0 (meaning partial reads) + due the SIGCANCEL, but the thread may still pending cancellation. */ + pthread_testcancel (); pthread_cleanup_pop (0); } @@ -84,7 +87,8 @@ tf_body (void) puts ("read succeeded"); exit (1); } - + /* Check for partial read. */ + pthread_testcancel (); read (fd[0], &c, 1); pthread_cleanup_pop (0); diff --git a/nptl/tst-cancel21.c b/nptl/tst-cancel21.c index b54f236..b1370e1 100644 --- a/nptl/tst-cancel21.c +++ b/nptl/tst-cancel21.c @@ -50,6 +50,9 @@ sh_body (void) puts ("read succeeded"); exit (1); } + /* The write can return a value higher than 0 (meaning partial write) + due the SIGCANCEL, but the thread may still pending cancellation. */ + pthread_testcancel (); pthread_cleanup_pop (0); } @@ -85,6 +88,8 @@ tf_body (void) puts ("read succeeded"); exit (1); } + /* Check partial read. */ + pthread_testcancel (); read (fd[0], &c, 1); diff --git a/nptl/tst-cancel26.c b/nptl/tst-cancel26.c new file mode 100644 index 0000000..9a370d0 --- /dev/null +++ b/nptl/tst-cancel26.c @@ -0,0 +1,68 @@ +/* Copyright (C) 2015 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 + . */ + +#include +#include +#include +#include +#include +#include + +static void * +tf (void *arg) +{ + int e, r; + + errno = 0; + + /* This is a cancellation point, but we should not be cancelled. */ + r = write (-1, 0, 0); + e = errno; + + /* Check that the cancelling syscall wrapper has handled the error correctly. */ + if (r != -1 || errno != EBADF) + { + printf ("write returned %d, errno %d\n", r, e); + exit (1); + } + + return NULL; +} + +static int +do_test (void) +{ + pthread_t th; + + if (pthread_create (&th, NULL, tf, NULL) != 0) + { + puts ("create failed"); + exit (1); + } + + void *r; + if (pthread_join (th, &r) != 0) + { + puts ("join failed"); + exit (1); + } + + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/nptl/tst-cancel27.c b/nptl/tst-cancel27.c new file mode 100644 index 0000000..aee25c9 --- /dev/null +++ b/nptl/tst-cancel27.c @@ -0,0 +1,70 @@ +/* Copyright (C) 2015 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 + . */ + +#include +#include +#include +#include +#include +#include + +static void * +tf (void *arg) +{ + int e, r; + + errno = 0; + + pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); + + /* This is a cancellation point, but we should not be cancelled. */ + r = write (-1, 0, 0); + e = errno; + + /* Check that the cancelling syscall wrapper has handled the error correctly. */ + if (r != -1 || errno != EBADF) + { + printf ("write returned %d, errno %d\n", r, e); + exit (1); + } + + return NULL; +} + +static int +do_test (void) +{ + pthread_t th; + + if (pthread_create (&th, NULL, tf, NULL) != 0) + { + puts ("create failed"); + exit (1); + } + + void *r; + if (pthread_join (th, &r) != 0) + { + puts ("join failed"); + exit (1); + } + + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/nptl/tst-cancel4.c b/nptl/tst-cancel4.c index e50afd7..0a41d95 100644 --- a/nptl/tst-cancel4.c +++ b/nptl/tst-cancel4.c @@ -38,8 +38,10 @@ #include #include -#include "pthreadP.h" - +/* The signal used for asynchronous cancelation. */ +#ifndef SIGCANCEL +# define SIGCANCEL __SIGRTMIN +#endif /* Since STREAMS are not supported in the standard Linux kernel and there we don't advertise STREAMS as supported is no need to test @@ -247,6 +249,9 @@ tf_write (void *arg) char buf[WRITE_BUFFER_SIZE]; memset (buf, '\0', sizeof (buf)); s = write (fd, buf, sizeof (buf)); + /* The write can return a value higher than 0 (meaning partial write) + due the SIGCANCEL, but the thread may still pending cancellation. */ + pthread_testcancel (); pthread_cleanup_pop (0); @@ -1143,6 +1148,8 @@ tf_send (void *arg) char mem[700000]; send (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0); + /* Check for partial send. */ + pthread_testcancel (); pthread_cleanup_pop (0); @@ -1425,6 +1432,38 @@ tf_open (void *arg) exit (1); } +static void * +tf_open64 (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); + } + + 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); + + open64 ("Makefile", O_RDONLY); + + pthread_cleanup_pop (0); + + printf ("%s: open returned\n", __FUNCTION__); + + exit (1); +} static void * tf_close (void *arg) @@ -1510,6 +1549,46 @@ tf_pread (void *arg) exit (1); } +static void * +tf_pread64 (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which pread() + // blocks we can enable this test to run in both rounds. + abort (); + + tempfd = open64 ("Makefile", O_RDONLY); + if (tempfd == -1) + { + printf ("%s: cannot open64 Makefile\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[10]; + pread64 (tempfd, mem, sizeof (mem), 0); + + pthread_cleanup_pop (0); + + printf ("%s: pread64 returned\n", __FUNCTION__); + + exit (1); +} static void * tf_pwrite (void *arg) @@ -1554,6 +1633,48 @@ tf_pwrite (void *arg) exit (1); } +static void * +tf_pwrite64 (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which pwrite() + // blocks we can enable this test to run in both rounds. + abort (); + + char fname[] = "/tmp/tst-cancel4-fd-XXXXXX"; + tempfd = mkstemp (fname); + if (tempfd == -1) + { + printf ("%s: mkstemp failed\n", __FUNCTION__); + exit (1); + } + unlink (fname); + + 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[10]; + pwrite64 (tempfd, mem, sizeof (mem), 0); + + pthread_cleanup_pop (0); + + printf ("%s: pwrite64 returned\n", __FUNCTION__); + + exit (1); +} static void * tf_fsync (void *arg) @@ -2141,9 +2262,12 @@ static struct ADD_TEST (recvfrom, 2, 0), ADD_TEST (recvmsg, 2, 0), ADD_TEST (open, 2, 1), + ADD_TEST (open64, 2, 1), ADD_TEST (close, 2, 1), ADD_TEST (pread, 2, 1), + ADD_TEST (pread64, 2, 1), ADD_TEST (pwrite, 2, 1), + ADD_TEST (pwrite64, 2, 1), ADD_TEST (fsync, 2, 1), ADD_TEST (fdatasync, 2, 1), ADD_TEST (msync, 2, 1),