mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-20 01:50:24 +08:00
[gdb/testsuite] Simplify gdb.base/info-types.exp.tcl further
After adding support for --any in match_line, we can simplify gdb.base/info-types.exp.tcl further: we can add the "All defined types:" regexp in the output_lines list: ... set output_lines \ [list \ + "All defined types:" \ + "--any" \ $file_re \ ... Consequently, we can simplify the state machine to track a variable "found" with values: - 0 (unmatched) - 1 (matched) - -1 (mismatch). This makes the code generic enough to factor out into a new proc gdb_test_lines. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2021-06-08 Tom de Vries <tdevries@suse.de> * gdb.base/info-types.exp.tcl (match_line): Handle --any. (gdb_test_lines): Factor out of ... (run_test): ... here.
This commit is contained in:
@ -1,3 +1,9 @@
|
|||||||
|
2021-06-08 Tom de Vries <tdevries@suse.de>
|
||||||
|
|
||||||
|
* gdb.base/info-types.exp.tcl (match_line): Handle --any.
|
||||||
|
(gdb_test_lines): Factor out of ...
|
||||||
|
(run_test): ... here.
|
||||||
|
|
||||||
2021-06-08 Tom de Vries <tdevries@suse.de>
|
2021-06-08 Tom de Vries <tdevries@suse.de>
|
||||||
|
|
||||||
* gdb.base/batch-preserve-term-settings.exp (spawn_shell): Fix
|
* gdb.base/batch-preserve-term-settings.exp (spawn_shell): Fix
|
||||||
|
@ -16,7 +16,8 @@
|
|||||||
# Check that 'info types' produces the expected output for an inferior
|
# Check that 'info types' produces the expected output for an inferior
|
||||||
# containing a number of different types.
|
# containing a number of different types.
|
||||||
|
|
||||||
# Match LINE against regexp OUTPUT_LINES[IDX].
|
# Match LINE against regexp OUTPUT_LINES[IDX]. Helper function for
|
||||||
|
# gdb_test_lines.
|
||||||
proc match_line { line output_lines idx_name } {
|
proc match_line { line output_lines idx_name } {
|
||||||
upvar $idx_name idx
|
upvar $idx_name idx
|
||||||
|
|
||||||
@ -27,14 +28,17 @@ proc match_line { line output_lines idx_name } {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set re [lindex $output_lines $idx]
|
set re [lindex $output_lines $idx]
|
||||||
|
set opt 0
|
||||||
|
set any 0
|
||||||
if { $re == "--optional" } {
|
if { $re == "--optional" } {
|
||||||
# Optional, get actual regexp.
|
# Optional, get actual regexp.
|
||||||
set opt 1
|
set opt 1
|
||||||
incr idx
|
incr idx
|
||||||
set re [lindex $output_lines $idx]
|
set re [lindex $output_lines $idx]
|
||||||
} else {
|
} elseif { $re == "--any" } {
|
||||||
# Not optional.
|
set any 1
|
||||||
set opt 0
|
incr idx
|
||||||
|
set re [lindex $output_lines $idx]
|
||||||
}
|
}
|
||||||
|
|
||||||
if { [regexp $re $line] } {
|
if { [regexp $re $line] } {
|
||||||
@ -55,6 +59,10 @@ proc match_line { line output_lines idx_name } {
|
|||||||
# Try next regexp on same line.
|
# Try next regexp on same line.
|
||||||
incr idx
|
incr idx
|
||||||
continue
|
continue
|
||||||
|
} elseif { $any } {
|
||||||
|
# Try again with next line.
|
||||||
|
incr idx -1
|
||||||
|
return 0
|
||||||
} else {
|
} else {
|
||||||
# Mismatch, bail out.
|
# Mismatch, bail out.
|
||||||
return -1
|
return -1
|
||||||
@ -67,6 +75,29 @@ proc match_line { line output_lines idx_name } {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Match output of COMMAND line-by-line, using PATTERNS.
|
||||||
|
# Report pass/fail with MESSAGE.
|
||||||
|
|
||||||
|
proc gdb_test_lines { command message patterns } {
|
||||||
|
set found 0
|
||||||
|
set idx 0
|
||||||
|
if { $message == ""} {
|
||||||
|
set message $command
|
||||||
|
}
|
||||||
|
gdb_test_multiple $command $message {
|
||||||
|
-re "\r\n(\[^\r\n\]*)(?=\r\n)" {
|
||||||
|
if { $found == 0 } {
|
||||||
|
set line $expect_out(1,string)
|
||||||
|
set found [match_line $line $patterns idx]
|
||||||
|
}
|
||||||
|
exp_continue
|
||||||
|
}
|
||||||
|
-re -wrap "" {
|
||||||
|
gdb_assert { $found == 1 } $gdb_test_name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Run 'info types' test, compiling the test file for language LANG,
|
# Run 'info types' test, compiling the test file for language LANG,
|
||||||
# which should be either 'c' or 'c++'.
|
# which should be either 'c' or 'c++'.
|
||||||
proc run_test { lang } {
|
proc run_test { lang } {
|
||||||
@ -94,6 +125,8 @@ proc run_test { lang } {
|
|||||||
if { $lang == "c++" } {
|
if { $lang == "c++" } {
|
||||||
set output_lines \
|
set output_lines \
|
||||||
[list \
|
[list \
|
||||||
|
"All defined types:" \
|
||||||
|
"--any" \
|
||||||
$file_re \
|
$file_re \
|
||||||
"98:\[\t \]+CL;" \
|
"98:\[\t \]+CL;" \
|
||||||
"42:\[\t \]+anon_struct_t;" \
|
"42:\[\t \]+anon_struct_t;" \
|
||||||
@ -129,6 +162,8 @@ proc run_test { lang } {
|
|||||||
} else {
|
} else {
|
||||||
set output_lines \
|
set output_lines \
|
||||||
[list \
|
[list \
|
||||||
|
"All defined types:" \
|
||||||
|
"--any" \
|
||||||
$file_re \
|
$file_re \
|
||||||
"52:\[\t \]+typedef enum {\\.\\.\\.} anon_enum_t;" \
|
"52:\[\t \]+typedef enum {\\.\\.\\.} anon_enum_t;" \
|
||||||
"45:\[\t \]+typedef struct {\\.\\.\\.} anon_struct_t;" \
|
"45:\[\t \]+typedef struct {\\.\\.\\.} anon_struct_t;" \
|
||||||
@ -157,33 +192,7 @@ proc run_test { lang } {
|
|||||||
""]
|
""]
|
||||||
}
|
}
|
||||||
|
|
||||||
set state 0
|
gdb_test_lines "info types" "" $output_lines
|
||||||
set idx 0
|
|
||||||
gdb_test_multiple "info types" "" {
|
|
||||||
-re "\r\nAll defined types:" {
|
|
||||||
if { $state == 0 } { set state 1 } else { set state -1 }
|
|
||||||
exp_continue
|
|
||||||
}
|
|
||||||
-re "^\r\n(\[^\r\n\]*)(?=\r\n)" {
|
|
||||||
if { $state == 1 } {
|
|
||||||
set line $expect_out(1,string)
|
|
||||||
set res [match_line $line $output_lines idx]
|
|
||||||
if { $res == 1 } {
|
|
||||||
set state 2
|
|
||||||
} elseif { $res == -1 } {
|
|
||||||
set state -2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exp_continue
|
|
||||||
}
|
|
||||||
-re -wrap "" {
|
|
||||||
if { $state == 2} {
|
|
||||||
pass $gdb_test_name
|
|
||||||
} else {
|
|
||||||
fail "$gdb_test_name (state == $state)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test $lang
|
run_test $lang
|
||||||
|
Reference in New Issue
Block a user