diff -r 000000000000 -r a41df078684a kerneltest/f32test/fsstress/t_sesfs.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/f32test/fsstress/t_sesfs.cpp Mon Oct 19 15:55:17 2009 +0100 @@ -0,0 +1,808 @@ +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// f32test\fsstress\t_sesfs.cpp +// +// +#define __E32TEST_EXTENSION__ +#include "t_sess.h" + +GLDEF_D TFileName tPath; +GLREF_D TFileName gExeFileName; + +LOCAL_C void printDriveAtt(TInt aDrive,TUint anAtt); +LOCAL_C void printDriveInfo(TInt aDrive,TDriveInfo& anInfo); +LOCAL_C void DriveInfo(TInt aDrive,TDriveInfo& anInfo); + + +void TSessionTest::Initialise(RFs& aFs) +// +// Initialise iFs +// + { + iFs=aFs; + } + + +void TSessionTest::RunTests() +// +// Run tests on iFs file server session +// + + { + + testDriveList(); + testDriveInfo(); + testVolumeInfo(); + testSetVolume(); + testPath(); + CreateTestDirectory(_L("\\SESSION_TEST\\TFSRV\\")); + testInitialisation(); + testSubst(); + CopyFileToTestDirectory(); + MakeAndDeleteFiles(); + } + + + +void TSessionTest::testDriveList() +// +// Test the drive list. +// + { + + test.Start(_L("The drive list")); + TDriveList list; + TDriveInfo info; + TInt r=iFs.DriveList(list); + test_KErrNone(r); + for (TInt i=0;i fileName=aBaseName; + fileName.AppendNum(aX); + RFile file; + TInt r=file.Replace(iFs,fileName,EFileWrite); + if (r==KErrDiskFull) + return(r); + if (r!=KErrNone) + { + test.Printf(_L("ERROR:: Replace returned %d\n"),r); + return(KErrDiskFull); + } + r=file.SetSize(65536); + if (r==KErrDiskFull) + { + file.Close(); + return(r); + } + if (r!=KErrNone) + { + test.Printf(_L("ERROR:: SetSize returned %d\n"),r); + file.Close(); + return(KErrDiskFull); + } + file.Close(); +// r=iFs.CheckDisk(fileName); +// if (r!=KErrNone && r!=KErrNotSupported) +// { +// test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r); +// test.Getch(); +// return(KErrDiskFull); +// } + test.Printf(_L("Created file %d size 64k\n"),aX); + return(KErrNone); + } + +LOCAL_C TInt DeleteFileX(TBuf<128>& aBaseName,TInt aX, RFs iFs) +// +// Delete a file. +// + { + + TBuf<128> fileName=aBaseName; + fileName.AppendNum(aX); + TInt r=iFs.Delete(fileName); + test_KErrNone(r); +// r=iFs.CheckDisk(fileName); +// if (r!=KErrNone && r!=KErrNotSupported) +// { +// test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r); +// test_KErrNone(r); +// } + test.Printf(_L("Deleted File %d\n"),aX); + return(KErrNone); + } + +void TSessionTest::MakeAndDeleteFiles() +// +// Create and delete large files in a randomish order +// + { + + test.Start(_L("Create and delete large files")); + TInt r=iFs.MkDirAll(_L("\\SESSION_TEST\\SMALLDIRECTORY\\")); + test_Value(r, r==KErrNone || r==KErrAlreadyExists); + TBuf<128> fileName=_L("\\SESSION_TEST\\SMALLDIRECTORY\\FILE"); + r=CreateFileX(fileName,0,iFs); + test_KErrNone(r); + r=CreateFileX(fileName,1,iFs); + test_KErrNone(r); + r=DeleteFileX(fileName,0,iFs); + test_KErrNone(r); + r=CreateFileX(fileName,2,iFs); + test_KErrNone(r); + r=CreateFileX(fileName,1,iFs); + test_KErrNone(r); + r=CreateFileX(fileName,3,iFs); + test_KErrNone(r); + r=DeleteFileX(fileName,1,iFs); + test_KErrNone(r); + r=CreateFileX(fileName,4,iFs); + test_KErrNone(r); + r=DeleteFileX(fileName,2,iFs); + test_KErrNone(r); + r=DeleteFileX(fileName,3,iFs); + test_KErrNone(r); + r=DeleteFileX(fileName,4,iFs); + test_KErrNone(r); + r=CreateFileX(fileName,1,iFs); + test_KErrNone(r); + r=DeleteFileX(fileName,1,iFs); + test_KErrNone(r); + + r=iFs.CheckDisk(fileName); + test_Value(r, r==KErrNone || r==KErrNotSupported); + test.End(); + } + +void TSessionTest::FillUpDisk() +// +// Test that a full disk is ok +// + { + + test.Start(_L("Fill disk to capacity")); + TInt r=iFs.MkDirAll(_L("\\SESSION_TEST\\BIGDIRECTORY\\")); + test_Value(r, r==KErrNone || r==KErrAlreadyExists); + TInt count=0; + TFileName sessionPath; + r=iFs.SessionPath(sessionPath); + test_KErrNone(r); + TBuf<128> fileName=_L("\\SESSION_TEST\\BIGDIRECTORY\\FILE"); + FOREVER + { + TInt r=CreateFileX(fileName,count,iFs); + if (r==KErrDiskFull) + break; + test_KErrNone(r); + count++; + #if defined(__WINS__) + if (count==32 && sessionPath[0]=='C') // Don't fill up disk on NT + break; + #endif + } + + r=iFs.CheckDisk(fileName); + test_Value(r, r==KErrNone || r==KErrNotSupported); + + while(count--) + DeleteFileX(fileName,count,iFs); + + r=iFs.CheckDisk(fileName); + test_Value(r, r==KErrNone || r==KErrNotSupported); + + test.End(); + } + +void TSessionTest::CopyFileToTestDirectory() +// +// Make a copy of the file in ram +// + { + + TFileName fn = _L("Z:\\TEST\\T_FSRV.CPP"); + fn[0] = gExeFileName[0]; + TParse f; + TInt r=iFs.Parse(fn,f); + test_KErrNone(r); + test.Next(_L("Copying file to test directory")); + TParse fCopy; + r=iFs.Parse(f.NameAndExt(),fCopy); + test_KErrNone(r); + + RFile f1; + r=f1.Open(iFs,f.FullName(),EFileStreamText|EFileShareReadersOnly); + test.Printf(_L("r=%d\n"),r); + test_KErrNone(r); + RFile f2; + r=f2.Replace(iFs,fCopy.FullName(),EFileWrite); + test_KErrNone(r); + TBuf8<512> copyBuf; + TInt rem; + r=f1.Size(rem); + test_KErrNone(r); + TInt pos=0; + while (rem) + { + TInt s=Min(rem,copyBuf.MaxSize()); + r=f1.Read(pos,copyBuf,s); + test_KErrNone(r); + test(copyBuf.Length()==s); + r=f2.Write(pos,copyBuf,s); + test_KErrNone(r); + pos+=s; + rem-=s; + } + f1.Close(); + f2.Close(); + } + + +void TSessionTest::testSetVolume() +// +// Test setting the volume info. +// + { + + test.Start(_L("Test setting the volume label")); + +#if defined(_UNICODE) + test.Printf(_L("Unicode volume label set not implemented ****\n")); + test.End(); + return; +#else + TInt driveNum=CurrentDrive(); + TVolumeInfo v; + TInt r=iFs.Volume(v,driveNum); + test_KErrNone(r); + TFileName n=v.iName; + test.Printf(_L("VOL=\"%S\"\n"),&n); + + test.Next(_L("Set volume label to nothing")); + r=iFs.SetVolumeLabel(_L(""),driveNum); +#if defined(__WINS__) + if (r==KErrGeneral || r==KErrAccessDenied || r==KErrNotSupported) + { + test.Printf(_L("Error %d: Set volume label not testing on WINS\n"),r); + test.End(); + return; + } +#endif + test_KErrNone(r); + r=iFs.Volume(v,driveNum); + test_KErrNone(r); + test(v.iName==_L("")); + test.Printf(_L("VOL=\"%S\"\n"),&v.iName); + + test.Next(_L("Set volume label to ABCDEFGHIJK")); + r=iFs.SetVolumeLabel(_L("ABCDEFGHIJK"),driveNum); + test_KErrNone(r); + r=iFs.Volume(v,driveNum); + test_KErrNone(r); + test(v.iName==_L("ABCDEFGHIJK")); + test.Printf(_L("VOL=\"%S\"\n"),&v.iName); + + test.Next(_L("Set volume label back to nothing")); + r=iFs.SetVolumeLabel(_L(""),driveNum); + test_KErrNone(r); + r=iFs.Volume(v,driveNum); + test_KErrNone(r); + test(v.iName==_L("")); + test.Printf(_L("VOL=\"%S\"\n"),&v.iName); + + test.Next(_L("Set volume label to original")); + r=iFs.SetVolumeLabel(n,driveNum); + test_KErrNone(r); + r=iFs.Volume(v,driveNum); + test_KErrNone(r); + test(v.iName==n); + test.Printf(_L("VOL=\"%S\"\n"),&v.iName); + + test.End(); +#endif + } + +LOCAL_C void printDriveAtt(TInt aDrive,TUint anAtt) +// +// Print a drive attribute. +// + { + + test.Printf(_L("%c: "),aDrive+'A'); + if (anAtt&KDriveAttLocal) + test.Printf(_L("LOCAL ")); + if (anAtt&KDriveAttRom) + test.Printf(_L("ROM ")); + if (anAtt&KDriveAttRedirected) + test.Printf(_L("REDIR ")); + if (anAtt&KDriveAttSubsted) + test.Printf(_L("SUBST ")); + if (anAtt&KDriveAttInternal) + test.Printf(_L("INTERNAL ")); + if ((anAtt&KDriveAttRemovable) && !(anAtt&KDriveAttLogicallyRemovable)) + test.Printf(_L("PHYSICALLY-REMOVABLE ")); + if (anAtt&KDriveAttLogicallyRemovable) + test.Printf(_L("LOGICALLY-REMOVABLE ")); + if (anAtt&KDriveAttHidden) + test.Printf(_L("HIDDEN ")); + test.Printf(_L("\n")); + } + +LOCAL_C void printDriveInfo(TInt aDrive,TDriveInfo& anInfo) +// +// Print a drive info. +// + { + + printDriveAtt(aDrive,anInfo.iDriveAtt); + test.Printf(_L(" MEDIA-ATT=")); + if (anInfo.iMediaAtt==0) + test.Printf(_L("")); + if (anInfo.iMediaAtt&KMediaAttVariableSize) + test.Printf(_L("VariableSize ")); + if (anInfo.iMediaAtt&KMediaAttDualDensity) + test.Printf(_L("DualDensity ")); + if (anInfo.iMediaAtt&KMediaAttFormattable) + test.Printf(_L("Formattable ")); + if (anInfo.iMediaAtt&KMediaAttWriteProtected) + test.Printf(_L("WProtected ")); + test.Printf(_L("\n BATTERY=")); + switch(anInfo.iBattery) + { + case EBatNotSupported: test.Printf(_L("Not supported\n")); break; + case EBatGood: test.Printf(_L("Good\n")); break; + case EBatLow: test.Printf(_L("Low\n")); break; + default: + test.Printf(_L("Unknown value\n")); + } + test.Printf(_L(" MEDIA=")); + switch(anInfo.iType) + { + case EMediaNotPresent: test.Printf(_L("Not present\n")); break; + case EMediaUnknown: test.Printf(_L("Unknown\n")); break; + case EMediaFloppy: test.Printf(_L("Floppy\n")); break; + case EMediaHardDisk: test.Printf(_L("Hard disk\n")); break; + case EMediaCdRom: test.Printf(_L("CD Rom\n")); break; + case EMediaRam: test.Printf(_L("Ram\n")); break; + case EMediaFlash: test.Printf(_L("Flash\n")); break; + case EMediaRom: test.Printf(_L("Rom\n")); break; + case EMediaRemote: test.Printf(_L("Remote\n")); break; + default: + test.Printf(_L("Unknown value\n")); + } + } + +LOCAL_C void DriveInfo(TInt aDrive,TDriveInfo& anInfo) +// +// Test the drive info is reasonable +// + { + + test(anInfo.iBattery==EBatLow || anInfo.iBattery==EBatGood || anInfo.iBattery==EBatNotSupported); + + if (aDrive==EDriveZ) + { + if (anInfo.iType==EMediaNotPresent) + return; + + test(anInfo.iMediaAtt==KMediaAttWriteProtected); + test(anInfo.iDriveAtt==(KDriveAttRom|KDriveAttInternal)); + test(anInfo.iType==EMediaRom); + } + +/* +Why assume certain drive letters can only refer to certain drive types? + else if (aDrive==EDriveC || aDrive==EDriveY) + { + if (anInfo.iType==EMediaNotPresent) + return; + +// test(anInfo.iDriveAtt==(KDriveAttLocal|KDriveAttInternal)); + + test(anInfo.iDriveAtt&(KDriveAttLocal|KDriveAttInternal)==KDriveAttLocal|KDriveAttInternal); // LFFS sets KDriveAttTransaction as well + test(anInfo.iType==EMediaRam || anInfo.iType==EMediaFlash); + if(anInfo.iType==EMediaRam) test(anInfo.iMediaAtt==(KMediaAttVariableSize|KMediaAttFormattable)); + else if(anInfo.iType==EMediaFlash) test(anInfo.iMediaAtt==KMediaAttFormattable); + } + + else if (aDrive==EDriveD || aDrive==EDriveX) + { + if (anInfo.iType==EMediaNotPresent) + return; + + test(anInfo.iDriveAtt==(KDriveAttLocal|KDriveAttRemovable)); + test(anInfo.iType==EMediaHardDisk); + test(anInfo.iMediaAtt&KMediaAttFormattable); + } +*/ + } + +void TSessionTest::CreateTestDirectory(const TDesC& aSessionPath) +// +// Create directory for test +// + { + TParsePtrC path(aSessionPath); + test(path.DrivePresent()==EFalse); + + TInt r=iFs.SetSessionPath(aSessionPath); + test_KErrNone(r); + r=iFs.SessionPath(gTestSessionPath); + test_KErrNone(r); + r=iFs.MkDirAll(gTestSessionPath); + test_Value(r, r==KErrNone || r==KErrAlreadyExists); + } + +TInt TSessionTest::CurrentDrive() +// +// Return the current drive number +// + { + + TInt driveNum; + TInt r=iFs.CharToDrive(gTestSessionPath[0],driveNum); + test_KErrNone(r); + return(driveNum); + } +