Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: base/debug/proc_maps_linux_unittest.cc

Issue 18328027: Fix ProcMapsTest.ReadProcMaps to work under Valgrind. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/valgrind/gtest_exclude/base_unittests.gtest.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 namespace base { 12 namespace base {
12 namespace debug { 13 namespace debug {
13 14
14 TEST(ProcMapsTest, Empty) { 15 TEST(ProcMapsTest, Empty) {
15 std::vector<MappedMemoryRegion> regions; 16 std::vector<MappedMemoryRegion> regions;
16 EXPECT_TRUE(ParseProcMaps("", &regions)); 17 EXPECT_TRUE(ParseProcMaps("", &regions));
17 EXPECT_EQ(0u, regions.size()); 18 EXPECT_EQ(0u, regions.size());
18 } 19 }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // 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
191 // 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
192 // stack. 193 // stack.
193 FilePath exe_path; 194 FilePath exe_path;
194 EXPECT_TRUE(PathService::Get(FILE_EXE, &exe_path)); 195 EXPECT_TRUE(PathService::Get(FILE_EXE, &exe_path));
195 uintptr_t address = reinterpret_cast<uintptr_t>(&proc_maps); 196 uintptr_t address = reinterpret_cast<uintptr_t>(&proc_maps);
196 bool found_exe = false; 197 bool found_exe = false;
197 bool found_stack = false; 198 bool found_stack = false;
198 for (size_t i = 0; i < regions.size(); ++i) { 199 for (size_t i = 0; i < regions.size(); ++i) {
199 if (regions[i].path == exe_path.value()) { 200 if (regions[i].path == exe_path.value()) {
201 // It's OK to find the executable mapped multiple times as there'll be
202 // multiple sections (e.g., text, data).
200 found_exe = true; 203 found_exe = true;
201 } 204 }
202 205
203 if (address >= regions[i].start && address < regions[i].end) { 206 if (regions[i].path == "[stack]") {
Mark Mentovai 2013/07/04 01:28:13 So now you’re looking for duplicate stacks based o
scherkus (not reviewing) 2013/07/04 01:44:39 Ooooo I like both. Done.
204 EXPECT_EQ("[stack]", regions[i].path); 207 // Only check if |address| lies within the real stack when not running
208 // Valgrind, otherwise |address| will be on a stack that Valgrind creates.
209 if (!RunningOnValgrind()) {
210 EXPECT_GE(address, regions[i].start);
211 EXPECT_LT(address, regions[i].end);
212 }
213
205 EXPECT_TRUE(regions[i].permissions & MappedMemoryRegion::READ); 214 EXPECT_TRUE(regions[i].permissions & MappedMemoryRegion::READ);
206 EXPECT_TRUE(regions[i].permissions & MappedMemoryRegion::WRITE); 215 EXPECT_TRUE(regions[i].permissions & MappedMemoryRegion::WRITE);
207 EXPECT_FALSE(regions[i].permissions & MappedMemoryRegion::EXECUTE); 216 EXPECT_FALSE(regions[i].permissions & MappedMemoryRegion::EXECUTE);
208 EXPECT_TRUE(regions[i].permissions & MappedMemoryRegion::PRIVATE); 217 EXPECT_TRUE(regions[i].permissions & MappedMemoryRegion::PRIVATE);
209 EXPECT_FALSE(found_stack) << "Found duplicate stacks"; 218 EXPECT_FALSE(found_stack) << "Found duplicate stacks";
210 found_stack = true; 219 found_stack = true;
211 } 220 }
212 } 221 }
213 222
214 EXPECT_TRUE(found_exe); 223 EXPECT_TRUE(found_exe);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 258
250 for (size_t i = 0; i < arraysize(kTestCases); ++i) { 259 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
251 SCOPED_TRACE(base::StringPrintf("kTestCases[%zu] = %s", i, kTestCases[i])); 260 SCOPED_TRACE(base::StringPrintf("kTestCases[%zu] = %s", i, kTestCases[i]));
252 std::vector<MappedMemoryRegion> regions; 261 std::vector<MappedMemoryRegion> regions;
253 EXPECT_FALSE(ParseProcMaps(kTestCases[i], &regions)); 262 EXPECT_FALSE(ParseProcMaps(kTestCases[i], &regions));
254 } 263 }
255 } 264 }
256 265
257 } // namespace debug 266 } // namespace debug
258 } // namespace base 267 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | tools/valgrind/gtest_exclude/base_unittests.gtest.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698