author | mikek |
Wed, 16 Jun 2010 12:59:18 +0100 | |
branch | GCC_SURGE |
changeset 160 | 30e086416910 |
parent 33 | 0173bcd7697c |
permissions | -rw-r--r-- |
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 |
// f32test\concur\t_cfssimple.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
#define __E32TEST_EXTENSION__ |
|
18 |
#include <f32file.h> |
|
19 |
#include <e32test.h> |
|
20 |
#include "t_server.h" |
|
21 |
#include "t_tdebug.h" |
|
22 |
||
23 |
GLDEF_D RTest test(_L("T_CFSSIMPLE")); |
|
24 |
GLDEF_D RFs TheFs; |
|
25 |
||
26 |
LOCAL_D TFullName OldFsName; |
|
27 |
LOCAL_D TFileName NewFsName; |
|
28 |
||
29 |
_LIT(KFsFile, "CFAFSDLY"); |
|
30 |
_LIT(KFsName, "DelayFS"); |
|
31 |
||
32 |
||
33 |
struct TExtension |
|
34 |
{ |
|
35 |
TFullName iName; |
|
36 |
TBool iExists; |
|
37 |
}; |
|
38 |
||
39 |
LOCAL_D TExtension gPrimaryExtensions[KMaxDrives]; |
|
40 |
||
41 |
LOCAL_C TChar MountTestFileSystem(TInt aDrive) |
|
42 |
// |
|
43 |
// Mount a new test filesystem on the drive under test |
|
44 |
// |
|
45 |
{ |
|
46 |
TBuf<64> b; |
|
47 |
TChar c; |
|
48 |
TInt r; |
|
49 |
if (aDrive > EDriveZ) |
|
50 |
{ |
|
51 |
c = aDrive; |
|
52 |
r=TheFs.CharToDrive(c, aDrive); |
|
53 |
test_KErrNone(r); |
|
54 |
} |
|
55 |
else |
|
56 |
{ |
|
57 |
r=TheFs.DriveToChar(aDrive,c); |
|
58 |
test_KErrNone(r); |
|
59 |
} |
|
60 |
||
61 |
b.Format(_L("Test mounting of test file system on %c:"),(TUint)c); |
|
62 |
test.Next(b); |
|
63 |
||
64 |
test.Printf(_L("Load filesystem from %S\n"), &KFsFile); |
|
65 |
||
66 |
r=TheFs.AddFileSystem(KFsFile); |
|
67 |
test_Value(r, r == KErrNone || r == KErrAlreadyExists); |
|
68 |
||
69 |
r=TheFs.FileSystemName(OldFsName,aDrive); |
|
70 |
test_Value(r, r == KErrNone || r == KErrNotFound); |
|
71 |
||
72 |
if (OldFsName.Length() > 0) |
|
73 |
{ |
|
74 |
r = TheFs.ExtensionName(gPrimaryExtensions[aDrive].iName, aDrive, 0); |
|
75 |
if (r == KErrNone) |
|
76 |
gPrimaryExtensions[aDrive].iExists = ETrue; |
|
77 |
||
78 |
test.Printf(_L("Dismount %S filesystem on %c:\n"), &OldFsName, (TUint)c); |
|
79 |
r=TheFs.DismountFileSystem(OldFsName,aDrive); |
|
80 |
if (r == KErrNotReady) |
|
81 |
{ |
|
82 |
TDriveInfo d; |
|
83 |
r=TheFs.Drive(d, aDrive); |
|
84 |
test_KErrNone(r); |
|
85 |
if (d.iType == EMediaNotPresent) |
|
86 |
test.Printf(_L("%c: Medium not present - cannot perform test.\n"), (TUint)c); |
|
87 |
else |
|
88 |
test.Printf(_L("medium found (type %d) but drive %c: not ready\nPrevious test may have hung; else, check hardware.\n"), (TInt)d.iType, (TUint)c); |
|
89 |
} |
|
90 |
else if (r == KErrCorrupt) |
|
91 |
test.Printf(_L("drive %c: corrupted, cannot unmount\nPrevious test may have aborted; else, check hardware.\n"), (TUint)c); |
|
92 |
||
93 |
test_KErrNone(r); |
|
94 |
} |
|
95 |
||
96 |
test.Printf(_L("Mount filesystem %S\n"), &KFsName); |
|
97 |
||
98 |
if (gPrimaryExtensions[aDrive].iExists == EFalse) |
|
99 |
r=TheFs.MountFileSystem(KFsName,aDrive); |
|
100 |
else |
|
101 |
r=TheFs.MountFileSystem(KFsName,gPrimaryExtensions[aDrive].iName,aDrive); |
|
102 |
test_KErrNone(r); |
|
103 |
||
104 |
r=TheFs.FileSystemName(NewFsName,aDrive); |
|
105 |
test_KErrNone(r); |
|
106 |
test(NewFsName.Compare(KFsName)==0); |
|
107 |
test.Printf(_L("New %S filesystem on %c:\n"), &NewFsName, (TUint)c); |
|
108 |
||
109 |
// Check attributes |
|
110 |
TDriveInfo info; |
|
111 |
r=TheFs.Drive(info,aDrive); |
|
112 |
test_KErrNone(r); |
|
113 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
114 |
test.Printf(_L("iType=%d,iConnctionBusType=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
115 |
(TUint)info.iConnectionBusType,info.iDriveAtt,info.iMediaAtt); |
0 | 116 |
return c; |
117 |
} |
|
118 |
||
119 |
LOCAL_C void UnmountFileSystem(TInt aDrive) |
|
120 |
// |
|
121 |
// Unmount the test filesystem on the drive under test |
|
122 |
// |
|
123 |
{ |
|
124 |
TChar c; |
|
125 |
TInt r; |
|
126 |
if (aDrive > EDriveZ) |
|
127 |
{ |
|
128 |
c = aDrive; |
|
129 |
r=TheFs.CharToDrive(c, aDrive); |
|
130 |
test_KErrNone(r); |
|
131 |
} |
|
132 |
else |
|
133 |
{ |
|
134 |
r=TheFs.DriveToChar(aDrive,c); |
|
135 |
test_KErrNone(r); |
|
136 |
} |
|
137 |
test.Printf(_L("Dismount %S filesystem on %c\n"), &NewFsName, (TUint)c); |
|
138 |
r=TheFs.DismountFileSystem(NewFsName,aDrive); |
|
139 |
test_KErrNone(r); |
|
140 |
if (OldFsName.Length() > 0) |
|
141 |
{ |
|
142 |
test.Printf(_L("Remount %S filesystem on %c\n"), &OldFsName, (TUint)c); |
|
143 |
||
144 |
if (gPrimaryExtensions[aDrive].iExists == EFalse) |
|
145 |
r=TheFs.MountFileSystem(OldFsName,aDrive); |
|
146 |
else |
|
147 |
r=TheFs.MountFileSystem(OldFsName,gPrimaryExtensions[aDrive].iName,aDrive); |
|
148 |
test_KErrNone(r); |
|
149 |
} |
|
150 |
} |
|
151 |
||
152 |
template <TInt N> |
|
153 |
LOCAL_C TDes* cvtbuff(const TDesC8& buff, TBuf<N>& b) |
|
154 |
// |
|
155 |
// Copy an 8-bit buffer to a character one. |
|
156 |
// |
|
157 |
{ |
|
158 |
TInt i; |
|
159 |
TInt len = buff.Length(); |
|
160 |
TInt max = b.MaxLength(); |
|
161 |
if (len > max) |
|
162 |
len = max; |
|
163 |
b.SetLength(len); |
|
164 |
for (i = 0; i < len; i++) |
|
165 |
b[i] = TText(buff[i]); |
|
166 |
return &b; |
|
167 |
} |
|
168 |
||
169 |
//--------------------------------------------- |
|
170 |
//! @SYMTestCaseID FSBASE-CR-PCHY-6PALT2 |
|
171 |
//! @SYMTestType CT |
|
172 |
//! @SYMREQ CR PCHY-6PALT2 |
|
173 |
//! @SYMTestCaseDesc Test asynchronous RFs::Flush(TRequestStatus& aStatus) |
|
174 |
//! @SYMTestStatus Implemented |
|
175 |
//! @SYMTestActions Perform an asynchronous flush and wait for completion |
|
176 |
//! @SYMTestExpectedResults Asynchronous flush completes after expected delay |
|
177 |
//! @SYMTestPriority Low |
|
178 |
//! @SYMAuthor Stefan Williams |
|
179 |
//! @SYMCreationDate 01/06/2006 |
|
180 |
//! @See EFSRV and EFILE components |
|
181 |
//! @file f32test\concur\t_cfssimple.cpp |
|
182 |
//--------------------------------------------- |
|
183 |
||
184 |
LOCAL_C void testAsyncFlush(RFile& aFile) |
|
185 |
{ |
|
186 |
TTest::Printf(_L("Test Async RFile::Flush()")); |
|
187 |
||
188 |
RTimer flushTimer; |
|
189 |
TRequestStatus flushTimerStatus; |
|
190 |
TInt err = flushTimer.CreateLocal(); |
|
191 |
TEST(err == KErrNone); |
|
192 |
||
193 |
flushTimer.After(flushTimerStatus, 10000000); // 10 seconds timeout for RFile::Flush on CFAFSDLY file system |
|
194 |
||
195 |
TTime startFlush; |
|
196 |
startFlush.HomeTime(); |
|
197 |
||
198 |
TRequestStatus flushStatus; |
|
199 |
aFile.Flush(flushStatus); |
|
200 |
TEST(flushStatus==KRequestPending); |
|
201 |
||
202 |
User::WaitForRequest(flushTimerStatus, flushStatus); |
|
203 |
if ((flushStatus == KRequestPending) && (flushTimerStatus == KErrNone)) |
|
204 |
{ |
|
205 |
TTest::Fail(HERE, _L("Flush : Timed Out")); |
|
206 |
} |
|
207 |
||
208 |
if (flushStatus != KErrNone) |
|
209 |
{ |
|
210 |
TTest::Fail(HERE, flushStatus.Int(), _L("Flush : Error")); |
|
211 |
} |
|
212 |
||
213 |
TTime endFlush; |
|
214 |
endFlush.HomeTime(); |
|
215 |
||
216 |
TTimeIntervalSeconds flushTime; |
|
217 |
err = endFlush.SecondsFrom(startFlush, flushTime); |
|
218 |
TEST(err == KErrNone); |
|
219 |
||
220 |
TTest::Printf(_L("Flush took %d seconds"), flushTime.Int()); |
|
221 |
||
222 |
if(flushTime.Int() < 3) |
|
223 |
{ |
|
224 |
TTest::Fail(HERE, _L("Flush took < 3 Seconds")); |
|
225 |
} |
|
226 |
||
227 |
flushTimer.Cancel(); |
|
228 |
flushTimer.Close(); |
|
229 |
} |
|
230 |
||
231 |
LOCAL_C TInt testAccessFile(TAny*) |
|
232 |
// |
|
233 |
// Test read file handling with two threads. |
|
234 |
// |
|
235 |
{ |
|
236 |
TTest::Start(_L("Test write file")); |
|
237 |
||
238 |
TThreadData& data = TTest::Self(); |
|
239 |
TFileName fileName = data.iFile; |
|
240 |
||
241 |
TTest::Printf(_L("Connect to myFs\n")); |
|
242 |
||
243 |
RFs myFs; |
|
244 |
TInt r = myFs.Connect(); |
|
245 |
TEST(r==KErrNone); |
|
246 |
||
247 |
TTest::Printf(_L("Create %S\n"), &fileName); |
|
248 |
||
249 |
RFile f; |
|
250 |
||
251 |
r = f.Replace(myFs, fileName, EFileStreamText | EFileWrite); |
|
252 |
TEST(r==KErrNone); |
|
253 |
||
254 |
// wait for both tasks to have a chance to complete opening the files |
|
255 |
User::After(1000); |
|
256 |
||
257 |
const TInt KNumBuf = 10; |
|
258 |
const TInt KBufLen = 0x80; |
|
259 |
TBuf8<KBufLen> a[KNumBuf]; |
|
260 |
TBuf8<KBufLen> b; |
|
261 |
TBuf<KBufLen> tbuf; |
|
262 |
TInt i; |
|
263 |
||
264 |
TUint base = 0; |
|
265 |
for (i = 0; i < fileName.Length(); i++) |
|
266 |
base = base * 0x11 + fileName[i]; |
|
267 |
base += base / 32; |
|
268 |
base = base % 32 + 0x30; |
|
269 |
||
270 |
TRequestStatus status[10]; |
|
271 |
||
272 |
TTest::Next(_L("Write file")); |
|
273 |
for (i = 0; i <= 9; i++) |
|
274 |
{ |
|
275 |
TChar val = TChar(base + i); |
|
276 |
a[i].Fill(TText(val), i+1); |
|
277 |
TTest::Printf(_L("write '%S' started\n"), cvtbuff(a[i], tbuf)); |
|
278 |
f.Write(a[i], status[i]); |
|
279 |
User::After(1); |
|
280 |
if (r != KErrNone) |
|
281 |
{ |
|
282 |
TTest::Fail(HERE, r, _L("Write")); |
|
283 |
} |
|
284 |
} |
|
285 |
||
286 |
for (i = 0; i < 10; i++) |
|
287 |
{ |
|
288 |
User::WaitForAnyRequest(); |
|
289 |
if (status[i] == KRequestPending) |
|
290 |
{ |
|
291 |
TTest::Printf(_L("write %d still pending!\n"), i); |
|
292 |
} |
|
293 |
else |
|
294 |
{ |
|
295 |
TTest::Printf(_L("write %d completed with status %d\n"), i, status[i].Int()); |
|
296 |
} |
|
297 |
} |
|
298 |
||
299 |
TTest::Printf(_L("Write 64 bytes at the end as padding\n")); |
|
300 |
TBuf8<32> fill; |
|
301 |
fill.Fill(TText('_'), 32); |
|
302 |
f.Write(fill); |
|
303 |
f.Write(fill); |
|
304 |
||
305 |
testAsyncFlush(f); |
|
306 |
||
307 |
f.Close(); |
|
308 |
||
309 |
b.Fill(TText('*'), b.MaxLength()); |
|
310 |
TTest::Next(_L("Read file")); |
|
311 |
||
312 |
// wait to allow the dust to settle |
|
313 |
User::After(1000000); |
|
314 |
||
315 |
r = f.Open(myFs, fileName, EFileStreamText); |
|
316 |
TEST(r==KErrNone); |
|
317 |
||
318 |
for (i = 0; i < 10; i++) |
|
319 |
{ |
|
320 |
r=f.Read(b, 12-i); |
|
321 |
if (r == KErrNone) |
|
322 |
{ |
|
323 |
TTest::Printf(_L("read %2d bytes <%S>\n"), b.Length(), cvtbuff(b, tbuf)); |
|
324 |
} |
|
325 |
else |
|
326 |
{ |
|
327 |
TTest::Fail(HERE, r, _L("Read")); |
|
328 |
} |
|
329 |
User::After(1); |
|
330 |
} |
|
331 |
r=f.Read(b); |
|
332 |
if (r != KErrNone) |
|
333 |
{ |
|
334 |
TTest::Fail(HERE, r, _L("Read\n")); |
|
335 |
// TEST(r==KErrNone); |
|
336 |
} |
|
337 |
if (!(b.Length()==0)) |
|
338 |
{ |
|
339 |
cvtbuff(b, tbuf); |
|
340 |
TTest::Printf(_L("read %2d bytes <%.32S>\n"), b.Length(), &tbuf); |
|
341 |
} |
|
342 |
||
343 |
// wait to allow the dust to settle |
|
344 |
User::After(1000000); |
|
345 |
||
346 |
TTest::Printf(_L("Close file")); |
|
347 |
f.Close(); |
|
348 |
||
349 |
TTest::Printf(_L("Close session")); |
|
350 |
myFs.Close(); |
|
351 |
return r; |
|
352 |
} |
|
353 |
||
354 |
LOCAL_C TInt createThread(TThreadFunction aFunc, TChar aDrvCh) |
|
355 |
// |
|
356 |
// Create a thread using function aFunc on drive aDrvCh |
|
357 |
// |
|
358 |
{ |
|
359 |
static TInt tnum = 0; |
|
360 |
TBuf<2> drive(_L("?")); |
|
361 |
TBuf<64> name; |
|
362 |
drive[0] = TText(aDrvCh); |
|
363 |
drive.UpperCase(); |
|
364 |
TThreadData& d = TTest::Data(tnum); |
|
365 |
d.iFile.Format(_L("%S:\\TEST%d.FILE"), &drive, tnum); |
|
366 |
name.Format(_L("Test_%S_%d"), &drive, tnum); |
|
367 |
TInt r = TTest::Create(tnum, aFunc, name); |
|
368 |
++tnum; |
|
369 |
return r; |
|
370 |
} |
|
371 |
||
372 |
LOCAL_C TInt testThreads(TChar aDrvCh1, TChar aDrvCh2) |
|
373 |
// |
|
374 |
// Create threads operating on files on two drives. |
|
375 |
// |
|
376 |
{ |
|
377 |
TInt r; |
|
378 |
r = createThread(testAccessFile, aDrvCh1); |
|
379 |
r = createThread(testAccessFile, aDrvCh2); |
|
380 |
r = TTest::Run(); |
|
381 |
return r; |
|
382 |
} |
|
383 |
||
384 |
LOCAL_C TBool isSpace(TChar c) |
|
385 |
// |
|
386 |
// Return true if the character is space or tab |
|
387 |
// |
|
388 |
{ |
|
389 |
return (c == ' ' || c == '\t'); |
|
390 |
} |
|
391 |
||
392 |
LOCAL_C void parseCmd(TDesC& cmd, TChar& dr0, TChar& dr1, TChar& dr2) |
|
393 |
// |
|
394 |
// Parse command line to get two characters for drive 1 and 2 |
|
395 |
// |
|
396 |
{ |
|
397 |
TInt i = 0; |
|
398 |
TInt n = cmd.Length(); |
|
399 |
// skip to first non-space |
|
400 |
while (i < n && isSpace(cmd[i])) |
|
401 |
++i; |
|
402 |
if (i < n) |
|
403 |
dr0 = cmd[i]; |
|
404 |
// skip to first space |
|
405 |
while (i < n && !isSpace(cmd[i])) |
|
406 |
++i; |
|
407 |
// skip to first non-space |
|
408 |
while (i < n && isSpace(cmd[i])) |
|
409 |
++i; |
|
410 |
if (i < n) |
|
411 |
dr1 = cmd[i]; |
|
412 |
// skip to first space |
|
413 |
while (i < n && !isSpace(cmd[i])) |
|
414 |
++i; |
|
415 |
// skip to first non-space |
|
416 |
while (i < n && isSpace(cmd[i])) |
|
417 |
++i; |
|
418 |
if (i < n) |
|
419 |
dr2 = cmd[i]; |
|
420 |
// skip to first space |
|
421 |
while (i < n && !isSpace(cmd[i])) |
|
422 |
++i; |
|
423 |
} |
|
424 |
||
425 |
GLDEF_C void CallTestsL() |
|
426 |
// |
|
427 |
// Do all tests |
|
428 |
// |
|
429 |
{ |
|
430 |
TBuf<0x100> cmd; |
|
431 |
User::CommandLine(cmd); |
|
432 |
cmd.UpperCase(); |
|
433 |
||
434 |
TChar dr0 = 'F'; |
|
435 |
TChar dr1 = 0; |
|
436 |
TChar dr2 = 0; |
|
437 |
parseCmd(cmd, dr0, dr1, dr2); |
|
438 |
||
439 |
if (dr1 < 'A') |
|
440 |
dr1 = dr0; |
|
441 |
||
442 |
if (dr2 < 'A') |
|
443 |
dr2 = dr1; |
|
444 |
||
445 |
if (dr0 < 'A' || dr0 >= 'Z') |
|
446 |
{ |
|
447 |
test.Printf(_L("Test cannnot run on drive\n")); |
|
448 |
return; |
|
449 |
} |
|
450 |
||
451 |
MountTestFileSystem(dr0); |
|
452 |
// TheFs.SetVolumeLabel(_L("TRACE")); |
|
453 |
TInt r = testThreads(dr1, dr2); |
|
454 |
TheFs.SetVolumeLabel(_L("OFF")); |
|
455 |
UnmountFileSystem(dr0); |
|
456 |
test_KErrNone(r); |
|
457 |
} |
|
458 |
||
459 |
GLDEF_C TInt E32Main() |
|
460 |
// |
|
461 |
// Main entry point |
|
462 |
// |
|
463 |
{ |
|
464 |
||
465 |
for (TInt i = 0; i < KMaxDrives; i++) |
|
466 |
{ |
|
467 |
gPrimaryExtensions[i].iExists = EFalse; |
|
468 |
} |
|
469 |
||
470 |
TInt r; |
|
471 |
CTrapCleanup* cleanup; |
|
472 |
cleanup=CTrapCleanup::New(); |
|
473 |
__UHEAP_MARK; |
|
474 |
||
475 |
test.Title(); |
|
476 |
test.Start(_L("Starting tests...")); |
|
477 |
||
478 |
r=TheFs.Connect(); |
|
479 |
test_KErrNone(r); |
|
480 |
||
481 |
// TheFs.SetAllocFailure(gAllocFailOn); |
|
482 |
TTime timerC; |
|
483 |
timerC.HomeTime(); |
|
484 |
||
485 |
TRAP(r,CallTestsL()); |
|
486 |
||
487 |
// reset the debug register |
|
488 |
TheFs.SetDebugRegister(0); |
|
489 |
||
490 |
TTime endTimeC; |
|
491 |
endTimeC.HomeTime(); |
|
492 |
TTimeIntervalSeconds timeTakenC; |
|
493 |
r=endTimeC.SecondsFrom(timerC,timeTakenC); |
|
494 |
test_KErrNone(r); |
|
495 |
test.Printf(_L("Time taken for test = %d seconds\n"),timeTakenC.Int()); |
|
496 |
// TheFs.SetAllocFailure(gAllocFailOff); |
|
497 |
TheFs.Close(); |
|
498 |
test.End(); |
|
499 |
test.Close(); |
|
500 |
__UHEAP_MARKEND; |
|
501 |
delete cleanup; |
|
502 |
return(KErrNone); |
|
503 |
} |
|
504 |