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 5b1b25f1d0ea12f329b6d25f574c6e21438d8bc4..fc53f77a7811e6db365800e9afc9bb3274092b1d 100644 |
| --- a/components/tracing/common/process_metrics_memory_dump_provider_unittest.cc |
| +++ b/components/tracing/common/process_metrics_memory_dump_provider_unittest.cc |
| @@ -17,6 +17,11 @@ |
| #include "base/trace_event/trace_event_argument.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#if defined(OS_MACOSX) |
| +#include <libgen.h> |
| +#include <mach-o/dyld.h> |
| +#endif |
| + |
| namespace tracing { |
| #if defined(OS_LINUX) || defined(OS_ANDROID) |
| @@ -269,4 +274,35 @@ TEST(ProcessMetricsMemoryDumpProviderTest, TestPollFastMemoryTotal) { |
| #endif |
| } |
| +#if defined(OS_MACOSX) |
| +TEST(ProcessMetricsMemoryDumpProviderTest, TestMachOReading) { |
|
Primiano Tucci (use gerrit)
2017/02/01 00:03:57
\o/ Look a test! thanks, you rock.
|
| + 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()); |
| + uint32_t size = 100; |
| + char full_path[size]; |
| + int result = _NSGetExecutablePath(full_path, &size); |
| + ASSERT_EQ(0, result); |
| + std::string name = basename(full_path); |
| + |
| + bool found_components_unittests = false; |
| + for (const VMRegion& region : dump.process_mmaps()->vm_regions()) { |
| + EXPECT_NE(0u, region.start_address); |
| + EXPECT_NE(0u, region.size_in_bytes); |
| + |
| + EXPECT_LT(region.size_in_bytes, 1ull << 32); |
| + uint32_t required_protection_flags = |
| + VMRegion::kProtectionFlagsRead | VMRegion::kProtectionFlagsExec; |
| + if (region.mapped_file.find(name) != std::string::npos && |
| + region.protection_flags == required_protection_flags) { |
| + found_components_unittests = true; |
| + } |
| + } |
| + EXPECT_TRUE(found_components_unittests); |
| +} |
| +#endif // defined(OS_MACOSX) |
| + |
| } // namespace tracing |