Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 } | 125 } |
| 126 | 126 |
| 127 // Makes sure that any pending task is processed. | 127 // Makes sure that any pending task is processed. |
| 128 void FlushQueue(disk_cache::Backend* cache) { | 128 void FlushQueue(disk_cache::Backend* cache) { |
| 129 TestOldCompletionCallback cb; | 129 TestOldCompletionCallback cb; |
| 130 int rv = | 130 int rv = |
| 131 reinterpret_cast<disk_cache::BackendImpl*>(cache)->FlushQueueForTest(&cb); | 131 reinterpret_cast<disk_cache::BackendImpl*>(cache)->FlushQueueForTest(&cb); |
| 132 cb.GetResult(rv); // Ignore the result; | 132 cb.GetResult(rv); // Ignore the result; |
| 133 } | 133 } |
| 134 | 134 |
| 135 bool CreateCache(const FilePath& path, base::Thread* thread, | |
| 136 disk_cache::Backend** cache, TestOldCompletionCallback* cb) { | |
| 137 int size = 1024 * 1024; | |
| 138 int rv = disk_cache::BackendImpl::CreateBackend( | |
| 139 path, false, size, net::DISK_CACHE, disk_cache::kNoRandom, | |
| 140 thread->message_loop_proxy(), NULL, cache, cb); | |
| 141 | |
| 142 return (cb->GetResult(rv) == net::OK && !(*cache)->GetEntryCount()); | |
| 143 } | |
|
gavinp
2011/11/28 16:15:01
I take it that crash_cache.cc had bitrotted becaus
rvargas (doing something else)
2011/11/28 19:06:18
Kind of. Without this change, it sometimes generat
| |
| 144 | |
| 135 // Generates the files for an empty and one item cache. | 145 // Generates the files for an empty and one item cache. |
| 136 int SimpleInsert(const FilePath& path, RankCrashes action, | 146 int SimpleInsert(const FilePath& path, RankCrashes action, |
| 137 base::Thread* cache_thread) { | 147 base::Thread* cache_thread) { |
| 138 TestOldCompletionCallback cb; | 148 TestOldCompletionCallback cb; |
| 139 disk_cache::Backend* cache; | 149 disk_cache::Backend* cache; |
| 140 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false, | 150 if (!CreateCache(path, cache_thread, &cache, &cb)) |
| 141 cache_thread->message_loop_proxy(), | |
| 142 NULL, &cache, &cb); | |
| 143 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) | |
| 144 return GENERIC; | 151 return GENERIC; |
| 145 | 152 |
| 146 const char* test_name = "some other key"; | 153 const char* test_name = "some other key"; |
| 147 | 154 |
| 148 if (action <= disk_cache::INSERT_EMPTY_3) { | 155 if (action <= disk_cache::INSERT_EMPTY_3) { |
| 149 test_name = kCrashEntryName; | 156 test_name = kCrashEntryName; |
| 150 disk_cache::g_rankings_crash = action; | 157 disk_cache::g_rankings_crash = action; |
| 151 } | 158 } |
| 152 | 159 |
| 153 disk_cache::Entry* entry; | 160 disk_cache::Entry* entry; |
| 154 rv = cache->CreateEntry(test_name, &entry, &cb); | 161 int rv = cache->CreateEntry(test_name, &entry, &cb); |
| 155 if (cb.GetResult(rv) != net::OK) | 162 if (cb.GetResult(rv) != net::OK) |
| 156 return GENERIC; | 163 return GENERIC; |
| 157 | 164 |
| 158 entry->Close(); | 165 entry->Close(); |
| 159 FlushQueue(cache); | 166 FlushQueue(cache); |
| 160 | 167 |
| 161 DCHECK(action <= disk_cache::INSERT_ONE_3); | 168 DCHECK(action <= disk_cache::INSERT_ONE_3); |
| 162 disk_cache::g_rankings_crash = action; | 169 disk_cache::g_rankings_crash = action; |
| 163 test_name = kCrashEntryName; | 170 test_name = kCrashEntryName; |
| 164 | 171 |
| 165 rv = cache->CreateEntry(test_name, &entry, &cb); | 172 rv = cache->CreateEntry(test_name, &entry, &cb); |
| 166 if (cb.GetResult(rv) != net::OK) | 173 if (cb.GetResult(rv) != net::OK) |
| 167 return GENERIC; | 174 return GENERIC; |
| 168 | 175 |
| 169 return NOT_REACHED; | 176 return NOT_REACHED; |
| 170 } | 177 } |
| 171 | 178 |
| 172 // Generates the files for a one item cache, and removing the head. | 179 // Generates the files for a one item cache, and removing the head. |
| 173 int SimpleRemove(const FilePath& path, RankCrashes action, | 180 int SimpleRemove(const FilePath& path, RankCrashes action, |
| 174 base::Thread* cache_thread) { | 181 base::Thread* cache_thread) { |
| 175 DCHECK(action >= disk_cache::REMOVE_ONE_1); | 182 DCHECK(action >= disk_cache::REMOVE_ONE_1); |
| 176 DCHECK(action <= disk_cache::REMOVE_TAIL_3); | 183 DCHECK(action <= disk_cache::REMOVE_TAIL_3); |
| 177 | 184 |
| 178 TestOldCompletionCallback cb; | 185 TestOldCompletionCallback cb; |
| 179 disk_cache::Backend* cache; | 186 disk_cache::Backend* cache; |
| 180 // Use a simple LRU for eviction. | 187 if (!CreateCache(path, cache_thread, &cache, &cb)) |
| 181 int rv = disk_cache::CreateCacheBackend(net::MEDIA_CACHE, path, 0, false, | |
| 182 cache_thread->message_loop_proxy(), | |
| 183 NULL, &cache, &cb); | |
| 184 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) | |
| 185 return GENERIC; | 188 return GENERIC; |
| 186 | 189 |
| 187 disk_cache::Entry* entry; | 190 disk_cache::Entry* entry; |
| 188 rv = cache->CreateEntry(kCrashEntryName, &entry, &cb); | 191 int rv = cache->CreateEntry(kCrashEntryName, &entry, &cb); |
| 189 if (cb.GetResult(rv) != net::OK) | 192 if (cb.GetResult(rv) != net::OK) |
| 190 return GENERIC; | 193 return GENERIC; |
| 191 | 194 |
| 192 entry->Close(); | 195 entry->Close(); |
| 193 FlushQueue(cache); | 196 FlushQueue(cache); |
| 194 | 197 |
| 195 if (action >= disk_cache::REMOVE_TAIL_1) { | 198 if (action >= disk_cache::REMOVE_TAIL_1) { |
| 196 rv = cache->CreateEntry("some other key", &entry, &cb); | 199 rv = cache->CreateEntry("some other key", &entry, &cb); |
| 197 if (cb.GetResult(rv) != net::OK) | 200 if (cb.GetResult(rv) != net::OK) |
| 198 return GENERIC; | 201 return GENERIC; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 213 return NOT_REACHED; | 216 return NOT_REACHED; |
| 214 } | 217 } |
| 215 | 218 |
| 216 int HeadRemove(const FilePath& path, RankCrashes action, | 219 int HeadRemove(const FilePath& path, RankCrashes action, |
| 217 base::Thread* cache_thread) { | 220 base::Thread* cache_thread) { |
| 218 DCHECK(action >= disk_cache::REMOVE_HEAD_1); | 221 DCHECK(action >= disk_cache::REMOVE_HEAD_1); |
| 219 DCHECK(action <= disk_cache::REMOVE_HEAD_4); | 222 DCHECK(action <= disk_cache::REMOVE_HEAD_4); |
| 220 | 223 |
| 221 TestOldCompletionCallback cb; | 224 TestOldCompletionCallback cb; |
| 222 disk_cache::Backend* cache; | 225 disk_cache::Backend* cache; |
| 223 // Use a simple LRU for eviction. | 226 if (!CreateCache(path, cache_thread, &cache, &cb)) |
| 224 int rv = disk_cache::CreateCacheBackend(net::MEDIA_CACHE, path, 0, false, | |
| 225 cache_thread->message_loop_proxy(), | |
| 226 NULL, &cache, &cb); | |
| 227 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) | |
| 228 return GENERIC; | 227 return GENERIC; |
| 229 | 228 |
| 230 disk_cache::Entry* entry; | 229 disk_cache::Entry* entry; |
| 231 rv = cache->CreateEntry("some other key", &entry, &cb); | 230 int rv = cache->CreateEntry("some other key", &entry, &cb); |
| 232 if (cb.GetResult(rv) != net::OK) | 231 if (cb.GetResult(rv) != net::OK) |
| 233 return GENERIC; | 232 return GENERIC; |
| 234 | 233 |
| 235 entry->Close(); | 234 entry->Close(); |
| 236 FlushQueue(cache); | 235 FlushQueue(cache); |
| 237 rv = cache->CreateEntry(kCrashEntryName, &entry, &cb); | 236 rv = cache->CreateEntry(kCrashEntryName, &entry, &cb); |
| 238 if (cb.GetResult(rv) != net::OK) | 237 if (cb.GetResult(rv) != net::OK) |
| 239 return GENERIC; | 238 return GENERIC; |
| 240 | 239 |
| 241 entry->Close(); | 240 entry->Close(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 257 int LoadOperations(const FilePath& path, RankCrashes action, | 256 int LoadOperations(const FilePath& path, RankCrashes action, |
| 258 base::Thread* cache_thread) { | 257 base::Thread* cache_thread) { |
| 259 DCHECK(action >= disk_cache::INSERT_LOAD_1); | 258 DCHECK(action >= disk_cache::INSERT_LOAD_1); |
| 260 | 259 |
| 261 // Work with a tiny index table (16 entries). | 260 // Work with a tiny index table (16 entries). |
| 262 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( | 261 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( |
| 263 path, 0xf, cache_thread->message_loop_proxy(), NULL); | 262 path, 0xf, cache_thread->message_loop_proxy(), NULL); |
| 264 if (!cache || !cache->SetMaxSize(0x100000)) | 263 if (!cache || !cache->SetMaxSize(0x100000)) |
| 265 return GENERIC; | 264 return GENERIC; |
| 266 | 265 |
| 266 // No experiments and use a simple LRU. | |
| 267 cache->SetFlags(disk_cache::kNoRandom); | |
| 267 TestOldCompletionCallback cb; | 268 TestOldCompletionCallback cb; |
| 268 int rv = cache->Init(&cb); | 269 int rv = cache->Init(&cb); |
| 269 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) | 270 if (cb.GetResult(rv) != net::OK || cache->GetEntryCount()) |
| 270 return GENERIC; | 271 return GENERIC; |
| 271 | 272 |
| 272 int seed = static_cast<int>(Time::Now().ToInternalValue()); | 273 int seed = static_cast<int>(Time::Now().ToInternalValue()); |
| 273 srand(seed); | 274 srand(seed); |
| 274 | 275 |
| 275 disk_cache::Entry* entry; | 276 disk_cache::Entry* entry; |
| 276 for (int i = 0; i < 100; i++) { | 277 for (int i = 0; i < 100; i++) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 | 365 |
| 365 FilePath path; | 366 FilePath path; |
| 366 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 367 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 367 path = path.AppendASCII("net"); | 368 path = path.AppendASCII("net"); |
| 368 path = path.AppendASCII("data"); | 369 path = path.AppendASCII("data"); |
| 369 path = path.AppendASCII("cache_tests"); | 370 path = path.AppendASCII("cache_tests"); |
| 370 path = path.AppendASCII("new_crashes"); | 371 path = path.AppendASCII("new_crashes"); |
| 371 | 372 |
| 372 return SlaveCode(path, action); | 373 return SlaveCode(path, action); |
| 373 } | 374 } |
| OLD | NEW |