sl@0
|
1 |
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Do benchmarking comparisons in asynchronous and synchronous modes.
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
//! @file f32test\concur\t_cfsbench.cpp
|
sl@0
|
19 |
|
sl@0
|
20 |
#include <f32file.h>
|
sl@0
|
21 |
#include <e32test.h>
|
sl@0
|
22 |
#include <f32dbg.h>
|
sl@0
|
23 |
#include "t_server.h"
|
sl@0
|
24 |
#include "t_tdebug.h"
|
sl@0
|
25 |
|
sl@0
|
26 |
// The following #defines are for using older (and less accurate) benchmark
|
sl@0
|
27 |
// timings. They use multiple threads to get the operations simultaneous
|
sl@0
|
28 |
// but this is inherrently inaccurate (it depends whether one of them starts
|
sl@0
|
29 |
// and/or ends before the other how accurate the timings are). If you leave
|
sl@0
|
30 |
// them both commented out then the tests will be done in a single thread
|
sl@0
|
31 |
// using asynchronous file operations, thus avoiding the problem.
|
sl@0
|
32 |
|
sl@0
|
33 |
// Uncomment the following if you want to test asynchronous file operations
|
sl@0
|
34 |
// using two threads rather than in a single thread.
|
sl@0
|
35 |
|
sl@0
|
36 |
// #define TEST_ASYNC_IN_THREAD
|
sl@0
|
37 |
|
sl@0
|
38 |
// Uncomment the following if you want to test using synchronous file
|
sl@0
|
39 |
// operations, using two threads to do both at once.
|
sl@0
|
40 |
|
sl@0
|
41 |
// #define TEST_SYNC_IN_THREAD
|
sl@0
|
42 |
|
sl@0
|
43 |
struct TStats
|
sl@0
|
44 |
//
|
sl@0
|
45 |
// Statistics -- size and time of operations.
|
sl@0
|
46 |
//
|
sl@0
|
47 |
{
|
sl@0
|
48 |
TInt64 iSize;
|
sl@0
|
49 |
TInt64 iTime;
|
sl@0
|
50 |
void Init() { iSize = 0; iTime = 0; }
|
sl@0
|
51 |
};
|
sl@0
|
52 |
|
sl@0
|
53 |
GLDEF_D RTest test(_L("T_CFSBENCH"));
|
sl@0
|
54 |
GLDEF_D RFs TheFs;
|
sl@0
|
55 |
|
sl@0
|
56 |
LOCAL_D TFullName gFsName;
|
sl@0
|
57 |
LOCAL_D TFullName gFsName1;
|
sl@0
|
58 |
LOCAL_D TFullName gFsName2;
|
sl@0
|
59 |
LOCAL_D TFullName gOldFsName;
|
sl@0
|
60 |
LOCAL_D TFullName gNewFsName;
|
sl@0
|
61 |
LOCAL_D TBool gNoMedia = ETrue;
|
sl@0
|
62 |
|
sl@0
|
63 |
#if defined(TEST_SYNC_IN_THREAD) || defined(TEST_ASYNC_IN_THREAD)
|
sl@0
|
64 |
LOCAL_D TInt gThreadNumber = 0;
|
sl@0
|
65 |
#endif
|
sl@0
|
66 |
|
sl@0
|
67 |
LOCAL_D RMutex gDataLock;
|
sl@0
|
68 |
LOCAL_D TStats gWrStats;
|
sl@0
|
69 |
LOCAL_D TStats gRdStats;
|
sl@0
|
70 |
|
sl@0
|
71 |
_LIT(KFsFile, "CFAFSDLY");
|
sl@0
|
72 |
_LIT(KFsName, "DelayFS");
|
sl@0
|
73 |
|
sl@0
|
74 |
LOCAL_D const TInt32 KSecond = 1000000;
|
sl@0
|
75 |
LOCAL_D const TInt32 KTimeBM = 20;
|
sl@0
|
76 |
LOCAL_D const TInt32 KNumBuf = 100;
|
sl@0
|
77 |
LOCAL_D const TInt32 KBufLen = 0x100;
|
sl@0
|
78 |
LOCAL_D const TInt32 KMaxThr = 10;
|
sl@0
|
79 |
LOCAL_D const TInt32 KMaxLag = 4;
|
sl@0
|
80 |
|
sl@0
|
81 |
LOCAL_D TBuf8<KBufLen> gBufferArr[KMaxThr][KNumBuf];
|
sl@0
|
82 |
LOCAL_D TRequestStatus gStatusArr[KMaxThr][KNumBuf];
|
sl@0
|
83 |
|
sl@0
|
84 |
LOCAL_C void AddStats(TStats& aStats, TInt64 aSize, TInt64 aTime)
|
sl@0
|
85 |
/// Add values to the statistics.
|
sl@0
|
86 |
{
|
sl@0
|
87 |
gDataLock.Wait();
|
sl@0
|
88 |
aStats.iSize += aSize;
|
sl@0
|
89 |
aStats.iTime += aTime;
|
sl@0
|
90 |
gDataLock.Signal();
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
LOCAL_C TInt GetSpeed(TStats& aStats)
|
sl@0
|
94 |
/// Calculate and return the data throughput from the statistics, rounded.
|
sl@0
|
95 |
{
|
sl@0
|
96 |
gDataLock.Wait();
|
sl@0
|
97 |
TInt speed = I64LOW((aStats.iSize + aStats.iTime/2) / aStats.iTime);
|
sl@0
|
98 |
gDataLock.Signal();
|
sl@0
|
99 |
return speed;
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
LOCAL_C TInt32 GetSpeed(TInt aOps, TInt64 aDtime)
|
sl@0
|
103 |
/// Calculate and return the throughput from the umber of blocks transferred
|
sl@0
|
104 |
/// and the elapsed time.
|
sl@0
|
105 |
{
|
sl@0
|
106 |
TInt64 dsize = MAKE_TINT64(0, aOps) * MAKE_TINT64(0, KBufLen) * MAKE_TINT64(0, KSecond);
|
sl@0
|
107 |
TInt32 speed = I64LOW((dsize + aDtime/2) / aDtime);
|
sl@0
|
108 |
return speed;
|
sl@0
|
109 |
}
|
sl@0
|
110 |
|
sl@0
|
111 |
LOCAL_C TBool DriveIsOK(TChar c)
|
sl@0
|
112 |
/// Test that a selected drive leter is OK to write files.
|
sl@0
|
113 |
{
|
sl@0
|
114 |
TInt r;
|
sl@0
|
115 |
TInt drv;
|
sl@0
|
116 |
r=TheFs.CharToDrive(c, drv);
|
sl@0
|
117 |
if (r != KErrNone)
|
sl@0
|
118 |
return EFalse;
|
sl@0
|
119 |
TDriveInfo info;
|
sl@0
|
120 |
r=TheFs.Drive(info,drv);
|
sl@0
|
121 |
test(r==KErrNone);
|
sl@0
|
122 |
return (info.iDriveAtt != 0 && !(info.iDriveAtt & KDriveAttRom));
|
sl@0
|
123 |
}
|
sl@0
|
124 |
|
sl@0
|
125 |
LOCAL_C TChar MountTestFileSystem(TInt aDrive)
|
sl@0
|
126 |
//
|
sl@0
|
127 |
// Mount a new CTestFileSystem on the drive under test
|
sl@0
|
128 |
//
|
sl@0
|
129 |
{
|
sl@0
|
130 |
TInt r;
|
sl@0
|
131 |
TBuf<64> b;
|
sl@0
|
132 |
TChar c;
|
sl@0
|
133 |
r=TheFs.DriveToChar(aDrive,c);
|
sl@0
|
134 |
test(r==KErrNone);
|
sl@0
|
135 |
b.Format(_L("Mount test file system on %c:"),(TUint)c);
|
sl@0
|
136 |
test.Next(b);
|
sl@0
|
137 |
|
sl@0
|
138 |
r=TheFs.AddFileSystem(KFsFile);
|
sl@0
|
139 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
140 |
|
sl@0
|
141 |
r=TheFs.FileSystemName(gOldFsName,aDrive);
|
sl@0
|
142 |
test(r==KErrNone || r==KErrNotFound);
|
sl@0
|
143 |
|
sl@0
|
144 |
TDriveInfo drv;
|
sl@0
|
145 |
r = TheFs.Drive(drv, aDrive);
|
sl@0
|
146 |
test(r == KErrNone);
|
sl@0
|
147 |
|
sl@0
|
148 |
gNoMedia = (drv.iType == EMediaUnknown || drv.iType == EMediaNotPresent);
|
sl@0
|
149 |
|
sl@0
|
150 |
if (gOldFsName.Length() > 0)
|
sl@0
|
151 |
{
|
sl@0
|
152 |
TTest::Printf(_L("Dismount %C: %S"), (TUint)c, &gOldFsName);
|
sl@0
|
153 |
r=TheFs.DismountFileSystem(gOldFsName,aDrive);
|
sl@0
|
154 |
test(r==KErrNone);
|
sl@0
|
155 |
}
|
sl@0
|
156 |
|
sl@0
|
157 |
r=TheFs.MountFileSystem(KFsName,aDrive);
|
sl@0
|
158 |
test(r==KErrNone);
|
sl@0
|
159 |
|
sl@0
|
160 |
r=TheFs.FileSystemName(gNewFsName,aDrive);
|
sl@0
|
161 |
test(r==KErrNone);
|
sl@0
|
162 |
test(gNewFsName.CompareF(KFsName)==0);
|
sl@0
|
163 |
return c;
|
sl@0
|
164 |
}
|
sl@0
|
165 |
|
sl@0
|
166 |
LOCAL_C void UnmountFileSystem(TInt aDrive)
|
sl@0
|
167 |
/// Unmount a test filesystem and mount the old one.
|
sl@0
|
168 |
{
|
sl@0
|
169 |
TChar c;
|
sl@0
|
170 |
TInt r=TheFs.DriveToChar(aDrive,c);
|
sl@0
|
171 |
test(r==KErrNone);
|
sl@0
|
172 |
r=TheFs.DismountFileSystem(gNewFsName,aDrive);
|
sl@0
|
173 |
test(r==KErrNone);
|
sl@0
|
174 |
// if there's no media present, don't try to mount it
|
sl@0
|
175 |
if (gNoMedia)
|
sl@0
|
176 |
{
|
sl@0
|
177 |
test.Printf(_L("No media on %C: so don't remount it"), (TUint)c);
|
sl@0
|
178 |
}
|
sl@0
|
179 |
else if (gOldFsName.Length() > 0)
|
sl@0
|
180 |
{
|
sl@0
|
181 |
test.Printf(_L("Mount %C: %S"), (TUint)c, &gOldFsName);
|
sl@0
|
182 |
r=TheFs.MountFileSystem(gOldFsName,aDrive);
|
sl@0
|
183 |
test(r==KErrNone);
|
sl@0
|
184 |
}
|
sl@0
|
185 |
if (r != KErrNone)
|
sl@0
|
186 |
test.Printf(_L("Error %d remounting %S on %C\n"), r, &gOldFsName, (TUint)c);
|
sl@0
|
187 |
}
|
sl@0
|
188 |
|
sl@0
|
189 |
LOCAL_C void RemountFileSystem(TInt aDrive, TBool aSync)
|
sl@0
|
190 |
/// Unmount and remount the file system on the specified drive in the
|
sl@0
|
191 |
/// selected mode.
|
sl@0
|
192 |
/// @param aDrive Drive number (EDriveC etc.).
|
sl@0
|
193 |
/// @param aSync Mount synchronous if true, asynchronous if not.
|
sl@0
|
194 |
{
|
sl@0
|
195 |
TChar c;
|
sl@0
|
196 |
TInt r=TheFs.DriveToChar(aDrive,c);
|
sl@0
|
197 |
r=TheFs.FileSystemName(gFsName, aDrive);
|
sl@0
|
198 |
test(r==KErrNone || r==KErrNotFound);
|
sl@0
|
199 |
|
sl@0
|
200 |
if (gFsName.Length() > 0)
|
sl@0
|
201 |
{
|
sl@0
|
202 |
r=TheFs.DismountFileSystem(gFsName, aDrive);
|
sl@0
|
203 |
if(r!=KErrNone)
|
sl@0
|
204 |
{
|
sl@0
|
205 |
test.Printf(_L("Error = %d"),r);
|
sl@0
|
206 |
test(EFalse);
|
sl@0
|
207 |
}
|
sl@0
|
208 |
}
|
sl@0
|
209 |
|
sl@0
|
210 |
TBufC<16> type = _L("asynchronous");
|
sl@0
|
211 |
if (aSync)
|
sl@0
|
212 |
type = _L("synchronous");
|
sl@0
|
213 |
test.Printf(_L("Mount filesystem %c: %-8S as %S\n"), (TUint)c, &gFsName, &type);
|
sl@0
|
214 |
|
sl@0
|
215 |
#ifdef __CONCURRENT_FILE_ACCESS__
|
sl@0
|
216 |
r=TheFs.MountFileSystem(gFsName, aDrive, aSync);
|
sl@0
|
217 |
#else
|
sl@0
|
218 |
r=TheFs.MountFileSystem(gFsName, aDrive);
|
sl@0
|
219 |
#endif
|
sl@0
|
220 |
|
sl@0
|
221 |
test(r==KErrNone);
|
sl@0
|
222 |
}
|
sl@0
|
223 |
|
sl@0
|
224 |
enum TOper
|
sl@0
|
225 |
{
|
sl@0
|
226 |
ERead,
|
sl@0
|
227 |
EWrite
|
sl@0
|
228 |
};
|
sl@0
|
229 |
|
sl@0
|
230 |
// ---------------------------------------------------------------------------
|
sl@0
|
231 |
|
sl@0
|
232 |
#if defined(TEST_SYNC_IN_THREAD)
|
sl@0
|
233 |
|
sl@0
|
234 |
LOCAL_C TInt testSyncAccess(TAny* aData)
|
sl@0
|
235 |
///
|
sl@0
|
236 |
/// Test read file handling.
|
sl@0
|
237 |
///
|
sl@0
|
238 |
/// @param aData pointer to the thread data area
|
sl@0
|
239 |
{
|
sl@0
|
240 |
TThreadData& data = *(TThreadData*)aData;
|
sl@0
|
241 |
TFileName fileName = data.iFile;
|
sl@0
|
242 |
TBool dowrite = (data.iData != NULL);
|
sl@0
|
243 |
|
sl@0
|
244 |
RFs myFs;
|
sl@0
|
245 |
TInt r = myFs.Connect();
|
sl@0
|
246 |
TEST(r==KErrNone);
|
sl@0
|
247 |
|
sl@0
|
248 |
r = myFs.SetSessionPath(gSessionPath);
|
sl@0
|
249 |
if (r != KErrNone)
|
sl@0
|
250 |
TTest::Fail(HERE, _L("SetSessionPath returned %d"), r);
|
sl@0
|
251 |
|
sl@0
|
252 |
TVolumeInfo vol;
|
sl@0
|
253 |
TInt drv;
|
sl@0
|
254 |
r = myFs.CharToDrive(fileName[0], drv);
|
sl@0
|
255 |
if (r != KErrNone)
|
sl@0
|
256 |
TTest::Fail(HERE, _L("CharToDrive(%c) returned %d"), fileName[0], r);
|
sl@0
|
257 |
r = myFs.Volume(vol, drv);
|
sl@0
|
258 |
if (r != KErrNone)
|
sl@0
|
259 |
TTest::Fail(HERE, _L("Volume() returned %d"), r);
|
sl@0
|
260 |
|
sl@0
|
261 |
TInt maxwrite = TInt(vol.iFree / 2 - KBufLen);
|
sl@0
|
262 |
if (maxwrite < KBufLen*2)
|
sl@0
|
263 |
TTest::Fail(HERE, _L("Not enough space to do test, only %d KB available"),
|
sl@0
|
264 |
TInt(vol.iFree/1024));
|
sl@0
|
265 |
|
sl@0
|
266 |
RFile f;
|
sl@0
|
267 |
RTimer timer;
|
sl@0
|
268 |
TTime startTime;
|
sl@0
|
269 |
TTime endTime;
|
sl@0
|
270 |
TTimeIntervalMicroSeconds timeTaken;
|
sl@0
|
271 |
|
sl@0
|
272 |
TBuf8<KBufLen> buff;
|
sl@0
|
273 |
TRequestStatus tstat;
|
sl@0
|
274 |
|
sl@0
|
275 |
TInt wrnum = 0;
|
sl@0
|
276 |
TInt rdnum = 0;
|
sl@0
|
277 |
|
sl@0
|
278 |
timer.CreateLocal();
|
sl@0
|
279 |
|
sl@0
|
280 |
if (dowrite)
|
sl@0
|
281 |
{
|
sl@0
|
282 |
// write tests
|
sl@0
|
283 |
|
sl@0
|
284 |
r = f.Replace(myFs, fileName, EFileStreamText | EFileWrite);
|
sl@0
|
285 |
TEST(r==KErrNone);
|
sl@0
|
286 |
|
sl@0
|
287 |
// wait for both tasks to have a chance to complete opening the files
|
sl@0
|
288 |
User::After(1000);
|
sl@0
|
289 |
|
sl@0
|
290 |
buff.Fill('_', KBufLen);
|
sl@0
|
291 |
|
sl@0
|
292 |
timer.After(tstat, KTimeBM * KSecond);
|
sl@0
|
293 |
|
sl@0
|
294 |
startTime.HomeTime();
|
sl@0
|
295 |
|
sl@0
|
296 |
while (tstat == KRequestPending)
|
sl@0
|
297 |
{
|
sl@0
|
298 |
TInt pos = (wrnum * KBufLen) % maxwrite;
|
sl@0
|
299 |
r = f.Write(pos, buff);
|
sl@0
|
300 |
TEST(r==KErrNone);
|
sl@0
|
301 |
++wrnum;
|
sl@0
|
302 |
}
|
sl@0
|
303 |
|
sl@0
|
304 |
endTime.HomeTime();
|
sl@0
|
305 |
timeTaken=endTime.MicroSecondsFrom(startTime);
|
sl@0
|
306 |
|
sl@0
|
307 |
TInt64 dtime = timeTaken.Int64();
|
sl@0
|
308 |
TInt64 dsize = wrnum * KBufLen * TInt64(KSecond);
|
sl@0
|
309 |
TInt32 speed = TInt32((dsize + dtime/2) / dtime);
|
sl@0
|
310 |
AddStats(gWrStats, dsize, dtime);
|
sl@0
|
311 |
|
sl@0
|
312 |
TTest::Printf(_L("%8d writes in %6d mS = %8d bytes per second\n"),
|
sl@0
|
313 |
wrnum, TInt32(dtime)/1000, speed);
|
sl@0
|
314 |
|
sl@0
|
315 |
timer.Cancel();
|
sl@0
|
316 |
f.Close();
|
sl@0
|
317 |
}
|
sl@0
|
318 |
else
|
sl@0
|
319 |
{
|
sl@0
|
320 |
// read tests
|
sl@0
|
321 |
|
sl@0
|
322 |
r = f.Open(myFs, fileName, EFileStreamText);
|
sl@0
|
323 |
TEST(r==KErrNone);
|
sl@0
|
324 |
|
sl@0
|
325 |
// wait for both tasks to have a chance to complete opening the files
|
sl@0
|
326 |
User::After(1000);
|
sl@0
|
327 |
|
sl@0
|
328 |
timer.After(tstat, KTimeBM * KSecond);
|
sl@0
|
329 |
|
sl@0
|
330 |
startTime.HomeTime();
|
sl@0
|
331 |
|
sl@0
|
332 |
while (tstat == KRequestPending)
|
sl@0
|
333 |
{
|
sl@0
|
334 |
TInt pos = (rdnum * KBufLen) % maxwrite;
|
sl@0
|
335 |
r = f.Read(pos, buff, KBufLen);
|
sl@0
|
336 |
TEST(r==KErrNone);
|
sl@0
|
337 |
++rdnum;
|
sl@0
|
338 |
}
|
sl@0
|
339 |
|
sl@0
|
340 |
endTime.HomeTime();
|
sl@0
|
341 |
timeTaken=endTime.MicroSecondsFrom(startTime);
|
sl@0
|
342 |
|
sl@0
|
343 |
TInt64 dtime = timeTaken.Int64();
|
sl@0
|
344 |
TInt64 dsize = rdnum * KBufLen * TInt64(KSecond);
|
sl@0
|
345 |
TInt32 speed = TInt32((dsize + dtime/2) / dtime);
|
sl@0
|
346 |
AddStats(gRdStats, dsize, dtime);
|
sl@0
|
347 |
|
sl@0
|
348 |
// wait to allow the dust to settle
|
sl@0
|
349 |
User::After(KSecond);
|
sl@0
|
350 |
|
sl@0
|
351 |
TTest::Printf(_L("%8d reads in %6d mS = %8d bytes per second\n"),
|
sl@0
|
352 |
rdnum, TInt32(dtime)/1000, speed);
|
sl@0
|
353 |
|
sl@0
|
354 |
timer.Cancel();
|
sl@0
|
355 |
timer.Close();
|
sl@0
|
356 |
f.Close();
|
sl@0
|
357 |
|
sl@0
|
358 |
// delete file after reading it
|
sl@0
|
359 |
myFs.Delete(fileName);
|
sl@0
|
360 |
}
|
sl@0
|
361 |
|
sl@0
|
362 |
myFs.Close();
|
sl@0
|
363 |
return r;
|
sl@0
|
364 |
}
|
sl@0
|
365 |
|
sl@0
|
366 |
#endif
|
sl@0
|
367 |
|
sl@0
|
368 |
// ---------------------------------------------------------------------------
|
sl@0
|
369 |
|
sl@0
|
370 |
#if defined(TEST_ASYNC_IN_THREAD)
|
sl@0
|
371 |
|
sl@0
|
372 |
LOCAL_C TInt testAsyncAccess(TAny* aData)
|
sl@0
|
373 |
//
|
sl@0
|
374 |
/// Test read file handling.
|
sl@0
|
375 |
///
|
sl@0
|
376 |
/// @param aData pointer to the thread data area
|
sl@0
|
377 |
{
|
sl@0
|
378 |
TThreadData& data = *(TThreadData*)aData;
|
sl@0
|
379 |
TFileName fileName = data.iFile;
|
sl@0
|
380 |
TBool dowrite = (data.iData != NULL);
|
sl@0
|
381 |
TBuf8<KBufLen>* buffer = gBufferArr[data.iNum];
|
sl@0
|
382 |
TRequestStatus* status = gStatusArr[data.iNum];
|
sl@0
|
383 |
|
sl@0
|
384 |
RFs myFs;
|
sl@0
|
385 |
TInt r = myFs.Connect();
|
sl@0
|
386 |
TEST(r==KErrNone);
|
sl@0
|
387 |
|
sl@0
|
388 |
r = myFs.SetSessionPath(gSessionPath);
|
sl@0
|
389 |
if (r != KErrNone)
|
sl@0
|
390 |
TTest::Fail(HERE, _L("SetSessionPath returned %d"), r);
|
sl@0
|
391 |
|
sl@0
|
392 |
TVolumeInfo vol;
|
sl@0
|
393 |
TInt drv;
|
sl@0
|
394 |
r = myFs.CharToDrive(fileName[0], drv);
|
sl@0
|
395 |
if (r != KErrNone)
|
sl@0
|
396 |
TTest::Fail(HERE, _L("CharToDrive(%c) returned %d"), fileName[0], r);
|
sl@0
|
397 |
r = myFs.Volume(vol, drv);
|
sl@0
|
398 |
if (r != KErrNone)
|
sl@0
|
399 |
TTest::Fail(HERE, _L("Volume() returned %d"), r);
|
sl@0
|
400 |
|
sl@0
|
401 |
TInt64 maxwrite = vol.iFree / 2 - KBufLen;
|
sl@0
|
402 |
if (maxwrite < KBufLen*2)
|
sl@0
|
403 |
TTest::Fail(HERE, _L("Not enough space to do test, only %d KB available"),
|
sl@0
|
404 |
TInt(vol.iFree/1024));
|
sl@0
|
405 |
|
sl@0
|
406 |
RFile f;
|
sl@0
|
407 |
RTimer timer;
|
sl@0
|
408 |
TRequestStatus tstat;
|
sl@0
|
409 |
TTime startTime;
|
sl@0
|
410 |
TTime endTime;
|
sl@0
|
411 |
TTimeIntervalMicroSeconds timeTaken;
|
sl@0
|
412 |
|
sl@0
|
413 |
TInt wrnum = 0;
|
sl@0
|
414 |
TInt rdnum = 0;
|
sl@0
|
415 |
TInt opnum = 0;
|
sl@0
|
416 |
TInt opfin = 0;
|
sl@0
|
417 |
TInt i;
|
sl@0
|
418 |
|
sl@0
|
419 |
timer.CreateLocal();
|
sl@0
|
420 |
|
sl@0
|
421 |
if (dowrite)
|
sl@0
|
422 |
{
|
sl@0
|
423 |
r = f.Replace(myFs, fileName, EFileStreamText | EFileWrite);
|
sl@0
|
424 |
TEST(r==KErrNone);
|
sl@0
|
425 |
|
sl@0
|
426 |
// wait for both tasks to have a chance to complete opening the files
|
sl@0
|
427 |
User::After(1000);
|
sl@0
|
428 |
|
sl@0
|
429 |
for (i = 0; i < KNumBuf; i++)
|
sl@0
|
430 |
buffer[i].Fill('_', KBufLen);
|
sl@0
|
431 |
|
sl@0
|
432 |
timer.After(tstat, KTimeBM * KSecond);
|
sl@0
|
433 |
|
sl@0
|
434 |
startTime.HomeTime();
|
sl@0
|
435 |
|
sl@0
|
436 |
while (tstat == KRequestPending)
|
sl@0
|
437 |
{
|
sl@0
|
438 |
TInt pos = TInt((wrnum * KBufLen) % maxwrite);
|
sl@0
|
439 |
TInt bnum = opnum++ % KNumBuf;
|
sl@0
|
440 |
f.Write(pos, buffer[bnum], status[bnum]);
|
sl@0
|
441 |
if (opnum - opfin > KMaxLag)
|
sl@0
|
442 |
{
|
sl@0
|
443 |
while (status[opfin % KNumBuf] == KRequestPending)
|
sl@0
|
444 |
User::WaitForRequest(status[opfin % KNumBuf]);
|
sl@0
|
445 |
opfin++;
|
sl@0
|
446 |
}
|
sl@0
|
447 |
++wrnum;
|
sl@0
|
448 |
}
|
sl@0
|
449 |
|
sl@0
|
450 |
while (opfin < opnum)
|
sl@0
|
451 |
{
|
sl@0
|
452 |
while (status[opfin % KNumBuf] == KRequestPending)
|
sl@0
|
453 |
User::WaitForRequest(status[opfin % KNumBuf]);
|
sl@0
|
454 |
opfin++;
|
sl@0
|
455 |
}
|
sl@0
|
456 |
|
sl@0
|
457 |
endTime.HomeTime();
|
sl@0
|
458 |
TTimeIntervalMicroSeconds timeTaken=endTime.MicroSecondsFrom(startTime);
|
sl@0
|
459 |
|
sl@0
|
460 |
TInt64 dtime = timeTaken.Int64();
|
sl@0
|
461 |
TInt64 dsize = wrnum * KBufLen * TInt64(KSecond);
|
sl@0
|
462 |
TInt32 speed = TInt32((dsize + dtime/2) / dtime);
|
sl@0
|
463 |
AddStats(gWrStats, dsize, dtime);
|
sl@0
|
464 |
|
sl@0
|
465 |
TTest::Printf(_L("%8d writes in %6d mS = %8d bytes per second\n"),
|
sl@0
|
466 |
wrnum, TInt32(dtime)/1000, speed);
|
sl@0
|
467 |
}
|
sl@0
|
468 |
else
|
sl@0
|
469 |
{
|
sl@0
|
470 |
r = f.Open(myFs, fileName, EFileStreamText);
|
sl@0
|
471 |
TEST(r==KErrNone);
|
sl@0
|
472 |
|
sl@0
|
473 |
timer.After(tstat, KTimeBM * KSecond);
|
sl@0
|
474 |
|
sl@0
|
475 |
startTime.HomeTime();
|
sl@0
|
476 |
|
sl@0
|
477 |
while (tstat == KRequestPending)
|
sl@0
|
478 |
{
|
sl@0
|
479 |
TInt pos = TInt((rdnum * KBufLen) % maxwrite);
|
sl@0
|
480 |
TInt bnum = opnum++ % KNumBuf;
|
sl@0
|
481 |
f.Read(pos, buffer[bnum], status[bnum]);
|
sl@0
|
482 |
if (opnum - opfin > KMaxLag)
|
sl@0
|
483 |
{
|
sl@0
|
484 |
User::WaitForRequest(status[opfin++ % KNumBuf]);
|
sl@0
|
485 |
}
|
sl@0
|
486 |
++rdnum;
|
sl@0
|
487 |
}
|
sl@0
|
488 |
|
sl@0
|
489 |
while (opfin < opnum)
|
sl@0
|
490 |
{
|
sl@0
|
491 |
if (status[opfin % KNumBuf] == KRequestPending)
|
sl@0
|
492 |
User::WaitForRequest(status[opfin % KNumBuf]);
|
sl@0
|
493 |
opfin++;
|
sl@0
|
494 |
}
|
sl@0
|
495 |
|
sl@0
|
496 |
endTime.HomeTime();
|
sl@0
|
497 |
timeTaken=endTime.MicroSecondsFrom(startTime);
|
sl@0
|
498 |
TInt64 dtime = timeTaken.Int64();
|
sl@0
|
499 |
TInt64 dsize = rdnum * KBufLen * TInt64(KSecond);
|
sl@0
|
500 |
TInt32 speed = TInt32((dsize + dtime/2) / dtime);
|
sl@0
|
501 |
AddStats(gRdStats, dsize, dtime);
|
sl@0
|
502 |
|
sl@0
|
503 |
// wait to allow the dust to settle
|
sl@0
|
504 |
User::After(KSecond);
|
sl@0
|
505 |
|
sl@0
|
506 |
TTest::Printf(_L("%8d reads in %6d mS = %8d bytes per second\n"),
|
sl@0
|
507 |
rdnum, TInt32(dtime)/1000, speed);
|
sl@0
|
508 |
|
sl@0
|
509 |
myFs.Delete(fileName);
|
sl@0
|
510 |
}
|
sl@0
|
511 |
|
sl@0
|
512 |
timer.Cancel();
|
sl@0
|
513 |
timer.Close();
|
sl@0
|
514 |
f.Close();
|
sl@0
|
515 |
myFs.Close();
|
sl@0
|
516 |
return r;
|
sl@0
|
517 |
}
|
sl@0
|
518 |
|
sl@0
|
519 |
#endif
|
sl@0
|
520 |
|
sl@0
|
521 |
// ---------------------------------------------------------------------------
|
sl@0
|
522 |
|
sl@0
|
523 |
class TFileOps
|
sl@0
|
524 |
/// Do operations on a file.
|
sl@0
|
525 |
{
|
sl@0
|
526 |
public:
|
sl@0
|
527 |
TFileOps();
|
sl@0
|
528 |
TInt Open(TChar dr, TInt n);
|
sl@0
|
529 |
TInt Close();
|
sl@0
|
530 |
TInt Reset();
|
sl@0
|
531 |
TInt Erase();
|
sl@0
|
532 |
TInt Write();
|
sl@0
|
533 |
TInt Read();
|
sl@0
|
534 |
TInt End();
|
sl@0
|
535 |
public:
|
sl@0
|
536 |
TFileName iName;
|
sl@0
|
537 |
RFile iF;
|
sl@0
|
538 |
TBuf8<KBufLen> iBuffer[KMaxLag];
|
sl@0
|
539 |
TRequestStatus iStatus[KMaxLag];
|
sl@0
|
540 |
TInt iPtr;
|
sl@0
|
541 |
TInt iNum;
|
sl@0
|
542 |
TInt iOps;
|
sl@0
|
543 |
TInt iMax;
|
sl@0
|
544 |
TBool iOpen;
|
sl@0
|
545 |
};
|
sl@0
|
546 |
|
sl@0
|
547 |
TFileOps::TFileOps() : iPtr(0), iNum(0), iOps(0), iMax(0), iOpen(EFalse)
|
sl@0
|
548 |
{
|
sl@0
|
549 |
for (TInt i = 0; i < KMaxLag; i++)
|
sl@0
|
550 |
{
|
sl@0
|
551 |
iStatus[i] = KErrNone;
|
sl@0
|
552 |
iBuffer[i].Fill(TChar('_'), KBufLen);
|
sl@0
|
553 |
}
|
sl@0
|
554 |
}
|
sl@0
|
555 |
|
sl@0
|
556 |
TInt TFileOps::Open(TChar aDrvCh, TInt aNum)
|
sl@0
|
557 |
/// Open the file for testing, give error if there is not enough space for it.
|
sl@0
|
558 |
/// @param aDrvCh Drive letter.
|
sl@0
|
559 |
/// @param aNum File number suffix.
|
sl@0
|
560 |
{
|
sl@0
|
561 |
TVolumeInfo vol;
|
sl@0
|
562 |
TInt drv;
|
sl@0
|
563 |
TInt r = TheFs.CharToDrive(aDrvCh, drv);
|
sl@0
|
564 |
if (r != KErrNone)
|
sl@0
|
565 |
TTest::Fail(HERE, _L("CharToDrive(%c) returned %d"), (TUint)aDrvCh, r);
|
sl@0
|
566 |
r = TheFs.Volume(vol, drv);
|
sl@0
|
567 |
if (r != KErrNone)
|
sl@0
|
568 |
TTest::Fail(HERE, _L("Volume(%c:) returned %d"), (TUint)aDrvCh, r);
|
sl@0
|
569 |
|
sl@0
|
570 |
iMax = I64LOW(vol.iFree / MAKE_TINT64(0,KBufLen)) / 2 - 1;
|
sl@0
|
571 |
if (iMax < 10)
|
sl@0
|
572 |
TTest::Fail(HERE, _L("Not enough space to do test, only %d KB available"),
|
sl@0
|
573 |
I64LOW(vol.iFree/1024));
|
sl@0
|
574 |
|
sl@0
|
575 |
Reset();
|
sl@0
|
576 |
iName.Format(_L("%c:\\TEST_%d"), (TUint)aDrvCh, aNum);
|
sl@0
|
577 |
r = iF.Replace(TheFs, iName, EFileStreamText | EFileWrite);
|
sl@0
|
578 |
if (r == KErrNone)
|
sl@0
|
579 |
iOpen = ETrue;
|
sl@0
|
580 |
return r;
|
sl@0
|
581 |
}
|
sl@0
|
582 |
|
sl@0
|
583 |
TInt TFileOps::Close()
|
sl@0
|
584 |
/// Close and delete the file, returning the number of operations done.
|
sl@0
|
585 |
{
|
sl@0
|
586 |
if (!iOpen)
|
sl@0
|
587 |
return 0;
|
sl@0
|
588 |
iF.Close();
|
sl@0
|
589 |
TheFs.Delete(iName);
|
sl@0
|
590 |
iOpen = EFalse;
|
sl@0
|
591 |
return iNum;
|
sl@0
|
592 |
}
|
sl@0
|
593 |
|
sl@0
|
594 |
TInt TFileOps::Reset()
|
sl@0
|
595 |
/// Reset all of the counts.
|
sl@0
|
596 |
{
|
sl@0
|
597 |
iPtr = 0;
|
sl@0
|
598 |
iNum = 0;
|
sl@0
|
599 |
iOps = 0;
|
sl@0
|
600 |
return 0;
|
sl@0
|
601 |
}
|
sl@0
|
602 |
|
sl@0
|
603 |
TInt TFileOps::Write()
|
sl@0
|
604 |
/// If there is a free buffer available, start a write.
|
sl@0
|
605 |
{
|
sl@0
|
606 |
if (!iOpen)
|
sl@0
|
607 |
return 0;
|
sl@0
|
608 |
while (iNum < iOps && iStatus[iNum%KMaxLag] != KRequestPending)
|
sl@0
|
609 |
iNum++;
|
sl@0
|
610 |
if (iOps < KMaxLag || iStatus[iPtr] != KRequestPending)
|
sl@0
|
611 |
{
|
sl@0
|
612 |
TInt pos = iNum%iMax * KBufLen;
|
sl@0
|
613 |
iF.Write(pos, iBuffer[iPtr], iStatus[iPtr]);
|
sl@0
|
614 |
iOps++;
|
sl@0
|
615 |
iPtr++;
|
sl@0
|
616 |
iPtr %= KMaxLag;
|
sl@0
|
617 |
return 1;
|
sl@0
|
618 |
}
|
sl@0
|
619 |
return 0;
|
sl@0
|
620 |
}
|
sl@0
|
621 |
|
sl@0
|
622 |
TInt TFileOps::Read()
|
sl@0
|
623 |
/// If there is a free buffer available, start a read.
|
sl@0
|
624 |
{
|
sl@0
|
625 |
if (!iOpen)
|
sl@0
|
626 |
return 0;
|
sl@0
|
627 |
while (iNum < iOps && iStatus[iNum%KMaxLag] != KRequestPending)
|
sl@0
|
628 |
iNum++;
|
sl@0
|
629 |
if (iOps < KMaxLag || iStatus[iPtr] != KRequestPending)
|
sl@0
|
630 |
{
|
sl@0
|
631 |
TInt pos = iNum%iMax * KBufLen;
|
sl@0
|
632 |
iF.Read(pos, iBuffer[iPtr], iStatus[iPtr]);
|
sl@0
|
633 |
iOps++;
|
sl@0
|
634 |
iPtr++;
|
sl@0
|
635 |
iPtr %= KMaxLag;
|
sl@0
|
636 |
return 1;
|
sl@0
|
637 |
}
|
sl@0
|
638 |
return 0;
|
sl@0
|
639 |
}
|
sl@0
|
640 |
|
sl@0
|
641 |
TInt TFileOps::End()
|
sl@0
|
642 |
/// Wait until all outstanding operations have ended, then return the number.
|
sl@0
|
643 |
{
|
sl@0
|
644 |
if (!iOpen)
|
sl@0
|
645 |
return 0;
|
sl@0
|
646 |
while (iNum < iOps)
|
sl@0
|
647 |
{
|
sl@0
|
648 |
if (iStatus[iNum%KMaxLag] == KRequestPending)
|
sl@0
|
649 |
User::WaitForRequest(iStatus[iNum%KMaxLag]);
|
sl@0
|
650 |
else
|
sl@0
|
651 |
iNum++;
|
sl@0
|
652 |
}
|
sl@0
|
653 |
if (iOps < iMax)
|
sl@0
|
654 |
iMax = iOps;
|
sl@0
|
655 |
return iNum;
|
sl@0
|
656 |
}
|
sl@0
|
657 |
|
sl@0
|
658 |
LOCAL_C TInt testAsyncAccess(TChar dc1, TChar dc2)
|
sl@0
|
659 |
//
|
sl@0
|
660 |
// Test one drive against the other.
|
sl@0
|
661 |
//
|
sl@0
|
662 |
{
|
sl@0
|
663 |
TFileOps f1;
|
sl@0
|
664 |
TFileOps f2;
|
sl@0
|
665 |
|
sl@0
|
666 |
f1.Open(dc1, 1);
|
sl@0
|
667 |
if (dc1 != dc2)
|
sl@0
|
668 |
f2.Open(dc2, 2);
|
sl@0
|
669 |
|
sl@0
|
670 |
TInt op1 = 0;
|
sl@0
|
671 |
TInt op2 = 0;
|
sl@0
|
672 |
RTimer timer;
|
sl@0
|
673 |
TRequestStatus tstat;
|
sl@0
|
674 |
TTime startTime;
|
sl@0
|
675 |
TTime endTime;
|
sl@0
|
676 |
TTimeIntervalMicroSeconds timeTaken;
|
sl@0
|
677 |
|
sl@0
|
678 |
timer.CreateLocal();
|
sl@0
|
679 |
|
sl@0
|
680 |
timer.After(tstat, KTimeBM * KSecond);
|
sl@0
|
681 |
|
sl@0
|
682 |
startTime.HomeTime();
|
sl@0
|
683 |
|
sl@0
|
684 |
while (tstat == KRequestPending)
|
sl@0
|
685 |
{
|
sl@0
|
686 |
TInt num = f1.Write();
|
sl@0
|
687 |
num += f2.Write();
|
sl@0
|
688 |
if (num == 0)
|
sl@0
|
689 |
User::WaitForAnyRequest();
|
sl@0
|
690 |
}
|
sl@0
|
691 |
|
sl@0
|
692 |
op1 = f1.End();
|
sl@0
|
693 |
op2 = f2.End();
|
sl@0
|
694 |
|
sl@0
|
695 |
endTime.HomeTime();
|
sl@0
|
696 |
timeTaken=endTime.MicroSecondsFrom(startTime);
|
sl@0
|
697 |
|
sl@0
|
698 |
TInt64 dtime = timeTaken.Int64();
|
sl@0
|
699 |
|
sl@0
|
700 |
TTest::Printf(_L("%c: %8d writes in %6d mS = %8d bytes per second\n"),
|
sl@0
|
701 |
(TUint)dc1, op1, I64LOW(dtime)/1000, GetSpeed(op1, dtime));
|
sl@0
|
702 |
|
sl@0
|
703 |
if (dc1 != dc2)
|
sl@0
|
704 |
TTest::Printf(_L("%c: %8d writes in %6d mS = %8d bytes per second\n"),
|
sl@0
|
705 |
(TUint)dc2, op2, I64LOW(dtime)/1000, GetSpeed(op2, dtime));
|
sl@0
|
706 |
|
sl@0
|
707 |
AddStats(gWrStats, MAKE_TINT64(0, op1 + op2) * MAKE_TINT64(0, KBufLen) * MAKE_TINT64(0, KSecond), dtime);
|
sl@0
|
708 |
|
sl@0
|
709 |
// now the reads!
|
sl@0
|
710 |
|
sl@0
|
711 |
f1.Reset();
|
sl@0
|
712 |
f2.Reset();
|
sl@0
|
713 |
|
sl@0
|
714 |
timer.After(tstat, KTimeBM * KSecond);
|
sl@0
|
715 |
|
sl@0
|
716 |
startTime.HomeTime();
|
sl@0
|
717 |
|
sl@0
|
718 |
while (tstat == KRequestPending)
|
sl@0
|
719 |
{
|
sl@0
|
720 |
f1.Read();
|
sl@0
|
721 |
f2.Read();
|
sl@0
|
722 |
User::WaitForAnyRequest();
|
sl@0
|
723 |
}
|
sl@0
|
724 |
|
sl@0
|
725 |
op1 = f1.End();
|
sl@0
|
726 |
op2 = f2.End();
|
sl@0
|
727 |
|
sl@0
|
728 |
endTime.HomeTime();
|
sl@0
|
729 |
timeTaken=endTime.MicroSecondsFrom(startTime);
|
sl@0
|
730 |
|
sl@0
|
731 |
dtime = timeTaken.Int64();
|
sl@0
|
732 |
|
sl@0
|
733 |
TTest::Printf(_L("%c: %8d reads in %6d mS = %8d bytes per second\n"),
|
sl@0
|
734 |
(TUint)dc1, op1, I64LOW(dtime)/1000, GetSpeed(op1, dtime));
|
sl@0
|
735 |
|
sl@0
|
736 |
if (dc1 != dc2)
|
sl@0
|
737 |
TTest::Printf(_L("%c: %8d reads in %6d mS = %8d bytes per second\n"),
|
sl@0
|
738 |
(TUint)dc2, op2, I64LOW(dtime)/1000, GetSpeed(op2, dtime));
|
sl@0
|
739 |
|
sl@0
|
740 |
AddStats(gRdStats, MAKE_TINT64(0, op1 + op2) * MAKE_TINT64(0, KBufLen) * MAKE_TINT64(0, KSecond), dtime);
|
sl@0
|
741 |
|
sl@0
|
742 |
test.Printf(_L("\n"));
|
sl@0
|
743 |
test.Printf(_L("average write throughput = %d bytes/sec\n"), GetSpeed(gWrStats));
|
sl@0
|
744 |
test.Printf(_L("average read throughput = %d bytes/sec\n"), GetSpeed(gRdStats));
|
sl@0
|
745 |
test.Printf(_L("\n"));
|
sl@0
|
746 |
gWrStats.Init();
|
sl@0
|
747 |
gRdStats.Init();
|
sl@0
|
748 |
|
sl@0
|
749 |
timer.Cancel();
|
sl@0
|
750 |
timer.Close();
|
sl@0
|
751 |
f1.Close();
|
sl@0
|
752 |
f2.Close();
|
sl@0
|
753 |
// delay for a second to allow the close to complete before dismounting.
|
sl@0
|
754 |
User::After(1000000);
|
sl@0
|
755 |
return KErrNone;
|
sl@0
|
756 |
}
|
sl@0
|
757 |
|
sl@0
|
758 |
#if defined(TEST_SYNC_IN_THREAD) || defined(TEST_ASYNC_IN_THREAD)
|
sl@0
|
759 |
|
sl@0
|
760 |
LOCAL_C TInt CreateThread(TThreadFunction aFunc, TChar c, TOper aOper)
|
sl@0
|
761 |
/// Create a thread to do the appropriate operation on a drive.
|
sl@0
|
762 |
{
|
sl@0
|
763 |
TBuf<2> drive(_L("?"));
|
sl@0
|
764 |
TBuf<64> name;
|
sl@0
|
765 |
drive[0] = TText(c);
|
sl@0
|
766 |
drive.UpperCase();
|
sl@0
|
767 |
TThreadData& d = TTest::Data(gThreadNumber);
|
sl@0
|
768 |
d.iFile.Format(_L("%S:\\TEST%d.FILE"), &drive, gThreadNumber);
|
sl@0
|
769 |
d.iData = (aOper == EWrite ? &aOper : NULL);
|
sl@0
|
770 |
name.Format(_L("Test_%S_%d"), &drive, gThreadNumber);
|
sl@0
|
771 |
TInt r = TTest::Create(gThreadNumber, aFunc, name);
|
sl@0
|
772 |
++gThreadNumber;
|
sl@0
|
773 |
return r;
|
sl@0
|
774 |
}
|
sl@0
|
775 |
|
sl@0
|
776 |
LOCAL_C TInt RunThreads(TThreadFunction aFunc, TChar aDrive1, TChar aDrive2, TOper aOper)
|
sl@0
|
777 |
/// Run threads to test one drive against the other at the same time.
|
sl@0
|
778 |
/// The thread will report any error and return it as a value, the program will
|
sl@0
|
779 |
/// exit at a higher level after cleaning up.
|
sl@0
|
780 |
{
|
sl@0
|
781 |
TInt r;
|
sl@0
|
782 |
gThreadNumber = 0;
|
sl@0
|
783 |
if ((r = CreateThread(aFunc, aDrive1, aOper)) != KErrNone) return r;
|
sl@0
|
784 |
if ((r = CreateThread(aFunc, aDrive2, aOper)) != KErrNone) return r;
|
sl@0
|
785 |
TTest::Printf();
|
sl@0
|
786 |
r = TTest::Run();
|
sl@0
|
787 |
TTest::Printf();
|
sl@0
|
788 |
return r;
|
sl@0
|
789 |
}
|
sl@0
|
790 |
|
sl@0
|
791 |
LOCAL_C TInt testThreads(TThreadFunction aFunc, TChar c, TChar d)
|
sl@0
|
792 |
/// Run threads testing read and write of the drives both ways round.
|
sl@0
|
793 |
/// The thread will report any error and return it as a value, the program will
|
sl@0
|
794 |
/// exit at a higher level after cleaning up.
|
sl@0
|
795 |
{
|
sl@0
|
796 |
TInt r;
|
sl@0
|
797 |
if ((r = RunThreads(aFunc, c, d, EWrite)) != KErrNone) return r;
|
sl@0
|
798 |
if ((r = RunThreads(aFunc, c, d, ERead)) != KErrNone) return r;
|
sl@0
|
799 |
if ((r = RunThreads(aFunc, d, c, EWrite)) != KErrNone) return r;
|
sl@0
|
800 |
if ((r = RunThreads(aFunc, d, c, ERead)) != KErrNone) return r;
|
sl@0
|
801 |
// display totals;
|
sl@0
|
802 |
test.Printf(_L("average write throughput = %d bytes/sec\n"), GetSpeed(gWrStats));
|
sl@0
|
803 |
test.Printf(_L("average read throughput = %d bytes/sec\n"), GetSpeed(gRdStats));
|
sl@0
|
804 |
test.Printf(_L("\n"));
|
sl@0
|
805 |
gWrStats.Init();
|
sl@0
|
806 |
gRdStats.Init();
|
sl@0
|
807 |
return r;
|
sl@0
|
808 |
}
|
sl@0
|
809 |
|
sl@0
|
810 |
#endif
|
sl@0
|
811 |
|
sl@0
|
812 |
LOCAL_C TInt parseCmd(TChar& aDrvCh1, TChar& aDrvCh2)
|
sl@0
|
813 |
/// Get parameters from the comand line; if there aren't enough then
|
sl@0
|
814 |
/// prompt the user for them and return KErrAbort if ^C is pressed.
|
sl@0
|
815 |
{
|
sl@0
|
816 |
while (aDrvCh1 < 'A' || aDrvCh1 > 'Z')
|
sl@0
|
817 |
{
|
sl@0
|
818 |
test.Printf(_L("Enter drive letter: "));
|
sl@0
|
819 |
while (aDrvCh1 < 'A' || aDrvCh1 > 'Z')
|
sl@0
|
820 |
{
|
sl@0
|
821 |
if (aDrvCh1 == 0x03)
|
sl@0
|
822 |
return KErrAbort;
|
sl@0
|
823 |
aDrvCh1 = User::UpperCase(test.Getch());
|
sl@0
|
824 |
}
|
sl@0
|
825 |
if (!DriveIsOK(aDrvCh1))
|
sl@0
|
826 |
{
|
sl@0
|
827 |
test.Printf(_L("%c: is not a valid drive\n"), (TUint)aDrvCh1);
|
sl@0
|
828 |
aDrvCh1 = 0;
|
sl@0
|
829 |
}
|
sl@0
|
830 |
else
|
sl@0
|
831 |
{
|
sl@0
|
832 |
TInt drv;
|
sl@0
|
833 |
TheFs.CharToDrive(aDrvCh1, drv);
|
sl@0
|
834 |
TheFs.FileSystemName(gFsName1, drv);
|
sl@0
|
835 |
test.Printf(_L("%c: (%S)\n"), (TUint)aDrvCh1, &gFsName1);
|
sl@0
|
836 |
}
|
sl@0
|
837 |
}
|
sl@0
|
838 |
|
sl@0
|
839 |
while (aDrvCh2 < 'A' || aDrvCh2 > 'Z')
|
sl@0
|
840 |
{
|
sl@0
|
841 |
test.Printf(_L("Enter drive letter: "));
|
sl@0
|
842 |
while (aDrvCh2 < 'A' || aDrvCh2 > 'Z')
|
sl@0
|
843 |
{
|
sl@0
|
844 |
if (aDrvCh2 == 0x03)
|
sl@0
|
845 |
return KErrAbort;
|
sl@0
|
846 |
aDrvCh2 = User::UpperCase(test.Getch());
|
sl@0
|
847 |
}
|
sl@0
|
848 |
if (!DriveIsOK(aDrvCh2))
|
sl@0
|
849 |
{
|
sl@0
|
850 |
test.Printf(_L("%c: is not a valid drive\n"), (TUint)aDrvCh2);
|
sl@0
|
851 |
aDrvCh2 = 0;
|
sl@0
|
852 |
}
|
sl@0
|
853 |
else
|
sl@0
|
854 |
{
|
sl@0
|
855 |
TInt drv;
|
sl@0
|
856 |
TheFs.CharToDrive(aDrvCh2, drv);
|
sl@0
|
857 |
TheFs.FileSystemName(gFsName2, drv);
|
sl@0
|
858 |
test.Printf(_L("%c: (%S)\n"), (TUint)aDrvCh2, &gFsName2);
|
sl@0
|
859 |
}
|
sl@0
|
860 |
}
|
sl@0
|
861 |
return KErrNone;
|
sl@0
|
862 |
}
|
sl@0
|
863 |
|
sl@0
|
864 |
GLDEF_C void CallTestsL()
|
sl@0
|
865 |
//
|
sl@0
|
866 |
// Do all tests
|
sl@0
|
867 |
//
|
sl@0
|
868 |
{
|
sl@0
|
869 |
TInt r = TTest::Init();
|
sl@0
|
870 |
test(r == KErrNone);
|
sl@0
|
871 |
|
sl@0
|
872 |
TChar drvch0 = TTest::DefaultDriveChar();
|
sl@0
|
873 |
TChar drvch1 = 0;
|
sl@0
|
874 |
TChar drvch2 = 0;
|
sl@0
|
875 |
TInt drive0;
|
sl@0
|
876 |
TInt drive1;
|
sl@0
|
877 |
TInt drive2;
|
sl@0
|
878 |
|
sl@0
|
879 |
const TInt KMaxArgs = 4;
|
sl@0
|
880 |
TPtrC argv[KMaxArgs];
|
sl@0
|
881 |
TInt argc = TTest::ParseCommandArguments(argv, KMaxArgs);
|
sl@0
|
882 |
if (argc > 1)
|
sl@0
|
883 |
drvch0 = User::UpperCase(argv[1][0]);
|
sl@0
|
884 |
if (argc > 2)
|
sl@0
|
885 |
drvch1 = User::UpperCase(argv[2][0]);
|
sl@0
|
886 |
if (argc > 3)
|
sl@0
|
887 |
drvch2 = User::UpperCase(argv[3][0]);
|
sl@0
|
888 |
|
sl@0
|
889 |
r = TheFs.CharToDrive(drvch0, drive0);
|
sl@0
|
890 |
test(r == KErrNone);
|
sl@0
|
891 |
|
sl@0
|
892 |
if (TheFs.IsValidDrive(drive0))
|
sl@0
|
893 |
MountTestFileSystem(drive0);
|
sl@0
|
894 |
else
|
sl@0
|
895 |
test.Printf(_L("Unable to mount test file system\n"));
|
sl@0
|
896 |
|
sl@0
|
897 |
r = parseCmd(drvch1, drvch2);
|
sl@0
|
898 |
if (r != KErrNone)
|
sl@0
|
899 |
{
|
sl@0
|
900 |
UnmountFileSystem(drive0);
|
sl@0
|
901 |
User::Panic(_L("USER ABORT"), 0);
|
sl@0
|
902 |
}
|
sl@0
|
903 |
|
sl@0
|
904 |
r = TheFs.CharToDrive(drvch1, drive1);
|
sl@0
|
905 |
test(r == KErrNone);
|
sl@0
|
906 |
r = TheFs.CharToDrive(drvch2, drive2);
|
sl@0
|
907 |
test(r == KErrNone);
|
sl@0
|
908 |
|
sl@0
|
909 |
r = TheFs.FileSystemName(gFsName1, drive1);
|
sl@0
|
910 |
test(r == KErrNone || r == KErrNotFound);
|
sl@0
|
911 |
r = TheFs.FileSystemName(gFsName2, drive2);
|
sl@0
|
912 |
test(r == KErrNone || r == KErrNotFound);
|
sl@0
|
913 |
|
sl@0
|
914 |
gDataLock.CreateLocal();
|
sl@0
|
915 |
|
sl@0
|
916 |
if (drive1 == drive2)
|
sl@0
|
917 |
{
|
sl@0
|
918 |
// !!! Disable platform security tests until we get the new APIs
|
sl@0
|
919 |
// if (User::Capability() & KCapabilityRoot)
|
sl@0
|
920 |
// CheckMountLFFS(TheFs, drvch1);
|
sl@0
|
921 |
|
sl@0
|
922 |
test.Printf(_L("Using drive %c: (%S)\n"),
|
sl@0
|
923 |
(TUint)drvch1, &gFsName1);
|
sl@0
|
924 |
if (r == KErrNone)
|
sl@0
|
925 |
{
|
sl@0
|
926 |
test.Next(_L("Test with drive asynchronous"));
|
sl@0
|
927 |
RemountFileSystem(drive1, EFalse);
|
sl@0
|
928 |
testAsyncAccess(drvch1, drvch1);
|
sl@0
|
929 |
}
|
sl@0
|
930 |
|
sl@0
|
931 |
if (r == KErrNone)
|
sl@0
|
932 |
{
|
sl@0
|
933 |
test.Next(_L("Test with drive synchronous"));
|
sl@0
|
934 |
RemountFileSystem(drive1, ETrue);
|
sl@0
|
935 |
testAsyncAccess(drvch1, drvch1);
|
sl@0
|
936 |
}
|
sl@0
|
937 |
}
|
sl@0
|
938 |
else
|
sl@0
|
939 |
{
|
sl@0
|
940 |
// !!! Disable platform security tests until we get the new APIs
|
sl@0
|
941 |
/* if (User::Capability() & KCapabilityRoot)
|
sl@0
|
942 |
{
|
sl@0
|
943 |
CheckMountLFFS(TheFs, drvch1);
|
sl@0
|
944 |
CheckMountLFFS(TheFs, drvch2);
|
sl@0
|
945 |
}
|
sl@0
|
946 |
*/
|
sl@0
|
947 |
test.Printf(_L("Using drives %c: (%S) and %c: (%S)\n"),
|
sl@0
|
948 |
(TUint)drvch1, &gFsName1, (TUint)drvch2, &gFsName2);
|
sl@0
|
949 |
|
sl@0
|
950 |
#if !defined(TEST_ASYNC_IN_THREAD)
|
sl@0
|
951 |
|
sl@0
|
952 |
if (r == KErrNone)
|
sl@0
|
953 |
{
|
sl@0
|
954 |
test.Next(_L("Test async r/w with both drives async"));
|
sl@0
|
955 |
RemountFileSystem(drive1, EFalse);
|
sl@0
|
956 |
RemountFileSystem(drive2, EFalse);
|
sl@0
|
957 |
testAsyncAccess(drvch1, drvch2);
|
sl@0
|
958 |
}
|
sl@0
|
959 |
|
sl@0
|
960 |
if (r == KErrNone)
|
sl@0
|
961 |
{
|
sl@0
|
962 |
test.Next(_L("Test async r/w with 1st drive sync and 2nd async"));
|
sl@0
|
963 |
RemountFileSystem(drive1, ETrue);
|
sl@0
|
964 |
RemountFileSystem(drive2, EFalse);
|
sl@0
|
965 |
testAsyncAccess(drvch1, drvch2);
|
sl@0
|
966 |
}
|
sl@0
|
967 |
|
sl@0
|
968 |
if (r == KErrNone)
|
sl@0
|
969 |
{
|
sl@0
|
970 |
test.Next(_L("Test async r/w with 1st drive async and 2nd sync"));
|
sl@0
|
971 |
RemountFileSystem(drive1, EFalse);
|
sl@0
|
972 |
RemountFileSystem(drive2, ETrue);
|
sl@0
|
973 |
testAsyncAccess(drvch1, drvch2);
|
sl@0
|
974 |
}
|
sl@0
|
975 |
|
sl@0
|
976 |
if (r == KErrNone)
|
sl@0
|
977 |
{
|
sl@0
|
978 |
test.Next(_L("Test async r/w with both drives sync"));
|
sl@0
|
979 |
RemountFileSystem(drive1, ETrue);
|
sl@0
|
980 |
RemountFileSystem(drive2, ETrue);
|
sl@0
|
981 |
testAsyncAccess(drvch1, drvch2);
|
sl@0
|
982 |
}
|
sl@0
|
983 |
|
sl@0
|
984 |
#else
|
sl@0
|
985 |
|
sl@0
|
986 |
if (r == KErrNone)
|
sl@0
|
987 |
{
|
sl@0
|
988 |
test.Next(_L("Test async r/w with both drives asynchronous"));
|
sl@0
|
989 |
RemountFileSystem(drive1, EFalse);
|
sl@0
|
990 |
RemountFileSystem(drive2, EFalse);
|
sl@0
|
991 |
r = testThreads(testAsyncAccess, drvch1, drvch2);
|
sl@0
|
992 |
}
|
sl@0
|
993 |
|
sl@0
|
994 |
if (r == KErrNone)
|
sl@0
|
995 |
{
|
sl@0
|
996 |
test.Next(_L("Test async r/w with one drive sync and one async"));
|
sl@0
|
997 |
RemountFileSystem(drive1, ETrue);
|
sl@0
|
998 |
RemountFileSystem(drive2, EFalse);
|
sl@0
|
999 |
r = testThreads(testAsyncAccess, drvch1, drvch2);
|
sl@0
|
1000 |
}
|
sl@0
|
1001 |
|
sl@0
|
1002 |
if (r == KErrNone)
|
sl@0
|
1003 |
{
|
sl@0
|
1004 |
test.Next(_L("Test async r/w with both drives synchronous"));
|
sl@0
|
1005 |
RemountFileSystem(drive1, ETrue);
|
sl@0
|
1006 |
RemountFileSystem(drive2, ETrue);
|
sl@0
|
1007 |
r = testThreads(testAsyncAccess, drvch1, drvch2);
|
sl@0
|
1008 |
}
|
sl@0
|
1009 |
#endif
|
sl@0
|
1010 |
|
sl@0
|
1011 |
#if defined(TEST_SYNC_IN_THREAD)
|
sl@0
|
1012 |
|
sl@0
|
1013 |
if (r == KErrNone)
|
sl@0
|
1014 |
{
|
sl@0
|
1015 |
test.Next(_L("Test sync r/w with both drives asynchronous"));
|
sl@0
|
1016 |
RemountFileSystem(drive1, EFalse);
|
sl@0
|
1017 |
RemountFileSystem(drive2, EFalse);
|
sl@0
|
1018 |
r = testThreads(testSyncAccess, drvch1, drvch2);
|
sl@0
|
1019 |
}
|
sl@0
|
1020 |
|
sl@0
|
1021 |
if (r == KErrNone)
|
sl@0
|
1022 |
{
|
sl@0
|
1023 |
test.Next(_L("Test sync r/w with one drive sync and one async"));
|
sl@0
|
1024 |
RemountFileSystem(drive1, ETrue);
|
sl@0
|
1025 |
RemountFileSystem(drive2, EFalse);
|
sl@0
|
1026 |
r = testThreads(testSyncAccess, drvch1, drvch2);
|
sl@0
|
1027 |
}
|
sl@0
|
1028 |
|
sl@0
|
1029 |
if (r == KErrNone)
|
sl@0
|
1030 |
{
|
sl@0
|
1031 |
test.Next(_L("Test sync r/w with both drives synchronous"));
|
sl@0
|
1032 |
RemountFileSystem(drive1, ETrue);
|
sl@0
|
1033 |
RemountFileSystem(drive2, ETrue);
|
sl@0
|
1034 |
r = testThreads(testSyncAccess, drvch1, drvch2);
|
sl@0
|
1035 |
}
|
sl@0
|
1036 |
#endif
|
sl@0
|
1037 |
}
|
sl@0
|
1038 |
|
sl@0
|
1039 |
gDataLock.Close();
|
sl@0
|
1040 |
|
sl@0
|
1041 |
UnmountFileSystem(drive0);
|
sl@0
|
1042 |
test(r == 0);
|
sl@0
|
1043 |
}
|
sl@0
|
1044 |
|
sl@0
|
1045 |
|
sl@0
|
1046 |
GLDEF_C TInt E32Main()
|
sl@0
|
1047 |
//
|
sl@0
|
1048 |
// Main entry point
|
sl@0
|
1049 |
//
|
sl@0
|
1050 |
{
|
sl@0
|
1051 |
TInt r;
|
sl@0
|
1052 |
|
sl@0
|
1053 |
CTrapCleanup* cleanup;
|
sl@0
|
1054 |
cleanup=CTrapCleanup::New();
|
sl@0
|
1055 |
__UHEAP_MARK;
|
sl@0
|
1056 |
|
sl@0
|
1057 |
test.Title();
|
sl@0
|
1058 |
test.Start(_L("Starting tests..."));
|
sl@0
|
1059 |
|
sl@0
|
1060 |
r=TheFs.Connect();
|
sl@0
|
1061 |
test(r==KErrNone);
|
sl@0
|
1062 |
|
sl@0
|
1063 |
// TheFs.SetAllocFailure(gAllocFailOn);
|
sl@0
|
1064 |
TTime timerC;
|
sl@0
|
1065 |
timerC.HomeTime();
|
sl@0
|
1066 |
|
sl@0
|
1067 |
// Do the tests
|
sl@0
|
1068 |
TRAP(r,CallTestsL());
|
sl@0
|
1069 |
|
sl@0
|
1070 |
// reset the debug register
|
sl@0
|
1071 |
TheFs.SetDebugRegister(0);
|
sl@0
|
1072 |
|
sl@0
|
1073 |
TTime endTimeC;
|
sl@0
|
1074 |
endTimeC.HomeTime();
|
sl@0
|
1075 |
TTimeIntervalSeconds timeTakenC;
|
sl@0
|
1076 |
r=endTimeC.SecondsFrom(timerC,timeTakenC);
|
sl@0
|
1077 |
test(r==KErrNone);
|
sl@0
|
1078 |
test.Printf(_L("Time taken for test = %d seconds\n"),timeTakenC.Int());
|
sl@0
|
1079 |
// TheFs.SetAllocFailure(gAllocFailOff);
|
sl@0
|
1080 |
TheFs.Close();
|
sl@0
|
1081 |
test.End();
|
sl@0
|
1082 |
test.Close();
|
sl@0
|
1083 |
__UHEAP_MARKEND;
|
sl@0
|
1084 |
delete cleanup;
|
sl@0
|
1085 |
return(KErrNone);
|
sl@0
|
1086 |
}
|