Avoid duplicate test in dw2-zero-range.exp

Message ID 20240119190752.4075435-1-tromey@adacore.com
State New
Headers
Series Avoid duplicate test in dw2-zero-range.exp |

Checks

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

Commit Message

Tom Tromey Jan. 19, 2024, 7:07 p.m. UTC
  I noticed that dw2-zero-range.exp reports a duplicate test name.  This
happens because have_index calls get_index_type with the default test
name.  This patch fixes the problem using with_test_prefix.
---
 gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
  

Comments

Simon Marchi Jan. 19, 2024, 9:18 p.m. UTC | #1
On 1/19/24 14:07, Tom Tromey wrote:
> I noticed that dw2-zero-range.exp reports a duplicate test name.  This
> happens because have_index calls get_index_type with the default test
> name.  This patch fixes the problem using with_test_prefix.

Hi Tom,

I was going to point out a few things that could be cleaned up in this
test to make it more readable, but I figured I might as well do them
instead of asking you for more work.  The patch below is what I came up
with.


From 7fe6cca02dc9a3beac947764d10bc0706b3272a1 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@efficios.com>
Date: Fri, 19 Jan 2024 21:15:41 +0000
Subject: [PATCH] gdb/testsuite: avoid duplicate test names in
 gdb.dwarf2/dw2-zero-range.exp (and more)

Tom Tromey noticed that dw2-zero-range.exp reported a duplicate test
name.  This happens because have_index calls get_index_type with the
default test name.  Refactor the test to avoid this, while cleaning a
few other things, the most important being:

 - factor out the relocated and unrelocated parts in their own procs
 - give different names to generated binaries in different variations,
   such that all binaries are left in the test output directory (this
   makes it easier to debug a specific variation)

Change-Id: I7cdf7a344834852fbb035d7e0434559eab6b1e94
---
 gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp | 143 ++++++++++----------
 1 file changed, 74 insertions(+), 69 deletions(-)

diff --git a/gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp b/gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp
index 79ccd620b8b7..1b3e3db30563 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp
@@ -23,6 +23,67 @@ require dwarf2_support allow_shlib_tests

 standard_testfile .c -shlib.c -dw.S

+# Test for presence of complaint, with the lib relocated.
+#
+proc_with_prefix test_relocated { exec_path lib_path complaint_re readnow_p } {
+    clean_restart $exec_path
+    gdb_load_shlib $lib_path
+
+    # Don't load the symbols for $lib_path during runto_main.
+    # Instead, we do this afterwards using "sharedlibrary $lib_path".
+    gdb_test_no_output "set auto-solib-add off"
+
+    if { ![runto_main] } {
+	return
+    }
+
+    # Test for presence of complaint.
+    with_complaints 1 {
+	set have_complaint 0
+	gdb_test_multiple "maint with dwarf synchronous on -- sharedlibrary [file tail $lib_path]" "load shared library" {
+	    -re -wrap $complaint_re {
+		set have_complaint 1
+	    }
+	    -re -wrap "" {
+	    }
+	}
+
+	# The complaint won't be seen if an index is in use.
+	if {[have_index $lib_path] == ""} {
+	    gdb_assert { $have_complaint } "complaint"
+	}
+
+	if { ! $readnow_p } {
+	    gdb_test "maint expand-symtabs $::srcfile2" $complaint_re \
+		"complaint when expanding symtab"
+	}
+    }
+}
+
+# Test for presence of complaint, with the lib unrelocated.
+
+proc_with_prefix test_unrelocated { exec_path lib_path complaint_re readnow_p } {
+    clean_restart
+    gdb_test_no_output "maint set dwarf synchronous on"
+
+    with_complaints 1 {
+	gdb_load $lib_path
+	set have_complaint [regexp $complaint_re.* $::gdb_file_cmd_msg]
+
+	# The complaint won't be seen if an index is in use.
+	if {[have_index $lib_path] == ""} {
+	    gdb_assert { $have_complaint } "complaint"
+	}
+
+	gdb_test_no_output "maint set dwarf synchronous off"
+
+	if { ! $readnow_p } {
+	    gdb_test "maint expand-symtabs $::srcfile2" $complaint_re \
+		"complaint when expanding symtab"
+	}
+    }
+}
+
 # Test with both a .debug_ranges section (DWARF 4) and a .debug_rnglists
 # section (DWARF 5).

@@ -86,83 +147,27 @@ foreach_with_prefix ranges_sect {ranges rnglists} {
 	error "invalid ranges section kind"
     }

