Chromium Code Reviews| Index: components/tracing/common/process_metrics_memory_dump_provider_unittest.cc |
| diff --git a/components/tracing/common/process_metrics_memory_dump_provider_unittest.cc b/components/tracing/common/process_metrics_memory_dump_provider_unittest.cc |
| index d05c3a736217d93e93bf179b66b25db8389f6261..44a26dc09753a684e4500967533c9a1ceb213165 100644 |
| --- a/components/tracing/common/process_metrics_memory_dump_provider_unittest.cc |
| +++ b/components/tracing/common/process_metrics_memory_dump_provider_unittest.cc |
| @@ -22,6 +22,10 @@ |
| #include <mach-o/dyld.h> |
| #endif |
| +#if defined(OS_WIN) |
| +#include <base/strings/sys_string_conversions.h> |
| +#endif |
| + |
| namespace tracing { |
| #if defined(OS_LINUX) || defined(OS_ANDROID) |
| @@ -274,6 +278,56 @@ TEST(ProcessMetricsMemoryDumpProviderTest, TestPollFastMemoryTotal) { |
| #endif |
| } |
| +#if defined(OS_WIN) |
| + |
| +void DummyFunction() {} |
| + |
| +TEST(ProcessMetricsMemoryDumpProviderTest, TestWinModuleReading) { |
| + using VMRegion = base::trace_event::ProcessMemoryMaps::VMRegion; |
| + |
| + ProcessMetricsMemoryDumpProvider mdp(base::kNullProcessId); |
| + base::trace_event::MemoryDumpArgs args; |
| + base::trace_event::ProcessMemoryDump dump(nullptr, args); |
| + ASSERT_TRUE(mdp.DumpProcessMemoryMaps(args, &dump)); |
| + ASSERT_TRUE(dump.has_process_mmaps()); |
| + |
| + wchar_t module_name[MAX_PATH]; |
| + DWORD result = GetModuleFileName(nullptr, module_name, MAX_PATH); |
| + ASSERT_TRUE(result); |
| + std::string executable_name = base::SysWideToNativeMB(module_name); |
| + |
| + HMODULE module_containing_dummy = nullptr; |
| + uintptr_t dummy_function_address = |
| + reinterpret_cast<uintptr_t>(&DummyFunction); |
| + result = GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, |
| + reinterpret_cast<LPCWSTR>(dummy_function_address), |
| + &module_containing_dummy); |
| + ASSERT_TRUE(result); |
| + result = GetModuleFileName(nullptr, module_name, MAX_PATH); |
| + ASSERT_TRUE(result); |
| + std::string module_containing_dummy_name = |
| + base::SysWideToNativeMB(module_name); |
| + |
| + bool found_components_unittests = false; |
|
Wez
2017/02/23 23:35:03
nit: Suggest renaming this to found_executable, si
erikchen
2017/02/24 17:32:48
Done.
|
| + bool found_region_with_dummy = false; |
| + for (const VMRegion& region : dump.process_mmaps()->vm_regions()) { |
| + EXPECT_NE(0u, region.start_address); |
| + EXPECT_NE(0u, region.size_in_bytes); |
| + |
| + if (region.mapped_file.find(executable_name) != std::string::npos) |
| + found_components_unittests = true; |
| + |
| + if (dummy_function_address >= region.start_address && |
| + dummy_function_address < region.start_address + region.size_in_bytes) { |
| + found_region_with_dummy = true; |
| + EXPECT_EQ(module_containing_dummy_name, region.mapped_file); |
| + } |
| + } |
| + EXPECT_TRUE(found_components_unittests); |
| + EXPECT_TRUE(found_region_with_dummy); |
| +} |
| +#endif |
| + |
| #if defined(OS_MACOSX) |
| TEST(ProcessMetricsMemoryDumpProviderTest, TestMachOReading) { |
| using VMRegion = base::trace_event::ProcessMemoryMaps::VMRegion; |