linux-snps-arc.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Vineet.Gupta1@synopsys.com (Vineet Gupta)
To: linux-snps-arc@lists.infradead.org
Subject: [PATCH] Fix subtle race in tst-cancel2 / tst-cancelx2
Date: Fri, 8 Dec 2017 09:47:56 -0800	[thread overview]
Message-ID: <1512755276-1705-1-git-send-email-vgupta@synopsys.com> (raw)

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 fnish befor
eparent gets a chance ti run and/or cancel - causing the occasional
failire.

Cc: Cupertino Miranda <cmiranda at synopsys.com>
Fix this subtelty by making it write not just once but forever.

Signed-off-by: Vineet Gupta <vgupta at synopsys.com>
---
 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;
 }
-- 
2.7.4

             reply	other threads:[~2017-12-08 17:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-08 17:47 Vineet Gupta [this message]
2017-12-08 18:07 ` [PATCH v2] Fix subtle race in tst-cancel2 / tst-cancelx2 Vineet Gupta
2017-12-18 19:18   ` [uclibc-ng-devel] " Vineet Gupta
2017-12-18 19:40     ` Waldemar Brodkorb

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1512755276-1705-1-git-send-email-vgupta@synopsys.com \
    --to=vineet.gupta1@synopsys.com \
    --cc=linux-snps-arc@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).