-    set lib1 [standard_output_file shr1.sl]
-    set lib_opts "nodebug"
-
-    set sources [list ${srcdir}/${subdir}/$srcfile2 $asm_file]
-    if { [gdb_compile_shlib $sources ${lib1} $lib_opts] != "" } {
+    set lib_path [standard_output_file shr1-${ranges_sect}.sl]
+    set lib_sources [list ${srcdir}/${subdir}/$srcfile2 $asm_file]
+    if { [gdb_compile_shlib $lib_sources $lib_path {nodebug}] != "" } {
 	untested "failed to compile"
-	return -1
+	return
     }

-    set exec_opts [list debug shlib=${lib1}]
-    set sources ${srcdir}/${subdir}/${srcfile}
-    if { [gdb_compile $sources  ${binfile} executable \
-	      $exec_opts] != ""} {
+    set exec_sources ${srcdir}/${subdir}/${srcfile}
+    set exec_path ${binfile}-${ranges_sect}
+    set exec_opts [list debug shlib=${lib_path}]
+    if { [gdb_compile $exec_sources $exec_path executable $exec_opts] != ""} {
 	untested "failed to compile"
-	return -1
-    }
-
-    clean_restart $binfile
-    gdb_load_shlib $lib1
-
-    set readnow_p [readnow]
-
-    # Don't load the symbols for $lib1 during runto_main.
-    # Instead, we do this afterwards using "sharedlibrary $lib1".
-    gdb_test_no_output "set auto-solib-add off"
-
-    if { ![runto_main] } {
-	return -1
+	return
     }

     set complaint_re ".debug_${ranges_sect} entry has start address of zero"
-    set re \
+    set complaint_re \
 	"During symbol reading: $complaint_re \\\[in module \[^\r\n\]*\\\]"

-    # Test for presence of complaint, with lib1 relocated.
-    with_complaints 1 {
-	set test "Zero address complaint - relocated - psymtab"
-	set have_complaint 0
-	gdb_test_multiple "maint with dwarf synchronous on -- sharedlibrary [file tail $lib1]" $test {
-	    -re -wrap $re {
-		set have_complaint 1
-	    }
-	    -re -wrap "" {
-	    }
-	}
-
-	# The complaint won't be seen if an index is in use.
-	if {[have_index $lib1] == ""} {
-	    gdb_assert { $have_complaint } $test
-	}
-    }
-
-    if { ! $readnow_p } {
-	with_complaints 1 {
-	    gdb_test "maint expand-symtabs $srcfile2" $re \
-		"Zero address complaint - relocated - symtab"
-	}
-    }
-
-    clean_restart
-    # Test for presence of complaint, with lib1 unrelocated.
-    gdb_test_no_output "maint set dwarf synchronous on"
-    with_complaints 1 {
-	gdb_load $lib1
-	set test "Zero address complaint - unrelocated - psymtab"
-	set have_complaint [regexp $re.* $gdb_file_cmd_msg]
-	# The complaint won't be seen if an index is in use.
-	if {[have_index $lib1] == ""} {
-	    gdb_assert { $have_complaint } $test
-	}
-    }
-    gdb_test_no_output "maint set dwarf synchronous off"
+    set readnow_p [readnow]

-    if { ! $readnow_p } {
-	with_complaints 1 {
-	    gdb_test "maint expand-symtabs $srcfile2" $re \
-		"Zero address complaint - unrelocated - symtab"
-	}
-    }
+    test_relocated $exec_path $lib_path $complaint_re $readnow_p
+    test_unrelocated $exec_path $lib_path $complaint_re $readnow_p
 }

base-commit: 74d8fa2df7e7844f9b1b8fac27fe7d0b82100ab0
  
Tom Tromey Jan. 22, 2024, 3:01 p.m. UTC | #2
>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:

Simon> On 1/19/24 14:07, Tom Tromey wrote:
>> I noticed that dw2-zero-range.exp reports a duplicate test name.  This
>> happens because have_index calls get_index_type with the default test
>> name.  This patch fixes the problem using with_test_prefix.

Simon> Hi Tom,

Simon> I was going to point out a few things that could be cleaned up in this
Simon> test to make it more readable, but I figured I might as well do them
Simon> instead of asking you for more work.  The patch below is what I came up
Simon> with.

Seems fine to me.

Tom
  
Simon Marchi Jan. 22, 2024, 7:54 p.m. UTC | #3
On 2024-01-22 10:01, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:
> 
> Simon> On 1/19/24 14:07, Tom Tromey wrote:
>>> I noticed that dw2-zero-range.exp reports a duplicate test name.  This
>>> happens because have_index calls get_index_type with the default test
>>> name.  This patch fixes the problem using with_test_prefix.
> 
> Simon> Hi Tom,
> 
> Simon> I was going to point out a few things that could be cleaned up in this
> Simon> test to make it more readable, but I figured I might as well do them
> Simon> instead of asking you for more work.  The patch below is what I came up
> Simon> with.
> 
> Seems fine to me.
> 
> Tom

Thanks, pushed.

Simon
  

Patch

diff --git a/gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp b/gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp
index 79ccd620b8b..265c1fd3651 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp
@@ -122,7 +122,7 @@  foreach_with_prefix ranges_sect {ranges rnglists} {
 
     # Test for presence of complaint, with lib1 relocated.
     with_complaints 1 {
-	set test "Zero address complaint - relocated - psymtab"
+	set test "Zero address - relocated - psymtab"
 	set have_complaint 0
 	gdb_test_multiple "maint with dwarf synchronous on -- sharedlibrary [file tail $lib1]" $test {
 	    -re -wrap $re {
@@ -133,8 +133,10 @@  foreach_with_prefix ranges_sect {ranges rnglists} {
 	}
 
 	# The complaint won't be seen if an index is in use.
-	if {[have_index $lib1] == ""} {
-	    gdb_assert { $have_complaint } $test
+	with_test_prefix $test {
+	    if {[have_index $lib1] == ""} {
+		gdb_assert { $have_complaint } "complaint"
+	    }
 	}
     }
 
@@ -150,11 +152,13 @@  foreach_with_prefix ranges_sect {ranges rnglists} {
     gdb_test_no_output "maint set dwarf synchronous on"
     with_complaints 1 {
 	gdb_load $lib1
-	set test "Zero address complaint - unrelocated - psymtab"
+	set test "Zero address - unrelocated - psymtab"
 	set have_complaint [regexp $re.* $gdb_file_cmd_msg]
 	# The complaint won't be seen if an index is in use.
-	if {[have_index $lib1] == ""} {
-	    gdb_assert { $have_complaint } $test
+	with_test_prefix $test {
+	    if {[have_index $lib1] == ""} {
+		gdb_assert { $have_complaint } "complaint"
+	    }
 	}
     }
     gdb_test_no_output "maint set dwarf synchronous off"