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 |
11 // infinite loop, and another one to asynchronously kill the process. | 11 // infinite loop, and another one to asynchronously kill the process. |
12 | 12 |
13 // A regular build should never crash. | 13 // A regular build should never crash. |
14 // To test that the disk cache doesn't generate critical errors with regular | 14 // To test that the disk cache doesn't generate critical errors with regular |
15 // application level crashes, edit stress_support.h. | 15 // application level crashes, edit stress_support.h. |
16 | 16 |
17 #include <string> | 17 #include <string> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
20 #include "base/at_exit.h" | 20 #include "base/at_exit.h" |
21 #include "base/bind.h" | 21 #include "base/bind.h" |
22 #include "base/command_line.h" | 22 #include "base/command_line.h" |
23 #include "base/debug/debugger.h" | 23 #include "base/debug/debugger.h" |
24 #include "base/files/file_path.h" | 24 #include "base/files/file_path.h" |
25 #include "base/logging.h" | 25 #include "base/logging.h" |
26 #include "base/message_loop/message_loop.h" | 26 #include "base/message_loop/message_loop.h" |
27 #include "base/path_service.h" | 27 #include "base/path_service.h" |
28 #include "base/process/kill.h" | 28 #include "base/process/kill.h" |
29 #include "base/process/launch.h" | 29 #include "base/process/launch.h" |
30 #include "base/process/process_handle.h" | |
31 #include "base/strings/string_number_conversions.h" | 30 #include "base/strings/string_number_conversions.h" |
32 #include "base/strings/string_util.h" | 31 #include "base/strings/string_util.h" |
33 #include "base/strings/utf_string_conversions.h" | 32 #include "base/strings/utf_string_conversions.h" |
34 #include "base/threading/platform_thread.h" | 33 #include "base/threading/platform_thread.h" |
35 #include "base/threading/thread.h" | 34 #include "base/threading/thread.h" |
36 #include "net/base/io_buffer.h" | 35 #include "net/base/io_buffer.h" |
37 #include "net/base/net_errors.h" | 36 #include "net/base/net_errors.h" |
38 #include "net/base/test_completion_callback.h" | 37 #include "net/base/test_completion_callback.h" |
39 #include "net/disk_cache/blockfile/backend_impl.h" | 38 #include "net/disk_cache/blockfile/backend_impl.h" |
40 #include "net/disk_cache/blockfile/stress_support.h" | 39 #include "net/disk_cache/blockfile/stress_support.h" |
(...skipping 11 matching lines...) Expand all Loading... |
52 const int kExpectedCrash = 100; | 51 const int kExpectedCrash = 100; |
53 | 52 |
54 // Starts a new process. | 53 // Starts a new process. |
55 int RunSlave(int iteration) { | 54 int RunSlave(int iteration) { |
56 base::FilePath exe; | 55 base::FilePath exe; |
57 PathService::Get(base::FILE_EXE, &exe); | 56 PathService::Get(base::FILE_EXE, &exe); |
58 | 57 |
59 base::CommandLine cmdline(exe); | 58 base::CommandLine cmdline(exe); |
60 cmdline.AppendArg(base::IntToString(iteration)); | 59 cmdline.AppendArg(base::IntToString(iteration)); |
61 | 60 |
62 base::ProcessHandle handle; | 61 base::Process process = base::LaunchProcess(cmdline, base::LaunchOptions()); |
63 if (!base::LaunchProcess(cmdline, base::LaunchOptions(), &handle)) { | 62 if (!process.IsValid()) { |
64 printf("Unable to run test\n"); | 63 printf("Unable to run test\n"); |
65 return kError; | 64 return kError; |
66 } | 65 } |
67 | 66 |
68 int exit_code; | 67 int exit_code; |
69 if (!base::WaitForExitCode(handle, &exit_code)) { | 68 if (!process.WaitForExit(&exit_code)) { |
70 printf("Unable to get return code\n"); | 69 printf("Unable to get return code\n"); |
71 return kError; | 70 return kError; |
72 } | 71 } |
73 return exit_code; | 72 return exit_code; |
74 } | 73 } |
75 | 74 |
76 // Main loop for the master process. | 75 // Main loop for the master process. |
77 int MasterCode() { | 76 int MasterCode() { |
78 for (int i = 0; i < 100000; i++) { | 77 for (int i = 0; i < 100000; i++) { |
79 int ret = RunSlave(i); | 78 int ret = RunSlave(i); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 long int iteration = strtol(argv[1], &end, 0); | 284 long int iteration = strtol(argv[1], &end, 0); |
286 | 285 |
287 if (!StartCrashThread()) { | 286 if (!StartCrashThread()) { |
288 printf("failed to start thread\n"); | 287 printf("failed to start thread\n"); |
289 return kError; | 288 return kError; |
290 } | 289 } |
291 | 290 |
292 StressTheCache(iteration); | 291 StressTheCache(iteration); |
293 return 0; | 292 return 0; |
294 } | 293 } |
OLD | NEW |