Update contrib.
1 // Copyright (c) 1998-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.
14 // f32test\fsstress\t_remses.cpp
18 #if !defined(__T_REMFSY_H__)
22 GLDEF_D TFileName tPath;
24 LOCAL_C void printDriveAtt(TInt aDrive,TUint anAtt,RTest& aTest);
25 LOCAL_C void printDriveInfo(TInt aDrive,TDriveInfo& anInfo, RTest& aTest);
26 LOCAL_C void DriveInformation(TInt aDrive,TDriveInfo& anInfo,RTest& aTest);
29 void TMultipleSessionTest::Initialise(RFs& aFs)
38 void TMultipleSessionTest::SetSessionPath(TInt aDrive)
40 // Set the session path for a RFs connection to aDrive
43 iSessionPath=(_L("?:\\MULTIPLE_SESSION_TEST\\"));
45 TInt r=iFs.DriveToChar(aDrive,driveLetter);
48 iSessionPath[0]=(TText)driveLetter;
49 r=iFs.SetSessionPath(iSessionPath);
51 r=iFs.MkDirAll(iSessionPath);
52 test(r==KErrNone || r==KErrAlreadyExists);
56 void TMultipleSessionTest::RunTests(RTest& aTest)
58 // Run tests on iFs file server session
65 testVolumeInfo(aTest);
66 // testPowerDown(aTest);
68 testInitialisation(aTest);
69 // testMediaChange(aTest);
71 MakeAndDeleteFiles(aTest);
76 void TMultipleSessionTest::testDriveList(RTest& aTest)
78 // Test the drive list.
82 aTest.Next(_L("The drive list"));
83 TInt r=iFs.SetSessionPath(iSessionPath);
85 r=iFs.DriveList(list);
88 for (TInt i=0;i<KMaxDrives;i++)
92 printDriveAtt(i,att,aTest);
96 void TMultipleSessionTest::testDriveInfo(RTest& aTest)
98 // Test the drive info.
102 aTest.Next(_L("The drive info"));
103 TInt r=iFs.SetSessionPath(iSessionPath);
105 r=iFs.DriveList(list);
107 for (TInt i=0;i<KMaxDrives;i++)
114 //aTest(r==KErrNone);
115 printDriveInfo(i,d,aTest);
116 aTest.Printf(_L("\n"));
118 DriveInformation(i,d, aTest);
123 void TMultipleSessionTest::testPowerDown(RTest& aTest)
125 // Test the effect of multiple power downs
128 aTest.Next(_L("Power Down"));
131 test(timer.CreateLocal()==KErrNone);
133 TRequestStatus status;
135 for (TInt index=0; index<5; index++)
137 aTest.Printf(_L("********** %d **********\n"),(5-index));
139 time+=TTimeIntervalSeconds(8);
140 timer.At(status,time);
141 UserHal::SwitchOff(); // Switch off
142 User::WaitForRequest(status); // Switch back on
143 aTest(status==KErrNone);
149 void TMultipleSessionTest::testMediaChange(RTest& aTest)
151 // Test the effect of multiple media changes
154 aTest.Next(_L("Media Change"));
155 TInt drive=CurrentDrive(aTest);
157 if (drive>KMaxLocalDrives)
160 #if defined (__MARM__)
165 TLocalDrive theDrive;
166 TLocalDriveCaps info;
168 for (TInt index=0; index<5; index++)
170 aTest.Printf(_L("********** %d **********\n"),(5-index));
172 TInt r=theDrive.Connect(drive,changedFlag);
174 UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change
179 r=theDrive.Caps(info);
180 } while (r==KErrNotReady);
182 // User::After(1000000);
187 void TMultipleSessionTest::testVolumeInfo(RTest& aTest)
193 aTest.Next(_L("The volume info"));
194 TInt r=iFs.SetSessionPath(iSessionPath);
196 r=iFs.DriveList(list);
198 for (TInt i=0;i<KMaxDrives;i++)
201 if ((r=iFs.Volume(v,i))==KErrNone)
203 printDriveInfo(i,v.iDrive,aTest);
204 aTest.Printf(_L(" VOL=\"%S\" ID=%08x\n"),&v.iName,v.iUniqueID);
205 aTest.Printf(_L(" SIZE=%ldK FREE=%ldK\n"),v.iSize/1024,v.iFree/1024);
207 else if (r==KErrNotReady)
208 aTest.Printf(_L("%c: Not Ready\n"),i+'A');
209 else if (r==KErrPathNotFound)
210 aTest.Printf(_L("%c: Not Found\n"),i+'A');
213 aTest.Printf(_L("%c: Error %d\n"),i+'A',r);
216 aTest.Printf(_L("\n"));
221 void TMultipleSessionTest::testInitialisation(RTest& aTest)
223 // Modified from T_SESSION. Still tests that calls to CheckedClose() are
224 // OK, ie, tests bug fix, but doesn't check returned error values since remote drive
225 // doesn't necessarily return them.
231 aTest.Next(_L("Test calls to CheckedClose are OK"));
233 TInt r=iFs.SetSessionPath(iSessionPath);
236 r=format.Open(iFs,_L("Z:\\"),EFullFormat,count);
238 aTest((r==KErrAccessDenied)||(r==KErrInUse));
240 r=dir.Open(iFs,_L("\\MULTIPLE_SESSION_TEST\\ERRORTEST\\"),KEntryAttMatchMask);
241 // aTest(r==KErrPathNotFound);
245 r=file.Open(iFs,_L("\\MULTIPLE_SESSION_TEST\\SessionTest1.txt"),EFileRead);
246 // aTest(r==KErrNotFound);
250 r=dir.Open(iFs,_L("\\MULTIPLE_SESSION_TEST\\ERRORTEST2\\"),KEntryAttMatchMask);
251 // aTest(r==KErrPathNotFound);
255 r=file.Open(iFs,_L("\\MULTIPLE_SESSION_TEST\\SessionTest2.txt"),EFileRead);
256 // aTest(r==KErrNotFound);
260 r=dir.Open(iFs,_L("\\MULTIPLE_SESSION_TEST\\ERRORTEST3\\"),KEntryAttMatchMask);
261 // aTest(r==KErrPathNotFound);
265 r=file.Open(iFs,_L("\\MULTIPLE_SESSION_TEST\\SessionTest3.txt"),EFileRead);
266 // aTest(r==KErrNotFound);
270 r=file.Open(iFs,_L("\\MULTIPLE_SESSION_TEST\\SessionTest4.txt"),EFileRead);
271 // aTest(r==KErrNotFound);
277 void TMultipleSessionTest::testSubst(RTest& aTest)
279 // Test the substitute functions
283 aTest.Next(_L("Test subst"));
284 TInt r=iFs.SetSessionPath(iSessionPath);
289 TDriveInfo driveInfo;
290 r=iFs.Drive(driveInfo,EDriveO);
293 testSetVolume(aTest);
295 if (driveInfo.iDriveAtt==KDriveAttLocal)
296 return; // Subst local drives fails
299 r=iFs.Subst(n,EDriveO);
301 aTest(n.Length()==0);
302 r=iFs.SetSubst(iSessionPath,EDriveO);
304 r=iFs.Subst(n,EDriveO);
306 aTest(n==iSessionPath);
308 r=iFs.Volume(w,EDriveO);
310 aTest(w.iDrive.iType==v.iDrive.iType);
311 aTest(w.iDrive.iConnectionBusType==v.iDrive.iConnectionBusType);
312 aTest(w.iDrive.iDriveAtt==v.iDrive.iDriveAtt);
313 aTest(w.iDrive.iMediaAtt==v.iDrive.iMediaAtt);
314 aTest(w.iUniqueID==v.iUniqueID);
315 aTest(w.iSize==v.iSize);
316 aTest(w.iFree==v.iFree);
317 aTest(w.iName==v.iName);
319 r=iFs.Drive(d,EDriveO);
321 aTest(d.iDriveAtt==KDriveAttSubsted);
323 aTest.Next(_L("Test real name"));
324 r=iFs.RealName(_L("O:\\FILE.XXX"),n);
326 TFileName substedPath=iSessionPath;
327 substedPath.Append(_L("FILE.XXX"));
328 aTest(n==substedPath);
330 aTest.Next(_L("Test MkDir, Rename and RmDir on Substed drive"));
331 r=iFs.MkDir(_L("C:\\MULTIPLE_SESSION_TEST\\TFSRV\\turgid\\"));
333 r=iFs.Rename(_L("O:\\turgid"), _L("O:\\facile"));
335 r=iFs.MkDir(_L("O:\\insipid\\"));
337 r=iFs.Rename(_L("O:\\insipid"), _L("O:\\glib"));
339 r=iFs.RmDir(_L("O:\\facile\\"));
341 r=iFs.RmDir(_L("C:\\MULTIPLE_SESSION_TEST\\TFSRV\\glib\\"));
344 r=iFs.SetSubst(_L(""),EDriveO);
346 r=iFs.Subst(n,EDriveO);
349 r=iFs.Drive(d,EDriveO);
351 aTest(d.iDriveAtt==0);
356 LOCAL_C TInt CreateFileX(const TDesC& aBaseName,TInt aX, RFs iFs, RTest& aTest)
358 // Create a large file. Return KErrEof or KErrNone
362 TBuf<128> fileName=aBaseName;
363 fileName.AppendNum(aX);
366 TInt r=file.Replace(iFs,fileName,EFileWrite);
371 aTest.Printf(_L("ERROR:: Replace returned %d\n"),r);
373 return(KErrDiskFull);
375 r=file.SetSize(65536);
383 aTest.Printf(_L("ERROR:: SetSize returned %d\n"),r);
386 return(KErrDiskFull);
389 aTest.Printf(_L("Created file %d size 64k\n"),aX);
393 LOCAL_C TInt DeleteFileX(TBuf<128>& aBaseName,TInt aX, RFs iFs, TInt aDrive,RTest& aTest)
399 TBuf<128> fileName=aBaseName;
400 fileName.AppendNum(aX);
402 TInt r=iFs.Delete(fileName);
403 if (aDrive!=EDriveQ) // T_REMFSY may return incorrect value on WINS
405 aTest.Printf(_L("Deleted File %d\n"),aX);
409 void TMultipleSessionTest::MakeAndDeleteFiles(RTest& aTest)
411 // Create and delete large files in a randomish order
415 aTest.Next(_L("Create and delete large files"));
416 TInt r=iFs.SetSessionPath(iSessionPath);
417 r=iFs.MkDirAll(_L("\\MULTIPLE_SESSION_TEST\\SMALLDIRECTORY\\"));
419 if (CurrentDrive(aTest)!=EDriveQ) // T_REMFSY may return incorrect result on WINS
420 aTest(r==KErrNone || r==KErrAlreadyExists);
422 TBuf<128> fileName=_L("\\MULTIPLE_SESSION_TEST\\SMALLDIRECTORY\\FILE");
423 r=CreateFileX(fileName,0,iFs,aTest);
425 r=CreateFileX(fileName,1,iFs,aTest);
427 r=DeleteFileX(fileName,0,iFs,CurrentDrive(aTest),aTest);
429 r=CreateFileX(fileName,2,iFs,aTest);
431 r=CreateFileX(fileName,1,iFs,aTest);
433 r=CreateFileX(fileName,3,iFs,aTest);
435 r=DeleteFileX(fileName,1,iFs,CurrentDrive(aTest),aTest);
437 r=CreateFileX(fileName,4,iFs,aTest);
439 r=DeleteFileX(fileName,2,iFs,CurrentDrive(aTest),aTest);
441 r=DeleteFileX(fileName,3,iFs,CurrentDrive(aTest),aTest);
443 r=DeleteFileX(fileName,4,iFs,CurrentDrive(aTest),aTest);
445 r=CreateFileX(fileName,1,iFs,aTest);
447 r=DeleteFileX(fileName,1,iFs,CurrentDrive(aTest),aTest);
450 r=iFs.CheckDisk(fileName);
451 if (r!=KErrNone && r!=KErrNotSupported)
452 aTest.Printf(_L("ERROR:: CheckDisk returned %d\n"),r);
455 void TMultipleSessionTest::FillUpDisk(RTest& aTest)
457 // Test that a full disk is ok
461 aTest.Next(_L("Fill disk to capacity"));
462 TInt r=iFs.SetSessionPath(iSessionPath);
463 r=iFs.MkDirAll(_L("\\MULTIPLE_SESSION_TEST\\BIGDIRECTORY\\"));
464 if (CurrentDrive(aTest)!=EDriveQ) // T_REMFSY may return incorrect result on WINS
465 aTest(r==KErrNone || r==KErrAlreadyExists);
467 TFileName sessionPath;
468 r=iFs.SessionPath(sessionPath);
469 test(sessionPath==iSessionPath);
471 TBuf<128> fileName=_L("\\MULTIPLE_SESSION_TEST\\BIGDIRECTORY\\FILE");
474 TInt r=CreateFileX(fileName,count,iFs, aTest);
479 #if defined(__WINS__)
480 if (count==32 && sessionPath[0]=='C') // Don't fill up disk on NT
485 r=iFs.CheckDisk(fileName);
486 if (r!=KErrNone && r!=KErrNotSupported)
488 aTest.Printf(_L("ERROR:: CheckDisk returned %d\n"),r);
493 DeleteFileX(fileName,count,iFs,CurrentDrive(aTest),aTest);
495 r=iFs.CheckDisk(fileName);
496 if (r!=KErrNone && r!=KErrNotSupported)
498 aTest.Printf(_L("ERROR:: CheckDisk returned %d\n"),r);
504 void TMultipleSessionTest::testSetVolume(RTest& aTest)
506 // Test setting the volume info.
510 aTest.Next(_L("Test setting the volume label"));
511 TInt r=iFs.SetSessionPath(iSessionPath);
513 #if defined(_UNICODE)
514 aTest.Printf(_L("Unicode volume label set not implemented ****\n"));
517 TInt driveNum=CurrentDrive(aTest);
519 r=iFs.Volume(v,driveNum);
522 aTest.Printf(_L("VOL=\"%S\"\n"),&n);
524 aTest.Next(_L("Set volume label to nothing"));
525 r=iFs.SetVolumeLabel(_L(""),driveNum);
529 r=iFs.Volume(v,driveNum);
531 aTest(v.iName==_L(""));
532 aTest.Printf(_L("VOL=\"%S\"\n"),&v.iName);
534 aTest.Next(_L("Set volume label to ABCDEFGHIJK"));
535 r=iFs.SetVolumeLabel(_L("ABCDEFGHIJK"),driveNum);
537 r=iFs.Volume(v,driveNum);
539 aTest(v.iName==_L("ABCDEFGHIJK"));
540 aTest.Printf(_L("VOL=\"%S\"\n"),&v.iName);
542 aTest.Next(_L("Set volume label back to nothing"));
543 r=iFs.SetVolumeLabel(_L(""),driveNum);
545 r=iFs.Volume(v,driveNum);
547 aTest(v.iName==_L(""));
548 aTest.Printf(_L("VOL=\"%S\"\n"),&v.iName);
550 aTest.Next(_L("Set volume label to original"));
551 r=iFs.SetVolumeLabel(n,driveNum);
553 r=iFs.Volume(v,driveNum);
556 aTest.Printf(_L("VOL=\"%S\"\n"),&v.iName);
562 LOCAL_C void printDriveAtt(TInt aDrive,TUint anAtt,RTest& aTest)
564 // Print a drive attribute.
568 aTest.Printf(_L("%c: "),aDrive+'A');
569 if (anAtt&KDriveAttRemote)
570 aTest.Printf(_L("REMOTE "));
571 else if (anAtt&KDriveAttLocal)
572 aTest.Printf(_L("LOCAL "));
573 if (anAtt&KDriveAttRom)
574 aTest.Printf(_L("ROM "));
575 if (anAtt&KDriveAttRedirected)
576 aTest.Printf(_L("REDIRECTED "));
577 if (anAtt&KDriveAttSubsted)
578 aTest.Printf(_L("SUBST "));
579 if (anAtt&KDriveAttInternal)
580 aTest.Printf(_L("INTERNAL "));
581 if (anAtt&KDriveAttRemovable)
582 aTest.Printf(_L("REMOVABLE "));
583 aTest.Printf(_L("\n"));
586 LOCAL_C void printDriveInfo(TInt aDrive,TDriveInfo& anInfo,RTest& aTest)
588 // Print a drive info.
592 printDriveAtt(aDrive,anInfo.iDriveAtt,aTest);
593 aTest.Printf(_L(" MEDIA-ATT="));
594 if (anInfo.iMediaAtt==0)
595 aTest.Printf(_L("<none>"));
596 if (anInfo.iMediaAtt&KMediaAttVariableSize)
597 aTest.Printf(_L("VariableSize "));
598 if (anInfo.iMediaAtt&KMediaAttDualDensity)
599 aTest.Printf(_L("DualDensity "));
600 if (anInfo.iMediaAtt&KMediaAttFormattable)
601 aTest.Printf(_L("Formattable "));
602 if (anInfo.iMediaAtt&KMediaAttWriteProtected)
603 aTest.Printf(_L("WProtected "));
604 aTest.Printf(_L("\n CONNECTION BUS TYPE="));
605 switch(anInfo.iConnectionBusType)
607 case EConnectionBusInternal: aTest.Printf(_L("Internal\n")); break;
608 case EConnectionBusUsb: aTest.Printf(_L("USB\n")); break;
610 aTest.Printf(_L("Unknown value\n"));
612 aTest.Printf(_L(" MEDIA="));
615 case EMediaNotPresent: aTest.Printf(_L("Not present\n")); break;
616 case EMediaUnknown: aTest.Printf(_L("Unknown\n")); break;
617 case EMediaFloppy: aTest.Printf(_L("Floppy\n")); break;
618 case EMediaHardDisk: aTest.Printf(_L("Hard disk\n")); break;
619 case EMediaCdRom: aTest.Printf(_L("CD Rom\n")); break;
620 case EMediaRam: aTest.Printf(_L("Ram\n")); break;
621 case EMediaFlash: aTest.Printf(_L("Flash\n")); break;
622 case EMediaRom: aTest.Printf(_L("Rom\n")); break;
623 case EMediaRemote: aTest.Printf(_L("Remote\n")); break;
625 aTest.Printf(_L("Unknown value\n"));
629 LOCAL_C void DriveInformation(TInt aDrive,TDriveInfo& anInfo,RTest& aTest)
631 // Test the drive info is reasonable
635 aTest(anInfo.iConnectionBusType==EConnectionBusInternal || anInfo.iConnectionBusType==EConnectionBusUsb);
639 if (anInfo.iType==EMediaNotPresent)
642 aTest(anInfo.iMediaAtt==KMediaAttWriteProtected);
643 aTest(anInfo.iDriveAtt==(KDriveAttRom|KDriveAttInternal));
644 aTest(anInfo.iType==EMediaRom);
647 else if (aDrive==EDriveC || aDrive==EDriveY)
649 if (anInfo.iType==EMediaNotPresent)
652 aTest(anInfo.iDriveAtt==(KDriveAttLocal|KDriveAttInternal));
653 aTest(anInfo.iType==EMediaHardDisk);
654 aTest(anInfo.iMediaAtt==(KMediaAttVariableSize|KMediaAttFormattable));
656 else if (aDrive==EDriveD || aDrive==EDriveX)
658 if (anInfo.iType==EMediaNotPresent)
661 aTest(anInfo.iDriveAtt==(KDriveAttLocal|KDriveAttRemovable));
662 aTest(anInfo.iType==EMediaHardDisk);
663 aTest(anInfo.iMediaAtt==KMediaAttFormattable);
669 GLDEF_C void ReportCheckDiskFailure(TInt aRet,RTest& aTest)
671 // Report the failure of checkdisk
675 aTest.Printf(_L("CHECKDISK FAILED: "));
678 case 1: aTest.Printf(_L("File cluster chain contains a bad value (<2 or >maxCluster)\n")); break;
679 case 2: aTest.Printf(_L("Two files are linked to the same cluster\n")); break;
680 case 3: aTest.Printf(_L("Unallocated cluster contains a value != 0\n")); break;
681 case 4: aTest.Printf(_L("Size of file != number of clusters in chain\n")); break;
682 default: aTest.Printf(_L("Undefined Error value %d\n"),aRet);
684 aTest.Printf(_L("Press any key to continue\n"));
690 TInt TMultipleSessionTest::CurrentDrive(RTest& aTest)
692 // Return the current drive number
695 TInt r=iFs.SetSessionPath(iSessionPath);
698 r=iFs.CharToDrive(iSessionPath[0],driveNum);