From patchwork Fri Dec 8 18:07:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 846389 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=uclibc-ng.org (client-ip=2a00:1828:2000:679::23; helo=helium.openadk.org; envelope-from=devel-bounces@uclibc-ng.org; receiver=) Received: from helium.openadk.org (helium.openadk.org [IPv6:2a00:1828:2000:679::23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ytgM25k4nz9s7F for ; Sat, 9 Dec 2017 05:08:14 +1100 (AEDT) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id A8A54105B5; Fri, 8 Dec 2017 19:08:11 +0100 (CET) X-Original-To: devel@uclibc-ng.org Delivered-To: devel@helium.openadk.org Received: from smtprelay.synopsys.com (smtprelay4.synopsys.com [198.182.47.9]) by helium.openadk.org (Postfix) with ESMTPS id 37819105B5 for ; Fri, 8 Dec 2017 19:08:10 +0100 (CET) Received: from mailhost.synopsys.com (mailhost2.synopsys.com [10.13.184.66]) by smtprelay.synopsys.com (Postfix) with ESMTP id EC59524E2041; Fri, 8 Dec 2017 10:08:08 -0800 (PST) Received: from mailhost.synopsys.com (localhost [127.0.0.1]) by mailhost.synopsys.com (Postfix) with ESMTP id D8E53909; Fri, 8 Dec 2017 10:08:08 -0800 (PST) Received: from us01wehtc1.internal.synopsys.com (us01wehtc1.internal.synopsys.com [10.12.239.235]) by mailhost.synopsys.com (Postfix) with ESMTP id A3B2C8F6; Fri, 8 Dec 2017 10:08:08 -0800 (PST) Received: from IN01WEHTCB.internal.synopsys.com (10.144.199.106) by us01wehtc1.internal.synopsys.com (10.12.239.235) with Microsoft SMTP Server (TLS) id 14.3.266.1; Fri, 8 Dec 2017 10:08:08 -0800 Received: from IN01WEHTCA.internal.synopsys.com (10.144.199.103) by IN01WEHTCB.internal.synopsys.com (10.144.199.105) with Microsoft SMTP Server (TLS) id 14.3.266.1; Fri, 8 Dec 2017 23:38:05 +0530 Received: from vineetg-Latitude-E7450.internal.synopsys.com (10.10.161.67) by IN01WEHTCA.internal.synopsys.com (10.144.199.243) with Microsoft SMTP Server (TLS) id 14.3.266.1; Fri, 8 Dec 2017 23:38:05 +0530 From: Vineet Gupta To: Date: Fri, 8 Dec 2017 10:07:56 -0800 Message-ID: <1512756476-2452-1-git-send-email-vgupta@synopsys.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1512755276-1705-1-git-send-email-vgupta@synopsys.com> References: <1512755276-1705-1-git-send-email-vgupta@synopsys.com> MIME-Version: 1.0 X-Originating-IP: [10.10.161.67] Cc: Cupertino Miranda , Vineet Gupta , linux-snps-arc@lists.infradead.org Subject: [uclibc-ng-devel] [PATCH v2] Fix subtle race in tst-cancel2 / tst-cancelx2 X-BeenThere: devel@uclibc-ng.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: uClibc-ng Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: devel-bounces@uclibc-ng.org Sender: "devel" When ran on ARC, these tests would ocassionally fail | [ARCLinux]# for i in 1 2 3 4 5 ; do ./tst-cancel2; echo $?; done | write succeeded | result is wrong: expected 0xffffffff, got 0x1 | 1 <-- fail | 0 <-- pass | 0 <--- pass | 0 <-- pass | write succeeded | result is wrong: expected 0xffffffff, got 0x1 | 1 <-- fail Same test (which originated form glibc) doesn't fail in glibc builds. Turns out there's a subtle race in uclibc version The test creates a new thread, makes it do a looong write call, and parent then cancels the thread, expecting it to unwind out of write call cleanly. However the write (even for 10k bytes) could finish before parent gets a chance to resume and/or cancel it, causing the occasional failure. Fix this subtelty by making it write not just once but forever. Cc: Cupertino Miranda Signed-off-by: Vineet Gupta --- Change since v1: fix typos in changelogs --- test/nptl/tst-cancel2.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/nptl/tst-cancel2.c b/test/nptl/tst-cancel2.c index 45c9e8ea957a..08dd13b10f37 100644 --- a/test/nptl/tst-cancel2.c +++ b/test/nptl/tst-cancel2.c @@ -32,11 +32,7 @@ tf (void *arg) write blocks. */ char buf[100000]; - if (write (fd[1], buf, sizeof (buf)) == sizeof (buf)) - { - puts ("write succeeded"); - return (void *) 1l; - } + while (write (fd[1], buf, sizeof (buf)) > 0); return (void *) 42l; }