os/kernelhwsrv/kerneltest/e32test/pccd/t_nandbm.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2007-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
// e32test\pccd\t_nandbm.cpp
sl@0
    15
// Test read/write performance for NAND drives accessed directly
sl@0
    16
// through the Local Media Sub-System
sl@0
    17
// When no command parameter is supplied search for first 
sl@0
    18
// writeable NAND drive that can be found
sl@0
    19
// If a drive number parameter in the range 0 - F is provided,
sl@0
    20
// interpret this as a local drive number in the range 0 - 15
sl@0
    21
// and test the drive if it is a writeable NAND drive
sl@0
    22
// Please note that local drive numbers at the Local Media Sub-System 
sl@0
    23
// level are not the same as drive numbers / drive letters at the 
sl@0
    24
// File Server level. File Server drive numbers / drive letters fall
sl@0
    25
// in the range 0 - 25 / a - z. The mapping between local drive numbers 
sl@0
    26
// and File Server drive numbers / drive letters is defined in 
sl@0
    27
// estart.txt or its equivalent 
sl@0
    28
// Use TBusLocalDrive directly and bypass the File Server
sl@0
    29
// Fill NAND user data drive with data prior to executing actual 
sl@0
    30
// performance tests. TBusLocalDrive should read from areas that have 
sl@0
    31
// been written to and are therefore assigned. Where areas are 
sl@0
    32
// unassigned, XSR FTL returns FFs without accessing the NAND flash 
sl@0
    33
// hardware. This type of behaviour generates misleadingly quick 
sl@0
    34
// performance figures
sl@0
    35
// Test various block sizes in the range 16 - 65536 bytes
sl@0
    36
// 
sl@0
    37
//
sl@0
    38
sl@0
    39
sl@0
    40
#include <e32test.h>
sl@0
    41
#include <f32fsys.h>
sl@0
    42
#include <e32hal.h>
sl@0
    43
#include <e32uid.h>
sl@0
    44
#include <f32dbg.h>
sl@0
    45
sl@0
    46
sl@0
    47
LOCAL_D TBuf<1048576> DataBuf;
sl@0
    48
LOCAL_D	TBusLocalDrive TheDrive;
sl@0
    49
LOCAL_D TBool ChangedFlag;
sl@0
    50
LOCAL_D RFs TheFs;
sl@0
    51
sl@0
    52
RTest test(_L("Local NAND Drive BenchMark Test"));
sl@0
    53
sl@0
    54
LOCAL_C void DoRead(TInt aReadBlockSize)
sl@0
    55
//
sl@0
    56
// Do Read benchmark
sl@0
    57
//
sl@0
    58
	{
sl@0
    59
    TInt msgHandle = KLocalMessageHandle;
sl@0
    60
	TLocalDriveCapsV2 info;
sl@0
    61
	TPckg<TLocalDriveCapsV2> infoPckg(info);
sl@0
    62
	TInt maxSize;
sl@0
    63
	TheDrive.Caps(infoPckg);
sl@0
    64
	maxSize=I64LOW(info.iSize);
sl@0
    65
	TInt count,pos,err;
sl@0
    66
	count=pos=err=0;
sl@0
    67
sl@0
    68
	RTimer timer;
sl@0
    69
	timer.CreateLocal();
sl@0
    70
	TRequestStatus reqStat;
sl@0
    71
	timer.After(reqStat,10000000); // After 10 secs
sl@0
    72
	while(reqStat==KRequestPending)
sl@0
    73
		{
sl@0
    74
		if (TheDrive.Read(pos,aReadBlockSize,&DataBuf,msgHandle,0)==KErrNone)
sl@0
    75
			count++;
sl@0
    76
		else
sl@0
    77
			err++;
sl@0
    78
		pos+=aReadBlockSize;
sl@0
    79
		if (pos>=(maxSize-aReadBlockSize))
sl@0
    80
			pos=0;
sl@0
    81
		}
sl@0
    82
#if defined (__WINS__)
sl@0
    83
	test.Printf(_L("Read %d %d byte blocks in 10 secs\n"),count,aReadBlockSize);
sl@0
    84
#else
sl@0
    85
	TBuf<60> buf;
sl@0
    86
	TReal32 rate=((TReal32)(count*aReadBlockSize))/10240.0F;
sl@0
    87
	TRealFormat rf(10,2);
sl@0
    88
	buf.Format(_L("Read %d %d byte blocks in 10 secs ("),count,aReadBlockSize);
sl@0
    89
	buf.AppendNum(rate,rf);
sl@0
    90
	buf.Append(_L("Kb/s)\n"));
sl@0
    91
	test.Printf(buf);
sl@0
    92
#endif
sl@0
    93
	test.Printf(_L("Errors:%d\n"),err);
sl@0
    94
	}
sl@0
    95
sl@0
    96
LOCAL_C void DoWrite(TInt aWriteBlockSize)
sl@0
    97
