| 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 16 matching lines...) Expand all Loading... |
| 27 #include "base/logging.h" | 27 #include "base/logging.h" |
| 28 #include "base/message_loop/message_loop.h" | 28 #include "base/message_loop/message_loop.h" |
| 29 #include "base/path_service.h" | 29 #include "base/path_service.h" |
| 30 #include "base/process/launch.h" | 30 #include "base/process/launch.h" |
| 31 #include "base/process/process.h" | 31 #include "base/process/process.h" |
| 32 #include "base/run_loop.h" | 32 #include "base/run_loop.h" |
| 33 #include "base/single_thread_task_runner.h" | 33 #include "base/single_thread_task_runner.h" |
| 34 #include "base/strings/string_number_conversions.h" | 34 #include "base/strings/string_number_conversions.h" |
| 35 #include "base/strings/string_util.h" | 35 #include "base/strings/string_util.h" |
| 36 #include "base/strings/utf_string_conversions.h" | 36 #include "base/strings/utf_string_conversions.h" |
| 37 #include "base/test/logging_utils.h" |
| 37 #include "base/threading/platform_thread.h" | 38 #include "base/threading/platform_thread.h" |
| 38 #include "base/threading/thread.h" | 39 #include "base/threading/thread.h" |
| 39 #include "base/threading/thread_task_runner_handle.h" | 40 #include "base/threading/thread_task_runner_handle.h" |
| 40 #include "net/base/io_buffer.h" | 41 #include "net/base/io_buffer.h" |
| 41 #include "net/base/net_errors.h" | 42 #include "net/base/net_errors.h" |
| 42 #include "net/base/test_completion_callback.h" | 43 #include "net/base/test_completion_callback.h" |
| 43 #include "net/disk_cache/blockfile/backend_impl.h" | 44 #include "net/disk_cache/blockfile/backend_impl.h" |
| 44 #include "net/disk_cache/blockfile/stress_support.h" | 45 #include "net/disk_cache/blockfile/stress_support.h" |
| 45 #include "net/disk_cache/blockfile/trace.h" | 46 #include "net/disk_cache/blockfile/trace.h" |
| 46 #include "net/disk_cache/disk_cache.h" | 47 #include "net/disk_cache/disk_cache.h" |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 // We leak everything here :) | 373 // We leak everything here :) |
| 373 bool StartCrashThread() { | 374 bool StartCrashThread() { |
| 374 base::Thread* thread = new base::Thread("party_crasher"); | 375 base::Thread* thread = new base::Thread("party_crasher"); |
| 375 if (!thread->Start()) | 376 if (!thread->Start()) |
| 376 return false; | 377 return false; |
| 377 | 378 |
| 378 RunSoon(thread->task_runner()); | 379 RunSoon(thread->task_runner()); |
| 379 return true; | 380 return true; |
| 380 } | 381 } |
| 381 | 382 |
| 382 void CrashHandler(const std::string& str) { | 383 void CrashHandler(const char* file, |
| 384 int line, |
| 385 size_t message_start, |
| 386 size_t stack_start, |
| 387 const std::string& str) { |
| 383 g_crashing = true; | 388 g_crashing = true; |
| 384 base::debug::BreakDebugger(); | 389 base::debug::BreakDebugger(); |
| 385 } | 390 } |
| 386 | 391 |
| 387 bool MessageHandler(int severity, const char* file, int line, | 392 bool MessageHandler(int severity, const char* file, int line, |
| 388 size_t message_start, const std::string& str) { | 393 size_t message_start, const std::string& str) { |
| 389 const size_t kMaxMessageLen = 48; | 394 const size_t kMaxMessageLen = 48; |
| 390 char message[kMaxMessageLen]; | 395 char message[kMaxMessageLen]; |
| 391 size_t len = std::min(str.length() - message_start, kMaxMessageLen - 1); | 396 size_t len = std::min(str.length() - message_start, kMaxMessageLen - 1); |
| 392 | 397 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 407 { 0x9a, 0xbf, 0xd5, 0x43, 0x83, 0xf1, 0x4a, 0xd } }; | 412 { 0x9a, 0xbf, 0xd5, 0x43, 0x83, 0xf1, 0x4a, 0xd } }; |
| 408 #endif | 413 #endif |
| 409 | 414 |
| 410 int main(int argc, const char* argv[]) { | 415 int main(int argc, const char* argv[]) { |
| 411 // Setup an AtExitManager so Singleton objects will be destructed. | 416 // Setup an AtExitManager so Singleton objects will be destructed. |
| 412 base::AtExitManager at_exit_manager; | 417 base::AtExitManager at_exit_manager; |
| 413 | 418 |
| 414 if (argc < 2) | 419 if (argc < 2) |
| 415 return MasterCode(); | 420 return MasterCode(); |
| 416 | 421 |
| 417 logging::SetLogAssertHandler(CrashHandler); | 422 logging::ScopedLogAssertHandler scoped_assert_handler( |
| 423 base::Bind(CrashHandler)); |
| 418 logging::SetLogMessageHandler(MessageHandler); | 424 logging::SetLogMessageHandler(MessageHandler); |
| 419 | 425 |
| 420 #if defined(OS_WIN) | 426 #if defined(OS_WIN) |
| 421 logging::LogEventProvider::Initialize(kStressCacheTraceProviderName); | 427 logging::LogEventProvider::Initialize(kStressCacheTraceProviderName); |
| 422 #else | 428 #else |
| 423 base::CommandLine::Init(argc, argv); | 429 base::CommandLine::Init(argc, argv); |
| 424 logging::LoggingSettings settings; | 430 logging::LoggingSettings settings; |
| 425 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 431 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| 426 logging::InitLogging(settings); | 432 logging::InitLogging(settings); |
| 427 #endif | 433 #endif |
| 428 | 434 |
| 429 // Some time for the memory manager to flush stuff. | 435 // Some time for the memory manager to flush stuff. |
| 430 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(3)); | 436 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(3)); |
| 431 base::MessageLoopForIO message_loop; | 437 base::MessageLoopForIO message_loop; |
| 432 | 438 |
| 433 char* end; | 439 char* end; |
| 434 long int iteration = strtol(argv[1], &end, 0); | 440 long int iteration = strtol(argv[1], &end, 0); |
| 435 | 441 |
| 436 if (!StartCrashThread()) { | 442 if (!StartCrashThread()) { |
| 437 printf("failed to start thread\n"); | 443 printf("failed to start thread\n"); |
| 438 return kError; | 444 return kError; |
| 439 } | 445 } |
| 440 | 446 |
| 441 StressTheCache(iteration); | 447 StressTheCache(iteration); |
| 442 return 0; | 448 return 0; |
| 443 } | 449 } |
| OLD | NEW |