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..a5754cf18bef7833ed457d343685f8d67c31ac73 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) && !defined(ADDRESS_SANITIZER) |
+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(0, r); |
+ |
+ 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(0, r); |
+ |
+ result = |
+ metrics->GetMemoryBytes(nullptr, nullptr, nullptr, &new_locked_bytes); |
+ ASSERT_TRUE(result); |
+ EXPECT_EQ(initial_locked_bytes, new_locked_bytes); |
+} |
+#endif // defined(OS_MACOSX) && !defined(OS_IOS) && !defined(ADDRESS_SANITIZER) |
+ |
#if defined(OS_LINUX) || defined(OS_ANDROID) |
TEST_F(SystemMetricsTest, IsValidDiskName) { |
std::string invalid_input1 = ""; |