//
sl@0
    98
// Do write benchmark
sl@0
    99
//
sl@0
   100
	{
sl@0
   101
    TInt msgHandle = KLocalMessageHandle;
sl@0
   102
	TLocalDriveCapsV2 info;
sl@0
   103
	TPckg<TLocalDriveCapsV2> infoPckg(info);
sl@0
   104
	TInt maxSize;
sl@0
   105
	TheDrive.Caps(infoPckg);
sl@0
   106
	maxSize=I64LOW(info.iSize);
sl@0
   107
	TInt count,pos,err;
sl@0
   108
	count=pos=err=0;
sl@0
   109
sl@0
   110
	RTimer timer;
sl@0
   111
	timer.CreateLocal();
sl@0
   112
	TRequestStatus reqStat;
sl@0
   113
	timer.After(reqStat,10000000); // After 10 secs
sl@0
   114
	while(reqStat==KRequestPending)
sl@0
   115
		{
sl@0
   116
		if (TheDrive.Write(pos,aWriteBlockSize,&DataBuf,msgHandle,0)==KErrNone)
sl@0
   117
			count++;
sl@0
   118
		else
sl@0
   119
			err++;
sl@0
   120
		pos+=aWriteBlockSize;
sl@0
   121
		if (pos>=(maxSize-aWriteBlockSize))
sl@0
   122
			pos=0;
sl@0
   123
		}
sl@0
   124
#if defined (__WINS__)
sl@0
   125
	test.Printf(_L("Write %d %d byte blocks in 10 secs\n"),count,aWriteBlockSize);
sl@0
   126
#else
sl@0
   127
	TBuf<60> buf;
sl@0
   128
	TReal32 rate=((TReal32)(count*aWriteBlockSize))/10240.0F;
sl@0
   129
	TRealFormat rf(10,2);
sl@0
   130
	buf.Format(_L("Write %d %d byte blocks in 10 secs ("),count,aWriteBlockSize);
sl@0
   131
	buf.AppendNum(rate,rf);
sl@0
   132
	buf.Append(_L("Kb/s)\n"));
sl@0
   133
	test.Printf(buf);
sl@0
   134
#endif
sl@0
   135
	test.Printf(_L("Errors:%d\n"),err);
sl@0
   136
	}
sl@0
   137
sl@0
   138
