From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id Bc/iI3I4Q2G6BQAAWB0awg (envelope-from ) for ; Thu, 16 Sep 2021 08:28:34 -0400 Received: by simark.ca (Postfix, from userid 112) id 812A51EE25; Thu, 16 Sep 2021 08:28:34 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 40F9D1EDF7 for ; Thu, 16 Sep 2021 08:28:33 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D61593857422 for ; Thu, 16 Sep 2021 12:28:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D61593857422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1631795311; bh=m5yAeQXJj7m1S1Cej+4jHxded+Jor2DQLux5Se5YgGs=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=xwNv0wKMKgyiV0BZmMu3X2wOX36F1Qlin4S3BtoIWu6MeQPzG1cbFELSVT2gEbKZR RA58swEjiVjdED92U1mr6mh05AHOrUPCu+7IByKtaHF2+mlDh23XZcuHQscYTnI0qk uer6ZuwtYww0Hmjvz0Asb/psDLcHnLkyr51caZU8= Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 8F0033858C39 for ; Thu, 16 Sep 2021 12:28:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8F0033858C39 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id C5A0D223BE for ; Thu, 16 Sep 2021 12:28:12 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id AEDD313480 for ; Thu, 16 Sep 2021 12:28:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id jwVrJVw4Q2HZPgAAMHmgww (envelope-from ) for ; Thu, 16 Sep 2021 12:28:12 +0000 Date: Thu, 16 Sep 2021 14:28:10 +0200 To: gdb-patches@sourceware.org Subject: [committed][gdb/testsuite] Fix interrupted sleep in multi-threaded test-cases Message-ID: <20210916122809.GA13596@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi, When running test-case gdb.threads/continue-pending-status.exp with native, I have: ... (gdb) continue^M Continuing.^M PASS: gdb.threads/continue-pending-status.exp: attempt 0: continue for ctrl-c ^C^M Thread 1 "continue-pendin" received signal SIGINT, Interrupt.^M [Switching to Thread 0x7ffff7fc4740 (LWP 1276)]^M 0x00007ffff758e4c0 in __GI___nanosleep () at nanosleep.c:27^M 27 return SYSCALL_CANCEL (nanosleep, requested_time, remaining);^M (gdb) PASS: gdb.threads/continue-pending-status.exp: attempt 0: caught interrupt ... but with target board unix/-m32, I run into: ... (gdb) continue^M Continuing.^M PASS: gdb.threads/continue-pending-status.exp: attempt 0: continue for ctrl-c [Thread 0xf74aeb40 (LWP 31957) exited]^M [Thread 0xf7cafb40 (LWP 31956) exited]^M [Inferior 1 (process 31952) exited normally]^M (gdb) Quit^M ... The problem is that the sleep (300) call at the end of main is interrupted, which causes the inferior to exit before the ctrl-c can be send. This problem is described at "Interrupted System Calls" in the docs, and the suggested solution (using a sleep loop) indeed fixes the problem. Fix this instead using the more prevalent: ... alarm (300); ... while (1) sleep (1); ... which is roughly equivalent because the sleep is called at the end of main, but slightly better because it guards against hangs from the start rather than from the end of main. Likewise in gdb.base/watch_thread_num.exp. Likewise in gdb.btrace/enable-running.exp, but use the sleep loop there, because the sleep is not called at the end of main. Tested on x86_64-linux. Committed to trunk. Thanks, - Tom [gdb/testsuite] Fix interrupted sleep in multi-threaded test-cases --- gdb/testsuite/gdb.base/watch_thread_num.c | 7 ++++++- gdb/testsuite/gdb.btrace/enable-running.c | 4 +++- gdb/testsuite/gdb.threads/continue-pending-status.c | 6 +++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/gdb/testsuite/gdb.base/watch_thread_num.c b/gdb/testsuite/gdb.base/watch_thread_num.c index 9a6f825b844..46029cf1291 100644 --- a/gdb/testsuite/gdb.base/watch_thread_num.c +++ b/gdb/testsuite/gdb.base/watch_thread_num.c @@ -43,6 +43,8 @@ int main () { void *thread_result; long i; + alarm (180); + pthread_barrier_init (&threads_started_barrier, NULL, NUM + 1); pthread_barrier_init (&threads_started_barrier2, NULL, 2); @@ -61,7 +63,10 @@ int main () { pthread_join (threads[0], NULL); - sleep (180); /* first child thread exited */ + /* first child thread exited */ + + while (1) + sleep (1); exit (EXIT_SUCCESS); } diff --git a/gdb/testsuite/gdb.btrace/enable-running.c b/gdb/testsuite/gdb.btrace/enable-running.c index 8f76241a892..2db3b7d28cb 100644 --- a/gdb/testsuite/gdb.btrace/enable-running.c +++ b/gdb/testsuite/gdb.btrace/enable-running.c @@ -25,7 +25,9 @@ test (void *arg) { /* Let's hope this is long enough for GDB to enable tracing and check that everything is working as expected. */ - sleep (10); + int unslept = 10; + while (unslept > 0) + unslept = sleep (unslept); return arg; } diff --git a/gdb/testsuite/gdb.threads/continue-pending-status.c b/gdb/testsuite/gdb.threads/continue-pending-status.c index 53e5944a0a9..965a071fe32 100644 --- a/gdb/testsuite/gdb.threads/continue-pending-status.c +++ b/gdb/testsuite/gdb.threads/continue-pending-status.c @@ -41,6 +41,8 @@ main (void) { int i; + alarm (300); + pthread_barrier_init (&barrier, NULL, NUM_THREADS); for (i = 0; i < NUM_THREADS; i++) @@ -53,6 +55,8 @@ main (void) assert (res == 0); } - sleep (300); + while (1) + sleep (1); + return 0; }