OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/trace_event/process_memory_maps_dump_provider.h" | 5 #include "base/trace_event/process_memory_maps_dump_provider.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
8 #include "base/trace_event/process_memory_dump.h" | 10 #include "base/trace_event/process_memory_dump.h" |
9 #include "base/trace_event/process_memory_maps.h" | 11 #include "base/trace_event/process_memory_maps.h" |
10 #include "base/trace_event/trace_event_argument.h" | 12 #include "base/trace_event/trace_event_argument.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 | 14 |
13 namespace base { | 15 namespace base { |
14 namespace trace_event { | 16 namespace trace_event { |
15 | 17 |
16 namespace { | 18 namespace { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 file.reset(temp_file); | 111 file.reset(temp_file); |
110 ASSERT_TRUE(temp_file); | 112 ASSERT_TRUE(temp_file); |
111 | 113 |
112 ASSERT_TRUE(base::WriteFileDescriptor(fileno(temp_file), smaps_string, | 114 ASSERT_TRUE(base::WriteFileDescriptor(fileno(temp_file), smaps_string, |
113 strlen(smaps_string))); | 115 strlen(smaps_string))); |
114 } | 116 } |
115 | 117 |
116 } // namespace | 118 } // namespace |
117 | 119 |
118 TEST(ProcessMemoryMapsDumpProviderTest, ParseProcSmaps) { | 120 TEST(ProcessMemoryMapsDumpProviderTest, ParseProcSmaps) { |
119 const uint32 kProtR = ProcessMemoryMaps::VMRegion::kProtectionFlagsRead; | 121 const uint32_t kProtR = ProcessMemoryMaps::VMRegion::kProtectionFlagsRead; |
120 const uint32 kProtW = ProcessMemoryMaps::VMRegion::kProtectionFlagsWrite; | 122 const uint32_t kProtW = ProcessMemoryMaps::VMRegion::kProtectionFlagsWrite; |
121 const uint32 kProtX = ProcessMemoryMaps::VMRegion::kProtectionFlagsExec; | 123 const uint32_t kProtX = ProcessMemoryMaps::VMRegion::kProtectionFlagsExec; |
122 const MemoryDumpArgs dump_args = {MemoryDumpLevelOfDetail::DETAILED}; | 124 const MemoryDumpArgs dump_args = {MemoryDumpLevelOfDetail::DETAILED}; |
123 | 125 |
124 auto pmmdp = ProcessMemoryMapsDumpProvider::GetInstance(); | 126 auto pmmdp = ProcessMemoryMapsDumpProvider::GetInstance(); |
125 | 127 |
126 // Emulate an empty /proc/self/smaps. | 128 // Emulate an empty /proc/self/smaps. |
127 ProcessMemoryDump pmd_invalid(nullptr /* session_state */); | 129 ProcessMemoryDump pmd_invalid(nullptr /* session_state */); |
128 ScopedFILE empty_file(OpenFile(FilePath("/dev/null"), "r")); | 130 ScopedFILE empty_file(OpenFile(FilePath("/dev/null"), "r")); |
129 ASSERT_TRUE(empty_file.get()); | 131 ASSERT_TRUE(empty_file.get()); |
130 ProcessMemoryMapsDumpProvider::proc_smaps_for_testing = empty_file.get(); | 132 ProcessMemoryMapsDumpProvider::proc_smaps_for_testing = empty_file.get(); |
131 pmmdp->OnMemoryDump(dump_args, &pmd_invalid); | 133 pmmdp->OnMemoryDump(dump_args, &pmd_invalid); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 EXPECT_EQ(32 * 1024UL, regions_2[0].byte_stats_proportional_resident); | 181 EXPECT_EQ(32 * 1024UL, regions_2[0].byte_stats_proportional_resident); |
180 EXPECT_EQ(16 * 1024UL, regions_2[0].byte_stats_shared_clean_resident); | 182 EXPECT_EQ(16 * 1024UL, regions_2[0].byte_stats_shared_clean_resident); |
181 EXPECT_EQ(12 * 1024UL, regions_2[0].byte_stats_shared_dirty_resident); | 183 EXPECT_EQ(12 * 1024UL, regions_2[0].byte_stats_shared_dirty_resident); |
182 EXPECT_EQ(8 * 1024UL, regions_2[0].byte_stats_private_clean_resident); | 184 EXPECT_EQ(8 * 1024UL, regions_2[0].byte_stats_private_clean_resident); |
183 EXPECT_EQ(4 * 1024UL, regions_2[0].byte_stats_private_dirty_resident); | 185 EXPECT_EQ(4 * 1024UL, regions_2[0].byte_stats_private_dirty_resident); |
184 EXPECT_EQ(0 * 1024UL, regions_2[0].byte_stats_swapped); | 186 EXPECT_EQ(0 * 1024UL, regions_2[0].byte_stats_swapped); |
185 } | 187 } |
186 | 188 |
187 } // namespace trace_event | 189 } // namespace trace_event |
188 } // namespace base | 190 } // namespace base |
OLD | NEW |