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