OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // A regular build should never crash. | 13 // A regular build should never crash. |
14 // To test that the disk cache doesn't generate critical errors with regular | 14 // To test that the disk cache doesn't generate critical errors with regular |
15 // application level crashes, edit stress_support.h. | 15 // application level crashes, edit stress_support.h. |
16 | 16 |
17 #include <string> | 17 #include <string> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
20 #include "base/at_exit.h" | 20 #include "base/at_exit.h" |
21 #include "base/bind.h" | 21 #include "base/bind.h" |
22 #include "base/command_line.h" | 22 #include "base/command_line.h" |
23 #include "base/debug/debugger.h" | 23 #include "base/debug/debugger.h" |
24 #include "base/file_path.h" | 24 #include "base/file_path.h" |
25 #include "base/logging.h" | 25 #include "base/logging.h" |
26 #include "base/message_loop.h" | 26 #include "base/message_loop.h" |
27 #include "base/path_service.h" | 27 #include "base/path_service.h" |
28 #include "base/process_util.h" | 28 #include "base/process_util.h" |
29 #include "base/scoped_temp_dir.h" | |
29 #include "base/string_number_conversions.h" | 30 #include "base/string_number_conversions.h" |
30 #include "base/string_util.h" | 31 #include "base/string_util.h" |
31 #include "base/threading/platform_thread.h" | 32 #include "base/threading/platform_thread.h" |
32 #include "base/threading/thread.h" | 33 #include "base/threading/thread.h" |
33 #include "base/utf_string_conversions.h" | 34 #include "base/utf_string_conversions.h" |
34 #include "net/base/net_errors.h" | 35 #include "net/base/net_errors.h" |
35 #include "net/base/test_completion_callback.h" | 36 #include "net/base/test_completion_callback.h" |
36 #include "net/base/io_buffer.h" | 37 #include "net/base/io_buffer.h" |
37 #include "net/disk_cache/backend_impl.h" | 38 #include "net/disk_cache/backend_impl.h" |
38 #include "net/disk_cache/disk_cache.h" | 39 #include "net/disk_cache/disk_cache.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 key[size - 1] = '\0'; | 95 key[size - 1] = '\0'; |
95 return std::string(key); | 96 return std::string(key); |
96 } | 97 } |
97 | 98 |
98 // This thread will loop forever, adding and removing entries from the cache. | 99 // This thread will loop forever, adding and removing entries from the cache. |
99 // iteration is the current crash cycle, so the entries on the cache are marked | 100 // iteration is the current crash cycle, so the entries on the cache are marked |
100 // to know which instance of the application wrote them. | 101 // to know which instance of the application wrote them. |
101 void StressTheCache(int iteration) { | 102 void StressTheCache(int iteration) { |
102 int cache_size = 0x2000000; // 32MB. | 103 int cache_size = 0x2000000; // 32MB. |
103 uint32 mask = 0xfff; // 4096 entries. | 104 uint32 mask = 0xfff; // 4096 entries. |
104 FilePath path = GetCacheFilePath().InsertBeforeExtensionASCII("_stress"); | 105 ScopedTempDir path; |
106 CHECK(path.CreateUniqueTempDir()); | |
rvargas (doing something else)
2012/08/16 21:04:19
This should definitely not be a random folder.
jam
2012/08/16 21:33:03
ah, thanks, I didn't read this test closely enough
| |
105 | 107 |
106 base::Thread cache_thread("CacheThread"); | 108 base::Thread cache_thread("CacheThread"); |
107 if (!cache_thread.StartWithOptions( | 109 if (!cache_thread.StartWithOptions( |
108 base::Thread::Options(MessageLoop::TYPE_IO, 0))) | 110 base::Thread::Options(MessageLoop::TYPE_IO, 0))) |
109 return; | 111 return; |
110 | 112 |
111 disk_cache::BackendImpl* cache = | 113 disk_cache::BackendImpl* cache = |
112 new disk_cache::BackendImpl(path, mask, cache_thread.message_loop_proxy(), | 114 new disk_cache::BackendImpl(path.path(), mask, |
113 NULL); | 115 cache_thread.message_loop_proxy(), NULL); |
114 cache->SetMaxSize(cache_size); | 116 cache->SetMaxSize(cache_size); |
115 cache->SetFlags(disk_cache::kNoLoadProtection); | 117 cache->SetFlags(disk_cache::kNoLoadProtection); |
116 | 118 |
117 net::TestCompletionCallback cb; | 119 net::TestCompletionCallback cb; |
118 int rv = cache->Init(cb.callback()); | 120 int rv = cache->Init(cb.callback()); |
119 | 121 |
120 if (cb.GetResult(rv) != net::OK) { | 122 if (cb.GetResult(rv) != net::OK) { |
121 printf("Unable to initialize cache.\n"); | 123 printf("Unable to initialize cache.\n"); |
122 return; | 124 return; |
123 } | 125 } |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 long int iteration = strtol(argv[1], &end, 0); | 280 long int iteration = strtol(argv[1], &end, 0); |
279 | 281 |
280 if (!StartCrashThread()) { | 282 if (!StartCrashThread()) { |
281 printf("failed to start thread\n"); | 283 printf("failed to start thread\n"); |
282 return kError; | 284 return kError; |
283 } | 285 } |
284 | 286 |
285 StressTheCache(iteration); | 287 StressTheCache(iteration); |
286 return 0; | 288 return 0; |
287 } | 289 } |
OLD | NEW |