os/kernelhwsrv/kerneltest/e32test/pccd/t_pccdsr.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_pccdsr.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,319 @@
     1.4 +// Copyright (c) 1998-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_pccdsr.cpp
    1.18 +// Stress test a single sector of Compact Flash card (ATA).
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +
    1.23 +//#define USE_F32_ACCESS
    1.24 +#include <e32test.h>
    1.25 +#include <e32svr.h>
    1.26 +#include <e32hal.h>
    1.27 +#include <e32uid.h>
    1.28 +#if defined (USE_F32_ACCESS)
    1.29 +#include <f32fsys.h>
    1.30 +#include <f32file.h>
    1.31 +#endif
    1.32 +
    1.33 +#define ATA_PDD_NAME _L("MEDATA")
    1.34 +
    1.35 +const TInt KAtaSectorSize=512;
    1.36 +const TInt KMaxSectors=8;
    1.37 +const TInt KMaxRdWrBufLen=(KAtaSectorSize*KMaxSectors); // 4K
    1.38 +const TInt KHeapSize=0x4000;
    1.39 +const TInt KMaxErr=8;
    1.40 +
    1.41 +#if defined (USE_F32_ACCESS)
    1.42 +GLDEF_D	RFs TheFs;
    1.43 +#else
    1.44 +LOCAL_D	TBusLocalDrive TheDrive;
    1.45 +LOCAL_D TBool ChangedFlag;
    1.46 +#endif
    1.47 +RTest test(_L("Local Drive Stress test"));
    1.48 +LOCAL_D TBuf8<KMaxRdWrBufLen> wrBufPat1,wrBufPat2,rdBuf;
    1.49 +
    1.50 +enum TOper {ENone,EWrite,ERead,ECompare};
    1.51 +class TErrInfo
    1.52 +	{
    1.53 +public:
    1.54 +	TErrInfo();
    1.55 +public:
    1.56 +	TInt iError;
    1.57 +	TOper iOperation;
    1.58 +	TInt iCycle;
    1.59 +	};
    1.60 +
    1.61 +class TResult
    1.62 +	{
    1.63 +public:
    1.64 +	TResult();
    1.65 +	void Display(CConsoleBase *aConsole, TInt aCycles);
    1.66 +	void Add(TInt anError,TOper anOperation,TInt aCycle);
    1.67 +public:
    1.68 +	TInt iTotalErrs;
    1.69 +	TErrInfo iFirstErr;
    1.70 +	TErrInfo iLastErrs[KMaxErr];
    1.71 +	TInt iNextFreeErr;
    1.72 +	TBool iHadAnError;
    1.73 +	};
    1.74 +
    1.75 +
    1.76 +LOCAL_C TUint OperationToChar(TOper anOperation)
    1.77 +//
    1.78 +// Convert operation enum to corresponding display character
    1.79 +//
    1.80 +	{
    1.81 +
    1.82 +	switch(anOperation)
    1.83 +		{
    1.84 +		case EWrite:
    1.85 +			return('W');
    1.86 +		case ERead:
    1.87 +			return('R');
    1.88 +		case ECompare:
    1.89 +			return('C');
    1.90 +		default:
    1.91 +			return('?');
    1.92 +		}
    1.93 +	}
    1.94 +
    1.95 +TErrInfo::TErrInfo()
    1.96 +//
    1.97 +// Constructor
    1.98 +//
    1.99 +	{
   1.100 +
   1.101 +	iError=KErrNone;
   1.102 +	iOperation=ENone;
   1.103 +	iCycle=0;
   1.104 +	}
   1.105 +
   1.106 +TResult::TResult()
   1.107 +//
   1.108 +// Constructor
   1.109 +//
   1.110 +	{
   1.111 +
   1.112 +	iNextFreeErr=0;
   1.113 +	iTotalErrs=0;
   1.114 +	iHadAnError=EFalse;
   1.115 +	}
   1.116 +
   1.117 +void TResult::Display(CConsoleBase *aConsole, TInt aCycles)
   1.118 +//
   1.119 +// Display test results
   1.120 +//
   1.121 +	{
   1.122 +
   1.123 +	TInt xStartPos=0;
   1.124 +	TInt yStartPos=7;
   1.125 +
   1.126 +	aConsole->SetPos(xStartPos,yStartPos);
   1.127 +	test.Printf(_L("CYCLES-> %07d   ERRORS-> %d"),aCycles,iTotalErrs);
   1.128 +
   1.129 +	aConsole->SetPos(xStartPos,yStartPos+1);
   1.130 +	test.Printf(_L("FIRST ERROR-> "));
   1.131 +	if (iHadAnError)
   1.132 +		test.Printf(_L("Error:%d Oper:%c Cycle:%07d"),iFirstErr.iError,OperationToChar(iFirstErr.iOperation),iFirstErr.iCycle);
   1.133 +
   1.134 +	aConsole->SetPos(xStartPos,yStartPos+2);
   1.135 +	test.Printf(_L("LAST ERRORS->"));
   1.136 +	if (iHadAnError)
   1.137 +		{
   1.138 +		TInt i;
   1.139 +		aConsole->SetPos(xStartPos+3,yStartPos+3);
   1.140 +		test.Printf(_L("Error:  "));
   1.141 +		for (i=0;(i<KMaxErr && iLastErrs[i].iOperation!=ENone);i++)
   1.142 +			test.Printf(_L("% 7d,"),iLastErrs[i].iError);
   1.143 +
   1.144 +		aConsole->SetPos(xStartPos+3,yStartPos+4);
   1.145 +		test.Printf(_L("Oper:   "));
   1.146 +		for (i=0;(i<KMaxErr && iLastErrs[i].iOperation!=ENone);i++)
   1.147 +			test.Printf(_L("      %c,"),OperationToChar(iLastErrs[i].iOperation));
   1.148 + 
   1.149 +		aConsole->SetPos(xStartPos+3,yStartPos+5);
   1.150 +		test.Printf(_L("Cycle:  "));
   1.151 +		for (i=0;(i<KMaxErr && iLastErrs[i].iOperation!=ENone);i++)
   1.152 +			test.Printf(_L("% 7d,"),iLastErrs[i].iCycle);
   1.153 +		}
   1.154 +
   1.155 +	test.Printf(_L("\r\n"));
   1.156 +	}
   1.157 +
   1.158 +void TResult::Add(TInt anError,TOper anOperation,TInt aCycle)
   1.159 +//
   1.160 +// Add a test result
   1.161 +//
   1.162 +	{
   1.163 +
   1.164 +	iTotalErrs++;
   1.165 +	if (!iHadAnError)
   1.166 +		{
   1.167 +		iFirstErr.iError=anError;
   1.168 +		iFirstErr.iOperation=anOperation;
   1.169 +		iFirstErr.iCycle=aCycle;
   1.170 +		iHadAnError=ETrue;
   1.171 +		}
   1.172 +	if (iNextFreeErr>=KMaxErr)
   1.173 +		{
   1.174 +		for (TInt i=0;i<(KMaxErr-1);i++)
   1.175 +			iLastErrs[i]=iLastErrs[i+1];
   1.176 +		iNextFreeErr=(KMaxErr-1);
   1.177 +		}
   1.178 +	iLastErrs[iNextFreeErr].iError=anError;
   1.179 +	iLastErrs[iNextFreeErr].iOperation=anOperation;
   1.180 +	iLastErrs[iNextFreeErr].iCycle=aCycle;
   1.181 +	iNextFreeErr++;
   1.182 +	}
   1.183 +
   1.184 +GLDEF_C TInt E32Main()
   1.185 +    {
   1.186 +	TBuf<64> b;
   1.187 +
   1.188 +	test.Title();
   1.189 +	TDriveInfoV1Buf diBuf;
   1.190 +	UserHal::DriveInfo(diBuf);
   1.191 +	TDriveInfoV1 &di=diBuf();
   1.192 +	test.Printf(_L("Select Local Drive (C-%c): "),'C'+(di.iTotalSupportedDrives-1));
   1.193 +	TChar c;
   1.194 +	TInt drv;
   1.195 +	FOREVER
   1.196 +		{
   1.197 +		c=(TUint)test.Getch();
   1.198 +		c.UpperCase();
   1.199 +		drv=((TUint)c)-'C';
   1.200 +		if (drv>=0&&drv<di.iTotalSupportedDrives)
   1.201 +			break;
   1.202 +		}
   1.203 +	test.Printf(_L("%c:\r\n"),'C'+drv);
   1.204 +
   1.205 +	TInt rdWrLen;
   1.206 +#if !defined (USE_F32_ACCESS)
   1.207 +	test.Printf(_L("Select total sectors to write(1-8): "));
   1.208 +	FOREVER
   1.209 +		{
   1.210 +		c=(TUint)test.Getch();
   1.211 +		rdWrLen=((TUint)c)-'0';
   1.212 +		if (rdWrLen>=1&&rdWrLen<=8)
   1.213 +			break;
   1.214 +		}
   1.215 +	test.Printf(_L("%dSector(s)\r\n"),rdWrLen);
   1.216 +	rdWrLen*=KAtaSectorSize;
   1.217 +#else
   1.218 +	rdWrLen=(KAtaSectorSize*2)+1;
   1.219 +#endif
   1.220 +
   1.221 +	b.Format(_L("Init test on drive %c:"),'C'+drv);
   1.222 +	test.Start(b);
   1.223 +
   1.224 +	TInt r;
   1.225 +#if defined (USE_F32_ACCESS)
   1.226 +	r=TheFs.Connect();
   1.227 +	test(r==KErrNone);
   1.228 +
   1.229 +	RFile f;
   1.230 +	b.Format(_L("%c:\\TEMP.BIN"),'C'+drv);
   1.231 +	r=f.Replace(TheFs,b,EFileShareAny|EFileStream|EFileWrite);
   1.232 +	test(r==KErrNone);
   1.233 +	b.Format(_L("Start testing (%c:\\TEMP.BIN):"),'C'+drv);
   1.234 +#else
   1.235 +	r=User::LoadPhysicalDevice(ATA_PDD_NAME);
   1.236 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.237 +
   1.238 +	ChangedFlag=EFalse;
   1.239 +	TheDrive.Connect(drv,ChangedFlag);
   1.240 +
   1.241 +	TLocalDriveCapsV2Buf info;
   1.242 +	test(TheDrive.Caps(info)==KErrNone);
   1.243 +	test(info().iType==EMediaHardDisk);
   1.244 +	TInt trgPos=I64LOW(info().iSize)-rdWrLen;	  // Hammer the very end of the disk
   1.245 +	b.Format(_L("Start testing (sector %xH):"),trgPos/KAtaSectorSize);
   1.246 +#endif
   1.247 +
   1.248 +	test.Next(b);
   1.249 +	wrBufPat1.SetLength(rdWrLen);
   1.250 +	TInt j;
   1.251 +	for (j=0;j<rdWrLen;j++)
   1.252 +		wrBufPat1[j]=(TUint8)j;
   1.253 +	wrBufPat2.SetLength(rdWrLen);
   1.254 +	for (j=0;j<rdWrLen;j++)
   1.255 +		wrBufPat2[j]=(TUint8)((rdWrLen-1)-j);
   1.256 +
   1.257 +	TInt cycles=0;
   1.258 +	TResult results;
   1.259 +	TBool toggleTest=EFalse;
   1.260 +
   1.261 +	TRequestStatus kStat;
   1.262 +	test.Console()->Read(kStat);
   1.263 +	FOREVER
   1.264 +		{
   1.265 +		if ((cycles%10)==0)
   1.266 +			results.Display(test.Console(),cycles);
   1.267 +
   1.268 +		TInt res;
   1.269 +#if defined (USE_F32_ACCESS)
   1.270 +		TInt len=(toggleTest)?rdWrLen:1;
   1.271 +
   1.272 +		wrBufPat1.SetLength(len);
   1.273 +		if ((res=f.SetSize(len))==KErrNone)
   1.274 +			res=f.Write(0,wrBufPat1);		// Write test (Pos=0)
   1.275 +		if (res!=KErrNone)
   1.276 +			results.Add(res,EWrite,cycles);
   1.277 +
   1.278 +		// Read test
   1.279 +		rdBuf.Fill(0,len);
   1.280 +		res=f.Read(0,rdBuf,len);
   1.281 +		if (res!=KErrNone)
   1.282 +			results.Add(res,ERead,cycles);
   1.283 +		if (rdBuf.Compare(wrBufPat1)!=0)
   1.284 +			results.Add(0,ECompare,cycles);
   1.285 +#else
   1.286 +		TDes8* wrBuf=(toggleTest)?&wrBufPat2:&wrBufPat1; // Change pattern written
   1.287 +		
   1.288 +		res=TheDrive.Write(trgPos,*wrBuf);	// Write test
   1.289 +		if (res!=KErrNone)
   1.290 +			results.Add(res,EWrite,cycles);
   1.291 +		
   1.292 +		rdBuf.Fill(0,rdWrLen);
   1.293 +		res=TheDrive.Read(trgPos,rdWrLen,rdBuf);	// Read test
   1.294 +		if (res!=KErrNone)
   1.295 +			results.Add(res,ERead,cycles);
   1.296 +		if (rdBuf.Compare(*wrBuf)!=0)
   1.297 +			results.Add(0,ECompare,cycles);
   1.298 +#endif
   1.299 +		cycles++;
   1.300 +		toggleTest^=0x01;
   1.301 +
   1.302 +		if (kStat!=KRequestPending)
   1.303 +			{
   1.304 +			TKeyCode c=test.Console()->KeyCode();
   1.305 +			if (c==EKeySpace)
   1.306 +				break;
   1.307 +			test.Console()->Read(kStat);
   1.308 +			}
   1.309 +		}
   1.310 +
   1.311 +	test.Next(_L("Close"));
   1.312 +#if defined (USE_F32_ACCESS)
   1.313 +	f.Close();
   1.314 +	TheFs.Close();
   1.315 +#else
   1.316 +	TheDrive.Disconnect();
   1.317 +#endif
   1.318 +
   1.319 +	test.End();
   1.320 +	return(0);
   1.321 +	}
   1.322 +