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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 cb.GetResult(rv); // Ignore the result; | 128 cb.GetResult(rv); // Ignore the result; |
129 } | 129 } |
130 | 130 |
131 // Generates the files for an empty and one item cache. | 131 // Generates the files for an empty and one item cache. |
132 int SimpleInsert(const FilePath& path, RankCrashes action, | 132 int SimpleInsert(const FilePath& path, RankCrashes action, |
133 base::Thread* cache_thread) { | 133 base::Thread* cache_thread) { |
134 TestCompletionCallback cb; | 134 TestCompletionCallback cb; |
135 disk_cache::Backend* cache; | 135 disk_cache::Backend* cache; |
136 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false, | 136 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false, |
137 cache_thread->message_loop_proxy(), | 137 cache_thread->message_loop_proxy(), |
138 NULL, &cache, &cb); | 138 &cache, &cb); |
139 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) | 139 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) |
140 return GENERIC; | 140 return GENERIC; |
141 | 141 |
142 const char* test_name = "some other key"; | 142 const char* test_name = "some other key"; |
143 | 143 |
144 if (action <= disk_cache::INSERT_EMPTY_3) { | 144 if (action <= disk_cache::INSERT_EMPTY_3) { |
145 test_name = kCrashEntryName; | 145 test_name = kCrashEntryName; |
146 g_rankings_crash = action; | 146 g_rankings_crash = action; |
147 } | 147 } |
148 | 148 |
(...skipping 20 matching lines...) Expand all Loading... |
169 int SimpleRemove(const FilePath& path, RankCrashes action, | 169 int SimpleRemove(const FilePath& path, RankCrashes action, |
170 base::Thread* cache_thread) { | 170 base::Thread* cache_thread) { |
171 DCHECK(action >= disk_cache::REMOVE_ONE_1); | 171 DCHECK(action >= disk_cache::REMOVE_ONE_1); |
172 DCHECK(action <= disk_cache::REMOVE_TAIL_3); | 172 DCHECK(action <= disk_cache::REMOVE_TAIL_3); |
173 | 173 |
174 TestCompletionCallback cb; | 174 TestCompletionCallback cb; |
175 disk_cache::Backend* cache; | 175 disk_cache::Backend* cache; |
176 // Use a simple LRU for eviction. | 176 // Use a simple LRU for eviction. |
177 int rv = disk_cache::CreateCacheBackend(net::MEDIA_CACHE, path, 0, false, | 177 int rv = disk_cache::CreateCacheBackend(net::MEDIA_CACHE, path, 0, false, |
178 cache_thread->message_loop_proxy(), | 178 cache_thread->message_loop_proxy(), |
179 NULL, &cache, &cb); | 179 &cache, &cb); |
180 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) | 180 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) |
181 return GENERIC; | 181 return GENERIC; |
182 | 182 |
183 disk_cache::Entry* entry; | 183 disk_cache::Entry* entry; |
184 rv = cache->CreateEntry(kCrashEntryName, &entry, &cb); | 184 rv = cache->CreateEntry(kCrashEntryName, &entry, &cb); |
185 if (cb.GetResult(rv) != net::OK) | 185 if (cb.GetResult(rv) != net::OK) |
186 return GENERIC; | 186 return GENERIC; |
187 | 187 |
188 entry->Close(); | 188 entry->Close(); |
189 FlushQueue(cache); | 189 FlushQueue(cache); |
(...skipping 22 matching lines...) Expand all Loading... |
212 int HeadRemove(const FilePath& path, RankCrashes action, | 212 int HeadRemove(const FilePath& path, RankCrashes action, |
213 base::Thread* cache_thread) { | 213 base::Thread* cache_thread) { |
214 DCHECK(action >= disk_cache::REMOVE_HEAD_1); | 214 DCHECK(action >= disk_cache::REMOVE_HEAD_1); |
215 DCHECK(action <= disk_cache::REMOVE_HEAD_4); | 215 DCHECK(action <= disk_cache::REMOVE_HEAD_4); |
216 | 216 |
217 TestCompletionCallback cb; | 217 TestCompletionCallback cb; |
218 disk_cache::Backend* cache; | 218 disk_cache::Backend* cache; |
219 // Use a simple LRU for eviction. | 219 // Use a simple LRU for eviction. |
220 int rv = disk_cache::CreateCacheBackend(net::MEDIA_CACHE, path, 0, false, | 220 int rv = disk_cache::CreateCacheBackend(net::MEDIA_CACHE, path, 0, false, |
221 cache_thread->message_loop_proxy(), | 221 cache_thread->message_loop_proxy(), |
222 NULL, &cache, &cb); | 222 &cache, &cb); |
223 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) | 223 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) |
224 return GENERIC; | 224 return GENERIC; |
225 | 225 |
226 disk_cache::Entry* entry; | 226 disk_cache::Entry* entry; |
227 rv = cache->CreateEntry("some other key", &entry, &cb); | 227 rv = cache->CreateEntry("some other key", &entry, &cb); |
228 if (cb.GetResult(rv) != net::OK) | 228 if (cb.GetResult(rv) != net::OK) |
229 return GENERIC; | 229 return GENERIC; |
230 | 230 |
231 entry->Close(); | 231 entry->Close(); |
232 FlushQueue(cache); | 232 FlushQueue(cache); |
(...skipping 16 matching lines...) Expand all Loading... |
249 return NOT_REACHED; | 249 return NOT_REACHED; |
250 } | 250 } |
251 | 251 |
252 // Generates the files for insertion and removals on heavy loaded caches. | 252 // Generates the files for insertion and removals on heavy loaded caches. |
253 int LoadOperations(const FilePath& path, RankCrashes action, | 253 int LoadOperations(const FilePath& path, RankCrashes action, |
254 base::Thread* cache_thread) { | 254 base::Thread* cache_thread) { |
255 DCHECK(action >= disk_cache::INSERT_LOAD_1); | 255 DCHECK(action >= disk_cache::INSERT_LOAD_1); |
256 | 256 |
257 // Work with a tiny index table (16 entries). | 257 // Work with a tiny index table (16 entries). |
258 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( | 258 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( |
259 path, 0xf, cache_thread->message_loop_proxy(), NULL); | 259 path, 0xf, cache_thread->message_loop_proxy()); |
260 if (!cache || !cache->SetMaxSize(0x100000)) | 260 if (!cache || !cache->SetMaxSize(0x100000)) |
261 return GENERIC; | 261 return GENERIC; |
262 | 262 |
263 TestCompletionCallback cb; | 263 TestCompletionCallback cb; |
264 int rv = cache->Init(&cb); | 264 int rv = cache->Init(&cb); |
265 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) | 265 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) |
266 return GENERIC; | 266 return GENERIC; |
267 | 267 |
268 int seed = static_cast<int>(Time::Now().ToInternalValue()); | 268 int seed = static_cast<int>(Time::Now().ToInternalValue()); |
269 srand(seed); | 269 srand(seed); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 | 360 |
361 FilePath path; | 361 FilePath path; |
362 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 362 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
363 path = path.AppendASCII("net"); | 363 path = path.AppendASCII("net"); |
364 path = path.AppendASCII("data"); | 364 path = path.AppendASCII("data"); |
365 path = path.AppendASCII("cache_tests"); | 365 path = path.AppendASCII("cache_tests"); |
366 path = path.AppendASCII("new_crashes"); | 366 path = path.AppendASCII("new_crashes"); |
367 | 367 |
368 return SlaveCode(path, action); | 368 return SlaveCode(path, action); |
369 } | 369 } |
OLD | NEW |