]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.mi/mi-file-transfer.exp
b02a6d992b220427d43dd09a6130b8d3430f1f61
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-file-transfer.exp
1 # This testcase is part of GDB, the GNU debugger.
2 # Copyright 2007-2017 Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 # Test gdbserver monitor commands.
18
19 load_lib gdbserver-support.exp
20 load_lib mi-support.exp
21 set MIFLAGS "-i=mi"
22
23 if { [skip_gdbserver_tests] } {
24 return 0
25 }
26
27 standard_testfile basics.c
28
29 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
30 untested "failed to compile"
31 return -1
32 }
33
34 gdb_exit
35 if [mi_gdb_start] {
36 continue
37 }
38 mi_delete_breakpoints
39 mi_gdb_reinitialize_dir $srcdir/$subdir
40 mi_gdb_file_cmd ${binfile}
41
42 proc mi_gdbserver_run { } {
43 mi_gdb_test "kill" ".*" ""
44
45 set res [gdbserver_spawn ""]
46 set protocol [lindex $res 0]
47 set gdbport [lindex $res 1]
48
49 if { [mi_gdb_target_cmd $protocol $gdbport] != 0 } {
50 return -1
51 }
52
53 return 0
54 }
55
56 proc test_file_transfer { filename description } {
57 # If we are running everything locally, then we want to be sure to
58 # put the files into the test's standard output location. On the
59 # other hand, if the host or target is remote, then we need to
60 # continue with the "old-style" directory-less approach.
61 if {![is_remote host] && ![is_remote target]} {
62 set up_server [standard_output_file up-server]
63 set down_server [standard_output_file down-server]
64 } else {
65 set up_server up-server
66 set down_server down-server
67 }
68
69 mi_gdb_test "-target-file-put \"$filename\" \"${down_server}\"" \
70 "\\^done" "put $description"
71 mi_gdb_test "-target-file-get \"${down_server}\" \"${up_server}\"" \
72 "\\^done" "get $description"
73
74 if { ![is_remote target] } {
75 # If we can check the target copy of the file, do that too.
76 # This should catch symmetric errors in upload and download.
77 set result [remote_exec host "cmp -s $filename ${down_server}"]
78 if { [lindex $result 0] == 0 } {
79 pass "compare intermediate $description"
80 } else {
81 fail "compare intermediate $description"
82 }
83 }
84
85 set result [remote_exec host "cmp -s $filename ${up_server}"]
86 if { [lindex $result 0] == 0 } {
87 pass "compare $description"
88 } else {
89 fail "compare $description"
90 }
91
92 mi_gdb_test "-target-file-delete \"${down_server}\"" \
93 "\\^done" "deleted $description"
94
95 if { ![is_remote target] } {
96 if { ! [remote_file target exists ${down_server}] } {
97 pass "verified deleted $description"
98 } else {
99 fail "verified deleted $description"
100 }
101 }
102
103 catch { file delete ${up_server} }
104 }
105
106 mi_gdbserver_run
107
108 test_file_transfer "$binfile" "binary file"
109
110 mi_gdb_exit