Index: base/trace_event/process_memory_dump_unittest.cc |
diff --git a/base/trace_event/process_memory_dump_unittest.cc b/base/trace_event/process_memory_dump_unittest.cc |
index 1e1fbc69cf91cab4262c4be1522e2e70705954b6..2fdc576035a502c646dfdb827a75ae31b095ba73 100644 |
--- a/base/trace_event/process_memory_dump_unittest.cc |
+++ b/base/trace_event/process_memory_dump_unittest.cc |
@@ -5,6 +5,7 @@ |
#include "base/trace_event/process_memory_dump.h" |
#include "base/memory/scoped_ptr.h" |
+#include "base/process/process_metrics.h" |
#include "base/trace_event/memory_allocator_dump_guid.h" |
#include "base/trace_event/trace_event_argument.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -154,5 +155,36 @@ TEST(ProcessMemoryDumpTest, Suballocations) { |
pmd.reset(); |
} |
+#if defined(OS_POSIX) && !defined(OS_NACL) |
+TEST(ProcessMemoryDumpTest, CountResidentBytes) { |
+ const size_t page_size = base::GetPageSize(); |
+ // Allocate a segment on stack and check if the page is resident. |
+ char memory1[100] = {0}; |
+ void* page_start1 = reinterpret_cast<void*>( |
+ reinterpret_cast<uintptr_t>(memory1) / page_size * page_size); |
+ ssize_t res1 = ProcessMemoryDump::CountResidentBytes(page_start1, page_size); |
+ ASSERT_GE(static_cast<size_t>(res1), page_size); |
+ |
+ // Allocate few page of dirty memory and check if it is resident. |
+ scoped_ptr<char[]> memory2(new char[5 * page_size]()); |
+ void* page_start2 = reinterpret_cast<void*>( |
+ reinterpret_cast<uintptr_t>(memory2.get()) / page_size * page_size); |
+ ssize_t res2 = |
+ ProcessMemoryDump::CountResidentBytes(page_start2, 5 * page_size); |
+ ASSERT_NE(-1, res2); |
+ ASSERT_GE(static_cast<size_t>(res2), 5 * page_size); |
+ |
+ // Allocate a large memory segment (>32Mib). |
+ const size_t kVeryLargeMemorySize = 34 * 1024 * 1024; |
+ scoped_ptr<char[]> memory3(new char[kVeryLargeMemorySize]()); |
+ void* page_start3 = reinterpret_cast<void*>( |
+ reinterpret_cast<uintptr_t>(memory3.get()) / page_size * page_size); |
+ ssize_t res3 = |
+ ProcessMemoryDump::CountResidentBytes(page_start3, kVeryLargeMemorySize); |
+ ASSERT_NE(-1, res3); |
+ ASSERT_GE(static_cast<size_t>(res3), kVeryLargeMemorySize); |
+} |
+#endif // defined(OS_POSIX) && !defined(OS_NACL) |
+ |
} // namespace trace_event |
} // namespace base |