0
|
1 |
// Copyright (c) 1996-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 |
// File Name: f32test/bench/t_fat_perf_impl.cpp
|
|
15 |
// This file contains FRAMEWORK implementation for the tests to test
|
|
16 |
// the FAT Performance on large number of files (PREQ 1885).
|
|
17 |
//
|
|
18 |
//
|
|
19 |
|
|
20 |
// Include Files
|
|
21 |
#include "t_fat_perf.h"
|
|
22 |
#include <e32math.h>
|
|
23 |
#include <hal.h>
|
|
24 |
|
|
25 |
const TInt gMeasurementScale = K1mSec; // defines the scales of measurement
|
|
26 |
|
|
27 |
CMeasureAndLogUnit::CMeasureAndLogUnit()
|
|
28 |
{
|
|
29 |
|
|
30 |
}
|
|
31 |
|
|
32 |
void CMeasureAndLogUnit::ConstructL(const TMLUnitParam& aParam)
|
|
33 |
{
|
|
34 |
iID = aParam.iID;
|
|
35 |
User::LeaveIfError(HAL::Get(HALData::EFastCounterFrequency, iFreq));
|
|
36 |
iScale = gMeasurementScale;
|
|
37 |
iLogItemNo = 1;
|
|
38 |
}
|
|
39 |
|
|
40 |
CMeasureAndLogUnit* CMeasureAndLogUnit::NewLC(const TMLUnitParam& aParam)
|
|
41 |
{
|
|
42 |
CMeasureAndLogUnit* self = new(ELeave) CMeasureAndLogUnit();
|
|
43 |
CleanupStack::PushL(self);
|
|
44 |
self->ConstructL(aParam);
|
|
45 |
return self;
|
|
46 |
}
|
|
47 |
|
|
48 |
CMeasureAndLogUnit* CMeasureAndLogUnit::NewL(const TMLUnitParam& aParam)
|
|
49 |
{
|
|
50 |
CMeasureAndLogUnit* self = CMeasureAndLogUnit::NewLC(aParam);
|
|
51 |
CleanupStack::Pop(self);
|
|
52 |
return self;
|
|
53 |
}
|
|
54 |
|
|
55 |
CMeasureAndLogUnit::~CMeasureAndLogUnit()
|
|
56 |
{
|
|
57 |
|
|
58 |
}
|
|
59 |
|
|
60 |
TInt CMeasureAndLogUnit::MeasureStart()
|
|
61 |
{
|
|
62 |
iStartStatus = User::FastCounter();
|
|
63 |
return KErrNone;
|
|
64 |
}
|
|
65 |
TInt CMeasureAndLogUnit::MeasureEnd()
|
|
66 |
{
|
|
67 |
iEndStatus = User::FastCounter();
|
|
68 |
return KErrNone;
|
|
69 |
}
|
|
70 |
|
|
71 |
//Measurement and Log unit
|
|
72 |
TInt CMeasureAndLogUnit::Log(const TFileName& aDirName, const TFileName& aFileName, TUint aCurrentFileNo, TUint aCurrentFilePos)
|
|
73 |
{
|
|
74 |
TReal measure = iScale * ((TReal)(iEndStatus - iStartStatus)) / ((TReal) iFreq);
|
|
75 |
TBuf<0x10> scale;
|
|
76 |
if (iScale == K1mSec)
|
|
77 |
{
|
|
78 |
scale = _L("millisecond");
|
|
79 |
}
|
|
80 |
else if (iScale == K1Sec)
|
|
81 |
{
|
|
82 |
scale = _L("second");
|
|
83 |
}
|
|
84 |
else if (iScale == K1uSec)
|
|
85 |
{
|
|
86 |
scale = _L("microsecond");
|
|
87 |
}
|
|
88 |
test.Printf(_L("[LOG]: \t%u \t\"%S\" \t%f \t%S \t\"%S\" \t%u \t%u\n"),
|
|
89 |
iLogItemNo, &aDirName, measure, &scale, &aFileName, aCurrentFileNo, aCurrentFilePos);
|
|
90 |
|
|
91 |
iLogItemNo++;
|
|
92 |
|
|
93 |
return KErrNone;
|
|
94 |
}
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
CFileOperationUnit::CFileOperationUnit()
|
|
99 |
:iDirCreated(EFalse)
|
|
100 |
{
|
|
101 |
|
|
102 |
}
|
|
103 |
|
|
104 |
// File Operation Unit
|
|
105 |
void CFileOperationUnit::ConstructL(const TFileOpUnitParam& aParam)
|
|
106 |
{
|
|
107 |
iDirName = aParam.iDirName;
|
|
108 |
iNamingSchemeParam = aParam.iNamingSchemeParam;
|
|
109 |
iFileOpMode = aParam.iFileOpMode;
|
|
110 |
iMLUnitPtr = aParam.iMLUnitPtr;
|
|
111 |
|
|
112 |
TInt rel = iRFs.Connect();
|
|
113 |
if (rel != KErrNone)
|
|
114 |
{
|
|
115 |
test.Printf(_L("<<Error>>: DIRUNIT: iRFs.Connect = %d\n"), rel);
|
|
116 |
test(EFalse);
|
|
117 |
}
|
|
118 |
}
|
|
119 |
|
|
120 |
|
|
121 |
CFileOperationUnit* CFileOperationUnit::NewLC(const TFileOpUnitParam& aParam)
|
|
122 |
{
|
|
123 |
CFileOperationUnit* self = new(ELeave) CFileOperationUnit();
|
|
124 |
CleanupStack::PushL(self);
|
|
125 |
self->ConstructL(aParam);
|
|
126 |
return self;
|
|
127 |
}
|
|
128 |
|
|
129 |
CFileOperationUnit* CFileOperationUnit::NewL(const TFileOpUnitParam& aParam)
|
|
130 |
{
|
|
131 |
CFileOperationUnit* self = CFileOperationUnit::NewLC(aParam);
|
|
132 |
CleanupStack::Pop(self);
|
|
133 |
return self;
|
|
134 |
}
|
|
135 |
|
|
136 |
CFileOperationUnit::~CFileOperationUnit()
|
|
137 |
{
|
|
138 |
iRFs.Close();
|
|
139 |
}
|
|
140 |
|
|
141 |
void CFileOperationUnit::SetMLUnit(CMeasureAndLogUnit* aMLUnit)
|
|
142 |
{
|
|
143 |
iMLUnitPtr = aMLUnit;
|
|
144 |
}
|
|
145 |
|
|
146 |
|
|
147 |
// File Operation unit - Test Functions
|
|
148 |
TInt CFileOperationUnit::Run(const TFileName& aDirName, const TFileName& aFileName, TBool aIsTakingMeasurement, TUint aCurFileNo, TUint aCurFilePos)
|
|
149 |
{
|
|
150 |
TMLParam mlParam;
|
|
151 |
RFile rfile;
|
|
152 |
TInt rel = KErrNone;
|
|
153 |
TInt rel1 = KErrNone;
|
|
154 |
TInt bufMaxLength = 4096;
|
|
155 |
TInt Ret1 = KErrNone;
|
|
156 |
TInt Ret2 = KErrNone;
|
|
157 |
RBuf8 buf;
|
|
158 |
RBuf8 databuf;
|
|
159 |
|
|
160 |
|
|
161 |
if (aIsTakingMeasurement && iMLUnitPtr != NULL)
|
|
162 |
{
|
|
163 |
mlParam.iDirName = iDirName;
|
|
164 |
mlParam.iFileName = aFileName;
|
|
165 |
mlParam.iNamingScheme = iNamingSchemeParam;
|
|
166 |
mlParam.iCurFileNo = aCurFileNo;
|
|
167 |
mlParam.iFileOpMode = iFileOpMode;
|
|
168 |
}
|
|
169 |
else if (aIsTakingMeasurement && iMLUnitPtr == NULL)
|
|
170 |
{
|
|
171 |
test.Printf(_L("<<Error>>CZFileOperationUnit::Run(): no logging unit associated!!\n"));
|
|
172 |
return KErrGeneral;
|
|
173 |
}
|
|
174 |
|
|
175 |
switch (iFileOpMode)
|
|
176 |
{
|
|
177 |
case EFATPerfFileReplace: // Replace Operations
|
|
178 |
{
|
|
179 |
test.Printf(_L("CZFileOperationUnit::Run(): EZFileReplace\n"));
|
|
180 |
break;
|
|
181 |
}
|
|
182 |
case EFATPerfFileCreate:
|
|
183 |
{
|
|
184 |
if (!iDirCreated && gTestCase != EFATPerfCreate) // 'EFATPerfCreate' is an enum defined in header file t_fat_perf.h
|
|
185 |
{
|
|
186 |
rel = iRFs.MkDirAll(aFileName);
|
|
187 |
test.Printf(_L("MakeDirAll \"%S\" error: %d\n"), &aFileName, rel);
|
|
188 |
if (rel != KErrNone && rel != KErrAlreadyExists)
|
|
189 |
{
|
|
190 |
test.Printf(_L("<<Error>>: MakeDirAll \"%S\" error: %d\n"), &aFileName, rel);
|
|
191 |
return rel;
|
|
192 |
}
|
|
193 |
iDirCreated = ETrue;
|
|
194 |
}
|
|
195 |
if (aIsTakingMeasurement)
|
|
196 |
{
|
|
197 |
iMLUnitPtr->MeasureStart();
|
|
198 |
rel = rfile.Create(iRFs, aFileName, EFileShareAny);
|
|
199 |
iMLUnitPtr->MeasureEnd();
|
|
200 |
iMLUnitPtr->Log(aDirName, aFileName, aCurFileNo, aCurFilePos);
|
|
201 |
if (rel != KErrNone)
|
|
202 |
{
|
|
203 |
test.Printf(_L("<<Error>>: FileCreating \"%S\" error: %d\n"), &aFileName, rel);
|
|
204 |
return rel;
|
|
205 |
}
|
|
206 |
}
|
|
207 |
else
|
|
208 |
{
|
|
209 |
rel = rfile.Create(iRFs, aFileName, EFileShareAny);
|
|
210 |
if (rel != KErrNone)
|
|
211 |
{
|
|
212 |
test.Printf(_L("<<Error>>: FileCreating error: %d\n"), rel);
|
|
213 |
return rel;
|
|
214 |
}
|
|
215 |
}
|
|
216 |
break;
|
|
217 |
}
|
|
218 |
|
|
219 |
case EFATPerfFileOpen: // Open Operations
|
|
220 |
{
|
|
221 |
if (aIsTakingMeasurement)
|
|
222 |
{
|
|
223 |
iMLUnitPtr->MeasureStart();
|
|
224 |
rel = rfile.Open(iRFs, aFileName, EFileShareAny);
|
|
225 |
iMLUnitPtr->MeasureEnd();
|
|
226 |
iMLUnitPtr->Log(aDirName, aFileName, aCurFileNo, aCurFilePos);
|
|
227 |
if (rel != KErrNone)
|
|
228 |
{
|
|
229 |
test.Printf(_L("<<Error>>: FileOpen \"%S\" error: %d\n"), &aFileName, rel);
|
|
230 |
return rel;
|
|
231 |
}
|
|
232 |
}
|
|
233 |
else
|
|
234 |
{
|
|
235 |
rel = rfile.Open(iRFs, aFileName, EFileShareAny);
|
|
236 |
if (rel != KErrNone)
|
|
237 |
{
|
|
238 |
test.Printf(_L("<<Error>>: FileOpen error: %d\n"), rel);
|
|
239 |
return rel;
|
|
240 |
}
|
|
241 |
}
|
|
242 |
break;
|
|
243 |
}
|
|
244 |
|
|
245 |
|
|
246 |
case EFATPerfFileDelete: // Delete Operations
|
|
247 |
{
|
|
248 |
|
|
249 |
|
|
250 |
if (aIsTakingMeasurement)
|
|
251 |
{
|
|
252 |
iMLUnitPtr->MeasureStart();
|
|
253 |
rel = iRFs.Delete(aFileName);
|
|
254 |
iMLUnitPtr->MeasureEnd();
|
|
255 |
iMLUnitPtr->Log(aDirName, aFileName, aCurFileNo, aCurFilePos);
|
|
256 |
if (rel != KErrNone)
|
|
257 |
{
|
|
258 |
test.Printf(_L("<<Error>>: FileDelete \"%S\" error: %d\n"), &aFileName, rel);
|
|
259 |
return rel;
|
|
260 |
}
|
|
261 |
|
|
262 |
}
|
|
263 |
else
|
|
264 |
{
|
|
265 |
|
|
266 |
rel = rfile.Open(iRFs, aFileName, EFileShareAny);
|
|
267 |
if (rel != KErrNone)
|
|
268 |
{
|
|
269 |
test.Printf(_L("<<Error>>: FileOpen \"%S\" error: %d\n"), &aFileName, rel);
|
|
270 |
return rel;
|
|
271 |
}
|
|
272 |
rfile.Close(); // file needs be closed before deleting.
|
|
273 |
|
|
274 |
rel = iRFs.Delete(aFileName);
|
|
275 |
if (rel != KErrNone)
|
|
276 |
{
|
|
277 |
test.Printf(_L("<<Error>>: FileDelete \"%S\" error: %d\n"), &aFileName, rel);
|
|
278 |
return rel;
|
|
279 |
}
|
|
280 |
|
|
281 |
}
|
|
282 |
break;
|
|
283 |
}
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
case EFATPerfFileWrite: //Write Operations
|
|
288 |
{
|
|
289 |
|
|
290 |
// creating buffer for Write operation
|
|
291 |
Ret2 = databuf.CreateMax(bufMaxLength);
|
|
292 |
|
|
293 |
if (Ret2 != KErrNone)
|
|
294 |
{
|
|
295 |
test.Printf(_L("<<Error>>: Unable to create a buffer 'databuf': %d\n"), Ret2);
|
|
296 |
return Ret2;
|
|
297 |
}
|
|
298 |
|
|
299 |
databuf.Fill('A', bufMaxLength);
|
|
300 |
|
|
301 |
|
|
302 |
if (aIsTakingMeasurement)
|
|
303 |
{
|
|
304 |
|
|
305 |
rel = rfile.Open(iRFs, aFileName, EFileShareAny|EFileWrite);
|
|
306 |
iMLUnitPtr->MeasureStart();
|
|
307 |
rel1 = rfile.Write(databuf);
|
|
308 |
iMLUnitPtr->MeasureEnd();
|
|
309 |
iMLUnitPtr->Log(aDirName, aFileName, aCurFileNo, aCurFilePos);
|
|
310 |
if (rel != KErrNone)
|
|
311 |
{
|
|
312 |
test.Printf(_L("<<Error>>: FileOpen \"%S\" error: %d\n"), &aFileName, rel);
|
|
313 |
return rel;
|
|
314 |
}
|
|
315 |
|
|
316 |
if (rel1 != KErrNone)
|
|
317 |
{
|
|
318 |
test.Printf(_L("<<Error>>: FileWrite \"%S\" error: %d\n"), &aFileName, rel1);
|
|
319 |
return rel1;
|
|
320 |
}
|
|
321 |
|
|
322 |
}
|
|
323 |
else
|
|
324 |
{
|
|
325 |
|
|
326 |
rel = rfile.Open(iRFs, aFileName, EFileShareAny|EFileWrite);
|
|
327 |
rel1 = rfile.Write(databuf);
|
|
328 |
|
|
329 |
if (rel != KErrNone)
|
|
330 |
{
|
|
331 |
test.Printf(_L("<<Error>>: FileOpen error: %d\n"), rel);
|
|
332 |
return rel;
|
|
333 |
}
|
|
334 |
|
|
335 |
if (rel1 != KErrNone)
|
|
336 |
{
|
|
337 |
test.Printf(_L("<<Error>>: FileWrite error: %d\n"), rel1);
|
|
338 |
return rel1;
|
|
339 |
}
|
|
340 |
}
|
|
341 |
break;
|
|
342 |
}
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
case EFATPerfFileRead: // Read Operations
|
|
347 |
{
|
|
348 |
|
|
349 |
// creating the buffer for Read operation
|
|
350 |
Ret1 = buf.CreateMax(bufMaxLength);
|
|
351 |
if (Ret1 != KErrNone)
|
|
352 |
{
|
|
353 |
test.Printf(_L("<<Error>>: Unable to create a buffer 'buf': %d\n"), Ret1);
|
|
354 |
return Ret1;
|
|
355 |
}
|
|
356 |
|
|
357 |
|
|
358 |
if (aIsTakingMeasurement)
|
|
359 |
{
|
|
360 |
|
|
361 |
rel = rfile.Open(iRFs, aFileName, EFileShareAny|EFileRead);
|
|
362 |
iMLUnitPtr->MeasureStart();
|
|
363 |
rel1 = rfile.Read(buf);
|
|
364 |
iMLUnitPtr->MeasureEnd();
|
|
365 |
iMLUnitPtr->Log(aDirName, aFileName, aCurFileNo, aCurFilePos);
|
|
366 |
if (rel != KErrNone)
|
|
367 |
{
|
|
368 |
test.Printf(_L("<<Error>>: FileOpen \"%S\" error: %d\n"), &aFileName, rel);
|
|
369 |
return rel;
|
|
370 |
}
|
|
371 |
if (rel1 != KErrNone)
|
|
372 |
{
|
|
373 |
test.Printf(_L("<<Error>>: FileRead \"%S\" error: %d\n"), &aFileName, rel1);
|
|
374 |
return rel1;
|
|
375 |
}
|
|
376 |
}
|
|
377 |
else
|
|
378 |
{
|
|
379 |
rel = rfile.Open(iRFs, aFileName, EFileShareAny|EFileRead);
|
|
380 |
rel1 = rfile.Read(buf);
|
|
381 |
|
|
382 |
if (rel != KErrNone)
|
|
383 |
{
|
|
384 |
test.Printf(_L("<<Error>>: FileOpen error: %d\n"), rel);
|
|
385 |
return rel;
|
|
386 |
}
|
|
387 |
|
|
388 |
if (rel1 != KErrNone)
|
|
389 |
{
|
|
390 |
test.Printf(_L("<<Error>>: FileRead \"%S\" error: %d\n"), &aFileName, rel1);
|
|
391 |
return rel1;
|
|
392 |
}
|
|
393 |
}
|
|
394 |
break;
|
|
395 |
}
|
|
396 |
|
|
397 |
default:
|
|
398 |
{
|
|
399 |
// Error: KErrNotSupported!!
|
|
400 |
test.Printf(_L("<<Error>>CZFileOperationUnit::Run(): KErrNotSupported!!\n"));
|
|
401 |
return KErrNotSupported;
|
|
402 |
}
|
|
403 |
}
|
|
404 |
|
|
405 |
rfile.Close();
|
|
406 |
buf.Close();
|
|
407 |
databuf.Close();
|
|
408 |
return KErrNone;
|
|
409 |
}
|
|
410 |
|
|
411 |
|
|
412 |
|
|
413 |
CDirUnit::CDirUnit()
|
|
414 |
{
|
|
415 |
|
|
416 |
}
|
|
417 |
|
|
418 |
void CDirUnit::ConstructL(const TDirUnitParam& aParam, const TChar aDriveChar)
|
|
419 |
{
|
|
420 |
iPriority = aParam.iPriority;
|
|
421 |
iDirName.Copy(aParam.iDirName);
|
|
422 |
iDirName[0] = (TUint16)aDriveChar;
|
|
423 |
iRuns = aParam.iRuns;
|
|
424 |
iCurrentRunNo = 1;
|
|
425 |
iFilesPerRun = aParam.iFilesPerRun;
|
|
426 |
iCurrentFileNo = 1;
|
|
427 |
iTotalFileNo = iRuns * iFilesPerRun;
|
|
428 |
iSampleInterval = aParam.iSampleInterval;
|
|
429 |
|
|
430 |
|
|
431 |
iConOrRan = aParam.iNamingScheme.iConOrRan;
|
|
432 |
iUniOrAsc = aParam.iNamingScheme.iUniOrAsc;
|
|
433 |
iZeroPadFileNumberForFixedLengthFileNames = aParam.iNamingScheme.iZeroPadFileNumber;
|
|
434 |
iFileNameBase = aParam.iNamingScheme.iFileNameBase;
|
|
435 |
iMaxFileNameLength = aParam.iNamingScheme.iMaxFileNameLength;
|
|
436 |
iMinStringLength = aParam.iNamingScheme.iMinStringLength;
|
|
437 |
|
|
438 |
if (iZeroPadFileNumberForFixedLengthFileNames)
|
|
439 |
{
|
|
440 |
// Calculate how many digits the highest file postfix will have so that
|
|
441 |
// zero padding can be added.
|
|
442 |
TFileName fileNamePostFixBuffer;
|
|
443 |
fileNamePostFixBuffer.AppendNum(iTotalFileNo);
|
|
444 |
iNumDigitsInTotalFileNo = fileNamePostFixBuffer.Length();
|
|
445 |
}
|
|
446 |
else
|
|
447 |
{
|
|
448 |
iNumDigitsInTotalFileNo = 0;
|
|
449 |
}
|
|
450 |
|
|
451 |
TFileOpUnitParam fileOpParam;
|
|
452 |
fileOpParam.iDirName = iDirName;
|
|
453 |
fileOpParam.iNamingSchemeParam = aParam.iNamingScheme;
|
|
454 |
fileOpParam.iFileOpMode = aParam.iFileOpMode;
|
|
455 |
fileOpParam.iMLUnitPtr = iMLUnitPtr;
|
|
456 |
CFileOperationUnit* fileOpUnit = CFileOperationUnit::NewL(fileOpParam);
|
|
457 |
iFileOpUnit = fileOpUnit;
|
|
458 |
}
|
|
459 |
|
|
460 |
CDirUnit* CDirUnit::NewLC(const TDirUnitParam& aParam, const TChar aDriveChar)
|
|
461 |
{
|
|
462 |
CDirUnit* self = new(ELeave) CDirUnit();
|
|
463 |
CleanupStack::PushL(self);
|
|
464 |
self->ConstructL(aParam, aDriveChar);
|
|
465 |
return self;
|
|
466 |
}
|
|
467 |
|
|
468 |
CDirUnit* CDirUnit::NewL(const TDirUnitParam& aParam, const TChar aDriveChar)
|
|
469 |
{
|
|
470 |
CDirUnit* self = CDirUnit::NewLC(aParam, aDriveChar);
|
|
471 |
CleanupStack::Pop(self);
|
|
472 |
return self;
|
|
473 |
}
|
|
474 |
|
|
475 |
CDirUnit::~CDirUnit()
|
|
476 |
{
|
|
477 |
delete iFileOpUnit;
|
|
478 |
}
|
|
479 |
|
|
480 |
TInt CDirUnit::Priority()
|
|
481 |
{
|
|
482 |
return iPriority;
|
|
483 |
}
|
|
484 |
|
|
485 |
const TFileName& CDirUnit::Name()
|
|
486 |
{
|
|
487 |
return iDirName;
|
|
488 |
}
|
|
489 |
|
|
490 |
|
|
491 |
_LIT(KFileExtDefault, ".TXT");
|
|
492 |
|
|
493 |
//Character set for random file generation
|
|
494 |
static TText16 gFileNameCharPool[] =
|
|
495 |
{
|
|
496 |
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
|
497 |
// 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
498 |
'-', '_', '^', '$', '~', '!', '#', '%', '&', '{', '}', '@', '(', ')', '\'',
|
|
499 |
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
|
|
500 |
};
|
|
501 |
|
|
502 |
const TUint KNumOfLegalAsciiChar = 51;
|
|
503 |
|
|
504 |
|
|
505 |
// Random String Generation for file names
|
|
506 |
TFileName CDirUnit::GenerateRandomString(const TUint aMinStringLength, const TUint aMaxStringLength, const TNamingUniOrAsc aUniOrAsc)
|
|
507 |
{
|
|
508 |
TInt strLen = -1;
|
|
509 |
TFileName aFileName;
|
|
510 |
|
|
511 |
if (aMinStringLength == aMaxStringLength && aMaxStringLength != 0)
|
|
512 |
{
|
|
513 |
strLen = aMinStringLength;
|
|
514 |
}
|
|
515 |
else if (aMaxStringLength > aMinStringLength)
|
|
516 |
{
|
|
517 |
do
|
|
518 |
{
|
|
519 |
strLen = aMinStringLength + ((TUint) (Math::Random())) % (aMaxStringLength - aMinStringLength);
|
|
520 |
}
|
|
521 |
while (strLen == 0);
|
|
522 |
}
|
|
523 |
else
|
|
524 |
{
|
|
525 |
test.Printf(_L("<<Random String Error>>: Bad String Length Setting!!\n"));
|
|
526 |
}
|
|
527 |
|
|
528 |
if (aUniOrAsc == EAscii)
|
|
529 |
{
|
|
530 |
TInt i;
|
|
531 |
for (i = 0; i < strLen; ++i)
|
|
532 |
{
|
|
533 |
TInt nextCharIdx = (((TUint) (Math::Random())) % KNumOfLegalAsciiChar);
|
|
534 |
aFileName.Append((TChar)gFileNameCharPool[nextCharIdx]);
|
|
535 |
}
|
|
536 |
}
|
|
537 |
else if(aUniOrAsc == EUnicode)
|
|
538 |
{
|
|
539 |
test.Printf(_L("<<Random String Error>>: Unicode is not supported yet!!\n"));
|
|
540 |
}
|
|
541 |
else
|
|
542 |
{
|
|
543 |
test(0);
|
|
544 |
}
|
|
545 |
|
|
546 |
return aFileName;
|
|
547 |
}
|
|
548 |
|
|
549 |
TBool CDirUnit::FileNameIsUnique(const TFileName& /*aFileName*/)
|
|
550 |
{
|
|
551 |
|
|
552 |
return ETrue;
|
|
553 |
|
|
554 |
}
|
|
555 |
|
|
556 |
// File Name Generation
|
|
557 |
TInt CDirUnit::GenerateFileName(TFileName& aFileName)
|
|
558 |
{
|
|
559 |
TBool fileNameIsUnique = EFalse;
|
|
560 |
if (iRuns == iFilesPerRun && iFilesPerRun == 1)
|
|
561 |
{
|
|
562 |
aFileName.Zero();
|
|
563 |
aFileName.Append(iDirName);
|
|
564 |
aFileName.Append(iFileNameBase);
|
|
565 |
aFileName.Append(KFileExtDefault);
|
|
566 |
fileNameIsUnique = FileNameIsUnique(aFileName);
|
|
567 |
if (fileNameIsUnique == EFalse)
|
|
568 |
{
|
|
569 |
test.Printf(_L("<<Error>>: File name is not unique!\n"));
|
|
570 |
return KErrArgument;
|
|
571 |
}
|
|
572 |
return KErrNone;
|
|
573 |
}
|
|
574 |
|
|
575 |
if (iConOrRan == EConsecutive)
|
|
576 |
{
|
|
577 |
aFileName.Zero();
|
|
578 |
aFileName.Append(iDirName);
|
|
579 |
aFileName.Append(iFileNameBase);
|
|
580 |
|
|
581 |
if (iZeroPadFileNumberForFixedLengthFileNames)
|
|
582 |
{
|
|
583 |
aFileName.AppendNumFixedWidth(iCurrentFileNo, EDecimal, iNumDigitsInTotalFileNo);
|
|
584 |
}
|
|
585 |
else
|
|
586 |
{
|
|
587 |
aFileName.AppendNum(iCurrentFileNo);
|
|
588 |
}
|
|
589 |
|
|
590 |
aFileName.Append(KFileExtDefault);
|
|
591 |
fileNameIsUnique = FileNameIsUnique(aFileName);
|
|
592 |
if (fileNameIsUnique == EFalse)
|
|
593 |
{
|
|
594 |
test.Printf(_L("<<Error>>: File name is not unique!\n"));
|
|
595 |
return KErrArgument;
|
|
596 |
}
|
|
597 |
return KErrNone;
|
|
598 |
}
|
|
599 |
else if(iConOrRan == ERandom)
|
|
600 |
{
|
|
601 |
if (iMaxFileNameLength <= 0)
|
|
602 |
{
|
|
603 |
test.Printf(_L("<<Parameter Error>>: DIR: \"%S\"\n"), &iDirName);
|
|
604 |
test.Printf(_L("<<Parameter Error>>: EZRandom && iMaxNameLength <= 0\n"));
|
|
605 |
return KErrArgument;
|
|
606 |
}
|
|
607 |
|
|
608 |
do
|
|
609 |
{
|
|
610 |
aFileName.Zero();
|
|
611 |
aFileName.Append(iDirName);
|
|
612 |
aFileName.Append(iFileNameBase);
|
|
613 |
TFileName randomString = GenerateRandomString(iMinStringLength, iMaxFileNameLength, iUniOrAsc);
|
|
614 |
aFileName.Append(randomString);
|
|
615 |
aFileName.Append(KFileExtDefault);
|
|
616 |
fileNameIsUnique = FileNameIsUnique(aFileName);
|
|
617 |
}
|
|
618 |
while(fileNameIsUnique == EFalse);
|
|
619 |
|
|
620 |
return KErrNone;
|
|
621 |
}
|
|
622 |
|
|
623 |
return KErrNone;
|
|
624 |
}
|
|
625 |
|
|
626 |
void CDirUnit::SetMLUnit(CMeasureAndLogUnit* aMLUnitPtr)
|
|
627 |
{
|
|
628 |
iMLUnitPtr = aMLUnitPtr;
|
|
629 |
iFileOpUnit->SetMLUnit(aMLUnitPtr);
|
|
630 |
}
|
|
631 |
|
|
632 |
TBool CDirUnit::CheckMeasurementTaking()
|
|
633 |
{
|
|
634 |
|
|
635 |
return (iSampleInterval > 0 &&
|
|
636 |
iCurrentFileNo >= iSampleInterval &&
|
|
637 |
((iCurrentFileNo % iSampleInterval) == 0));
|
|
638 |
}
|
|
639 |
|
|
640 |
TInt CDirUnit::Run(const TInt aCurrentPriority)
|
|
641 |
{
|
|
642 |
if (aCurrentPriority != iPriority)
|
|
643 |
{
|
|
644 |
return KErrNotReady;
|
|
645 |
}
|
|
646 |
|
|
647 |
|
|
648 |
if (iCurrentRunNo <= iRuns)
|
|
649 |
{
|
|
650 |
|
|
651 |
TUint i;
|
|
652 |
for (i = 0; i < iFilesPerRun; ++i, ++iCurrentFileNo)
|
|
653 |
{
|
|
654 |
// check currentFileNo < totalFileNo
|
|
655 |
if (iCurrentFileNo > iTotalFileNo)
|
|
656 |
{
|
|
657 |
// Error
|
|
658 |
User::Panic(_L("<<CZDirUnit::Run>>: file overflow!"), 100);
|
|
659 |
}
|
|
660 |
// generate file name
|
|
661 |
TFileName fileName;
|
|
662 |
GenerateFileName(fileName);
|
|
663 |
|
|
664 |
// check if is taking measurement
|
|
665 |
TBool isTakingMeasurement = CheckMeasurementTaking();
|
|
666 |
|
|
667 |
// file operation
|
|
668 |
iFileOpUnit->Run(iDirName, fileName, isTakingMeasurement, iCurrentFileNo, iCurrentFileNo);
|
|
669 |
}
|
|
670 |
iCurrentRunNo++;
|
|
671 |
}
|
|
672 |
|
|
673 |
if (iCurrentRunNo > iRuns)
|
|
674 |
{
|
|
675 |
return KErrCompletion;
|
|
676 |
}
|
|
677 |
return KErrNone;
|
|
678 |
}
|
|
679 |
|
|
680 |
|
|
681 |
|
|
682 |
CExecutionUnit::CExecutionUnit()
|
|
683 |
{
|
|
684 |
|
|
685 |
}
|
|
686 |
|
|
687 |
void CExecutionUnit::ConstructL(CMeasureAndLogUnit* aMLUnitPtr, const TChar aDriveChar)
|
|
688 |
{
|
|
689 |
iCurPriority = -1;
|
|
690 |
iDriveChar = aDriveChar;
|
|
691 |
|
|
692 |
if (aMLUnitPtr != NULL)
|
|
693 |
{
|
|
694 |
iMLUnitPtr = aMLUnitPtr;
|
|
695 |
}
|
|
696 |
}
|
|
697 |
|
|
698 |
CExecutionUnit* CExecutionUnit::NewLC(CMeasureAndLogUnit* aMLUnitPtr, const TChar aDriveChar)
|
|
699 |
{
|
|
700 |
CExecutionUnit* self = new(ELeave) CExecutionUnit();
|
|
701 |
CleanupStack::PushL(self);
|
|
702 |
self->ConstructL(aMLUnitPtr, aDriveChar);
|
|
703 |
return self;
|
|
704 |
}
|
|
705 |
|
|
706 |
CExecutionUnit* CExecutionUnit::NewL(CMeasureAndLogUnit* aMLUnitPtr, const TChar aDriveChar)
|
|
707 |
{
|
|
708 |
CExecutionUnit* self = CExecutionUnit::NewLC(aMLUnitPtr, aDriveChar);
|
|
709 |
CleanupStack::Pop(self);
|
|
710 |
return self;
|
|
711 |
}
|
|
712 |
|
|
713 |
CExecutionUnit::~CExecutionUnit()
|
|
714 |
{
|
|
715 |
TInt count = iDirUnitArray.Count();
|
|
716 |
if (count > 0)
|
|
717 |
{
|
|
718 |
TInt i;
|
|
719 |
for (i = 0; i < count; ++i)
|
|
720 |
{
|
|
721 |
CDirUnit* tempDirUnit = iDirUnitArray[i];
|
|
722 |
delete tempDirUnit;
|
|
723 |
}
|
|
724 |
}
|
|
725 |
iDirUnitArray.Close();
|
|
726 |
}
|
|
727 |
|
|
728 |
|
|
729 |
TInt CExecutionUnit::AddDirUnitL(const TDirUnitParam& aParam)
|
|
730 |
{
|
|
731 |
CDirUnit* dirUnit = CDirUnit::NewL(aParam, iDriveChar);
|
|
732 |
if (iMLUnitPtr)
|
|
733 |
{
|
|
734 |
dirUnit->SetMLUnit(iMLUnitPtr);
|
|
735 |
}
|
|
736 |
TInt rel = iDirUnitArray.Append(dirUnit);
|
|
737 |
return rel;
|
|
738 |
}
|
|
739 |
|
|
740 |
|
|
741 |
// To Re-calculate the priority
|
|
742 |
TInt CExecutionUnit::RecalculateCurrentPrioirty()
|
|
743 |
{
|
|
744 |
// findout the least number of iPriority in current array
|
|
745 |
if (iDirUnitArray.Count() == 0)
|
|
746 |
{
|
|
747 |
iCurPriority = -1;
|
|
748 |
return iCurPriority;
|
|
749 |
}
|
|
750 |
|
|
751 |
TBool found = EFalse;
|
|
752 |
|
|
753 |
TInt i;
|
|
754 |
|
|
755 |
for (i = 0; i < iDirUnitArray.Count(); ++i)
|
|
756 |
{
|
|
757 |
if (iDirUnitArray[i]->Priority() == iCurPriority)
|
|
758 |
{
|
|
759 |
found = ETrue;
|
|
760 |
}
|
|
761 |
}
|
|
762 |
|
|
763 |
if (!found)
|
|
764 |
{
|
|
765 |
iCurPriority = iDirUnitArray[0]->Priority();
|
|
766 |
for (i = 0; i < iDirUnitArray.Count(); ++i)
|
|
767 |
{
|
|
768 |
if (iDirUnitArray[i]->Priority() < iCurPriority)
|
|
769 |
{
|
|
770 |
iCurPriority = iDirUnitArray[i]->Priority();
|
|
771 |
}
|
|
772 |
}
|
|
773 |
}
|
|
774 |
|
|
775 |
return iCurPriority;
|
|
776 |
}
|
|
777 |
|
|
778 |
TInt CExecutionUnit::Run()
|
|
779 |
{
|
|
780 |
test.Printf(_L("CZExecutionUnit::Run()\n"));
|
|
781 |
|
|
782 |
TInt curPriority = RecalculateCurrentPrioirty();
|
|
783 |
|
|
784 |
while (iDirUnitArray.Count() > 0)
|
|
785 |
{
|
|
786 |
TInt i;
|
|
787 |
for (i = 0; i < iDirUnitArray.Count(); ++i)
|
|
788 |
{
|
|
789 |
TInt rel = iDirUnitArray[i]->Run(curPriority);
|
|
790 |
if (rel == KErrCompletion)
|
|
791 |
{
|
|
792 |
test.Printf(_L("DIR: \"%S\" terminated.\n"), &iDirUnitArray[i]->Name());
|
|
793 |
CDirUnit* dirUnit = iDirUnitArray[i];
|
|
794 |
iDirUnitArray.Remove(i);
|
|
795 |
delete dirUnit;
|
|
796 |
--i;
|
|
797 |
curPriority = RecalculateCurrentPrioirty();
|
|
798 |
}
|
|
799 |
else if (rel == KErrNotReady)
|
|
800 |
{
|
|
801 |
// do nothing
|
|
802 |
}
|
|
803 |
}
|
|
804 |
}
|
|
805 |
|
|
806 |
test.Printf(_L("\n"));
|
|
807 |
test.Printf(_L("CZExecutionUnit::Finished.\n"));
|
|
808 |
return KErrNone;
|
|
809 |
}
|
|
810 |
|
|
811 |
/*-- EOF--*/
|