blob: cb1b6c8edac2045ab4651ff6cd3c2168bd6de70e [file]
# Copyright 2023-2026 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Check tuiterm procs that interact with gdb as well as tuiterm.
tuiterm_env
proc test_accept_gdb_output { } {
if { $::action_cnt == [llength $::actions] } {
return 0
}
set action [lindex $::actions $::action_cnt]
incr ::action_cnt
uplevel $action
return 1
}
proc test_send_gdb { string } {
set expected [lindex $::expect_send $::send_cnt]
gdb_assert { [string equal $string $expected] }
incr ::send_cnt
}
with_override Term::accept_gdb_output test_accept_gdb_output {
with_override send_gdb test_send_gdb {
foreach_with_prefix border { "" "|" } {
with_test_prefix "Term::command match" {
Term::_setup 4 20
set send_cnt 0
set expect_send { foo\n }
set action_cnt 0
set actions {
{
Term::_insert "${::border}(gdb) foo"
}
{
Term::_ctl_0x0d
Term::_ctl_0x0a
Term::_insert "${::border}(gdb) "
}
}
gdb_assert { [Term::command "foo"] }
}
with_test_prefix "Term::command mismatch" {
Term::_setup 4 20
set send_cnt 0
set expect_send { foo\n }
set action_cnt 0
set actions {
{
Term::_insert "$::border (gdb) foo"
}
{
Term::_ctl_0x0d
Term::_ctl_0x0a
Term::_insert "${::border}(gdb) "
}
}
gdb_assert { ![Term::command "foo"] }
}
with_test_prefix "Term::command mismatch 2" {
Term::_setup 4 20
set send_cnt 0
set expect_send { foo\n }
set action_cnt 0
set actions {
{
Term::_insert "${::border}(gdb) foo"
}
{
Term::_ctl_0x0d
Term::_ctl_0x0a
Term::_insert "${::border} (gdb) "
}
}
gdb_assert { ![Term::command "foo"] }
}
with_test_prefix Term::wait_for {
Term::_setup 4 20
set send_cnt 0
set expect_send {}
set action_cnt 0
set actions {
{
Term::_insert "(gdb) "
}
}
gdb_assert { [Term::wait_for ""] }
}
with_test_prefix "Term::wait_for 2" {
Term::_setup 4 20
set send_cnt 0
set expect_send {}
set action_cnt 0
set actions {
{
Term::_move_cursor 0 0
Term::_insert "${::border}(gdb) "
set pos $::Term::_cur_col
Term::_insert "foo"
Term::_move_cursor 19 0
Term::_insert "$::border"
Term::_move_cursor $pos 0
}
{
Term::_move_cursor 0 1
Term::_insert "${::border}(gdb) "
set pos $::Term::_cur_col
Term::_move_cursor 19 1
Term::_insert "$::border"
Term::_move_cursor $pos 1
}
}
# Wait for a prompt.
gdb_assert { [Term::wait_for ""] }
# The first action sets the cursor after the prompt on the
# first line. The second action sets the cursor after the
# prompt on the second line. Check that wait_for returns
# after the second action, not the first.
gdb_assert { $Term::_cur_row == 1 }
}
}
}
}
proc_with_prefix unrecognized_escape_sequence {} {
if { [spawn $::srcdir/$::subdir/gdb.sh] == 0 } {
unsupported "cannot spawn gdb.sh"
return
}
switch_gdb_spawn_id $spawn_id
Term::_setup 4 20
save_vars ::timeout {
set ::timeout 1
set line { 0 0 20 1 }
# Parse "foo".
gdb_assert { [Term::wait_for_region_contents \
{*}$line \
[string_to_regexp "foo"]] } \
"foo"
# Parse "\033(%5".
gdb_assert { ![Term::accept_gdb_output 0] } \
"fail to parse escape sequence"
gdb_assert { [Term::wait_for_region_contents \
{*}$line \
[string_to_regexp "^\[(%5"]] } \
"echoed escape sequence"
}
Term::dump_screen
close $spawn_id
clear_gdb_spawn_id
}
unrecognized_escape_sequence