| 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 char* file, | 382 void CrashHandler(const std::string& str) { |
| 383 int line, | |
| 384 const base::StringPiece str, | |
| 385 const base::StringPiece stack_trace) { | |
| 386 g_crashing = true; | 383 g_crashing = true; |
| 387 base::debug::BreakDebugger(); | 384 base::debug::BreakDebugger(); |
| 388 } | 385 } |
| 389 | 386 |
| 390 bool MessageHandler(int severity, const char* file, int line, | 387 bool MessageHandler(int severity, const char* file, int line, |
| 391 size_t message_start, const std::string& str) { | 388 size_t message_start, const std::string& str) { |
| 392 const size_t kMaxMessageLen = 48; | 389 const size_t kMaxMessageLen = 48; |
| 393 char message[kMaxMessageLen]; | 390 char message[kMaxMessageLen]; |
| 394 size_t len = std::min(str.length() - message_start, kMaxMessageLen - 1); | 391 size_t len = std::min(str.length() - message_start, kMaxMessageLen - 1); |
| 395 | 392 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 410 { 0x9a, 0xbf, 0xd5, 0x43, 0x83, 0xf1, 0x4a, 0xd } }; | 407 { 0x9a, 0xbf, 0xd5, 0x43, 0x83, 0xf1, 0x4a, 0xd } }; |
| 411 #endif | 408 #endif |
| 412 | 409 |
| 413 int main(int argc, const char* argv[]) { | 410 int main(int argc, const char* argv[]) { |
| 414 // Setup an AtExitManager so Singleton objects will be destructed. | 411 // Setup an AtExitManager so Singleton objects will be destructed. |
| 415 base::AtExitManager at_exit_manager; | 412 base::AtExitManager at_exit_manager; |
| 416 | 413 |
| 417 if (argc < 2) | 414 if (argc < 2) |
| 418 return MasterCode(); | 415 return MasterCode(); |
| 419 | 416 |
| 420 logging::ScopedLogAssertHandler scoped_assert_handler( | 417 logging::SetLogAssertHandler(CrashHandler); |
| 421 base::Bind(CrashHandler)); | |
| 422 logging::SetLogMessageHandler(MessageHandler); | 418 logging::SetLogMessageHandler(MessageHandler); |
| 423 | 419 |
| 424 #if defined(OS_WIN) | 420 #if defined(OS_WIN) |
| 425 logging::LogEventProvider::Initialize(kStressCacheTraceProviderName); | 421 logging::LogEventProvider::Initialize(kStressCacheTraceProviderName); |
| 426 #else | 422 #else |
| 427 base::CommandLine::Init(argc, argv); | 423 base::CommandLine::Init(argc, argv); |
| 428 logging::LoggingSettings settings; | 424 logging::LoggingSettings settings; |
| 429 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 425 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| 430 logging::InitLogging(settings); | 426 logging::InitLogging(settings); |
| 431 #endif | 427 #endif |
| 432 | 428 |
| 433 // Some time for the memory manager to flush stuff. | 429 // Some time for the memory manager to flush stuff. |
| 434 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(3)); | 430 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(3)); |
| 435 base::MessageLoopForIO message_loop; | 431 base::MessageLoopForIO message_loop; |
| 436 | 432 |
| 437 char* end; | 433 char* end; |
| 438 long int iteration = strtol(argv[1], &end, 0); | 434 long int iteration = strtol(argv[1], &end, 0); |
| 439 | 435 |
| 440 if (!StartCrashThread()) { | 436 if (!StartCrashThread()) { |
| 441 printf("failed to start thread\n"); | 437 printf("failed to start thread\n"); |
| 442 return kError; | 438 return kError; |
| 443 } | 439 } |
| 444 | 440 |
| 445 StressTheCache(iteration); | 441 StressTheCache(iteration); |
| 446 return 0; | 442 return 0; |
| 447 } | 443 } |
| OLD | NEW |