@@ -25,6 +25,10 @@ extern cl::opt<std::string> ReadPerfEvents;
25
25
} // namespace opts
26
26
27
27
namespace {
28
+
29
+ // / Perform checks on memory map events normally captured in perf. Tests use
30
+ // / the 'opts::ReadPerfEvents' flag to emulate these events, passing a custom
31
+ // / 'perf script' output to DataAggregator.
28
32
struct MemoryMapsTester : public testing ::TestWithParam<Triple::ArchType> {
29
33
void SetUp () override {
30
34
initalizeLLVM ();
@@ -81,8 +85,7 @@ INSTANTIATE_TEST_SUITE_P(AArch64, MemoryMapsTester,
81
85
#endif
82
86
83
87
// / Check that the correct mmap size is computed when we have multiple text
84
- // / segment mappings. Uses 'opts::ReadPerfEvents' flag to pass a custom 'perf
85
- // / script' output, along with two text segments (SegmentInfo).
88
+ // / segment mappings.
86
89
TEST_P (MemoryMapsTester, ParseMultipleSegments) {
87
90
const int Pid = 1234 ;
88
91
StringRef Filename = " BINARY" ;
@@ -94,13 +97,9 @@ TEST_P(MemoryMapsTester, ParseMultipleSegments) {
94
97
Pid, Filename);
95
98
96
99
BC->SegmentMapInfo [0x11da000 ] =
97
- SegmentInfo{0x11da000 , 0x10da000 , 0x11ca000 , 0x10da000 , 0x10000 };
100
+ SegmentInfo{0x11da000 , 0x10da000 , 0x11ca000 , 0x10da000 , 0x10000 , true };
98
101
BC->SegmentMapInfo [0x31d0000 ] =
99
- SegmentInfo{0x31d0000 , 0x51ac82c , 0x31d0000 , 0x3000000 , 0x200000 };
100
-
101
- // Dont show DataAggregators out/err output.
102
- testing::internal::CaptureStdout ();
103
- testing::internal::CaptureStderr ();
102
+ SegmentInfo{0x31d0000 , 0x51ac82c , 0x31d0000 , 0x3000000 , 0x200000 , true };
104
103
105
104
DataAggregator DA (" " );
106
105
BC->setFilename (Filename);
@@ -115,3 +114,29 @@ TEST_P(MemoryMapsTester, ParseMultipleSegments) {
115
114
ASSERT_NE (El, BinaryMMapInfo.end ());
116
115
ASSERT_EQ (El->second .Size , static_cast <uint64_t >(0xb1d0000 ));
117
116
}
117
+
118
+ // / Check that DataAggregator aborts when pre-processing an input binary
119
+ // / with multiple text segments that have different base addresses.
120
+ TEST_P (MemoryMapsTester, MultipleSegmentsMismatchedBaseAddress) {
121
+ const int Pid = 1234 ;
122
+ StringRef Filename = " BINARY" ;
123
+ opts::ReadPerfEvents = formatv (
124
+ " name 0 [000] 0.000000: PERF_RECORD_MMAP2 {0}/{0}: "
125
+ " [0xabc0000000(0x1000000) @ 0x11c0000 103:01 1573523 0]: r-xp {1}\n "
126
+ " name 0 [000] 0.000000: PERF_RECORD_MMAP2 {0}/{0}: "
127
+ " [0xabc2000000(0x8000000) @ 0x31d0000 103:01 1573523 0]: r-xp {1}\n " ,
128
+ Pid, Filename);
129
+
130
+ BC->SegmentMapInfo [0x11da000 ] =
131
+ SegmentInfo{0x11da000 , 0x10da000 , 0x11ca000 , 0x10da000 , 0x10000 , true };
132
+ // Using '0x31d0fff' FileOffset which triggers a different base address
133
+ // for this second text segment.
134
+ BC->SegmentMapInfo [0x31d0000 ] =
135
+ SegmentInfo{0x31d0000 , 0x51ac82c , 0x31d0fff , 0x3000000 , 0x200000 , true };
136
+
137
+ DataAggregator DA (" " );
138
+ BC->setFilename (Filename);
139
+ ASSERT_DEATH (
140
+ { Error Err = DA.preprocessProfile (*BC); },
141
+ " Base address on multiple segment mappings should match" );
142
+ }
0 commit comments