From patchwork Tue Dec 13 14:02:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 61870 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 519FA3875B5D for ; Tue, 13 Dec 2022 14:03:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 519FA3875B5D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670940183; bh=swaF2fuXKyf1YojrZhb1kwV+JBlJ5wkTsxw2xR/u2NU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=bpRqjfQB250Oh6WV8UrAespmxuJY/p1sii5661VMfXjzWWf0r1G6kBx4VzNaN7NsY XdZIfIUrPFJTXl3A9KTdO9K/PI4U8WtGdmE78lTj5hnmKkq2Ta8n+y9it5DCaNkiYM Dg64/21ZejUi0aj5VOqeYu6Pbn/UMQhuYoqBJUD0= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id E0774383C7FF for ; Tue, 13 Dec 2022 14:02:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E0774383C7FF 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-out2.suse.de (Postfix) with ESMTPS id 243381FDD2 for ; Tue, 13 Dec 2022 14:02:38 +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 11413138F9 for ; Tue, 13 Dec 2022 14:02:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ybonA/6FmGMtYgAAMHmgww (envelope-from ) for ; Tue, 13 Dec 2022 14:02:38 +0000 To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/testsuite] Fix race in gdb.threads/detach-step-over.exp Date: Tue, 13 Dec 2022 15:02:37 +0100 Message-Id: <20221213140237.32325-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Once in a while I run into: ... FAIL: gdb.threads/detach-step-over.exp: \ breakpoint-condition-evaluation=host: target-non-stop=off: non-stop=off: \ displaced=off: iter 1: all threads running ... In can easily reproduce this by doing: ... # Wait a bit, to give time for the threads to hit the # breakpoint. - sleep 1 return true ... Fix this by counting the running threads in a loop, effectively allowing 10 seconds (instead of 1) for the threads to start running, but only sleeping if needed. Reduces total execution time from 1m27s to 56s. Tested on x86_64-linux. --- .../gdb.threads/detach-step-over.exp | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) base-commit: fa59ab98685e4b5431d2be423f449df5069a454e diff --git a/gdb/testsuite/gdb.threads/detach-step-over.exp b/gdb/testsuite/gdb.threads/detach-step-over.exp index 38d796620cb..225d3ab5313 100644 --- a/gdb/testsuite/gdb.threads/detach-step-over.exp +++ b/gdb/testsuite/gdb.threads/detach-step-over.exp @@ -187,10 +187,6 @@ proc prepare_test_iter {testpid non_stop attempt attempts tid_re} { } } - # Wait a bit, to give time for the threads to hit the - # breakpoint. - sleep 1 - return true } @@ -233,7 +229,8 @@ proc_with_prefix test_detach_command {condition_eval target_non_stop non_stop di set running_count 0 set interrupted 0 - gdb_test_multiple "info threads" "all threads running" { + set running_expected [expr ($::n_threads + 1) * 2] + gdb_test_multiple "info threads" "threads running" { -re "\\(running\\)" { incr running_count exp_continue @@ -254,10 +251,31 @@ proc_with_prefix test_detach_command {condition_eval target_non_stop non_stop di } } } - -re "$::gdb_prompt $" { - gdb_assert {$running_count == ($::n_threads + 1) * 2} \ - $gdb_test_name + -re "$::gdb_prompt " { + } + } + + if { $interrupted == 0 } { + set iterations 0 + set max_iterations 10 + while { $running_count < $running_expected } { + sleep 1 + set running_count 0 + gdb_test_multiple "info threads" "threads running" { + -re "\\(running\\)" { + incr running_count + exp_continue + } + -re "$::gdb_prompt " { + } + } + incr iterations + if { $iterations == $max_iterations } { + break + } } + gdb_assert {$running_count == $running_expected} \ + "all threads running" } gdb_test "detach" "Detaching from.*"