public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] [gdb/testsuite] Set remotedir by default in some boards
@ 2023-03-17 15:06 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2023-03-17 15:06 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3741934fdb04cde6661335e160249f9a83e498a7

commit 3741934fdb04cde6661335e160249f9a83e498a7
Author: Tom de Vries <tdevries@suse.de>
Date:   Fri Mar 17 16:06:39 2023 +0100

    [gdb/testsuite] Set remotedir by default in some boards
    
    When doing a gdb_simple_compile, and downloading the resulting exec $obj
    to target the result $target_obj may be a relative file path, which may give
    problems when trying to do:
    ...
    remote_exec target $target_obj
    ...
    
    Fix/workaround this on some target boards by setting remotedir by default, and
    add a corresponding test in gdb.testsuite/board-sanity.exp.
    
    This doesn't work for host/target board local-remote-host-native, so xfail this.
    
    Tested on x86_64-linux.

Diff:
---
 .../boards/remote-gdbserver-on-localhost.exp       | 45 ++++++++++++++--------
 gdb/testsuite/boards/remote-stdio-gdbserver.exp    | 16 ++++++++
 gdb/testsuite/gdb.testsuite/board-sanity.exp       | 32 +++++++++++++++
 3 files changed, 77 insertions(+), 16 deletions(-)

diff --git a/gdb/testsuite/boards/remote-gdbserver-on-localhost.exp b/gdb/testsuite/boards/remote-gdbserver-on-localhost.exp
index a08d2d19801..530e744c9b4 100644
--- a/gdb/testsuite/boards/remote-gdbserver-on-localhost.exp
+++ b/gdb/testsuite/boards/remote-gdbserver-on-localhost.exp
@@ -37,22 +37,35 @@ if { [info exists REMOTE_TARGET_USERNAME] } {
 }
 set_board_info hostname localhost
 
-# Handle separate test account.
-if { [board_info $board username] != $env(USER) } {
-    # We're pretending that some local user account is remote target.
-    # Make things a bit more realistic by restricting file permissions.
-
-    # Make sure remote target can't see files on build.
-    remote_exec build "chmod go-rx $objdir"
-
-    # Make sure build can't see files on remote target.  We can't use
-    # remote_exec target, because we're in the middle of parsing the
-    # target board.
-    remote_exec build \
-	"[board_info $board rsh_prog] \
-		     -l [board_info $board username] \
-			[board_info $board hostname] \
-	chmod go-rx ."
+save_vars {rsh_cmd res} {
+    set rsh_cmd \
+	[join \
+	     [list \
+		  [board_info $board rsh_prog] \
+		  -l [board_info $board username] \
+		  [board_info $board hostname]]]
+
+    # Handle separate test account.
+    if { [board_info $board username] != $env(USER) } {
+	# We're pretending that some local user account is remote target.
+	# Make things a bit more realistic by restricting file permissions.
+
+	# Make sure remote target can't see files on build.
+	remote_exec build "chmod go-rx $objdir"
+
+	# Make sure build can't see files on remote target.  We can't use
+	# remote_exec target, because we're in the middle of parsing the
+	# target board.
+	remote_exec build $rsh_cmd chmod go-rx ."
+    }
+
+    # Set remotedir by default, to force remote_download target to give an
+    # absolute file name.
+    set res [remote_exec build $rsh_cmd pwd]
+    if { [lindex $res 0] != 0 } {
+	error "Couldn't set remotedir using pwd"
+    }
+    set_board_info remotedir [string trim [lindex $res 1]]
 }
 
 proc ${board}_file { dest op args } {
diff --git a/gdb/testsuite/boards/remote-stdio-gdbserver.exp b/gdb/testsuite/boards/remote-stdio-gdbserver.exp
index 53e40d86477..c4e29e402fe 100644
--- a/gdb/testsuite/boards/remote-stdio-gdbserver.exp
+++ b/gdb/testsuite/boards/remote-stdio-gdbserver.exp
@@ -45,6 +45,22 @@ set_board_info rcp_prog /usr/bin/scp
 # Some remote machines don't have writable home directories.
 if [info exists REMOTE_TMPDIR] {
     set_board_info remotedir $REMOTE_TMPDIR
+} else {
+    # Set remotedir by default, to force remote_download target to give an
+    # absolute file name.
+    save_vars {rsh_cmd res} {
+	set rsh_cmd \
+	    [join \
+		 [list \
+		      [board_info $board rsh_prog] \
+		      -l [board_info $board username] \
+		      [board_info $board hostname]]]
+	set res [remote_exec build $rsh_cmd pwd]
+	if { [lindex $res 0] != 0 } {
+	    error "Couldn't set remotedir using pwd"
+	}
+	set_board_info remotedir [string trim [lindex $res 1]]
+    }
 }
 
 if [info exists GDBSERVER] {
diff --git a/gdb/testsuite/gdb.testsuite/board-sanity.exp b/gdb/testsuite/gdb.testsuite/board-sanity.exp
index b2b3690d1b5..d6402262f60 100644
--- a/gdb/testsuite/gdb.testsuite/board-sanity.exp
+++ b/gdb/testsuite/gdb.testsuite/board-sanity.exp
@@ -120,3 +120,35 @@ foreach_with_prefix remote {host target} {
 	test_remote $remote $host_is_target
     }
 }
+
+proc_with_prefix gdb_simple_compile_and_run {} {
+    set src {
+	int main() {
+	    return 0;
+	}
+    }
+
+    set test "compile"
+    if {![gdb_simple_compile board-sanity $src executable]} {
+	fail $test
+	return
+    }
+    pass $test
+
+    set target_obj [gdb_remote_download target $obj]
+    set result [remote_exec target $target_obj]
+    set status [lindex $result 0]
+    set output [lindex $result 1]
+
+    if { [host_info name] == "local-remote-host-native"
+	 && [target_info name] == "local-remote-host-native" } {
+	# Setting remotedir on this board has effect on both host and
+	# target, and it seems to broken for host.  Xfail this for now.
+	setup_xfail *-*-*
+    }
+    gdb_assert { $status == 0 && $output == "" }
+
+    remote_file build delete $obj
+}
+
+gdb_simple_compile_and_run

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-17 15:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-17 15:06 [binutils-gdb] [gdb/testsuite] Set remotedir by default in some boards Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).