GLDEF_C TInt E32Main()
sl@0
   139
    {
sl@0
   140
	test.Title();
sl@0
   141
sl@0
   142
	TBuf<0x100> cmd;
sl@0
   143
	User::CommandLine(cmd);						// put command line into decriptor
sl@0
   144
	TLex lex(cmd);
sl@0
   145
	TPtrC param=lex.NextToken();				// point token at local drive number if any
sl@0
   146
	test.Printf(_L("Local Drive = %S\r\n"),&param);
sl@0
   147
sl@0
   148
	TChar localDrv;
sl@0
   149
	TInt localDrvNum;
sl@0
   150
	TBusLocalDrive drive;
sl@0
   151
	TBool changeFlag;
sl@0
   152
	TLocalDriveCapsV4 driveCaps;
sl@0
   153
	TPckg<TLocalDriveCapsV4> capsPckg(driveCaps);
sl@0
   154
	TInt r;
sl@0
   155
	
sl@0
   156
	if (param.Length()==0)
sl@0
   157
		{
sl@0
   158
		// locate writeable NAND drive
sl@0
   159
		for (localDrvNum=0; localDrvNum<KMaxLocalDrives; localDrvNum++)
sl@0
   160
			{
sl@0
   161
sl@0
   162
			r = drive.Connect(localDrvNum,changeFlag);
sl@0
   163
sl@0
   164
			if (r!=KErrNone)
sl@0
   165
				continue;
sl@0
   166
sl@0
   167
			r = drive.Caps(capsPckg);
sl@0
   168
  			drive.Disconnect();
sl@0
   169
			if ((r==KErrNone)
sl@0
   170
				&&(driveCaps.iType==EMediaNANDFlash)
sl@0
   171
				&&!(driveCaps.iMediaAtt&KMediaAttWriteProtected)
sl@0
   172
				&&(driveCaps.iPartitionType!=KPartitionTypeSymbianCrashLog))
sl@0
   173
			break;
sl@0
   174
			}
sl@0
   175
		if (localDrvNum==16)
sl@0
   176
			{
sl@0
   177
			test.Printf(_L("Suitable drive could not be found\r\n"));
sl@0
   178
			test.Printf(_L("Writeable NAND drive required for test\r\n"));
sl@0
   179
			return(KErrGeneral);
sl@0
   180
			}
sl@0
   181
		}
sl@0
   182
	else
sl@0
   183
		{
sl@0
   184
		// is selected local drive number in the range 0-15
sl@0
   185
		localDrv=param[0];
sl@0
   186
		localDrv.UpperCase();
sl@0
   187
		if (localDrv>='0'&&localDrv<='9')
sl@0
   188
			{
sl@0
   189
			localDrvNum=((TInt)localDrv-'0');
sl@0
   190
			}
sl@0
   191
		else if (localDrv>='A'&&localDrv<='F')
sl@0
   192
			{
sl@0
   193
			localDrvNum=((TInt)localDrv-'A'+10);
sl@0
   194
			}
sl@0
   195
		else
sl@0
   196
			{
sl@0
   197
			test.Printf(_L("Commandline %S invalid\r\n"), &cmd);
sl@0
   198
			test.Printf(_L("Usage:\r\n"));
sl@0
   199
			test.Printf(_L("t_nandbm with no arguments, test first suitable NAND drive \r\n"));
sl@0
   200
			test.Printf(_L("t_nandbm x, where x = 0-F test local drive number 0-15\r\n"));
sl@0
   201
			return(KErrGeneral);
sl@0
   202
			}
sl@0
   203
		// is selected drive suitable for test
sl@0
   204
		r = drive.Connect(localDrvNum,changeFlag);
sl@0
   205
		if(r!=KErrNone)
sl@0
   206
			{
sl@0
   207
			test.Printf(_L("Can't connect to drive %d\r\n"), localDrvNum);
sl@0
   208
			return(KErrGeneral);
sl@0
   209
			}
sl@0
   210
		r = drive.Caps(capsPckg);
sl@0
   211
		if(r!=KErrNone)
sl@0
   212
			{
sl@0
   213
			test.Printf(_L("Drive %d caps method error\r\n"), localDrvNum);
sl@0
   214
			return(KErrGeneral);
sl@0
   215
			}
sl@0
   216
 		drive.Disconnect();
sl@0
   217
		if ((driveCaps.iType!=EMediaNANDFlash)
sl@0
   218
			||(driveCaps.iMediaAtt&KMediaAttWriteProtected)
sl@0
   219
			||(driveCaps.iPartitionType==KPartitionTypeSymbianCrashLog))
sl@0
   220
			{
sl@0
   221
			test.Printf(_L("Drive %d has unsuitable capabilities\r\n"), localDrvNum);
sl@0
   222
			test.Printf(_L("Writeable NAND drive required for test\r\n"));
sl@0
   223
			return(KErrGeneral);
sl@0
   224
			}
sl@0
   225
sl@0
   226
		}
sl@0
   227
sl@0
   228
	// Fill the nand user data drive with data so TBusLocalDrive reads 
sl@0
   229
	// from areas that have been written to and are therefore assigned.
sl@0
   230
	// Where areas are unassigned, XSR FTL returns FFs without accessing 
sl@0
   231
	// the NAND flash hardware. This type of behaviour generates misleadingly 
sl@0
   232
	// quick performance figures.
sl@0
   233
	TInt writesize=1048576;
sl@0
   234
	TInt pos = 0;
sl@0
   235
	TInt msgHandle = KLocalMessageHandle;
sl@0
   236
	
sl@0
   237
	TheDrive.Connect(localDrvNum,ChangedFlag);
sl@0
   238
	test.Printf( _L("Fill up NAND drive %d\r\n"),localDrvNum);
sl@0
   239
	while(writesize>=1)
sl@0
   240
		{
sl@0
   241
		test.Printf( _L("%d byte write to pos %d of NAND drive\r\n"),writesize,pos);
sl@0
   242
		if (TheDrive.Write(pos,writesize,&DataBuf,msgHandle,0)!=KErrNone)
sl@0
   243
			{
sl@0
   244
			writesize/=16;
sl@0
   245
			}
sl@0
   246
		else
sl@0
   247
			{
sl@0
   248
			pos += writesize;
sl@0
   249
			}
sl@0
   250
		}
sl@0
   251
sl@0
   252
	test.Start(_L("Start Benchmarking ..."));
sl@0
   253
sl@0
   254
	DoRead(16);
sl@0
   255
	DoRead(256);
sl@0
   256
	DoRead(512);
sl@0
   257
	DoRead(513);
sl@0
   258
	DoRead(2048);
sl@0
   259
	DoRead(4096);
sl@0
   260
	DoRead(16384);
sl@0
   261
	DoRead(32768);
sl@0
   262
	DoRead(65536);
sl@0
   263
sl@0
   264
	DoWrite(16);
sl@0
   265
	DoWrite(256);
sl@0
   266
	DoWrite(512);
sl@0
   267
	DoWrite(513); 
sl@0
   268
	DoWrite(2048);
sl@0
   269
	DoWrite(4096);
sl@0
   270
	DoWrite(16384);
sl@0
   271
	DoWrite(32768);
sl@0
   272
	DoWrite(65536);
sl@0
   273
    
sl@0
   274
	test.End();
sl@0
   275
sl@0
   276
	TheFs.Close();
sl@0
   277
sl@0
   278
	return(KErrNone);
sl@0
   279
	}
sl@0
   280