Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@codesourcery.com>
To: gdb-patches@sourceware.org
Cc: Marek Polacek <mpolacek@redhat.com>,
	Joel Brobecker <brobecker@adacore.com>
Subject: Re: [RFC] Fixing gdb.base/completion.exp (PR testsuite/12649)
Date: Thu, 28 Apr 2011 15:14:00 -0000	[thread overview]
Message-ID: <201104281614.31962.pedro@codesourcery.com> (raw)
In-Reply-To: <201104281519.21615.pedro@codesourcery.com>

On Thursday 28 April 2011 15:19:21, Pedro Alves wrote:
> On Wednesday 27 April 2011 18:40:32, Marek Polacek wrote:
> > On 04/27/2011 05:23 PM, Pedro Alves wrote:
> > > What are these problems exactly?
> > 
> > Duh.  Now I'm not sure what I've meant when writing this.  But
> > you cannot, for instance, use the '\t' in gdb_test "blahblah\t",
> > since this will end up with "ERROR: Undefined command".
> 
> Are you sure?  I did't see that when I try it.
> 
> > > I also wonder what's the rationale for the sleeps in the
> > > current implementation?
> > 
> > Probably some imperfect way to avoid races--so the buffer would
> > be read at once after that sleep.
> 
> Yeah.
> 
> send_gdb "show output\t"
> sleep 1
> gdb_expect  {
>         -re "^show output-radix $"\
>             { send_gdb "\n"
>               gdb_expect {
>                       -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
>                                         { pass "complete 'show output'"}
>                       -re ".*$gdb_prompt $" { fail "complete 'show output'"}
>                       timeout           {fail "(timeout) complete 'show output'"}
>                      }
>             }
>         -re "^show output$"\
>             { send_gdb "\n"
>                gdb_expect {
>                       -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
>                                         { fail "complete 'show output'"}
>                       -re ".*$gdb_prompt $" { fail "complete 'show output'"}
>                       timeout           { fail "(timeout) complete 'show output'"}
>                      }
> 
>              }
> 
>         -re ".*$gdb_prompt $"       { fail "complete 'show output'" }
>         timeout         { fail "(timeout) complete 'show output'" }
>         }
> 
> The "^show output$" regex will match if expect happens
> to not see the expanded output-radix in the buffer yet.  I don't
> see a reason for that regex, so I think we should just remove it in this case.
> 
> And I'd much rather we do this (remote the races) as first step instead
> of completely rewriting the whole test file into something completely
> different...
> 
> The other races are similar in spirit.  It's caused by having a
> single gdb_expect with regexes like:
> 
>                       -re "address.*types.*$gdb_prompt info $" {}
>                       -re ".*$gdb_prompt $" {}
> 
> This is racy because the recond regex will also match
> "address.*types.*$gdb_prompt" if "$gdb_prompt " happens to
> be in the buffer but "info " isn't yet.
> 
> Please try the patch below, and let me know what you think.
> A follow up step would convert/simplify the send_gdb+gdb_expects
> into gdb_test&friends.

Here's a better one.  I forgot to run the test _without_ Jan's read1
hack before, which revealed we should remove the end of line anchors
after the prompt as well, when matching the result of showing the
tab completion options, given that there'll be text afterwards (the
current command is left on readline's current line buffer), e.g.:

 (gdb) set follow-fork-mode 
 child   parent  
 (gdb) set follow-fork-mode 

