Home | History | Annotate | Line # | Download | only in gdb.base
new-ui.exp revision 1.1.1.2
      1  1.1.1.2  christos # Copyright 2016-2017 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 	untested "could not run to main"
     86      1.1  christos 	return -1
     87      1.1  christos     }
     88      1.1  christos 
     89      1.1  christos     gdb_test "new-ui" \
     90      1.1  christos 	"usage: new-ui <interpreter> <tty>" \
     91      1.1  christos 	"new-ui without arguments"
     92      1.1  christos 
     93      1.1  christos     set test "new-ui does not repeat"
     94      1.1  christos     send_gdb "\n"
     95      1.1  christos     gdb_test_multiple "" $test {
     96      1.1  christos 	-re "^\r\n$gdb_prompt $" {
     97      1.1  christos 	    pass $test
     98      1.1  christos 	}
     99      1.1  christos     }
    100      1.1  christos 
    101      1.1  christos     # Save the main UI's spawn ID.
    102      1.1  christos     set gdb_main_spawn_id $gdb_spawn_id
    103      1.1  christos 
    104      1.1  christos     # Create the new PTY for the secondary console UI.
    105      1.1  christos     spawn -pty
    106      1.1  christos     set extra_spawn_id $spawn_id
    107      1.1  christos     set extra_tty_name $spawn_out(slave,name)
    108      1.1  christos     gdb_test_multiple "new-ui console $extra_tty_name" "new-ui" {
    109      1.1  christos 	-re "New UI allocated\r\n$gdb_prompt $" {
    110      1.1  christos 	}
    111      1.1  christos     }
    112      1.1  christos 
    113      1.1  christos     with_spawn_id $extra_spawn_id {
    114      1.1  christos 	set test "initial prompt on extra console"
    115      1.1  christos 	gdb_test_multiple "" $test {
    116      1.1  christos 	    -re "$gdb_prompt $" {
    117      1.1  christos 		pass $test
    118      1.1  christos 	    }
    119      1.1  christos 	}
    120      1.1  christos     }
    121      1.1  christos 
    122      1.1  christos     # Ensure non-execution commands in one console don't cause output
    123      1.1  christos     # in the other consoles.
    124      1.1  christos     with_spawn_id $gdb_main_spawn_id {
    125      1.1  christos 	gdb_test "print 1" "^print 1\r\n\\\$1 = 1" "print on main console"
    126      1.1  christos     }
    127      1.1  christos     with_spawn_id $extra_spawn_id {
    128      1.1  christos 	gdb_test "print 2" "^print 2\r\n\\\$2 = 2" "print on extra console"
    129      1.1  christos     }
    130      1.1  christos 
    131  1.1.1.2  christos     # Verify that we get proper queries on the main UI, but that they are
    132  1.1.1.2  christos     # auto-answered on secondary UIs.
    133  1.1.1.2  christos     with_spawn_id $gdb_main_spawn_id {
    134  1.1.1.2  christos 	gdb_test "delete" "" "delete all breakpoint on main console" \
    135  1.1.1.2  christos 		 "Delete all breakpoints. .y or n. $" "n"
    136  1.1.1.2  christos     }
    137  1.1.1.2  christos     with_spawn_id $extra_spawn_id {
    138  1.1.1.2  christos 	gdb_test "delete" \
    139  1.1.1.2  christos 		 "Delete all breakpoints. .y or n. .answered Y; input not from terminal." \
    140  1.1.1.2  christos 		 "delete all breakpoints on extra console"
    141  1.1.1.2  christos     }
    142  1.1.1.2  christos 
    143      1.1  christos     # Run a few execution tests with the main console as the driver
    144      1.1  christos     # console.
    145      1.1  christos     with_test_prefix "main console" {
    146      1.1  christos 	do_execution_tests \
    147      1.1  christos 	    $gdb_main_spawn_id "main console" \
    148      1.1  christos 	    $extra_spawn_id "extra console"
    149      1.1  christos     }
    150      1.1  christos     # Same, but with the extra console as driver.
    151      1.1  christos     with_test_prefix "extra console" {
    152      1.1  christos 	do_execution_tests \
    153      1.1  christos 	    $extra_spawn_id "extra console" \
    154      1.1  christos 	    $gdb_main_spawn_id "main console"
    155      1.1  christos     }
    156      1.1  christos }
    157      1.1  christos 
    158      1.1  christos # Test missing / invalid arguments.
    159      1.1  christos 
    160  1.1.1.2  christos proc_with_prefix do_test_invalid_args {} {
    161      1.1  christos     global testfile
    162      1.1  christos 
    163      1.1  christos     clean_restart $testfile
    164      1.1  christos 
    165      1.1  christos     spawn -pty
    166      1.1  christos     set extra_tty_name $spawn_out(slave,name)
    167      1.1  christos 
    168      1.1  christos     # Test bad terminal path.
    169      1.1  christos     gdb_test "new-ui console /non/existent/path" \
    170      1.1  christos 	     "opening terminal failed: No such file or directory\." \
    171      1.1  christos 	     "new-ui with bad terminal path"
    172      1.1  christos 
    173      1.1  christos     # Test bad interpreter name.
    174      1.1  christos     gdb_test "new-ui bloop $extra_tty_name" \
    175      1.1  christos 	     "Interpreter `bloop' unrecognized" \
    176      1.1  christos 	     "new-ui with bad interpreter name"
    177      1.1  christos 
    178      1.1  christos     # Test that we can continue working normally.
    179      1.1  christos     if ![runto_main] {
    180      1.1  christos 	fail "could not run to main"
    181      1.1  christos     }
    182      1.1  christos }
    183      1.1  christos 
    184  1.1.1.2  christos do_test
    185  1.1.1.2  christos do_test_invalid_args
    186