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