diff -r 000000000000 -r a41df078684a kerneltest/e32test/pccd/t_atadrv.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32test/pccd/t_atadrv.cpp Mon Oct 19 15:55:17 2009 +0100 @@ -0,0 +1,529 @@ +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// e32test\pccd\t_atadrv.cpp +// Test the Compact Flash card (ATA) media driver +// +// + +#include +#include +#include +#include +#include +#include +#include + +const TInt KAtaSectorSize=512; +const TInt KAtaSectorShift=9; +const TUint KAtaSectorMask=0xFFFFFE00; +const TInt KSectBufSizeInSectors=8; +const TInt KSectBufSizeInBytes=(KSectBufSizeInSectors< wrBuf,rdBuf; +LOCAL_D TInt DriveNumber; + +const TInt KSingSectorNo=1; +void singleSectorRdWrTest(TBusLocalDrive &aDrv,TInt aSectorOffset,TInt aLen) +// +// Perform a write / read test on a single sector (KSingSectorNo). Verify that the +// write / read back is successful and that the rest of the sector is unchanged. +// + { + + TBuf8 saveBuf; + test.Start(_L("Single sector write/read test")); + test(aSectorOffset+aLen<=KAtaSectorSize); + + // Now save state of sector before we write to it + TInt secStart=(KSingSectorNo< saveBuf1; + TBuf8 saveBuf2; + test.Start(_L("Multiple sector write/read test")); + test(aFirstSectorOffset infoPckg(info); + nTest(anotherAtaDrive.Caps(infoPckg)==KErrNone); + nTest(info.iType==EMediaHardDisk); + + nTest.End(); + return(KErrNone); + } + +LOCAL_C void ProgressBar(TInt aPos,TInt anEndPos,TInt anXPos) +// +// Display progress of local drive operation on screen (1-16 dots) +// + { + static TInt prev; + TInt curr; + if ((curr=(aPos-1)/(anEndPos>>4))>prev) + { // Update progress bar + test.Console()->SetPos(anXPos); + for (TInt i=curr;i>=0;i--) + test.Printf(_L(".")); + } + prev=curr; + } + +#pragma warning( disable : 4702 ) // unreachable code + +GLDEF_C TInt E32Main() + { + TInt i; + TBuf<64> b; + + TDriveInfoV1Buf diBuf; + UserHal::DriveInfo(diBuf); + TDriveInfoV1 &di=diBuf(); + test.Title(); + test.Start(_L("Test the Compact Flash card (ATA) media drive")); + test.Printf(_L("DRIVES PRESENT :%d\r\n"),di.iTotalSupportedDrives); + test.Printf(_L("1ST DRIVE NAME :%- 16S\r\n"),&di.iDriveName[0]); + test.Printf(_L("2ND DRIVE NAME :%- 16S\r\n"),&di.iDriveName[1]); + test.Printf(_L("3RD DRIVE NAME :%- 16S\r\n"),&di.iDriveName[2]); + test.Printf(_L("4TH DRIVE NAME :%- 16S\r\n"),&di.iDriveName[3]); + test.Printf(_L("5TH DRIVE NAME :%- 16S\r\n"),&di.iDriveName[4]); + test.Printf(_L("6TH DRIVE NAME :%- 16S\r\n"),&di.iDriveName[5]); + test.Printf(_L("7TH DRIVE NAME :%- 16S\r\n"),&di.iDriveName[6]); + test.Printf(_L("8TH DRIVE NAME :%- 16S\r\n"),&di.iDriveName[7]); + test.Printf(_L("9TH DRIVE NAME :%- 16S\r\n"),&di.iDriveName[8]); + + test.Printf(_L("\r\nWarning - all data on removable drive will be lost.\r\n")); + test.Printf(_L("<<>>\r\n")); + TChar c=(TUint)test.Getch(); + c.UpperCase(); + DriveNumber=((TUint)c)-'C'; + test(DriveNumber >= 1 && DriveNumber < di.iTotalSupportedDrives); + +#if defined (__WINS__) + // Connect to all the local drives first as will be the case in ARM + TBusLocalDrive Drive[KMaxLocalDrives]; + TBool DriveFlag[KMaxLocalDrives]; + for (i=0;i infoPckg(info); + test(theAtaDrive.Caps(infoPckg)==KErrNone); + diskSize=I64LOW(info.iSize); + test.Printf( _L("Check drive size: %d\r\n"),diskSize); +#if defined (__WINS__) + test.Printf(_L("Check hidden sectors (=0): %d\r\n"),info.iHiddenSectors); +#else + test.Printf(_L("Check hidden sectors (=16/32): %d\r\n"),info.iHiddenSectors); +#endif + // test.Getch(); + test(info.iType==EMediaHardDisk); + test(info.iBattery==EBatNotSupported); + test(info.iDriveAtt==(TUint)(KDriveAttLocal|KDriveAttRemovable)); + test(info.iMediaAtt==KMediaAttFormattable); + test(info.iFileSystemId==KDriveFileSysFAT); +// TSupplyInfoV1Buf supply2; +// test(UserHal::SupplyInfo(supply2)==KErrNone); +// if (mediaChangeSupported) +// test(supply2().iCurrentConsumptionMilliAmps==supply1().iCurrentConsumptionMilliAmps+KAtaIdleCurrentInMilliAmps); // Snowball idle current is zero + + b.Format(_L("ATA drive: Sector RdWr(%d)"),KAtaSectorSize); + test.Next(b); + TInt len; + wrBuf.SetLength(KAtaSectorSize); + TUint *p=(TUint*)&wrBuf[0]; + for (i=0;i savBuf1,savBuf2; + TInt fmtTestPos=(10<>>\r\n")); +#else + test.Printf( _L("<<>>\r\n")); +#endif + test.Getch(); + User::After(300000); // Allow 0.3s after power down for controller to detect door closed. + test(ChangeFlag); +// test(UserHal::SupplyInfo(supply2)==KErrNone); +// test(supply2().iCurrentConsumptionMilliAmps==supply1().iCurrentConsumptionMilliAmps); + __KHEAP_MARK; + + test.Next(_L("ATA drive: Caps following media change")); + test(theAtaDrive.Caps(infoPckg)==KErrNone); + test(info.iType==EMediaHardDisk); +// test(UserHal::SupplyInfo(supply2)==KErrNone); +// test(supply2().iCurrentConsumptionMilliAmps==supply1().iCurrentConsumptionMilliAmps+KAtaIdleCurrentInMilliAmps); + + test.Next(_L("ATA drive: Caps while OOM")); + TInt err=KErrNoMemory; + test.Printf(_L("Mount returns:")); + for (TInt j=1; err!=KErrNone && j<16; j++) + { + theAtaDrive.ForceMediaChange(); // Generate media change + User::After(300000); // Allow 0.3s after power down for controller to detect door closed. +// __KHEAP_MARK; + __KHEAP_SETFAIL(RHeap::EDeterministic,j); + err=theAtaDrive.Caps(infoPckg); + test.Printf(_L("(%d)"),err); + test(err==KErrNoMemory || err==KErrNone); +// __KHEAP_MARKEND; // fails because card functions only released by media change or power down + __KHEAP_RESET; + } + test(err==KErrNone); + test.Printf(_L("\r\n")); + theAtaDrive.ForceMediaChange(); // Generate media change + User::After(300000); // Allow 0.3s after power down for controller to detect door closed. + __KHEAP_MARKEND; // test memory released after media change + +// __KHEAP_MARK; + test.Next(_L("ATA drive: Caps before power off")); + test(theAtaDrive.Caps(infoPckg)==KErrNone); + test(info.iType==EMediaHardDisk); + + test.Next(_L("ATA drive: Machine power-off.")); + ChangeFlag=EFalse; + RTimer timer; + test(timer.CreateLocal()==KErrNone); + TRequestStatus timerStat; + TTime tim; + tim.HomeTime(); + tim+=TTimeIntervalSeconds(8); + timer.At(timerStat,tim); + UserHal::SwitchOff(); + User::WaitForRequest(timerStat); + test(!ChangeFlag); // ie machine power off hasn't updated it + timer.Close(); +// __KHEAP_MARKEND; // test memory released on power off + + test.Next(_L("ATA drive: Caps following power off")); + test(theAtaDrive.Caps(infoPckg)==KErrNone); + test(info.iType==EMediaHardDisk); + + test.Next(_L("Starting 2nd thread")); + SecThreadChangeFlag=EFalse; + RThread thread; + TRequestStatus stat; + test(thread.Create(_L("Thread"),dontDisconnectThread,KDefaultStackSize,KHeapSize,KHeapSize,NULL)==KErrNone); + thread.Logon(stat); + thread.Resume(); + User::WaitForRequest(stat); + test(stat==KErrNone); + CLOSE_AND_WAIT(thread); + + test.Next(_L("ATA drive: 2nd media change")); + theAtaDrive.ForceMediaChange(); // Generate media change + test(ChangeFlag); + test(!SecThreadChangeFlag); // Closed 2nd thread so shouldn't have been updated + + b.Format(_L("Disconnect from local drive (%c:)"),DriveNumber+'C'); + test.Next(b); + theAtaDrive.Disconnect(); + + test.End(); + +#if defined (__WINS__) + for (i=0;i