diff -r 000000000000 -r a41df078684a kerneltest/f32test/fsstress/t_ramstr.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/f32test/fsstress/t_ramstr.cpp Mon Oct 19 15:55:17 2009 +0100 @@ -0,0 +1,675 @@ +// Copyright (c) 1996-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_ramstr.cpp +// +// + +#include +#include +#include +#include +#include "t_stress.h" + +GLDEF_D RTest test(_L("T_RAMSTR")); + +LOCAL_D TBuf8<512> testBuf(512); +LOCAL_D TInt64 TheSeed=917824; +LOCAL_D TInt KMaxIteration; +LOCAL_D const TInt KMaxFiles=4; +LOCAL_D const TInt KMaxLengthIncrement=7770; +LOCAL_D const TInt mult[] = { 1, 5, 13, 37}; +LOCAL_D const TInt KReduceSizeFrequency=20; // 1 reduce in ?? iterations +LOCAL_D const TInt KCheckFileFrequency=20000; // 1 check in ?? iterations +LOCAL_D const TInt KMaxBufferLength=0x8000; + +LOCAL_C TInt CreateFileEx(const TDesC& aBaseName,TInt aX, TInt anInitialSize) +// +// Create a single cluster file +// + { + TBuf<128> fileName=aBaseName; + fileName.AppendNum(aX); + RFile file; + TInt r=file.Replace(TheFs,fileName,EFileWrite); + if (r==KErrDiskFull) + return(r); + if (r!=KErrNone) + { + test.Printf(_L("ERROR:: Replace returned %d\n"),r); + test.Getch(); + return(r); + } + + r=file.SetSize(anInitialSize); + file.Close(); + if (r==KErrDiskFull) + return(r); + + if (r!=KErrNone) + { + test.Printf(_L("ERROR:: SetSize returned %d\n"),r); + test.Getch(); + return(r); + } + +// r=TheFs.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 %d\n"),aX, anInitialSize); + return(KErrNone); + } + +LOCAL_C TInt DeleteFileEx(TBuf<128>& aBaseName,TInt aX) +// +// Delete a file. +// + { + + TBuf<128> fileName=aBaseName; + fileName.AppendNum(aX); + TInt r=TheFs.Delete(fileName); + test(r==KErrNone); +// r=TheFs.CheckDisk(fileName); +// if (r!=KErrNone && r!=KErrNotSupported) +// { +// test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r); +// test(r==KErrNone); +// } + test.Printf(_L("Deleted File %d\n"),aX); + return(KErrNone); + } + +LOCAL_C void WriteCluster(RFile& aFile,TInt aCluster) +// +// Extend aFile by 1 cluster +// + { + TUint8* bufPtr=(TUint8*)testBuf.Ptr(); + testBuf.SetLength(testBuf.MaxSize()); + Mem::Fill(bufPtr,testBuf.MaxSize(),aCluster); + TInt r=aFile.Write(testBuf); + test(r==KErrNone); + } + +LOCAL_C void SeekToCluster(RFile& aFile,TInt aCluster) +// +// Seek to aCluster and check it is found correctly +// + { + TBuf8<508> seekBuf(508); + TInt r=aFile.Read(aCluster*testBuf.MaxSize(),seekBuf); + test(r==KErrNone); + test(seekBuf[0]==(TUint8)aCluster && seekBuf[507]==(TUint8)aCluster); + } + +LOCAL_C void SeekToCluster(RFile& aFile,TInt aCluster1,TInt aCluster2) +// +// Seek to aCluster and check it is found correctly +// + { + TBuf8<508> seekBuf(508); + TInt r=aFile.Read(aCluster1*testBuf.MaxSize(),seekBuf); + test(r==KErrNone); + test(seekBuf[0]==(TUint8)aCluster1 && seekBuf[507]==(TUint8)aCluster1); + r=aFile.Read(aCluster2*testBuf.MaxSize(),seekBuf); + test(r==KErrNone); + test(seekBuf[0]==(TUint8)aCluster2 && seekBuf[507]==(TUint8)aCluster2); + } + +LOCAL_C void ExhaustiveTest(RFile& aFile,TInt aCount1) +// +// Test every possible seeking combination +// + { + TInt i=0,k=0; + for(k=0;k0;i--) + { + SeekToCluster(aFile,i); + SeekToCluster(aFile,k); + } + test.Printf(_L("Seek from %d \r"),k); + } + test.Printf(_L("\n")); + } + +LOCAL_C void Test1() +// +// Test opening a large file +// + { + test.Next(_L("Create interleaved files")); + RFile f1,f2; + + TInt r=f1.Replace(TheFs,_L("BIGFILE1.TST"),EFileWrite); + test(r==KErrNone); + r=f2.Replace(TheFs,_L("BIGFILE2.TST"),EFileWrite); + test(r==KErrNone); + + TInt maxListLength=4; + TInt i=0,k=0; + TInt countf1=0; + TInt countf2=0; + for (k=0;k iData; + TInt iPos; + }; + +TFileReader::TFileReader(RFile* aFile) +// +// Constructor +// + : iFile(*aFile), iPos(0) + { + + TInt r=iFile.Read(0,iData); + test(r==KErrNone); + } + +void TFileReader::Next(TUint8& aVal,TInt& aLength) +// +// Read aLength contiguous bytes with aVal +// + { + + if (iPos==iData.Length()) + { + TInt r=iFile.Read(iData); + test(r==KErrNone); + iPos=0; + if (iData.Length()==0) + { + aLength=0; + return; + } + } + + aVal=iData[iPos]; + aLength=0; + while(iPosPtr(); + Mem::Fill(data,KMaxBufferLength,value); + + if (pos+len>size) + size=pos+len; + + for (TInt i=0;i0) + { + TInt l=(s>KMaxBufferLength) ? KMaxBufferLength : s; + dataBuf->Des().SetLength(l); + r=f[fileNum].Write(*dataBuf); + if (r==KErrDiskFull) + goto End; + test(r==KErrNone); + s-=l; + } + + } + + if ((iteration%KCheckFileFrequency)==0) + CheckFileContents(&f[0]); + + test.Printf(_L("Iteration %d, size %d \r"),iteration,size); + if (iteration==KMaxIteration) + break; + + if ((iteration%KReduceSizeFrequency)==0) + { + size=(size) ? Math::Rand(TheSeed)%size : 0; + test.Printf(_L("\nReduceSize newsize=%d\n"),size); + for (TInt i=0;i fileName=_L("\\F32-TST\\BIGDIRECTORY\\FILE"); + + for (;indexhalfCount; index--) + DeleteFileEx(fileName,index); + + TBuf<128> baseName; + RFile file; +// Double the size of those files remaining + for (index=0; index