sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\pccd\t_pccdsr.cpp sl@0: // Stress test a single sector of Compact Flash card (ATA). sl@0: // sl@0: // sl@0: sl@0: sl@0: //#define USE_F32_ACCESS sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #if defined (USE_F32_ACCESS) sl@0: #include sl@0: #include sl@0: #endif sl@0: sl@0: #define ATA_PDD_NAME _L("MEDATA") sl@0: sl@0: const TInt KAtaSectorSize=512; sl@0: const TInt KMaxSectors=8; sl@0: const TInt KMaxRdWrBufLen=(KAtaSectorSize*KMaxSectors); // 4K sl@0: const TInt KHeapSize=0x4000; sl@0: const TInt KMaxErr=8; sl@0: sl@0: #if defined (USE_F32_ACCESS) sl@0: GLDEF_D RFs TheFs; sl@0: #else sl@0: LOCAL_D TBusLocalDrive TheDrive; sl@0: LOCAL_D TBool ChangedFlag; sl@0: #endif sl@0: RTest test(_L("Local Drive Stress test")); sl@0: LOCAL_D TBuf8 wrBufPat1,wrBufPat2,rdBuf; sl@0: sl@0: enum TOper {ENone,EWrite,ERead,ECompare}; sl@0: class TErrInfo sl@0: { sl@0: public: sl@0: TErrInfo(); sl@0: public: sl@0: TInt iError; sl@0: TOper iOperation; sl@0: TInt iCycle; sl@0: }; sl@0: sl@0: class TResult sl@0: { sl@0: public: sl@0: TResult(); sl@0: void Display(CConsoleBase *aConsole, TInt aCycles); sl@0: void Add(TInt anError,TOper anOperation,TInt aCycle); sl@0: public: sl@0: TInt iTotalErrs; sl@0: TErrInfo iFirstErr; sl@0: TErrInfo iLastErrs[KMaxErr]; sl@0: TInt iNextFreeErr; sl@0: TBool iHadAnError; sl@0: }; sl@0: sl@0: sl@0: LOCAL_C TUint OperationToChar(TOper anOperation) sl@0: // sl@0: // Convert operation enum to corresponding display character sl@0: // sl@0: { sl@0: sl@0: switch(anOperation) sl@0: { sl@0: case EWrite: sl@0: return('W'); sl@0: case ERead: sl@0: return('R'); sl@0: case ECompare: sl@0: return('C'); sl@0: default: sl@0: return('?'); sl@0: } sl@0: } sl@0: sl@0: TErrInfo::TErrInfo() sl@0: // sl@0: // Constructor sl@0: // sl@0: { sl@0: sl@0: iError=KErrNone; sl@0: iOperation=ENone; sl@0: iCycle=0; sl@0: } sl@0: sl@0: TResult::TResult() sl@0: // sl@0: // Constructor sl@0: // sl@0: { sl@0: sl@0: iNextFreeErr=0; sl@0: iTotalErrs=0; sl@0: iHadAnError=EFalse; sl@0: } sl@0: sl@0: void TResult::Display(CConsoleBase *aConsole, TInt aCycles) sl@0: // sl@0: // Display test results sl@0: // sl@0: { sl@0: sl@0: TInt xStartPos=0; sl@0: TInt yStartPos=7; sl@0: sl@0: aConsole->SetPos(xStartPos,yStartPos); sl@0: test.Printf(_L("CYCLES-> %07d ERRORS-> %d"),aCycles,iTotalErrs); sl@0: sl@0: aConsole->SetPos(xStartPos,yStartPos+1); sl@0: test.Printf(_L("FIRST ERROR-> ")); sl@0: if (iHadAnError) sl@0: test.Printf(_L("Error:%d Oper:%c Cycle:%07d"),iFirstErr.iError,OperationToChar(iFirstErr.iOperation),iFirstErr.iCycle); sl@0: sl@0: aConsole->SetPos(xStartPos,yStartPos+2); sl@0: test.Printf(_L("LAST ERRORS->")); sl@0: if (iHadAnError) sl@0: { sl@0: TInt i; sl@0: aConsole->SetPos(xStartPos+3,yStartPos+3); sl@0: test.Printf(_L("Error: ")); sl@0: for (i=0;(iSetPos(xStartPos+3,yStartPos+4); sl@0: test.Printf(_L("Oper: ")); sl@0: for (i=0;(iSetPos(xStartPos+3,yStartPos+5); sl@0: test.Printf(_L("Cycle: ")); sl@0: for (i=0;(i=KMaxErr) sl@0: { sl@0: for (TInt i=0;i<(KMaxErr-1);i++) sl@0: iLastErrs[i]=iLastErrs[i+1]; sl@0: iNextFreeErr=(KMaxErr-1); sl@0: } sl@0: iLastErrs[iNextFreeErr].iError=anError; sl@0: iLastErrs[iNextFreeErr].iOperation=anOperation; sl@0: iLastErrs[iNextFreeErr].iCycle=aCycle; sl@0: iNextFreeErr++; sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: TBuf<64> b; sl@0: sl@0: test.Title(); sl@0: TDriveInfoV1Buf diBuf; sl@0: UserHal::DriveInfo(diBuf); sl@0: TDriveInfoV1 &di=diBuf(); sl@0: test.Printf(_L("Select Local Drive (C-%c): "),'C'+(di.iTotalSupportedDrives-1)); sl@0: TChar c; sl@0: TInt drv; sl@0: FOREVER sl@0: { sl@0: c=(TUint)test.Getch(); sl@0: c.UpperCase(); sl@0: drv=((TUint)c)-'C'; sl@0: if (drv>=0&&drv=1&&rdWrLen<=8) sl@0: break; sl@0: } sl@0: test.Printf(_L("%dSector(s)\r\n"),rdWrLen); sl@0: rdWrLen*=KAtaSectorSize; sl@0: #else sl@0: rdWrLen=(KAtaSectorSize*2)+1; sl@0: #endif sl@0: sl@0: b.Format(_L("Init test on drive %c:"),'C'+drv); sl@0: test.Start(b); sl@0: sl@0: TInt r; sl@0: #if defined (USE_F32_ACCESS) sl@0: r=TheFs.Connect(); sl@0: test(r==KErrNone); sl@0: sl@0: RFile f; sl@0: b.Format(_L("%c:\\TEMP.BIN"),'C'+drv); sl@0: r=f.Replace(TheFs,b,EFileShareAny|EFileStream|EFileWrite); sl@0: test(r==KErrNone); sl@0: b.Format(_L("Start testing (%c:\\TEMP.BIN):"),'C'+drv); sl@0: #else sl@0: r=User::LoadPhysicalDevice(ATA_PDD_NAME); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: ChangedFlag=EFalse; sl@0: TheDrive.Connect(drv,ChangedFlag); sl@0: sl@0: TLocalDriveCapsV2Buf info; sl@0: test(TheDrive.Caps(info)==KErrNone); sl@0: test(info().iType==EMediaHardDisk); sl@0: TInt trgPos=I64LOW(info().iSize)-rdWrLen; // Hammer the very end of the disk sl@0: b.Format(_L("Start testing (sector %xH):"),trgPos/KAtaSectorSize); sl@0: #endif sl@0: sl@0: test.Next(b); sl@0: wrBufPat1.SetLength(rdWrLen); sl@0: TInt j; sl@0: for (j=0;jRead(kStat); sl@0: FOREVER sl@0: { sl@0: if ((cycles%10)==0) sl@0: results.Display(test.Console(),cycles); sl@0: sl@0: TInt res; sl@0: #if defined (USE_F32_ACCESS) sl@0: TInt len=(toggleTest)?rdWrLen:1; sl@0: sl@0: wrBufPat1.SetLength(len); sl@0: if ((res=f.SetSize(len))==KErrNone) sl@0: res=f.Write(0,wrBufPat1); // Write test (Pos=0) sl@0: if (res!=KErrNone) sl@0: results.Add(res,EWrite,cycles); sl@0: sl@0: // Read test sl@0: rdBuf.Fill(0,len); sl@0: res=f.Read(0,rdBuf,len); sl@0: if (res!=KErrNone) sl@0: results.Add(res,ERead,cycles); sl@0: if (rdBuf.Compare(wrBufPat1)!=0) sl@0: results.Add(0,ECompare,cycles); sl@0: #else sl@0: TDes8* wrBuf=(toggleTest)?&wrBufPat2:&wrBufPat1; // Change pattern written sl@0: sl@0: res=TheDrive.Write(trgPos,*wrBuf); // Write test sl@0: if (res!=KErrNone) sl@0: results.Add(res,EWrite,cycles); sl@0: sl@0: rdBuf.Fill(0,rdWrLen); sl@0: res=TheDrive.Read(trgPos,rdWrLen,rdBuf); // Read test sl@0: if (res!=KErrNone) sl@0: results.Add(res,ERead,cycles); sl@0: if (rdBuf.Compare(*wrBuf)!=0) sl@0: results.Add(0,ECompare,cycles); sl@0: #endif sl@0: cycles++; sl@0: toggleTest^=0x01; sl@0: sl@0: if (kStat!=KRequestPending) sl@0: { sl@0: TKeyCode c=test.Console()->KeyCode(); sl@0: if (c==EKeySpace) sl@0: break; sl@0: test.Console()->Read(kStat); sl@0: } sl@0: } sl@0: sl@0: test.Next(_L("Close")); sl@0: #if defined (USE_F32_ACCESS) sl@0: f.Close(); sl@0: TheFs.Close(); sl@0: #else sl@0: TheDrive.Disconnect(); sl@0: #endif sl@0: sl@0: test.End(); sl@0: return(0); sl@0: } sl@0: