os/kernelhwsrv/kerneltest/e32test/lffs/bf_raw.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/lffs/bf_raw.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,263 @@
     1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Performs some benchmarking of the LFFS media driver
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +/**
    1.22 + @file bf_raw.cpp
    1.23 +*/
    1.24 +
    1.25 +#include <e32std.h>
    1.26 +#include <e32std_private.h>
    1.27 +#include <e32base.h>
    1.28 +#include <e32base_private.h>
    1.29 +#include <e32test.h>
    1.30 +#include <e32svr.h>
    1.31 +#include "bf_raw.h"
    1.32 +#include "user_config.h"
    1.33 +
    1.34 +const TInt KAverageOverInSeconds=10;	///< Number of seconds to run tests for
    1.35 +
    1.36 +//TInt64 Count;				///< Global variable used to count number of operations completed
    1.37 +TUint32 Count;
    1.38 +
    1.39 +RTest test(_L("BF_RAW"));
    1.40 +
    1.41 +
    1.42 +TTestInfo	TestInfo;		///< Data passed to exector thread
    1.43 +
    1.44 +TBusLocalDrive	drive;
    1.45 +TLocalDriveCapsV2Buf driveInfo;
    1.46 +
    1.47 +GLDEF_D	HBufC8*	writeBuffer;	///< Buffer for transferring data
    1.48 +GLDEF_D	HBufC8*	readBuffer;		///< Buffer for transferring data
    1.49 +
    1.50 +GLDEF_D TBool StopTest;		///< set to ETrue to stop the test
    1.51 +
    1.52 +
    1.53 +GLREF_C TInt BmWrite(TAny*);
    1.54 +GLREF_C TInt BmWriteThread(TAny*);
    1.55 +GLREF_C TInt BmRead(TAny*);
    1.56 +GLREF_C TInt BmReadThread(TAny*);
    1.57 +
    1.58 +GLDEF_D TInt	mainThreadHandle;
    1.59 +
    1.60 +TUint32 runTest(TThreadFunction aFunction)
    1.61 +    /**
    1.62 +	 * Function which actually runs the test.
    1.63 +	 *
    1.64 +	 * It creates a new thread to exeute the operations and then waits
    1.65 +	 * for a pre-determined time. The executor thread increments a counter
    1.66 +	 * each time it completes one operation. After the time period expires
    1.67 +	 * the counter is averaged to get an "operations per second". This is
    1.68 +	 * then multiplied by the data size to obtain tranfer rate
    1.69 +	 */
    1.70 +	{
    1.71 +
    1.72 +    RThread thread;
    1.73 +	TInt r=thread.Create(_L("TESTER"),aFunction,KDefaultStackSize,&User::Heap(),NULL);
    1.74 +	if(r!=KErrNone)
    1.75 +		{
    1.76 +		test.Printf(_L("Failed to create thread with error %d\n"),r);
    1.77 +		return(r);
    1.78 +		}
    1.79 +	StopTest = EFalse;	// allow the test to run
    1.80 +    TRequestStatus deadStat;
    1.81 +	thread.Logon( deadStat );
    1.82 +
    1.83 +	RThread().SetPriority( EPriorityMuchMore );
    1.84 +
    1.85 +	thread.Resume();
    1.86 +    User::After(1000000);
    1.87 +    Count=0;
    1.88 +    User::After(KAverageOverInSeconds*1000000);
    1.89 +    TUint32 result=Count;
    1.90 +	
    1.91 +	// tell test to stop and wait for thread to exit.
    1.92 +	StopTest = ETrue;
    1.93 +	User::WaitForRequest( deadStat );
    1.94 +	
    1.95 +	CLOSE_AND_WAIT(thread);
    1.96 +    return(result);
    1.97 +    }
    1.98 +
    1.99 +void PrintResult( TUint32 aCount, const TDesC& aTitle )
   1.100 +	/**
   1.101 +	 * Prints result of test
   1.102 +	 */
   1.103 +	{
   1.104 +	TInt64 count(static_cast<TUint>(aCount));
   1.105 +	TInt64 transferRate = (count * TestInfo.iLength) / KAverageOverInSeconds;
   1.106 +
   1.107 +    test.Printf(_L("%S: %d bytes/second\n"),
   1.108 +					&aTitle,
   1.109 +					I64LOW(transferRate) );
   1.110 +	}
   1.111 +
   1.112 +
   1.113 +LOCAL_C TInt EraseSegment( TInt aSegmentNumber )
   1.114 +	/**
   1.115 +	 * Erases a segment on Flash
   1.116 +	 *
   1.117 +	 * @param aSegmentNumber index of segment to erase
   1.118 +	 * @return KErrNone or error code
   1.119 +	 */
   1.120 +	{
   1.121 +	TInt offset = aSegmentNumber * driveInfo().iEraseBlockSize;
   1.122 +	
   1.123 +	TInt r = drive.Format( offset, driveInfo().iEraseBlockSize );
   1.124 +	return  r;
   1.125 +	}
   1.126 +
   1.127 +
   1.128 +/**
   1.129 + * Structure defining tests
   1.130 + */
   1.131 +class TTestData
   1.132 +	{
   1.133 +	public:
   1.134 +		TThreadFunction		iFunction;	///< function to execute, NULL for end of list
   1.135 +		TInt				iLength;	///< data length
   1.136 +		TInt				iOffset;	///< Flash offset
   1.137 +		const TDesC*				iDescription;	///< descriptive text
   1.138 +	};
   1.139 +
   1.140 +
   1.141 +_LIT( KErasingSegment0, "Erasing segment 0" );
   1.142 +
   1.143 +_LIT( KWrite1Start, "Write, 1 byte, 32-byte boundary, current thread" );
   1.144 +_LIT( KWrite24Start, "Write, 24 bytes, 32-byte boundary, current thread" );
   1.145 +_LIT( KWrite64Start, "Write, 64 bytes, 32-byte boundary, current thread" );
   1.146 +_LIT( KWrite512Start, "Write, 512 bytes, 32-byte boundary, current thread" );
   1.147 +
   1.148 +_LIT( KRead1Start, "Read, 1 byte, 32-byte boundary, current thread" );
   1.149 +_LIT( KRead24Start, "Read, 24 bytes, 32-byte boundary, current thread" );
   1.150 +_LIT( KRead64Start, "Read, 64 bytes, 32-byte boundary, current thread" );
   1.151 +_LIT( KRead512Start, "Read, 512 bytes, 32-byte boundary, current thread" );
   1.152 +
   1.153 +const TThreadFunction KEraseSegment = (TThreadFunction)0x000000F1;
   1.154 +
   1.155 +const TTestData testData[] =		///< the test data
   1.156 +	{
   1.157 +		{ KEraseSegment, 0, 0, &KErasingSegment0 },
   1.158 +
   1.159 +		{ BmWrite, 1, 0, &KWrite1Start },
   1.160 +		{ BmWrite, 24, 32, &KWrite24Start },
   1.161 +		{ BmWrite, 64, 64, &KWrite64Start },
   1.162 +		{ BmWrite, 512, 128, &KWrite512Start },
   1.163 +
   1.164 +		{ BmRead, 1, 0, &KRead1Start },
   1.165 +		{ BmRead, 24, 0, &KRead24Start },
   1.166 +		{ BmRead, 64, 0, &KRead64Start },
   1.167 +		{ BmRead, 512, 0, &KRead512Start },
   1.168 +
   1.169 +		{ NULL, 0, 0, NULL }
   1.170 +	};
   1.171 +
   1.172 +
   1.173 +
   1.174 +void Initialize()
   1.175 +	/**
   1.176 +	 * Open channel to media driver
   1.177 +	 */
   1.178 +	{
   1.179 +	//
   1.180 +	// Load the media driver
   1.181 +	//
   1.182 +#ifndef SKIP_PDD_LOAD
   1.183 +	test.Printf( _L("Loading %S\n"), &KLfsDriverName );
   1.184 +	TInt r = User::LoadPhysicalDevice( KLfsDriverName );
   1.185 +	test( KErrNone == r || KErrAlreadyExists == r );
   1.186 +#endif
   1.187 +
   1.188 +#ifdef UNMOUNT_DRIVE
   1.189 +	RFs fs;
   1.190 +	test( KErrNone == fs.Connect() );
   1.191 +#if 0
   1.192 +	// XXX - not EKA2
   1.193 +	test( KErrNone == fs.SetDefaultPath( _L("Z:\\") ) );
   1.194 +#endif
   1.195 +	TFullName name;
   1.196 +	fs.FileSystemName( name, KLffsLogicalDriveNumber );
   1.197 +	if( name.Length() > 0 )
   1.198 +		{
   1.199 +		test.Printf( _L("Unmounting drive") );
   1.200 +		test( KErrNone == fs.DismountFileSystem( _L("Lffs"), KLffsLogicalDriveNumber) );
   1.201 +		User::After( 2000000 );
   1.202 +		test.Printf( _L("Drive unmounted") );
   1.203 +		}
   1.204 +	fs.Close();
   1.205 +#endif
   1.206 +
   1.207 +	//
   1.208 +	// Open a TBusLogicalDevice to it
   1.209 +	//
   1.210 +	test.Printf( _L("Opening media channel\n") );
   1.211 +	TBool changedFlag = EFalse;
   1.212 +	test( KErrNone == drive.Connect( KDriveNumber, changedFlag ) );
   1.213 +	
   1.214 +	//
   1.215 +	// Get size of Flash drive, block size, block count
   1.216 +	//
   1.217 +    drive.Caps(driveInfo);
   1.218 +
   1.219 +	//
   1.220 +	// Create data buffer
   1.221 +	//
   1.222 +	writeBuffer = HBufC8::New( 1024 );
   1.223 +	test( NULL != writeBuffer );
   1.224 +	writeBuffer->Des().FillZ(1024);
   1.225 +
   1.226 +	readBuffer = HBufC8::New( 1024 );
   1.227 +	test( NULL != readBuffer );
   1.228 +	readBuffer->Des().FillZ(1024);
   1.229 +
   1.230 +	mainThreadHandle = RThread().Handle();
   1.231 +	}
   1.232 +
   1.233 +
   1.234 +
   1.235 +TInt E32Main()
   1.236 +    {
   1.237 +
   1.238 +    test.Title();
   1.239 +    test.Start(_L("Benchmarks for media driver"));
   1.240 +
   1.241 +	Initialize();
   1.242 +
   1.243 +	const TTestData* pTest = &testData[0];
   1.244 +	while( pTest->iFunction )
   1.245 +		{
   1.246 +		if( KEraseSegment == pTest->iFunction )
   1.247 +			{
   1.248 +			test.Printf( *pTest->iDescription );
   1.249 +			TInt r = EraseSegment( pTest->iOffset );
   1.250 +			test( KErrNone == r );
   1.251 +			test.Printf( _L("Segment erased") );
   1.252 +			}
   1.253 +		else
   1.254 +			{
   1.255 +			TestInfo.iLength = pTest->iLength;
   1.256 +			TestInfo.iOffset = pTest->iOffset;
   1.257 +			PrintResult( runTest( pTest->iFunction ), *pTest->iDescription );
   1.258 +			}
   1.259 +		++pTest;
   1.260 +		}
   1.261 +
   1.262 +	drive.Disconnect();
   1.263 +    test.End();
   1.264 +	return(KErrNone);
   1.265 +    }
   1.266 +