OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This is a simple application that stress-tests the crash recovery of the disk | 5 // This is a simple application that stress-tests the crash recovery of the disk |
6 // cache. The main application starts a copy of itself on a loop, checking the | 6 // cache. The main application starts a copy of itself on a loop, checking the |
7 // exit code of the child process. When the child dies in an unexpected way, | 7 // exit code of the child process. When the child dies in an unexpected way, |
8 // the main application quits. | 8 // the main application quits. |
9 | 9 |
10 // The child application has two threads: one to exercise the cache in an | 10 // The child application has two threads: one to exercise the cache in an |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 // We leak everything here :) | 372 // We leak everything here :) |
373 bool StartCrashThread() { | 373 bool StartCrashThread() { |
374 base::Thread* thread = new base::Thread("party_crasher"); | 374 base::Thread* thread = new base::Thread("party_crasher"); |
375 if (!thread->Start()) | 375 if (!thread->Start()) |
376 return false; | 376 return false; |
377 | 377 |
378 RunSoon(thread->task_runner()); | 378 RunSoon(thread->task_runner()); |
379 return true; | 379 return true; |
380 } | 380 } |
381 | 381 |
382 void CrashHandler(const std::string& str) { | 382 void CrashHandler(const char* file, |
| 383 int line, |
| 384 const base::StringPiece str, |
| 385 const base::StringPiece stack_trace) { |
383 g_crashing = true; | 386 g_crashing = true; |
384 base::debug::BreakDebugger(); | 387 base::debug::BreakDebugger(); |
385 } | 388 } |
386 | 389 |
387 bool MessageHandler(int severity, const char* file, int line, | 390 bool MessageHandler(int severity, const char* file, int line, |
388 size_t message_start, const std::string& str) { | 391 size_t message_start, const std::string& str) { |
389 const size_t kMaxMessageLen = 48; | 392 const size_t kMaxMessageLen = 48; |
390 char message[kMaxMessageLen]; | 393 char message[kMaxMessageLen]; |
391 size_t len = std::min(str.length() - message_start, kMaxMessageLen - 1); | 394 size_t len = std::min(str.length() - message_start, kMaxMessageLen - 1); |
392 | 395 |
(...skipping 14 matching lines...) Expand all Loading... |
407 { 0x9a, 0xbf, 0xd5, 0x43, 0x83, 0xf1, 0x4a, 0xd } }; | 410 { 0x9a, 0xbf, 0xd5, 0x43, 0x83, 0xf1, 0x4a, 0xd } }; |
408 #endif | 411 #endif |
409 | 412 |
410 int main(int argc, const char* argv[]) { | 413 int main(int argc, const char* argv[]) { |
411 // Setup an AtExitManager so Singleton objects will be destructed. | 414 // Setup an AtExitManager so Singleton objects will be destructed. |
412 base::AtExitManager at_exit_manager; | 415 base::AtExitManager at_exit_manager; |
413 | 416 |
414 if (argc < 2) | 417 if (argc < 2) |
415 return MasterCode(); | 418 return MasterCode(); |
416 | 419 |
417 logging::SetLogAssertHandler(CrashHandler); | 420 logging::ScopedLogAssertHandler scoped_assert_handler( |
| 421 base::Bind(CrashHandler)); |
418 logging::SetLogMessageHandler(MessageHandler); | 422 logging::SetLogMessageHandler(MessageHandler); |
419 | 423 |
420 #if defined(OS_WIN) | 424 #if defined(OS_WIN) |
421 logging::LogEventProvider::Initialize(kStressCacheTraceProviderName); | 425 logging::LogEventProvider::Initialize(kStressCacheTraceProviderName); |
422 #else | 426 #else |
423 base::CommandLine::Init(argc, argv); | 427 base::CommandLine::Init(argc, argv); |
424 logging::LoggingSettings settings; | 428 logging::LoggingSettings settings; |
425 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 429 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
426 logging::InitLogging(settings); | 430 logging::InitLogging(settings); |
427 #endif | 431 #endif |
428 | 432 |
429 // Some time for the memory manager to flush stuff. | 433 // Some time for the memory manager to flush stuff. |
430 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(3)); | 434 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(3)); |
431 base::MessageLoopForIO message_loop; | 435 base::MessageLoopForIO message_loop; |
432 | 436 |
433 char* end; | 437 char* end; |
434 long int iteration = strtol(argv[1], &end, 0); | 438 long int iteration = strtol(argv[1], &end, 0); |
435 | 439 |
436 if (!StartCrashThread()) { | 440 if (!StartCrashThread()) { |
437 printf("failed to start thread\n"); | 441 printf("failed to start thread\n"); |
438 return kError; | 442 return kError; |
439 } | 443 } |
440 | 444 |
441 StressTheCache(iteration); | 445 StressTheCache(iteration); |
442 return 0; | 446 return 0; |
443 } | 447 } |
OLD | NEW |