os/kernelhwsrv/kerneltest/e32test/lffs/bf_raw.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Performs some benchmarking of the LFFS media driver
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
/**
sl@0
    19
 @file bf_raw.cpp
sl@0
    20
*/
sl@0
    21
sl@0
    22
#include <e32std.h>
sl@0
    23
#include <e32std_private.h>
sl@0
    24
#include <e32base.h>
sl@0
    25
#include <e32base_private.h>
sl@0
    26
#include <e32test.h>
sl@0
    27
#include <e32svr.h>
sl@0
    28
#include "bf_raw.h"
sl@0
    29
#include "user_config.h"
sl@0
    30
sl@0
    31
const TInt KAverageOverInSeconds=10;	///< Number of seconds to run tests for
sl@0
    32
sl@0
    33
//TInt64 Count;				///< Global variable used to count number of operations completed
sl@0
    34
TUint32 Count;
sl@0
    35
sl@0
    36
RTest test(_L("BF_RAW"));
sl@0
    37
sl@0
    38
sl@0
    39
TTestInfo	TestInfo;		///< Data passed to exector thread
sl@0
    40
sl@0
    41
TBusLocalDrive	drive;
sl@0
    42
TLocalDriveCapsV2Buf driveInfo;
sl@0
    43
sl@0
    44
GLDEF_D	HBufC8*	writeBuffer;	///< Buffer for transferring data
sl@0
    45
GLDEF_D	HBufC8*	readBuffer;		///< Buffer for transferring data
sl@0
    46
sl@0
    47
GLDEF_D TBool StopTest;		///< set to ETrue to stop the test
sl@0
    48
sl@0
    49
sl@0
    50
GLREF_C TInt BmWrite(TAny*);
sl@0
    51
GLREF_C TInt BmWriteThread(TAny*);
sl@0
    52
GLREF_C TInt BmRead(TAny*);
sl@0
    53
GLREF_C TInt BmReadThread(TAny*);
sl@0
    54
sl@0
    55
GLDEF_D TInt	mainThreadHandle;
sl@0
    56
sl@0
    57
TUint32 runTest(TThreadFunction aFunction)
sl@0
    58
    /**
sl@0
    59
	 * Function which actually runs the test.
sl@0
    60
	 *
sl@0
    61
	 * It creates a new thread to exeute the operations and then waits
sl@0
    62
	 * for a pre-determined time. The executor thread increments a counter
sl@0
    63
	 * each time it completes one operation. After the time period expires
sl@0
    64
	 * the counter is averaged to get an "operations per second". This is
sl@0
    65
	 * then multiplied by the data size to obtain tranfer rate
sl@0
    66
	 */
sl@0
    67
	{
sl@0
    68
sl@0
    69
    RThread thread;
sl@0
    70
	TInt r=thread.Create(_L("TESTER"),aFunction,KDefaultStackSize,&User::Heap(),NULL);
sl@0
    71
	if(r!=KErrNone)
sl@0
    72
		{
sl@0
    73
		test.Printf(_L("Failed to create thread with error %d\n"),r);
sl@0
    74
		return(r);
sl@0
    75
		}
sl@0
    76
	StopTest = EFalse;	// allow the test to run
sl@0
    77
    TRequestStatus deadStat;
sl@0
    78
	thread.Logon( deadStat );
sl@0
    79
sl@0
    80
	RThread().SetPriority( EPriorityMuchMore );
sl@0
    81
sl@0
    82
	thread.Resume();
sl@0
    83
    User::After(1000000);
sl@0
    84
    Count=0;
sl@0
    85
    User::After(KAverageOverInSeconds*1000000);
sl@0
    86
    TUint32 result=Count;
sl@0
    87
	
sl@0
    88
	// tell test to stop and wait for thread to exit.
sl@0
    89
	StopTest = ETrue;
sl@0
    90
	User::WaitForRequest( deadStat );
sl@0
    91
	
sl@0
    92
	CLOSE_AND_WAIT(thread);
sl@0
    93
    return(result);
sl@0
    94
    }
sl@0
    95
sl@0
    96
void PrintResult( TUint32 aCount, const TDesC& aTitle )
sl@0
    97
	/**
sl@0
    98
	 * Prints result of test
sl@0
    99
	 */
