From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id 3C9943858437; Tue, 11 Oct 2022 00:46:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3C9943858437 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665449193; bh=SEXS26UD8zgJKpir4yuAUJwjF7tvkonXMNpUV3WheJQ=; h=From:To:Subject:Date:From; b=J7XNSsLmxFaaj25mV1bLeZW+lSQCPIKKpMuys7JKL51uoFgAy4Y/cfykaN3qFv7Ot fao/PywprHNc0r9kztrjOZX8FrijT3996RxWu6PjIO7y23QxL29dMGVrmdfMwwvEp+ rFOMBJ4+FHMNYvws8v4d8XvoDZQHEjzklCK2xPSs= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/testsuite: fix race in gdb.base/async-shell.exp X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 4a5d6345a0bb18f8688540025036647509f56f81 X-Git-Newrev: f6c874187a5a8b6f7108fff3b668395de45f9904 Message-Id: <20221011004633.3C9943858437@sourceware.org> Date: Tue, 11 Oct 2022 00:46:33 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Df6c874187a5a= 8b6f7108fff3b668395de45f9904 commit f6c874187a5a8b6f7108fff3b668395de45f9904 Author: Simon Marchi Date: Sun Oct 9 21:21:53 2022 -0400 gdb/testsuite: fix race in gdb.base/async-shell.exp =20 I see some random failures in this test: =20 FAIL: gdb.base/async-shell.exp: run & (timeout) =20 It can be reliably reproduced on a recent enough GNU/Linux with this change: =20 diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 44cc28b30051..2a3c8253ba5a 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -1301,6 +1301,7 @@ proc gdb_test_multiple { command message args= } { } set gdb_test_name "$message" =20 + sleep 2 set result 0 set code [catch {gdb_expect $code} string] =20 "recent enough" means a system where libpthread.so was merged with libc.so, so at least glibc 2.34. =20 The problem is that the `run &` command prints some things after the prompt: =20 (gdb) [Thread debugging using libthread_db enabled] Using host libthread_db library "/usr/lib/../lib/libthread_db.so.1". =20 If expect is quick enough, it will consume only up to the prompt. But if it is slow enough, it will consume those messages at the same time as the prompt, in which case the gdb_test used for "run &" won't match. By default, the prompt used by gdb_test uses a `$` to anchor the match at the end of the buffer. If there's anything following the prompt, it won't match. =20 The diff above adds a delay between sending the command and consuming the output, giving GDB more time to output the messages, giving a good chance that expect consumes them at the same time as the prompt. =20 This is normally handled by using gdb_test_multiple and specifying a pattern that ends with "$gdb_prompt", but not a trailing $. I think this is common enough that it deserves its own gdb_test option. Therefore, add the -no-anchor-prompt option to gdb_test, and gdb_test_no_output for completeness. Use it in gdb.base/async-shell.exp. =20 Change-Id: I9051d8800d1c10a2e95db1a575991f7723492f1b Approved-By: Tom de Vries Diff: --- gdb/testsuite/gdb.base/async-shell.exp | 2 +- gdb/testsuite/lib/gdb.exp | 29 ++++++++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/gdb/testsuite/gdb.base/async-shell.exp b/gdb/testsuite/gdb.bas= e/async-shell.exp index e2d71826bab..2c09863ad59 100644 --- a/gdb/testsuite/gdb.base/async-shell.exp +++ b/gdb/testsuite/gdb.base/async-shell.exp @@ -34,7 +34,7 @@ save_vars { GDBFLAGS } { =20 set gdbindex_warning_re "warning: Skipping \[^\r\n\]+ \\.gdb_index section= \[^\r\n\]*\r\nDo \"set use-deprecated-index-sections on\" before the file = is read\r\nto use the section anyway\\." =20 -gdb_test "run &" "Starting program: \[^\r\n\]*(\r\n$gdbindex_warning_re)?" +gdb_test -no-prompt-anchor "run &" "Starting program: \[^\r\n\]*(\r\n$gdbi= ndex_warning_re)?" =20 # `sleep 5' here would workaround the bug, do not sleep here. # "shell" could eat waitpid event from the asynchronous inferior process. diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index ac28ede1b08..f53d90edd00 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -861,9 +861,18 @@ proc gdb_internal_error_resync {} { } =20 # Fill in the default prompt if PROMPT_REGEXP is empty. -proc fill_in_default_prompt {prompt_regexp} { +# +# If WITH_ANCHOR is true and the default prompt is used, append a `$` at t= he end +# of the regexp, to anchor the match at the end of the buffer. +proc fill_in_default_prompt {prompt_regexp with_anchor} { if { "$prompt_regexp" =3D=3D "" } { - return "$::gdb_prompt $" + set prompt "$::gdb_prompt " + + if { $with_anchor } { + append prompt "$" + } + + return $prompt } return $prompt_regexp } @@ -993,7 +1002,7 @@ proc gdb_test_multiple { command message args } { error "Too few arguments to gdb_test_multiple" } =20 - set prompt_regexp [fill_in_default_prompt $prompt_regexp] + set prompt_regexp [fill_in_default_prompt $prompt_regexp true] =20 if { $message =3D=3D "" } { set message $command @@ -1369,6 +1378,10 @@ proc gdb_test_multiline { name args } { # # -prompt PROMPT_REGEXP specifies a regexp matching the expected prompt # after the command output. If empty, defaults to "$gdb_prompt $". +# -no-prompt-anchor specifies that if the default prompt regexp is used, it +# should not be anchored at the end of the buffer. This means that the +# pattern can match even if there is stuff output after the prompt. Doe= s not +# have any effect if -prompt is specified. # -lbl specifies that line-by-line matching will be used. # -nopass specifies that a PASS should not be issued. # @@ -1383,6 +1396,7 @@ proc gdb_test { args } { =20 parse_args { {prompt ""} + {no-prompt-anchor} {lbl} {nopass} } @@ -1398,7 +1412,7 @@ proc gdb_test { args } { set message $command } =20 - set prompt [fill_in_default_prompt $prompt] + set prompt [fill_in_default_prompt $prompt [expr !${no-prompt-anchor}]] =20 set saw_question 0 =20 @@ -1475,20 +1489,21 @@ if { [tcl_version_at_least 8 5] =3D=3D 0 } { # gdb_test_no_output [-prompt PROMPT_REGEXP] [-nopass] COMMAND [MESSAGE] # Send a command to GDB and verify that this command generated no output. # -# See gdb_test for a description of the -prompt, -nopass, COMMAND, and -# MESSAGE parameters. +# See gdb_test for a description of the -prompt, -no-prompt-anchor, -nopas= s, +# COMMAND, and MESSAGE parameters. =20 proc gdb_test_no_output { args } { global gdb_prompt =20 parse_args { {prompt ""} + {no-prompt-anchor} {nopass} } =20 lassign $args command message =20 - set prompt [fill_in_default_prompt $prompt] + set prompt [fill_in_default_prompt $prompt [expr !${no-prompt-anchor}]] =20 set command_regex [string_to_regexp $command] gdb_test_multiple $command $message -prompt $prompt {