Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Unified Diff: components/tracing/common/process_metrics_memory_dump_provider_unittest.cc

Issue 2710163002: Implement basic support for Windows module emission. (Closed)
Patch Set: Respond to comments. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/tracing/common/process_metrics_memory_dump_provider.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..95a565d148ab8b502af840f0339672c10eb4d3c8 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_executable = false;
+ 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_executable = 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_executable);
+ EXPECT_TRUE(found_region_with_dummy);
+}
+#endif
+
#if defined(OS_MACOSX)
TEST(ProcessMetricsMemoryDumpProviderTest, TestMachOReading) {
using VMRegion = base::trace_event::ProcessMemoryMaps::VMRegion;
« no previous file with comments | « components/tracing/common/process_metrics_memory_dump_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698