Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: net/disk_cache/stress_cache.cc

Issue 10824336: Run the disk cache tests in scoped temporary directories instead of a fixed directory so that they … (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/disk_cache_test_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
39 #include "net/disk_cache/disk_cache_test_util.h" 40 #include "net/disk_cache/disk_cache_test_util.h"
40 #include "net/disk_cache/stress_support.h" 41 #include "net/disk_cache/stress_support.h"
41 #include "net/disk_cache/trace.h" 42 #include "net/disk_cache/trace.h"
42 43
43 #if defined(OS_WIN) 44 #if defined(OS_WIN)
44 #include "base/logging_win.h" 45 #include "base/logging_win.h"
45 #endif 46 #endif
46 47
47 using base::Time; 48 using base::Time;
48 49
49 const int kError = -1; 50 const int kError = -1;
50 const int kExpectedCrash = 100; 51 const int kExpectedCrash = 100;
52 const char kIterationSwitch[] = "iteration";
53 const char kCachePathSwitch[] = "cache_path";
51 54
52 // Starts a new process. 55 // Starts a new process.
53 int RunSlave(int iteration) { 56 int RunSlave(int iteration, const FilePath& path) {
54 FilePath exe; 57 FilePath exe;
55 PathService::Get(base::FILE_EXE, &exe); 58 PathService::Get(base::FILE_EXE, &exe);
56 59
57 CommandLine cmdline(exe); 60 CommandLine cmdline(exe);
58 cmdline.AppendArg(base::IntToString(iteration)); 61 cmdline.AppendSwitchASCII(kIterationSwitch, base::IntToString(iteration));
62 cmdline.AppendSwitchPath(kCachePathSwitch, path);
59 63
60 base::ProcessHandle handle; 64 base::ProcessHandle handle;
61 if (!base::LaunchProcess(cmdline, base::LaunchOptions(), &handle)) { 65 if (!base::LaunchProcess(cmdline, base::LaunchOptions(), &handle)) {
62 printf("Unable to run test\n"); 66 printf("Unable to run test\n");
63 return kError; 67 return kError;
64 } 68 }
65 69
66 int exit_code; 70 int exit_code;
67 if (!base::WaitForExitCode(handle, &exit_code)) { 71 if (!base::WaitForExitCode(handle, &exit_code)) {
68 printf("Unable to get return code\n"); 72 printf("Unable to get return code\n");
69 return kError; 73 return kError;
70 } 74 }
71 return exit_code; 75 return exit_code;
72 } 76 }
73 77
74 // Main loop for the master process. 78 // Main loop for the master process.
75 int MasterCode() { 79 int MasterCode() {
80 ScopedTempDir path;
rvargas (doing something else) 2012/08/16 22:26:43 Sorry, what I meant is that stress tests as a whol
81 CHECK(path.CreateUniqueTempDir());
76 for (int i = 0; i < 100000; i++) { 82 for (int i = 0; i < 100000; i++) {
77 int ret = RunSlave(i); 83 int ret = RunSlave(i, path.path());
78 if (kExpectedCrash != ret) 84 if (kExpectedCrash != ret)
79 return ret; 85 return ret;
80 } 86 }
81 87
82 printf("More than enough...\n"); 88 printf("More than enough...\n");
83 89
84 return 0; 90 return 0;
85 } 91 }
86 92
87 // ----------------------------------------------------------------------- 93 // -----------------------------------------------------------------------
88 94
89 std::string GenerateStressKey() { 95 std::string GenerateStressKey() {
90 char key[20 * 1024]; 96 char key[20 * 1024];
91 size_t size = 50 + rand() % 20000; 97 size_t size = 50 + rand() % 20000;
92 CacheTestFillBuffer(key, size, true); 98 CacheTestFillBuffer(key, size, true);
93 99
94 key[size - 1] = '\0'; 100 key[size - 1] = '\0';
95 return std::string(key); 101 return std::string(key);
96 } 102 }
97 103
98 // This thread will loop forever, adding and removing entries from the cache. 104 // 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 105 // iteration is the current crash cycle, so the entries on the cache are marked
100 // to know which instance of the application wrote them. 106 // to know which instance of the application wrote them.
101 void StressTheCache(int iteration) { 107 void StressTheCache(int iteration) {
108 FilePath path = CommandLine::ForCurrentProcess()->GetSwitchValuePath(
109 kCachePathSwitch);
110
102 int cache_size = 0x2000000; // 32MB. 111 int cache_size = 0x2000000; // 32MB.
103 uint32 mask = 0xfff; // 4096 entries. 112 uint32 mask = 0xfff; // 4096 entries.
104 FilePath path = GetCacheFilePath().InsertBeforeExtensionASCII("_stress");
105 113
106 base::Thread cache_thread("CacheThread"); 114 base::Thread cache_thread("CacheThread");
107 if (!cache_thread.StartWithOptions( 115 if (!cache_thread.StartWithOptions(
108 base::Thread::Options(MessageLoop::TYPE_IO, 0))) 116 base::Thread::Options(MessageLoop::TYPE_IO, 0)))
109 return; 117 return;
110 118
111 disk_cache::BackendImpl* cache = 119 disk_cache::BackendImpl* cache =
112 new disk_cache::BackendImpl(path, mask, cache_thread.message_loop_proxy(), 120 new disk_cache::BackendImpl(path, mask, cache_thread.message_loop_proxy(),
113 NULL); 121 NULL);
114 cache->SetMaxSize(cache_size); 122 cache->SetMaxSize(cache_size);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 int main(int argc, const char* argv[]) { 262 int main(int argc, const char* argv[]) {
255 // Setup an AtExitManager so Singleton objects will be destructed. 263 // Setup an AtExitManager so Singleton objects will be destructed.
256 base::AtExitManager at_exit_manager; 264 base::AtExitManager at_exit_manager;
257 265
258 if (argc < 2) 266 if (argc < 2)
259 return MasterCode(); 267 return MasterCode();
260 268
261 logging::SetLogAssertHandler(CrashHandler); 269 logging::SetLogAssertHandler(CrashHandler);
262 logging::SetLogMessageHandler(MessageHandler); 270 logging::SetLogMessageHandler(MessageHandler);
263 271
272 CommandLine::Init(argc, argv);
264 #if defined(OS_WIN) 273 #if defined(OS_WIN)
265 logging::LogEventProvider::Initialize(kStressCacheTraceProviderName); 274 logging::LogEventProvider::Initialize(kStressCacheTraceProviderName);
266 #else 275 #else
267 CommandLine::Init(argc, argv);
268 logging::InitLogging(NULL, logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, 276 logging::InitLogging(NULL, logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
269 logging::LOCK_LOG_FILE, logging::DELETE_OLD_LOG_FILE, 277 logging::LOCK_LOG_FILE, logging::DELETE_OLD_LOG_FILE,
270 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); 278 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS);
271 #endif 279 #endif
272 280
273 // Some time for the memory manager to flush stuff. 281 // Some time for the memory manager to flush stuff.
274 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(3)); 282 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(3));
275 MessageLoop message_loop(MessageLoop::TYPE_IO); 283 MessageLoop message_loop(MessageLoop::TYPE_IO);
276 284
277 char* end; 285
278 long int iteration = strtol(argv[1], &end, 0); 286 int iteration;
287 base::StringToInt(
288 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(kIterationSwitch),
289 &iteration);
279 290
280 if (!StartCrashThread()) { 291 if (!StartCrashThread()) {
281 printf("failed to start thread\n"); 292 printf("failed to start thread\n");
282 return kError; 293 return kError;
283 } 294 }
284 295
285 StressTheCache(iteration); 296 StressTheCache(iteration);
286 return 0; 297 return 0;
287 } 298 }
OLDNEW
« no previous file with comments | « net/disk_cache/disk_cache_test_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698