Update contrib.
1 // Copyright (c) 1997-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_pccdsk.cpp
15 // Soak test the Compact Flash card (ATA).
21 #define USE_MEDIA_CHANGE
22 //#define USE_POWER_OFF_ON
30 #define ATA_PDD_NAME _L("MEDATA")
32 const TInt KAtaSectorSize=512;
33 const TInt KMaxSectors=16;
34 const TInt KMaxRdWrBufLen=(KAtaSectorSize*KMaxSectors); // 8K
35 const TInt KMaxErrPos=5;
37 LOCAL_D TBusLocalDrive TheDrive;
38 LOCAL_D TBool ChangedFlag;
39 RTest test(_L("Local Drive Soak Test"));
40 LOCAL_D TBuf8<KMaxRdWrBufLen> wrBuf1,wrBuf2,rdBuf;
45 enum TResTest {EWrite,ERead,ECompare,EFormat,EReMount};
47 void Display(CConsoleBase *aConsole, TInt aCycles);
48 void Add(TResTest aTst,TInt anErr,TInt anErrPos);
49 inline void SetMemStillFree(TInt aVal)
51 inline void WriteAborted()
53 inline TInt WriteFails()
54 {return(iWriteTimeoutFails+iWriteWriteFails+iWriteGeneralFails+iWriteCorruptFails+iWriteBatLowFails+iWriteOtherFails);}
55 inline TInt ReadFails()
56 {return(iReadTimeoutFails+iReadCorruptFails+iReadOtherFails);}
57 inline TInt CompareFails()
58 {return(iCompareFails);}
59 inline TInt FormatFails()
60 {return(iFormatTimeoutFails+iFormatEmergencyFails+iFormatBatLowFails+iFormatOtherFails);}
61 inline TInt ReMountFails()
62 {return(iReMountFails);}
64 TInt iWriteTimeoutFails;
65 TInt iWriteWriteFails;
66 TInt iWriteGeneralFails;
67 TInt iWriteCorruptFails;
68 TInt iWriteBatLowFails;
69 TInt iWriteOtherFails;
70 TInt iReadTimeoutFails;
71 TInt iReadCorruptFails;
74 TInt iFormatTimeoutFails;
75 TInt iFormatEmergencyFails;
76 TInt iFormatBatLowFails;
77 TInt iFormatOtherFails;
79 TInt iLastErrorPos[KMaxErrPos];
86 LOCAL_C void StatusBar(TInt aPos,TInt anEndPos,TInt aYPos,const TPtrC &aTitle)
88 // Display progress of local drive operation on screen (1-16 dots)
93 if ((curr=(aPos-1)/(anEndPos>>4))>prev)
94 { // Update progress bar
95 test.Console()->SetPos(0,aYPos);
97 test.Console()->SetPos(2);
98 test.Printf(_L("%S "),&aTitle);
99 for (TInt i=curr;i>=0;i--)
100 test.Printf(_L("."));
111 iWriteTimeoutFails=0;
113 iWriteGeneralFails=0;
114 iWriteCorruptFails=0;
121 iFormatTimeoutFails=0;
122 iFormatEmergencyFails=0;
123 iFormatBatLowFails=0;
126 for (TInt i=0;i<KMaxErrPos;i++)
133 void TResult::Display(CConsoleBase *aConsole, TInt aCycles)
135 // Display test results
142 aConsole->SetPos(xStartPos,yStartPos);
143 test.Printf(_L("Cycles(%08xH) : %d"),iFreeMem,aCycles);
145 aConsole->SetPos(xStartPos,yStartPos+1);
147 test.Printf(_L("Write Fails : %d (TO:%d BT:%d WR:%d GE:%d CU:%d OT:%d)"),WriteFails(),iWriteTimeoutFails,\
148 iWriteBatLowFails,iWriteWriteFails,iWriteGeneralFails,iWriteCorruptFails,iWriteOtherFails);
150 test.Printf(_L("Write Fails : 0"));
152 aConsole->SetPos(xStartPos,yStartPos+2);
154 test.Printf(_L("Read Fails : %d (TO:%d CU:%d OT:%d)"),ReadFails(),iReadTimeoutFails,iReadCorruptFails,iReadOtherFails);
156 test.Printf(_L("Read Fails : 0"));
158 aConsole->SetPos(xStartPos,yStartPos+3);
159 test.Printf(_L("Compare Fails : %d"),CompareFails());
161 aConsole->SetPos(xStartPos,yStartPos+4);
163 test.Printf(_L("Format Fails : %d (TO:%d EM:%d BT:%d OT:%d)"),FormatFails(),iFormatTimeoutFails,iFormatEmergencyFails,iFormatBatLowFails,iFormatOtherFails);
165 test.Printf(_L("Format Fails : 0"));
167 aConsole->SetPos(xStartPos,yStartPos+5);
168 #if defined (USE_MEDIA_CHANGE)
169 test.Printf(_L("MediaChange Fails : %d"),ReMountFails());
171 test.Printf(_L("Pwr off/on Fails : %d"),ReMountFails());
174 aConsole->SetPos(xStartPos,yStartPos+6);
175 test.Printf(_L("Last failures at : "));
176 for (TInt i=iLastErrorPtr;i>0;i--)
177 test.Printf(_L("%xH "),iLastErrorPos[i-1]);
178 aConsole->SetPos(xStartPos,yStartPos+7);
179 test.Printf(_L("Writes aborted : %d"),iAbortedWrites);
180 test.Printf(_L("\r\n"));
183 void TResult::Add(TResTest aTst,TInt anErr,TInt anErrPos)
191 RDebug::Print(_L("%d) %d(%x)"),aTst,anErr,anErrPos);
192 // Save start sector involved in operation which failed
195 if (iLastErrorPtr>=KMaxErrPos)
198 for (i=0;i<(KMaxErrPos-1);i++)
199 iLastErrorPos[i]=iLastErrorPos[i+1];
200 iLastErrorPos[i]=anErrPos;
205 iLastErrorPos[iLastErrorPtr-1]=anErrPos;
213 if (anErr==KErrTimedOut)
214 iWriteTimeoutFails++;
215 else if (anErr==KErrWrite)
217 else if (anErr==KErrGeneral)
218 iWriteGeneralFails++;
219 else if (anErr==KErrCorrupt)
220 iWriteCorruptFails++;
221 else if (anErr==KErrBadPower)
227 if (anErr==KErrTimedOut)
229 else if (anErr==KErrCorrupt)
238 if (anErr==KErrTimedOut)
239 iFormatTimeoutFails++;
240 else if (anErr==KErrAbort)
241 iFormatEmergencyFails++;
242 else if (anErr==KErrBadPower)
243 iFormatBatLowFails++;
254 LOCAL_C TUint GetTUintFromConsole(const TDesC &aText)
256 // Get a TUint value from the console
264 TUint linePos=(aText.Length()+2);
265 test.Console()->SetPos(linePos);
268 switch((kc=test.Getch()))
270 case EKeyEscape: case EKeyEnter:
274 if (lex.Val(v,EDecimal)==KErrNone)
278 case EKeyBackspace: case EKeyDelete:
282 test.Console()->SetPos(linePos);
283 test.Printf(_L(" "));
284 test.Console()->SetPos(linePos);
288 if (ch.IsDigit() && pos<9)
292 test.Printf(_L("%c"),(TUint)ch);
300 GLDEF_C TInt E32Main()
305 TDriveInfoV1Buf diBuf;
306 UserHal::DriveInfo(diBuf);
307 TDriveInfoV1 &di=diBuf();
308 test.Printf(_L("Select Local Drive (C-%c): "),'C'+(di.iTotalSupportedDrives-1));
313 c=(TUint)test.Getch();
316 if (drv>=0&&drv<di.iTotalSupportedDrives)
319 test.Printf(_L("%c:\r\n"),'C'+drv);
321 test.Printf(_L("Select Test Sequence (Sector 1-R,2-WR,3-WRF)/(SubSector 4-R,5-WR,6-WRF): "));
325 c=(TUint)test.Getch();
326 testSeq=((TUint)c)-'0';
327 if (testSeq>=0&&testSeq<=6)
330 test.Printf(_L("%d\r\n"),testSeq);
332 TInt RdWrLen=(TInt)GetTUintFromConsole(_L("Select Buffer Size In Sectors: "));
333 RdWrLen*=KAtaSectorSize;
335 test.Start(_L("Load Ata Media Driver"));
337 r=User::LoadPhysicalDevice(ATA_PDD_NAME);
338 test(r==KErrNone || r==KErrAlreadyExists);
339 #if defined (USE_POWER_OFF_ON)
341 test(timer.CreateLocal()==KErrNone);
346 r=HAL::Get(HAL::EMachineUid, muid);
348 TBool reMountTestSupported=ETrue;
349 // if (machineName.MatchF(_L("SNOWBALL*"))>=0) // snowball is ancient history
350 // reMountTestSupported=EFalse;
352 b.Format(_L("Connect to drive %c:"),'C'+drv);
355 TheDrive.Connect(drv,ChangedFlag);
357 test.Next(_L("ATA drive: Capabilities"));
358 TLocalDriveCapsV2Buf info;
359 test(TheDrive.Caps(info)==KErrNone);
360 test(info().iType==EMediaHardDisk);
361 TInt diskSize=I64LOW(info().iSize);
363 wrBuf1.SetLength(RdWrLen);
365 for (j=0;j<RdWrLen;j++)
367 wrBuf2.SetLength(RdWrLen);
368 for (j=0;j<RdWrLen;j++)
369 wrBuf2[j]=(TUint8)((RdWrLen-1)-j);
375 TBool decendPat=EFalse;
377 TRequestStatus kStat;
378 test.Console()->Read(kStat);
381 wrBuf=(decendPat)?&wrBuf2:&wrBuf1;
382 p=(decendPat)?(TUint*)&wrBuf2[0]:(TUint*)&wrBuf1[0];
385 // Recalculate amount of free memory
386 TMemoryInfoV1Buf membuf;
387 UserHal::MemoryInfo(membuf);
388 TMemoryInfoV1 &memoryInfo=membuf();
389 results.SetMemStillFree(memoryInfo.iFreeRamInBytes);
390 results.Display(test.Console(),cycles);
393 RDebug::Print(_L("0"));
394 if (testSeq==2||testSeq==3||testSeq==5||testSeq==6)
396 for (i=0,j=0;i<diskSize;i+=len,j++)
398 StatusBar(i,diskSize,16,_L("WRITING "));
400 len=Min(RdWrLen-3,(diskSize-i)); // Not on sector boundary
402 len=Min(RdWrLen,(diskSize-i));
404 wrBuf->SetLength(len);
407 res=TheDrive.Write(i,*wrBuf);
410 results.WriteAborted();
411 results.Display(test.Console(),cycles);
413 } while (res==KErrNotReady||res==KErrAbort);
414 results.Add(TResult::EWrite,res,i);
418 results.Display(test.Console(),cycles);
422 RDebug::Print(_L("1"));
425 for (i=0,j=0;i<diskSize;i+=len,j++)
427 StatusBar(i,diskSize,16,_L("READING "));
429 len=Min(RdWrLen-3,(diskSize-i)); // Not on sector boundary
431 len=Min(RdWrLen,(diskSize-i));
435 res=TheDrive.Read(i,len,rdBuf);
436 } while (res==KErrNotReady);
438 results.Add(TResult::ERead,res,i);
441 if (testSeq==2||testSeq==3||testSeq==5||testSeq==6)
444 wrBuf->SetLength(len);
445 if (rdBuf.Compare(*wrBuf)!=0)
447 results.Add(TResult::ECompare,KErrGeneral,-1);
452 results.Display(test.Console(),cycles);
456 RDebug::Print(_L("3"));
457 if (testSeq==3||testSeq==6)
462 StatusBar((fi.i512ByteSectorsFormatted<<9),diskSize,16,_L("FORMATTING"));
465 res=TheDrive.Format(fi);
466 } while (res==KErrNotReady);
469 results.Add(TResult::EFormat,res,(fi.i512ByteSectorsFormatted<<9));
473 results.Display(test.Console(),cycles);
476 RDebug::Print(_L("4"));
477 if (reMountTestSupported)
479 // Media change test / power off-on test
480 #if defined (USE_MEDIA_CHANGE)
481 TheDrive.ForceMediaChange();
482 if (ChangedFlag==EFalse)
483 results.Add(TResult::EReMount,KErrGeneral,-1);
486 tim+=TTimeIntervalSeconds(8);
488 UserHal::SwitchOff(); // Switch off
489 User::WaitForRequest(prs); // Switch back on
490 if (prs.Int()!=KErrNone)
491 results.Add(TResult::EReMount,KErrGeneral,-1);
497 res=TheDrive.Caps(info);
498 } while (res==KErrNotReady);
501 if (info().iType!=EMediaHardDisk)
502 results.Add(TResult::EReMount,KErrGeneral,-1);
505 results.Add(TResult::EReMount,res,-1);
513 if (kStat!=KRequestPending)
515 TKeyCode c=test.Console()->KeyCode();
518 test.Console()->Read(kStat);
520 RDebug::Print(_L("<<"));
523 b.Format(_L("Disconnect from local drive (%c:)"),'C'+drv);
525 TheDrive.Disconnect();