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