[2/2] gdb/testsuite: fix duplicate test names in gdb.trace/circ.exp

Message ID 3a05c395ca3cc92ff4388539623b9d58eb0dfc3f.1706792515.git.aburgess@redhat.com
State New
Headers
Series Fix remaining gdb.trace/ duplicate test names |

Checks

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

Commit Message

Andrew Burgess Feb. 1, 2024, 1:04 p.m. UTC
  This fixes some duplicate test names in gdb.trace/circ.exp when using
native-gdbserver and native-extended-gdbserver boards.

In this test we set the trace buffer size twice.  The same test name
was used each time the size was adjusted.

I've fixed this issue by:

  1. Creating a new proc, set_trace_buffer_size, which factors out the
  code to change the buffer size, and uses test names based on the
  size we're setting the buffer too,

  2. Calling the new proc each time we want to adjust the buffer size.

After this the duplicate test names are resolved.  There should be no
change in what is tested after this commit.
---
 gdb/testsuite/gdb.trace/circ.exp | 76 +++++++++++++++++++-------------
 1 file changed, 45 insertions(+), 31 deletions(-)
  

Patch

diff --git a/gdb/testsuite/gdb.trace/circ.exp b/gdb/testsuite/gdb.trace/circ.exp
index 66bb64852fd..d123a1e7686 100644
--- a/gdb/testsuite/gdb.trace/circ.exp
+++ b/gdb/testsuite/gdb.trace/circ.exp
@@ -115,45 +115,59 @@  gdb_test "show circular-trace-buffer" \
     "Target's use of circular trace buffer is on." \
     "show circular-trace-buffer (on)"
 
-# Check if changing the trace buffer size is supported.  This step is
-# repeated twice.  This helps in case the trace buffer size is 100.
-set test_size 100
-set test "change buffer size to $test_size"
-gdb_test_multiple "set trace-buffer-size $test_size" $test {
-    -re ".*Target does not support this command.*$gdb_prompt $" {
-	unsupported "target does not support changing trace buffer size"
-	return 1
+# Use 'set trace-buffer-size' to change the trace buffer size to
+# REQUIRED_SIZE.  Return -1 if the current target doesn't support
+# adjusting the trace buffer size.  Return 0 if the adjustment failed
+# for some other reason.  Return 1 if the trace buffer size was
+# correctly adjusted.
+#
+# If this proc returns -1 then a suitable call to the unsupported proc
+# will have already been made.
+proc set_trace_buffer_size { required_size } {
+    set test_passed false
+    gdb_test_multiple "set trace-buffer-size $required_size" "" {
+	-re -wrap ".*Target does not support this command.*" {
+	    unsupported "target does not support changing trace buffer size"
+	    return -1
+	}
+	-re -wrap "" {
+	    pass $gdb_test_name
+	    set test_passed true
+	}
     }
-    -re "$gdb_prompt $" {
-	pass $test
+
+    if { !$test_passed } {
+	return 0
     }
-}
 
-set test "check whether setting trace buffer size is supported"
-gdb_test_multiple "tstatus" $test {
-    -re ".*Trace buffer has ($decimal) bytes of ($decimal) bytes free.*$gdb_prompt $" {
-	set total_size $expect_out(2,string)
-	if { $test_size != $total_size } {
-	    unsupported "target does not support changing trace buffer size"
-	    return 1
+    set test_passed false
+    gdb_test_multiple "tstatus" "check trace-buffer-size is $required_size" {
+	-re -wrap ".*Trace buffer has ($::decimal) bytes of ($::decimal) bytes free.*" {
+	    set total_size $expect_out(2,string)
+	    if { $required_size != $total_size } {
+		unsupported "target does not support changing trace buffer size"
+		return -1
+	    }
+	    pass $gdb_test_name
+	    set test_passed true
 	}
-	pass $test
     }
+
+    if { !$test_passed } {
+	return 0
+    }
+
+    return 1
 }
 
-set test_size 400
-gdb_test_no_output "set trace-buffer-size $test_size" \
-    "change buffer size to $test_size"
+# Check if changing the trace buffer size is supported.  This step is
+# repeated twice.  This helps in case the trace buffer size is 100.
+if {[set_trace_buffer_size 100] < 0} {
+    return
+}
 
-gdb_test_multiple "tstatus" $test {
-    -re ".*Trace buffer has ($decimal) bytes of ($decimal) bytes free.*$gdb_prompt $" {
-	set total_size $expect_out(2,string)
-	if { $test_size != $total_size } {
-	    unsupported "target does not support changing trace buffer size"
-	    return 1
-	}
-	pass $test
-    }
+if {[set_trace_buffer_size 400] < 0} {
+    return
 }
 
 gdb_test_no_output "set circular-trace-buffer off" \