1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/pccd/t_pccdsk.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,530 @@
1.4 +// Copyright (c) 1997-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_pccdsk.cpp
1.18 +// Soak test the Compact Flash card (ATA).
1.19 +//
1.20 +//
1.21 +
1.22 +
1.23 +// One of these
1.24 +#define USE_MEDIA_CHANGE
1.25 +//#define USE_POWER_OFF_ON
1.26 +
1.27 +#include <e32test.h>
1.28 +#include <e32svr.h>
1.29 +#include <e32hal.h>
1.30 +#include <e32uid.h>
1.31 +#include <hal.h>
1.32 +
1.33 +#define ATA_PDD_NAME _L("MEDATA")
1.34 +
1.35 +const TInt KAtaSectorSize=512;
1.36 +const TInt KMaxSectors=16;
1.37 +const TInt KMaxRdWrBufLen=(KAtaSectorSize*KMaxSectors); // 8K
1.38 +const TInt KMaxErrPos=5;
1.39 +
1.40 +LOCAL_D TBusLocalDrive TheDrive;
1.41 +LOCAL_D TBool ChangedFlag;
1.42 +RTest test(_L("Local Drive Soak Test"));
1.43 +LOCAL_D TBuf8<KMaxRdWrBufLen> wrBuf1,wrBuf2,rdBuf;
1.44 +
1.45 +class TResult
1.46 + {
1.47 +public:
1.48 + enum TResTest {EWrite,ERead,ECompare,EFormat,EReMount};
1.49 + TResult();
1.50 + void Display(CConsoleBase *aConsole, TInt aCycles);
1.51 + void Add(TResTest aTst,TInt anErr,TInt anErrPos);
1.52 + inline void SetMemStillFree(TInt aVal)
1.53 + {iFreeMem=aVal;}
1.54 + inline void WriteAborted()
1.55 + {iAbortedWrites++;}
1.56 + inline TInt WriteFails()
1.57 + {return(iWriteTimeoutFails+iWriteWriteFails+iWriteGeneralFails+iWriteCorruptFails+iWriteBatLowFails+iWriteOtherFails);}
1.58 + inline TInt ReadFails()
1.59 + {return(iReadTimeoutFails+iReadCorruptFails+iReadOtherFails);}
1.60 + inline TInt CompareFails()
1.61 + {return(iCompareFails);}
1.62 + inline TInt FormatFails()
1.63 + {return(iFormatTimeoutFails+iFormatEmergencyFails+iFormatBatLowFails+iFormatOtherFails);}
1.64 + inline TInt ReMountFails()
1.65 + {return(iReMountFails);}
1.66 +public:
1.67 + TInt iWriteTimeoutFails;
1.68 + TInt iWriteWriteFails;
1.69 + TInt iWriteGeneralFails;
1.70 + TInt iWriteCorruptFails;
1.71 + TInt iWriteBatLowFails;
1.72 + TInt iWriteOtherFails;
1.73 + TInt iReadTimeoutFails;
1.74 + TInt iReadCorruptFails;
1.75 + TInt iReadOtherFails;
1.76 + TInt iCompareFails;
1.77 + TInt iFormatTimeoutFails;
1.78 + TInt iFormatEmergencyFails;
1.79 + TInt iFormatBatLowFails;
1.80 + TInt iFormatOtherFails;
1.81 + TInt iReMountFails;
1.82 + TInt iLastErrorPos[KMaxErrPos];
1.83 + TInt iLastErrorPtr;
1.84 + TInt iFreeMem;
1.85 + TInt iAbortedWrites;
1.86 + };
1.87 +
1.88 +
1.89 +LOCAL_C void StatusBar(TInt aPos,TInt anEndPos,TInt aYPos,const TPtrC &aTitle)
1.90 +//
1.91 +// Display progress of local drive operation on screen (1-16 dots)
1.92 +//
1.93 + {
1.94 + static TInt prev;
1.95 + TInt curr;
1.96 + if ((curr=(aPos-1)/(anEndPos>>4))>prev)
1.97 + { // Update progress bar
1.98 + test.Console()->SetPos(0,aYPos);
1.99 + test.Printf(_L(" "));
1.100 + test.Console()->SetPos(2);
1.101 + test.Printf(_L("%S "),&aTitle);
1.102 + for (TInt i=curr;i>=0;i--)
1.103 + test.Printf(_L("."));
1.104 + }
1.105 + prev=curr;
1.106 + }
1.107 +
1.108 +TResult::TResult()
1.109 +//
1.110 +// Constructor
1.111 +//
1.112 + {
1.113 +
1.114 + iWriteTimeoutFails=0;
1.115 + iWriteWriteFails=0;
1.116 + iWriteGeneralFails=0;
1.117 + iWriteCorruptFails=0;
1.118 + iWriteBatLowFails=0;
1.119 + iWriteOtherFails=0;
1.120 + iReadTimeoutFails=0;
1.121 + iReadCorruptFails=0;
1.122 + iReadOtherFails=0;
1.123 + iCompareFails=0;
1.124 + iFormatTimeoutFails=0;
1.125 + iFormatEmergencyFails=0;
1.126 + iFormatBatLowFails=0;
1.127 + iFormatOtherFails=0;
1.128 + iReMountFails=0;
1.129 + for (TInt i=0;i<KMaxErrPos;i++)
1.130 + iLastErrorPos[i]=0;
1.131 + iLastErrorPtr=0;
1.132 + iFreeMem=0;
1.133 + iAbortedWrites=0;
1.134 + }
1.135 +
1.136 +void TResult::Display(CConsoleBase *aConsole, TInt aCycles)
1.137 +//
1.138 +// Display test results
1.139 +//
1.140 + {
1.141 +
1.142 + TInt xStartPos=3;
1.143 + TInt yStartPos=8;
1.144 +
1.145 + aConsole->SetPos(xStartPos,yStartPos);
1.146 + test.Printf(_L("Cycles(%08xH) : %d"),iFreeMem,aCycles);
1.147 +
1.148 + aConsole->SetPos(xStartPos,yStartPos+1);
1.149 + if (WriteFails())
1.150 + test.Printf(_L("Write Fails : %d (TO:%d BT:%d WR:%d GE:%d CU:%d OT:%d)"),WriteFails(),iWriteTimeoutFails,\
1.151 + iWriteBatLowFails,iWriteWriteFails,iWriteGeneralFails,iWriteCorruptFails,iWriteOtherFails);
1.152 + else
1.153 + test.Printf(_L("Write Fails : 0"));
1.154 +
1.155 + aConsole->SetPos(xStartPos,yStartPos+2);
1.156 + if (ReadFails())
1.157 + test.Printf(_L("Read Fails : %d (TO:%d CU:%d OT:%d)"),ReadFails(),iReadTimeoutFails,iReadCorruptFails,iReadOtherFails);
1.158 + else
1.159 + test.Printf(_L("Read Fails : 0"));
1.160 +
1.161 + aConsole->SetPos(xStartPos,yStartPos+3);
1.162 + test.Printf(_L("Compare Fails : %d"),CompareFails());
1.163 +
1.164 + aConsole->SetPos(xStartPos,yStartPos+4);
1.165 + if (FormatFails())
1.166 + test.Printf(_L("Format Fails : %d (TO:%d EM:%d BT:%d OT:%d)"),FormatFails(),iFormatTimeoutFails,iFormatEmergencyFails,iFormatBatLowFails,iFormatOtherFails);
1.167 + else
1.168 + test.Printf(_L("Format Fails : 0"));
1.169 +
1.170 + aConsole->SetPos(xStartPos,yStartPos+5);
1.171 +#if defined (USE_MEDIA_CHANGE)
1.172 + test.Printf(_L("MediaChange Fails : %d"),ReMountFails());
1.173 +#else
1.174 + test.Printf(_L("Pwr off/on Fails : %d"),ReMountFails());
1.175 +#endif
1.176 +
1.177 + aConsole->SetPos(xStartPos,yStartPos+6);
1.178 + test.Printf(_L("Last failures at : "));
1.179 + for (TInt i=iLastErrorPtr;i>0;i--)
1.180 + test.Printf(_L("%xH "),iLastErrorPos[i-1]);
1.181 + aConsole->SetPos(xStartPos,yStartPos+7);
1.182 + test.Printf(_L("Writes aborted : %d"),iAbortedWrites);
1.183 + test.Printf(_L("\r\n"));
1.184 + }
1.185 +
1.186 +void TResult::Add(TResTest aTst,TInt anErr,TInt anErrPos)
1.187 +//
1.188 +// Add a test result
1.189 +//
1.190 + {
1.191 +
1.192 + if (anErr!=KErrNone)
1.193 + {
1.194 + RDebug::Print(_L("%d) %d(%x)"),aTst,anErr,anErrPos);
1.195 + // Save start sector involved in operation which failed
1.196 + if (anErrPos>=0)
1.197 + {
1.198 + if (iLastErrorPtr>=KMaxErrPos)
1.199 + {
1.200 + TInt i;
1.201 + for (i=0;i<(KMaxErrPos-1);i++)
1.202 + iLastErrorPos[i]=iLastErrorPos[i+1];
1.203 + iLastErrorPos[i]=anErrPos;
1.204 + }
1.205 + else
1.206 + {
1.207 + iLastErrorPtr++;
1.208 + iLastErrorPos[iLastErrorPtr-1]=anErrPos;
1.209 + }
1.210 + }
1.211 +
1.212 + // Save error type
1.213 + switch (aTst)
1.214 + {
1.215 + case EWrite:
1.216 + if (anErr==KErrTimedOut)
1.217 + iWriteTimeoutFails++;
1.218 + else if (anErr==KErrWrite)
1.219 + iWriteWriteFails++;
1.220 + else if (anErr==KErrGeneral)
1.221 + iWriteGeneralFails++;
1.222 + else if (anErr==KErrCorrupt)
1.223 + iWriteCorruptFails++;
1.224 + else if (anErr==KErrBadPower)
1.225 + iWriteBatLowFails++;
1.226 + else
1.227 + iWriteOtherFails++;
1.228 + break;
1.229 + case ERead:
1.230 + if (anErr==KErrTimedOut)
1.231 + iReadTimeoutFails++;
1.232 + else if (anErr==KErrCorrupt)
1.233 + iReadCorruptFails++;
1.234 + else
1.235 + iReadOtherFails++;
1.236 + break;
1.237 + case ECompare:
1.238 + iCompareFails++;
1.239 + break;
1.240 + case EFormat:
1.241 + if (anErr==KErrTimedOut)
1.242 + iFormatTimeoutFails++;
1.243 + else if (anErr==KErrAbort)
1.244 + iFormatEmergencyFails++;
1.245 + else if (anErr==KErrBadPower)
1.246 + iFormatBatLowFails++;
1.247 + else
1.248 + iFormatOtherFails++;
1.249 + break;
1.250 + case EReMount:
1.251 + iReMountFails++;
1.252 + break;
1.253 + }
1.254 + }
1.255 + }
1.256 +
1.257 +LOCAL_C TUint GetTUintFromConsole(const TDesC &aText)
1.258 +//
1.259 +// Get a TUint value from the console
1.260 +//
1.261 + {
1.262 +
1.263 + TBuf<10> buf(0);
1.264 + TKeyCode kc;
1.265 + TUint pos=0;
1.266 + test.Printf(aText);
1.267 + TUint linePos=(aText.Length()+2);
1.268 + test.Console()->SetPos(linePos);
1.269 + FOREVER
1.270 + {
1.271 + switch((kc=test.Getch()))
1.272 + {
1.273 + case EKeyEscape: case EKeyEnter:
1.274 + {
1.275 + TLex lex(buf);
1.276 + TUint v;
1.277 + if (lex.Val(v,EDecimal)==KErrNone)
1.278 + return(v);
1.279 + return(0);
1.280 + }
1.281 + case EKeyBackspace: case EKeyDelete:
1.282 + pos--;
1.283 + buf.Delete(pos,1);
1.284 + linePos--;
1.285 + test.Console()->SetPos(linePos);
1.286 + test.Printf(_L(" "));
1.287 + test.Console()->SetPos(linePos);
1.288 + break;
1.289 + default:
1.290 + TChar ch=(TUint)kc;
1.291 + if (ch.IsDigit() && pos<9)
1.292 + {
1.293 + buf.Append(ch);
1.294 + pos++;
1.295 + test.Printf(_L("%c"),(TUint)ch);
1.296 + linePos++;
1.297 + }
1.298 + break;
1.299 + }
1.300 + }
1.301 + }
1.302 +
1.303 +GLDEF_C TInt E32Main()
1.304 + {
1.305 + TBuf<64> b;
1.306 +
1.307 + test.Title();
1.308 + TDriveInfoV1Buf diBuf;
1.309 + UserHal::DriveInfo(diBuf);
1.310 + TDriveInfoV1 &di=diBuf();
1.311 + test.Printf(_L("Select Local Drive (C-%c): "),'C'+(di.iTotalSupportedDrives-1));
1.312 + TChar c;
1.313 + TInt drv;
1.314 + FOREVER
1.315 + {
1.316 + c=(TUint)test.Getch();
1.317 + c.UpperCase();
1.318 + drv=((TUint)c)-'C';
1.319 + if (drv>=0&&drv<di.iTotalSupportedDrives)
1.320 + break;
1.321 + }
1.322 + test.Printf(_L("%c:\r\n"),'C'+drv);
1.323 +
1.324 + test.Printf(_L("Select Test Sequence (Sector 1-R,2-WR,3-WRF)/(SubSector 4-R,5-WR,6-WRF): "));
1.325 + TInt testSeq;
1.326 + FOREVER
1.327 + {
1.328 + c=(TUint)test.Getch();
1.329 + testSeq=((TUint)c)-'0';
1.330 + if (testSeq>=0&&testSeq<=6)
1.331 + break;
1.332 + }
1.333 + test.Printf(_L("%d\r\n"),testSeq);
1.334 +
1.335 + TInt RdWrLen=(TInt)GetTUintFromConsole(_L("Select Buffer Size In Sectors: "));
1.336 + RdWrLen*=KAtaSectorSize;
1.337 +
1.338 + test.Start(_L("Load Ata Media Driver"));
1.339 + TInt r;
1.340 + r=User::LoadPhysicalDevice(ATA_PDD_NAME);
1.341 + test(r==KErrNone || r==KErrAlreadyExists);
1.342 +#if defined (USE_POWER_OFF_ON)
1.343 + RTimer timer;
1.344 + test(timer.CreateLocal()==KErrNone);
1.345 + TRequestStatus prs;
1.346 + TTime tim;
1.347 +#endif
1.348 + TInt muid=0;
1.349 + r=HAL::Get(HAL::EMachineUid, muid);
1.350 + test(r==KErrNone);
1.351 + TBool reMountTestSupported=ETrue;
1.352 +// if (machineName.MatchF(_L("SNOWBALL*"))>=0) // snowball is ancient history
1.353 +// reMountTestSupported=EFalse;
1.354 +
1.355 + b.Format(_L("Connect to drive %c:"),'C'+drv);
1.356 + test.Next(b);
1.357 + ChangedFlag=EFalse;
1.358 + TheDrive.Connect(drv,ChangedFlag);
1.359 +
1.360 + test.Next(_L("ATA drive: Capabilities"));
1.361 + TLocalDriveCapsV2Buf info;
1.362 + test(TheDrive.Caps(info)==KErrNone);
1.363 + test(info().iType==EMediaHardDisk);
1.364 + TInt diskSize=I64LOW(info().iSize);
1.365 +
1.366 + wrBuf1.SetLength(RdWrLen);
1.367 + TInt j;
1.368 + for (j=0;j<RdWrLen;j++)
1.369 + wrBuf1[j]=(TUint8)j;
1.370 + wrBuf2.SetLength(RdWrLen);
1.371 + for (j=0;j<RdWrLen;j++)
1.372 + wrBuf2[j]=(TUint8)((RdWrLen-1)-j);
1.373 +
1.374 + TUint *p;
1.375 + TDes8* wrBuf;
1.376 + TInt cycles=0;
1.377 + TResult results;
1.378 + TBool decendPat=EFalse;
1.379 +
1.380 + TRequestStatus kStat;
1.381 + test.Console()->Read(kStat);
1.382 + FOREVER
1.383 + {
1.384 + wrBuf=(decendPat)?&wrBuf2:&wrBuf1;
1.385 + p=(decendPat)?(TUint*)&wrBuf2[0]:(TUint*)&wrBuf1[0];
1.386 + TInt i,j,len,res;
1.387 +
1.388 + // Recalculate amount of free memory
1.389 + TMemoryInfoV1Buf membuf;
1.390 + UserHal::MemoryInfo(membuf);
1.391 + TMemoryInfoV1 &memoryInfo=membuf();
1.392 + results.SetMemStillFree(memoryInfo.iFreeRamInBytes);
1.393 + results.Display(test.Console(),cycles);
1.394 +
1.395 + // Write test
1.396 + RDebug::Print(_L("0"));
1.397 + if (testSeq==2||testSeq==3||testSeq==5||testSeq==6)
1.398 + {
1.399 + for (i=0,j=0;i<diskSize;i+=len,j++)
1.400 + {
1.401 + StatusBar(i,diskSize,16,_L("WRITING "));
1.402 + if (testSeq>3)
1.403 + len=Min(RdWrLen-3,(diskSize-i)); // Not on sector boundary
1.404 + else
1.405 + len=Min(RdWrLen,(diskSize-i));
1.406 + (*p)=j;
1.407 + wrBuf->SetLength(len);
1.408 + do
1.409 + {
1.410 + res=TheDrive.Write(i,*wrBuf);
1.411 + if (res==KErrAbort)
1.412 + {
1.413 + results.WriteAborted();
1.414 + results.Display(test.Console(),cycles);
1.415 + }
1.416 + } while (res==KErrNotReady||res==KErrAbort);
1.417 + results.Add(TResult::EWrite,res,i);
1.418 + if (res!=KErrNone)
1.419 + break;
1.420 + }
1.421 + results.Display(test.Console(),cycles);
1.422 + }
1.423 +
1.424 + // Read test
1.425 + RDebug::Print(_L("1"));
1.426 + if (testSeq>=1)
1.427 + {
1.428 + for (i=0,j=0;i<diskSize;i+=len,j++)
1.429 + {
1.430 + StatusBar(i,diskSize,16,_L("READING "));
1.431 + if (testSeq>3)
1.432 + len=Min(RdWrLen-3,(diskSize-i)); // Not on sector boundary
1.433 + else
1.434 + len=Min(RdWrLen,(diskSize-i));
1.435 + rdBuf.Fill(0,len);
1.436 + do
1.437 + {
1.438 + res=TheDrive.Read(i,len,rdBuf);
1.439 + } while (res==KErrNotReady);
1.440 +
1.441 + results.Add(TResult::ERead,res,i);
1.442 + if (res!=KErrNone)
1.443 + break;
1.444 + if (testSeq==2||testSeq==3||testSeq==5||testSeq==6)
1.445 + {
1.446 + (*p)=j;
1.447 + wrBuf->SetLength(len);
1.448 + if (rdBuf.Compare(*wrBuf)!=0)
1.449 + {
1.450 + results.Add(TResult::ECompare,KErrGeneral,-1);
1.451 + break;
1.452 + }
1.453 + }
1.454 + }
1.455 + results.Display(test.Console(),cycles);
1.456 + }
1.457 +
1.458 + // Format test
1.459 + RDebug::Print(_L("3"));
1.460 + if (testSeq==3||testSeq==6)
1.461 + {
1.462 + TFormatInfo fi;
1.463 + FOREVER
1.464 + {
1.465 + StatusBar((fi.i512ByteSectorsFormatted<<9),diskSize,16,_L("FORMATTING"));
1.466 + do
1.467 + {
1.468 + res=TheDrive.Format(fi);
1.469 + } while (res==KErrNotReady);
1.470 + if (res==KErrEof)
1.471 + break;
1.472 + results.Add(TResult::EFormat,res,(fi.i512ByteSectorsFormatted<<9));
1.473 + if (res!=KErrNone)
1.474 + break;
1.475 + }
1.476 + results.Display(test.Console(),cycles);
1.477 + }
1.478 +
1.479 + RDebug::Print(_L("4"));
1.480 + if (reMountTestSupported)
1.481 + {
1.482 + // Media change test / power off-on test
1.483 +#if defined (USE_MEDIA_CHANGE)
1.484 + TheDrive.ForceMediaChange();
1.485 + if (ChangedFlag==EFalse)
1.486 + results.Add(TResult::EReMount,KErrGeneral,-1);
1.487 +#else
1.488 + tim.HomeTime();
1.489 + tim+=TTimeIntervalSeconds(8);
1.490 + timer.At(prs,tim);
1.491 + UserHal::SwitchOff(); // Switch off
1.492 + User::WaitForRequest(prs); // Switch back on
1.493 + if (prs.Int()!=KErrNone)
1.494 + results.Add(TResult::EReMount,KErrGeneral,-1);
1.495 +#endif
1.496 + else
1.497 + {
1.498 + do
1.499 + {
1.500 + res=TheDrive.Caps(info);
1.501 + } while (res==KErrNotReady);
1.502 + if (res==KErrNone)
1.503 + {
1.504 + if (info().iType!=EMediaHardDisk)
1.505 + results.Add(TResult::EReMount,KErrGeneral,-1);
1.506 + }
1.507 + else
1.508 + results.Add(TResult::EReMount,res,-1);
1.509 + }
1.510 + ChangedFlag=EFalse;
1.511 + }
1.512 +
1.513 + cycles++;
1.514 + decendPat^=0x01;
1.515 +
1.516 + if (kStat!=KRequestPending)
1.517 + {
1.518 + TKeyCode c=test.Console()->KeyCode();
1.519 + if (c==EKeySpace)
1.520 + break;
1.521 + test.Console()->Read(kStat);
1.522 + }
1.523 + RDebug::Print(_L("<<"));
1.524 + }
1.525 +
1.526 + b.Format(_L("Disconnect from local drive (%c:)"),'C'+drv);
1.527 + test.Next(b);
1.528 + TheDrive.Disconnect();
1.529 +
1.530 + test.End();
1.531 + return(0);
1.532 + }
1.533 +