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

Side by Side Diff: snapshot/crashpad_info_client_options_test.cc

Issue 1052813002: win: make CrashpadInfo retrievable (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: more fixes Created 5 years, 7 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
OLDNEW
1 // Copyright 2015 The Crashpad Authors. All rights reserved. 1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "snapshot/mac/crashpad_info_client_options.h" 15 #include "snapshot/crashpad_info_client_options.h"
16
17 #include <dlfcn.h>
18 16
19 #include "base/files/file_path.h" 17 #include "base/files/file_path.h"
18 #include "build/build_config.h"
20 #include "client/crashpad_info.h" 19 #include "client/crashpad_info.h"
21 #include "gtest/gtest.h" 20 #include "gtest/gtest.h"
21 #include "test/errors.h"
22 #include "test/paths.h"
23
24 #if defined(OS_MACOSX)
25 #include <dlfcn.h>
22 #include "snapshot/mac/process_snapshot_mac.h" 26 #include "snapshot/mac/process_snapshot_mac.h"
23 #include "test/paths.h" 27 #elif defined(OS_WIN)
28 #include <windows.h>
29 #include "snapshot/win/process_snapshot_win.h"
30 #endif
24 31
25 namespace crashpad { 32 namespace crashpad {
26 namespace test { 33 namespace test {
27 namespace { 34 namespace {
28 35
29 TEST(CrashpadInfoClientOptions, TriStateFromCrashpadInfo) { 36 TEST(CrashpadInfoClientOptions, TriStateFromCrashpadInfo) {
30 EXPECT_EQ(TriState::kUnset, 37 EXPECT_EQ(TriState::kUnset,
31 CrashpadInfoClientOptions::TriStateFromCrashpadInfo(0)); 38 CrashpadInfoClientOptions::TriStateFromCrashpadInfo(0));
32 EXPECT_EQ(TriState::kEnabled, 39 EXPECT_EQ(TriState::kEnabled,
33 CrashpadInfoClientOptions::TriStateFromCrashpadInfo(1)); 40 CrashpadInfoClientOptions::TriStateFromCrashpadInfo(1));
(...skipping 21 matching lines...) Expand all
55 } 62 }
56 63
57 private: 64 private:
58 CrashpadInfo* crashpad_info_; 65 CrashpadInfo* crashpad_info_;
59 66
60 DISALLOW_COPY_AND_ASSIGN(ScopedUnsetCrashpadInfoOptions); 67 DISALLOW_COPY_AND_ASSIGN(ScopedUnsetCrashpadInfoOptions);
61 }; 68 };
62 69
63 TEST(CrashpadInfoClientOptions, OneModule) { 70 TEST(CrashpadInfoClientOptions, OneModule) {
64 // Make sure that the initial state has all values unset. 71 // Make sure that the initial state has all values unset.
72 #if defined(OS_MACOSX)
65 ProcessSnapshotMac process_snapshot; 73 ProcessSnapshotMac process_snapshot;
66 ASSERT_TRUE(process_snapshot.Initialize(mach_task_self())); 74 ASSERT_TRUE(process_snapshot.Initialize(mach_task_self()));
75 #elif defined(OS_WIN)
76 ProcessSnapshotWin process_snapshot;
77 ASSERT_TRUE(process_snapshot.Initialize(GetCurrentProcess()));
78 #else
79 #error Port.
80 #endif // OS_MACOSX
67 81
68 CrashpadInfoClientOptions options; 82 CrashpadInfoClientOptions options;
69 process_snapshot.GetCrashpadOptions(&options); 83 process_snapshot.GetCrashpadOptions(&options);
70 84
71 EXPECT_EQ(TriState::kUnset, options.crashpad_handler_behavior); 85 EXPECT_EQ(TriState::kUnset, options.crashpad_handler_behavior);
72 EXPECT_EQ(TriState::kUnset, options.system_crash_reporter_forwarding); 86 EXPECT_EQ(TriState::kUnset, options.system_crash_reporter_forwarding);
73 87
74 CrashpadInfo* crashpad_info = CrashpadInfo::GetCrashpadInfo(); 88 CrashpadInfo* crashpad_info = CrashpadInfo::GetCrashpadInfo();
75 ASSERT_TRUE(crashpad_info); 89 ASSERT_TRUE(crashpad_info);
76 90
(...skipping 11 matching lines...) Expand all
88 ScopedUnsetCrashpadInfoOptions unset(crashpad_info); 102 ScopedUnsetCrashpadInfoOptions unset(crashpad_info);
89 103
90 crashpad_info->set_system_crash_reporter_forwarding(TriState::kDisabled); 104 crashpad_info->set_system_crash_reporter_forwarding(TriState::kDisabled);
91 105
92 process_snapshot.GetCrashpadOptions(&options); 106 process_snapshot.GetCrashpadOptions(&options);
93 EXPECT_EQ(TriState::kUnset, options.crashpad_handler_behavior); 107 EXPECT_EQ(TriState::kUnset, options.crashpad_handler_behavior);
94 EXPECT_EQ(TriState::kDisabled, options.system_crash_reporter_forwarding); 108 EXPECT_EQ(TriState::kDisabled, options.system_crash_reporter_forwarding);
95 } 109 }
96 } 110 }
97 111
112 #if defined(OS_POSIX)
113 using DlHandle = void*;
114 #elif defined(OS_WIN)
115 using DlHandle = HMODULE;
116 #endif // OS_POSIX
117
98 class ScopedDlHandle { 118 class ScopedDlHandle {
99 public: 119 public:
100 explicit ScopedDlHandle(void* dl_handle) 120 explicit ScopedDlHandle(DlHandle dl_handle)
101 : dl_handle_(dl_handle) { 121 : dl_handle_(dl_handle) {
102 } 122 }
103 123
104 ~ScopedDlHandle() { 124 ~ScopedDlHandle() {
105 if (dl_handle_) { 125 if (dl_handle_) {
126 #if defined(OS_POSIX)
106 if (dlclose(dl_handle_) != 0) { 127 if (dlclose(dl_handle_) != 0) {
107 LOG(ERROR) << "dlclose: " << dlerror(); 128 LOG(ERROR) << "dlclose: " << dlerror();
108 } 129 }
130 #elif defined(OS_WIN)
131 if (!FreeLibrary(dl_handle_))
132 PLOG(ERROR) << "FreeLibrary";
133 #endif // OS_POSIX
109 } 134 }
110 } 135 }
111 136
112 bool valid() const { return dl_handle_ != nullptr; } 137 bool valid() const { return dl_handle_ != nullptr; }
113 138
114 template <typename T> 139 template <typename T>
115 T LookUpSymbol(const char* symbol_name) { 140 T LookUpSymbol(const char* symbol_name) {
141 #if defined(OS_POSIX)
116 return reinterpret_cast<T>(dlsym(dl_handle_, symbol_name)); 142 return reinterpret_cast<T>(dlsym(dl_handle_, symbol_name));
143 #elif defined(OS_WIN)
144 return reinterpret_cast<T>(GetProcAddress(dl_handle_, symbol_name));
145 #endif // OS_POSIX
117 } 146 }
118 147
119 private: 148 private:
120 void* dl_handle_; 149 DlHandle dl_handle_;
121 150
122 DISALLOW_COPY_AND_ASSIGN(ScopedDlHandle); 151 DISALLOW_COPY_AND_ASSIGN(ScopedDlHandle);
123 }; 152 };
124 153
125 TEST(CrashpadInfoClientOptions, TwoModules) { 154 TEST(CrashpadInfoClientOptions, TwoModules) {
126 // Open the module, which has its own CrashpadInfo structure. 155 // Open the module, which has its own CrashpadInfo structure.
127 base::FilePath module_path = 156 #if defined(OS_MACOSX)
128 Paths::Executable().DirName().Append("crashpad_snapshot_test_module.so"); 157 const base::FilePath::StringType kDlExtension = FILE_PATH_LITERAL(".so");
158 #elif defined(OS_WIN)
159 const base::FilePath::StringType kDlExtension = FILE_PATH_LITERAL(".dll");
160 #endif
161 base::FilePath module_path = Paths::Executable().DirName().Append(
162 FILE_PATH_LITERAL("crashpad_snapshot_test_module") + kDlExtension);
163 #if defined(OS_MACOSX)
129 ScopedDlHandle dl_handle( 164 ScopedDlHandle dl_handle(
130 dlopen(module_path.value().c_str(), RTLD_LAZY | RTLD_LOCAL)); 165 dlopen(module_path.value().c_str(), RTLD_LAZY | RTLD_LOCAL));
131 ASSERT_TRUE(dl_handle.valid()) << "dlopen " << module_path.value() << ": " 166 ASSERT_TRUE(dl_handle.valid()) << "dlopen " << module_path.value() << ": "
132 << dlerror(); 167 << dlerror();
168 #elif defined(OS_WIN)
169 ScopedDlHandle dl_handle(LoadLibrary(module_path.value().c_str()));
170 ASSERT_TRUE(dl_handle.valid()) << "LoadLibrary "
171 << module_path.value().c_str() << ": "
172 << ErrorMessage();
173 #else
174 #error Port.
175 #endif // OS_MACOSX
133 176
134 // Get the function pointer from the module. This wraps GetCrashpadInfo(), but 177 // Get the function pointer from the module. This wraps GetCrashpadInfo(), but
135 // because it runs in the module, it returns the remote module’s CrashpadInfo 178 // because it runs in the module, it returns the remote module’s CrashpadInfo
136 // structure. 179 // structure.
137 CrashpadInfo* (*TestModule_GetCrashpadInfo)() = 180 CrashpadInfo* (*TestModule_GetCrashpadInfo)() =
138 dl_handle.LookUpSymbol<CrashpadInfo* (*)()>("TestModule_GetCrashpadInfo"); 181 dl_handle.LookUpSymbol<CrashpadInfo* (*)()>("TestModule_GetCrashpadInfo");
139 ASSERT_TRUE(TestModule_GetCrashpadInfo); 182 ASSERT_TRUE(TestModule_GetCrashpadInfo);
140 183
141 // Make sure that the initial state has all values unset. 184 // Make sure that the initial state has all values unset.
185 #if defined(OS_MACOSX)
142 ProcessSnapshotMac process_snapshot; 186 ProcessSnapshotMac process_snapshot;
143 ASSERT_TRUE(process_snapshot.Initialize(mach_task_self())); 187 ASSERT_TRUE(process_snapshot.Initialize(mach_task_self()));
188 #elif defined(OS_WIN)
189 ProcessSnapshotWin process_snapshot;
190 ASSERT_TRUE(process_snapshot.Initialize(GetCurrentProcess()));
191 #else
192 #error Port.
193 #endif // OS_MACOSX
144 194
145 CrashpadInfoClientOptions options; 195 CrashpadInfoClientOptions options;
146 process_snapshot.GetCrashpadOptions(&options); 196 process_snapshot.GetCrashpadOptions(&options);
147 197
148 EXPECT_EQ(TriState::kUnset, options.crashpad_handler_behavior); 198 EXPECT_EQ(TriState::kUnset, options.crashpad_handler_behavior);
149 EXPECT_EQ(TriState::kUnset, options.system_crash_reporter_forwarding); 199 EXPECT_EQ(TriState::kUnset, options.system_crash_reporter_forwarding);
150 200
151 // Get both CrashpadInfo structures. 201 // Get both CrashpadInfo structures.
152 CrashpadInfo* local_crashpad_info = CrashpadInfo::GetCrashpadInfo(); 202 CrashpadInfo* local_crashpad_info = CrashpadInfo::GetCrashpadInfo();
153 ASSERT_TRUE(local_crashpad_info); 203 ASSERT_TRUE(local_crashpad_info);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 246
197 process_snapshot.GetCrashpadOptions(&options); 247 process_snapshot.GetCrashpadOptions(&options);
198 EXPECT_EQ(TriState::kUnset, options.crashpad_handler_behavior); 248 EXPECT_EQ(TriState::kUnset, options.crashpad_handler_behavior);
199 EXPECT_EQ(TriState::kEnabled, options.system_crash_reporter_forwarding); 249 EXPECT_EQ(TriState::kEnabled, options.system_crash_reporter_forwarding);
200 } 250 }
201 } 251 }
202 252
203 } // namespace 253 } // namespace
204 } // namespace test 254 } // namespace test
205 } // namespace crashpad 255 } // namespace crashpad
OLDNEW
« no previous file with comments | « snapshot/crashpad_info_client_options.cc ('k') | snapshot/crashpad_info_client_options_test_module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698