OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/at_exit.h" | 16 #include "base/at_exit.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "base/debug_util.h" | 18 #include "base/debug_util.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
21 #include "base/path_service.h" | 21 #include "base/path_service.h" |
22 #include "base/platform_thread.h" | 22 #include "base/platform_thread.h" |
23 #include "base/process_util.h" | 23 #include "base/process_util.h" |
24 #include "base/string_util.h" | 24 #include "base/string_util.h" |
25 #include "base/thread.h" | 25 #include "base/thread.h" |
26 #include "net/base/io_buffer.h" | |
27 #include "net/disk_cache/disk_cache.h" | 26 #include "net/disk_cache/disk_cache.h" |
28 #include "net/disk_cache/disk_cache_test_util.h" | 27 #include "net/disk_cache/disk_cache_test_util.h" |
29 | 28 |
30 using base::Time; | 29 using base::Time; |
31 | 30 |
32 const int kError = -1; | 31 const int kError = -1; |
33 const int kExpectedCrash = 100; | 32 const int kExpectedCrash = 100; |
34 | 33 |
35 // Starts a new process. | 34 // Starts a new process. |
36 int RunSlave(int iteration) { | 35 int RunSlave(int iteration) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 89 |
91 const int kNumKeys = 5000; | 90 const int kNumKeys = 5000; |
92 const int kNumEntries = 30; | 91 const int kNumEntries = 30; |
93 std::string keys[kNumKeys]; | 92 std::string keys[kNumKeys]; |
94 disk_cache::Entry* entries[kNumEntries] = {0}; | 93 disk_cache::Entry* entries[kNumEntries] = {0}; |
95 | 94 |
96 for (int i = 0; i < kNumKeys; i++) { | 95 for (int i = 0; i < kNumKeys; i++) { |
97 keys[i] = GenerateKey(true); | 96 keys[i] = GenerateKey(true); |
98 } | 97 } |
99 | 98 |
100 const int kSize = 4000; | 99 const int kDataLen = 4000; |
101 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); | 100 char data[kDataLen]; |
102 memset(buffer->data(), 'k', kSize); | 101 memset(data, 'k', kDataLen); |
103 | 102 |
104 for (int i = 0;; i++) { | 103 for (int i = 0;; i++) { |
105 int slot = rand() % kNumEntries; | 104 int slot = rand() % kNumEntries; |
106 int key = rand() % kNumKeys; | 105 int key = rand() % kNumKeys; |
107 | 106 |
108 if (entries[slot]) | 107 if (entries[slot]) |
109 entries[slot]->Close(); | 108 entries[slot]->Close(); |
110 | 109 |
111 if (!cache->OpenEntry(keys[key], &entries[slot])) | 110 if (!cache->OpenEntry(keys[key], &entries[slot])) |
112 CHECK(cache->CreateEntry(keys[key], &entries[slot])); | 111 CHECK(cache->CreateEntry(keys[key], &entries[slot])); |
113 | 112 |
114 base::snprintf(buffer->data(), kSize, "%d %d", iteration, i); | 113 base::snprintf(data, kDataLen, "%d %d", iteration, i); |
115 CHECK(kSize == entries[slot]->WriteData(0, 0, buffer, kSize, NULL, false)); | 114 CHECK(kDataLen == entries[slot]->WriteData(0, 0, data, kDataLen, NULL, |
| 115 false)); |
116 | 116 |
117 if (rand() % 100 > 80) { | 117 if (rand() % 100 > 80) { |
118 key = rand() % kNumKeys; | 118 key = rand() % kNumKeys; |
119 cache->DoomEntry(keys[key]); | 119 cache->DoomEntry(keys[key]); |
120 } | 120 } |
121 | 121 |
122 if (!(i % 100)) | 122 if (!(i % 100)) |
123 printf("Entries: %d \r", i); | 123 printf("Entries: %d \r", i); |
124 } | 124 } |
125 } | 125 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 // Setup an AtExitManager so Singleton objects will be destructed. | 181 // Setup an AtExitManager so Singleton objects will be destructed. |
182 base::AtExitManager at_exit_manager; | 182 base::AtExitManager at_exit_manager; |
183 | 183 |
184 if (argc < 2) | 184 if (argc < 2) |
185 return MasterCode(); | 185 return MasterCode(); |
186 | 186 |
187 logging::SetLogAssertHandler(CrashHandler); | 187 logging::SetLogAssertHandler(CrashHandler); |
188 | 188 |
189 // Some time for the memory manager to flush stuff. | 189 // Some time for the memory manager to flush stuff. |
190 PlatformThread::Sleep(3000); | 190 PlatformThread::Sleep(3000); |
191 MessageLoop message_loop(MessageLoop::TYPE_IO); | 191 MessageLoop message_loop; |
192 | 192 |
193 char* end; | 193 char* end; |
194 long int iteration = strtol(argv[1], &end, 0); | 194 long int iteration = strtol(argv[1], &end, 0); |
195 | 195 |
196 if (!StartCrashThread()) { | 196 if (!StartCrashThread()) { |
197 printf("failed to start thread\n"); | 197 printf("failed to start thread\n"); |
198 return kError; | 198 return kError; |
199 } | 199 } |
200 | 200 |
201 StressTheCache(iteration); | 201 StressTheCache(iteration); |
202 return 0; | 202 return 0; |
203 } | 203 } |
204 | 204 |
OLD | NEW |