This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: MI testsuite to use PTY for inferior


On Wed, Aug 03, 2005 at 02:32:11PM -0400, Daniel Jacobowitz wrote:
> On Wed, Aug 03, 2005 at 02:23:51PM -0400, Bob Rossi wrote:
> > Sorry, I'm a little trigger happy, here's the patch.
> 
> Patch is OK with formatting corrections.

Thanks Daniel,

All applied, here's the patch.

Bob Rossi

Index: gdb/testsuite/ChangeLog
+	* gdb.mi/mi-basics.exp: Tell mi_gdb_start to use a PTY for inferior.
+	(test_setshow_inferior_tty): Add global mi_inferior_tty_name to scope.
+	Change tests to inferior-tty-set/show.
+	* gdb.mi/mi-console.exp: Tell mi_gdb_start to use a PTY for inferior.
+	(47-exec-next): Use mi_gdb_test to get GDB and Inferior output.
+	* gdb.mi/mi-syn-frame.exp: Tell mi_gdb_start to use a PTY for
+	inferior.  Use mi_gdb_test to get GDB and Inferior output.
+	* lib/mi-support.exp (mi_inferior_spawn_id): Add inferior PTY
+	descriptor.
+	(mi_inferior_tty_name): Add inferior PTY file name.
+	(mi_gdb_start): Add INFERIOR_PTY parameter.
+	(mi_gdb_test): Add IPATTERN parameter.

Index: gdb/testsuite/gdb.mi/mi-basics.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.mi/mi-basics.exp,v
retrieving revision 1.10
diff -u -r1.10 mi-basics.exp
--- gdb/testsuite/gdb.mi/mi-basics.exp	6 Jul 2005 14:54:37 -0000	1.10
+++ gdb/testsuite/gdb.mi/mi-basics.exp	3 Aug 2005 19:24:58 -0000
@@ -33,7 +33,7 @@
 set MIFLAGS "-i=mi"
 
 gdb_exit