(no test required eating the previous leftover in the buffer,
e.g., due to some ^ anchor, so I didn't bother with it)

-- 
Pedro Alves

2011-04-28  Pedro Alves  <pedro@codesourcery.com>

	Fix races.
	* gdb.base/completion.exp: Remove all sleep calls.  Remove
	unnecessary regexs.  Don't explicitly expect anything after the
	prompt.  Eat the prompt if necessary.

---
 gdb/testsuite/gdb.base/completion.exp |  142 +++++++++-------------------------
 1 file changed, 41 insertions(+), 101 deletions(-)

Index: src/gdb/testsuite/gdb.base/completion.exp
===================================================================
--- src.orig/gdb/testsuite/gdb.base/completion.exp	2011-04-28 14:02:22.000000000 +0100
+++ src/gdb/testsuite/gdb.base/completion.exp	2011-04-28 16:05:15.125644002 +0100
@@ -92,11 +92,10 @@ if ![runto_main] then {
 }
 
 set oldtimeout1 $timeout
-set timeout 30
+set timeout 10
 
 
 send_gdb "hfgfh\t"
-sleep 1
 gdb_expect  {
         -re "^hfgfh\\\x07$"\
             { send_gdb "\n"
@@ -114,7 +113,6 @@ gdb_expect  {
 #exp_internal 0
 
 send_gdb "show output\t"
-sleep 1
 gdb_expect  {
         -re "^show output-radix $"\
             { send_gdb "\n"
@@ -125,16 +123,6 @@ gdb_expect  {
                       timeout           {fail "(timeout) complete 'show output'"}
                      }
             }
-        -re "^show output$"\
-            { send_gdb "\n"
-               gdb_expect {
-                      -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
-                                        { fail "complete 'show output'"}
-                      -re ".*$gdb_prompt $" { fail "complete 'show output'"}
-                      timeout           { fail "(timeout) complete 'show output'"}
-                     }
-
-             }
 
         -re ".*$gdb_prompt $"       { fail "complete 'show output'" }
         timeout         { fail "(timeout) complete 'show output'" }
@@ -142,7 +130,6 @@ gdb_expect  {
 
 
 send_gdb "show output-\t"
-sleep 1
 gdb_expect  {
         -re "^show output-radix $"\
             { send_gdb "\n"
@@ -153,27 +140,15 @@ gdb_expect  {
                       timeout           {fail "(timeout) complete 'show output-'"}
                      }
             }
-        -re "^show output-$"\
-            { send_gdb "\n"
-               gdb_expect {
-                      -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
-                                        { fail "complete 'show output-'"}
-                      -re ".*$gdb_prompt $" { fail "complete 'show output-'"}
-                      timeout           { fail "(timeout) complete 'show output-'"}
-                     }
-
-             }
 
         -re ".*$gdb_prompt $"       { fail "complete 'show output-'" }
         timeout         { fail "(timeout) complete 'show output-'" }
         }
 
 send_gdb "p\t"
-sleep 1
 gdb_expect  {
         -re "^p\\\x07$"\
             { send_gdb "\n"
-	      sleep 1
               gdb_expect {
                       -re "The history is empty\\..*$gdb_prompt $"\
                                         { pass "complete 'p'"}
@@ -186,11 +161,9 @@ gdb_expect  {
         }
 
 send_gdb "p \t"
-sleep 3
 gdb_expect  {
         -re "^p \\\x07$"\
             { send_gdb "\n"
-	      sleep 1
               gdb_expect {
                       -re "The history is empty\\..*$gdb_prompt $"\
                                         { pass "complete 'p '"}
@@ -204,7 +177,6 @@ gdb_expect  {
 
 
 send_gdb "info t foo\t"
-sleep 1
 gdb_expect  {
         -re "^info t foo\\\x07$"\
             { send_gdb "\n"
@@ -220,7 +192,6 @@ gdb_expect  {
         }
 
 send_gdb "info t\t"
-sleep 1
 gdb_expect  {
         -re "^info t\\\x07$"\
             { send_gdb "\n"
@@ -238,7 +209,6 @@ gdb_expect  {
 
 
 send_gdb "info t \t"
-sleep 1
 gdb_expect  {
         -re "^info t \\\x07$"\
             { send_gdb "\n"
@@ -256,7 +226,6 @@ gdb_expect  {
 
 
 send_gdb "info asdfgh\t"
-sleep 1
 gdb_expect  {
         -re "^info asdfgh\\\x07$"\
             { send_gdb "\n"
@@ -274,7 +243,6 @@ gdb_expect  {
 
 
 send_gdb "info asdfgh \t"
-sleep 1
 gdb_expect  {
         -re "^info asdfgh \\\x07$"\
             { send_gdb "\n"
@@ -291,7 +259,6 @@ gdb_expect  {
         }
 
 send_gdb "info\t"
-sleep 1
 gdb_expect  {
         -re "^info $"\
             { send_gdb "\n"
@@ -307,7 +274,6 @@ gdb_expect  {
         }
 
 send_gdb "info \t"
-sleep 1
 gdb_expect  {
         -re "^info \\\x07$"\
             { send_gdb "\n"
@@ -322,14 +288,12 @@ gdb_expect  {
         timeout         { fail "(timeout) complete 'info '" }
         }
 
-
 send_gdb "info \t"
-sleep 1
 gdb_expect  {
         -re "^info \\\x07$"\
             { send_gdb "\t"
               gdb_expect {
-                      -re "address.*types.*$gdb_prompt info $"\
+                      -re "address.*types.*$gdb_prompt "\
                           { send_gdb "\n"
                             gdb_expect {
                                      -re "\"info\".*unambiguous\\..*$gdb_prompt $"\
@@ -365,7 +329,6 @@ gdb_expect  {
 
 
 send_gdb "p \"break1\t"
-sleep 1
 gdb_expect  {
         -re "^p \"break1\\\x07$"\
             { send_gdb "\n"
@@ -381,20 +344,12 @@ gdb_expect  {
 		    timeout           {fail "(timeout) complete 'p \"break1'"}
 		}
 	    }
-	-re "^p \"break1.*$"
-	    {	send_gdb "\n"
-		gdb_expect {
-		    -re ".*$gdb_prompt $" { fail "complete 'p \"break1'"}
-		    timeout           {fail "(timeout) complete 'p \"break1'"}
-		}
-	    }
         -re ".*$gdb_prompt $"       { fail "complete 'p \"break1'" }
         timeout         { fail "(timeout) complete 'p \"break1'" }
         }
 
 setup_xfail "*-*-*"
 send_gdb "p \"break1.\t"
-sleep 1
 gdb_expect  {
         -re "^p \"break1\\.\\\x07$"\
             { send_gdb "\n"
@@ -410,7 +365,7 @@ gdb_expect  {
 		    timeout           {fail "(timeout) complete 'p \"break1.'"}
 		}
 	    }
-	-re "^p \"break1\\..*$"
+	-re "^p \"break1\\...*$"
 	    {	send_gdb "\n"
 		gdb_expect {
 		    -re ".*$gdb_prompt $" { fail "complete 'p \"break1.'"}
@@ -422,7 +377,6 @@ gdb_expect  {
         }
 
 send_gdb "p 'arg\t"
-sleep 1
 gdb_expect  {
         -re "^p 'arg\\\x07$"\
             { send_gdb "\n"
@@ -438,12 +392,11 @@ gdb_expect  {
         }
 
 send_gdb "p 'arg\t"
-sleep 1
 gdb_expect {
     -re "^p 'arg\\\x07$" {
 	send_gdb "\t"
 	gdb_expect {
-	    -re ".*argv.*$gdb_prompt p 'arg$" {
+	    -re ".*argv.*$gdb_prompt " {
 		send_gdb "\n"
 		gdb_expect {
 		    -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
@@ -503,7 +456,6 @@ gdb_expect {
 # So, I'm hoping that there is no system with a static library variable named
 # `no_var_by_this_name'.
 send_gdb "p no_var_named_this-arg\t"
-sleep 1
 gdb_expect {
     -re "^p no_var_named_this-arg\\\x07$" {
         send_gdb "\n"
@@ -528,12 +480,11 @@ gdb_expect {
 }
 
 send_gdb "p no_var_named_this-arg\t"
-sleep 1
 gdb_expect {
     -re "^p no_var_named_this-arg\\\x07$" {
 	send_gdb "\t"
 	gdb_expect {
-	    -re ".*argv.*$gdb_prompt p no_var_named_this-arg$" {
+	    -re ".*argv.*$gdb_prompt " {
 		send_gdb "\n"
 		gdb_expect {
 		    -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
@@ -548,28 +499,26 @@ gdb_expect {
 		}
 	    }
 	    -re "(There are $decimal possibilities\\.  Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
-		send_gdb "n"
+		send_gdb "n\n"
+
+		# Eat the prompt
 		gdb_expect {
-		    -re "\\(gdb\\) p no_var_named_this-arg$" {
-			send_gdb "\n"
-			gdb_expect {
-			    -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
-				pass "complete (2) 'p no_var_named_this-arg'"
-			    }
-			    -re ".*$gdb_prompt $" {
-				fail "complete (2) 'p no_var_named_this-arg'"
-			    }
-			    timeout {
-                                fail "(timeout) complete (2) 'p no_var_named_this-arg'"
-                            }
-			}
+		    -re "$gdb_prompt " {
+			pass "complete (2) 'p no_var_named_this-arg' (eat prompt)"
+		    }
+		    timeout { fail "(timeout) complete (2) 'p no_var_named_this-' (eat prompt)" }
+		}
+
+		gdb_expect {
+		    -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
+			pass "complete (2) 'p no_var_named_this-arg'"
 		    }
 		    -re ".*$gdb_prompt $" {
-                        fail "complete (2) 'p no_var_named_this-arg'"
-                    }
+			fail "complete (2) 'p no_var_named_this-arg'"
+		    }
 		    timeout {
-                        fail "(timeout) complete (2) 'p no_var_named_this-arg'"
-                    }
+			fail "(timeout) complete (2) 'p no_var_named_this-arg'"
+		    }
 		}
 	    }
 	    -re ".*$gdb_prompt $" {
@@ -583,37 +532,35 @@ gdb_expect {
 }
 
 send_gdb "p no_var_named_this-\t"
-sleep 1
 gdb_expect  {
     -re "^p no_var_named_this-\\\x07$" {
 	send_gdb "\t"
+
 	gdb_expect {
 	    -re "(There are $decimal possibilities\\.  Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
-		send_gdb "n"
+		send_gdb "n\n"
+
+		# Eat the prompt
 		gdb_expect {
-		    -re "\\(gdb\\) p no_var_named_this-$" {
-			send_gdb "\n"
-			gdb_expect {
-			    -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
-				pass "complete (2) 'p no_var_named_this-'"
-			    }
-			    -re ".*$gdb_prompt $" {
-				fail "complete (2) 'p no_var_named_this-'"
-			    }
-			    timeout {
-                                fail "(timeout) complete (2) 'p no_var_named_this-'"
-                            }
-			}
+		    -re "$gdb_prompt " {
+			pass "complete (2) 'p no_var_named_this-' (eat prompt)"
+		    }
+		    timeout { fail "(timeout) complete (2) 'p no_var_named_this-' (eat prompt)" }
+		}
+
+		gdb_expect {
+		    -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
+			pass "complete (2) 'p no_var_named_this-'"
 		    }
 		    -re ".*$gdb_prompt $" {
-                        fail "complete (2) 'p no_var_named_this-'"
-                    }
+			fail "complete (2) 'p no_var_named_this-'"
+		    }
 		    timeout {
-                        fail "(timeout) complete (2) 'p no_var_named_this-'"
-                    }
+			fail "(timeout) complete (2) 'p no_var_named_this-'"
+		    }
 		}
 	    }
-	    -re ".*argv.*$gdb_prompt p no_var_named_this-$" {
+	    -re ".*argv.*$gdb_prompt $" {
 		send_gdb "\n"
 		gdb_expect {
 		    -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
@@ -638,11 +585,9 @@ gdb_expect  {
 }
 
 send_gdb "p values\[0\].a\t"
-sleep 3
 gdb_expect  {
         -re "^p values.0..a_field $"\
             { send_gdb "\n"
-	      sleep 1
               gdb_expect {
                       -re "^.* = 0.*$gdb_prompt $"\
                                         { pass "complete 'p values\[0\].a'"}
@@ -761,7 +706,6 @@ gdb_test " " "Source directories searche
 
 
 send_gdb "complete file ./gdb.base/compl\n"
-sleep 1
 gdb_expect  {
     -re "file ./gdb.base/completion\\.exp.*$gdb_prompt $"
 	{ pass "complete-command 'file ./gdb.base/compl'"}
@@ -770,7 +714,6 @@ gdb_expect  {
 }
 
 send_gdb "file ./gdb.base/complet\t"
-sleep 1
 gdb_expect  {
         -re "^file ./gdb.base/completion\\.exp $"\
             { send_gdb "\n"
@@ -788,14 +731,12 @@ gdb_expect  {
         }
 
 send_gdb "info func marke\t"
-sleep 1
 gdb_expect  {
         -re "^info func marke.*r$"\
             {
 	      send_gdb "\t\t"
-              sleep 3
               gdb_expect {
-                      -re "marker1.*$gdb_prompt info func marker$"\
+                      -re "marker1.*$gdb_prompt "\
                       { send_gdb "\n"
                         gdb_expect {
                                 -re "All functions matching regular expression \"marker\":.*File.*break1.c:\r\nint marker1\\((void|)\\);\r\nint marker2\\(int\\).*marker3\\(char.*char.*\\).*marker4\\(long( int)?\\);.*$gdb_prompt $"\
@@ -814,9 +755,8 @@ gdb_expect  {
 
 
 send_gdb "set follow-fork-mode \t\t"
-sleep 1
 gdb_expect  {
-        -re "child.*parent.*$gdb_prompt set follow-fork-mode $"\
+        -re "child.*parent.*$gdb_prompt "\
             { send_gdb "\n"
               gdb_expect {
                       -re "Requires an argument.*child.*parent.*$gdb_prompt $"\


  reply	other threads:[~2011-04-28 15:14 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-27 14:59 Marek Polacek
2011-04-27 15:05 ` Joel Brobecker
2011-04-27 15:13   ` Tom Tromey
2011-04-27 15:23   ` Pedro Alves
2011-04-27 17:41     ` Marek Polacek
2011-04-28 14:19       ` Pedro Alves
2011-04-28 15:14         ` Pedro Alves [this message]
2011-04-29 14:10           ` Marek Polacek
2011-05-02 14:58             ` Pedro Alves
2011-05-01  9:17           ` Jan Kratochvil
2011-05-02 14:00             ` Marek Polacek
2011-05-02 14:19             ` Pedro Alves
2011-05-02 14:53               ` Jan Kratochvil
2011-05-02 15:30                 ` Pedro Alves
2011-05-02 15:44                   ` Joel Brobecker
2011-05-02 15:50                     ` Pedro Alves
2011-05-02 15:56                   ` Jan Kratochvil
2011-05-02 16:10                     ` Pedro Alves
2011-05-02 16:35                       ` Jan Kratochvil
2011-05-02 16:54                         ` Pedro Alves
2011-05-02 17:04                           ` Jan Kratochvil
2011-05-02 17:21                             ` Jan Kratochvil
2011-05-02 17:23                             ` Pedro Alves
2011-05-02 17:29                               ` Jan Kratochvil
2011-05-02 17:53                                 ` Pedro Alves
2011-05-02 17:56                                   ` Pedro Alves
2011-05-05 15:11                 ` Tom Tromey
2011-04-28 11:56 ` Marek Polacek

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=201104281614.31962.pedro@codesourcery.com \
    --to=pedro@codesourcery.com \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=mpolacek@redhat.com \
    /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