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 821f3c22ae49192646662241ada0768fe847efb1..2f4ea7e8c991ab80aba3ffe3e230aefaa258cf48 100644 |
| --- a/components/tracing/common/process_metrics_memory_dump_provider_unittest.cc |
| +++ b/components/tracing/common/process_metrics_memory_dump_provider_unittest.cc |
| @@ -9,6 +9,8 @@ |
| #include <memory> |
| #include "base/files/file_util.h" |
| +#include "base/memory/ptr_util.h" |
| +#include "base/process/process_metrics.h" |
| #include "base/trace_event/process_memory_dump.h" |
| #include "base/trace_event/process_memory_maps.h" |
| #include "base/trace_event/process_memory_totals.h" |
| @@ -107,15 +109,16 @@ const char kTestSmaps2[] = |
| "Locked: 0 kB\n" |
| "VmFlags: rd wr mr mw me ac sd\n"; |
| -void CreateAndSetSmapsFileForTesting(const char* smaps_string, |
| - base::ScopedFILE& file) { |
| +const char kTestStatm[] = "200 100 20 2 3 4"; |
| + |
| +void CreateTempFileWithContents(const char* contents, base::ScopedFILE* file) { |
| base::FilePath temp_path; |
| FILE* temp_file = CreateAndOpenTemporaryFile(&temp_path); |
| - file.reset(temp_file); |
| + file->reset(temp_file); |
| ASSERT_TRUE(temp_file); |
| - ASSERT_TRUE(base::WriteFileDescriptor(fileno(temp_file), smaps_string, |
| - strlen(smaps_string))); |
| + ASSERT_TRUE( |
| + base::WriteFileDescriptor(fileno(temp_file), contents, strlen(contents))); |
| } |
| } // namespace |
| @@ -182,7 +185,7 @@ TEST(ProcessMetricsMemoryDumpProviderTest, ParseProcSmaps) { |
| base::trace_event::ProcessMemoryDump pmd_1(nullptr /* session_state */, |
| dump_args); |
| base::ScopedFILE temp_file1; |
| - CreateAndSetSmapsFileForTesting(kTestSmaps1, temp_file1); |
| + CreateTempFileWithContents(kTestSmaps1, &temp_file1); |
| ProcessMetricsMemoryDumpProvider::proc_smaps_for_testing = temp_file1.get(); |
| pmmdp->OnMemoryDump(dump_args, &pmd_1); |
| ASSERT_TRUE(pmd_1.has_process_mmaps()); |
| @@ -215,7 +218,7 @@ TEST(ProcessMetricsMemoryDumpProviderTest, ParseProcSmaps) { |
| base::trace_event::ProcessMemoryDump pmd_2(nullptr /* session_state */, |
| dump_args); |
| base::ScopedFILE temp_file2; |
| - CreateAndSetSmapsFileForTesting(kTestSmaps2, temp_file2); |
| + CreateTempFileWithContents(kTestSmaps2, &temp_file2); |
| ProcessMetricsMemoryDumpProvider::proc_smaps_for_testing = temp_file2.get(); |
| pmmdp->OnMemoryDump(dump_args, &pmd_2); |
| ASSERT_TRUE(pmd_2.has_process_mmaps()); |
| @@ -234,4 +237,29 @@ TEST(ProcessMetricsMemoryDumpProviderTest, ParseProcSmaps) { |
| } |
| #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
| +TEST(ProcessMetricsMemoryDumpProviderTest, TestPollFastMemoryTotal) { |
| + ProcessMetricsMemoryDumpProvider mdp(base::kNullProcessId); |
| + mdp.SetFastMemoryPollingEnabled(true); |
|
Primiano Tucci (use gerrit)
2016/12/15 15:00:02
i'd remove this line to make sure that the file is
ssid
2016/12/16 03:16:41
now its needed.
|
| + uint64_t value; |
| + |
| +#if defined(OS_LINUX) || defined(OS_ANDROID) |
| + EXPECT_EQ(-1, mdp.fast_polling_statm_fd_); |
| + base::ScopedFILE temp_file; |
| + CreateTempFileWithContents(kTestStatm, &temp_file); |
| + mdp.set_fast_polling_statm_fd_for_testing(fileno(temp_file.get())); |
| + size_t page_size = base::GetPageSize(); |
| + for (int i = 0; i < 3; ++i) { |
| + mdp.PollFastMemoryTotal(&value); |
| + EXPECT_EQ(100 * page_size, value); |
| + } |
| + EXPECT_GE(mdp.fast_polling_statm_fd_, 0); |
| + mdp.SetFastMemoryPollingEnabled(false); |
| + EXPECT_EQ(-1, mdp.fast_polling_statm_fd_); |
| +#else |
| + mdp.PollFastMemoryTotal(&value); |
| + EXPECT_GT(value, 0); |
| + mdp.SetFastMemoryPollingEnabled(false); |
| +#endif |
| +} |
| + |
| } // namespace tracing |