]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
testsuite: Fix issues with cross testing in guality tests
authorJoseph Myers <josmyers@redhat.com>
Wed, 14 Jan 2026 17:09:40 +0000 (17:09 +0000)
committerJoseph Myers <josmyers@redhat.com>
Wed, 14 Jan 2026 17:09:40 +0000 (17:09 +0000)
The guality tests expect to run (native) GDB on the target.  If this
is available, there is some support for cross testing, but with
various defects and limitations, some of them fixed here.

* GUALITY_GDB_NAME doesn't get passed through to the target for remote
  testing (a general limitation of the DejaGnu interface: it doesn't
  support setting environment variables on the target).  Not fixed
  here.

* Using in-tree GDB is only appropriate when host = target, since
  in-tree GDB runs on the host and the testsuite runs GDB on the
  target.  Fixed here.  (Note that [isnative] isn't used because that
  refers to build = target, and we need host = target here.)

* [transform gdb] is not appropriate because that's a cross-GDB and
  the tests run GDB on the target, so need a native GDB.  Fixed here.

* gdb-test (used by some guality tests) exits early in cross and
  remote cases (whereas the tests running GDB directly from the test
  itself via popen can already do so on the target without needing
  further patches).  Fixed here.  There are various other fixes done
  in gdb-test as well; it needs to transfer files to the target then
  delete them afterwards.

* report_gdb expects to run GDB on the host when the tests run it on
  the target.  Fixed here.

Note: some similar fixes will also be needed for simulate-thread tests
to get them working for cross testing, but I haven't done those yet.

Tested for x86_64-pc-linux-gnu to make sure native testing isn't
broken, and with cross to aarch64-linux.

* lib/gcc-gdb-test.exp (gdb-test): Do not return early for
non-native and remote.  Download executable and GDB command file
to target before running GDB there, and delete when closing
target.
(report_gdb): Use target when testing GDB availability and
version.
* g++.dg/guality/guality.exp: Only use in-tree GDB when host =
target.  Do not use [transform gdb].
* gcc.dg/guality/guality.exp: Likewise.
* gfortran.dg/guality/guality.exp: Likewise.

gcc/testsuite/g++.dg/guality/guality.exp
gcc/testsuite/gcc.dg/guality/guality.exp
gcc/testsuite/gfortran.dg/guality/guality.exp
gcc/testsuite/lib/gcc-gdb-test.exp

index 6de5e8091a5062dfd0d4b6ebc2317b664f79b968..695ed02b89bb732c3c27e877754de5a6daa6bb5e 100644 (file)
@@ -40,14 +40,17 @@ dg-init
 torture-init
 
 global GDB
+global host_triplet target_triplet
 if ![info exists ::env(GUALITY_GDB_NAME)] {
     if [info exists GDB] {
        set guality_gdb_name "$GDB"
-    } elseif { [info exists rootme] && [file exists $rootme/../gdb/gdb] } {
+    } elseif { [string equal $host_triplet $target_triplet]
+              && [info exists rootme]
+              && [file exists $rootme/../gdb/gdb] } {
        # If we're doing a combined build, and gdb is available, use it.
        set guality_gdb_name "$rootme/../gdb/gdb"
     } else {
-       set guality_gdb_name "[transform gdb]"
+       set guality_gdb_name "gdb"
     }
     setenv GUALITY_GDB_NAME "$guality_gdb_name"
 }
index 0dc8f10762d7a68fc1daf27b51288167c4a063ba..4d342aa51658edf616359cf530956062dace2cec 100644 (file)
@@ -40,14 +40,17 @@ dg-init
 torture-init
 
 global GDB
+global host_triplet target_triplet
 if ![info exists ::env(GUALITY_GDB_NAME)] {
     if [info exists GDB] {
        set guality_gdb_name "$GDB"
-    } elseif { [info exists rootme] && [file exists $rootme/../gdb/gdb] } {
+    } elseif { [string equal $host_triplet $target_triplet]
+              && [info exists rootme]
+              && [file exists $rootme/../gdb/gdb] } {
        # If we're doing a combined build, and gdb is available, use it.
        set guality_gdb_name "$rootme/../gdb/gdb"
     } else {
-       set guality_gdb_name "[transform gdb]"
+       set guality_gdb_name "gdb"
     }
     setenv GUALITY_GDB_NAME "$guality_gdb_name"
 }
index 105e08a70d882beb8c8ecf829bfe5361eb55b0bd..3ee157abf7b37e1945b170a937379d6e80cfdd37 100644 (file)
@@ -21,14 +21,17 @@ dg-init
 torture-init
 
 global GDB
