2
2
Test the 'memory read' command.
3
3
"""
4
4
5
-
6
-
7
5
import lldb
8
- from lldbsuite .test .lldbtest import *
9
6
import lldbsuite .test .lldbutil as lldbutil
10
7
8
+ from lldbsuite .test .decorators import *
9
+ from lldbsuite .test .lldbtest import *
10
+
11
11
12
12
class MemoryReadTestCase (TestBase ):
13
13
@@ -19,27 +19,34 @@ def setUp(self):
19
19
# Find the line number to break inside main().
20
20
self .line = line_number ('main.cpp' , '// Set break point at this line.' )
21
21
22
- def test_memory_read (self ):
23
- """Test the 'memory read' command with plain and vector formats."""
22
+ def build_run_stop (self ):
24
23
self .build ()
25
24
exe = self .getBuildArtifact ("a.out" )
26
25
self .runCmd ("file " + exe , CURRENT_EXECUTABLE_SET )
27
26
28
27
# Break in main() after the variables are assigned values.
29
- lldbutil .run_break_set_by_file_and_line (
30
- self , "main.cpp" , self .line , num_expected_locations = 1 , loc_exact = True )
28
+ lldbutil .run_break_set_by_file_and_line (self ,
29
+ "main.cpp" ,
30
+ self .line ,
31
+ num_expected_locations = 1 ,
32
+ loc_exact = True )
31
33
32
34
self .runCmd ("run" , RUN_SUCCEEDED )
33
35
34
36
# The stop reason of the thread should be breakpoint.
35
- self .expect ("thread list" , STOPPED_DUE_TO_BREAKPOINT ,
37
+ self .expect ("thread list" ,
38
+ STOPPED_DUE_TO_BREAKPOINT ,
36
39
substrs = ['stopped' , 'stop reason = breakpoint' ])
37
40
38
41
# The breakpoint should have a hit count of 1.
39
- self .expect ("breakpoint list -f" , BREAKPOINT_HIT_ONCE ,
42
+ self .expect ("breakpoint list -f" ,
43
+ BREAKPOINT_HIT_ONCE ,
40
44
substrs = [' resolved, hit count = 1' ])
41
45
42
- # Test the memory read commands.
46
+ @no_debug_info_test
47
+ def test_memory_read (self ):
48
+ """Test the 'memory read' command with plain and vector formats."""
49
+ self .build_run_stop ()
43
50
44
51
# (lldb) memory read -f d -c 1 `&argc`
45
52
# 0x7fff5fbff9a0: 1
@@ -131,3 +138,40 @@ def test_memory_read(self):
131
138
for o in objects_read :
132
139
self .assertEqual (len (o ), expected_object_length )
133
140
self .assertEquals (len (objects_read ), 4 )
141
+
142
+ @no_debug_info_test
143
+ def test_memory_read_file (self ):
144
+ self .build_run_stop ()
145
+ res = lldb .SBCommandReturnObject ()
146
+ self .ci .HandleCommand ("memory read -f d -c 1 `&argc`" , res )
147
+ self .assertTrue (res .Succeeded (), "memory read failed:" + res .GetError ())
148
+
149
+ # Record golden output.
150
+ golden_output = res .GetOutput ()
151
+
152
+ memory_read_file = self .getBuildArtifact ("memory-read-output" )
153
+
154
+ def check_file_content (expected ):
155
+ with open (memory_read_file ) as f :
156
+ lines = f .readlines ()
157
+ lines = [s .strip () for s in lines ]
158
+ expected = [s .strip () for s in expected ]
159
+ self .assertEqual (lines , expected )
160
+
161
+ # Sanity check.
162
+ self .runCmd ("memory read -f d -c 1 -o '{}' `&argc`" .format (memory_read_file ))
163
+ check_file_content ([golden_output ])
164
+
165
+ # Write some garbage to the file.
166
+ with open (memory_read_file , 'w' ) as f :
167
+ f .write ("some garbage" )
168
+
169
+ # Make sure the file is truncated when we run the command again.
170
+ self .runCmd ("memory read -f d -c 1 -o '{}' `&argc`" .format (memory_read_file ))
171
+ check_file_content ([golden_output ])
172
+
173
+ # Make sure the file is appended when we run the command with --append-outfile.
174
+ self .runCmd (
175
+ "memory read -f d -c 1 -o '{}' --append-outfile `&argc`" .format (
176
+ memory_read_file ))
177
+ check_file_content ([golden_output , golden_output ])
0 commit comments