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

Side by Side Diff: breakpad/linux/linux_dumper_unittest.cc

Issue 414049: Linux: Use upstream google-breakpad instead of our fork.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month 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 | « breakpad/linux/linux_dumper.cc ('k') | breakpad/linux/linux_libc_support.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 #include <unistd.h>
31
32 #include "breakpad/linux/linux_dumper.h"
33 #include "testing/gtest/include/gtest/gtest.h"
34
35 using namespace google_breakpad;
36
37 namespace {
38 typedef testing::Test LinuxDumperTest;
39 }
40
41 TEST(LinuxDumperTest, Setup) {
42 LinuxDumper dumper(getpid());
43 }
44
45 TEST(LinuxDumperTest, FindMappings) {
46 LinuxDumper dumper(getpid());
47 ASSERT_TRUE(dumper.Init());
48
49 ASSERT_TRUE(dumper.FindMapping(reinterpret_cast<void*>(getpid)));
50 ASSERT_TRUE(dumper.FindMapping(reinterpret_cast<void*>(printf)));
51 ASSERT_FALSE(dumper.FindMapping(NULL));
52 }
53
54 TEST(LinuxDumperTest, ThreadList) {
55 LinuxDumper dumper(getpid());
56 ASSERT_TRUE(dumper.Init());
57
58 ASSERT_GE(dumper.threads().size(), 1);
59 bool found = false;
60 for (size_t i = 0; i < dumper.threads().size(); ++i) {
61 if (dumper.threads()[i] == getpid()) {
62 found = true;
63 break;
64 }
65 }
66 }
67
68 TEST(LinuxDumperTest, BuildProcPath) {
69 const pid_t pid = getpid();
70 LinuxDumper dumper(pid);
71
72 char maps_path[256] = "dummymappath";
73 char maps_path_expected[256];
74 snprintf(maps_path_expected, sizeof(maps_path_expected),
75 "/proc/%d/maps", pid);
76 dumper.BuildProcPath(maps_path, pid, "maps");
77 ASSERT_STREQ(maps_path, maps_path_expected);
78
79 // In release mode, we expect BuildProcPath to handle the invalid
80 // parameters correctly and fill map_path with an empty
81 // NULL-terminated string.
82 #ifdef NDEBUG
83 snprintf(maps_path, sizeof(maps_path), "dummymappath");
84 dumper.BuildProcPath(maps_path, 0, "maps");
85 EXPECT_STREQ(maps_path, "");
86
87 snprintf(maps_path, sizeof(maps_path), "dummymappath");
88 dumper.BuildProcPath(maps_path, getpid(), "");
89 EXPECT_STREQ(maps_path, "");
90
91 snprintf(maps_path, sizeof(maps_path), "dummymappath");
92 dumper.BuildProcPath(maps_path, getpid(), NULL);
93 EXPECT_STREQ(maps_path, "");
94 #endif
95 }
96
97 TEST(LinuxDumperTest, MappingsIncludeLinuxGate) {
98 LinuxDumper dumper(getpid());
99 ASSERT_TRUE(dumper.Init());
100
101 void* linux_gate_loc = dumper.FindBeginningOfLinuxGateSharedLibrary(getpid());
102 if (linux_gate_loc) {
103 bool found_linux_gate = false;
104
105 const wasteful_vector<MappingInfo*> mappings = dumper.mappings();
106 const MappingInfo* mapping;
107 for (unsigned i = 0; i < mappings.size(); ++i) {
108 mapping = mappings[i];
109 if (!strcmp(mapping->name, kLinuxGateLibraryName)) {
110 found_linux_gate = true;
111 break;
112 }
113 }
114 EXPECT_TRUE(found_linux_gate);
115 EXPECT_EQ(linux_gate_loc, reinterpret_cast<void*>(mapping->start_addr));
116 EXPECT_EQ(0, memcmp(linux_gate_loc, ELFMAG, SELFMAG));
117 }
118 }
OLDNEW
« no previous file with comments | « breakpad/linux/linux_dumper.cc ('k') | breakpad/linux/linux_libc_support.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698