Skip to content

Commit afb0a6a

Browse files
committed
Move test validation into helper method, do validation of expected and expected invalid ranges
1 parent 811f64c commit afb0a6a

File tree

2 files changed

+48
-25
lines changed

2 files changed

+48
-25
lines changed

lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidumpYaml.py

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
from lldbsuite.test.decorators import *
88
from lldbsuite.test.lldbtest import *
99
from lldbsuite.test import lldbutil
10+
from dataclass import dataclass
11+
12+
class AddressRange:
13+
begin: int
14+
end: int
15+
16+
def __init__(self, begin, end):
17+
self.begin = begin
18+
self.end = end
1019

1120

1221
class ProcessSaveCoreMinidumpTestCaseYaml(TestBase):
@@ -17,12 +26,34 @@ def process_from_yaml(self, yaml_file):
1726
self.process = self.target.LoadCore(minidump_path)
1827
return self.process
1928

29+
def validate_regions_saved_correctly(self, core_process, expected_region, expected_invalid_region=None):
30+
""" Validate that the expected_region is saved in the core_proc, and that the expected invalid region is not saved, if not not none. """
31+
32+
# Validate we can read the entire expected_region
33+
error = lldb.SBError()
34+
core_process.ReadMemory(expected_region.begin, expected_region.end - expected_region.begin, error)
35+
self.assertTrue(error.Success(), error.GetCString())
36+
37+
# Validate we can't read before and after the expected_region
38+
core_process.ReadMemory(expected_region.begin - 1, 1, error)
39+
self.assertTrue(error.Fail(), error.GetCString())
40+
41+
core_process.ReadMemory(expected_region.end + 1, 1, error)
42+
self.assertTrue(error.Fail(), error.GetCString())
43+
44+
if expected_invalid_region is None:
45+
return
46+
47+
# Validate we can't read the original_region
48+
core_process.ReadMemory(expected_invalid_region.begin, expected_invalid_region.end - expected_invalid_region.end, error)
49+
self.assertTrue(error.Success(), error.GetCString())
50+
2051
def test_saving_sub_memory_range(self):
2152
"""
2253
Validate we can save a Minidump for a subsection of a memory range.
2354
I.E.
24-
If our memory range is 0x1000-0x2000 nd the user specifies 0x1200-0x1800
25-
we should still capture 0x1200 to 0x1800
55+
If our memory range is 0x2000-0x2020 and the user specifies 0x2000-0x2008
56+
we should still capture 0x2000-0x2008
2657
"""
2758
yaml = "minidump_mem64.yaml"
2859
proc = self.process_from_yaml(yaml)
@@ -43,20 +74,16 @@ def test_saving_sub_memory_range(self):
4374
core_target = self.dbg.CreateTarget(None)
4475
core_process = core_target.LoadCore(new_minidump_path)
4576

46-
error = lldb.SBError()
47-
core_process.ReadMemory(begin, size, error)
48-
self.assertTrue(error.Success(), error.GetCString())
49-
50-
# Try to read 1 byte past the end
51-
core_process.ReadMemory(end + 1, 1, error)
52-
self.assertTrue(error.Fail(), error.GetCString())
77+
expected_address_range = AddressRange(begin, end)
78+
expected_invalid_range = AddressRange(begin, 0x2020)
79+
self.validate_regions_saved_correctly(core_process, expected_address_range, expected_invalid_range)
5380

5481
def test_saving_super_memory_range(self):
5582
"""
5683
Validate we can save a Minidump for a subsection of a memory range.
5784
I.E.
58-
If our memory range is 0x1000-0x2000 nd the user specifies 0x0800-0x2800
59-
we should still capture 0x1000-0x2000
85+
If our memory range is 0x1000-0x1100 and the user specifies 0x900-x1200
86+
we should still capture 0x1000-0x1100
6087
"""
6188
yaml = "minidump_mem64.yaml"
6289
proc = self.process_from_yaml(yaml)
@@ -77,9 +104,9 @@ def test_saving_super_memory_range(self):
77104
core_target = self.dbg.CreateTarget(None)
78105
core_process = core_target.LoadCore(new_minidump_path)
79106

80-
error = lldb.SBError()
81-
core_process.ReadMemory(begin, size, error)
82-
self.assertTrue(error.Success(), error.GetCString())
107+
expected_address_range = AddressRange(begin, end)
108+
expected_invalid_range = AddressRange(begin - 16, end + 16)
109+
self.validate_regions_saved_correctly(core_process, expected_address_range, expected_invalid_range)
83110

84111
def test_region_that_goes_out_of_bounds(self):
85112
"""
@@ -105,13 +132,9 @@ def test_region_that_goes_out_of_bounds(self):
105132
core_target = self.dbg.CreateTarget(None)
106133
core_process = core_target.LoadCore(new_minidump_path)
107134

108-
error = lldb.SBError()
109-
core_process.ReadMemory(begin, 0x00000020, error)
110-
self.assertTrue(error.Success(), error.GetCString())
111-
112-
# Whole region should be unavailable
113-
core_process.ReadMemory(end, 1, error)
114-
self.assertTrue(error.Fail(), error.GetCString())
135+
expected_address_range = AddressRange(begin, end)
136+
expected_invalid_range = AddressRange(begin - 16, end + 16)
137+
self.validate_regions_saved_correctly(core_process, expected_address_range, expected_invalid_range)
115138

116139
def test_region_that_starts_out_of_bounds(self):
117140
"""
@@ -137,6 +160,6 @@ def test_region_that_starts_out_of_bounds(self):
137160
core_target = self.dbg.CreateTarget(None)
138161
core_process = core_target.LoadCore(new_minidump_path)
139162

140-
error = lldb.SBError()
141-
core_process.ReadMemory(begin, 0x00000020, error)
142-
self.assertTrue(error.Success(), error.GetCString())
163+
expected_address_range = AddressRange(begin, end)
164+
expected_invalid_range = AddressRange(begin - 16, end)
165+
self.validate_regions_saved_correctly(core_process, expected_address_range, expected_invalid_range)

lldb/test/API/functionalities/process_save_core_minidump/minidump_mem64.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Streams:
2727
Data Size: 0x20
2828
Content : ''
2929
- Start of Memory Range: 0x3000
30-
Data Size: 0x4000
30+
Data Size: 0x400
3131
Content : ''
3232
- Start of Memory Range: 0x5000
3333
Data Size: 0x2000

0 commit comments

Comments
 (0)