Chromium Code Reviews| Index: base/process/process_metrics_unittest.cc |
| diff --git a/base/process/process_metrics_unittest.cc b/base/process/process_metrics_unittest.cc |
| index b11a26b24ba7cfd5417c519dff06257d5b3bb17b..890e624bfa2e1f731f19084fba7cc27de15943e9 100644 |
| --- a/base/process/process_metrics_unittest.cc |
| +++ b/base/process/process_metrics_unittest.cc |
| @@ -24,6 +24,10 @@ |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "testing/multiprocess_func_list.h" |
| +#if defined(OS_MACOSX) |
| +#include <sys/mman.h> |
| +#endif |
| + |
| namespace base { |
| namespace debug { |
| @@ -53,6 +57,42 @@ class SystemMetricsTest : public testing::Test { |
| ///////////////////////////////////////////////////////////////////////////// |
| +#if defined(OS_MACOSX) && !defined(OS_IOS) |
| +TEST_F(SystemMetricsTest, LockedBytes) { |
| + ProcessHandle handle = GetCurrentProcessHandle(); |
| + std::unique_ptr<ProcessMetrics> metrics( |
| + ProcessMetrics::CreateProcessMetrics(handle, nullptr)); |
| + |
| + size_t initial_locked_bytes; |
| + bool result = |
| + metrics->GetMemoryBytes(nullptr, nullptr, nullptr, &initial_locked_bytes); |
| + ASSERT_TRUE(result); |
| + |
| + size_t size = 8 * 1024 * 1024; |
| + std::unique_ptr<char[]> memory(new char[size]); |
| + int r = mlock(memory.get(), size); |
| + ASSERT_EQ(r, 0); |
|
Lei Zhang
2017/03/30 04:26:35
ASSERT_EQ(expected, actual);
Mark Mentovai
2017/03/30 11:56:15
Lei Zhang wrote:
erikchen
2017/03/30 18:02:48
Done.
|
| + |
| + size_t new_locked_bytes; |
| + result = |
| + metrics->GetMemoryBytes(nullptr, nullptr, nullptr, &new_locked_bytes); |
| + ASSERT_TRUE(result); |
| + |
| + // There should be around |size| more locked bytes, but multi-threading might |
| + // cause noise. |
| + EXPECT_LT(initial_locked_bytes + size / 2, new_locked_bytes); |
| + EXPECT_GT(initial_locked_bytes + size * 1.5, new_locked_bytes); |
| + |
| + r = munlock(memory.get(), size); |
| + ASSERT_EQ(r, 0); |
| + |
| + result = |
| + metrics->GetMemoryBytes(nullptr, nullptr, nullptr, &new_locked_bytes); |
| + ASSERT_TRUE(result); |
| + EXPECT_EQ(initial_locked_bytes, new_locked_bytes); |
| +} |
| +#endif // defined(OS_MACOSX) |
| + |
| #if defined(OS_LINUX) || defined(OS_ANDROID) |
| TEST_F(SystemMetricsTest, IsValidDiskName) { |
| std::string invalid_input1 = ""; |