author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 02 Sep 2010 21:54:16 +0300 | |
changeset 259 | 57b9594f5772 |
parent 247 | d8d70de2bd36 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// f32test\server\t_fsched.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
/** |
|
19 |
@file |
|
20 |
@internalTechnology |
|
21 |
*/ |
|
22 |
||
23 |
#define __E32TEST_EXTENSION__ |
|
24 |
||
25 |
#include <f32file.h> |
|
26 |
#include <e32test.h> |
|
27 |
#include <e32svr.h> |
|
28 |
#include <f32dbg.h> |
|
29 |
#include "t_server.h" |
|
30 |
#include <e32twin.h> |
|
31 |
#include <e32cmn.h> |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
32 |
#include <hal.h> |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
33 |
#include "tf32testtimer.h" |
200
73ea206103e6
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
34 |
#include "f32_test_utils.h" |
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
35 |
using namespace F32_Test_Utils; |
200
73ea206103e6
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
36 |
|
0 | 37 |
|
38 |
//---------------------------------------------------------------------------------------------- |
|
39 |
//! @SYMTestCaseID PBASE-T_FSCHED-0191 |
|
40 |
//! @SYMTestType CIT |
|
41 |
//! @SYMPREQ PREQ914 |
|
42 |
//! @SYMTestCaseDesc This test case is exercising the Fair Scheduling functionality added to |
|
43 |
//! the File Server. There are negative and positive tests. |
|
44 |
//! @SYMTestActions 0 setup the environment to execute the tests and benchmarks the time |
|
45 |
//! taken to write the two files that are going to be used during the test |
|
46 |
//! 1 TestReadingWhileWriting uses two threads (sync case) to write a big file/ |
|
47 |
//! read a small file simultaneously and verifies that the timing is correct. |
|
48 |
//! Same test in the async case. |
|
49 |
//! 2 TestWritingWhileWriting same test as before, but the two operations are |
|
50 |
//! writes. |
|
51 |
//! 3 TestTwoBigOnes does the same test as 1, but with two big files, ensuring |
|
52 |
//! that the first starting is the first finishing. |
|
53 |
//! 4 TestReadingWhileWritingSameFile reads a file while it is being written. |
|
54 |
//! 5 TestClientDies starts a file write and kills it, then checks the integrity |
|
55 |
//! of the volume. |
|
56 |
//! 6 Finally it performs the benchmark of writing the two files again, to see |
|
57 |
//! if it has been degraded during the execution |
|
58 |
//! |
|
59 |
//! @SYMTestExpectedResults finishes if the fair scheduling behaves as expected, panics otherwise |
|
60 |
//! @SYMTestPriority High |
|
61 |
//! @SYMTestStatus Implemented |
|
62 |
//---------------------------------------------------------------------------------------------- |
|
63 |
||
64 |
||
65 |
class RTestThreadSemaphore : public RSemaphore |
|
66 |
{ |
|
67 |
public: |
|
68 |
inline void Signal(TInt aError = KErrNone) {iError = aError; RSemaphore::Signal();}; |
|
69 |
public: |
|
70 |
TInt iError; |
|
71 |
}; |
|
72 |
||
73 |
// macro to be used in place of test(). Signals main thread if assertion fails |
|
74 |
#define TEST(x) \ |
|
75 |
if (!(x)) \ |
|
76 |
{ \ |
|
77 |
RThread t; \ |
|
78 |
if (t.Id() != gMainThreadId) \ |
|
79 |
client.Signal(KErrGeneral); \ |
|
80 |
test(x); \ |
|
81 |
} |
|
82 |
#define TESTERROR(x) \ |
|
83 |
if (x != KErrNone) \ |
|
84 |
{ \ |
|
85 |
RThread t; \ |
|
86 |
if (t.Id() != gMainThreadId) \ |
|
87 |
RDebug::Print(_L("error %d\n"), x); \ |
|
88 |
else \ |
|
89 |
test.Printf(_L("error %d\n"), x); \ |
|
90 |
TEST(x==KErrNone); \ |
|
91 |
} |
|
92 |
||
93 |
#define CLIENTWAIT() {client.Wait(); test(client.iError == KErrNone);} |
|
94 |
||
95 |
//////////////////////////////////////////////////////////// |
|
96 |
// Template functions encapsulating ControlIo magic |
|
97 |
// |
|
98 |
GLDEF_D template <class C> |
|
99 |
GLDEF_C TInt controlIo(RFs &fs, TInt drv, TInt fkn, C &c) |
|
100 |
{ |
|
101 |
TPtr8 ptrC((TUint8 *)&c, sizeof(C), sizeof(C)); |
|
102 |
||
103 |
TInt r = fs.ControlIo(drv, fkn, ptrC); |
|
104 |
||
105 |
return r; |
|
106 |
} |
|
107 |
||
108 |
||
109 |
GLDEF_D RTest test(_L("T_FSCHED")); |
|
110 |
||
111 |
GLDEF_D RFs TheFs; |
|
112 |
GLDEF_D TInt gDrive; |
|
113 |
GLDEF_D TFileName gSessionPath; |
|
114 |
GLDEF_D TChar gDriveToTest; |
|
115 |
TThreadId gMainThreadId; |
|
116 |
||
117 |
HBufC8* gBuf = NULL; |
|
118 |
TPtr8 gBufReadPtr(NULL, 0); |
|
119 |
HBufC8* gBufSec = NULL; |
|
120 |
TPtr8 gBufWritePtr(NULL, 0); |
|
121 |
||
122 |
const TInt KOneK = 1024; |
|
123 |
const TInt KOneMeg = KOneK * 1024; |
|
124 |
const TInt KBigBlockSize = KOneMeg ; |
|
125 |
const TInt KBlockSize = KOneK * 129 ; |
|
126 |
const TInt KWaitRequestsTableSize = 70; |
|
127 |
||
128 |
TInt gBigFileSize = 0; |
|
129 |
TInt gSmallFileSize = 0; |
|
130 |
TInt64 gMediaSize = 0; |
|
131 |
TInt gTotalTimeSync[2]; |
|
132 |
TInt gTotalTimeAsync[2]; |
|
133 |
||
134 |
TTimeIntervalMicroSeconds32 gTimeTakenBigFile(0); |
|
135 |
TTimeIntervalMicroSeconds32 gTimeTakenBigBlock(0); |
|
136 |
TBuf16<45> gSmallFile, gBigFile; |
|
137 |
TInt gNextFile=0; |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
138 |
|
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
139 |
TF32TestTimer gTestTimer; |
0 | 140 |
|
141 |
RSemaphore gSync; |
|
142 |
||
143 |
// Concurrent Threads |
|
144 |
RThread gBig; |
|
145 |
RThread gSmall; |
|
146 |
RTestThreadSemaphore client; |
|
147 |
const TInt KHeapSize = 0x4000; |
|
148 |
const TInt KMaxHeapSize = 0x200000; |
|
149 |
TRequestStatus gStatus[KWaitRequestsTableSize]; |
|
150 |
||
151 |
enum TTestState |
|
152 |
{ |
|
153 |
EThreadWait, |
|
154 |
EThreadSignal, |
|
155 |
ENoThreads |
|
156 |
}; |
|
157 |
||
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
158 |
|
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
159 |
|
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
160 |
|
0 | 161 |
/** Generates a file name of the form FFFFF*<aPos>.TXT (aLong.3) |
162 |
||
163 |
@param aBuffer The filename will be returned here |
|
164 |
@param aLong Defines the longitude of the file name |
|
165 |
@param aPos Defines the number that will be attached to the filename |
|
166 |
*/ |
|
167 |
void FileNameGen(TDes16& aBuffer, TInt aLong, TInt aPos) |
|
168 |
{ |
|
169 |
TInt padding; |
|
170 |
TInt i=0; |
|
171 |
TBuf16<10> tempbuf; |
|
172 |
||
173 |
_LIT(KNumber,"%d"); |
|
174 |
tempbuf.Format(KNumber,aPos); |
|
175 |
padding=aLong-tempbuf.Size()/2; |
|
176 |
aBuffer=_L(""); |
|
177 |
while(i<padding) |
|
178 |
{ |
|
179 |
aBuffer.Append('F'); |
|
180 |
i++; |
|
181 |
} |
|
182 |
aBuffer.Append(tempbuf); |
|
183 |
||
184 |
_LIT(KExtension1, ".TXT"); |
|
185 |
aBuffer.Append(KExtension1); |
|
186 |
} |
|
187 |
||
188 |
||
189 |
/** Reads the parameters from the comand line |
|
190 |
and updates the appropriate variables |
|
191 |
*/ |
|
192 |
void parseCommandLine() |
|
193 |
{ |
|
194 |
TBuf<0x100> cmd; |
|
195 |
User::CommandLine(cmd); |
|
196 |
TLex lex(cmd); |
|
197 |
TPtrC token=lex.NextToken(); |
|
198 |
TInt r=0; |
|
199 |
||
200 |
if(token.Length()!=0) |
|
201 |
{ |
|
202 |
gDriveToTest = token[0]; |
|
203 |
gDriveToTest.UpperCase(); |
|
204 |
} |
|
205 |
else |
|
206 |
{ |
|
207 |
gDriveToTest='C'; |
|
208 |
} |
|
209 |
||
210 |
r = TheFs.CharToDrive(gDriveToTest,gDrive); |
|
211 |
TESTERROR(r); |
|
212 |
gSessionPath = _L("?:\\F32-TST\\"); |
|
213 |
gSessionPath[0] = (TText)(gDrive+'A'); |
|
214 |
test.Printf(_L("\nCLP=%C\n"), (TInt)gDriveToTest); |
|
215 |
} |
|
216 |
||
217 |
/** Verifies the content of a buffer (all the letters are like the first one) |
|
218 |
||
219 |
@param aBuffer Buffer to be verified |
|
220 |
||
221 |
@return KErrNone if all the letters are the same, KErrCorrupt otherwise |
|
222 |
*/ |
|
223 |
TInt VerifyBuffer(TDes8& aBuffer, TChar aExpectedChar) |
|
224 |
{ |
|
225 |
TChar c = aExpectedChar; |
|
226 |
||
227 |
for(TInt i = 1; i<aBuffer.Length(); i++) |
|
228 |
{ |
|
229 |
if(c != (TChar)(aBuffer[i])) |
|
230 |
{ |
|
231 |
RDebug::Print(_L("VerifyBuffer() failed at +%d, %02X != %02X"), i, (TInt) c, aBuffer[i] ); |
|
232 |
return KErrCorrupt; |
|
233 |
} |
|
234 |
} |
|
235 |
||
236 |
return KErrNone; |
|
237 |
} |
|
238 |
||
239 |
/** Fills a buffer with character aC |
|
240 |
||
241 |
@param aBuffer Buffer to be filled, output |
|
242 |
@param aLength Length to be filled |
|
243 |
@param aC Character to be used to fill the buffer |
|
244 |
*/ |
|
245 |
void FillBuffer(TDes8& aBuffer, TInt aLength, TChar aC) |
|
246 |
{ |
|
247 |
test (aBuffer.MaxLength() >= aLength); |
|
248 |
for(TInt i=0; i<aLength; i++) |
|
249 |
{ |
|
250 |
aBuffer.Append(aC); |
|
251 |
} |
|
252 |
} |
|
253 |
||
254 |
/** Waits for all the TRequestStatus in status[] to complete |
|
255 |
||
256 |
@param status Array of TRequestStatus |
|
257 |
@param aLength Length to be filled |
|
258 |
@param aC Character to be used to fill the buffer |
|
259 |
*/ |
|
260 |
void WaitForAll(TRequestStatus* status, TInt aFileSize, TInt aBlockSize) |
|
261 |
{ |
|
262 |
TInt i = 0; |
|
263 |
TInt size = 0; |
|
264 |
||
265 |
if((aFileSize % aBlockSize) == 0 ) |
|
266 |
size = aFileSize/aBlockSize; |
|
267 |
else |
|
268 |
size = (aFileSize/aBlockSize) + 1; |
|
269 |
||
270 |
while(i < size) |
|
271 |
{ |
|
272 |
User::WaitForRequest(status[i++]); |
|
273 |
} |
|
274 |
} |
|
275 |
||
276 |
/** Writes a file synchronously in blocks of aBlockSize size |
|
277 |
||
278 |
@param fs RFs object |
|
279 |
@param aFile File name |
|
280 |
@param aSize Size of the file in bytes |
|
281 |
@param aBlockSize Size of the blocks to be used in bytes |
|
282 |
@param aState Determines if the operation is being done in the main process |
|
283 |
or in a thread |
|
284 |
||
285 |
@return Returns KErrNone if everything ok, otherwise it panics |
|
286 |
*/ |
|
287 |
TInt WriteFile(RFs& fs, TDes16& aFile, TInt aSize, TInt aBlockSize, TTestState aState) |
|
288 |
{ |
|
289 |
TInt r = 0; |
|
290 |
RFile fileWrite; |
|
291 |
||
292 |
TEST(aBlockSize>0); |
|
293 |
||
294 |
r = fileWrite.Replace(fs,aFile,EFileShareAny|EFileWrite|EFileWriteDirectIO); |
|
295 |
TESTERROR(r); |
|
296 |
||
297 |
if(aState==EThreadWait) |
|
298 |
{ |
|
299 |
gSync.Wait(); |
|
300 |
User::After(gTimeTakenBigBlock); |
|
301 |
} |
|
302 |
||
303 |
TInt j = 0; |
|
304 |
while(j < aSize) |
|
305 |
{ |
|
306 |
if((j == 0) && (aState == EThreadSignal)) |
|
307 |
{ |
|
308 |
gSync.Signal(); |
|
309 |
} |
|
310 |
||
311 |
if((aSize - j) >= aBlockSize) // All the blocks but the last one |
|
312 |
r = fileWrite.Write(gBufWritePtr, aBlockSize); |
|
313 |
else // The last block |
|
314 |
r = fileWrite.Write(gBufWritePtr, (aSize - j)); |
|
315 |
||
316 |
TESTERROR(r); |
|
317 |
j += aBlockSize; |
|
318 |
} |
|
319 |
||
320 |
fileWrite.Close(); |
|
321 |
||
322 |
return KErrNone; |
|
323 |
} |
|
324 |
||
325 |
/** Read File in blocks of size aBlockSize |
|
326 |
||
327 |
@param fs RFs object |
|
328 |
@param aFile File name |
|
329 |
@param aBlockSize Size of the blocks to be used in bytes |
|
330 |
@param aState Determines if the operation is being done in the main process |
|
331 |
or in a thread |
|
332 |
||
333 |
@return Returns KErrNone if everything ok, otherwise it panics |
|
334 |
*/ |
|
335 |
TInt ReadFile(RFs& fs, TDes16& aFile, TInt aBlockSize, TTestState aState) |
|
336 |
{ |
|
337 |
RTest test(_L("T_FSCHED")); |
|
338 |
TInt r = 0, size = 0; |
|
339 |
RFile fileRead; |
|
340 |
||
341 |
TEST(aBlockSize > 0); |
|
342 |
||
343 |
r = fileRead.Open(fs, aFile, EFileShareAny|EFileRead|EFileReadDirectIO); |
|
344 |
TESTERROR(r); |
|
345 |
||
346 |
r = fileRead.Size(size); |
|
347 |
TESTERROR(r); |
|
348 |
||
349 |
if(aState == EThreadWait) |
|
350 |
{ |
|
351 |
gSync.Wait(); |
|
352 |
User::After(gTimeTakenBigBlock); |
|
353 |
} |
|
354 |
||
355 |
TInt j = 0; |
|
356 |
while(j < size) |
|
357 |
{ |
|
358 |
if((j == 0)&&(aState == EThreadSignal)) |
|
359 |
{ |
|
360 |
gSync.Signal(); |
|
361 |
} |
|
362 |
r = fileRead.Read(gBufReadPtr, aBlockSize); |
|
363 |
TESTERROR(r); |
|
364 |
r = VerifyBuffer(gBufReadPtr, 'B'); |
|
365 |
TESTERROR(r); |
|
366 |
||
367 |
j += aBlockSize; |
|
368 |
r = fileRead.Size(size); |
|
369 |
TESTERROR(r); |
|
370 |
} |
|
371 |
||
372 |
fileRead.Close(); |
|
373 |
||
374 |
return KErrNone; |
|
375 |
} |
|
376 |
||
377 |
||
378 |
/** Write a file asynchronously in blocks of aBlockSize size |
|
379 |
||
380 |
@param fs RFs object |
|
381 |
@param aFileWrite RFile object, needs to exist beyond the scope of this function |
|
382 |
@param aFile File name |
|
383 |
@param aSize Size of the file in bytes |
|
384 |
@param aBlockSize Size of the blocks to be used in bytes |
|
385 |
@param aStatus TRequestStatus array for all the requests |
|
386 |
*/ |
|
387 |
void WriteFileAsync(RFs& fs, RFile& aFileWrite, TDes16& aFile, TInt aSize, TInt aBlockSize, TRequestStatus aStatus[]) |
|
388 |
{ |
|
389 |
||
390 |
TInt r = 0; |
|
391 |
||
392 |
TEST(aBlockSize > 0); // Block size must be greater than 0 |
|
393 |
||
394 |
r = aFileWrite.Replace(fs,aFile,EFileShareAny|EFileWrite|EFileWriteDirectIO); |
|
395 |
TESTERROR(r); |
|
396 |
||
397 |
TInt j = 0; |
|
398 |
TInt i = 0; |
|
399 |
while(j < aSize) |
|
400 |
{ |
|
401 |
if((aSize - j) >= aBlockSize) // All the blocks but the last one |
|
402 |
aFileWrite.Write(gBufWritePtr, aBlockSize, aStatus[i]); |
|
403 |
else // The last block |
|
404 |
aFileWrite.Write(gBufWritePtr, (aSize - j), aStatus[i]); |
|
405 |
||
406 |
TInt status = aStatus[i].Int(); |
|
407 |
if (status != KErrNone && status != KRequestPending) |
|
408 |
{ |
|
409 |
test.Printf(_L("RFile::Write() returned %d\n"), aStatus[i].Int()); |
|
410 |
} |
|
411 |
||
412 |
test (status == KErrNone || status == KRequestPending); |
|
413 |
i++; |
|
414 |
j += aBlockSize; |
|
415 |
} |
|
416 |
} |
|
417 |
||
418 |
/** Read a file asynchronously in blocks of aBlockSize size |
|
419 |
||
420 |
@param fs RFs object |
|
421 |
@param aFileRead RFile object, needs to exist beyond the scope of this function |
|
422 |
@param aFile File name |
|
423 |
@param aSize Size of the file in bytes |
|
424 |
@param aBlockSize Size of the blocks to be used in bytes |
|
425 |
@param aStatus TRequestStatus array for all the requests |
|
426 |
||
427 |
@return KErrNone |
|
428 |
*/ |
|
429 |
TInt ReadFileAsync(RFs& fs, RFile& aFileRead, TDes16& aFile, TInt aBlockSize, TRequestStatus aStatus[]) |
|
430 |
{ |
|
431 |
TInt r = 0, size = 0; |
|
432 |
||
433 |
TEST(aBlockSize > 0); // Block size must be greater than 0 |
|
434 |
||
435 |
||
436 |
r = aFileRead.Open(fs, aFile, EFileShareAny|EFileRead|EFileReadDirectIO); |
|
437 |
TESTERROR(r); |
|
438 |
||
439 |
r = aFileRead.Size(size); |
|
440 |
TESTERROR(r); |
|
441 |
||
442 |
TInt j = 0, i = 0; |
|
443 |
while(j < size) |
|
444 |
{ |
|
445 |
aFileRead.Read(gBufReadPtr, aBlockSize, aStatus[i]); |
|
446 |
test (aStatus[i].Int() == KErrNone || aStatus[i].Int() == KRequestPending); |
|
447 |
i++; |
|
448 |
TESTERROR(r); |
|
449 |
j += aBlockSize; |
|
450 |
} |
|
451 |
||
452 |
return KErrNone; |
|
453 |
} |
|
454 |
||
455 |
||
456 |
/** |
|
457 |
Write a pattern to 2 files simultaneously in blocks of aBlockSize size and verify that fair scheduling |
|
458 |
does not interfere with the write order by reading both files back and verifying the contents. |
|
459 |
||
460 |
aBlockSize should be slightly bigger that the fair scheduling size |
|
461 |
||
462 |
@param aFs RFs object |
|
463 |
@param aSize Size of the file in bytes |
|
464 |
@param aBlockSize Size of the blocks to be used in bytes, should be slightly bigger that the fair scheduling size |
|
465 |
*/ |
|
466 |
void WriteOrderTest(RFs& aFs, TInt aSize, TInt aBlockSize) |
|
467 |
{ |
|
468 |
TFileName fileName1, fileName2; |
|
469 |
FileNameGen(fileName1, 8, 99); |
|
470 |
FileNameGen(fileName2, 8, 100); |
|
471 |
||
472 |
RFile file1, file2; |
|
473 |
||
474 |
TRequestStatus status1[KWaitRequestsTableSize]; |
|
475 |
TRequestStatus status2[KWaitRequestsTableSize]; |
|
476 |
||
477 |
TInt r = 0; |
|
478 |
||
479 |
TEST(aBlockSize > 0); // Block size must be greater than 0 |
|
480 |
||
481 |
r = file1.Replace(aFs, fileName1,EFileShareAny|EFileWrite|EFileWriteDirectIO); |
|
482 |
TESTERROR(r); |
|
483 |
||
484 |
r = file2.Replace(aFs, fileName2,EFileShareAny|EFileWrite|EFileWriteDirectIO); |
|
485 |
TESTERROR(r); |
|
486 |
||
487 |
||
488 |
HBufC8* buf1 = NULL; |
|
489 |
TRAP(r,buf1 = HBufC8::NewL(KBigBlockSize)); |
|
490 |
TEST(r == KErrNone && buf1 != NULL); |
|
491 |
||
492 |
TInt maxBlockNum = KBigBlockSize / aBlockSize; |
|
493 |
TInt blockNum = 0; |
|
494 |
TInt blocksFree = maxBlockNum; |
|
495 |
||
496 |
TInt blockHead = 0; // ha ha |
|
497 |
TInt blockTail = 0; |
|
498 |
||
499 |
||
500 |
TPtrC8* writeBuffer = new TPtrC8[maxBlockNum]; |
|
501 |
for (TInt n=0; n<maxBlockNum; n++) |
|
502 |
{ |
|
503 |
TUint8* addr = (TUint8*) buf1->Des().Ptr() + (n * aBlockSize); |
|
504 |
writeBuffer[n].Set(addr, aBlockSize); |
|
505 |
} |
|
506 |
||
507 |
TInt j = 0; |
|
508 |
TInt i = 0; |
|
509 |
while(j < aSize) |
|
510 |
{ |
|
511 |
||
512 |
// fill the buffer with a char based on the block number |
|
513 |
TPtr8 bufWritePtr((TUint8*) writeBuffer[blockHead].Ptr(), 0, writeBuffer[blockHead].Length()); |
|
514 |
TUint8* addr = (TUint8*) buf1->Des().Ptr() + (blockHead * aBlockSize); |
|
515 |
bufWritePtr.Set(addr, 0, aBlockSize); |
|
516 |
FillBuffer(bufWritePtr, aBlockSize, 'A'+blockNum); |
|
517 |
||
518 |
//test.Printf(_L("j %d, addr %08X, aSize %d, blockNum %d, blockTail %d, blockHead %d, maxBlockNum %d, blocksFree %d\n"), |
|
519 |
// j, writeBuffer[blockHead].Ptr(), aSize, blockNum, blockTail, blockHead, maxBlockNum, blocksFree); |
|
520 |
||
521 |
if((aSize - j) >= aBlockSize) // All the blocks but the last one |
|
522 |
file1.Write(writeBuffer[blockHead], aBlockSize, status1[blockHead]); |
|
523 |
else // The last block |
|
524 |
file1.Write(writeBuffer[blockHead], (aSize - j), status1[blockHead]); |
|
525 |
||
526 |
if((aSize - j) >= aBlockSize) // All the blocks but the last one |
|
527 |
file2.Write(writeBuffer[blockHead], aBlockSize, status2[blockHead]); |
|
528 |
else // The last block |
|
529 |
file2.Write(writeBuffer[blockHead], (aSize - j), status2[blockHead]); |
|
530 |
||
531 |
TInt status = status1[blockHead].Int(); |
|
532 |
if (status != KErrNone && status != KRequestPending) |
|
533 |
test.Printf(_L("RFile::Write() returned %d\n"), status1[blockHead].Int()); |
|
534 |
test (status == KErrNone || status == KRequestPending); |
|
535 |
||
536 |
status = status2[blockHead].Int(); |
|
537 |
if (status != KErrNone && status != KRequestPending) |
|
538 |
test.Printf(_L("RFile::Write() returned %d\n"), status1[blockHead].Int()); |
|
539 |
test (status == KErrNone || status == KRequestPending); |
|
540 |
||
541 |
i++; |
|
542 |
j += aBlockSize; |
|
543 |
blockNum++; |
|
544 |
blockHead = (blockHead + 1) % maxBlockNum; |
|
545 |
blocksFree--; |
|
546 |
||
547 |
if (blocksFree == 0) |
|
548 |
{ |
|
549 |
//test.Printf(_L("Waiting for block %d\n"), blockTail); |
|
550 |
User::WaitForRequest(status1[blockTail]); |
|
551 |
User::WaitForRequest(status2[blockTail]); |
|
552 |
blockTail = (blockTail + 1) % maxBlockNum; |
|
553 |
blocksFree++; |
|
554 |
} |
|
555 |
||
556 |
} |
|
557 |
||
558 |
while (blockTail != blockHead) |
|
559 |
{ |
|
560 |
//test.Printf(_L("Waiting for block %d\n"), blockTail); |
|
561 |
User::WaitForRequest(status1[blockTail]); |
|
562 |
User::WaitForRequest(status2[blockTail]); |
|
563 |
blockTail = (blockTail + 1) % maxBlockNum; |
|
564 |
blocksFree++; |
|
565 |
} |
|
566 |
||
567 |
file1.Close(); |
|
568 |
file2.Close(); |
|
569 |
||
570 |
// Verify file1 |
|
571 |
r = file1.Open(aFs, fileName1, EFileShareAny|EFileRead|EFileReadDirectIO); |
|
572 |
TESTERROR(r); |
|
573 |
TInt size; |
|
574 |
r = file1.Size(size); |
|
575 |
TESTERROR(r); |
|
576 |
blockNum = 0; |
|
577 |
j = 0; |
|
578 |
while(j < size) |
|
579 |
{ |
|
580 |
TPtr8 readPtr((TUint8*) writeBuffer[0].Ptr(), aBlockSize, aBlockSize); |
|
581 |
r = file1.Read(readPtr); |
|
582 |
TESTERROR(r); |
|
583 |
r = VerifyBuffer(readPtr, 'A' + blockNum); |
|
584 |
TESTERROR(r); |
|
585 |
j += aBlockSize; |
|
586 |
blockNum++; |
|
587 |
} |
|
588 |
||
589 |
// Verify file2 |
|
590 |
r = file2.Open(aFs, fileName2, EFileShareAny|EFileRead|EFileReadDirectIO); |
|
591 |
TESTERROR(r); |
|
592 |
r = file2.Size(size); |
|
593 |
TESTERROR(r); |
|
594 |
blockNum = 0; |
|
595 |
j = 0; |
|
596 |
while(j < size) |
|
597 |
{ |
|
598 |
TPtr8 readPtr((TUint8*) writeBuffer[0].Ptr(), aBlockSize, aBlockSize); |
|
599 |
r = file2.Read(readPtr); |
|
600 |
TESTERROR(r); |
|
601 |
r = VerifyBuffer(readPtr, 'A' + blockNum); |
|
602 |
TESTERROR(r); |
|
603 |
j += aBlockSize; |
|
604 |
blockNum++; |
|
605 |
} |
|
606 |
||
607 |
file2.Close(); |
|
608 |
file1.Close(); |
|
609 |
||
610 |
delete [] writeBuffer; |
|
611 |
delete buf1; |
|
612 |
||
613 |
r = aFs.Delete(fileName1); |
|
614 |
TEST(r == KErrNone); |
|
615 |
r = aFs.Delete(fileName2); |
|
616 |
TEST(r == KErrNone); |
|
617 |
} |
|
618 |
||
619 |
||
620 |
/** Measure the time taken for a big block to be written synchronously |
|
621 |
*/ |
|
622 |
void TimeTakenToWriteBigBlock() |
|
623 |
{ |
|
624 |
RFile fileWrite; |
|
625 |
||
626 |
TInt r = fileWrite.Replace(TheFs,gBigFile,EFileShareAny|EFileWrite|EFileWriteDirectIO); |
|
627 |
TESTERROR(r); |
|
628 |
||
629 |
// Calculate how long it takes to write a big block to be able to issue at the right time the concurrent writes |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
630 |
TF32TestTimer timer; |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
631 |
timer.Start(); |
0 | 632 |
|
633 |
r = fileWrite.Write(gBufWritePtr, KBigBlockSize); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
634 |
|
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
635 |
timer.Stop(); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
636 |
|
0 | 637 |
fileWrite.Close(); |
638 |
||
639 |
TESTERROR(r); |
|
640 |
||
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
641 |
gTimeTakenBigBlock = timer.TimeInMicroSeconds()/3; |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
642 |
|
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
643 |
test.Printf(_L("\nTime spent to write the big block in isolation: %d ms\n"), TF32TestTimer::TimeInMilliSeconds(gTimeTakenBigBlock)); |
0 | 644 |
} |
645 |
||
646 |
||
647 |
/** Measure the time taken for this file to be written synchronously |
|
648 |
*/ |
|
649 |
void TimeTakenToWriteBigFile(TInt aPos) |
|
650 |
{ |
|
651 |
test((aPos >= 0) && (aPos <= 1)); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
652 |
TF32TestTimer timer; |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
653 |
timer.Start(); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
654 |
|
0 | 655 |
WriteFile(TheFs,gBigFile, gBigFileSize, KBigBlockSize, ENoThreads); |
656 |
||
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
657 |
timer.Stop(); |
0 | 658 |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
659 |
gTimeTakenBigFile = timer.Time32(); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
660 |
|
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
661 |
test.Printf(_L("\nTime spent to write the big file in isolation: %d ms\n"), TF32TestTimer::TimeInMilliSeconds(gTimeTakenBigFile)); |
0 | 662 |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
663 |
gTotalTimeSync[aPos] = Max(TF32TestTimer::TimeInMilliSeconds(gTimeTakenBigFile), gTotalTimeSync[aPos]) ; |
0 | 664 |
} |
665 |
||
666 |
/** Measure the time taken for this file to be written asynchronously |
|
667 |
*/ |
|
668 |
void TimeTakenToWriteBigFileAsync(TInt aPos) |
|
669 |
{ |
|
670 |
TRequestStatus status[KWaitRequestsTableSize]; |
|
671 |
RFile bigFile; |
|
672 |
||
673 |
test((aPos >= 0) && (aPos <= 1)); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
674 |
|
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
675 |
TF32TestTimer2 timer; |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
676 |
timer.Start(); |
0 | 677 |
WriteFileAsync(TheFs, bigFile, gBigFile, gBigFileSize,KBigBlockSize,status); |
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
678 |
timer.Stop(); |
0 | 679 |
|
680 |
WaitForAll(status, gBigFileSize, KBigBlockSize); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
681 |
timer.Stop2(); |
0 | 682 |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
683 |
gTimeTakenBigFile = timer.Time32(); |
0 | 684 |
bigFile.Close(); |
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
685 |
test.Printf(_L("\nTime to queue the blocks in isolation asynchronously: %d ms, "), timer.TimeInMilliSeconds()); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
686 |
gTimeTakenBigFile = timer.Time2(); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
687 |
test.Printf(_L("to actually write it: %d ms\n"), TF32TestTimer::TimeInMilliSeconds(gTimeTakenBigFile)); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
688 |
gTotalTimeAsync[aPos] = Max(TF32TestTimer::TimeInMilliSeconds(gTimeTakenBigFile), gTotalTimeAsync[aPos]) ; |
0 | 689 |
} |
690 |
||
691 |
/** Delete content of directory |
|
692 |
||
693 |
@param aDir Target directory |
|
694 |
||
695 |
@return Error returned if any, otherwise KErrNone |
|
696 |
*/ |
|
697 |
TInt DeleteAll(TDes16& aDir) |
|
698 |
{ |
|
699 |
TBuf16<100> dir; |
|
700 |
CFileMan* fMan=CFileMan::NewL(TheFs); |
|
701 |
TInt r=0; |
|
702 |
||
703 |
dir = aDir; |
|
704 |
dir.Append(_L("F*.*")); |
|
705 |
r = fMan->Delete(dir); |
|
706 |
||
707 |
delete fMan; |
|
708 |
return r; |
|
709 |
} |
|
710 |
||
711 |
/** Read a small file sync, in a different thread |
|
712 |
||
713 |
@return ETrue |
|
714 |
*/ |
|
715 |
TInt ReadSmallFile(TAny* ) |
|
716 |
{ |
|
717 |
RTest test(_L("T_FSCHED")); |
|
718 |
RFs fs; |
|
719 |
TInt r=fs.Connect(); |
|
720 |
TESTERROR(r); |
|
721 |
||
722 |
r = fs.SetSessionPath(gSessionPath); |
|
723 |
TESTERROR(r); |
|
724 |
||
725 |
ReadFile(fs,gSmallFile,KBlockSize, EThreadWait); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
726 |
gTestTimer.Start(); |
0 | 727 |
|
728 |
client.Signal(); |
|
729 |
||
730 |
fs.Close(); |
|
731 |
test.Close(); |
|
732 |
||
733 |
return ETrue; |
|
734 |
} |
|
735 |
||
736 |
/** Read the big file sync, in a different thread |
|
737 |
||
738 |
@return ETrue |
|
739 |
*/ |
|
740 |
TInt ReadBigFile(TAny* ) |
|
741 |
{ |
|
742 |
RTest test(_L("T_FSCHED")); |
|
743 |
RFs fs; |
|
744 |
TInt r=fs.Connect(); |
|
745 |
TESTERROR(r); |
|
746 |
||
747 |
r=fs.SetSessionPath(gSessionPath); |
|
748 |
TESTERROR(r); |
|
749 |
||
750 |
ReadFile(fs,gBigFile,KBlockSize, EThreadWait); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
751 |
gTestTimer.Stop(); |
0 | 752 |
|
753 |
client.Signal(); |
|
754 |
||
755 |
fs.Close(); |
|
756 |
test.Close(); |
|
757 |
||
758 |
return ETrue; |
|
759 |
} |
|
760 |
||
761 |
/** Write a small file sync, in a different thread |
|
762 |
||
763 |
@return ETrue |
|
764 |
*/ |
|
765 |
TInt WriteSmallFile(TAny* ) |
|
766 |
{ |
|
767 |
RTest test(_L("T_FSCHED")); |
|
768 |
RFs fs; |
|
769 |
TInt r=fs.Connect(); |
|
770 |
TESTERROR(r); |
|
771 |
||
772 |
r=fs.SetSessionPath(gSessionPath); |
|
773 |
TESTERROR(r); |
|
774 |
||
775 |
WriteFile(fs,gSmallFile,gSmallFileSize, KBlockSize, EThreadWait); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
776 |
gTestTimer.Start(); |
0 | 777 |
|
778 |
client.Signal(); |
|
779 |
||
780 |
fs.Close(); |
|
781 |
test.Close(); |
|
782 |
||
783 |
return ETrue; |
|
784 |
} |
|
785 |
||
786 |
/** Write a big file sync, in a different thread |
|
787 |
||
788 |
@return ETrue |
|
789 |
*/ |
|
790 |
TInt WriteBigFile(TAny* ) |
|
791 |
{ |
|
792 |
RTest test(_L("T_FSCHED")); |
|
793 |
RFs fs; |
|
794 |
TInt r=fs.Connect(); |
|
795 |
TESTERROR(r); |
|
796 |
||
797 |
r=fs.SetSessionPath(gSessionPath); |
|
798 |
TESTERROR(r); |
|
799 |
||
800 |
WriteFile(fs, gBigFile, gBigFileSize, KBigBlockSize, EThreadSignal); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
801 |
gTestTimer.Stop(); |
0 | 802 |
|
803 |
client.Signal(); |
|
804 |
||
805 |
fs.Close(); |
|
806 |
test.Close(); |
|
807 |
||
808 |
return ETrue; |
|
809 |
} |
|
810 |
||
811 |
/** Write big file after a signalling thread has been scheduled, in a different thread |
|
812 |
||
813 |
@return ETrue |
|
814 |
*/ |
|
815 |
TInt WriteBigFile2(TAny* ) |
|
816 |
{ |
|
817 |
RTest test(_L("T_FSCHED")); |
|
818 |
RFs fs; |
|
819 |
TInt r=fs.Connect(); |
|
820 |
TESTERROR(r); |
|
821 |
||
822 |
r = fs.SetSessionPath(gSessionPath); |
|
823 |
TESTERROR(r); |
|
824 |
||
825 |
WriteFile(fs, gSmallFile, gBigFileSize, KBigBlockSize, EThreadWait); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
826 |
gTestTimer.Stop(); |
0 | 827 |
|
828 |
client.Signal(); |
|
829 |
||
830 |
fs.Close(); |
|
831 |
test.Close(); |
|
832 |
||
833 |
return ETrue; |
|
834 |
} |
|
835 |
||
836 |
/** Write a big file async, in a different thread |
|
837 |
||
838 |
@return ETrue |
|
839 |
*/ |
|
840 |
TInt WriteBigFileAsync(TAny* ) |
|
841 |
{ |
|
842 |
RTest test(_L("T_FSCHED")); |
|
843 |
RFs fs; |
|
844 |
TInt r = fs.Connect(); |
|
845 |
TESTERROR(r); |
|
846 |
||
847 |
r=fs.SetSessionPath(gSessionPath); |
|
848 |
TESTERROR(r); |
|
849 |
||
850 |
||
851 |
RFile bigFile; |
|
852 |
||
853 |
WriteFileAsync(fs, bigFile, gSmallFile, gBigFileSize, KBlockSize,gStatus); |
|
854 |
gSync.Signal(); |
|
855 |
WaitForAll(gStatus, gBigFileSize, KBlockSize); |
|
856 |
||
857 |
fs.Close(); |
|
858 |
test.Close(); |
|
859 |
||
860 |
return ETrue; |
|
861 |
} |
|
862 |
||
863 |
/** Delete a big file, in a different thread |
|
864 |
||
865 |
@return ETrue |
|
866 |
*/ |
|
867 |
TInt DeleteBigFile(TAny* ) |
|
868 |
{ |
|
869 |
RTest test(_L("T_FSCHED")); |
|
870 |
RFs fs; |
|
871 |
TInt r = fs.Connect(); |
|
872 |
TESTERROR(r); |
|
873 |
||
874 |
r = fs.SetSessionPath(gSessionPath); |
|
875 |
TESTERROR(r); |
|
876 |
||
877 |
gSync.Wait(); |
|
878 |
||
879 |
r = fs.Delete(gBigFile); |
|
880 |
#if defined(__WINS__) |
|
881 |
TEST(r == KErrInUse || r == KErrNone); |
|
882 |
#else |
|
883 |
test_Equal(KErrInUse, r); |
|
884 |
#endif |
|
885 |
||
886 |
client.Signal(); |
|
887 |
||
888 |
fs.Close(); |
|
889 |
test.Close(); |
|
890 |
||
891 |
return ETrue; |
|
892 |
} |
|
893 |
||
894 |
/** Reads a small file while writing a big one |
|
895 |
||
896 |
*/ |
|
897 |
void TestReadingWhileWriting() |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
898 |
{ |
0 | 899 |
// Write the small file and take the appropriate measures |
900 |
WriteFile(TheFs,gSmallFile,KBlockSize, KBlockSize, ENoThreads); |
|
901 |
||
902 |
// Sync test |
|
903 |
TBuf<20> buf=_L("Big Write"); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
904 |
TInt r = gBig.Create(buf, WriteBigFile, KDefaultStackSize, KHeapSize, KMaxHeapSize, NULL); |
0 | 905 |
TEST(r == KErrNone); |
906 |
||
907 |
buf = _L("Small Read"); |
|
908 |
r = gSmall.Create(buf, ReadSmallFile, KDefaultStackSize, KHeapSize, KMaxHeapSize, NULL); |
|
909 |
TEST(r == KErrNone); |
|
910 |
||
911 |
gBig.Resume(); |
|
912 |
gSmall.Resume(); |
|
913 |
||
914 |
CLIENTWAIT(); |
|
915 |
CLIENTWAIT(); |
|
916 |
||
917 |
gBig.Close(); |
|
918 |
gSmall.Close(); |
|
919 |
||
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
920 |
TTimeIntervalMicroSeconds timeTaken = gTestTimer.Time(); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
921 |
test.Printf(_L("\nSync read done %d ms before the write ended\n"), TF32TestTimer::TimeInMilliSeconds(timeTaken)); |
0 | 922 |
#if !defined(__WINS__) |
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
923 |
// If this condition fails, it means that writing the sync file while |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
924 |
// fairscheduling a small sync read takes too long. Reading small file |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
925 |
// should complete first. |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
926 |
test(timeTaken > 0); |
0 | 927 |
#endif |
928 |
||
929 |
// Async test |
|
930 |
TRequestStatus status[KWaitRequestsTableSize]; |
|
931 |
TRequestStatus status2[2]; |
|
932 |
RFile bigFile, smallFile; |
|
933 |
||
934 |
WriteFileAsync(TheFs, bigFile, gBigFile, gBigFileSize, KBigBlockSize ,status); |
|
935 |
ReadFileAsync(TheFs, smallFile, gSmallFile, KBlockSize, status2 ); |
|
936 |
||
937 |
WaitForAll(status2,KBlockSize , KBlockSize ); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
938 |
|
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
939 |
TF32TestTimer timer; |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
940 |
timer.Start(); |
0 | 941 |
|
942 |
WaitForAll(status,gBigFileSize, KBigBlockSize); |
|
943 |
||
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
944 |
timer.Stop(); |
0 | 945 |
bigFile.Close(); |
946 |
smallFile.Close(); |
|
947 |
||
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
948 |
timeTaken = timer.Time(); |
0 | 949 |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
950 |
test.Printf(_L("\nAsync read done %d ms before the write ended\n"), timer.TimeInMilliSeconds()); |
0 | 951 |
|
952 |
#if !defined(__WINS__) |
|
200
73ea206103e6
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
953 |
if (!Is_HVFS(TheFs, gDrive)) |
73ea206103e6
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
954 |
{ |
73ea206103e6
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
955 |
// If this condition fails, it means that writing the async file while fairscheduling a small async read takes too long |
0 | 956 |
test.Printf(_L("gTotalTimeAsync[0] = %d , gTotalTimeAsync[1] = %d\n"),gTotalTimeAsync[0],gTotalTimeAsync[1] ); |
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
957 |
test(timeTaken > 0); |
200
73ea206103e6
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
958 |
} |
0 | 959 |
#endif |
960 |
} |
|
961 |
||
962 |
/** Writes a small file while writing a big one |
|
963 |
||
964 |
*/ |
|
965 |
void TestWritingWhileWriting() |
|
966 |
{ |
|
967 |
TInt r = 0; |
|
968 |
||
969 |
// Sync test |
|
970 |
TBuf<20> buf = _L("Big Write II"); |
|
971 |
r = gBig.Create(buf, WriteBigFile, KDefaultStackSize, KHeapSize, KMaxHeapSize, NULL); |
|
972 |
TEST(r == KErrNone); |
|
973 |
||
974 |
buf = _L("Small Write II"); |
|
975 |
r = gSmall.Create(buf, WriteSmallFile, KDefaultStackSize, KHeapSize, KMaxHeapSize, NULL); |
|
976 |
TEST(r==KErrNone); |
|
977 |
||
978 |
gBig.Resume(); |
|
979 |
gSmall.Resume(); |
|
980 |
||
981 |
CLIENTWAIT(); |
|
982 |
CLIENTWAIT(); |
|
983 |
||
984 |
gBig.Close(); |
|
985 |
gSmall.Close(); |
|
986 |
||
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
987 |
TTimeIntervalMicroSeconds timeTaken = gTestTimer.Time(); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
988 |
test.Printf(_L("\nSync write done %d ms before the big write ended\n"), gTestTimer.TimeInMilliSeconds()); |
0 | 989 |
#if !defined(__WINS__) |
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
990 |
// If this condition fails, it means that writing the sync file while |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
991 |
// fairscheduling a small sync write takes too long |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
992 |
test(timeTaken > 0); |
0 | 993 |
#endif |
994 |
||
995 |
// Async test |
|
996 |
TRequestStatus status[KWaitRequestsTableSize]; |
|
997 |
TRequestStatus status2[1]; |
|
998 |
RFile bigFile, smallFile; |
|
999 |
||
1000 |
WriteFileAsync(TheFs, bigFile, gBigFile, gBigFileSize, KBigBlockSize, status); |
|
1001 |
WriteFileAsync(TheFs,smallFile, gSmallFile,gSmallFileSize,KBlockSize,status2); |
|
1002 |
WaitForAll(status2,gSmallFileSize, KBlockSize); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
1003 |
TF32TestTimer timer; |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
1004 |
timer.Start(); |
0 | 1005 |
WaitForAll(status, gBigFileSize, KBigBlockSize); |
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
1006 |
timer.Stop(); |
0 | 1007 |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
1008 |
timeTaken = timer.Time(); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
1009 |
test.Printf(_L("\nAsync write done %d ms before the big write ended\n"),timer.TimeInMilliSeconds()); |
0 | 1010 |
#if !defined(__WINS__) |
200
73ea206103e6
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
1011 |
if (!Is_HVFS(TheFs, gDrive)) |
73ea206103e6
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
1012 |
{ |
73ea206103e6
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
1013 |
// If this condition fails, it means that writing the async file while fairscheduling a small async write takes too long |
0 | 1014 |
test.Printf(_L("gTotalTimeAsync[0] = %d , gTotalTimeAsync[1] = %d\n"),gTotalTimeAsync[0],gTotalTimeAsync[1] ); |
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
1015 |
test(timeTaken > 0); |
200
73ea206103e6
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
1016 |
} |
0 | 1017 |
#endif |
1018 |
bigFile.Close(); |
|
1019 |
smallFile.Close(); |
|
1020 |
} |
|
1021 |
||
1022 |
/** Writes two big files, ensuring the one that started to be written later ends the last one |
|
1023 |
||
1024 |
*/ |
|
1025 |
void TestTwoBigOnes() |
|
1026 |
{ |
|
1027 |
TInt r = 0; |
|
1028 |
||
1029 |
// Sync test |
|
1030 |
TBuf<20> buf = _L("Big Write IIII"); |
|
1031 |
r = gBig.Create(buf, WriteBigFile, KDefaultStackSize, KHeapSize, KMaxHeapSize, NULL); |
|
1032 |
TEST(r == KErrNone); |
|
1033 |
||
1034 |
buf = _L("Big Write The Second"); |
|
1035 |
r = gSmall.Create(buf, WriteBigFile2, KDefaultStackSize, KHeapSize, KMaxHeapSize, NULL); |
|
1036 |
TEST(r == KErrNone); |
|
1037 |
||
1038 |
gBig.Resume(); |
|
1039 |
gSmall.Resume(); |
|
1040 |
||
1041 |
CLIENTWAIT(); |
|
1042 |
CLIENTWAIT(); |
|
1043 |
||
1044 |
gBig.Close(); |
|
1045 |
gSmall.Close(); |
|
1046 |
||
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
1047 |
TTimeIntervalMicroSeconds timeTaken = gTestTimer.Time(); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
1048 |
test.Printf(_L("\nSync first write ended %d ms before the second write ended (same file size)\n"),TF32TestTimer::TimeInMilliSeconds(timeTaken)); |
0 | 1049 |
|
1050 |
// Async test |
|
1051 |
TRequestStatus status[KWaitRequestsTableSize]; |
|
1052 |
TRequestStatus status2[KWaitRequestsTableSize]; |
|
1053 |
RFile bigFile, bigFile2; |
|
1054 |
||
1055 |
WriteFileAsync(TheFs, bigFile, gBigFile, gBigFileSize, KBigBlockSize, status); |
|
1056 |
WriteFileAsync(TheFs, bigFile2, gSmallFile, gBigFileSize, KBigBlockSize, status2); |
|
1057 |
WaitForAll(status, gBigFileSize, KBigBlockSize); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
1058 |
TF32TestTimer timer; |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
1059 |
timer.Start(); |
0 | 1060 |
WaitForAll(status2, gBigFileSize, KBigBlockSize); |
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
1061 |
timer.Stop(); |
0 | 1062 |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
1063 |
timeTaken = timer.Time(); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
1064 |
test.Printf(_L("\nAsync first write ended %d ms before the second write ended (same file size)\n"),TF32TestTimer::TimeInMilliSeconds(timeTaken)); |
0 | 1065 |
bigFile.Close(); |
1066 |
bigFile2.Close(); |
|
1067 |
} |
|
1068 |
||
1069 |
/** Reads the file that is being written |
|
1070 |
||
1071 |
*/ |
|
1072 |
void TestReadingWhileWritingSameFile() |
|
1073 |
{ |
|
1074 |
TInt r = 0; |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
1075 |
TF32TestTimer timer; |
0 | 1076 |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
1077 |
timer.Start(); |
0 | 1078 |
|
1079 |
// Sync test |
|
1080 |
TBuf<20> buf = _L("Big Write IV"); |
|
1081 |
r = gBig.Create(buf, WriteBigFile, KDefaultStackSize, KHeapSize, KMaxHeapSize, NULL); |
|
1082 |
TEST(r == KErrNone); |
|
1083 |
||
1084 |
buf = _L("Read IV"); |
|
1085 |
r = gSmall.Create(buf, ReadBigFile, KDefaultStackSize, KHeapSize, KMaxHeapSize, NULL); |
|
1086 |
TEST(r == KErrNone); |
|
1087 |
||
1088 |
gBig.Resume(); |
|
1089 |
gSmall.Resume(); |
|
1090 |
||
1091 |
CLIENTWAIT(); |
|
1092 |
CLIENTWAIT(); |
|
1093 |
||
1094 |
CLOSE_AND_WAIT(gBig); |
|
1095 |
CLOSE_AND_WAIT(gSmall); |
|
1096 |
||
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
1097 |
TTimeIntervalMicroSeconds timeTaken = gTestTimer.Time(); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
200
diff
changeset
|
1098 |
test.Printf(_L("\nSync write finished %d ms before the read ended\n"),TF32TestTimer::TimeInMilliSeconds(timeTaken)); |
0 | 1099 |
|
1100 |
} |
|
1101 |
||
1102 |
/** Client dying uncleanly before the operation is finished |
|
1103 |
||
1104 |
*/ |
|
1105 |
void TestClientDies() |
|
1106 |
{ |
|
1107 |
TInt r = 0; |
|
1108 |
||
1109 |
||
1110 |
TBuf<20> drive = _L("?:\\"); |
|
1111 |
TVolumeInfo volInfo; |
|
1112 |
drive[0]=(TText)(gDrive+'A'); |
|
1113 |
||
1114 |
r = TheFs.CheckDisk(drive); |
|
1115 |
TEST(r == KErrNone || r == KErrNotSupported); |
|
1116 |
||
1117 |
// Sync test |
|
1118 |
TBuf<20> buf = _L("Big Write V"); |
|
1119 |
r = gBig.Create(buf, WriteBigFile, KDefaultStackSize, KHeapSize, KMaxHeapSize, NULL); |
|
1120 |
TEST(r == KErrNone); |
|
1121 |
||
1122 |
TRequestStatus status; |
|
1123 |
gBig.Logon(status); |
|
1124 |
gBig.Resume(); |
|
1125 |
gSync.Wait(); |
|
1126 |
||
1127 |
// Kill the writing thread and wait for it to die. |
|
1128 |
||
1129 |
if(status.Int() == KRequestPending) |
|
1130 |
{// the people who wrote this test did not consider the case when the file write finishes before they try to kill the thread. |
|
1131 |
gBig.Kill(KErrGeneral); |
|
1132 |
User::WaitForRequest(status); |
|
1133 |
TEST(gBig.ExitReason() == KErrGeneral); |
|
1134 |
TEST(gBig.ExitType() == EExitKill); |
|
1135 |
} |
|
1136 |
||
1137 |
||
1138 |
// Make sure the thread is destroyed and the handles it owned and IPCs |
|
1139 |
// it executed are closed/cancelled. |
|
1140 |
CLOSE_AND_WAIT(gBig); |
|
1141 |
||
1142 |
||
1143 |
r = TheFs.Volume(volInfo, gDrive); |
|
1144 |
TESTERROR(r); |
|
1145 |
||
1146 |
r = TheFs.CheckDisk(drive); |
|
1147 |
TEST(r == KErrNone || r == KErrNotSupported); |
|
1148 |
||
1149 |
r = TheFs.ScanDrive(drive); |
|
1150 |
TEST(r == KErrNone || r == KErrNotSupported); |
|
1151 |
||
1152 |
test.Printf(_L("Sync operation stopped\n")); |
|
1153 |
||
1154 |
// Async test |
|
1155 |
buf = _L("Big Write VI"); |
|
1156 |
r = gSmall.Create(buf, WriteBigFileAsync, KDefaultStackSize * 2, KHeapSize, KMaxHeapSize, NULL); |
|
1157 |
TEST(r == KErrNone); |
|
1158 |
||
1159 |
gSmall.Logon(status); |
|
1160 |
gSmall.Resume(); |
|
1161 |
gSync.Wait(); |
|
1162 |
||
1163 |
||
1164 |
if(status.Int() == KRequestPending) |
|
1165 |
{ |
|
1166 |
// Kill the writing thread and wait for it to die. |
|
1167 |
gSmall.Kill(KErrGeneral); |
|
1168 |
User::WaitForRequest(status); |
|
1169 |
TEST(gSmall.ExitReason() == KErrGeneral); |
|
1170 |
TEST(gSmall.ExitType() == EExitKill); |
|
1171 |
} |
|
1172 |
||
1173 |
||
1174 |
// Make sure the thread is destroyed and the handles it owned and IPCs |
|
1175 |
// it executed are closed/cancelled. |
|
1176 |
CLOSE_AND_WAIT(gSmall); |
|
1177 |
||
1178 |
r = TheFs.CheckDisk(drive); |
|
1179 |
TEST(r == KErrNone || r == KErrNotSupported); |
|
1180 |
||
1181 |
r=TheFs.ScanDrive(drive); |
|
1182 |
TEST(r == KErrNone || r == KErrNotSupported); |
|
1183 |
||
1184 |
test.Printf(_L("Async operation stopped\n")); |
|
1185 |
} |
|
1186 |
||
1187 |
/** Reads a small file while writing a big one |
|
1188 |
||
1189 |
*/ |
|
1190 |
void TestDeletionWhileWriting() |
|
1191 |
{ |
|
1192 |
TInt r = 0; |
|
1193 |
||
1194 |
// Sync test |
|
1195 |
TBuf<20> buf = _L("Big Write V"); |
|
1196 |
r = gBig.Create(buf, WriteBigFile, KDefaultStackSize, KHeapSize, KMaxHeapSize, NULL); |
|
1197 |
TEST(r == KErrNone); |
|
1198 |
||
1199 |
buf = _L("Deletion"); |
|
1200 |
r = gSmall.Create(buf, DeleteBigFile, KDefaultStackSize, KHeapSize, KMaxHeapSize, NULL); |
|
1201 |
TEST(r == KErrNone); |
|
1202 |
||
1203 |
gSmall.Resume(); |
|
1204 |
gBig.Resume(); |
|
1205 |
||
1206 |
CLIENTWAIT(); |
|
1207 |
CLIENTWAIT(); |
|
1208 |
||
1209 |
gBig.Close(); |
|
1210 |
gSmall.Close(); |
|
1211 |
||
1212 |
test.Printf(_L("The file was properly blocked when writing sync, not deleted\n")); |
|
1213 |
||
1214 |
// Async test |
|
1215 |
TRequestStatus status[KWaitRequestsTableSize]; |
|
1216 |
RFile bigFile; |
|
1217 |
RFs fs; |
|
1218 |
||
1219 |
r = fs.Connect(); |
|
1220 |
TESTERROR(r); |
|
1221 |
r = fs.SetSessionPath(gSessionPath); |
|
1222 |
TESTERROR(r); |
|
1223 |
||
1224 |
WriteFileAsync(TheFs, bigFile, gBigFile, gBigFileSize, KBigBlockSize, status); |
|
1225 |
||
1226 |
r = fs.Delete(gBigFile); |
|
1227 |
TEST(r == KErrInUse); |
|
1228 |
||
1229 |
WaitForAll(status, gBigFileSize, KBigBlockSize); |
|
1230 |
||
1231 |
bigFile.Close(); |
|
1232 |
fs.Close(); |
|
1233 |
||
1234 |
test.Printf(_L("The file was properly blocked when writing async, not deleted\n")); |
|
1235 |
||
1236 |
} |
|
1237 |
||
1238 |
||
1239 |
void TestWriteOrder() |
|
1240 |
{ |
|
1241 |
RFs fs; |
|
1242 |
||
1243 |
TInt r = fs.Connect(); |
|
1244 |
TESTERROR(r); |
|
1245 |
r = fs.SetSessionPath(gSessionPath); |
|
1246 |
TESTERROR(r); |
|
1247 |
||
1248 |
WriteOrderTest(TheFs, gBigFileSize, KBlockSize); |
|
1249 |
||
1250 |
fs.Close(); |
|
1251 |
} |
|
1252 |
||
1253 |
||
1254 |
/** Main tests function |
|
1255 |
*/ |
|
1256 |
void CallTestsL() |
|
1257 |
{ |
|
1258 |
TBuf16<45> dir; |
|
1259 |
TInt r = 0; |
|
1260 |
||
1261 |
||
1262 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
1263 |
test.Printf(_L("Disabling Lock Fail simulation ...\n")); |
|
1264 |
// turn OFF lock failure mode (if cache is enabled) |
|
1265 |
||
1266 |
TBool simulatelockFailureMode = EFalse; |
|
1267 |
r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1268 |
test_Value(r, r == KErrNone || r == KErrNotSupported); |
0 | 1269 |
#endif |
1270 |
||
1271 |
// FileNames/File generation |
|
1272 |
test.Start(_L("Preparing the environment\n")); |
|
1273 |
||
1274 |
FileNameGen(gSmallFile, 8, gNextFile++); |
|
1275 |
FileNameGen(gBigFile, 8, gNextFile++); |
|
1276 |
||
1277 |
dir = gSessionPath; |
|
1278 |
dir.Append(gSmallFile); |
|
1279 |
||
1280 |
gSmallFile = dir; |
|
1281 |
dir = gSessionPath; |
|
1282 |
dir.Append(gBigFile); |
|
1283 |
gBigFile = dir; |
|
1284 |
||
1285 |
TRAPD(res,gBuf = HBufC8::NewL(KBigBlockSize)); |
|
1286 |
TEST(res == KErrNone && gBuf != NULL); |
|
1287 |
||
1288 |
gBufWritePtr.Set(gBuf->Des()); |
|
1289 |
FillBuffer(gBufWritePtr, KBigBlockSize, 'B'); |
|
1290 |
||
1291 |
TRAPD(res2, gBufSec = HBufC8::NewL(KBlockSize)); |
|
1292 |
TEST(res2 == KErrNone && gBufSec != NULL); |
|
1293 |
gBufReadPtr.Set(gBufSec->Des()); |
|
1294 |
||
1295 |
test.Next(_L("Benchmarking\n")); |
|
1296 |
TimeTakenToWriteBigFile(0); |
|
1297 |
TimeTakenToWriteBigFileAsync(0); |
|
1298 |
||
1299 |
test.Printf(_L("second try, second timings account for the last comparison\n")); |
|
1300 |
TimeTakenToWriteBigFile(0); |
|
1301 |
TimeTakenToWriteBigFileAsync(0); |
|
1302 |
||
1303 |
TimeTakenToWriteBigBlock(); |
|
1304 |
||
1305 |
test.Next(_L("Big file sync written, small file read from the media at the same time\n")); |
|
1306 |
TestReadingWhileWriting(); |
|
1307 |
||
1308 |
test.Next(_L("Big file written, small file written at the same time\n")); |
|
1309 |
TestWritingWhileWriting(); |
|
1310 |
||
1311 |
test.Next(_L("Big file written async, deletion in the meantime\n")); |
|
1312 |
TestDeletionWhileWriting(); |
|
1313 |
||
1314 |
test.Next(_L("Two big files written at the same time\n")); |
|
1315 |
TestTwoBigOnes(); |
|
1316 |
||
1317 |
test.Next(_L("Big file being written, start reading\n")); |
|
1318 |
TestReadingWhileWritingSameFile(); |
|
1319 |
||
1320 |
test.Next(_L("Client dying unexpectedly\n")); |
|
1321 |
TestClientDies(); |
|
1322 |
||
1323 |
test.Next(_L("Ensure write order is preserved\n")); |
|
1324 |
TestWriteOrder(); |
|
1325 |
||
1326 |
// Format the drive to make sure no blocks are left to be erased in LFFS |
|
200
73ea206103e6
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
1327 |
if (!Is_Win32(TheFs, gDrive)) |
0 | 1328 |
Format(gDrive); |
200
73ea206103e6
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
1329 |
|
0 | 1330 |
r = TheFs.MkDirAll(gSessionPath); |
1331 |
||
1332 |
TimeTakenToWriteBigFile(1); |
|
1333 |
TimeTakenToWriteBigFileAsync(1); |
|
1334 |
||
1335 |
// Make sure that the difference between the first time and the last time the files are written doesn't |
|
1336 |
// differ more than 3% |
|
1337 |
test.Printf(_L("Abs(gTotalTimeSync[0]-gTotalTimeSync[1]) :%d\n"), Abs(gTotalTimeSync[0]-gTotalTimeSync[1])); |
|
1338 |
test.Printf(_L("Abs(gTotalTimeAsync[0]-gTotalTimeAsync[1]) :%d\n"), Abs(gTotalTimeAsync[0]-gTotalTimeAsync[1])); |
|
1339 |
test.Printf(_L("gTotalTimeSync[0] :%d\n"), gTotalTimeSync[0]); |
|
1340 |
test.Printf(_L("gTotalTimeAsync[0] :%d\n"), gTotalTimeAsync[0]); |
|
1341 |
||
1342 |
#if !defined(__WINS__) |
|
1343 |
test((Abs(gTotalTimeSync[0]-gTotalTimeSync[1])/gTotalTimeSync[0]) < 0.03); |
|
1344 |
test((Abs(gTotalTimeAsync[0]-gTotalTimeAsync[1])/gTotalTimeAsync[0]) < 0.03); |
|
1345 |
#endif |
|
1346 |
||
1347 |
r = DeleteAll(gSessionPath); |
|
1348 |
TESTERROR(r); |
|
1349 |
||
1350 |
delete gBuf; |
|
1351 |
delete gBufSec; |
|
1352 |
||
1353 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
1354 |
// turn lock failure mode back ON (if cache is enabled) |
|
1355 |
simulatelockFailureMode = ETrue; |
|
1356 |
r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1357 |
test_Value(r, r == KErrNone || r == KErrNotSupported); |
0 | 1358 |
#endif |
1359 |
||
1360 |
test.End(); |
|
1361 |
} |
|
1362 |
||
1363 |
/** Initialises semaphores and call the tests |
|
1364 |
*/ |
|
1365 |
void DoTests() |
|
1366 |
{ |
|
1367 |
TInt r = 0; |
|
1368 |
||
1369 |
r = client.CreateLocal(0); |
|
1370 |
TESTERROR(r); |
|
1371 |
||
1372 |
r = gSync.CreateLocal(0); |
|
1373 |
TESTERROR(r); |
|
1374 |
||
1375 |
r = TheFs.SetSessionPath(gSessionPath); |
|
1376 |
TESTERROR(r); |
|
1377 |
||
1378 |
r = TheFs.MkDirAll(gSessionPath); |
|
1379 |
if (r != KErrNone && r != KErrAlreadyExists) |
|
1380 |
{ |
|
1381 |
TESTERROR(r); |
|
1382 |
} |
|
1383 |
TheFs.ResourceCountMarkStart(); |
|
1384 |
TRAP(r,CallTestsL()); |
|
1385 |
if (r == KErrNone) |
|
1386 |
TheFs.ResourceCountMarkEnd(); |
|
1387 |
else |
|
1388 |
{ |
|
1389 |
TESTERROR(r); |
|
1390 |
} |
|
1391 |
} |
|
1392 |
||
1393 |
/** Determines the space that can be used for the files |
|
1394 |
||
1395 |
*/ |
|
1396 |
TBool CheckForDiskSize() |
|
1397 |
{ |
|
1398 |
TVolumeInfo volInfo; |
|
1399 |
TInt r = TheFs.Volume(volInfo, gDrive); |
|
1400 |
TESTERROR(r); |
|
1401 |
||
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
247
diff
changeset
|
1402 |
gMediaSize = volInfo.iFree; |
0 | 1403 |
gSmallFileSize = KBlockSize; |
1404 |
gBigFileSize = KBlockSize*20; |
|
1405 |
||
1406 |
while(((2*gBigFileSize)+KOneMeg) > gMediaSize ) |
|
1407 |
{ |
|
1408 |
gBigFileSize -= (2*KBlockSize); |
|
1409 |
} |
|
1410 |
||
1411 |
TReal32 small = (TReal32)(gSmallFileSize/KOneK); |
|
1412 |
TReal32 big = (TReal32)(gBigFileSize/KOneK); |
|
1413 |
||
1414 |
||
1415 |
test.Printf(_L("Small File Size: %.2f KB\n"), small); |
|
1416 |
test.Printf(_L("Big File Size: %.2f KB (%.2f MB)\n"), big, big / KOneK); |
|
1417 |
||
1418 |
if(gBigFileSize< (3*gSmallFileSize)) |
|
1419 |
return EFalse; |
|
1420 |
else |
|
1421 |
return ETrue; |
|
1422 |
} |
|
1423 |
||
1424 |
/** Formats the drive |
|
1425 |
||
1426 |
@param aDrive Drive to be formatted |
|
1427 |
*/ |
|
1428 |
void Format(TInt aDrive) |
|
1429 |
{ |
|
1430 |
||
1431 |
test.Next(_L("Format")); |
|
1432 |
TBuf<4> driveBuf = _L("?:\\"); |
|
1433 |
driveBuf[0] = (TText)(aDrive+'A'); |
|
1434 |
RFormat format; |
|
1435 |
TInt count, prevcount = 0; |
|
1436 |
TInt r = format.Open(TheFs, driveBuf, EQuickFormat, count); |
|
1437 |
TESTERROR(r); |
|
1438 |
||
1439 |
while(count) |
|
1440 |
{ |
|
1441 |
TInt r = format.Next(count); |
|
1442 |
if(count != prevcount) |
|
1443 |
{ |
|
1444 |
test.Printf(_L(".")); |
|
1445 |
prevcount = count; |
|
1446 |
} |
|
1447 |
TESTERROR(r); |
|
1448 |
} |
|
1449 |
||
1450 |
format.Close(); |
|
1451 |
} |
|
1452 |
||
1453 |
/** Main function |
|
1454 |
||
1455 |
@return KErrNone if everything was ok, panics otherwise |
|
1456 |
*/ |
|
1457 |
TInt E32Main() |
|
1458 |
{ |
|
1459 |
RThread t; |
|
1460 |
gMainThreadId = t.Id(); |
|
1461 |
||
1462 |
CTrapCleanup* cleanup; |
|
1463 |
cleanup = CTrapCleanup::New(); |
|
1464 |
||
1465 |
__UHEAP_MARK; |
|
1466 |
test.Start(_L("Starting tests... T_FSCHED")); |
|
1467 |
parseCommandLine(); |
|
1468 |
||
1469 |
TInt r = TheFs.Connect(); |
|
1470 |
TESTERROR(r); |
|
1471 |
||
1472 |
TDriveInfo info; |
|
1473 |
TVolumeInfo volInfo; |
|
1474 |
r = TheFs.Drive(info, gDrive); |
|
1475 |
TESTERROR(r); |
|
1476 |
||
1477 |
if(info.iMediaAtt&KMediaAttVariableSize) |
|
1478 |
{ |
|
1479 |
test.Printf(_L("Tests skipped in RAM drive\n")); |
|
1480 |
goto out; |
|
1481 |
} |
|
1482 |
||
1483 |
r = TheFs.Volume(volInfo, gDrive); |
|
1484 |
if (r == KErrNotReady) |
|
1485 |
{ |
|
1486 |
if (info.iType == EMediaNotPresent) |
|
1487 |
test.Printf(_L("%c: Medium not present - cannot perform test.\n"), (TUint)gDrive + 'A'); |
|
1488 |
else |
|
1489 |
test.Printf(_L("medium found (type %d) but drive %c: not ready\nPrevious test may have hung; else, check hardware.\n"), (TInt)info.iType, (TUint)gDrive + 'A'); |
|
1490 |
} |
|
1491 |
else if (r == KErrCorrupt) |
|
1492 |
{ |
|
1493 |
test.Printf(_L("%c: Media corruption; previous test may have aborted; else, check hardware\n"), (TUint)gDrive + 'A'); |
|
1494 |
} |
|
1495 |
TESTERROR(r); |
|
200
73ea206103e6
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
1496 |
|
73ea206103e6
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
1497 |
if (!Is_Win32(TheFs, gDrive) && (volInfo.iDrive.iMediaAtt & KMediaAttFormattable)) |
0 | 1498 |
Format(gDrive); |
1499 |
||
1500 |
if(CheckForDiskSize()) |
|
1501 |
{ |
|
1502 |
DoTests(); |
|
1503 |
} |
|
1504 |
else |
|
1505 |
{ |
|
1506 |
test.Printf(_L("Skipping tests due to lack of space to perform them in this drive\n")); |
|
1507 |
} |
|
1508 |
out: |
|
1509 |
test.End(); |
|
1510 |
||
1511 |
TheFs.Close(); |
|
1512 |
test.Close(); |
|
1513 |
||
1514 |
__UHEAP_MARKEND; |
|
1515 |
delete cleanup; |
|
1516 |
return(KErrNone); |
|
1517 |
} |