OLD | NEW |
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 #if defined(ARCH_CPU_64_BITS) | 192 #if defined(ARCH_CPU_64_BITS) |
193 TEST(ProcessInfo, OtherProcessWOW64) { | 193 TEST(ProcessInfo, OtherProcessWOW64) { |
194 #ifndef NDEBUG | 194 #ifndef NDEBUG |
195 TestOtherProcess(FILE_PATH_LITERAL("..\\..\\out\\Debug")); | 195 TestOtherProcess(FILE_PATH_LITERAL("..\\..\\out\\Debug")); |
196 #else | 196 #else |
197 TestOtherProcess(FILE_PATH_LITERAL("..\\..\\out\\Release")); | 197 TestOtherProcess(FILE_PATH_LITERAL("..\\..\\out\\Release")); |
198 #endif | 198 #endif |
199 } | 199 } |
200 #endif // ARCH_CPU_64_BITS | 200 #endif // ARCH_CPU_64_BITS |
201 | 201 |
| 202 TEST(ProcessInfo, AccessibleRangesNone) { |
| 203 std::vector<ProcessInfo::MemoryInfo> memory_info; |
| 204 MEMORY_BASIC_INFORMATION mbi = {0}; |
| 205 |
| 206 mbi.BaseAddress = 0; |
| 207 mbi.RegionSize = 10; |
| 208 mbi.State = MEM_FREE; |
| 209 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); |
| 210 |
| 211 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = |
| 212 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(2, 4), |
| 213 memory_info); |
| 214 |
| 215 EXPECT_TRUE(result.empty()); |
| 216 } |
| 217 |
| 218 TEST(ProcessInfo, AccessibleRangesOneInside) { |
| 219 std::vector<ProcessInfo::MemoryInfo> memory_info; |
| 220 MEMORY_BASIC_INFORMATION mbi = {0}; |
| 221 |
| 222 mbi.BaseAddress = 0; |
| 223 mbi.RegionSize = 10; |
| 224 mbi.State = MEM_COMMIT; |
| 225 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); |
| 226 |
| 227 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = |
| 228 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(2, 4), |
| 229 memory_info); |
| 230 |
| 231 ASSERT_EQ(result.size(), 1u); |
| 232 EXPECT_EQ(2, result[0].base()); |
| 233 EXPECT_EQ(4, result[0].size()); |
| 234 } |
| 235 |
| 236 TEST(ProcessInfo, AccessibleRangesOneTruncatedSize) { |
| 237 std::vector<ProcessInfo::MemoryInfo> memory_info; |
| 238 MEMORY_BASIC_INFORMATION mbi = {0}; |
| 239 |
| 240 mbi.BaseAddress = 0; |
| 241 mbi.RegionSize = 10; |
| 242 mbi.State = MEM_COMMIT; |
| 243 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); |
| 244 |
| 245 mbi.BaseAddress = reinterpret_cast<void*>(10); |
| 246 mbi.RegionSize = 20; |
| 247 mbi.State = MEM_FREE; |
| 248 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); |
| 249 |
| 250 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = |
| 251 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(5, 10), |
| 252 memory_info); |
| 253 |
| 254 ASSERT_EQ(result.size(), 1u); |
| 255 EXPECT_EQ(5, result[0].base()); |
| 256 EXPECT_EQ(5, result[0].size()); |
| 257 } |
| 258 |
| 259 TEST(ProcessInfo, AccessibleRangesOneMovedStart) { |
| 260 std::vector<ProcessInfo::MemoryInfo> memory_info; |
| 261 MEMORY_BASIC_INFORMATION mbi = {0}; |
| 262 |
| 263 mbi.BaseAddress = 0; |
| 264 mbi.RegionSize = 10; |
| 265 mbi.State = MEM_FREE; |
| 266 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); |
| 267 |
| 268 mbi.BaseAddress = reinterpret_cast<void*>(10); |
| 269 mbi.RegionSize = 20; |
| 270 mbi.State = MEM_COMMIT; |
| 271 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); |
| 272 |
| 273 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = |
| 274 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(5, 10), |
| 275 memory_info); |
| 276 |
| 277 ASSERT_EQ(result.size(), 1u); |
| 278 EXPECT_EQ(10, result[0].base()); |
| 279 EXPECT_EQ(5, result[0].size()); |
| 280 } |
| 281 |
| 282 TEST(ProcessInfo, AccessibleRangesCoalesced) { |
| 283 std::vector<ProcessInfo::MemoryInfo> memory_info; |
| 284 MEMORY_BASIC_INFORMATION mbi = {0}; |
| 285 |
| 286 mbi.BaseAddress = 0; |
| 287 mbi.RegionSize = 10; |
| 288 mbi.State = MEM_FREE; |
| 289 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); |
| 290 |
| 291 mbi.BaseAddress = reinterpret_cast<void*>(10); |
| 292 mbi.RegionSize = 2; |
| 293 mbi.State = MEM_COMMIT; |
| 294 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); |
| 295 |
| 296 mbi.BaseAddress = reinterpret_cast<void*>(12); |
| 297 mbi.RegionSize = 5; |
| 298 mbi.State = MEM_RESERVE; |
| 299 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); |
| 300 |
| 301 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = |
| 302 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(11, 4), |
| 303 memory_info); |
| 304 |
| 305 ASSERT_EQ(result.size(), 1u); |
| 306 EXPECT_EQ(11, result[0].base()); |
| 307 EXPECT_EQ(4, result[0].size()); |
| 308 } |
| 309 |
| 310 TEST(ProcessInfo, AccessibleRangesMiddleUnavailable) { |
| 311 std::vector<ProcessInfo::MemoryInfo> memory_info; |
| 312 MEMORY_BASIC_INFORMATION mbi = {0}; |
| 313 |
| 314 mbi.BaseAddress = 0; |
| 315 mbi.RegionSize = 10; |
| 316 mbi.State = MEM_COMMIT; |
| 317 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); |
| 318 |
| 319 mbi.BaseAddress = reinterpret_cast<void*>(10); |
| 320 mbi.RegionSize = 5; |
| 321 mbi.State = MEM_FREE; |
| 322 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); |
| 323 |
| 324 mbi.BaseAddress = reinterpret_cast<void*>(15); |
| 325 mbi.RegionSize = 100; |
| 326 mbi.State = MEM_COMMIT; |
| 327 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); |
| 328 |
| 329 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = |
| 330 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(5, 45), |
| 331 memory_info); |
| 332 |
| 333 ASSERT_EQ(result.size(), 2u); |
| 334 EXPECT_EQ(5, result[0].base()); |
| 335 EXPECT_EQ(5, result[0].size()); |
| 336 EXPECT_EQ(15, result[1].base()); |
| 337 EXPECT_EQ(35, result[1].size()); |
| 338 } |
| 339 |
| 340 TEST(ProcessInfo, RequestedBeforeMap) { |
| 341 std::vector<ProcessInfo::MemoryInfo> memory_info; |
| 342 MEMORY_BASIC_INFORMATION mbi = {0}; |
| 343 |
| 344 mbi.BaseAddress = reinterpret_cast<void*>(10); |
| 345 mbi.RegionSize = 10; |
| 346 mbi.State = MEM_COMMIT; |
| 347 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); |
| 348 |
| 349 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = |
| 350 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(5, 10), |
| 351 memory_info); |
| 352 |
| 353 ASSERT_EQ(result.size(), 1u); |
| 354 EXPECT_EQ(10, result[0].base()); |
| 355 EXPECT_EQ(5, result[0].size()); |
| 356 } |
| 357 |
| 358 TEST(ProcessInfo, RequestedAfterMap) { |
| 359 std::vector<ProcessInfo::MemoryInfo> memory_info; |
| 360 MEMORY_BASIC_INFORMATION mbi = {0}; |
| 361 |
| 362 mbi.BaseAddress = reinterpret_cast<void*>(10); |
| 363 mbi.RegionSize = 10; |
| 364 mbi.State = MEM_COMMIT; |
| 365 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); |
| 366 |
| 367 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = |
| 368 GetReadableRangesOfMemoryMap( |
| 369 CheckedRange<WinVMAddress, WinVMSize>(15, 100), memory_info); |
| 370 |
| 371 ASSERT_EQ(result.size(), 1u); |
| 372 EXPECT_EQ(15, result[0].base()); |
| 373 EXPECT_EQ(5, result[0].size()); |
| 374 } |
| 375 |
202 } // namespace | 376 } // namespace |
203 } // namespace test | 377 } // namespace test |
204 } // namespace crashpad | 378 } // namespace crashpad |
OLD | NEW |