sl@0
   100
	{
sl@0
   101
	TInt64 count(static_cast<TUint>(aCount));
sl@0
   102
	TInt64 transferRate = (count * TestInfo.iLength) / KAverageOverInSeconds;
sl@0
   103
sl@0
   104
    test.Printf(_L("%S: %d bytes/second\n"),
sl@0
   105
					&aTitle,
sl@0
   106
					I64LOW(transferRate) );
sl@0
   107
	}
sl@0
   108
sl@0
   109
sl@0
   110
LOCAL_C TInt EraseSegment( TInt aSegmentNumber )
sl@0
   111
	/**
sl@0
   112
	 * Erases a segment on Flash
sl@0
   113
	 *
sl@0
   114
	 * @param aSegmentNumber index of segment to erase
sl@0
   115
	 * @return KErrNone or error code
sl@0
   116
	 */
sl@0
   117
	{
sl@0
   118
	TInt offset = aSegmentNumber * driveInfo().iEraseBlockSize;
sl@0
   119
	
sl@0
   120
	TInt r = drive.Format( offset, driveInfo().iEraseBlockSize );
sl@0
   121
	return  r;
sl@0
   122
	}
sl@0
   123
sl@0
   124
sl@0
   125
/**
sl@0
   126
 * Structure defining tests
sl@0
   127
 */
sl@0
   128
class TTestData
sl@0
   129
	{
sl@0
   130
	public:
sl@0
   131
		TThreadFunction		iFunction;	///< function to execute, NULL for end of list
sl@0
   132
		TInt				iLength;	///< data length
sl@0
   133
		TInt				iOffset;	///< Flash offset
sl@0
   134
		const TDesC*				iDescription;	///< descriptive text
sl@0
   135
	};
sl@0
   136
sl@0
   137
sl@0
   138
_LIT( KErasingSegment0, "Erasing segment 0" );
sl@0
   139
sl@0
   140
_LIT( KWrite1Start, "Write, 1 byte, 32-byte boundary, current thread" );
sl@0
   141
_LIT( KWrite24Start, "Write, 24 bytes, 32-byte boundary, current thread" );
sl@0
   142
_LIT( KWrite64Start, "Write, 64 bytes, 32-byte boundary, current thread" );
sl@0
   143
_LIT( KWrite512Start, "Write, 512 bytes, 32-byte boundary, current thread" );
sl@0
   144
sl@0
   145
_LIT( KRead1Start, "Read, 1 byte, 32-byte boundary, current thread" );
sl@0
   146
_LIT( KRead24Start, "Read, 24 bytes, 32-byte boundary, current thread" );
sl@0
   147
_LIT( KRead64Start, "Read, 64 bytes, 32-byte boundary, current thread" );
sl@0
   148
_LIT( KRead512Start, "Read, 512 bytes, 32-byte boundary, current thread" );
sl@0
   149
sl@0
   150
const TThreadFunction KEraseSegment = (TThreadFunction)0x000000F1;
sl@0
   151
sl@0
   152
const TTestData testData[] =		///< the test data
sl@0
   153
	{
sl@0
   154
		{ KEraseSegment, 0, 0, &KErasingSegment0 },
sl@0
   155
sl@0
   156
		{ BmWrite, 1, 0, &KWrite1Start },
sl@0
   157
		{ BmWrite, 24, 32, &KWrite24Start },
sl@0
   158
		{ BmWrite, 64, 64, &KWrite64Start },
sl@0
   159
		{ BmWrite, 512, 128, &KWrite512Start },
sl@0
   160
sl@0
   161
		{ BmRead, 1, 0, &KRead1Start },
sl@0
   162
		{ BmRead, 24, 0, &KRead24Start },
sl@0
   163
		{ BmRead, 64, 0, &KRead64Start },
sl@0
   164
		{ BmRead, 512, 0, &KRead512Start },
sl@0
   165
sl@0
   166
		{ NULL, 0, 0, NULL }
sl@0
   167
	};
sl@0
   168
sl@0
   169
sl@0
   170
sl@0
   171
void Initialize()
sl@0
   172
	/**
sl@0
   173
	 * Open channel to media driver
sl@0
   174
	 */
