[gdb/testsuite] Set remotedir by default in some boards
[binutils-gdb.git] / gdb / testsuite / gdb.testsuite / board-sanity.exp
1 # Copyright 2023 Free Software Foundation, Inc.
2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 3 of the License, or
5 # (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
11 #
12 # You should have received a copy of the GNU General Public License
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14
15 # The purpose of this test-case is to test the sanity of the used host/target
16 # board files.
17
18 proc test_remote { remote host_is_target } {
19 global srcdir subdir
20
21 set file board-sanity.exp
22
23 set shell_ok 0
24 set delete_ok 0
25 set exists_ok 1
26
27 if { $host_is_target } {
28 if { $remote == "host" } {
29 set other_remote "target"
30 } else {
31 set other_remote "host"
32 }
33 }
34
35 with_test_prefix cleanup-remote {
36 set res [remote_file $remote delete $file]
37 gdb_assert { [lindex $res 0] == $delete_ok } \
38 "remove $remote copy "
39
40 set res [remote_file $remote exists $file]
41 gdb_assert { $res != $exists_ok } \
42 "$remote copy does not exist"
43
44 if { $host_is_target } {
45 set res [remote_file $other_remote exists $file]
46 gdb_assert { $res != $exists_ok } \
47 "$other_remote copy does not exist"
48 }
49 }
50
51 with_test_prefix copy-to-remote {
52 set remote_file [remote_download $remote $srcdir/$subdir/$file]
53 gdb_assert { [string equal [file tail $remote_file] $file] == 1} \
54 "remote_download returns valid value"
55
56 set res [remote_file $remote exists $file]
57 gdb_assert { $res == $exists_ok } \
58 "$remote copy exists"
59
60 if { $host_is_target } {
61 set res [remote_file $other_remote exists $file]
62 gdb_assert { $res == $exists_ok } \
63 "$other_remote copy exists"
64 }
65 }
66
67 with_test_prefix cleanup-build {
68 # Note: we're not comparing with delete_ok, return value seems to be
69 # different for build.
70 set res [remote_file build delete $file]
71 gdb_assert { [string equal $res ""] } \
72 "remove build copy"
73
74 set res [remote_file build exists $file]
75 gdb_assert { $res != $exists_ok } \
76 "build copy does not exist"
77 }
78
79 with_test_prefix copy-from-remote {
80 # Note: we're using $remote_file here instead of $file, otherwise
81 # this breaks with board_info remotedir.
82 set build_file [remote_upload $remote $remote_file]
83 gdb_assert { [string equal [file tail $build_file] $file] == 1 } \
84 "remote_upload returns valid value"
85
86 set res [remote_file $remote delete $file]
87 gdb_assert { [string equal $res $delete_ok] == 1 } \
88 "remove $remote copy"
89
90 set res [remote_file $remote exists $file]
91 gdb_assert { $res != $exists_ok } \
92 "$remote copy does not exist"
93
94 if { $host_is_target } {
95 set res [remote_file $other_remote exists $file]
96 gdb_assert { $res != $exists_ok } \
97 "$other_remote copy does not exist"
98 }
99
100 set res [remote_file build exists $file]
101 gdb_assert { $res == $exists_ok } \
102 "build copy exists"
103
104 set res [remote_file $remote delete $file]
105 gdb_assert { $res == $delete_ok } \
106 "remove build copy"
107 }
108 }
109
110 # Host_is_target == 1 for local-remote-host-native.exp, if as intended specified
111 # with both --target_board and --host_board.
112 if { [info exists host_board] } {
113 set host_is_target [string equal $host_board [target_info name]]
114 } else {
115 set host_is_target 0
116 }
117
118 foreach_with_prefix remote {host target} {
119 if { [is_remote $remote] } {
120 test_remote $remote $host_is_target
121 }
122 }
123
124 proc_with_prefix gdb_simple_compile_and_run {} {
125 set src {
126 int main() {
127 return 0;
128 }
129 }
130
131 set test "compile"
132 if {![gdb_simple_compile board-sanity $src executable]} {
133 fail $test
134 return
135 }
136 pass $test
137
138 set target_obj [gdb_remote_download target $obj]
139 set result [remote_exec target $target_obj]
140 set status [lindex $result 0]
141 set output [lindex $result 1]
142
143 if { [host_info name] == "local-remote-host-native"
144 && [target_info name] == "local-remote-host-native" } {
145 # Setting remotedir on this board has effect on both host and
146 # target, and it seems to broken for host. Xfail this for now.
147 setup_xfail *-*-*
148 }
149 gdb_assert { $status == 0 && $output == "" }
150
151 remote_file build delete $obj
152 }
153
154 gdb_simple_compile_and_run