os/kernelhwsrv/kerneltest/e32test/pccd/t_nandbm.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/pccd/t_nandbm.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,280 @@
     1.4 +// Copyright (c) 2007-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 +// e32test\pccd\t_nandbm.cpp
    1.18 +// Test read/write performance for NAND drives accessed directly
    1.19 +// through the Local Media Sub-System
    1.20 +// When no command parameter is supplied search for first 
    1.21 +// writeable NAND drive that can be found
    1.22 +// If a drive number parameter in the range 0 - F is provided,
    1.23 +// interpret this as a local drive number in the range 0 - 15
    1.24 +// and test the drive if it is a writeable NAND drive
    1.25 +// Please note that local drive numbers at the Local Media Sub-System 
    1.26 +// level are not the same as drive numbers / drive letters at the 
    1.27 +// File Server level. File Server drive numbers / drive letters fall
    1.28 +// in the range 0 - 25 / a - z. The mapping between local drive numbers 
    1.29 +// and File Server drive numbers / drive letters is defined in 
    1.30 +// estart.txt or its equivalent 
    1.31 +// Use TBusLocalDrive directly and bypass the File Server
    1.32 +// Fill NAND user data drive with data prior to executing actual 
    1.33 +// performance tests. TBusLocalDrive should read from areas that have 
    1.34 +// been written to and are therefore assigned. Where areas are 
    1.35 +// unassigned, XSR FTL returns FFs without accessing the NAND flash 
    1.36 +// hardware. This type of behaviour generates misleadingly quick 
    1.37 +// performance figures
    1.38 +// Test various block sizes in the range 16 - 65536 bytes
    1.39 +// 
    1.40 +//
    1.41 +
    1.42 +
    1.43 +#include <e32test.h>
    1.44 +#include <f32fsys.h>
    1.45 +#include <e32hal.h>
    1.46 +#include <e32uid.h>
    1.47 +#include <f32dbg.h>
    1.48 +
    1.49 +
    1.50 +LOCAL_D TBuf<1048576> DataBuf;
    1.51 +LOCAL_D	TBusLocalDrive TheDrive;
    1.52 +LOCAL_D TBool ChangedFlag;
    1.53 +LOCAL_D RFs TheFs;
    1.54 +
    1.55 +RTest test(_L("Local NAND Drive BenchMark Test"));
    1.56 +
    1.57 +LOCAL_C void DoRead(TInt aReadBlockSize)
    1.58 +//
    1.59 +// Do Read benchmark
    1.60 +//
    1.61 +	{
    1.62 +    TInt msgHandle = KLocalMessageHandle;
    1.63 +	TLocalDriveCapsV2 info;
    1.64 +	TPckg<TLocalDriveCapsV2> infoPckg(info);
    1.65 +	TInt maxSize;
    1.66 +	TheDrive.Caps(infoPckg);
    1.67 +	maxSize=I64LOW(info.iSize);
    1.68 +	TInt count,pos,err;
    1.69 +	count=pos=err=0;
    1.70 +
    1.71 +	RTimer timer;
    1.72 +	timer.CreateLocal();
    1.73 +	TRequestStatus reqStat;
    1.74 +	timer.After(reqStat,10000000); // After 10 secs
    1.75 +	while(reqStat==KRequestPending)
    1.76 +		{
    1.77 +		if (TheDrive.Read(pos,aReadBlockSize,&DataBuf,msgHandle,0)==KErrNone)
    1.78 +			count++;
    1.79 +		else
    1.80 +			err++;
    1.81 +		pos+=aReadBlockSize;
    1.82 +		if (pos>=(maxSize-aReadBlockSize))
    1.83 +			pos=0;
    1.84 +		}
    1.85 +#if defined (__WINS__)
    1.86 +	test.Printf(_L("Read %d %d byte blocks in 10 secs\n"),count,aReadBlockSize);
    1.87 +#else
    1.88 +	TBuf<60> buf;
    1.89 +	TReal32 rate=((TReal32)(count*aReadBlockSize))/10240.0F;
    1.90 +	TRealFormat rf(10,2);
    1.91 +	buf.Format(_L("Read %d %d byte blocks in 10 secs ("),count,aReadBlockSize);
    1.92 +	buf.AppendNum(rate,rf);
    1.93 +	buf.Append(_L("Kb/s)\n"));
    1.94 +	test.Printf(buf);
    1.95 +#endif
    1.96 +	test.Printf(_L("Errors:%d\n"),err);
    1.97 +	}
    1.98 +
    1.99 +LOCAL_C void DoWrite(TInt aWriteBlockSize)
   1.100 +//
   1.101 +// Do write benchmark
   1.102 +//
   1.103 +	{
   1.104 +    TInt msgHandle = KLocalMessageHandle;
   1.105 +	TLocalDriveCapsV2 info;
   1.106 +	TPckg<TLocalDriveCapsV2> infoPckg(info);
   1.107 +	TInt maxSize;
   1.108 +	TheDrive.Caps(infoPckg);
   1.109 +	maxSize=I64LOW(info.iSize);
   1.110 +	TInt count,pos,err;
   1.111 +	count=pos=err=0;
   1.112 +
   1.113 +	RTimer timer;
   1.114 +	timer.CreateLocal();
   1.115 +	TRequestStatus reqStat;
   1.116 +	timer.After(reqStat,10000000); // After 10 secs
   1.117 +	while(reqStat==KRequestPending)
   1.118 +		{
   1.119 +		if (TheDrive.Write(pos,aWriteBlockSize,&DataBuf,msgHandle,0)==KErrNone)
   1.120 +			count++;
   1.121 +		else
   1.122 +			err++;
   1.123 +		pos+=aWriteBlockSize;
   1.124 +		if (pos>=(maxSize-aWriteBlockSize))
   1.125 +			pos=0;
   1.126 +		}
   1.127 +#if defined (__WINS__)
   1.128 +	test.Printf(_L("Write %d %d byte blocks in 10 secs\n"),count,aWriteBlockSize);
   1.129 +#else
   1.130 +	TBuf<60> buf;
   1.131 +	TReal32 rate=((TReal32)(count*aWriteBlockSize))/10240.0F;
   1.132 +	TRealFormat rf(10,2);
   1.133 +	buf.Format(_L("Write %d %d byte blocks in 10 secs ("),count,aWriteBlockSize);
   1.134 +	buf.AppendNum(rate,rf);
   1.135 +	buf.Append(_L("Kb/s)\n"));
   1.136 +	test.Printf(buf);
   1.137 +#endif
   1.138 +	test.Printf(_L("Errors:%d\n"),err);
   1.139 +	}
   1.140 +
   1.141 +GLDEF_C TInt E32Main()
   1.142 +    {
   1.143 +	test.Title();
   1.144 +
   1.145 +	TBuf<0x100> cmd;
   1.146 +	User::CommandLine(cmd);						// put command line into decriptor
   1.147 +	TLex lex(cmd);
   1.148 +	TPtrC param=lex.NextToken();				// point token at local drive number if any
   1.149 +	test.Printf(_L("Local Drive = %S\r\n"),&param);
   1.150 +
   1.151 +	TChar localDrv;
   1.152 +	TInt localDrvNum;
   1.153 +	TBusLocalDrive drive;
   1.154 +	TBool changeFlag;
   1.155 +	TLocalDriveCapsV4 driveCaps;
   1.156 +	TPckg<TLocalDriveCapsV4> capsPckg(driveCaps);
   1.157 +	TInt r;
   1.158 +	
   1.159 +	if (param.Length()==0)
   1.160 +		{
   1.161 +		// locate writeable NAND drive
   1.162 +		for (localDrvNum=0; localDrvNum<KMaxLocalDrives; localDrvNum++)
   1.163 +			{
   1.164 +
   1.165 +			r = drive.Connect(localDrvNum,changeFlag);
   1.166 +
   1.167 +			if (r!=KErrNone)
   1.168 +				continue;
   1.169 +
   1.170 +			r = drive.Caps(capsPckg);
   1.171 +  			drive.Disconnect();
   1.172 +			if ((r==KErrNone)
   1.173 +				&&(driveCaps.iType==EMediaNANDFlash)
   1.174 +				&&!(driveCaps.iMediaAtt&KMediaAttWriteProtected)
   1.175 +				&&(driveCaps.iPartitionType!=KPartitionTypeSymbianCrashLog))
   1.176 +			break;
   1.177 +			}
   1.178 +		if (localDrvNum==16)
   1.179 +			{
   1.180 +			test.Printf(_L("Suitable drive could not be found\r\n"));
   1.181 +			test.Printf(_L("Writeable NAND drive required for test\r\n"));
   1.182 +			return(KErrGeneral);
   1.183 +			}
   1.184 +		}
   1.185 +	else
   1.186 +		{
   1.187 +		// is selected local drive number in the range 0-15
   1.188 +		localDrv=param[0];
   1.189 +		localDrv.UpperCase();
   1.190 +		if (localDrv>='0'&&localDrv<='9')
   1.191 +			{
   1.192 +			localDrvNum=((TInt)localDrv-'0');
   1.193 +			}
   1.194 +		else if (localDrv>='A'&&localDrv<='F')
   1.195 +			{
   1.196 +			localDrvNum=((TInt)localDrv-'A'+10);
   1.197 +			}
   1.198 +		else
   1.199 +			{
   1.200 +			test.Printf(_L("Commandline %S invalid\r\n"), &cmd);
   1.201 +			test.Printf(_L("Usage:\r\n"));
   1.202 +			test.Printf(_L("t_nandbm with no arguments, test first suitable NAND drive \r\n"));
   1.203 +			test.Printf(_L("t_nandbm x, where x = 0-F test local drive number 0-15\r\n"));
   1.204 +			return(KErrGeneral);
   1.205 +			}
   1.206 +		// is selected drive suitable for test
   1.207 +		r = drive.Connect(localDrvNum,changeFlag);
   1.208 +		if(r!=KErrNone)
   1.209 +			{
   1.210 +			test.Printf(_L("Can't connect to drive %d\r\n"), localDrvNum);
   1.211 +			return(KErrGeneral);
   1.212 +			}
   1.213 +		r = drive.Caps(capsPckg);
   1.214 +		if(r!=KErrNone)
   1.215 +			{
   1.216 +			test.Printf(_L("Drive %d caps method error\r\n"), localDrvNum);
   1.217 +			return(KErrGeneral);
   1.218 +			}
   1.219 + 		drive.Disconnect();
   1.220 +		if ((driveCaps.iType!=EMediaNANDFlash)
   1.221 +			||(driveCaps.iMediaAtt&KMediaAttWriteProtected)
   1.222 +			||(driveCaps.iPartitionType==KPartitionTypeSymbianCrashLog))
   1.223 +			{
   1.224 +			test.Printf(_L("Drive %d has unsuitable capabilities\r\n"), localDrvNum);
   1.225 +			test.Printf(_L("Writeable NAND drive required for test\r\n"));
   1.226 +			return(KErrGeneral);
   1.227 +			}
   1.228 +
   1.229 +		}
   1.230 +
   1.231 +	// Fill the nand user data drive with data so TBusLocalDrive reads 
   1.232 +	// from areas that have been written to and are therefore assigned.
   1.233 +	// Where areas are unassigned, XSR FTL returns FFs without accessing 
   1.234 +	// the NAND flash hardware. This type of behaviour generates misleadingly 
   1.235 +	// quick performance figures.
   1.236 +	TInt writesize=1048576;
   1.237 +	TInt pos = 0;
   1.238 +	TInt msgHandle = KLocalMessageHandle;
   1.239 +	
   1.240 +	TheDrive.Connect(localDrvNum,ChangedFlag);
   1.241 +	test.Printf( _L("Fill up NAND drive %d\r\n"),localDrvNum);
   1.242 +	while(writesize>=1)
   1.243 +		{
   1.244 +		test.Printf( _L("%d byte write to pos %d of NAND drive\r\n"),writesize,pos);
   1.245 +		if (TheDrive.Write(pos,writesize,&DataBuf,msgHandle,0)!=KErrNone)
   1.246 +			{
   1.247 +			writesize/=16;
   1.248 +			}
   1.249 +		else
   1.250 +			{
   1.251 +			pos += writesize;
   1.252 +			}
   1.253 +		}
   1.254 +
   1.255 +	test.Start(_L("Start Benchmarking ..."));
   1.256 +
   1.257 +	DoRead(16);
   1.258 +	DoRead(256);
   1.259 +	DoRead(512);
   1.260 +	DoRead(513);
   1.261 +	DoRead(2048);
   1.262 +	DoRead(4096);
   1.263 +	DoRead(16384);
   1.264 +	DoRead(32768);
   1.265 +	DoRead(65536);
   1.266 +
   1.267 +	DoWrite(16);
   1.268 +	DoWrite(256);
   1.269 +	DoWrite(512);
   1.270 +	DoWrite(513); 
   1.271 +	DoWrite(2048);
   1.272 +	DoWrite(4096);
   1.273 +	DoWrite(16384);
   1.274 +	DoWrite(32768);
   1.275 +	DoWrite(65536);
   1.276 +    
   1.277 +	test.End();
   1.278 +
   1.279 +	TheFs.Close();
   1.280 +
   1.281 +	return(KErrNone);
   1.282 +	}
   1.283 +