* [pushed 1/2] [gdb/testsuite] Extend gdb.tui/tuiterm.exp
2026-10-16 9:18 [pushed 0/2] [gdb/testsuite] More tuiterm maintenance Tom de Vries
@ 2026-10-16 9:18 ` Tom de Vries
2026-10-16 9:18 ` [pushed 2/2] [gdb/testsuite] Factor out Term::_copy_lines Tom de Vries
1 sibling, 0 replies; 3+ messages in thread
From: Tom de Vries @ 2026-10-16 9:18 UTC (permalink / raw)
To: gdb-patches
Add a few more corner-case tests in gdb.tui/tuiterm.exp.
Tested on x86_64-linux.
---
gdb/testsuite/gdb.tui/tuiterm.exp | 52 +++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/gdb/testsuite/gdb.tui/tuiterm.exp b/gdb/testsuite/gdb.tui/tuiterm.exp
index 7c3aabaf6ea..4966800c0bb 100644
--- a/gdb/testsuite/gdb.tui/tuiterm.exp
+++ b/gdb/testsuite/gdb.tui/tuiterm.exp
@@ -177,6 +177,18 @@ proc test_insert_characters { } {
} 0 1
}
+proc test_insert_characters_2 { } {
+ # As in test_insert_characters, but start at initial state.
+ Term::_move_cursor 0 0
+ Term::_csi_@ 20
+ check "insert characters 4" {
+ " "
+ "ijklmnop"
+ "qrstuvwx"
+ "yz01234 "
+ } 0 0
+}
+
proc test_pan_down { } {
Term::_move_cursor 1 2
Term::_csi_S
@@ -204,6 +216,18 @@ proc test_pan_down { } {
} 1 2
}
+proc test_pan_down_2 { } {
+ # As in test_pan_down, but start at initial state.
+ Term::_move_cursor 0 0
+ Term::_csi_S 100
+ check "pan down, initial state, excessive arg" {
+ " "
+ " "
+ " "
+ " "
+ } 0 0
+}
+
proc test_pan_up { } {
Term::_move_cursor 1 2
Term::_csi_T
@@ -231,6 +255,18 @@ proc test_pan_up { } {
} 1 2
}
+proc test_pan_up_2 { } {
+ # As in test_pan_up, but start at initial state.
+ Term::_move_cursor 0 0
+ Term::_csi_T 100
+ check "pan up, initial state, excessive arg" {
+ " "
+ " "
+ " "
+ " "
+ } 0 0
+}
+
proc test_cursor_up { } {
Term::_move_cursor 2 3
@@ -457,6 +493,18 @@ proc test_delete_line { } {
} 3 0
}
+proc test_delete_line_2 { } {
+ # Excessive param at initial state.
+ Term::_move_cursor 3 2
+ Term::_csi_M 100
+ check "delete line, excessive param" {
+ "abcdefgh"
+ "ijklmnop"
+ " "
+ " "
+ } 3 2
+}
+
proc test_delete_character { } {
Term::_move_cursor 2 1
@@ -742,6 +790,7 @@ foreach_with_prefix test {
test_linefeed_scroll
test_carriage_return
test_insert_characters
+ test_insert_characters_2
test_cursor_up
test_cursor_down
test_cursor_forward
@@ -753,6 +802,7 @@ foreach_with_prefix test {
test_erase_in_display
test_erase_in_line
test_delete_line
+ test_delete_line_2
test_delete_character
test_erase_character
test_repeat
@@ -760,7 +810,9 @@ foreach_with_prefix test {
test_insert_line
test_insert_line_2
test_pan_up
+ test_pan_up_2
test_pan_down
+ test_pan_down_2
} {
run_one_test_small $test
}
--
2.51.0
^ permalink raw reply [flat|nested] 3+ messages in thread* [pushed 2/2] [gdb/testsuite] Factor out Term::_copy_lines
2026-10-16 9:18 [pushed 0/2] [gdb/testsuite] More tuiterm maintenance Tom de Vries
2026-10-16 9:18 ` [pushed 1/2] [gdb/testsuite] Extend gdb.tui/tuiterm.exp Tom de Vries
@ 2026-10-16 9:18 ` Tom de Vries
1 sibling, 0 replies; 3+ messages in thread
From: Tom de Vries @ 2026-10-16 9:18 UTC (permalink / raw)
To: gdb-patches
Factor out Term::_copy_lines.
No functional changes.
Tested on x86_64-linux.
---
gdb/testsuite/lib/tuiterm.exp | 77 ++++++++++++++++++-----------------
1 file changed, 40 insertions(+), 37 deletions(-)
diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp
index 6140d32872f..edabadeb1a3 100644
--- a/gdb/testsuite/lib/tuiterm.exp
+++ b/gdb/testsuite/lib/tuiterm.exp
@@ -148,6 +148,35 @@ proc Term::_copy_line { from to } {
}
}
+# Helper function. Copy the lines [SY, EY) to [DY, ...). Return the size of
+# the source range.
+proc Term::_copy_lines { sy ey dy } {
+ set cnt [expr {max($ey - $sy, 0)}]
+ if {$cnt == 0} {
+ # Empty source range.
+ return $cnt
+ }
+
+ if {$sy == $dy} {
+ # Copy has no effect.
+ return $cnt
+ }
+
+ # Handle overlapping source and destination ranges by choosing iteration
+ # order.
+ if {$sy > $dy} {
+ for {set n 0} {$n < $cnt} {incr n} {
+ _copy_line [expr {$sy + $n}] [expr {$dy + $n}]
+ }
+ } else {
+ for {set n [expr {$cnt - 1}]} {$n >= 0} {incr n -1} {
+ _copy_line [expr {$sy + $n}] [expr {$dy + $n}]
+ }
+ }
+
+ return $cnt
+}
+
# Linefeed.
proc Term::_ctl_0x0a {} {
_log_cur "Line feed" {
@@ -162,10 +191,7 @@ proc Term::_ctl_0x0a {} {
# cursor back on the screen. But we wrap the
# scrolling inside a while loop just to be on the safe
# side.
- for {set y 0} {$y < $_rows - 1} {incr y} {
- set next_y [expr {$y + 1}]
- _copy_line $next_y $y
- }
+ _copy_lines 1 $_rows 0
incr _cur_row -1
_clear_lines $_cur_row $_rows
@@ -485,15 +511,10 @@ proc Term::_csi_L {args} {
set arg [expr {min($arg, $_rows - $_cur_row)}]
- set y [expr {$_rows - $arg - 1}]
- set next_y [expr {$_rows - 1}]
- while {$y >= $_cur_row} {
- _copy_line $y $next_y
- incr y -1
- incr next_y -1
- }
+ set dy [expr {$_cur_row + $arg}]
+ _copy_lines $_cur_row [expr {$_rows - $arg}] $dy
- _clear_lines $_cur_row [expr {$_cur_row + $arg}]
+ _clear_lines $_cur_row $dy
}
}
@@ -507,14 +528,10 @@ proc Term::_csi_M {args} {
variable _cur_row
variable _rows
- set y $_cur_row
- set next_y [expr {$y + $count}]
- while {$next_y < $_rows} {
- _copy_line $next_y $y
- incr y
- incr next_y
- }
- _clear_lines $y $_rows
+ set sy [expr {$_cur_row + $count}]
+ set copy_cnt [_copy_lines $sy $_rows $_cur_row]
+
+ _clear_lines [expr {$_cur_row + $copy_cnt}] $_rows
}
}
@@ -560,16 +577,9 @@ proc Term::_csi_S {args} {
# margins. If/when that changes, then the following will
# need to be updated.
- set dy 0
- set y $count
+ set copy_cnt [_copy_lines $count $_rows 0]
- while {$y < $_rows} {
- _copy_line $y $dy
- incr y 1
- incr dy 1
- }
-
- _clear_lines $dy $_rows
+ _clear_lines $copy_cnt $_rows
}
}
@@ -590,14 +600,7 @@ proc Term::_csi_T {args} {
# margins. If/when that changes, then the following will
# need to be updated.
- set y [expr {$_rows - $count - 1}]
- set dy [expr {$_rows - 1}]
-
- while {$dy >= $count} {
- _copy_line $y $dy
- incr y -1
- incr dy -1
- }
+ _copy_lines 0 [expr {$_rows - $count}] $count
_clear_lines 0 $count
}
--
2.51.0
^ permalink raw reply [flat|nested] 3+ messages in thread