[gdb/testsuite] Fix another fail and tcl error in gdb.dap/sources.exp

Message ID 20240213161823.25945-1-tdevries@suse.de
State Committed
Headers
Series [gdb/testsuite] Fix another fail and tcl error in gdb.dap/sources.exp |

Checks

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

Commit Message

Tom de Vries Feb. 13, 2024, 4:18 p.m. UTC
  With gdb.dap/sources.exp on aarch64-linux, I'm running into:
...
{"request_seq": 3, "type": "response", "command": "loadedSources", \
  "success": false, "message": "notStopped", "seq": 7}Content-Length: 92^M
^M
{"type": "event", "event": "thread", \
  "body": {"reason": "started", "threadId": 1}, \
  "seq": 8}FAIL: gdb.dap/sources.exp: loadedSources success
ERROR: tcl error sourcing gdb.dap/sources.exp.
ERROR: tcl error code TCL LOOKUP DICT body
ERROR: key "body" not known in dictionary
    while executing
"dict get [lindex $obj 0] body sources"
...

These are the same type of tcl error and FAIL I just fixed for a later
request in the same test-case.

Fix this by:
- moving the wait-for-stop to before the loadedSources request to fix the
  FAIL, and
- checking for $obj == "" to fix the tcl error.

Also make the code a bit less indented and more readable by wrapping the tests
in a proc, allowing the use of return to bail out, while still running
dap_shutdown afterwards.

Tested on aarch64-linux.
---
 gdb/testsuite/gdb.dap/sources.exp | 41 ++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 17 deletions(-)


base-commit: a16034bf6417dc2259fef43fd5bcc2dd1dac562f
  

Comments

Tom Tromey Feb. 13, 2024, 6:08 p.m. UTC | #1
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> These are the same type of tcl error and FAIL I just fixed for a later
Tom> request in the same test-case.

Tom> Fix this by:
Tom> - moving the wait-for-stop to before the loadedSources request to fix the
Tom>   FAIL, and
Tom> - checking for $obj == "" to fix the tcl error.

This is fine as long as these tests are actually being run in the end.
What I mean is, it would be bad to cover up a real failure of some kind.

Approved-By: Tom Tromey <tom@tromey.com>

Tom
  
Tom de Vries Feb. 14, 2024, 8:56 a.m. UTC | #2
On 2/13/24 19:08, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
> 
> Tom> These are the same type of tcl error and FAIL I just fixed for a later
> Tom> request in the same test-case.
> 
> Tom> Fix this by:
> Tom> - moving the wait-for-stop to before the loadedSources request to fix the
> Tom>   FAIL, and
> Tom> - checking for $obj == "" to fix the tcl error.
> 
> This is fine as long as these tests are actually being run in the end.
> What I mean is, it would be bad to cover up a real failure of some kind.
> 

Hi Tom,

thanks for the review.

Agreed, that would be bad, but I don't think this is the case.

The only thing that's happening here is that the test-case is cut short 
as soon as one test FAILs. There's always a FAIL to signal that 
something went wrong.

The dap_check_request_and_response proc itself produces a FAIL, which is 
why it isn't obvious from looking at the test-case that a FAIL is produced.

[ I'm on the fence about this.  Having the proc itself produce the fail 
guarantees a FAIL without effort from the call, but make you wonder when 
looking at the call whether something is missing.  Conversely, having to 
check the result of the call and produce a FAIL means it can be forgotten. ]

I know there's some high level goal to produce the same amount of 
PASS/FAIL, but IMO that's to be applied if that's easy, if it makes the 
test-case convoluted then it's not worth the trouble.

Committed.

Thanks,
- Tom

> Approved-By: Tom Tromey <tom@tromey.com>
> 
> Tom
  

Patch

diff --git a/gdb/testsuite/gdb.dap/sources.exp b/gdb/testsuite/gdb.dap/sources.exp
index 9b56337e5a8..ee853cc68aa 100644
--- a/gdb/testsuite/gdb.dap/sources.exp
+++ b/gdb/testsuite/gdb.dap/sources.exp
@@ -33,30 +33,37 @@  if {[dap_launch $testfile stop_at_main 1] == ""} {
     return
 }
 
-set obj [dap_check_request_and_response loadedSources loadedSources]
-set path ""
-foreach src [dict get [lindex $obj 0] body sources] {
-    if {[file tail [dict get $src name]] == "sources.c"} {
-	set path [dict get $src path]
-    }	
-}
-
-if {$path == ""} {
-    fail "sources.c in loadedSources"
-} else {
-    pass "sources.c in loadedSources"
-
+proc do_tests {} {
     dap_wait_for_event_and_check "stopped at function breakpoint" stopped \
 	"body reason" breakpoint
 
+    set obj [dap_check_request_and_response loadedSources loadedSources]
+    if { $obj == "" } {
+	return
+    }
+
+    set path ""
+    foreach src [dict get [lindex $obj 0] body sources] {
+	if {[file tail [dict get $src name]] == "sources.c"} {
+	    set path [dict get $src path]
+	}
+    }
+    gdb_assert {$path != "" } "sources.c in loadedSources"
+    if {$path == ""} {
+	return
+    }
+
     set obj [dap_check_request_and_response "get source" source \
 		 [format {o source [o path [s %s]] \
-			    sourceReference [i 0]} $path]]
-    if { $obj != "" } {
-	set text [dict get [lindex $obj 0] body content]
-	gdb_assert {[string first "Distinguishing comment" $text] != -1}
+			      sourceReference [i 0]} $path]]
+    if { $obj == "" } {
+	return
     }
+
+    set text [dict get [lindex $obj 0] body content]
+    gdb_assert {[string first "Distinguishing comment" $text] != -1}
 }
 
+do_tests
 
 dap_shutdown