Update contrib.
1 // Copyright (c) 1998-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\pccd\t_pccdsr.cpp
15 // Stress test a single sector of Compact Flash card (ATA).
20 //#define USE_F32_ACCESS
25 #if defined (USE_F32_ACCESS)
30 #define ATA_PDD_NAME _L("MEDATA")
32 const TInt KAtaSectorSize=512;
33 const TInt KMaxSectors=8;
34 const TInt KMaxRdWrBufLen=(KAtaSectorSize*KMaxSectors); // 4K
35 const TInt KHeapSize=0x4000;
38 #if defined (USE_F32_ACCESS)
41 LOCAL_D TBusLocalDrive TheDrive;
42 LOCAL_D TBool ChangedFlag;
44 RTest test(_L("Local Drive Stress test"));
45 LOCAL_D TBuf8<KMaxRdWrBufLen> wrBufPat1,wrBufPat2,rdBuf;
47 enum TOper {ENone,EWrite,ERead,ECompare};
62 void Display(CConsoleBase *aConsole, TInt aCycles);
63 void Add(TInt anError,TOper anOperation,TInt aCycle);
67 TErrInfo iLastErrs[KMaxErr];
73 LOCAL_C TUint OperationToChar(TOper anOperation)
75 // Convert operation enum to corresponding display character
114 void TResult::Display(CConsoleBase *aConsole, TInt aCycles)
116 // Display test results
123 aConsole->SetPos(xStartPos,yStartPos);
124 test.Printf(_L("CYCLES-> %07d ERRORS-> %d"),aCycles,iTotalErrs);
126 aConsole->SetPos(xStartPos,yStartPos+1);
127 test.Printf(_L("FIRST ERROR-> "));
129 test.Printf(_L("Error:%d Oper:%c Cycle:%07d"),iFirstErr.iError,OperationToChar(iFirstErr.iOperation),iFirstErr.iCycle);
131 aConsole->SetPos(xStartPos,yStartPos+2);
132 test.Printf(_L("LAST ERRORS->"));
136 aConsole->SetPos(xStartPos+3,yStartPos+3);
137 test.Printf(_L("Error: "));
138 for (i=0;(i<KMaxErr && iLastErrs[i].iOperation!=ENone);i++)
139 test.Printf(_L("% 7d,"),iLastErrs[i].iError);
141 aConsole->SetPos(xStartPos+3,yStartPos+4);
142 test.Printf(_L("Oper: "));
143 for (i=0;(i<KMaxErr && iLastErrs[i].iOperation!=ENone);i++)
144 test.Printf(_L(" %c,"),OperationToChar(iLastErrs[i].iOperation));
146 aConsole->SetPos(xStartPos+3,yStartPos+5);
147 test.Printf(_L("Cycle: "));
148 for (i=0;(i<KMaxErr && iLastErrs[i].iOperation!=ENone);i++)
149 test.Printf(_L("% 7d,"),iLastErrs[i].iCycle);
152 test.Printf(_L("\r\n"));
155 void TResult::Add(TInt anError,TOper anOperation,TInt aCycle)
164 iFirstErr.iError=anError;
165 iFirstErr.iOperation=anOperation;
166 iFirstErr.iCycle=aCycle;
169 if (iNextFreeErr>=KMaxErr)
171 for (TInt i=0;i<(KMaxErr-1);i++)
172 iLastErrs[i]=iLastErrs[i+1];
173 iNextFreeErr=(KMaxErr-1);
175 iLastErrs[iNextFreeErr].iError=anError;
176 iLastErrs[iNextFreeErr].iOperation=anOperation;
177 iLastErrs[iNextFreeErr].iCycle=aCycle;
181 GLDEF_C TInt E32Main()
186 TDriveInfoV1Buf diBuf;
187 UserHal::DriveInfo(diBuf);
188 TDriveInfoV1 &di=diBuf();
189 test.Printf(_L("Select Local Drive (C-%c): "),'C'+(di.iTotalSupportedDrives-1));
194 c=(TUint)test.Getch();
197 if (drv>=0&&drv<di.iTotalSupportedDrives)
200 test.Printf(_L("%c:\r\n"),'C'+drv);
203 #if !defined (USE_F32_ACCESS)
204 test.Printf(_L("Select total sectors to write(1-8): "));
207 c=(TUint)test.Getch();
208 rdWrLen=((TUint)c)-'0';
209 if (rdWrLen>=1&&rdWrLen<=8)
212 test.Printf(_L("%dSector(s)\r\n"),rdWrLen);
213 rdWrLen*=KAtaSectorSize;
215 rdWrLen=(KAtaSectorSize*2)+1;
218 b.Format(_L("Init test on drive %c:"),'C'+drv);
222 #if defined (USE_F32_ACCESS)
227 b.Format(_L("%c:\\TEMP.BIN"),'C'+drv);
228 r=f.Replace(TheFs,b,EFileShareAny|EFileStream|EFileWrite);
230 b.Format(_L("Start testing (%c:\\TEMP.BIN):"),'C'+drv);
232 r=User::LoadPhysicalDevice(ATA_PDD_NAME);
233 test(r==KErrNone || r==KErrAlreadyExists);
236 TheDrive.Connect(drv,ChangedFlag);
238 TLocalDriveCapsV2Buf info;
239 test(TheDrive.Caps(info)==KErrNone);
240 test(info().iType==EMediaHardDisk);
241 TInt trgPos=I64LOW(info().iSize)-rdWrLen; // Hammer the very end of the disk
242 b.Format(_L("Start testing (sector %xH):"),trgPos/KAtaSectorSize);
246 wrBufPat1.SetLength(rdWrLen);
248 for (j=0;j<rdWrLen;j++)
249 wrBufPat1[j]=(TUint8)j;
250 wrBufPat2.SetLength(rdWrLen);
251 for (j=0;j<rdWrLen;j++)
252 wrBufPat2[j]=(TUint8)((rdWrLen-1)-j);
256 TBool toggleTest=EFalse;
258 TRequestStatus kStat;
259 test.Console()->Read(kStat);
263 results.Display(test.Console(),cycles);
266 #if defined (USE_F32_ACCESS)
267 TInt len=(toggleTest)?rdWrLen:1;
269 wrBufPat1.SetLength(len);
270 if ((res=f.SetSize(len))==KErrNone)
271 res=f.Write(0,wrBufPat1); // Write test (Pos=0)
273 results.Add(res,EWrite,cycles);
277 res=f.Read(0,rdBuf,len);
279 results.Add(res,ERead,cycles);
280 if (rdBuf.Compare(wrBufPat1)!=0)
281 results.Add(0,ECompare,cycles);
283 TDes8* wrBuf=(toggleTest)?&wrBufPat2:&wrBufPat1; // Change pattern written
285 res=TheDrive.Write(trgPos,*wrBuf); // Write test
287 results.Add(res,EWrite,cycles);
289 rdBuf.Fill(0,rdWrLen);
290 res=TheDrive.Read(trgPos,rdWrLen,rdBuf); // Read test
292 results.Add(res,ERead,cycles);
293 if (rdBuf.Compare(*wrBuf)!=0)
294 results.Add(0,ECompare,cycles);
299 if (kStat!=KRequestPending)
301 TKeyCode c=test.Console()->KeyCode();
304 test.Console()->Read(kStat);
308 test.Next(_L("Close"));
309 #if defined (USE_F32_ACCESS)
313 TheDrive.Disconnect();