1
1
# lldb test suite imports
2
2
from lldbsuite .test .decorators import *
3
3
from lldbsuite .test .lldbtest import TestBase
4
+ from lldbsuite .test import lldbutil
4
5
5
6
# gdb-remote-specific imports
6
7
import lldbgdbserverutils
@@ -108,6 +109,20 @@ def test_platform_file_wronly_fail(self):
108
109
)
109
110
self .expect_gdbremote_sequence ()
110
111
112
+ def remote_install (self , path , filename = "test" ):
113
+ if lldb .remote_platform :
114
+ remote_path = lldbutil .append_to_process_working_directory (self , filename )
115
+ err = lldb .remote_platform .Install (
116
+ lldb .SBFileSpec (path , True ), lldb .SBFileSpec (remote_path , False )
117
+ )
118
+ if err .Fail ():
119
+ raise Exception (
120
+ "remote_platform.Install('%s', '%s') failed: %s"
121
+ % (path , remote_path , err )
122
+ )
123
+ path = remote_path
124
+ return path
125
+
111
126
@skipIfWindows
112
127
@add_test_categories (["llgs" ])
113
128
def test_platform_file_wronly_creat_excl_fail (self ):
@@ -117,6 +132,7 @@ def test_platform_file_wronly_creat_excl_fail(self):
117
132
temp_file = self .getBuildArtifact ("test" )
118
133
with open (temp_file , "wb" ):
119
134
pass
135
+ temp_file = self .remote_install (temp_file )
120
136
121
137
# attempt to open the file with O_CREAT|O_EXCL
122
138
self .do_handshake ()
@@ -140,6 +156,7 @@ def test_platform_file_size(self):
140
156
test_data = b"test data of some length"
141
157
with open (temp_path , "wb" ) as temp_file :
142
158
temp_file .write (test_data )
159
+ temp_path = self .remote_install (temp_path )
143
160
144
161
self .do_handshake ()
145
162
self .test_sequence .add_log_lines (
@@ -167,7 +184,11 @@ def test_platform_file_mode(self):
167
184
test_mode = 0o751
168
185
169
186
with open (temp_path , "wb" ) as temp_file :
170
- os .chmod (temp_file .fileno (), test_mode )
187
+ if lldbplatformutil .getHostPlatform () == "windows" :
188
+ test_mode = 0o700
189
+ else :
190
+ os .chmod (temp_file .fileno (), test_mode )
191
+ temp_path = self .remote_install (temp_path )
171
192
172
193
self .do_handshake ()
173
194
self .test_sequence .add_log_lines (
@@ -213,6 +234,7 @@ def test_platform_file_exists(self):
213
234
temp_path = self .getBuildArtifact ("test" )
214
235
with open (temp_path , "wb" ):
215
236
pass
237
+ temp_path = self .remote_install (temp_path )
216
238
217
239
self .do_handshake ()
218
240
self .test_sequence .add_log_lines (
@@ -244,6 +266,10 @@ def test_platform_file_exists_not(self):
244
266
self .expect_gdbremote_sequence ()
245
267
246
268
@skipIfWindows
269
+ # FIXME: lldb.remote_platform.Install() cannot copy opened temp file on Windows.
270
+ # It is possible to use tempfile.NamedTemporaryFile(..., delete=False) and
271
+ # delete the temp file manually at the end.
272
+ @skipIf (hostoslist = ["windows" ])
247
273
@add_test_categories (["llgs" ])
248
274
def test_platform_file_fstat (self ):
249
275
server = self .connect_to_debug_monitor ()
@@ -252,12 +278,13 @@ def test_platform_file_fstat(self):
252
278
with tempfile .NamedTemporaryFile () as temp_file :
253
279
temp_file .write (b"some test data for stat" )
254
280
temp_file .flush ()
281
+ temp_path = self .remote_install (temp_file .name , "temp" )
255
282
256
283
self .do_handshake ()
257
284
self .test_sequence .add_log_lines (
258
285
[
259
286
"read packet: $vFile:open:%s,0,0#00"
260
- % (binascii .b2a_hex (temp_file . name .encode ()).decode (),),
287
+ % (binascii .b2a_hex (temp_path .encode ()).decode (),),
261
288
{
262
289
"direction" : "send" ,
263
290
"regex" : r"^\$F([0-9a-fA-F]+)#[0-9a-fA-F]{2}$" ,
@@ -359,9 +386,12 @@ def vFile_test(
359
386
360
387
if creat :
361
388
self .assertFalse (os .path .exists (temp_path ))
389
+ if lldb .remote_platform :
390
+ temp_path = lldbutil .append_to_process_working_directory (self , "test" )
362
391
else :
363
392
with open (temp_path , "wb" ) as temp_file :
364
393
temp_file .write (test_data .encode ())
394
+ temp_path = self .remote_install (temp_path )
365
395
366
396
# open the file for reading
367
397
self .do_handshake ()
@@ -448,8 +478,19 @@ def vFile_test(
448
478
449
479
if write :
450
480
# check if the data was actually written
481
+ if lldb .remote_platform :
482
+ local_path = self .getBuildArtifact ("file_from_target" )
483
+ error = lldb .remote_platform .Get (
484
+ lldb .SBFileSpec (temp_path , False ), lldb .SBFileSpec (local_path , True )
485
+ )
486
+ self .assertTrue (
487
+ error .Success (),
488
+ "Reading file {0} failed: {1}" .format (temp_path , error ),
489
+ )
490
+ temp_path = local_path
491
+
451
492
with open (temp_path , "rb" ) as temp_file :
452
- if creat :
493
+ if creat and lldbplatformutil . getHostPlatform () != "windows" :
453
494
self .assertEqual (
454
495
os .fstat (temp_file .fileno ()).st_mode & 0o7777 , 0o640
455
496
)
0 commit comments