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