kerneltest/e32test/lffs/t_lfsdrvbm.cpp
changeset 0 a41df078684a
child 215 8096a832df02
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2005-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 // e32test\lffs\t_lfsdrvbm.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32test.h>
       
    19 #include <e32svr.h>
       
    20 #include <e32hal.h>
       
    21 #include <e32uid.h>
       
    22 #include "..\misc\prbs.h"
       
    23 
       
    24 
       
    25 LOCAL_D TBuf<16384> DataBuf;
       
    26 LOCAL_D	TBusLocalDrive TheDrive;
       
    27 LOCAL_D TBool ChangedFlag;
       
    28 
       
    29 const TInt KBufferSize=4096;
       
    30 const TInt KBigBufferSize=4096*4;
       
    31 TUint8 Buffer[KBigBufferSize];
       
    32 
       
    33 
       
    34 #define LFFS_PDD_NAME _L("MEDLFS")
       
    35 
       
    36 
       
    37 RTest test(_L("LFFS Driver BenchMark Test"));
       
    38 
       
    39 LOCAL_C void DoRead(TInt aReadBlockSize)
       
    40 //
       
    41 // Do Read benchmark
       
    42 //
       
    43 	{
       
    44     TInt msgHandle = KLocalMessageHandle;
       
    45 	TLocalDriveCapsV7 info;
       
    46 	TPckg<TLocalDriveCapsV7> capsPckg(info);
       
    47   	TheDrive.Caps(capsPckg);
       
    48 	TInt maxSize;
       
    49 	maxSize=I64LOW(info.iSize);
       
    50 	TInt count,pos,err;
       
    51 	count=pos=err=0;
       
    52 
       
    53 	RTimer timer;
       
    54 	timer.CreateLocal();
       
    55 	TRequestStatus reqStat;
       
    56 	timer.After(reqStat,10000000); // After 10 secs
       
    57 	while(reqStat==KRequestPending)
       
    58 		{
       
    59 		if (TheDrive.Read(pos,aReadBlockSize,&DataBuf,msgHandle,0)==KErrNone)
       
    60 			count++;
       
    61 		else
       
    62 			err++;
       
    63 		pos+=aReadBlockSize;
       
    64 		if (pos>=(maxSize-aReadBlockSize))
       
    65 			pos=0;
       
    66 		}
       
    67 #if defined (__WINS__)
       
    68 	test.Printf(_L("Read %d %d byte blocks in 10 secs\n"),count,aReadBlockSize);
       
    69 #else
       
    70 	TBuf<60> buf;
       
    71 	TReal32 rate=((TReal32)(count*aReadBlockSize))/10240.0F;
       
    72 	TRealFormat rf(10,2);
       
    73 	buf.Format(_L("Read %d %d byte blocks in 10 secs ("),count,aReadBlockSize);
       
    74 	buf.AppendNum(rate,rf);
       
    75 	buf.Append(_L("Kb/s)\n"));
       
    76 	test.Printf(buf);
       
    77 #endif
       
    78 	test.Printf(_L("Errors:%d\n"),err);
       
    79 	}
       
    80 
       
    81 LOCAL_C void DoWrite(TInt aWriteBlockSize)
       
    82 //
       
    83 // Do write benchmark
       
    84 //
       
    85 	{
       
    86 	TLocalDriveCapsV7 info;
       
    87 	TPckg<TLocalDriveCapsV7> capsPckg(info);
       
    88   	TheDrive.Caps(capsPckg);
       
    89 	TInt maxSize;
       
    90 	maxSize=I64LOW(info.iSize);
       
    91 	TInt count,err;
       
    92 	TUint pos;
       
    93 	count=pos=err=0;
       
    94 
       
    95 	// Erase the first 16 blocks to ensure write completes OK
       
    96 	TUint32 EbSz=(TInt)info.iEraseBlockSize;
       
    97 	TInt r=KErrNone;
       
    98 	for (pos=0; pos<16*EbSz; pos+=EbSz)
       
    99 		{
       
   100 		TInt64 pos64 = MAKE_TINT64(0, pos);
       
   101 		r=TheDrive.Format(pos64,EbSz);
       
   102 		test(r==KErrNone);
       
   103 		}
       
   104 
       
   105 	pos=0;
       
   106 	RTimer timer;
       
   107 	timer.CreateLocal();
       
   108 	TRequestStatus reqStat;
       
   109 	TPtrC8 ptr(Buffer,aWriteBlockSize);
       
   110 	timer.After(reqStat,10000000); // After 10 secs
       
   111 	while(reqStat==KRequestPending)
       
   112 		{
       
   113 		TInt64 pos64 = MAKE_TINT64(0, pos);
       
   114 		TInt r=TheDrive.Write(pos64,ptr);
       
   115 		if (r==KErrNone)
       
   116 			count++;
       
   117 		else
       
   118 			err++;
       
   119 		pos+=aWriteBlockSize;
       
   120 		if ((TInt)pos>=(maxSize-aWriteBlockSize))
       
   121 			pos=0;
       
   122 		}
       
   123 
       
   124 #if defined (__WINS__)
       
   125 	test.Printf(_L("Write %d %d byte blocks in 10 secs\n"),count,aWriteBlockSize);
       
   126 #else
       
   127 	TBuf<60> buf;
       
   128 	TReal32 rate=((TReal32)(count*aWriteBlockSize))/10240.0F;
       
   129 	TRealFormat rf(10,2);
       
   130 	buf.Format(_L("Write %d %d byte blocks in 10 secs ("),count,aWriteBlockSize);
       
   131 	buf.AppendNum(rate,rf);
       
   132 	buf.Append(_L("Kb/s)\n"));
       
   133 	test.Printf(buf);
       
   134 #endif
       
   135 	test.Printf(_L("Errors:%d\n"),err);
       
   136 	}
       
   137 
       
   138 
       
   139 GLDEF_C TInt E32Main()
       
   140     {
       
   141 	TBuf<32> b;
       
   142 
       
   143 	test.Title();
       
   144 	TDriveInfoV1Buf diBuf;
       
   145 	UserHal::DriveInfo(diBuf);
       
   146 	TDriveInfoV1 &di=diBuf();
       
   147 	TInt r;
       
   148 	TInt drv;
       
   149 
       
   150 	test.Printf(_L("DRIVES PRESENT  :%d\r\n"),di.iTotalSupportedDrives);
       
   151 	test.Printf(_L("C:(1ST) DRIVE NAME  :%- 16S\r\n"),&di.iDriveName[0]);
       
   152 	test.Printf(_L("D:(2ND) DRIVE NAME  :%- 16S\r\n"),&di.iDriveName[1]);
       
   153 	test.Printf(_L("E:(3RD) DRIVE NAME  :%- 16S\r\n"),&di.iDriveName[2]);
       
   154 	test.Printf(_L("F:(4TH) DRIVE NAME  :%- 16S\r\n"),&di.iDriveName[3]);
       
   155 	test.Printf(_L("G:(5TH) DRIVE NAME  :%- 16S\r\n"),&di.iDriveName[4]);
       
   156 	test.Printf(_L("H:(6TH) DRIVE NAME  :%- 16S\r\n"),&di.iDriveName[5]);
       
   157 	test.Printf(_L("I:(7TH) DRIVE NAME  :%- 16S\r\n"),&di.iDriveName[6]);
       
   158 	test.Printf(_L("J:(8TH) DRIVE NAME  :%- 16S\r\n"),&di.iDriveName[7]);
       
   159 	test.Printf(_L("K:(9TH) DRIVE NAME  :%- 16S\r\n"),&di.iDriveName[8]);
       
   160 
       
   161 	test.Printf(_L("Select Local Drive (C-%c):\r\n"),'C'+ 8);
       
   162 	TChar c;
       
   163 	FOREVER
       
   164 		{
       
   165 		c=(TUint)test.Getch();
       
   166 		c.UpperCase();
       
   167 		drv=((TUint)c)-'C';
       
   168 		if (drv>=0&&drv<='C'+ 8)
       
   169 			break;
       
   170 		}
       
   171 
       
   172 	r=User::LoadPhysicalDevice(LFFS_PDD_NAME);
       
   173 	test(r==KErrNone || r==KErrAlreadyExists);
       
   174 
       
   175 
       
   176 	b.Format(_L("Connect to drive %c:"),'C'+drv);
       
   177 	test.Next(b);
       
   178 	TheDrive.Connect(drv,ChangedFlag);
       
   179 
       
   180 	TLocalDriveCapsV7 info;
       
   181 	TPckg<TLocalDriveCapsV7> capsPckg(info);
       
   182   	TheDrive.Caps(capsPckg);
       
   183 
       
   184 	test.Start(_L("Starting write tests\n"));
       
   185 
       
   186 	// Full buffer write test - pre-load the buffer and write 
       
   187 	TUint32* pB=(TUint32*)(Buffer);
       
   188 	TUint32* pE=(TUint32*)(Buffer+KBufferSize);
       
   189 	TUint seed[2];
       
   190 	seed[0]=0xb17217f8;
       
   191 	seed[1]=0;
       
   192 	while (pB<pE)
       
   193 		*pB++=Random(seed);
       
   194 
       
   195 	pB=(TUint32*)(Buffer);
       
   196 	if(info.iWriteBufferSize)
       
   197 		DoWrite(info.iWriteBufferSize);
       
   198 
       
   199 	// Erase test
       
   200 	// Get the current time
       
   201 	TInt64 zeroTime=MAKE_TINT64(0, 0);
       
   202 	TTime TheTimer=TTime(zeroTime);
       
   203 
       
   204 	// Invoke the erase sequuence
       
   205 
       
   206 	// Report the time interval
       
   207 	TInt64 currentTime=TheTimer.Int64();
       
   208 test.Printf(_L("currentTime now = %d\n"),(TInt)currentTime);
       
   209 
       
   210 currentTime=TheTimer.Int64();
       
   211 test.Printf(_L("currentTime now = %d\n"),(TInt)currentTime);
       
   212 
       
   213 currentTime=TheTimer.Int64();
       
   214 test.Printf(_L("currentTime now = %d\n"),(TInt)currentTime);
       
   215 
       
   216 
       
   217 	if ((info.iWriteBufferSize)<1024)
       
   218 	/* 
       
   219 	these tests would cause errors on M18 Intel Strataflash. this type
       
   220 	of Strataflash operates in object and control mode. when writing 16
       
   221 	byte blocks the first write puts puts each M18 1024 byte programming 
       
   222 	region into control mode so that all susequent even numbered writes 
       
   223 	succeed but all subsequent odd numbered writes fail (in control 
       
   224 	mode writes to bytes 16 - 31, 48 - 63 aren't allowed). successes match
       
   225 	failures. when writing 256 byte blocks only 1 in 4 writes succeeds -
       
   226 	the first write in each programming region succeeds and puts the 
       
   227 	region into object mode so that the subsequent three writes to the 
       
   228 	same programming region fail (in object mode a programming region may
       
   229 	only be written to once). when writing 512 byte blocks 1 in 2 writes 
       
   230 	fail with the first write to each programming region succeeding and the 
       
   231 	second failing. with 513 byte writes the analysis is slightly more 
       
   232 	complex than with 512 byte writes but the failure rate of 1 in 2 still
       
   233 	applies. 
       
   234 	*/		
       
   235 		{
       
   236 		DoWrite(16);
       
   237 		DoWrite(256);
       
   238 		DoWrite(512);
       
   239 		DoWrite(513); 
       
   240 		}
       
   241 	DoWrite(1024); 
       
   242 	DoWrite(2048);
       
   243 	DoWrite(16384);
       
   244 
       
   245 
       
   246 	DoRead(16);
       
   247 	DoRead(256);
       
   248 	DoRead(512);
       
   249 	DoRead(513);
       
   250 	DoRead(2048);
       
   251 	DoRead(16384);
       
   252 
       
   253    test.End();
       
   254 
       
   255 	return(0);
       
   256 	}
       
   257