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

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

Issue 20134: Extend the IOBuffer to the disk cache. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include <string> 13 #include <string>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/at_exit.h" 16 #include "base/at_exit.h"
17 #include "base/command_line.h" 17 #include "base/command_line.h"
18 #include "base/debug_util.h" 18 #include "base/debug_util.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/message_loop.h" 20 #include "base/message_loop.h"
21 #include "base/path_service.h" 21 #include "base/path_service.h"
22 #include "base/platform_thread.h" 22 #include "base/platform_thread.h"
23 #include "base/process_util.h" 23 #include "base/process_util.h"
24 #include "base/string_util.h" 24 #include "base/string_util.h"
25 #include "base/thread.h" 25 #include "base/thread.h"
26 #include "net/base/io_buffer.h"
26 #include "net/disk_cache/disk_cache.h" 27 #include "net/disk_cache/disk_cache.h"
27 #include "net/disk_cache/disk_cache_test_util.h" 28 #include "net/disk_cache/disk_cache_test_util.h"
28 29
29 using base::Time; 30 using base::Time;
30 31
31 const int kError = -1; 32 const int kError = -1;
32 const int kExpectedCrash = 100; 33 const int kExpectedCrash = 100;
33 34
34 // Starts a new process. 35 // Starts a new process.
35 int RunSlave(int iteration) { 36 int RunSlave(int iteration) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 90
90 const int kNumKeys = 5000; 91 const int kNumKeys = 5000;
91 const int kNumEntries = 30; 92 const int kNumEntries = 30;
92 std::string keys[kNumKeys]; 93 std::string keys[kNumKeys];
93 disk_cache::Entry* entries[kNumEntries] = {0}; 94 disk_cache::Entry* entries[kNumEntries] = {0};
94 95
95 for (int i = 0; i < kNumKeys; i++) { 96 for (int i = 0; i < kNumKeys; i++) {
96 keys[i] = GenerateKey(true); 97 keys[i] = GenerateKey(true);
97 } 98 }
98 99
99 const int kDataLen = 4000; 100 const int kSize = 4000;
100 char data[kDataLen]; 101 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize);
101 memset(data, 'k', kDataLen); 102 memset(buffer->data(), 'k', kSize);
102 103
103 for (int i = 0;; i++) { 104 for (int i = 0;; i++) {
104 int slot = rand() % kNumEntries; 105 int slot = rand() % kNumEntries;
105 int key = rand() % kNumKeys; 106 int key = rand() % kNumKeys;
106 107
107 if (entries[slot]) 108 if (entries[slot])
108 entries[slot]->Close(); 109 entries[slot]->Close();
109 110
110 if (!cache->OpenEntry(keys[key], &entries[slot])) 111 if (!cache->OpenEntry(keys[key], &entries[slot]))
111 CHECK(cache->CreateEntry(keys[key], &entries[slot])); 112 CHECK(cache->CreateEntry(keys[key], &entries[slot]));
112 113
113 base::snprintf(data, kDataLen, "%d %d", iteration, i); 114 base::snprintf(buffer->data(), kSize, "%d %d", iteration, i);
114 CHECK(kDataLen == entries[slot]->WriteData(0, 0, data, kDataLen, NULL, 115 CHECK(kSize == entries[slot]->WriteData(0, 0, buffer, kSize, NULL, false));
115 false));
116 116
117 if (rand() % 100 > 80) { 117 if (rand() % 100 > 80) {
118 key = rand() % kNumKeys; 118 key = rand() % kNumKeys;
119 cache->DoomEntry(keys[key]); 119 cache->DoomEntry(keys[key]);
120 } 120 }
121 121
122 if (!(i % 100)) 122 if (!(i % 100))
123 printf("Entries: %d \r", i); 123 printf("Entries: %d \r", i);
124 } 124 }
125 } 125 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // Setup an AtExitManager so Singleton objects will be destructed. 181 // Setup an AtExitManager so Singleton objects will be destructed.
182 base::AtExitManager at_exit_manager; 182 base::AtExitManager at_exit_manager;
183 183
184 if (argc < 2) 184 if (argc < 2)
185 return MasterCode(); 185 return MasterCode();
186 186
187 logging::SetLogAssertHandler(CrashHandler); 187 logging::SetLogAssertHandler(CrashHandler);
188 188
189 // Some time for the memory manager to flush stuff. 189 // Some time for the memory manager to flush stuff.
190 PlatformThread::Sleep(3000); 190 PlatformThread::Sleep(3000);
191 MessageLoop message_loop; 191 MessageLoop message_loop(MessageLoop::TYPE_IO);
192 192
193 char* end; 193 char* end;
194 long int iteration = strtol(argv[1], &end, 0); 194 long int iteration = strtol(argv[1], &end, 0);
195 195
196 if (!StartCrashThread()) { 196 if (!StartCrashThread()) {
197 printf("failed to start thread\n"); 197 printf("failed to start thread\n");
198 return kError; 198 return kError;
199 } 199 }
200 200
201 StressTheCache(iteration); 201 StressTheCache(iteration);
202 return 0; 202 return 0;
203 } 203 }
204 204
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698