diff -r 000000000000 -r 96e5fb8b040d kerneltest/f32test/server/t_rand.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/f32test/server/t_rand.cpp Thu Dec 17 09:24:54 2009 +0200 @@ -0,0 +1,527 @@ +// 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\server\t_rand.cpp +// +// + +#include +#include +#include +#include +#include "t_server.h" + +GLDEF_D RTest test(_L("T_RAND")); + +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 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 openning 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); + + // Flush if write caching enabled to ensure we get disk space notifications + if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone)) + r = f[fileNum].Flush(); + + 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