From patchwork Wed Mar 28 15:06:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 26503 Received: (qmail 106515 invoked by alias); 28 Mar 2018 15:06:35 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 106446 invoked by uid 89); 28 Mar 2018 15:06:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=sleep, turns, tweak, safeguard X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 28 Mar 2018 15:06:33 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4001E8190293 for ; Wed, 28 Mar 2018 15:06:32 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id E322410AF9FE for ; Wed, 28 Mar 2018 15:06:31 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH] Fix gdb.base/fork-running-state.exp race Date: Wed, 28 Mar 2018 16:06:30 +0100 Message-Id: <20180328150630.18319-1-palves@redhat.com> 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 * 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; }