sl@0: // Copyright (c) 2001-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: // sl@0: sl@0: sl@0: #ifndef __TF_WRITE_H__ sl@0: #define __TF_WRITE_H__ sl@0: sl@0: #include sl@0: sl@0: enum TPanicNo sl@0: { sl@0: EPanicGetDesOverflow, sl@0: EPanicGetDesInitialOverflow, sl@0: EPanicCheckOverflow, sl@0: EPanicCompareDescOverflow, sl@0: EPanicEraseBlockOOR, sl@0: EPanicEraseBlockNeg, sl@0: EPanicJoinMaths sl@0: }; sl@0: sl@0: GLREF_C void Panic( TPanicNo aPanic ); sl@0: sl@0: class CWriteTest; sl@0: sl@0: class MGeneralizedWrite sl@0: // sl@0: // Provides an generic interface to a write function which sl@0: // can be either the simple of thread version. Used to hide which sl@0: // version of the write function a test is using sl@0: // sl@0: { sl@0: public: sl@0: virtual void Write(TInt aPos,const TDesC8& aSrc) = 0; sl@0: virtual void CheckedWrite(TInt aPos,const TDesC8& aSrc) = 0; sl@0: }; sl@0: sl@0: class TWriteBase: public MGeneralizedWrite sl@0: { sl@0: public: sl@0: TWriteBase( CWriteTest& aOwner ); sl@0: virtual void CheckedWrite(TInt aPos,const TDesC8& aSrc); sl@0: sl@0: protected: sl@0: CWriteTest& iOwner; sl@0: }; sl@0: sl@0: sl@0: class TSimpleWrite : public TWriteBase sl@0: // sl@0: // Simple implementation of write function sl@0: // sl@0: { sl@0: public: sl@0: TSimpleWrite( CWriteTest& aOwner ); sl@0: virtual void Write( TInt aPos, const TDesC8& aSrc ); sl@0: sl@0: private: sl@0: TBusLocalDrive& iDrive; sl@0: }; sl@0: sl@0: class TThreadWrite : public TWriteBase sl@0: // sl@0: // Thread implementation of write function sl@0: // sl@0: { sl@0: public: sl@0: TThreadWrite( CWriteTest& aOwner ); sl@0: virtual void Write(TInt aPos,const TDesC8& aSrc); sl@0: sl@0: // Thread functions with offset, added by this class sl@0: void CheckedThreadWrite(TInt aPos, TInt aLength, const TDesC8& aSrc, TInt aDescOffset ); sl@0: void CurrentThreadCheckedThreadWrite(TInt aPos, TInt aLength, const TDesC8& aSrc, TInt aDescOffset ); sl@0: sl@0: private: sl@0: TBusLocalDrive& iDrive; sl@0: const TInt iThreadHandle; sl@0: }; sl@0: sl@0: sl@0: class CBlockManager : public CBase sl@0: // sl@0: // class used to control erasing and allocation of blocks sl@0: // sl@0: { sl@0: public: sl@0: CBlockManager( TBusLocalDrive& iDrive, CWriteTest& aOwner ); sl@0: ~CBlockManager(); sl@0: sl@0: void CreateL(); sl@0: sl@0: void EraseBlock( TInt aBlockNumber ); sl@0: void EraseAllBlocks(); sl@0: void VerifyErased( TInt aBlockNumber ); sl@0: sl@0: void InitialiseSequentialBlockAllocator(); sl@0: TInt NextErasedBlock(); sl@0: sl@0: void InitialiseDataChunkAllocator(); sl@0: TUint NextErasedDataChunk( TInt aRequiredLength, TInt aMultiple=4 ); sl@0: sl@0: sl@0: inline TInt BlockCount() const; sl@0: inline TInt BlockSize() const; sl@0: inline TInt FlashSize() const; sl@0: inline TUint BlockAddress( TInt aBlockNumber ) const; sl@0: sl@0: private: sl@0: TBusLocalDrive& iDrive; sl@0: TBuf8<512> iReadBuffer; sl@0: CWriteTest& iOwner; sl@0: TInt iBlockCount; sl@0: TInt iBlockSize; sl@0: sl@0: enum TEraseStatus sl@0: { sl@0: EErased, sl@0: ENotErased sl@0: }; sl@0: TEraseStatus* iEraseArray; sl@0: sl@0: TInt iNextBlock; sl@0: sl@0: TInt iDataBlock; sl@0: TInt iDataOffset; sl@0: }; sl@0: sl@0: sl@0: sl@0: class CWriteTest : public CBase sl@0: { sl@0: public: sl@0: ~CWriteTest(); sl@0: sl@0: void CreateL(); sl@0: sl@0: void DoTests(); sl@0: sl@0: TBool CompareAgainstFlash( TInt aFlashOffset, const TDesC8& aDes ); sl@0: TBool CompareAgainstFlash( TInt aFlashOffset, TInt aLength, const TDesC8& aDes, TInt aDescOffset ); sl@0: sl@0: inline const TUint8* ChunkBase() const; sl@0: inline TBusLocalDrive& Drive(); sl@0: inline TInt DummyThreadHandle() const; sl@0: sl@0: private: sl@0: static TInt DummyThread( TAny* aParam ); sl@0: sl@0: void CreateRandomData( TDes8& aDestBuf, TInt aLength ); sl@0: TBool CheckOnes( TUint aFlashOffset, TInt aLength ); sl@0: void CreateTestData( TInt aBlockNumber, TBool aEndOfBlock ); sl@0: sl@0: void SimpleWriteTest(); sl@0: void SimpleThreadWriteTest(); sl@0: void DoSimpleWriteTest( MGeneralizedWrite& aWriter ); sl@0: sl@0: void AlignedWriteTest(); sl@0: void AlignedThreadWriteTest(); sl@0: void DoAlignedWriteTest( MGeneralizedWrite& aWriter ); sl@0: sl@0: void UnalignedWriteTest(); sl@0: void UnalignedThreadWriteTest(); sl@0: void DoUnalignedWriteTest( MGeneralizedWrite& aWriter ); sl@0: sl@0: void OffsetDescriptorAlignedWriteTest(); sl@0: void OffsetDescriptorUnalignedWriteTest(); sl@0: void OffsetDescriptorCurrentThreadAlignedWriteTest(); sl@0: void OffsetDescriptorCurrentThreadUnalignedWriteTest(); sl@0: sl@0: void JoinedWriteTest(); sl@0: void JoinedThreadWriteTest(); sl@0: sl@0: void SingleBitOverwriteTest(); sl@0: void TwoBitOverwriteTest(); sl@0: sl@0: void RunSimulationTest(); sl@0: sl@0: sl@0: private: sl@0: TBusLocalDrive iDrive; sl@0: TBool iDriveOpened; sl@0: TBuf8<512> iReadBuffer; sl@0: CBlockManager* iBlocks; sl@0: sl@0: TRandomGenerator iRandom; sl@0: sl@0: TSimpleWrite* iSimpleWriter; sl@0: TThreadWrite* iThreadWriter; sl@0: sl@0: RThread iDummyThread; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: inline TBusLocalDrive& CWriteTest::Drive() sl@0: { sl@0: return iDrive; sl@0: } sl@0: sl@0: inline TInt CWriteTest::DummyThreadHandle() const sl@0: { sl@0: return iDummyThread.Handle(); sl@0: } sl@0: sl@0: sl@0: #endif sl@0: