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

Side by Side Diff: src/client/windows/unittests/exception_handler_test.cc

Issue 2050013: Added a death test for the pure virtual function call.... (Closed) Base URL: http://google-breakpad.googlecode.com/svn/trunk/
Patch Set: '' Created 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2009, Google Inc. 1 // Copyright 2009, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 // Member variable for each test that they can use 53 // Member variable for each test that they can use
54 // for temporary storage. 54 // for temporary storage.
55 TCHAR temp_path_[MAX_PATH]; 55 TCHAR temp_path_[MAX_PATH];
56 56
57 // Actually constructs a temp path name. 57 // Actually constructs a temp path name.
58 virtual void SetUp(); 58 virtual void SetUp();
59 59
60 // Deletes temporary files. 60 // Deletes temporary files.
61 virtual void TearDown(); 61 virtual void TearDown();
62 62
63 void DoCrash(); 63 void DoCrashInvalidParameter();
64 void DoCrashPureVirtualCall();
64 65
65 // Utility function to test for a path's existence. 66 // Utility function to test for a path's existence.
66 static BOOL DoesPathExist(const TCHAR *path_name); 67 static BOOL DoesPathExist(const TCHAR *path_name);
67 68
68 // Client callback. 69 // Client callback.
69 static void ClientDumpCallback( 70 static void ClientDumpCallback(
70 void *dump_context, 71 void *dump_context,
71 const google_breakpad::ClientInfo *client_info, 72 const google_breakpad::ClientInfo *client_info,
72 const std::wstring *dump_path); 73 const std::wstring *dump_path);
73 74
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 121
121 void ExceptionHandlerTest::ClientDumpCallback( 122 void ExceptionHandlerTest::ClientDumpCallback(
122 void *dump_context, 123 void *dump_context,
123 const google_breakpad::ClientInfo *client_info, 124 const google_breakpad::ClientInfo *client_info,
124 const std::wstring *dump_path) { 125 const std::wstring *dump_path) {
125 dump_file = *dump_path; 126 dump_file = *dump_path;
126 // Create the full dump file name from the dump path. 127 // Create the full dump file name from the dump path.
127 full_dump_file = dump_file.substr(0, dump_file.length() - 4) + L"-full.dmp"; 128 full_dump_file = dump_file.substr(0, dump_file.length() - 4) + L"-full.dmp";
128 } 129 }
129 130
130 void ExceptionHandlerTest::DoCrash() { 131 void ExceptionHandlerTest::DoCrashInvalidParameter() {
131 google_breakpad::ExceptionHandler *exc = 132 google_breakpad::ExceptionHandler *exc =
132 new google_breakpad::ExceptionHandler( 133 new google_breakpad::ExceptionHandler(
133 temp_path_, NULL, NULL, NULL, 134 temp_path_, NULL, NULL, NULL,
134 google_breakpad::ExceptionHandler::HANDLER_INVALID_PARAMETER, 135 google_breakpad::ExceptionHandler::HANDLER_INVALID_PARAMETER,
135 kFullDumpType, kPipeName, NULL); 136 kFullDumpType, kPipeName, NULL);
136 137
137 // Disable the message box for assertions 138 // Disable the message box for assertions
138 _CrtSetReportMode(_CRT_ASSERT, 0); 139 _CrtSetReportMode(_CRT_ASSERT, 0);
139 140
140 // Although this is executing in the child process of the death test, 141 // Although this is executing in the child process of the death test,
141 // if it's not true we'll still get an error rather than the crash 142 // if it's not true we'll still get an error rather than the crash
142 // being expected. 143 // being expected.
143 ASSERT_TRUE(exc->IsOutOfProcess()); 144 ASSERT_TRUE(exc->IsOutOfProcess());
144 printf(NULL); 145 printf(NULL);
145 } 146 }
146 147
148
149 struct PureVirtualCallBase {
150 PureVirtualCallBase() {
151 // We have to reinterpret so the linker doesn't get confused because the
152 // method isn't defined.
153 reinterpret_cast<PureVirtualCallBase*>(this)->PureFunction();
154 }
155 virtual ~PureVirtualCallBase() {}
156 virtual void PureFunction() const = 0;
157 };
158 struct PureVirtualCall : public PureVirtualCallBase {
159 PureVirtualCall() { PureFunction(); }
160 virtual void PureFunction() const {}
161 };
162
163 void ExceptionHandlerTest::DoCrashPureVirtualCall() {
164 google_breakpad::ExceptionHandler *exc =
165 new google_breakpad::ExceptionHandler(
166 temp_path_, NULL, NULL, NULL,
167 google_breakpad::ExceptionHandler::HANDLER_PURECALL,
168 kFullDumpType, kPipeName, NULL);
169
170 // Disable the message box for assertions
171 _CrtSetReportMode(_CRT_ASSERT, 0);
172
173 // Although this is executing in the child process of the death test,
174 // if it's not true we'll still get an error rather than the crash
175 // being expected.
176 ASSERT_TRUE(exc->IsOutOfProcess());
177
178 // Create a new frame to ensure PureVirtualCall is not optimized to some
179 // other line in this function.
180 {
181 PureVirtualCall instance;
182 }
183 }
184
147 // This test validates that the minidump is written correctly. 185 // This test validates that the minidump is written correctly.
148 TEST_F(ExceptionHandlerTest, InvalidParameterMiniDumpTest) { 186 TEST_F(ExceptionHandlerTest, InvalidParameterMiniDumpTest) {
149 ASSERT_TRUE(DoesPathExist(temp_path_)); 187 ASSERT_TRUE(DoesPathExist(temp_path_));
150 188
151 // Call with a bad argument 189 // Call with a bad argument
152 ASSERT_TRUE(DoesPathExist(temp_path_)); 190 ASSERT_TRUE(DoesPathExist(temp_path_));
153 std::wstring dump_path(temp_path_); 191 std::wstring dump_path(temp_path_);
154 google_breakpad::CrashGenerationServer server( 192 google_breakpad::CrashGenerationServer server(
155 kPipeName, NULL, NULL, NULL, ClientDumpCallback, NULL, NULL, NULL, true, 193 kPipeName, NULL, NULL, NULL, ClientDumpCallback, NULL, NULL, NULL, true,
156 &dump_path); 194 &dump_path);
157 195
158 ASSERT_TRUE(dump_file.empty() && full_dump_file.empty()); 196 ASSERT_TRUE(dump_file.empty() && full_dump_file.empty());
159 197
160 // This HAS to be EXPECT_, because when this test case is executed in the 198 // This HAS to be EXPECT_, because when this test case is executed in the
161 // child process, the server registration will fail due to the named pipe 199 // child process, the server registration will fail due to the named pipe
162 // being the same. 200 // being the same.
163 EXPECT_TRUE(server.Start()); 201 EXPECT_TRUE(server.Start());
164 EXPECT_EXIT(this->DoCrash(), ::testing::ExitedWithCode(0), ""); 202 EXPECT_EXIT(DoCrashInvalidParameter(), ::testing::ExitedWithCode(0), "");
165 ASSERT_TRUE(!dump_file.empty() && !full_dump_file.empty()); 203 ASSERT_TRUE(!dump_file.empty() && !full_dump_file.empty());
166 ASSERT_TRUE(DoesPathExist(dump_file.c_str())); 204 ASSERT_TRUE(DoesPathExist(dump_file.c_str()));
167 205
168 // Verify the dump for infos. 206 // Verify the dump for infos.
169 DumpAnalysis mini(dump_file); 207 DumpAnalysis mini(dump_file);
170 DumpAnalysis full(full_dump_file); 208 DumpAnalysis full(full_dump_file);
171 209
172 // The dump should have all of these streams. 210 // The dump should have all of these streams.
173 EXPECT_TRUE(mini.HasStream(ThreadListStream)); 211 EXPECT_TRUE(mini.HasStream(ThreadListStream));
174 EXPECT_TRUE(full.HasStream(ThreadListStream)); 212 EXPECT_TRUE(full.HasStream(ThreadListStream));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 EXPECT_FALSE(full.HasStream(FunctionTableStream)); 244 EXPECT_FALSE(full.HasStream(FunctionTableStream));
207 EXPECT_FALSE(mini.HasStream(MemoryInfoListStream)); 245 EXPECT_FALSE(mini.HasStream(MemoryInfoListStream));
208 EXPECT_FALSE(full.HasStream(MemoryInfoListStream)); 246 EXPECT_FALSE(full.HasStream(MemoryInfoListStream));
209 EXPECT_FALSE(mini.HasStream(ThreadInfoListStream)); 247 EXPECT_FALSE(mini.HasStream(ThreadInfoListStream));
210 EXPECT_FALSE(full.HasStream(ThreadInfoListStream)); 248 EXPECT_FALSE(full.HasStream(ThreadInfoListStream));
211 EXPECT_FALSE(mini.HasStream(HandleOperationListStream)); 249 EXPECT_FALSE(mini.HasStream(HandleOperationListStream));
212 EXPECT_FALSE(full.HasStream(HandleOperationListStream)); 250 EXPECT_FALSE(full.HasStream(HandleOperationListStream));
213 EXPECT_FALSE(mini.HasStream(TokenStream)); 251 EXPECT_FALSE(mini.HasStream(TokenStream));
214 EXPECT_FALSE(full.HasStream(TokenStream)); 252 EXPECT_FALSE(full.HasStream(TokenStream));
215 } 253 }
254
255
256 // This test validates that the minidump is written correctly.
257 TEST_F(ExceptionHandlerTest, PureVirtualCallMiniDumpTest) {
258 ASSERT_TRUE(DoesPathExist(temp_path_));
259
260 // Call with a bad argument
261 ASSERT_TRUE(DoesPathExist(temp_path_));
262 std::wstring dump_path(temp_path_);
263 google_breakpad::CrashGenerationServer server(
264 kPipeName, NULL, NULL, NULL, ClientDumpCallback, NULL, NULL, NULL, true,
265 &dump_path);
266
267 ASSERT_TRUE(dump_file.empty() && full_dump_file.empty());
268
269 // This HAS to be EXPECT_, because when this test case is executed in the
270 // child process, the server registration will fail due to the named pipe
271 // being the same.
272 EXPECT_TRUE(server.Start());
273 EXPECT_EXIT(DoCrashPureVirtualCall(), ::testing::ExitedWithCode(0), "");
274 ASSERT_TRUE(!dump_file.empty() && !full_dump_file.empty());
275 ASSERT_TRUE(DoesPathExist(dump_file.c_str()));
276
277 // Verify the dump for infos.
278 DumpAnalysis mini(dump_file);
279 DumpAnalysis full(full_dump_file);
280
281 // The dump should have all of these streams.
282 EXPECT_TRUE(mini.HasStream(ThreadListStream));
283 EXPECT_TRUE(full.HasStream(ThreadListStream));
284 EXPECT_TRUE(mini.HasStream(ModuleListStream));
285 EXPECT_TRUE(full.HasStream(ModuleListStream));
286 EXPECT_TRUE(mini.HasStream(ExceptionStream));
287 EXPECT_TRUE(full.HasStream(ExceptionStream));
288 EXPECT_TRUE(mini.HasStream(SystemInfoStream));
289 EXPECT_TRUE(full.HasStream(SystemInfoStream));
290 EXPECT_TRUE(mini.HasStream(MiscInfoStream));
291 EXPECT_TRUE(full.HasStream(MiscInfoStream));
292 EXPECT_TRUE(mini.HasStream(HandleDataStream));
293 EXPECT_TRUE(full.HasStream(HandleDataStream));
294
295 // We expect PEB and TEBs in this dump.
296 EXPECT_TRUE(mini.HasTebs() || full.HasTebs());
297 EXPECT_TRUE(mini.HasPeb() || full.HasPeb());
298
299 // Minidump should have a memory listing, but no 64-bit memory.
300 EXPECT_TRUE(mini.HasStream(MemoryListStream));
301 EXPECT_FALSE(mini.HasStream(Memory64ListStream));
302
303 EXPECT_FALSE(full.HasStream(MemoryListStream));
304 EXPECT_TRUE(full.HasStream(Memory64ListStream));
305
306 // This is the only place we don't use OR because we want both not
307 // to have the streams.
308 EXPECT_FALSE(mini.HasStream(ThreadExListStream));
309 EXPECT_FALSE(full.HasStream(ThreadExListStream));
310 EXPECT_FALSE(mini.HasStream(CommentStreamA));
311 EXPECT_FALSE(full.HasStream(CommentStreamA));
312 EXPECT_FALSE(mini.HasStream(CommentStreamW));
313 EXPECT_FALSE(full.HasStream(CommentStreamW));
314 EXPECT_FALSE(mini.HasStream(FunctionTableStream));
315 EXPECT_FALSE(full.HasStream(FunctionTableStream));
316 EXPECT_FALSE(mini.HasStream(MemoryInfoListStream));
317 EXPECT_FALSE(full.HasStream(MemoryInfoListStream));
318 EXPECT_FALSE(mini.HasStream(ThreadInfoListStream));
319 EXPECT_FALSE(full.HasStream(ThreadInfoListStream));
320 EXPECT_FALSE(mini.HasStream(HandleOperationListStream));
321 EXPECT_FALSE(full.HasStream(HandleOperationListStream));
322 EXPECT_FALSE(mini.HasStream(TokenStream));
323 EXPECT_FALSE(full.HasStream(TokenStream));
324 }
216 } 325 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698