sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\fsstress\t_remses.cpp sl@0: // sl@0: // sl@0: sl@0: #if !defined(__T_REMFSY_H__) sl@0: #include "t_remfsy.h" sl@0: #endif sl@0: sl@0: GLDEF_D TFileName tPath; sl@0: sl@0: LOCAL_C void printDriveAtt(TInt aDrive,TUint anAtt,RTest& aTest); sl@0: LOCAL_C void printDriveInfo(TInt aDrive,TDriveInfo& anInfo, RTest& aTest); sl@0: LOCAL_C void DriveInformation(TInt aDrive,TDriveInfo& anInfo,RTest& aTest); sl@0: sl@0: sl@0: void TMultipleSessionTest::Initialise(RFs& aFs) sl@0: // sl@0: // Initialise iFs sl@0: // sl@0: { sl@0: iFs=aFs; sl@0: } sl@0: sl@0: sl@0: void TMultipleSessionTest::SetSessionPath(TInt aDrive) sl@0: // sl@0: // Set the session path for a RFs connection to aDrive sl@0: // sl@0: { sl@0: iSessionPath=(_L("?:\\MULTIPLE_SESSION_TEST\\")); sl@0: TChar driveLetter; sl@0: TInt r=iFs.DriveToChar(aDrive,driveLetter); sl@0: test(r==KErrNone); sl@0: sl@0: iSessionPath[0]=(TText)driveLetter; sl@0: r=iFs.SetSessionPath(iSessionPath); sl@0: test(r==KErrNone); sl@0: r=iFs.MkDirAll(iSessionPath); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: } sl@0: sl@0: sl@0: void TMultipleSessionTest::RunTests(RTest& aTest) sl@0: // sl@0: // Run tests on iFs file server session sl@0: // sl@0: sl@0: { sl@0: sl@0: testDriveList(aTest); sl@0: testDriveInfo(aTest); sl@0: testVolumeInfo(aTest); sl@0: // testPowerDown(aTest); sl@0: testSetVolume(aTest); sl@0: testInitialisation(aTest); sl@0: // testMediaChange(aTest); sl@0: testSubst(aTest); sl@0: MakeAndDeleteFiles(aTest); sl@0: } sl@0: sl@0: sl@0: sl@0: void TMultipleSessionTest::testDriveList(RTest& aTest) sl@0: // sl@0: // Test the drive list. sl@0: // sl@0: { sl@0: sl@0: aTest.Next(_L("The drive list")); sl@0: TInt r=iFs.SetSessionPath(iSessionPath); sl@0: TDriveList list; sl@0: r=iFs.DriveList(list); sl@0: aTest(r==KErrNone); sl@0: sl@0: for (TInt i=0;iKMaxLocalDrives) sl@0: return; sl@0: sl@0: #if defined (__MARM__) sl@0: if (drive==EDriveC) sl@0: return; sl@0: #endif sl@0: sl@0: TLocalDrive theDrive; sl@0: TLocalDriveCaps info; sl@0: TBool changedFlag; sl@0: for (TInt index=0; index<5; index++) sl@0: { sl@0: aTest.Printf(_L("********** %d **********\n"),(5-index)); sl@0: changedFlag=EFalse; sl@0: TInt r=theDrive.Connect(drive,changedFlag); sl@0: aTest(r==KErrNone); sl@0: UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change sl@0: aTest(changedFlag); sl@0: sl@0: do sl@0: { sl@0: r=theDrive.Caps(info); sl@0: } while (r==KErrNotReady); sl@0: // Wait a second... sl@0: // User::After(1000000); sl@0: } sl@0: } sl@0: */ sl@0: sl@0: void TMultipleSessionTest::testVolumeInfo(RTest& aTest) sl@0: // sl@0: // Test volume info. sl@0: // sl@0: { sl@0: sl@0: aTest.Next(_L("The volume info")); sl@0: TInt r=iFs.SetSessionPath(iSessionPath); sl@0: TDriveList list; sl@0: r=iFs.DriveList(list); sl@0: aTest(r==KErrNone); sl@0: for (TInt i=0;i fileName=aBaseName; sl@0: fileName.AppendNum(aX); sl@0: sl@0: RFile file; sl@0: TInt r=file.Replace(iFs,fileName,EFileWrite); sl@0: if (r==KErrDiskFull) sl@0: return(r); sl@0: if (r!=KErrNone) sl@0: { sl@0: aTest.Printf(_L("ERROR:: Replace returned %d\n"),r); sl@0: aTest.Getch(); sl@0: return(KErrDiskFull); sl@0: } sl@0: r=file.SetSize(65536); sl@0: if (r==KErrDiskFull) sl@0: { sl@0: file.Close(); sl@0: return(r); sl@0: } sl@0: if (r!=KErrNone) sl@0: { sl@0: aTest.Printf(_L("ERROR:: SetSize returned %d\n"),r); sl@0: aTest.Getch(); sl@0: file.Close(); sl@0: return(KErrDiskFull); sl@0: } sl@0: file.Close(); sl@0: aTest.Printf(_L("Created file %d size 64k\n"),aX); sl@0: return(KErrNone); sl@0: } sl@0: sl@0: LOCAL_C TInt DeleteFileX(TBuf<128>& aBaseName,TInt aX, RFs iFs, TInt aDrive,RTest& aTest) sl@0: // sl@0: // Delete a file. sl@0: // sl@0: { sl@0: sl@0: TBuf<128> fileName=aBaseName; sl@0: fileName.AppendNum(aX); sl@0: sl@0: TInt r=iFs.Delete(fileName); sl@0: if (aDrive!=EDriveQ) // T_REMFSY may return incorrect value on WINS sl@0: aTest(r==KErrNone); sl@0: aTest.Printf(_L("Deleted File %d\n"),aX); sl@0: return(KErrNone); sl@0: } sl@0: sl@0: void TMultipleSessionTest::MakeAndDeleteFiles(RTest& aTest) sl@0: // sl@0: // Create and delete large files in a randomish order sl@0: // sl@0: { sl@0: sl@0: aTest.Next(_L("Create and delete large files")); sl@0: TInt r=iFs.SetSessionPath(iSessionPath); sl@0: r=iFs.MkDirAll(_L("\\MULTIPLE_SESSION_TEST\\SMALLDIRECTORY\\")); sl@0: sl@0: if (CurrentDrive(aTest)!=EDriveQ) // T_REMFSY may return incorrect result on WINS sl@0: aTest(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: TBuf<128> fileName=_L("\\MULTIPLE_SESSION_TEST\\SMALLDIRECTORY\\FILE"); sl@0: r=CreateFileX(fileName,0,iFs,aTest); sl@0: aTest(r==KErrNone); sl@0: r=CreateFileX(fileName,1,iFs,aTest); sl@0: aTest(r==KErrNone); sl@0: r=DeleteFileX(fileName,0,iFs,CurrentDrive(aTest),aTest); sl@0: aTest(r==KErrNone); sl@0: r=CreateFileX(fileName,2,iFs,aTest); sl@0: aTest(r==KErrNone); sl@0: r=CreateFileX(fileName,1,iFs,aTest); sl@0: aTest(r==KErrNone); sl@0: r=CreateFileX(fileName,3,iFs,aTest); sl@0: aTest(r==KErrNone); sl@0: r=DeleteFileX(fileName,1,iFs,CurrentDrive(aTest),aTest); sl@0: aTest(r==KErrNone); sl@0: r=CreateFileX(fileName,4,iFs,aTest); sl@0: aTest(r==KErrNone); sl@0: r=DeleteFileX(fileName,2,iFs,CurrentDrive(aTest),aTest); sl@0: aTest(r==KErrNone); sl@0: r=DeleteFileX(fileName,3,iFs,CurrentDrive(aTest),aTest); sl@0: aTest(r==KErrNone); sl@0: r=DeleteFileX(fileName,4,iFs,CurrentDrive(aTest),aTest); sl@0: aTest(r==KErrNone); sl@0: r=CreateFileX(fileName,1,iFs,aTest); sl@0: aTest(r==KErrNone); sl@0: r=DeleteFileX(fileName,1,iFs,CurrentDrive(aTest),aTest); sl@0: aTest(r==KErrNone); sl@0: sl@0: r=iFs.CheckDisk(fileName); sl@0: if (r!=KErrNone && r!=KErrNotSupported) sl@0: aTest.Printf(_L("ERROR:: CheckDisk returned %d\n"),r); sl@0: } sl@0: sl@0: void TMultipleSessionTest::FillUpDisk(RTest& aTest) sl@0: // sl@0: // Test that a full disk is ok sl@0: // sl@0: { sl@0: sl@0: aTest.Next(_L("Fill disk to capacity")); sl@0: TInt r=iFs.SetSessionPath(iSessionPath); sl@0: r=iFs.MkDirAll(_L("\\MULTIPLE_SESSION_TEST\\BIGDIRECTORY\\")); sl@0: if (CurrentDrive(aTest)!=EDriveQ) // T_REMFSY may return incorrect result on WINS sl@0: aTest(r==KErrNone || r==KErrAlreadyExists); sl@0: TInt count=0; sl@0: TFileName sessionPath; sl@0: r=iFs.SessionPath(sessionPath); sl@0: test(sessionPath==iSessionPath); sl@0: aTest(r==KErrNone); sl@0: TBuf<128> fileName=_L("\\MULTIPLE_SESSION_TEST\\BIGDIRECTORY\\FILE"); sl@0: FOREVER sl@0: { sl@0: TInt r=CreateFileX(fileName,count,iFs, aTest); sl@0: if (r==KErrDiskFull) sl@0: break; sl@0: aTest(r==KErrNone); sl@0: count++; sl@0: #if defined(__WINS__) sl@0: if (count==32 && sessionPath[0]=='C') // Don't fill up disk on NT sl@0: break; sl@0: #endif sl@0: } sl@0: sl@0: r=iFs.CheckDisk(fileName); sl@0: if (r!=KErrNone && r!=KErrNotSupported) sl@0: { sl@0: aTest.Printf(_L("ERROR:: CheckDisk returned %d\n"),r); sl@0: aTest.Getch(); sl@0: } sl@0: sl@0: while(count--) sl@0: DeleteFileX(fileName,count,iFs,CurrentDrive(aTest),aTest); sl@0: sl@0: r=iFs.CheckDisk(fileName); sl@0: if (r!=KErrNone && r!=KErrNotSupported) sl@0: { sl@0: aTest.Printf(_L("ERROR:: CheckDisk returned %d\n"),r); sl@0: aTest.Getch(); sl@0: } sl@0: } sl@0: sl@0: sl@0: void TMultipleSessionTest::testSetVolume(RTest& aTest) sl@0: // sl@0: // Test setting the volume info. sl@0: // sl@0: { sl@0: sl@0: aTest.Next(_L("Test setting the volume label")); sl@0: TInt r=iFs.SetSessionPath(iSessionPath); sl@0: aTest(r==KErrNone); sl@0: #if defined(_UNICODE) sl@0: aTest.Printf(_L("Unicode volume label set not implemented ****\n")); sl@0: return; sl@0: #else sl@0: TInt driveNum=CurrentDrive(aTest); sl@0: TVolumeInfo v; sl@0: r=iFs.Volume(v,driveNum); sl@0: aTest(r==KErrNone); sl@0: TFileName n=v.iName; sl@0: aTest.Printf(_L("VOL=\"%S\"\n"),&n); sl@0: sl@0: aTest.Next(_L("Set volume label to nothing")); sl@0: r=iFs.SetVolumeLabel(_L(""),driveNum); sl@0: if (r==KErrGeneral) sl@0: return; sl@0: aTest(r==KErrNone); sl@0: r=iFs.Volume(v,driveNum); sl@0: aTest(r==KErrNone); sl@0: aTest(v.iName==_L("")); sl@0: aTest.Printf(_L("VOL=\"%S\"\n"),&v.iName); sl@0: sl@0: aTest.Next(_L("Set volume label to ABCDEFGHIJK")); sl@0: r=iFs.SetVolumeLabel(_L("ABCDEFGHIJK"),driveNum); sl@0: aTest(r==KErrNone); sl@0: r=iFs.Volume(v,driveNum); sl@0: aTest(r==KErrNone); sl@0: aTest(v.iName==_L("ABCDEFGHIJK")); sl@0: aTest.Printf(_L("VOL=\"%S\"\n"),&v.iName); sl@0: sl@0: aTest.Next(_L("Set volume label back to nothing")); sl@0: r=iFs.SetVolumeLabel(_L(""),driveNum); sl@0: aTest(r==KErrNone); sl@0: r=iFs.Volume(v,driveNum); sl@0: aTest(r==KErrNone); sl@0: aTest(v.iName==_L("")); sl@0: aTest.Printf(_L("VOL=\"%S\"\n"),&v.iName); sl@0: sl@0: aTest.Next(_L("Set volume label to original")); sl@0: r=iFs.SetVolumeLabel(n,driveNum); sl@0: aTest(r==KErrNone); sl@0: r=iFs.Volume(v,driveNum); sl@0: aTest(r==KErrNone); sl@0: aTest(v.iName==n); sl@0: aTest.Printf(_L("VOL=\"%S\"\n"),&v.iName); sl@0: sl@0: #endif sl@0: } sl@0: sl@0: sl@0: LOCAL_C void printDriveAtt(TInt aDrive,TUint anAtt,RTest& aTest) sl@0: // sl@0: // Print a drive attribute. sl@0: // sl@0: { sl@0: sl@0: aTest.Printf(_L("%c: "),aDrive+'A'); sl@0: if (anAtt&KDriveAttRemote) sl@0: aTest.Printf(_L("REMOTE ")); sl@0: else if (anAtt&KDriveAttLocal) sl@0: aTest.Printf(_L("LOCAL ")); sl@0: if (anAtt&KDriveAttRom) sl@0: aTest.Printf(_L("ROM ")); sl@0: if (anAtt&KDriveAttRedirected) sl@0: aTest.Printf(_L("REDIRECTED ")); sl@0: if (anAtt&KDriveAttSubsted) sl@0: aTest.Printf(_L("SUBST ")); sl@0: if (anAtt&KDriveAttInternal) sl@0: aTest.Printf(_L("INTERNAL ")); sl@0: if (anAtt&KDriveAttRemovable) sl@0: aTest.Printf(_L("REMOVABLE ")); sl@0: aTest.Printf(_L("\n")); sl@0: } sl@0: sl@0: LOCAL_C void printDriveInfo(TInt aDrive,TDriveInfo& anInfo,RTest& aTest) sl@0: // sl@0: // Print a drive info. sl@0: // sl@0: { sl@0: sl@0: printDriveAtt(aDrive,anInfo.iDriveAtt,aTest); sl@0: aTest.Printf(_L(" MEDIA-ATT=")); sl@0: if (anInfo.iMediaAtt==0) sl@0: aTest.Printf(_L("")); sl@0: if (anInfo.iMediaAtt&KMediaAttVariableSize) sl@0: aTest.Printf(_L("VariableSize ")); sl@0: if (anInfo.iMediaAtt&KMediaAttDualDensity) sl@0: aTest.Printf(_L("DualDensity ")); sl@0: if (anInfo.iMediaAtt&KMediaAttFormattable) sl@0: aTest.Printf(_L("Formattable ")); sl@0: if (anInfo.iMediaAtt&KMediaAttWriteProtected) sl@0: aTest.Printf(_L("WProtected ")); sl@0: aTest.Printf(_L("\n CONNECTION BUS TYPE=")); sl@0: switch(anInfo.iConnectionBusType) sl@0: { sl@0: case EConnectionBusInternal: aTest.Printf(_L("Internal\n")); break; sl@0: case EConnectionBusUsb: aTest.Printf(_L("USB\n")); break; sl@0: default: sl@0: aTest.Printf(_L("Unknown value\n")); sl@0: } sl@0: aTest.Printf(_L(" MEDIA=")); sl@0: switch(anInfo.iType) sl@0: { sl@0: case EMediaNotPresent: aTest.Printf(_L("Not present\n")); break; sl@0: case EMediaUnknown: aTest.Printf(_L("Unknown\n")); break; sl@0: case EMediaFloppy: aTest.Printf(_L("Floppy\n")); break; sl@0: case EMediaHardDisk: aTest.Printf(_L("Hard disk\n")); break; sl@0: case EMediaCdRom: aTest.Printf(_L("CD Rom\n")); break; sl@0: case EMediaRam: aTest.Printf(_L("Ram\n")); break; sl@0: case EMediaFlash: aTest.Printf(_L("Flash\n")); break; sl@0: case EMediaRom: aTest.Printf(_L("Rom\n")); break; sl@0: case EMediaRemote: aTest.Printf(_L("Remote\n")); break; sl@0: default: sl@0: aTest.Printf(_L("Unknown value\n")); sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void DriveInformation(TInt aDrive,TDriveInfo& anInfo,RTest& aTest) sl@0: // sl@0: // Test the drive info is reasonable sl@0: // sl@0: { sl@0: sl@0: aTest(anInfo.iConnectionBusType==EConnectionBusInternal || anInfo.iConnectionBusType==EConnectionBusUsb); sl@0: sl@0: if (aDrive==EDriveZ) sl@0: { sl@0: if (anInfo.iType==EMediaNotPresent) sl@0: return; sl@0: sl@0: aTest(anInfo.iMediaAtt==KMediaAttWriteProtected); sl@0: aTest(anInfo.iDriveAtt==(KDriveAttRom|KDriveAttInternal)); sl@0: aTest(anInfo.iType==EMediaRom); sl@0: } sl@0: sl@0: else if (aDrive==EDriveC || aDrive==EDriveY) sl@0: { sl@0: if (anInfo.iType==EMediaNotPresent) sl@0: return; sl@0: sl@0: aTest(anInfo.iDriveAtt==(KDriveAttLocal|KDriveAttInternal)); sl@0: aTest(anInfo.iType==EMediaHardDisk); sl@0: aTest(anInfo.iMediaAtt==(KMediaAttVariableSize|KMediaAttFormattable)); sl@0: } sl@0: else if (aDrive==EDriveD || aDrive==EDriveX) sl@0: { sl@0: if (anInfo.iType==EMediaNotPresent) sl@0: return; sl@0: sl@0: aTest(anInfo.iDriveAtt==(KDriveAttLocal|KDriveAttRemovable)); sl@0: aTest(anInfo.iType==EMediaHardDisk); sl@0: aTest(anInfo.iMediaAtt==KMediaAttFormattable); sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: GLDEF_C void ReportCheckDiskFailure(TInt aRet,RTest& aTest) sl@0: // sl@0: // Report the failure of checkdisk sl@0: // sl@0: { sl@0: sl@0: aTest.Printf(_L("CHECKDISK FAILED: ")); sl@0: switch(aRet) sl@0: { sl@0: case 1: aTest.Printf(_L("File cluster chain contains a bad value (<2 or >maxCluster)\n")); break; sl@0: case 2: aTest.Printf(_L("Two files are linked to the same cluster\n")); break; sl@0: case 3: aTest.Printf(_L("Unallocated cluster contains a value != 0\n")); break; sl@0: case 4: aTest.Printf(_L("Size of file != number of clusters in chain\n")); break; sl@0: default: aTest.Printf(_L("Undefined Error value %d\n"),aRet); sl@0: } sl@0: aTest.Printf(_L("Press any key to continue\n")); sl@0: aTest.Getch(); sl@0: } sl@0: sl@0: sl@0: sl@0: TInt TMultipleSessionTest::CurrentDrive(RTest& aTest) sl@0: // sl@0: // Return the current drive number sl@0: // sl@0: { sl@0: TInt r=iFs.SetSessionPath(iSessionPath); sl@0: aTest(r==KErrNone); sl@0: TInt driveNum; sl@0: r=iFs.CharToDrive(iSessionPath[0],driveNum); sl@0: aTest(r==KErrNone); sl@0: return(driveNum); sl@0: } sl@0: sl@0: sl@0: sl@0: