public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] Fix gdb.base/fork-running-state.exp race
Date: Wed, 28 Mar 2018 15:06:00 -0000	[thread overview]
Message-ID: <20180328150630.18319-1-palves@redhat.com> (raw)

On my multi-target branch I was occasionaly seeing a FAIL like this:

  (gdb) PASS: gdb.base/fork-running-state.exp: detach-on-fork=off: follow-fork=parent: non-stop: kill parent
  [Inferior 2 (process 32672) exited normally]
  kill inferior 2
  warning: Inferior ID 2 is not running.
  (gdb) FAIL: gdb.base/fork-running-state.exp: detach-on-fork=off: follow-fork=parent: non-stop: kill child (the program exited)
  ... other similar fails ...

Turns out to be a testcase bug/race.  A tweak like this increases the
changes of hitting the race substancially:

  --- a/gdb/testsuite/gdb.base/fork-running-state.c
  +++ b/gdb/testsuite/gdb.base/fork-running-state.c
  @@ -29,7 +29,7 @@ fork_child (void)
   {
     while (1)
       {
  -      sleep (1);
  +      usleep (100);


The testcase has two processes, parent and child fork.  The problem is
that the child exits itself if it notices the parent is gone, but the
testcase .exp does not expect that.

I first wrote a patch that handled the different combinations of
non-stop/detach-on-fork/follow-fork/schedule-multiple, making the .exp
file know when to expect the child to exit itself vs when to kill it
explicitly, but the result was that the code to kill the parent and
child was getting about as large as the test code that is the actual
point of the testcase, above the kills.

So I scratched that approach and came up with a simpler patch --
simply make the child not exit itself when the parent exits.

The .exp file is going to kill both parent and child explicitly, and,
main() already calls alarm() as a safeguard.  I don't think we lose
anything.

gdb/testsuite/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* gdb.base/fork-running-state.c (fork_child): Don't exit if parent
	exits.  Instead loop running forever.
	(fork_parent): Run forever too.
---
 gdb/testsuite/gdb.base/fork-running-state.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/gdb/testsuite/gdb.base/fork-running-state.c b/gdb/testsuite/gdb.base/fork-running-state.c
index 233b515831..8ea4739609 100644
--- a/gdb/testsuite/gdb.base/fork-running-state.c
+++ b/gdb/testsuite/gdb.base/fork-running-state.c
@@ -28,30 +28,18 @@ static int
 fork_child (void)
 {
   while (1)
-    {
-      sleep (1);
-
-      /* Exit if GDB kills the parent.  */
-      if (getppid () != save_parent)
-	break;
-      if (kill (getppid (), 0) != 0)
-	break;
-    }
+    pause ();
 
   return 0;
 }
 
-/* The fork parent.  Just runs forever waiting for the child to
-   exit.  */
+/* The fork parent.  Just runs forever.  */
 
 static int
 fork_parent (void)
 {
-  if (wait (NULL) == -1)
-    {
-      perror ("wait");
-      return 1;
-    }
+  while (1)
+    pause ();
 
   return 0;
 }
-- 
2.14.3

             reply	other threads:[~2018-03-28 15:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-28 15:06 Pedro Alves [this message]
2018-03-30  6:23 ` Simon Marchi
2018-04-10 14:05   ` Pedro Alves

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=20180328150630.18319-1-palves@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.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 read-only IMAP folder(s) and NNTP newsgroup(s).