sl@0
   175
	{
sl@0
   176
	//
sl@0
   177
	// Load the media driver
sl@0
   178
	//
sl@0
   179
#ifndef SKIP_PDD_LOAD
sl@0
   180
	test.Printf( _L("Loading %S\n"), &KLfsDriverName );
sl@0
   181
	TInt r = User::LoadPhysicalDevice( KLfsDriverName );
sl@0
   182
	test( KErrNone == r || KErrAlreadyExists == r );
sl@0
   183
#endif
sl@0
   184
sl@0
   185
#ifdef UNMOUNT_DRIVE
sl@0
   186
	RFs fs;
sl@0
   187
	test( KErrNone == fs.Connect() );
sl@0
   188
#if 0
sl@0
   189
	// XXX - not EKA2
sl@0
   190
	test( KErrNone == fs.SetDefaultPath( _L("Z:\\") ) );
sl@0
   191
#endif
sl@0
   192
	TFullName name;
sl@0
   193
	fs.FileSystemName( name, KLffsLogicalDriveNumber );
sl@0
   194
	if( name.Length() > 0 )
sl@0
   195
		{
sl@0
   196
		test.Printf( _L("Unmounting drive") );
sl@0
   197
		test( KErrNone == fs.DismountFileSystem( _L("Lffs"), KLffsLogicalDriveNumber) );
sl@0
   198
		User::After( 2000000 );
sl@0
   199
		test.Printf( _L("Drive unmounted") );
sl@0
   200
		}
sl@0
   201
	fs.Close();
sl@0
   202
#endif
sl@0
   203
sl@0
   204
	//
sl@0
   205
	// Open a TBusLogicalDevice to it
sl@0
   206
	//
sl@0
   207
	test.Printf( _L("Opening media channel\n") );
sl@0
   208
	TBool changedFlag = EFalse;
sl@0
   209
	test( KErrNone == drive.Connect( KDriveNumber, changedFlag ) );
sl@0
   210
	
sl@0
   211
	//
sl@0
   212
	// Get size of Flash drive, block size, block count
sl@0
   213
	//
sl@0
   214
    drive.Caps(driveInfo);
sl@0
   215
sl@0
   216
	//
sl@0
   217
	// Create data buffer
sl@0
   218
	//
sl@0
   219
	writeBuffer = HBufC8::New( 1024 );
sl@0
   220
	test( NULL != writeBuffer );
sl@0
   221
	writeBuffer->Des().FillZ(1024);
sl@0
   222
sl@0
   223
	readBuffer = HBufC8::New( 1024 );
sl@0
   224
	test( NULL != readBuffer );
sl@0
   225
	readBuffer->Des().FillZ(1024);
sl@0
   226
sl@0
   227
	mainThreadHandle = RThread().Handle();
sl@0
   228
	}
sl@0
   229
sl@0
   230
sl@0
   231
sl@0
   232
TInt E32Main()
sl@0
   233
    {
sl@0
   234
sl@0
   235
    test.Title();
sl@0
   236
    test.Start(_L("Benchmarks for media driver"));
sl@0
   237
sl@0
   238
	Initialize();
sl@0
   239
sl@0
   240
	const TTestData* pTest = &testData[0];
sl@0
   241
	while( pTest->iFunction )
sl@0
   242
		{
sl@0
   243
		if( KEraseSegment == pTest->iFunction )
sl@0
   244
			{
sl@0
   245
			test.Printf( *pTest->iDescription );
sl@0
   246
			TInt r = EraseSegment( pTest->iOffset );
sl@0
   247
			test( KErrNone == r );
sl@0
   248
			test.Printf( _L("Segment erased") );
sl@0
   249
			}
sl@0
   250
		else
sl@0
   251
			{
sl@0
   252
			TestInfo.iLength = pTest->iLength;
sl@0
   253
			TestInfo.iOffset = pTest->iOffset;
sl@0
   254
			PrintResult( runTest( pTest->iFunction ), *pTest->iDescription );
sl@0
   255
			}
sl@0
   256
		++pTest;
sl@0
   257
		}
sl@0
   258
sl@0
   259
	drive.Disconnect();
sl@0
   260
    test.End();
sl@0
   261
	return(KErrNone);
sl@0
   262
    }
sl@0
   263