os/kernelhwsrv/kerneltest/e32test/lffs/tf_write.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 
    17 #ifndef __TF_WRITE_H__
    18 #define __TF_WRITE_H__
    19 
    20 #include <e32std.h>
    21 
    22 enum TPanicNo
    23 	{
    24 	EPanicGetDesOverflow,
    25 	EPanicGetDesInitialOverflow,
    26 	EPanicCheckOverflow,
    27 	EPanicCompareDescOverflow,
    28 	EPanicEraseBlockOOR,
    29 	EPanicEraseBlockNeg,
    30 	EPanicJoinMaths
    31 	};
    32 
    33 GLREF_C void Panic( TPanicNo aPanic );
    34 
    35 class CWriteTest;
    36 
    37 class MGeneralizedWrite
    38 	//
    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
    42 	//
    43 	{
    44 	public:
    45 		virtual void Write(TInt aPos,const TDesC8& aSrc) = 0;
    46 		virtual void CheckedWrite(TInt aPos,const TDesC8& aSrc) = 0;
    47 	};
    48 
    49 class TWriteBase: public MGeneralizedWrite
    50 	{
    51 	public:
    52 		TWriteBase( CWriteTest& aOwner );
    53 		virtual void CheckedWrite(TInt aPos,const TDesC8& aSrc);
    54 	
    55 	protected:
    56 		CWriteTest&	iOwner;
    57 	};
    58 
    59 
    60 class TSimpleWrite : public TWriteBase
    61 	//
    62 	// Simple implementation of write function
    63 	//
    64 	{
    65 	public:
    66 		TSimpleWrite( CWriteTest& aOwner );
    67 		virtual void Write( TInt aPos, const TDesC8& aSrc );
    68 
    69 	private:
    70 		TBusLocalDrive&	iDrive;
    71 	};
    72 
    73 class TThreadWrite : public TWriteBase
    74 	//
    75 	// Thread implementation of write function
    76 	//
    77 	{
    78 	public:
    79 		TThreadWrite( CWriteTest& aOwner );
    80 		virtual void Write(TInt aPos,const TDesC8& aSrc);
    81 		
    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 );
    85 
    86 	private:
    87 		TBusLocalDrive& iDrive;
    88 		const TInt iThreadHandle;
    89 	};
    90 
    91 
    92 class CBlockManager : public CBase
    93 	//
    94 	// class used to control erasing and allocation of blocks
    95 	//
    96 	{
    97 	public:
    98 		CBlockManager( TBusLocalDrive& iDrive, CWriteTest& aOwner );
    99 		~CBlockManager();
   100 
   101 		void CreateL();
   102 
   103 		void EraseBlock( TInt aBlockNumber );
   104 		void EraseAllBlocks();
   105 		void VerifyErased( TInt aBlockNumber );
   106 
   107 		void InitialiseSequentialBlockAllocator();
   108 		TInt NextErasedBlock();
   109 
   110 		void InitialiseDataChunkAllocator();
   111 		TUint NextErasedDataChunk( TInt aRequiredLength, TInt aMultiple=4 );
   112 
   113 
   114 		inline TInt BlockCount() const;
   115 		inline TInt BlockSize() const;
   116 		inline TInt FlashSize() const;
   117 		inline TUint BlockAddress( TInt aBlockNumber ) const;
   118 
   119 	private:
   120 		TBusLocalDrive&	iDrive;
   121 		TBuf8<512>	iReadBuffer;
   122 		CWriteTest&	iOwner;
   123 		TInt	iBlockCount;
   124 		TInt	iBlockSize;
   125 
   126 		enum TEraseStatus
   127 			{
   128 			EErased,
   129 			ENotErased
   130 			};
   131 		TEraseStatus*	iEraseArray;
   132 
   133 		TInt iNextBlock;
   134 
   135 		TInt iDataBlock;
   136 		TInt iDataOffset;
   137 	};
   138 
   139 
   140 
   141 class CWriteTest : public CBase
   142 	{
   143 	public:
   144 		~CWriteTest();
   145 
   146 		void CreateL();
   147 
   148 		void DoTests();
   149 
   150 		TBool CompareAgainstFlash( TInt aFlashOffset, const TDesC8& aDes );
   151 		TBool CompareAgainstFlash( TInt aFlashOffset, TInt aLength, const TDesC8& aDes, TInt aDescOffset );
   152 
   153 		inline const TUint8* ChunkBase() const;
   154 		inline TBusLocalDrive& Drive();
   155 		inline TInt DummyThreadHandle() const;
   156 
   157 	private:
   158 		static TInt DummyThread( TAny* aParam );
   159 
   160 		void CreateRandomData( TDes8& aDestBuf, TInt aLength );
   161 		TBool CheckOnes( TUint aFlashOffset, TInt aLength );
   162 		void CreateTestData( TInt aBlockNumber, TBool aEndOfBlock );
   163 
   164 		void SimpleWriteTest();
   165 		void SimpleThreadWriteTest();
   166 		void DoSimpleWriteTest( MGeneralizedWrite& aWriter );
   167 
   168 		void AlignedWriteTest();
   169 		void AlignedThreadWriteTest();
   170 		void DoAlignedWriteTest( MGeneralizedWrite& aWriter );
   171 
   172 		void UnalignedWriteTest();
   173 		void UnalignedThreadWriteTest();
   174 		void DoUnalignedWriteTest( MGeneralizedWrite& aWriter );
   175 
   176 		void OffsetDescriptorAlignedWriteTest();
   177 		void OffsetDescriptorUnalignedWriteTest();
   178 		void OffsetDescriptorCurrentThreadAlignedWriteTest();
   179 		void OffsetDescriptorCurrentThreadUnalignedWriteTest();
   180 
   181 		void JoinedWriteTest();
   182 		void JoinedThreadWriteTest();
   183 
   184 		void SingleBitOverwriteTest();
   185 		void TwoBitOverwriteTest();
   186 		
   187 		void RunSimulationTest();
   188 
   189 
   190 	private:
   191 		TBusLocalDrive	iDrive;
   192 		TBool			iDriveOpened;
   193 		TBuf8<512>		iReadBuffer;
   194 		CBlockManager*	iBlocks;
   195 
   196 		TRandomGenerator	iRandom;
   197 
   198 		TSimpleWrite*	iSimpleWriter;
   199 		TThreadWrite*	iThreadWriter;
   200 
   201 		RThread	iDummyThread;
   202 	};
   203 
   204 
   205 
   206 
   207 inline TBusLocalDrive& CWriteTest::Drive()
   208 	{
   209 	return iDrive;
   210 	}
   211 
   212 inline TInt CWriteTest::DummyThreadHandle() const
   213 	{
   214 	return iDummyThread.Handle();
   215 	}
   216 
   217 
   218 #endif
   219