OLD | NEW |
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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 command-line program generates the set of files needed for the crash- | 5 // This command-line program generates the set of files needed for the crash- |
6 // cache unit tests (DiskCacheTest,CacheBackend_Recover*). This program only | 6 // cache unit tests (DiskCacheTest,CacheBackend_Recover*). This program only |
7 // works properly on debug mode, because the crash functionality is not compiled | 7 // works properly on debug mode, because the crash functionality is not compiled |
8 // on release builds of the cache. | 8 // on release builds of the cache. |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 DCHECK(action > disk_cache::NO_CRASH && action < disk_cache::MAX_CRASH); | 111 DCHECK(action > disk_cache::NO_CRASH && action < disk_cache::MAX_CRASH); |
112 | 112 |
113 *full_path = path.AppendASCII(folders[action]); | 113 *full_path = path.AppendASCII(folders[action]); |
114 | 114 |
115 if (file_util::PathExists(*full_path)) | 115 if (file_util::PathExists(*full_path)) |
116 return false; | 116 return false; |
117 | 117 |
118 return file_util::CreateDirectory(*full_path); | 118 return file_util::CreateDirectory(*full_path); |
119 } | 119 } |
120 | 120 |
121 // Makes sure that any pending task is processed. | |
122 void FlushQueue(disk_cache::Backend* cache) { | |
123 TestCompletionCallback cb; | |
124 int rv = | |
125 reinterpret_cast<disk_cache::BackendImpl*>(cache)->FlushQueueForTest(&cb); | |
126 cb.GetResult(rv); // Ignore the result; | |
127 } | |
128 | |
129 // Generates the files for an empty and one item cache. | 121 // Generates the files for an empty and one item cache. |
130 int SimpleInsert(const FilePath& path, RankCrashes action, | 122 int SimpleInsert(const FilePath& path, RankCrashes action, |
131 base::Thread* cache_thread) { | 123 base::Thread* cache_thread) { |
132 TestCompletionCallback cb; | 124 TestCompletionCallback cb; |
133 disk_cache::Backend* cache; | 125 disk_cache::Backend* cache; |
134 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false, | 126 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false, |
135 cache_thread->message_loop_proxy(), | 127 cache_thread->message_loop_proxy(), |
136 &cache, &cb); | 128 &cache, &cb); |
137 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) | 129 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) |
138 return GENERIC; | 130 return GENERIC; |
139 | 131 |
140 const char* test_name = "some other key"; | 132 const char* test_name = "some other key"; |
141 | 133 |
142 if (action <= disk_cache::INSERT_EMPTY_3) { | 134 if (action <= disk_cache::INSERT_EMPTY_3) { |
143 test_name = kCrashEntryName; | 135 test_name = kCrashEntryName; |
144 g_rankings_crash = action; | 136 g_rankings_crash = action; |
145 } | 137 } |
146 | 138 |
147 disk_cache::Entry* entry; | 139 disk_cache::Entry* entry; |
148 rv = cache->CreateEntry(test_name, &entry, &cb); | 140 rv = cache->CreateEntry(test_name, &entry, &cb); |
149 if (cb.GetResult(rv) != net::OK) | 141 if (cb.GetResult(rv) != net::OK) |
150 return GENERIC; | 142 return GENERIC; |
151 | 143 |
152 entry->Close(); | 144 entry->Close(); |
153 FlushQueue(cache); | |
154 | 145 |
155 DCHECK(action <= disk_cache::INSERT_ONE_3); | 146 DCHECK(action <= disk_cache::INSERT_ONE_3); |
156 g_rankings_crash = action; | 147 g_rankings_crash = action; |
157 test_name = kCrashEntryName; | 148 test_name = kCrashEntryName; |
158 | 149 |
159 rv = cache->CreateEntry(test_name, &entry, &cb); | 150 rv = cache->CreateEntry(test_name, &entry, &cb); |
160 if (cb.GetResult(rv) != net::OK) | 151 if (cb.GetResult(rv) != net::OK) |
161 return GENERIC; | 152 return GENERIC; |
162 | 153 |
163 return NOT_REACHED; | 154 return NOT_REACHED; |
164 } | 155 } |
165 | 156 |
166 // Generates the files for a one item cache, and removing the head. | 157 // Generates the files for a one item cache, and removing the head. |
167 int SimpleRemove(const FilePath& path, RankCrashes action, | 158 int SimpleRemove(const FilePath& path, RankCrashes action, |
168 base::Thread* cache_thread) { | 159 base::Thread* cache_thread) { |
169 DCHECK(action >= disk_cache::REMOVE_ONE_1); | 160 DCHECK(action >= disk_cache::REMOVE_ONE_1); |
170 DCHECK(action <= disk_cache::REMOVE_TAIL_3); | 161 DCHECK(action <= disk_cache::REMOVE_TAIL_3); |
171 | 162 |
172 TestCompletionCallback cb; | 163 TestCompletionCallback cb; |
173 disk_cache::Backend* cache; | 164 disk_cache::Backend* cache; |
174 // Use a simple LRU for eviction. | 165 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false, |
175 int rv = disk_cache::CreateCacheBackend(net::MEDIA_CACHE, path, 0, false, | |
176 cache_thread->message_loop_proxy(), | 166 cache_thread->message_loop_proxy(), |
177 &cache, &cb); | 167 &cache, &cb); |
178 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) | 168 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) |
179 return GENERIC; | 169 return GENERIC; |
180 | 170 |
181 disk_cache::Entry* entry; | 171 disk_cache::Entry* entry; |
182 rv = cache->CreateEntry(kCrashEntryName, &entry, &cb); | 172 rv = cache->CreateEntry(kCrashEntryName, &entry, &cb); |
183 if (cb.GetResult(rv) != net::OK) | 173 if (cb.GetResult(rv) != net::OK) |
184 return GENERIC; | 174 return GENERIC; |
185 | 175 |
186 entry->Close(); | 176 entry->Close(); |
187 FlushQueue(cache); | |
188 | 177 |
189 if (action >= disk_cache::REMOVE_TAIL_1) { | 178 if (action >= disk_cache::REMOVE_TAIL_1) { |
190 rv = cache->CreateEntry("some other key", &entry, &cb); | 179 rv = cache->CreateEntry("some other key", &entry, &cb); |
191 if (cb.GetResult(rv) != net::OK) | 180 if (cb.GetResult(rv) != net::OK) |
192 return GENERIC; | 181 return GENERIC; |
193 | 182 |
194 entry->Close(); | 183 entry->Close(); |
195 FlushQueue(cache); | |
196 } | 184 } |
197 | 185 |
198 rv = cache->OpenEntry(kCrashEntryName, &entry, &cb); | 186 rv = cache->OpenEntry(kCrashEntryName, &entry, &cb); |
199 if (cb.GetResult(rv) != net::OK) | 187 if (cb.GetResult(rv) != net::OK) |
200 return GENERIC; | 188 return GENERIC; |
201 | 189 |
202 g_rankings_crash = action; | 190 g_rankings_crash = action; |
203 entry->Doom(); | 191 entry->Doom(); |
204 entry->Close(); | 192 entry->Close(); |
205 FlushQueue(cache); | |
206 | 193 |
207 return NOT_REACHED; | 194 return NOT_REACHED; |
208 } | 195 } |
209 | 196 |
210 int HeadRemove(const FilePath& path, RankCrashes action, | 197 int HeadRemove(const FilePath& path, RankCrashes action, |
211 base::Thread* cache_thread) { | 198 base::Thread* cache_thread) { |
212 DCHECK(action >= disk_cache::REMOVE_HEAD_1); | 199 DCHECK(action >= disk_cache::REMOVE_HEAD_1); |
213 DCHECK(action <= disk_cache::REMOVE_HEAD_4); | 200 DCHECK(action <= disk_cache::REMOVE_HEAD_4); |
214 | 201 |
215 TestCompletionCallback cb; | 202 TestCompletionCallback cb; |
216 disk_cache::Backend* cache; | 203 disk_cache::Backend* cache; |
217 // Use a simple LRU for eviction. | 204 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false, |
218 int rv = disk_cache::CreateCacheBackend(net::MEDIA_CACHE, path, 0, false, | |
219 cache_thread->message_loop_proxy(), | 205 cache_thread->message_loop_proxy(), |
220 &cache, &cb); | 206 &cache, &cb); |
221 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) | 207 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) |
222 return GENERIC; | 208 return GENERIC; |
223 | 209 |
224 disk_cache::Entry* entry; | 210 disk_cache::Entry* entry; |
225 rv = cache->CreateEntry("some other key", &entry, &cb); | 211 rv = cache->CreateEntry("some other key", &entry, &cb); |
226 if (cb.GetResult(rv) != net::OK) | 212 if (cb.GetResult(rv) != net::OK) |
227 return GENERIC; | 213 return GENERIC; |
228 | 214 |
229 entry->Close(); | 215 entry->Close(); |
230 FlushQueue(cache); | |
231 rv = cache->CreateEntry(kCrashEntryName, &entry, &cb); | 216 rv = cache->CreateEntry(kCrashEntryName, &entry, &cb); |
232 if (cb.GetResult(rv) != net::OK) | 217 if (cb.GetResult(rv) != net::OK) |
233 return GENERIC; | 218 return GENERIC; |
234 | 219 |
235 entry->Close(); | 220 entry->Close(); |
236 FlushQueue(cache); | |
237 | 221 |
238 rv = cache->OpenEntry(kCrashEntryName, &entry, &cb); | 222 rv = cache->OpenEntry(kCrashEntryName, &entry, &cb); |
239 if (cb.GetResult(rv) != net::OK) | 223 if (cb.GetResult(rv) != net::OK) |
240 return GENERIC; | 224 return GENERIC; |
241 | 225 |
242 g_rankings_crash = action; | 226 g_rankings_crash = action; |
243 entry->Doom(); | 227 entry->Doom(); |
244 entry->Close(); | 228 entry->Close(); |
245 FlushQueue(cache); | |
246 | 229 |
247 return NOT_REACHED; | 230 return NOT_REACHED; |
248 } | 231 } |
249 | 232 |
250 // Generates the files for insertion and removals on heavy loaded caches. | 233 // Generates the files for insertion and removals on heavy loaded caches. |
251 int LoadOperations(const FilePath& path, RankCrashes action, | 234 int LoadOperations(const FilePath& path, RankCrashes action, |
252 base::Thread* cache_thread) { | 235 base::Thread* cache_thread) { |
253 DCHECK(action >= disk_cache::INSERT_LOAD_1); | 236 DCHECK(action >= disk_cache::INSERT_LOAD_1); |
254 | 237 |
255 // Work with a tiny index table (16 entries). | 238 // Work with a tiny index table (16 entries). |
256 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( | 239 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( |
257 path, 0xf, cache_thread->message_loop_proxy()); | 240 path, 0xf, cache_thread->message_loop_proxy()); |
258 if (!cache || !cache->SetMaxSize(0x100000)) | 241 if (!cache || !cache->SetMaxSize(0x100000)) |
259 return GENERIC; | 242 return GENERIC; |
260 | 243 |
261 TestCompletionCallback cb; | 244 if (!cache->Init() || cache->GetEntryCount()) |
262 int rv = cache->Init(&cb); | |
263 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) | |
264 return GENERIC; | 245 return GENERIC; |
265 | 246 |
266 int seed = static_cast<int>(Time::Now().ToInternalValue()); | 247 int seed = static_cast<int>(Time::Now().ToInternalValue()); |
267 srand(seed); | 248 srand(seed); |
268 | 249 |
| 250 TestCompletionCallback cb; |
| 251 int rv; |
269 disk_cache::Entry* entry; | 252 disk_cache::Entry* entry; |
270 for (int i = 0; i < 100; i++) { | 253 for (int i = 0; i < 100; i++) { |
271 std::string key = GenerateKey(true); | 254 std::string key = GenerateKey(true); |
272 rv = cache->CreateEntry(key, &entry, &cb); | 255 rv = cache->CreateEntry(key, &entry, &cb); |
273 if (cb.GetResult(rv) != net::OK) | 256 if (cb.GetResult(rv) != net::OK) |
274 return GENERIC; | 257 return GENERIC; |
275 entry->Close(); | 258 entry->Close(); |
276 FlushQueue(cache); | |
277 if (50 == i && action >= disk_cache::REMOVE_LOAD_1) { | 259 if (50 == i && action >= disk_cache::REMOVE_LOAD_1) { |
278 rv = cache->CreateEntry(kCrashEntryName, &entry, &cb); | 260 rv = cache->CreateEntry(kCrashEntryName, &entry, &cb); |
279 if (cb.GetResult(rv) != net::OK) | 261 if (cb.GetResult(rv) != net::OK) |
280 return GENERIC; | 262 return GENERIC; |
281 entry->Close(); | 263 entry->Close(); |
282 FlushQueue(cache); | |
283 } | 264 } |
284 } | 265 } |
285 | 266 |
286 if (action <= disk_cache::INSERT_LOAD_2) { | 267 if (action <= disk_cache::INSERT_LOAD_2) { |
287 g_rankings_crash = action; | 268 g_rankings_crash = action; |
288 | 269 |
289 rv = cache->CreateEntry(kCrashEntryName, &entry, &cb); | 270 rv = cache->CreateEntry(kCrashEntryName, &entry, &cb); |
290 if (cb.GetResult(rv) != net::OK) | 271 if (cb.GetResult(rv) != net::OK) |
291 return GENERIC; | 272 return GENERIC; |
292 } | 273 } |
293 | 274 |
294 rv = cache->OpenEntry(kCrashEntryName, &entry, &cb); | 275 rv = cache->OpenEntry(kCrashEntryName, &entry, &cb); |
295 if (cb.GetResult(rv) != net::OK) | 276 if (cb.GetResult(rv) != net::OK) |
296 return GENERIC; | 277 return GENERIC; |
297 | 278 |
298 g_rankings_crash = action; | 279 g_rankings_crash = action; |
299 | 280 |
300 entry->Doom(); | 281 entry->Doom(); |
301 entry->Close(); | 282 entry->Close(); |
302 FlushQueue(cache); | |
303 | 283 |
304 return NOT_REACHED; | 284 return NOT_REACHED; |
305 } | 285 } |
306 | 286 |
307 // Main function on the child process. | 287 // Main function on the child process. |
308 int SlaveCode(const FilePath& path, RankCrashes action) { | 288 int SlaveCode(const FilePath& path, RankCrashes action) { |
309 MessageLoopForIO message_loop; | 289 MessageLoopForIO message_loop; |
310 | 290 |
311 FilePath full_path; | 291 FilePath full_path; |
312 if (!CreateTargetFolder(path, action, &full_path)) { | 292 if (!CreateTargetFolder(path, action, &full_path)) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 | 338 |
359 FilePath path; | 339 FilePath path; |
360 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 340 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
361 path = path.AppendASCII("net"); | 341 path = path.AppendASCII("net"); |
362 path = path.AppendASCII("data"); | 342 path = path.AppendASCII("data"); |
363 path = path.AppendASCII("cache_tests"); | 343 path = path.AppendASCII("cache_tests"); |
364 path = path.AppendASCII("new_crashes"); | 344 path = path.AppendASCII("new_crashes"); |
365 | 345 |
366 return SlaveCode(path, action); | 346 return SlaveCode(path, action); |
367 } | 347 } |
OLD | NEW |