Home | History | Annotate | Line # | Download | only in gdb.base
new-ui.exp revision 1.1.1.1.4.1
      1 # Copyright 2016-2017 Free Software Foundation, Inc.
      2 
      3 # This program is free software; you can redistribute it and/or modify
      4 # it under the terms of the GNU General Public License as published by
      5 # the Free Software Foundation; either version 3 of the License, or
      6 # (at your option) any later version.
      7 #
      8 # This program is distributed in the hope that it will be useful,
      9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11 # GNU General Public License for more details.
     12 #
     13 # You should have received a copy of the GNU General Public License
     14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15 
     16 standard_testfile
     17 
     18 set compile_options "debug"
     19 if {[build_executable $testfile.exp $testfile ${srcfile} ${compile_options}] == -1} {
     20     untested "failed to compile"
     21     return -1
     22 }
     23 
     24 # Ensure no output has been sent.  Use MESSAGE as test message.
     25 
     26 proc ensure_no_output {message} {
     27     global decimal
     28 
     29     # Run a command and use an anchor to make sure no output appears
     30     # before the command's expected output.
     31     gdb_test "print 999" "^print 999\r\n\\\$$decimal = 999" $message
     32 }
     33 
     34 # Run a few execution-related commands on CON1, and ensure the proper
     35 # output, or none, if appropriate, is sent to CON2.  CON1_NAME and
     36 # CON2_NAME are the names of the consoles.
     37 
     38 proc do_execution_tests {con1 con1_name con2 con2_name} {
     39     global srcfile
     40     global decimal
     41 
     42     set bp_lineno [gdb_get_line_number "set break $con1_name here"]
     43 
     44     with_spawn_id $con1 {
     45 	gdb_test "next" "global = 1;"
     46     }
     47     with_spawn_id $con2 {
     48 	ensure_no_output "next causes no spurious output on other console"
     49     }
     50 
     51     with_spawn_id $con1 {
     52 	gdb_test "break $srcfile:$bp_lineno" \
     53 	    "Breakpoint $decimal .*$srcfile, line $bp_lineno\\." \
     54 	    "set breakpoint"
     55     }
     56     with_spawn_id $con2 {
     57 	ensure_no_output "break causes no spurious output on other console"
     58     }
     59 
     60     with_spawn_id $con1 {
     61 	gdb_test "continue" "set break $con1_name here .*" "continue to breakpoint"
     62     }
     63 
     64     with_spawn_id $con2 {
     65 	set test "breakpoint hit reported on other console"
     66 	gdb_test_multiple "" $test {
     67 	    -re "Breakpoint $decimal, .* set break $con1_name here " {
     68 		pass $test
     69 	    }
     70 	}
     71     }
     72 }
     73 
     74 # The test proper.
     75 
     76 proc_with_prefix do_test {} {
     77     global srcfile testfile
     78     global gdb_prompt
     79     global gdb_spawn_id
     80     global gdb_main_spawn_id extra_spawn_id
     81 
     82     clean_restart $testfile
     83 
     84     if ![runto_main] {
     85 	untested "could not run to main"
     86 	return -1
     87     }
     88 
     89     gdb_test "new-ui" \
     90 	"usage: new-ui <interpreter> <tty>" \
     91 	"new-ui without arguments"
     92 
     93     set test "new-ui does not repeat"
     94     send_gdb "\n"
     95     gdb_test_multiple "" $test {
     96 	-re "^\r\n$gdb_prompt $" {
     97 	    pass $test
     98 	}
     99     }
    100 
    101     # Save the main UI's spawn ID.
    102     set gdb_main_spawn_id $gdb_spawn_id
    103 
    104     # Create the new PTY for the secondary console UI.
    105     spawn -pty
    106     set extra_spawn_id $spawn_id
    107     set extra_tty_name $spawn_out(slave,name)
    108     gdb_test_multiple "new-ui console $extra_tty_name" "new-ui" {
    109 	-re "New UI allocated\r\n$gdb_prompt $" {
    110 	}
    111     }
    112 
    113     with_spawn_id $extra_spawn_id {
    114 	set test "initial prompt on extra console"
    115 	gdb_test_multiple "" $test {
    116 	    -re "$gdb_prompt $" {
    117 		pass $test
    118 	    }
    119 	}
    120     }
    121 
    122     # Ensure non-execution commands in one console don't cause output
    123     # in the other consoles.
    124     with_spawn_id $gdb_main_spawn_id {
    125 	gdb_test "print 1" "^print 1\r\n\\\$1 = 1" "print on main console"
    126     }
    127     with_spawn_id $extra_spawn_id {
    128 	gdb_test "print 2" "^print 2\r\n\\\$2 = 2" "print on extra console"
    129     }
    130 
    131     # Verify that we get proper queries on the main UI, but that they are
    132     # auto-answered on secondary UIs.
    133     with_spawn_id $gdb_main_spawn_id {
    134 	gdb_test "delete" "" "delete all breakpoint on main console" \
    135 		 "Delete all breakpoints. .y or n. $" "n"
    136     }
    137     with_spawn_id $extra_spawn_id {
    138 	gdb_test "delete" \
    139 		 "Delete all breakpoints. .y or n. .answered Y; input not from terminal." \
    140 		 "delete all breakpoints on extra console"
    141     }
    142 
    143     # Run a few execution tests with the main console as the driver
    144     # console.
    145     with_test_prefix "main console" {
    146 	do_execution_tests \
    147 	    $gdb_main_spawn_id "main console" \
    148 	    $extra_spawn_id "extra console"
    149     }
    150     # Same, but with the extra console as driver.
    151     with_test_prefix "extra console" {
    152 	do_execution_tests \
    153 	    $extra_spawn_id "extra console" \
    154 	    $gdb_main_spawn_id "main console"
    155     }
    156 }
    157 
    158 # Test missing / invalid arguments.
    159 
    160 proc_with_prefix do_test_invalid_args {} {
    161     global testfile
    162 
    163     clean_restart $testfile
    164 
    165     spawn -pty
    166     set extra_tty_name $spawn_out(slave,name)
    167 
    168     # Test bad terminal path.
    169     gdb_test "new-ui console /non/existent/path" \
    170 	     "opening terminal failed: No such file or directory\." \
    171 	     "new-ui with bad terminal path"
    172 
    173     # Test bad interpreter name.
    174     gdb_test "new-ui bloop $extra_tty_name" \
    175 	     "Interpreter `bloop' unrecognized" \
    176 	     "new-ui with bad interpreter name"
    177 
    178     # Test that we can continue working normally.
    179     if ![runto_main] {
    180 	fail "could not run to main"
    181     }
    182 }
    183 
    184 do_test
    185 do_test_invalid_args
    186