[v2,5/5] gdb/testsuite: Test completion of register names in expressions

Message ID 20240828014916.162446-6-nt8r@protonmail.com
State New
Headers
Series Tab complete convenience variables |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Antonio Rische Aug. 28, 2024, 1:50 a.m. UTC
  ---
 gdb/testsuite/gdb.base/completion.exp | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
  

Comments

Keith Seitz Aug. 30, 2024, 7:35 p.m. UTC | #1
On 8/27/24 6:50 PM, Antonio Rische wrote:

Please add a commit message.

> ---
>   gdb/testsuite/gdb.base/completion.exp | 25 ++++++++++++++++++++-----
>   1 file changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
> index 131c36e23..2af9104fd 100644
> --- a/gdb/testsuite/gdb.base/completion.exp
> +++ b/gdb/testsuite/gdb.base/completion.exp
> @@ -139,17 +139,24 @@ gdb_test "complete set trace-buffer-size unl" "set trace-buffer-size unlimited"
>   set regs_output [capture_command_output "mt print registers" \
>   		     ".*Name.*Nr.*Rel.*Offset.*Size.*Type.\[^\n\]*\n"]
>   append regs_output "\n"
> -append regs_output [capture_command_output "mt print reggroups" \
> -			".*Group.*Type\[^\n]*\n"]
> -append regs_output "\n"
>   append regs_output [capture_command_output "mt print user-registers" \
>   		     ".*Name.*Nr\[^\n]*\n"]
> +set reg_groups_output [capture_command_output "mt print reggroups" \
> +			".*Group.*Type\[^\n]*\n"]
> +append reg_groups_output "\n"
> +
>   set all_regs {}
>   foreach {- reg} [regexp -all -inline -line {^\s+(\w+)} $regs_output] {
>       lappend all_regs $reg
>   }
>   
> -set all_regs [join [lsort -unique $all_regs]]
> +set all_reg_groups {}
> +foreach {- group} [regexp -all -inline -line {^\s+(\w+)} $reg_groups_output] {
> +    lappend all_reg_groups $group
> +}
> +
> +set all_regs_and_groups [concat $all_regs $all_reg_groups]
> +set all_regs_and_groups [join [lsort -unique $all_regs_and_groups]]
>   
>   # ... and then compare them to the completion of "info registers".
>   
> @@ -159,7 +166,7 @@ foreach {-> reg} [regexp -all -inline -line {^info registers (\w+\S*)} $regs_out
>       lappend completed_regs $reg
>   }
>   set completed_regs [join [lsort $completed_regs]]
> -gdb_assert {$all_regs eq $completed_regs} "complete 'info registers '"
> +gdb_assert {$all_regs_and_groups eq $completed_regs} "complete 'info registers '"
>   
>   # Tests below are about tab-completion, which doesn't work if readline
>   # library isn't used.  Check it first.
> @@ -168,6 +175,14 @@ if { ![readline_is_used] } {
>       return -1
>   }
>   
> +# Test "print $<registername>" completion
> +set complete_dollar_output [capture_command_output "complete print $" ""]
> +
> +foreach {- reg} $all_regs {
> +    set found_reg {[string first $reg $complete_dollar_output] != -1}
> +    gdb_assert $found_reg "complete 'print \$' contains $reg"
> +}
> +
>   # The bulk of this test script pre-dates the completion-support
>   # library, and should probably (where possible) be converted.
>   # However, for now, new tests are being added using this library.

I think this is okay. Thank you for writing tests!

Reviewed-by: Keith Seitz <keiths@redhat.com>

Keith
  

Patch

diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
index 131c36e23..2af9104fd 100644
--- a/gdb/testsuite/gdb.base/completion.exp
+++ b/gdb/testsuite/gdb.base/completion.exp
@@ -139,17 +139,24 @@  gdb_test "complete set trace-buffer-size unl" "set trace-buffer-size unlimited"
 set regs_output [capture_command_output "mt print registers" \
 		     ".*Name.*Nr.*Rel.*Offset.*Size.*Type.\[^\n\]*\n"]
 append regs_output "\n"
-append regs_output [capture_command_output "mt print reggroups" \
-			".*Group.*Type\[^\n]*\n"]
-append regs_output "\n"
 append regs_output [capture_command_output "mt print user-registers" \
 		     ".*Name.*Nr\[^\n]*\n"]
+set reg_groups_output [capture_command_output "mt print reggroups" \
+			".*Group.*Type\[^\n]*\n"]
+append reg_groups_output "\n"
+
 set all_regs {}
 foreach {- reg} [regexp -all -inline -line {^\s+(\w+)} $regs_output] {
     lappend all_regs $reg
 }
 
-set all_regs [join [lsort -unique $all_regs]]
+set all_reg_groups {}
+foreach {- group} [regexp -all -inline -line {^\s+(\w+)} $reg_groups_output] {
+    lappend all_reg_groups $group
+}
+
+set all_regs_and_groups [concat $all_regs $all_reg_groups]
+set all_regs_and_groups [join [lsort -unique $all_regs_and_groups]]
 
 # ... and then compare them to the completion of "info registers".
 
@@ -159,7 +166,7 @@  foreach {-> reg} [regexp -all -inline -line {^info registers (\w+\S*)} $regs_out
     lappend completed_regs $reg
 }
 set completed_regs [join [lsort $completed_regs]]
-gdb_assert {$all_regs eq $completed_regs} "complete 'info registers '"
+gdb_assert {$all_regs_and_groups eq $completed_regs} "complete 'info registers '"
 
 # Tests below are about tab-completion, which doesn't work if readline
 # library isn't used.  Check it first.
@@ -168,6 +175,14 @@  if { ![readline_is_used] } {
     return -1
 }
 
+# Test "print $<registername>" completion
+set complete_dollar_output [capture_command_output "complete print $" ""]
+
+foreach {- reg} $all_regs {
+    set found_reg {[string first $reg $complete_dollar_output] != -1}
+    gdb_assert $found_reg "complete 'print \$' contains $reg"
+}
+
 # The bulk of this test script pre-dates the completion-support
 # library, and should probably (where possible) be converted.
 # However, for now, new tests are being added using this library.