First public contribution.
1 // Copyright (c) 2002-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 //! @file f32test\concur\t_csfsoak.cpp
26 #include "t_cfssoak.h"
28 GLDEF_D RTest test(_L("T_CFSSOAK"));
31 GLREF_D TPtrC gArgV[];
34 LOCAL_D TFullName gFsName;
35 LOCAL_D TFullName gFsName1;
36 LOCAL_D TFullName gFsName2;
37 LOCAL_D TFullName gOldFsName;
38 LOCAL_D TFullName gNewFsName;
39 LOCAL_D TBool gNoMedia = ETrue;
41 _LIT(KFsFile, "CFAFSDLY");
42 _LIT(KFsName, "DelayFS");
44 LOCAL_D const TInt32 KSecond = 1000000;
46 LOCAL_D TChar gRemFsChr = 0;
47 LOCAL_D TInt gRemFsDrv = 0;
49 LOCAL_D TChar gDrvChFill = 0;
51 LOCAL_D TInt gNumRead = 0;
52 LOCAL_D TInt gNumFill = 0;
53 LOCAL_D TInt gNumRem = 0;
55 GLDEF_D TExtension gPrimaryExtensions[KMaxDrives];
57 inline void TraceError(const char* aFile, TInt aLine, const TDesC& aStr, TInt aRsp)
59 // 'Helper' routine to output the file and line of an error as well as a string
60 // and a response value.
64 TPtrC8 fptr((const TUint8*)aFile);
66 RDebug::Print(_L("%S:%d %S: r = %d"), &fbuf, aLine, &aStr, aRsp);
69 #define TESTSTR(r,s,cond) if (!(cond)) { TraceError(__FILE__, __LINE__, (s), (r)); test(0); }
70 #define TESTLIT(r,s,cond) { _LIT(KStr,s); TESTSTR(r,KStr,cond); }
71 #define TESTRES(r,cond) TESTLIT(r,"ERROR",cond)
73 LOCAL_C TChar MountTestFileSystem(TInt aDrive)
75 /// Mount a new CTestFileSystem on the drive under test.
76 /// @param aDrive Drive number (EDriveC etc.) to be used.
83 r=TheFs.DriveToChar(aDrive,c);
84 TESTLIT(r, "TheFs.DriveToChar", r==KErrNone);
86 b.Format(_L("Mount test file system on %c:"),(TUint)c);
89 r=TheFs.AddFileSystem(KFsFile);
90 TESTLIT(r, "TheFs.AddFileSystem", r==KErrNone || r==KErrAlreadyExists);
92 r=TheFs.FileSystemName(gOldFsName,aDrive);
93 TESTLIT(r, "TheFs.FileSystemName", r==KErrNone || r==KErrNotFound);
96 r = TheFs.Drive(drv, gRemFsDrv);
97 TESTLIT(r, "Drive()", r == KErrNone);
99 gNoMedia = (drv.iType == EMediaUnknown || drv.iType == EMediaNotPresent);
101 if (gOldFsName.Length() > 0)
103 r = TheFs.ExtensionName(gPrimaryExtensions[aDrive].iName, aDrive, 0);
105 gPrimaryExtensions[aDrive].iExists = ETrue;
107 TTest::Printf(_L("Dismount %C: %S"), (TUint)c, &gOldFsName);
108 r=TheFs.DismountFileSystem(gOldFsName,aDrive);
109 TESTLIT(r, "DismountFileSystem", r==KErrNone);
112 if (gPrimaryExtensions[aDrive].iExists == EFalse)
113 r=TheFs.MountFileSystem(KFsName,aDrive);
115 r=TheFs.MountFileSystem(KFsName,gPrimaryExtensions[aDrive].iName,aDrive);
117 TESTLIT(r, "TheFs.MountFileSystem", r==KErrNone);
119 r=TheFs.FileSystemName(gNewFsName,aDrive);
120 TESTLIT(r, "TheFs.FileSystemName", r==KErrNone);
122 r = gNewFsName.CompareF(KFsName);
123 TESTLIT(r, "gNewFsName.Compare", r==0);
128 LOCAL_C void UnmountFileSystem(TInt aDrive)
130 /// Dismount the filesystem and remount the original one.
131 /// @param aDrive Drive number (EDriveC etc.) to be unmounted.
135 TInt r=TheFs.DriveToChar(aDrive,c);
136 TESTLIT(r, "TheFs.DriveToChar", r==KErrNone);
138 r=TheFs.DismountFileSystem(gNewFsName,aDrive);
139 TESTLIT(r, "TheFs.DismountFileSystem", r==KErrNone);
143 TTest::Printf(_L("No media on %C: so don't remount it"), (TUint)c);
145 else if (gOldFsName.Length() > 0)
147 TTest::Printf(_L("Mount %C: %S"), (TUint)c, &gOldFsName);
148 if (gPrimaryExtensions[aDrive].iExists == EFalse)
149 r=TheFs.MountFileSystem(gOldFsName,aDrive);
151 r=TheFs.MountFileSystem(gOldFsName,gPrimaryExtensions[aDrive].iName,aDrive);
152 TESTLIT(r, "MountFileSystem", r==KErrNone);
156 LOCAL_C TInt testReadOnly(TAny* /*aData*/)
158 /// Task to test read-only operations.
161 CTrapCleanup* cleanup = CTrapCleanup::New();
162 TSoakReadOnly rdonly;
163 TInt64 seed = 178543;
165 rdonly.ExcludeDrive(gRemFsDrv);
166 while (r == KErrNone)
168 r = rdonly.ScanDrives(ETrue, Math::Rand(seed) % 90 + 10);
171 TTest::Printf(_L("Read-only test results:\n"));
173 rdonly.iDrives.Print(_L("Drives:"));
174 rdonly.iDirs.Print(_L("Dirs:"));
175 rdonly.iFiles.Print(_L("Files:"));
176 rdonly.iReads.Print(_L("Reads:"));
178 TTest::PrintUnlock();
182 TTest::Fail(HERE, r, _L("ScanDrives error"));
186 LOCAL_C TInt testFillEmpty(TAny* /*aData*/)
188 /// Task to repeatedly fill and clean a drive.
191 CTrapCleanup* cleanup = CTrapCleanup::New();
198 TInt r = fs.Connect();
200 TTest::Fail(HERE, r, _L("can't connect to fileserver\n"));
203 // User specified the drive, so use that explicitly
208 // User didn't specify the drive, so scan through them looking for
209 // likely candidates. Don't use ROM or RAM drives, or LFFS ones, or
210 // our own 'slow' file system. Out of what's left, look for the one
211 // with the least (but non-zero) free space.
212 for (drive = EDriveA; drive <= EDriveZ; drive++)
214 if (drive != gRemFsDrv)
218 r = fs.Drive(d, drive);
219 if (r == KErrNone && d.iDriveAtt != 0 &&
220 !(d.iDriveAtt & KDriveAttRom) &&
221 d.iMediaAtt != EMediaRam &&
222 !IsFileSystemLFFS(fs, drive))
224 r = fs.Volume(info, drive);
227 if (free <= 0 || info.iFree < free)
229 r = fs.DriveToChar(drive, drvch);
231 TTest::Fail(HERE, r, _L("DriveToChar(%d)"), drive);
237 // not interested in drives which produce errors, they
238 // probably don't really exist.
243 // Drive doesn't exist, is a ROM drive or an LFFS drive, don't
250 // If no drive found, can't do fill test so fail.
253 TTest::Fail(HERE, _L("No drive found for fill test!"));
256 r = fs.CharToDrive(drvch, drive);
258 TTest::Fail(HERE, r, _L("CharToDrive(%C:)\n"), (TUint)drvch);
259 r = fs.FileSystemName(gFsName, drive);
261 TTest::Fail(HERE, r, _L("FileSystemName(%C:)\n"), (TUint)drvch);
263 r = fs.Volume(info, drive);
265 TTest::Fail(HERE, r, _L("Volume(%C:)\n"), (TUint)drvch);
269 TTest::Printf(_L("Using %C: (%S) with %d KB free for fill/clean cycle test\n"),
270 (TUint)drvch, &gFsName, I64LOW(info.iFree / 1024));
273 r = fill.SetDrive(drvch);
275 TTest::Fail(HERE, r, _L("Unable to setup drive %C"), (TUint)drvch);
277 r = fill.CleanDrive();
278 if (r != KErrNone && r != KErrNotFound && r != KErrPathNotFound)
279 TTest::Fail(HERE, r, _L("Error cleaning drive %C"), (TUint)drvch);
281 // Loop to do the actual test
282 while (r == KErrNone)
284 r = fill.FillDrive();
285 if (r != KErrNone && r != KErrDiskFull)
286 TTest::Fail(HERE, r, _L("Error filling drive %C"), (TUint)drvch);
289 TTest::Printf(_L("%C: filled\n"), (TUint)drvch);
290 TTest::PrintUnlock();
292 r = fill.CleanDrive();
293 if (r == KErrPathNotFound)
296 TTest::Fail(HERE, r, _L("cleaning drive %C"), (TUint)drvch);
299 TTest::Printf(_L("%C: cleaned\n"), (TUint)drvch);
300 TTest::PrintUnlock();
305 TTest::Fail(HERE, r, _L("Fill/clean error"));
309 LOCAL_C TInt testRemote(TAny* /*aData*/)
311 /// Task to exercise the remote (special) filesystem.
314 CTrapCleanup* cleanup = CTrapCleanup::New();
315 TSoakRemote rem(gRemFsChr);
317 for (TBool sync = EFalse; r == KErrNone; sync = !sync)
319 for (TInt i = 0; i < 1; i++)
322 r = rem.TestSession();
324 TTest::Fail(HERE, r, _L("TestSession failed"));
325 r = rem.TestSubSession();
327 TTest::Fail(HERE, r, _L("TestSubSession failed"));
330 TTest::Fail(HERE, r, _L("Mount/dismount failed"));
331 User::After(100*1000000);
336 TTest::Fail(HERE, r, _L("Test (remote) filesystem error"));
340 GLDEF_C void CallTestsL()
345 // first thing, initialise local test class to make sure it gets done.
346 TInt r = TTest::Init();
349 const TInt KMaxArgs = 4;
350 TPtrC argv[KMaxArgs];
351 TInt argc = TTest::ParseCommandArguments(argv, KMaxArgs);
353 gRemFsChr = 'M'; // probably a 'safe' drive
357 gRemFsChr = User::UpperCase(argv[1][0]);
359 gDrvChFill = User::UpperCase(argv[2][0]);
361 r = TheFs.CharToDrive(gRemFsChr, gRemFsDrv);
363 if (r != KErrNone || gRemFsDrv == EDriveZ)
365 test.Printf(_L("Test cannnot run on drive %C:\n"), (TUint)gRemFsChr);
369 // If we can do it, check whether the drives are LFFS and are OK
370 // !!! Disable platform security tests until we get the new APIs
371 /* if (User::Capability() & KCapabilityRoot)
373 if (gDrvChFill != 0 && gDrvChFill != gRemFsChr)
374 CheckMountLFFS(TheFs, gDrvChFill);
377 MountTestFileSystem(gRemFsDrv);
379 r = TTest::Create(0, testReadOnly, _L("T_ReadOnly"));
382 r = TTest::Create(1, testFillEmpty, _L("T_FillEmpty"));
385 r = TTest::Create(2, testRemote, _L("T_Remote"));
388 TRequestStatus kStat;
389 test.Console()->Read(kStat);
390 TInt displaycount = 0;
391 while ((r = TTest::Run(ETrue, 1*KSecond)) == KErrNone) // run until any thread exits
393 if (++displaycount >= 60 || kStat == KErrNone)
395 test.Printf(_L("Fill %-6d Rem %-6d Read %d\n"), gNumFill, gNumRem, gNumRead);
398 if (kStat == KErrNone)
400 test.Printf(_L("Aborted by user!\n"));
406 // Kill all outstanding threads.
407 TTest::KillAll(KErrAbort);
409 UnmountFileSystem(gRemFsDrv);
412 GLDEF_C TInt E32Main()
417 for (TInt i = 0; i < KMaxDrives; i++)
419 gPrimaryExtensions[i].iExists = EFalse;
423 CTrapCleanup* cleanup;
424 cleanup=CTrapCleanup::New();
428 test.Start(_L("Starting tests..."));
433 // TheFs.SetAllocFailure(gAllocFailOn);
438 TRAP(r,CallTestsL());
440 // reset the debug register
441 TheFs.SetDebugRegister(0);
445 TTimeIntervalSeconds timeTakenC;
446 r=endTimeC.SecondsFrom(timerC,timeTakenC);
448 test.Printf(_L("Time taken for test = %d seconds\n"),timeTakenC.Int());
449 // TheFs.SetAllocFailure(gAllocFailOff);