-if [mi_gdb_start] {
+if [mi_gdb_start separate-inferior-tty] {
     continue
 }
 
@@ -238,6 +238,7 @@
 
 proc test_setshow_inferior_tty {} {
     global mi_gdb_prompt
+    global mi_inferior_tty_name
 
     # Test that the commands,
     #   -inferior-tty-set
@@ -245,8 +246,8 @@
     # are setting/getting the same data in GDB.
 
     mi_gdb_test "301-inferior-tty-show" \
-		"301\\\^done" \
-		"initial tty is empty"
+		"301\\\^done,inferior_tty_terminal=\"$mi_inferior_tty_name\"" \
+		"initial tty is mi_inferior_tty_name"
 
     mi_gdb_test "302-inferior-tty-set /dev/pts/1" \
 		"302\\\^done" \
@@ -262,7 +263,15 @@
 
     mi_gdb_test "305-inferior-tty-show" \
 		"305\\\^done" \
-		"final tty is empty"
+		"make sure tty is empty"
+
+    mi_gdb_test "306-inferior-tty-set $mi_inferior_tty_name" \
+		"306\\\^done" \
+		"set tty to mi_inferior_tty_name (the way it was)"
+
+    mi_gdb_test "307-inferior-tty-show" \
+		"307\\\^done,inferior_tty_terminal=\"$mi_inferior_tty_name\"" \
+		"verify tty is correct"
 }
 
 if [test_mi_interpreter_selection] {
Index: gdb/testsuite/gdb.mi/mi-console.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.mi/mi-console.exp,v
retrieving revision 1.14
diff -u -r1.14 mi-console.exp
--- gdb/testsuite/gdb.mi/mi-console.exp	27 Apr 2005 16:35:15 -0000	1.14
+++ gdb/testsuite/gdb.mi/mi-console.exp	3 Aug 2005 19:24:58 -0000
@@ -36,7 +36,7 @@
 set MIFLAGS "-i=mi"
 
 gdb_exit
-if [mi_gdb_start] {
+if [mi_gdb_start separate-inferior-tty] {
     continue
 }
 
@@ -54,37 +54,10 @@
 mi_run_to_main
 
 # Next over the hello() call which will produce lots of output
-send_gdb "47-exec-next\n"
-gdb_expect {
-    -re "47\\^running\r\n$mi_gdb_prompt" {
-	pass "Started step over hello"
-    }
-    timeout {
-	fail "Started step over hello (timeout)"
-    }
-}
-
-if { ![target_info exists gdb,noinferiorio]}  {
-    gdb_expect {
-	-re "@\"H\"\r\n.*@\"e\"\r\n.*@\"l\"\r\n.*@\"l\"\r\n.*@\"o\"\r\n.*@\" \"\r\n.*@\"\\\\\\\\\"\r\n.*@\"\\\\\"\"\r\n.*@\"!\"\r\n.*@\"\\\\r\"\r\n.*@\"\\\\n\"\r\n" {
-	    pass "Hello message"
-	}
-	-re "Hello" {
-
-	    # Probably a native system where GDB doesn't have direct #
-	    # control over the inferior console.  # For this to work,
-	    # GDB would need to run the inferior process # under a PTY
-	    # and then use the even-loops ability to wait on #
-	    # multiple event sources to channel the output back
-	    # through the # MI.
-
-	    kfail "gdb/623" "Hello message"
-	}
-	timeout {
-	    fail "Hello message (timeout)"
-	}
-    }
-}
+mi_gdb_test "47-exec-next" \
+	    "47\\^running" \
+	    "Testing console output" \
+	    "Hello \\\\\"!\[\r\n\]+"
     
 gdb_expect {
     -re "47\\*stopped.*$mi_gdb_prompt$" {
Index: gdb/testsuite/gdb.mi/mi-syn-frame.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.mi/mi-syn-frame.exp,v
retrieving revision 1.5
diff -u -r1.5 mi-syn-frame.exp
--- gdb/testsuite/gdb.mi/mi-syn-frame.exp	2 Aug 2005 14:21:01 -0000	1.5
+++ gdb/testsuite/gdb.mi/mi-syn-frame.exp	3 Aug 2005 19:24:58 -0000
@@ -38,7 +38,7 @@
 set my_mi_gdb_prompt "\\(gdb\\)\[ \]*\[\r\n\]*"
 
 mi_gdb_exit
-mi_gdb_start
+mi_gdb_start separate-inferior-tty
 mi_delete_breakpoints
 mi_gdb_reinitialize_dir $srcdir/$subdir
 mi_gdb_load ${binfile}
@@ -60,16 +60,10 @@
 #
 # Continue back to main()
 #
-
-send_gdb "403-exec-continue\n"
-gdb_expect {
-  -re "403\\^running\[\r\n\]+${my_mi_gdb_prompt}hi in foo\[\r\n\]+403\\\*stopped\[\r\n\]+${my_mi_gdb_prompt}$" {
-    pass "403-exec-continue"
-  }
-  timeout {
-    fail "403-exec-continue"
-  }
-}
+mi_gdb_test "403-exec-continue" \
+  "403\\^running\[\r\n\]+${my_mi_gdb_prompt}403\\\*stopped" \
+  "testing exec continue" \
+  "hi in foo\[\r\n\]\+"
 
 mi_gdb_test "404-stack-list-frames 0 0" \
   "404\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"main\",file=\".*mi-syn-frame.c\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$decimal\"\}.*\\\]" \
@@ -85,8 +79,9 @@
   "insert breakpoint subroutine"
 
 mi_gdb_test "406-data-evaluate-expression have_a_very_merry_interrupt()" \
-  "Waiting to get a signal\[\r\n\]+\\&\"The program being debugged stopped while in a function called from GDB.\\\\n\"\[\r\n\]+\\&\"When the function \\(have_a_very_merry_interrupt\\) is done executing, GDB will silently\\\\n\"\[\r\n\]+\\&\"stop \\(instead of continuing to evaluate the expression containing\\\\n\"\[\r\n\]+\\&\"the function call\\).\\\\n\"\[\r\n\]+406\\^error,msg=\"The program being debugged stopped while in a function called from GDB.\\\\nWhen the function \\(have_a_very_merry_interrupt\\) is done executing, GDB will silently\\\\nstop \\(instead of continuing to evaluate the expression containing\\\\nthe function call\\).\"" \
-  "evaluate expression have_a_very_merry_interrupt"
+  "\\&\"The program being debugged stopped while in a function called from GDB.\\\\n\"\[\r\n\]+\\&\"When the function \\(have_a_very_merry_interrupt\\) is done executing, GDB will silently\\\\n\"\[\r\n\]+\\&\"stop \\(instead of continuing to evaluate the expression containing\\\\n\"\[\r\n\]+\\&\"the function call\\).\\\\n\"\[\r\n\]+406\\^error,msg=\"The program being debugged stopped while in a function called from GDB.\\\\nWhen the function \\(have_a_very_merry_interrupt\\) is done executing, GDB will silently\\\\nstop \\(instead of continuing to evaluate the expression containing\\\\nthe function call\\).\"" \
+  "data evaluate expression" \
+  "Waiting to get a signal\[\r\n\]+"
 
 # We should have both a signal handler and a call dummy frame
 # in this next output.
@@ -96,15 +91,8 @@
   "list stack frames"
 
 
-send_gdb "408-exec-continue\n"
-gdb_expect {
-  -re "408\\^running\[\r\n\]+${my_mi_gdb_prompt}408\\\*stopped\[\r\n\]+${my_mi_gdb_prompt}$" {
-    pass "408-exec-continue"
-  }
-  timeout {
-    fail "408-exec-continue"
-  }
-}
+mi_gdb_test "408-exec-continue" \
+  "408\\^running\[\r\n\]+${my_mi_gdb_prompt}408\\\*stopped"
 
 mi_gdb_test "409-stack-list-frames 0 0" \
   "409\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"main\",file=\".*mi-syn-frame.c\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$decimal\"\}.*\\\]" \
@@ -114,7 +102,10 @@
 # Call bar() by hand, which should get an exception while running.
 # 
 
-mi_gdb_test "410-data-evaluate-expression bar()" "hi in bar\[\r\n\]+\\&\"The program being debugged was signaled while in a function called from GDB.\\\\n\"\[\r\n\]+\\&\"GDB remains in the frame where the signal was received.\\\\n\"\[\r\n\]+\\&\"To change this behavior use \\\\\"set unwindonsignal on\\\\\"\\\\n\"\[\r\n\]+\\&\"Evaluation of the expression containing the function \\(bar\\) will be abandoned.\\\\n\"\[\r\n\]+410\\^error,msg=\"The program being debugged was signaled while in a function called from GDB.\\\\nGDB remains in the frame where the signal was received.\\\\nTo change this behavior use \\\\\"set unwindonsignal on\\\\\"\\\\nEvaluation of the expression containing the function \\(bar\\) will be abandoned.\"" "call inferior function which raises exception"
+mi_gdb_test "410-data-evaluate-expression bar()" \
+  "\\&\"The program being debugged was signaled while in a function called from GDB.\\\\n\"\[\r\n\]+\\&\"GDB remains in the frame where the signal was received.\\\\n\"\[\r\n\]+\\&\"To change this behavior use \\\\\"set unwindonsignal on\\\\\"\\\\n\"\[\r\n\]+\\&\"Evaluation of the expression containing the function \\(bar\\) will be abandoned.\\\\n\"\[\r\n\]+410\\^error,msg=\"The program being debugged was signaled while in a function called from GDB.\\\\nGDB remains in the frame where the signal was received.\\\\nTo change this behavior use \\\\\"set unwindonsignal on\\\\\"\\\\nEvaluation of the expression containing the function \\(bar\\) will be abandoned.\"" \
+  "call inferior function which raises exception" \
+  "hi in bar\[\r\n\]+"
 
 mi_gdb_test "411-stack-list-frames" "411\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"bar\",file=\".*mi-syn-frame.c\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$decimal\"},frame=\{level=\"1\",addr=\"$hex\",func=\"<function called from gdb>\"\},frame=\{level=\"2\",addr=\"$hex\",func=\"main\",file=\".*mi-syn-frame.c\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$decimal\"}.*\\\]" "backtrace from inferior function at exception"
 
Index: gdb/testsuite/lib/mi-support.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/lib/mi-support.exp,v
retrieving revision 1.28
diff -u -r1.28 mi-support.exp
--- gdb/testsuite/lib/mi-support.exp	2 Aug 2005 14:21:01 -0000	1.28
+++ gdb/testsuite/lib/mi-support.exp	3 Aug 2005 19:24:58 -0000
@@ -28,6 +28,9 @@
     set mi_gdb_prompt "\[(\]gdb\[)\] \r\n"
 }
 
+global mi_inferior_spawn_id
+global mi_inferior_tty_name
+
 set MIFLAGS "-i=mi"
 
 #
@@ -81,13 +84,17 @@
 }
 
 #
-# start gdb -- start gdb running, default procedure
+# mi_gdb_start [INFERIOR_PTY] -- start gdb running, default procedure
+#
+# INFERIOR_PTY should be set to separate-inferior-tty to have the inferior work 
+# with it's own PTY. If set to same-inferior-tty, the inferior shares GDB's PTY. 
+# The default value is same-inferior-tty.
 #
 # When running over NFS, particularly if running many simultaneous
 # tests on different hosts all using the same server, things can
 # get really slow.  Give gdb at least 3 minutes to start up.
 #
-proc mi_gdb_start { } {
+proc mi_gdb_start { args } {
     global verbose
     global GDB
     global GDBFLAGS
@@ -98,6 +105,13 @@
     global MIFLAGS
 
     gdb_stop_suppressing_tests;
+    set inferior_pty no-tty
+
+    if { [llength $args] == 1} {
+	set inferior_pty [lindex $args 0]
+    }
+
+    set separate_inferior_pty [string match $inferior_pty separate-inferior-tty]
 
     # Start SID.
     if { [info procs sid_start] != "" } {
@@ -117,6 +131,16 @@
 	    exit 1
 	}
     }
+
+    # Create the new PTY for the inferior process.
+    if { $separate_inferior_pty } {
+	spawn -pty
+	global mi_inferior_spawn_id
+	global mi_inferior_tty_name
+	set mi_inferior_spawn_id $spawn_id
+	set mi_inferior_tty_name $spawn_out(slave,name)
+    }
+
     set res [remote_spawn host "$GDB -nw $GDBFLAGS $MIFLAGS [host_info gdb_opts]"];
     if { $res < 0 || $res == "" } {
 	perror "Spawning $GDB failed."
@@ -189,6 +213,19 @@
 	    warning "Couldn't set the width to 0."
 	}
     }
+    # If allowing the inferior to have its own PTY then assign the inferior
+    # its own terminal device here.
+    if { $separate_inferior_pty } {
+	send_gdb "102-inferior-tty-set $mi_inferior_tty_name\n"
+	gdb_expect 10 {
+	    -re ".*102\\\^done\r\n$mi_gdb_prompt$" {
+		verbose "redirect inferior output to new terminal device."
+	    }
+	    timeout {
+	    	warning "Couldn't redirect inferior output." 2
+	    }
+    	}
+    }
 
     return 0;
 }
@@ -511,7 +548,8 @@
     return 0
 }
 
-# mi_gdb_test COMMAND PATTERN MESSAGE -- send a command to gdb; test the result.
+# mi_gdb_test COMMAND PATTERN MESSAGE [IPATTERN] -- send a command to gdb; 
+#   test the result.
 #
 # COMMAND is the command to execute, send to GDB with send_gdb.  If
 #   this is the null string no command is sent.
@@ -520,6 +558,9 @@
 # MESSAGE is the message to be printed.  (If this is the empty string, 
 #   then sometimes we don't call pass or fail at all; I don't 
 #   understand this at all.)
+# IPATTERN is the pattern to match for the inferior's output.  This parameter
+#   is optional.  If present, it will produce a PASS if the match is 
+#   successful, and a FAIL if unsuccessful.
 #
 # Returns:
 #    1 if the test failed,
@@ -536,6 +577,10 @@
     set pattern [lindex $args 1]
     set message [lindex $args 2]
 
+    if [llength $args]==4 {
+	set ipattern [lindex $args 3]
+    }
+
     if [llength $args]==5 {
 	set question_string [lindex $args 3];
 	set response_string [lindex $args 4];
@@ -686,6 +731,23 @@
 	    set result 1
 	}
     }
+
+    # If the GDB output matched, compare the inferior output.
+    if { $result == 0 } {
+	if [ info exists ipattern ] {
+	    global mi_inferior_spawn_id
+	    expect {
+		-i $mi_inferior_spawn_id -re "$ipattern" {
+		    pass "inferior_output:$message"
+		}
+		timeout {
+		    fail "inferior output timeout"
+		    set result 1
+		}
+	    }
+        }
+    }
+
     return $result
 }
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]