First public contribution.
1 // Copyright (c) 2001-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.
17 #ifndef __TF_WRITE_H__
18 #define __TF_WRITE_H__
25 EPanicGetDesInitialOverflow,
27 EPanicCompareDescOverflow,
33 GLREF_C void Panic( TPanicNo aPanic );
37 class MGeneralizedWrite
39 // Provides an generic interface to a write function which
40 // can be either the simple of thread version. Used to hide which
41 // version of the write function a test is using
45 virtual void Write(TInt aPos,const TDesC8& aSrc) = 0;
46 virtual void CheckedWrite(TInt aPos,const TDesC8& aSrc) = 0;
49 class TWriteBase: public MGeneralizedWrite
52 TWriteBase( CWriteTest& aOwner );
53 virtual void CheckedWrite(TInt aPos,const TDesC8& aSrc);
60 class TSimpleWrite : public TWriteBase
62 // Simple implementation of write function
66 TSimpleWrite( CWriteTest& aOwner );
67 virtual void Write( TInt aPos, const TDesC8& aSrc );
70 TBusLocalDrive& iDrive;
73 class TThreadWrite : public TWriteBase
75 // Thread implementation of write function
79 TThreadWrite( CWriteTest& aOwner );
80 virtual void Write(TInt aPos,const TDesC8& aSrc);
82 // Thread functions with offset, added by this class
83 void CheckedThreadWrite(TInt aPos, TInt aLength, const TDesC8& aSrc, TInt aDescOffset );
84 void CurrentThreadCheckedThreadWrite(TInt aPos, TInt aLength, const TDesC8& aSrc, TInt aDescOffset );
87 TBusLocalDrive& iDrive;
88 const TInt iThreadHandle;
92 class CBlockManager : public CBase
94 // class used to control erasing and allocation of blocks
98 CBlockManager( TBusLocalDrive& iDrive, CWriteTest& aOwner );
103 void EraseBlock( TInt aBlockNumber );
104 void EraseAllBlocks();
105 void VerifyErased( TInt aBlockNumber );
107 void InitialiseSequentialBlockAllocator();
108 TInt NextErasedBlock();
110 void InitialiseDataChunkAllocator();
111 TUint NextErasedDataChunk( TInt aRequiredLength, TInt aMultiple=4 );
114 inline TInt BlockCount() const;
115 inline TInt BlockSize() const;
116 inline TInt FlashSize() const;
117 inline TUint BlockAddress( TInt aBlockNumber ) const;
120 TBusLocalDrive& iDrive;
121 TBuf8<512> iReadBuffer;
131 TEraseStatus* iEraseArray;
141 class CWriteTest : public CBase
150 TBool CompareAgainstFlash( TInt aFlashOffset, const TDesC8& aDes );
151 TBool CompareAgainstFlash( TInt aFlashOffset, TInt aLength, const TDesC8& aDes, TInt aDescOffset );
153 inline const TUint8* ChunkBase() const;
154 inline TBusLocalDrive& Drive();
155 inline TInt DummyThreadHandle() const;
158 static TInt DummyThread( TAny* aParam );
160 void CreateRandomData( TDes8& aDestBuf, TInt aLength );
161 TBool CheckOnes( TUint aFlashOffset, TInt aLength );
162 void CreateTestData( TInt aBlockNumber, TBool aEndOfBlock );
164 void SimpleWriteTest();
165 void SimpleThreadWriteTest();
166 void DoSimpleWriteTest( MGeneralizedWrite& aWriter );
168 void AlignedWriteTest();
169 void AlignedThreadWriteTest();
170 void DoAlignedWriteTest( MGeneralizedWrite& aWriter );
172 void UnalignedWriteTest();
173 void UnalignedThreadWriteTest();
174 void DoUnalignedWriteTest( MGeneralizedWrite& aWriter );
176 void OffsetDescriptorAlignedWriteTest();
177 void OffsetDescriptorUnalignedWriteTest();
178 void OffsetDescriptorCurrentThreadAlignedWriteTest();
179 void OffsetDescriptorCurrentThreadUnalignedWriteTest();
181 void JoinedWriteTest();
182 void JoinedThreadWriteTest();
184 void SingleBitOverwriteTest();
185 void TwoBitOverwriteTest();
187 void RunSimulationTest();
191 TBusLocalDrive iDrive;
193 TBuf8<512> iReadBuffer;
194 CBlockManager* iBlocks;
196 TRandomGenerator iRandom;
198 TSimpleWrite* iSimpleWriter;
199 TThreadWrite* iThreadWriter;
201 RThread iDummyThread;
207 inline TBusLocalDrive& CWriteTest::Drive()
212 inline TInt CWriteTest::DummyThreadHandle() const
214 return iDummyThread.Handle();