| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/debug/proc_maps_linux.h" | 5 #include "base/debug/proc_maps_linux.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 173 |
| 174 std::vector<MappedMemoryRegion> regions; | 174 std::vector<MappedMemoryRegion> regions; |
| 175 EXPECT_TRUE(ParseProcMaps(kTestCases[i].input, ®ions)); | 175 EXPECT_TRUE(ParseProcMaps(kTestCases[i].input, ®ions)); |
| 176 EXPECT_EQ(1u, regions.size()); | 176 EXPECT_EQ(1u, regions.size()); |
| 177 if (regions.empty()) | 177 if (regions.empty()) |
| 178 continue; | 178 continue; |
| 179 EXPECT_EQ(kTestCases[i].permissions, regions[0].permissions); | 179 EXPECT_EQ(kTestCases[i].permissions, regions[0].permissions); |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 | 182 |
| 183 // ProcMapsTest.ReadProcMaps fails under TSan on Linux, | 183 TEST(ProcMapsTest, ReadProcMaps) { |
| 184 // see http://crbug.com/258451. | |
| 185 #if defined(THREAD_SANITIZER) | |
| 186 #define MAYBE_ReadProcMaps DISABLED_ReadProcMaps | |
| 187 #else | |
| 188 #define MAYBE_ReadProcMaps ReadProcMaps | |
| 189 #endif | |
| 190 TEST(ProcMapsTest, MAYBE_ReadProcMaps) { | |
| 191 std::string proc_maps; | 184 std::string proc_maps; |
| 192 ASSERT_TRUE(ReadProcMaps(&proc_maps)); | 185 ASSERT_TRUE(ReadProcMaps(&proc_maps)); |
| 193 | 186 |
| 194 std::vector<MappedMemoryRegion> regions; | 187 std::vector<MappedMemoryRegion> regions; |
| 195 ASSERT_TRUE(ParseProcMaps(proc_maps, ®ions)); | 188 ASSERT_TRUE(ParseProcMaps(proc_maps, ®ions)); |
| 196 ASSERT_FALSE(regions.empty()); | 189 ASSERT_FALSE(regions.empty()); |
| 197 | 190 |
| 198 // We should be able to find both the current executable as well as the stack | 191 // We should be able to find both the current executable as well as the stack |
| 199 // mapped into memory. Use the address of |proc_maps| as a way of finding the | 192 // mapped into memory. Use the address of |proc_maps| as a way of finding the |
| 200 // stack. | 193 // stack. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 231 EXPECT_FALSE(found_address) << "Found same address in multiple regions"; | 224 EXPECT_FALSE(found_address) << "Found same address in multiple regions"; |
| 232 found_address = true; | 225 found_address = true; |
| 233 } | 226 } |
| 234 } | 227 } |
| 235 | 228 |
| 236 EXPECT_TRUE(found_exe); | 229 EXPECT_TRUE(found_exe); |
| 237 EXPECT_TRUE(found_stack); | 230 EXPECT_TRUE(found_stack); |
| 238 EXPECT_TRUE(found_address); | 231 EXPECT_TRUE(found_address); |
| 239 } | 232 } |
| 240 | 233 |
| 234 TEST(ProcMapsTest, ReadProcMapsNonEmptyString) { |
| 235 std::string old_string("I forgot to clear the string"); |
| 236 std::string proc_maps(old_string); |
| 237 ASSERT_TRUE(ReadProcMaps(&proc_maps)); |
| 238 EXPECT_EQ(std::string::npos, proc_maps.find(old_string)); |
| 239 } |
| 240 |
| 241 TEST(ProcMapsTest, MissingFields) { | 241 TEST(ProcMapsTest, MissingFields) { |
| 242 static const char* kTestCases[] = { | 242 static const char* kTestCases[] = { |
| 243 "00400000\n", // Missing end + beyond. | 243 "00400000\n", // Missing end + beyond. |
| 244 "00400000-0040b000\n", // Missing perms + beyond. | 244 "00400000-0040b000\n", // Missing perms + beyond. |
| 245 "00400000-0040b000 r-xp\n", // Missing offset + beyond. | 245 "00400000-0040b000 r-xp\n", // Missing offset + beyond. |
| 246 "00400000-0040b000 r-xp 00000000\n", // Missing device + beyond. | 246 "00400000-0040b000 r-xp 00000000\n", // Missing device + beyond. |
| 247 "00400000-0040b000 r-xp 00000000 fc:00\n", // Missing inode + beyond. | 247 "00400000-0040b000 r-xp 00000000 fc:00\n", // Missing inode + beyond. |
| 248 "00400000-0040b000 00000000 fc:00 794418 /bin/cat\n", // Missing perms. | 248 "00400000-0040b000 00000000 fc:00 794418 /bin/cat\n", // Missing perms. |
| 249 "00400000-0040b000 r-xp fc:00 794418 /bin/cat\n", // Missing offset. | 249 "00400000-0040b000 r-xp fc:00 794418 /bin/cat\n", // Missing offset. |
| 250 "00400000-0040b000 r-xp 00000000 fc:00 /bin/cat\n", // Missing inode. | 250 "00400000-0040b000 r-xp 00000000 fc:00 /bin/cat\n", // Missing inode. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 272 | 272 |
| 273 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | 273 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
| 274 SCOPED_TRACE(base::StringPrintf("kTestCases[%zu] = %s", i, kTestCases[i])); | 274 SCOPED_TRACE(base::StringPrintf("kTestCases[%zu] = %s", i, kTestCases[i])); |
| 275 std::vector<MappedMemoryRegion> regions; | 275 std::vector<MappedMemoryRegion> regions; |
| 276 EXPECT_FALSE(ParseProcMaps(kTestCases[i], ®ions)); | 276 EXPECT_FALSE(ParseProcMaps(kTestCases[i], ®ions)); |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 | 279 |
| 280 } // namespace debug | 280 } // namespace debug |
| 281 } // namespace base | 281 } // namespace base |
| OLD | NEW |