+global host_triplet target_triplet
 if ![info exists ::env(GUALITY_GDB_NAME)] {
     if [info exists GDB] {
        set guality_gdb_name "$GDB"
-    } elseif { [info exists rootme] && [file exists $rootme/../gdb/gdb] } {
+    } elseif { [string equal $host_triplet $target_triplet]
+              && [info exists rootme]
+              && [file exists $rootme/../gdb/gdb] } {
        # If we're doing a combined build, and gdb is available, use it.
        set guality_gdb_name "$rootme/../gdb/gdb"
     } else {
-       set guality_gdb_name "[transform gdb]"
+       set guality_gdb_name "gdb"
     }
     setenv GUALITY_GDB_NAME "$guality_gdb_name"
 }
index 942853f183e6fe81ef853ea2fb1d63b6bb1bdb42..f7c1da8fae254a6a9bfd78752a309406c15c6601 100644 (file)
@@ -27,8 +27,6 @@
 #   the literal string with extra whitespace removed.
 # Argument 3 handles expected failures and the like
 proc gdb-test { useline args } {
-    if { ![isnative] || [is_remote target] } { return }
-
     if { [llength $args] >= 4 } {
        switch [dg-process-target [lindex $args 3]] {
            "S" { }
@@ -80,11 +78,17 @@ proc gdb-test { useline args } {
     puts $fd "quit"
     close $fd
 
-    send_log "Spawning: $gdb_name -nx -nw -quiet -batch -x $cmd_file ./$output_file\n"
-    set res [remote_spawn target "$gdb_name -nx -nw -quiet -batch -x $cmd_file ./$output_file"]
+    set cmd_file_remote [remote_download target $cmd_file]
+    set output_file_remote [remote_download target $output_file]
+    send_log "Spawning: $gdb_name -nx -nw -quiet -batch -x $cmd_file_remote $output_file_remote\n"
+    set res [remote_spawn target "$gdb_name -nx -nw -quiet -batch -x $cmd_file_remote $output_file_remote"]
     if { $res < 0 || $res == "" } {
        unsupported "$testname"
        file delete $cmd_file
+       if { [is_remote target] } {
+           remote_file target delete $cmd_file_remote
+           remote_file target delete $output_file_remote
+       }
        return
     }
 
@@ -94,6 +98,10 @@ proc gdb-test { useline args } {
            unsupported "$testname"
            remote_close target
            file delete $cmd_file
+           if { [is_remote target] } {
+               remote_file target delete $cmd_file_remote
+               remote_file target delete $output_file_remote
+           }
            return
        }
        # print var; print expected
@@ -110,6 +118,10 @@ proc gdb-test { useline args } {
            }
            remote_close target
            file delete $cmd_file
+           if { [is_remote target] } {
+               remote_file target delete $cmd_file_remote
+               remote_file target delete $output_file_remote
+           }
            return
        }
        # ptype var;
@@ -131,12 +143,20 @@ proc gdb-test { useline args } {
            }
            remote_close target
            file delete $cmd_file
+           if { [is_remote target] } {
+               remote_file target delete $cmd_file_remote
+               remote_file target delete $output_file_remote
+           }
            return
        }
        timeout {
            unsupported "$testname"
            remote_close target
            file delete $cmd_file
+           if { [is_remote target] } {
+               remote_file target delete $cmd_file_remote
+               remote_file target delete $output_file_remote
+           }
            return
        }
     }
@@ -144,6 +164,10 @@ proc gdb-test { useline args } {
     unsupported "$testname"
     remote_close target
     file delete $cmd_file
+    if { [is_remote target] } {
+       remote_file target delete $cmd_file_remote
+       remote_file target delete $output_file_remote
+    }
     return
 }
 
@@ -152,15 +176,18 @@ proc gdb-test { useline args } {
 # Argument 1 is the location where gdb is used
 # 
 proc report_gdb { gdb loc } {
-    if { [catch { exec which $gdb } msg] } {
-       send_log "gdb not found in $loc: $msg\n"
+    set status [remote_exec target "which" "$gdb"]
+    set gdb [string trim [lindex $status 1]]
+    if { [lindex $status 0] != 0 } {
+       send_log "gdb not found in $loc: $gdb\n"
        return
     }
-    set gdb [exec which $gdb]
     send_log "gdb used in $loc: $gdb\n"
 
     send_log "gdb used in $loc: "
-    if { [catch { exec $gdb -v } gdb_version] } {
+    set status [remote_exec target "$gdb" "-v"]
+    set gdb_version [lindex $status 1]
+    if { [lindex $status 0] != 0 } {
        send_log "getting version failed:\n"
     } else {
        send_log "version:\n"