os/kernelhwsrv/kerneltest/e32test/pccd/t_atadrv.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/pccd/t_atadrv.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,529 @@
     1.4 +// Copyright (c) 1996-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_atadrv.cpp
    1.18 +// Test the Compact Flash card (ATA) media driver
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +#include <e32test.h>
    1.23 +#include <e32svr.h>
    1.24 +#include <e32hal.h>
    1.25 +#include <e32uid.h>
    1.26 +#include <hal.h>
    1.27 +#include <e32def.h>
    1.28 +#include <e32def_private.h>
    1.29 +
    1.30 +const TInt KAtaSectorSize=512;
    1.31 +const TInt KAtaSectorShift=9;
    1.32 +const TUint KAtaSectorMask=0xFFFFFE00;
    1.33 +const TInt KSectBufSizeInSectors=8;
    1.34 +const TInt KSectBufSizeInBytes=(KSectBufSizeInSectors<<KAtaSectorShift);
    1.35 +const TInt KRdWrBufLen=(KSectBufSizeInBytes+KAtaSectorSize); // 4.5K - exceeds driver local buffer size
    1.36 +
    1.37 +const TInt KShortFormatInSectors=1;
    1.38 +const TInt KShortFormatInBytes=(KShortFormatInSectors<<KAtaSectorShift);
    1.39 +const TInt KLongFormatInSectors=KSectBufSizeInSectors+1;	// 4.5K - exceeds driver local buffer size
    1.40 +const TInt KLongFormatInBytes=(KLongFormatInSectors<<KAtaSectorShift);
    1.41 +
    1.42 +const TInt KHeapSize=0x4000;
    1.43 +const TInt KAtaIdleCurrentInMilliAmps=1; 
    1.44 +
    1.45 +#define PDD_NAME _L("MEDATA")
    1.46 +
    1.47 +LOCAL_D RTest test(_L("T_ATADRV"));
    1.48 +LOCAL_D RTest nTest(_L("This thread doesn't disconnect"));
    1.49 +LOCAL_D TBool ChangeFlag;
    1.50 +LOCAL_D TBool SecThreadChangeFlag;
    1.51 +LOCAL_D TBuf8<KRdWrBufLen> wrBuf,rdBuf;
    1.52 +LOCAL_D TInt DriveNumber;
    1.53 +
    1.54 +const TInt KSingSectorNo=1;
    1.55 +void singleSectorRdWrTest(TBusLocalDrive &aDrv,TInt aSectorOffset,TInt aLen)
    1.56 +//
    1.57 +// Perform a write / read test on a single sector (KSingSectorNo). Verify that the
    1.58 +// write / read back is successful and that the rest of the sector is unchanged.
    1.59 +//
    1.60 +	{
    1.61 +
    1.62 +	TBuf8<KAtaSectorSize> saveBuf;
    1.63 +	test.Start(_L("Single sector write/read test"));
    1.64 +	test(aSectorOffset+aLen<=KAtaSectorSize);
    1.65 +
    1.66 +	// Now save state of sector before we write to it
    1.67 +	TInt secStart=(KSingSectorNo<<KAtaSectorShift);
    1.68 + 	test(aDrv.Read(secStart,KAtaSectorSize,saveBuf)==KErrNone);
    1.69 +
    1.70 +	// Write zero's to another sector altogether (to ensure drivers 
    1.71 +	// local buffer hasn't already got test pattern we expect).
    1.72 +	wrBuf.Fill(0,KAtaSectorSize);
    1.73 +	test(aDrv.Write((KSingSectorNo+4)<<KAtaSectorShift,wrBuf)==KErrNone);
    1.74 +
    1.75 +	// Write / read back sector in question
    1.76 +	wrBuf.SetLength(aLen);
    1.77 +	for (TInt i=0;i<aLen;i++)
    1.78 +		wrBuf[i]=(TUint8)(0xFF-i);
    1.79 +	test(aDrv.Write((secStart+aSectorOffset),wrBuf)==KErrNone);
    1.80 +	rdBuf.Fill(0,aLen);
    1.81 + 	test(aDrv.Read((secStart+aSectorOffset),aLen,rdBuf)==KErrNone);
    1.82 +  	test(rdBuf.Compare(wrBuf)==0);
    1.83 +
    1.84 +	// Now check the rest of the sector is unchanged
    1.85 +	rdBuf.Fill(0,KAtaSectorSize);
    1.86 + 	test(aDrv.Read(secStart,KAtaSectorSize,rdBuf)==KErrNone);
    1.87 +	saveBuf.Replace(aSectorOffset,aLen,wrBuf);
    1.88 +  	test(rdBuf.Compare(saveBuf)==0);
    1.89 +	test.End();
    1.90 +	}
    1.91 +
    1.92 +const TInt KMultSectorNo=2; 
    1.93 +void MultipleSectorRdWrTest(TBusLocalDrive &aDrv,TInt aFirstSectorOffset,TInt aLen)
    1.94 +//
    1.95 +// Perform a write / read test over multiple sectors (starting within sector KMultSectorNo).
    1.96 +// Verify that the write / read back is successful and that the remainder of the first and
    1.97 +// last sectors are not affected.
    1.98 +//
    1.99 +	{
   1.100 +
   1.101 +	TBuf8<KAtaSectorSize> saveBuf1;
   1.102 +	TBuf8<KAtaSectorSize> saveBuf2;
   1.103 +	test.Start(_L("Multiple sector write/read test"));
   1.104 +	test(aFirstSectorOffset<KAtaSectorSize&&aLen<=KRdWrBufLen);
   1.105 +
   1.106 +	// If not starting on sector boundary then save 1st sector to check rest of 1st sector is unchanged
   1.107 +	TInt startSecPos=(KMultSectorNo<<KAtaSectorShift);
   1.108 +	if (aFirstSectorOffset!=0)
   1.109 + 		test(aDrv.Read(startSecPos,KAtaSectorSize,saveBuf1)==KErrNone);
   1.110 +
   1.111 +	// If not ending on sector boundary then save last sector to check rest of last sector is unchanged
   1.112 +	TInt endOffset=(aFirstSectorOffset+aLen)&(~KAtaSectorMask);
   1.113 +	TInt endSecPos=((startSecPos+aFirstSectorOffset+aLen)&KAtaSectorMask);
   1.114 +	if (endOffset)
   1.115 + 		test(aDrv.Read(endSecPos,KAtaSectorSize,saveBuf2)==KErrNone);
   1.116 +	
   1.117 +	// Write zero's to another sector altogether (to ensure drivers 
   1.118 +	// local buffer hasn't already got test pattern we expect).
   1.119 +	wrBuf.Fill(0,KSectBufSizeInBytes);
   1.120 +	test(aDrv.Write((KMultSectorNo+20)<<KAtaSectorShift,wrBuf)==KErrNone);
   1.121 +	
   1.122 +	wrBuf.SetLength(aLen);
   1.123 +	for (TInt i=0;i<aLen;i++)
   1.124 +		wrBuf[i]=(TUint8)(0xFF-i);
   1.125 +	test(aDrv.Write((startSecPos+aFirstSectorOffset),wrBuf)==KErrNone);
   1.126 +	rdBuf.Fill(0,aLen);
   1.127 + 	test(aDrv.Read((startSecPos+aFirstSectorOffset),aLen,rdBuf)==KErrNone);
   1.128 +  	test(rdBuf.Compare(wrBuf)==0);
   1.129 +
   1.130 +	// Check rest of first sector involved is unchanged (if offset specified)
   1.131 +	if (aFirstSectorOffset!=0)
   1.132 +		{
   1.133 +		rdBuf.Fill(0,KAtaSectorSize);
   1.134 + 		test(aDrv.Read(startSecPos,KAtaSectorSize,rdBuf)==KErrNone);
   1.135 +		wrBuf.SetLength(KAtaSectorSize-aFirstSectorOffset);
   1.136 +		saveBuf1.Replace(aFirstSectorOffset,(KAtaSectorSize-aFirstSectorOffset),wrBuf);
   1.137 +  		test(rdBuf.Compare(saveBuf1)==0);
   1.138 +		}
   1.139 +
   1.140 +	// Check rest of last sector involved is unchanged (if not ending on sector boundary)
   1.141 +	if (endOffset)
   1.142 +		{
   1.143 +		rdBuf.Fill(0,KAtaSectorSize);
   1.144 + 		test(aDrv.Read(endSecPos,KAtaSectorSize,rdBuf)==KErrNone);
   1.145 +		wrBuf.SetLength(aLen);
   1.146 +		wrBuf.Delete(0,aLen-endOffset);
   1.147 +		saveBuf2.Replace(0,endOffset,wrBuf);
   1.148 +  		test(rdBuf.Compare(saveBuf2)==0);
   1.149 +		}
   1.150 +	test.End();
   1.151 +	}
   1.152 +
   1.153 +LOCAL_C TInt dontDisconnectThread(TAny*)
   1.154 +	{
   1.155 +
   1.156 +	TBusLocalDrive anotherAtaDrive;
   1.157 +	nTest.Title();
   1.158 +
   1.159 +	nTest.Start(_L("Connect to internal drive"));
   1.160 +	anotherAtaDrive.Connect(DriveNumber,SecThreadChangeFlag);
   1.161 +
   1.162 +	nTest.Next(_L("Capabilities"));
   1.163 +	TLocalDriveCapsV2 info;
   1.164 +	TPckg<TLocalDriveCapsV2> infoPckg(info);
   1.165 +	nTest(anotherAtaDrive.Caps(infoPckg)==KErrNone);
   1.166 +	nTest(info.iType==EMediaHardDisk);
   1.167 +
   1.168 +    nTest.End();
   1.169 +	return(KErrNone);
   1.170 +	}
   1.171 +
   1.172 +LOCAL_C void ProgressBar(TInt aPos,TInt anEndPos,TInt anXPos)
   1.173 +//
   1.174 +// Display progress of local drive operation on screen (1-16 dots)
   1.175 +//
   1.176 +	{
   1.177 +	static TInt prev;
   1.178 +	TInt curr;
   1.179 +	if ((curr=(aPos-1)/(anEndPos>>4))>prev)
   1.180 +		{ // Update progress bar
   1.181 +		test.Console()->SetPos(anXPos);
   1.182 +		for (TInt i=curr;i>=0;i--)
   1.183 +			test.Printf(_L("."));
   1.184 +		}
   1.185 +	prev=curr;
   1.186 +	}
   1.187 +
   1.188 +#pragma warning( disable : 4702 ) // unreachable code
   1.189 +
   1.190 +GLDEF_C TInt E32Main()
   1.191 +    {
   1.192 +	TInt i;
   1.193 +	TBuf<64> b;
   1.194 +
   1.195 +	TDriveInfoV1Buf diBuf;
   1.196 +	UserHal::DriveInfo(diBuf);
   1.197 +	TDriveInfoV1 &di=diBuf();
   1.198 +	test.Title();
   1.199 +	test.Start(_L("Test the Compact Flash card (ATA) media drive"));
   1.200 +	test.Printf(_L("DRIVES PRESENT  :%d\r\n"),di.iTotalSupportedDrives);
   1.201 +	test.Printf(_L("1ST DRIVE NAME  :%- 16S\r\n"),&di.iDriveName[0]);
   1.202 +	test.Printf(_L("2ND DRIVE NAME  :%- 16S\r\n"),&di.iDriveName[1]);
   1.203 +	test.Printf(_L("3RD DRIVE NAME  :%- 16S\r\n"),&di.iDriveName[2]);
   1.204 +	test.Printf(_L("4TH DRIVE NAME  :%- 16S\r\n"),&di.iDriveName[3]);
   1.205 +	test.Printf(_L("5TH DRIVE NAME  :%- 16S\r\n"),&di.iDriveName[4]);
   1.206 +	test.Printf(_L("6TH DRIVE NAME  :%- 16S\r\n"),&di.iDriveName[5]);
   1.207 +	test.Printf(_L("7TH DRIVE NAME  :%- 16S\r\n"),&di.iDriveName[6]);
   1.208 +	test.Printf(_L("8TH DRIVE NAME  :%- 16S\r\n"),&di.iDriveName[7]);
   1.209 +	test.Printf(_L("9TH DRIVE NAME  :%- 16S\r\n"),&di.iDriveName[8]);
   1.210 +
   1.211 +	test.Printf(_L("\r\nWarning - all data on removable drive will be lost.\r\n"));
   1.212 +	test.Printf(_L("<<<Hit D to continue>>>\r\n"));
   1.213 +	TChar c=(TUint)test.Getch();
   1.214 +	c.UpperCase();
   1.215 +	DriveNumber=((TUint)c)-'C';
   1.216 +	test(DriveNumber >= 1 && DriveNumber < di.iTotalSupportedDrives);
   1.217 +
   1.218 +#if defined (__WINS__)
   1.219 +	// Connect to all the local drives first as will be the case in ARM
   1.220 +	TBusLocalDrive Drive[KMaxLocalDrives];
   1.221 +	TBool DriveFlag[KMaxLocalDrives];
   1.222 +	for (i=0;i<KMaxLocalDrives;i++)
   1.223 +		Drive[i].Connect(i,DriveFlag[i]);
   1.224 +#endif
   1.225 +
   1.226 +	test.Next(_L("Load ATA Media Driver"));
   1.227 +	TInt r=User::LoadPhysicalDevice(PDD_NAME);
   1.228 +	test(r==KErrNone||r==KErrAlreadyExists);
   1.229 +
   1.230 +    test.Next(_L("Read machine information"));
   1.231 +	TInt mid;
   1.232 +	r=HAL::Get(HAL::EMachineUid,mid);
   1.233 +	test(r==KErrNone);
   1.234 +	TBool mediaChangeSupported=EFalse;
   1.235 +
   1.236 +	b.Format(_L("Connect to local drive (%c:)"),DriveNumber+'C');
   1.237 +	test.Next(b);
   1.238 +	TBusLocalDrive theAtaDrive;
   1.239 +	ChangeFlag=EFalse;
   1.240 +	test(theAtaDrive.Connect(DriveNumber,ChangeFlag)==KErrNone);
   1.241 +	if (mediaChangeSupported)
   1.242 +		{
   1.243 +		theAtaDrive.ForceMediaChange();	// Generate media change to reset PC Card current consumption
   1.244 +		User::After(300000);			// Allow 0.3s after power down for controller to detect door closed.
   1.245 +		}
   1.246 +//	TSupplyInfoV1Buf supply1;
   1.247 +//	test(UserHal::SupplyInfo(supply1)==KErrNone);
   1.248 +
   1.249 +	test.Next(_L("ATA drive: Capabilities"));
   1.250 +	TInt diskSize;
   1.251 +	TTime startTime;
   1.252 +	startTime.HomeTime();
   1.253 +	TLocalDriveCapsV2 info;
   1.254 +	TPckg<TLocalDriveCapsV2> infoPckg(info);
   1.255 +	test(theAtaDrive.Caps(infoPckg)==KErrNone);
   1.256 +	diskSize=I64LOW(info.iSize);
   1.257 +	test.Printf( _L("Check drive size: %d\r\n"),diskSize);
   1.258 +#if defined (__WINS__)
   1.259 +	test.Printf(_L("Check hidden sectors (=0): %d\r\n"),info.iHiddenSectors);
   1.260 +#else
   1.261 +	test.Printf(_L("Check hidden sectors (=16/32): %d\r\n"),info.iHiddenSectors);
   1.262 +#endif
   1.263 +	// test.Getch();
   1.264 +	test(info.iType==EMediaHardDisk);
   1.265 +	test(info.iConnectionBusType==EConnectionBusInternal);
   1.266 +	test(info.iDriveAtt==(TUint)(KDriveAttLocal|KDriveAttRemovable));
   1.267 +	test(info.iMediaAtt==KMediaAttFormattable);
   1.268 +	test(info.iFileSystemId==KDriveFileSysFAT);
   1.269 +//	TSupplyInfoV1Buf supply2;
   1.270 +//	test(UserHal::SupplyInfo(supply2)==KErrNone);
   1.271 +//	if (mediaChangeSupported)
   1.272 +//		test(supply2().iCurrentConsumptionMilliAmps==supply1().iCurrentConsumptionMilliAmps+KAtaIdleCurrentInMilliAmps); // Snowball idle current is zero
   1.273 +
   1.274 +	b.Format(_L("ATA drive: Sector RdWr(%d)"),KAtaSectorSize);
   1.275 +	test.Next(b);
   1.276 +	TInt len;
   1.277 +	wrBuf.SetLength(KAtaSectorSize);
   1.278 +	TUint *p=(TUint*)&wrBuf[0];
   1.279 +	for (i=0;i<KAtaSectorSize;i++)
   1.280 +		wrBuf[i]=(TUint8)i;
   1.281 +
   1.282 +	test.Printf(_L("Writing    "));
   1.283 +	for (i=0;i<diskSize;i+=len)	 // B - Sector wr/rd on sector boundary
   1.284 +		{
   1.285 +		ProgressBar(i,diskSize,11);
   1.286 +		len=Min(KAtaSectorSize,(diskSize-i));
   1.287 +		(*p)=(i/KAtaSectorSize);
   1.288 +		wrBuf.SetLength(len);
   1.289 +		test(theAtaDrive.Write(i,wrBuf)==KErrNone);
   1.290 +		}
   1.291 +	test.Printf(_L("\r\nReading    "));
   1.292 +	for (i=0;i<diskSize;i+=len)
   1.293 +		{
   1.294 +		ProgressBar(i,diskSize,11);
   1.295 +		len=Min(KAtaSectorSize,(diskSize-i));
   1.296 +		rdBuf.Fill(0,len);
   1.297 + 		test(theAtaDrive.Read(i,len,rdBuf)==KErrNone);
   1.298 +		(*p)=(i/KAtaSectorSize);
   1.299 +		wrBuf.SetLength(len);
   1.300 +  	    test(rdBuf.Compare(wrBuf)==0);
   1.301 +		}
   1.302 +	test.Printf(_L("\r\n"));
   1.303 +
   1.304 +	b.Format(_L("ATA drive: Short RdWr(1) (%dbytes at %d)"),25,0); 
   1.305 +	test.Next(b);
   1.306 +	singleSectorRdWrTest(theAtaDrive,0,25); // A - Sub-sector wr/rd at sector start
   1.307 +
   1.308 +	b.Format(_L("ATA drive: Short RdWr(2) (%dbytes at %d)"),16,277); 
   1.309 +	test.Next(b);
   1.310 +	singleSectorRdWrTest(theAtaDrive,277,16); // E - Sub-sector wr/rd in mid sector
   1.311 +
   1.312 +	b.Format(_L("ATA drive: Short RdWr(3) (%dbytes at %d)"),100,412); 
   1.313 +	test.Next(b);
   1.314 +	singleSectorRdWrTest(theAtaDrive,412,100); // F - Sub-sector wr/rd at sector end
   1.315 +
   1.316 +	b.Format(_L("ATA drive: Long RdWr(1) (%dbytes at %d)"),KAtaSectorSize+15,0);
   1.317 +	test.Next(b);
   1.318 +	MultipleSectorRdWrTest(theAtaDrive,0,KAtaSectorSize+15); // C - Long wr/rd starting on sector boundary
   1.319 +
   1.320 +	b.Format(_L("ATA drive: Long RdWr(2) (%dbytes at %d)"),(KAtaSectorSize<<1),0);
   1.321 +	test.Next(b);
   1.322 +	MultipleSectorRdWrTest(theAtaDrive,0,(KAtaSectorSize<<1)); // D - Long wr/rd starting/ending on sector boundary
   1.323 +
   1.324 +	b.Format(_L("ATA drive: Long RdWr(3) (%dbytes at %d)"),KAtaSectorSize+3,509);
   1.325 +	test.Next(b);
   1.326 +	MultipleSectorRdWrTest(theAtaDrive,509,KAtaSectorSize+3); // H -  - Long wr/rd ending on sector boundary
   1.327 +
   1.328 +	b.Format(_L("ATA drive: Long RdWr(4) (%dbytes at %d)"),(KAtaSectorSize<<1),508);
   1.329 +	test.Next(b);
   1.330 +	MultipleSectorRdWrTest(theAtaDrive,508,(KAtaSectorSize<<1));
   1.331 +
   1.332 +	b.Format(_L("ATA drive: Sector RdWr across sector boundary(%dbytes at %d)"),KAtaSectorSize,508);
   1.333 +	test.Next(b);
   1.334 +	MultipleSectorRdWrTest(theAtaDrive,508,KAtaSectorSize); // G - Sector wr/rd over sector boundary
   1.335 +
   1.336 +  	b.Format(_L("ATA drive: Very long RdWr(1) (%dbytes at %d)"),KRdWrBufLen,0);
   1.337 +	test.Next(b);
   1.338 +	MultipleSectorRdWrTest(theAtaDrive,0,KRdWrBufLen); // Exceeds driver's buffer, starts/ends on sector boundary
   1.339 +
   1.340 +  	b.Format(_L("ATA drive: Very long RdWr(2) (%dbytes at %d)"),(KRdWrBufLen-KAtaSectorSize+5),507);
   1.341 +	test.Next(b);
   1.342 +	MultipleSectorRdWrTest(theAtaDrive,507,(KRdWrBufLen-KAtaSectorSize+5)); // Exceeds driver's buffer, ends on sector boundary
   1.343 +
   1.344 +  	b.Format(_L("ATA drive: Very long RdWr(3) (%dbytes at %d)"),KRdWrBufLen,10);
   1.345 +	test.Next(b);
   1.346 +	MultipleSectorRdWrTest(theAtaDrive,10,KRdWrBufLen); // Exceeds driver's buffer, starts/ends off sector boundary
   1.347 +
   1.348 +  	b.Format(_L("ATA drive: Very long RdWr(4) (%dbytes at %d)"),(KRdWrBufLen-3),0);
   1.349 +	test.Next(b);
   1.350 +	MultipleSectorRdWrTest(theAtaDrive,0,KRdWrBufLen-3); // Exceeds driver's buffer, starts on sector boundary
   1.351 +
   1.352 +  	b.Format(_L("ATA drive: Very long RdWr(5) (%dbytes at %d)"),(KRdWrBufLen-KAtaSectorSize),27);
   1.353 +	test.Next(b);
   1.354 +	MultipleSectorRdWrTest(theAtaDrive,27,(KRdWrBufLen-KAtaSectorSize)); // Exceeds driver's buffer (due to start offset), starts/ends off sector boundary
   1.355 +
   1.356 +  	b.Format(_L("ATA drive: Very long RdWr(6) (%dbytes at %d)"),(KRdWrBufLen-KAtaSectorSize-3),0);
   1.357 +	test.Next(b);
   1.358 +	MultipleSectorRdWrTest(theAtaDrive,0,KRdWrBufLen-KAtaSectorSize-3); // Equals driver's buffer, starts on sector boundary
   1.359 +
   1.360 +  	b.Format(_L("ATA drive: Very long RdWr(7) (%dbytes at %d)"),(KRdWrBufLen-3),3);
   1.361 +	test.Next(b);
   1.362 +	MultipleSectorRdWrTest(theAtaDrive,3,KRdWrBufLen-3); // Equals driver's buffer, ends on sector boundary
   1.363 +/*
   1.364 +	test.Next(_L("ATA drive: Inter-thread RdWr"));
   1.365 +	RThread dummyThread;
   1.366 +	dummyThread.Duplicate(RThread());
   1.367 +  	TInt threadHandle=dummyThread.Handle();
   1.368 +	wrBuf.SetLength(KAtaSectorSize);
   1.369 +	for (i=0;i<KAtaSectorSize;i++)
   1.370 +		wrBuf[i]=(TUint8)i;
   1.371 +	test(theAtaDrive.Write(10,KAtaSectorSize,&wrBuf,threadHandle,0)==KErrNone);
   1.372 +	rdBuf.Fill(0,KAtaSectorSize);
   1.373 + 	test(theAtaDrive.Read(10,KAtaSectorSize,&rdBuf,threadHandle,0)==KErrNone);
   1.374 +  	test(rdBuf.Compare(wrBuf)==0);
   1.375 +	dummyThread.Close();
   1.376 +*/
   1.377 +	test.Next(_L("ATA drive: Format sectors (short)"));
   1.378 +	TBuf8<KAtaSectorSize> savBuf1,savBuf2;
   1.379 +	TInt fmtTestPos=(10<<KAtaSectorShift);
   1.380 +	// Save sectors surrounding those which will be formatted
   1.381 + 	test(theAtaDrive.Read((fmtTestPos-KAtaSectorSize),KAtaSectorSize,savBuf1)==KErrNone);
   1.382 + 	test(theAtaDrive.Read((fmtTestPos+KShortFormatInBytes),KAtaSectorSize,savBuf2)==KErrNone);
   1.383 +	test(theAtaDrive.Format(fmtTestPos,KShortFormatInBytes)==KErrNone);
   1.384 + 	test(theAtaDrive.Read(fmtTestPos,KShortFormatInBytes,rdBuf)==KErrNone);
   1.385 +	wrBuf.Fill(0xFF,KShortFormatInBytes);
   1.386 +  	test(rdBuf.Compare(wrBuf)==0);
   1.387 +    // Check that surrounding sectors unaffected
   1.388 + 	test(theAtaDrive.Read((fmtTestPos-KAtaSectorSize),KAtaSectorSize,rdBuf)==KErrNone);
   1.389 +  	test(rdBuf.Compare(savBuf1)==0);
   1.390 + 	test(theAtaDrive.Read((fmtTestPos+KShortFormatInBytes),KAtaSectorSize,rdBuf)==KErrNone);
   1.391 +  	test(rdBuf.Compare(savBuf2)==0);
   1.392 +
   1.393 +	test.Next(_L("ATA drive: Format sectors (long)"));
   1.394 +	fmtTestPos+=(4<<KAtaSectorShift);
   1.395 +	// Save sectors surrounding those which will be formatted
   1.396 + 	test(theAtaDrive.Read((fmtTestPos-KAtaSectorSize),KAtaSectorSize,savBuf1)==KErrNone);
   1.397 + 	test(theAtaDrive.Read((fmtTestPos+KLongFormatInBytes),KAtaSectorSize,savBuf2)==KErrNone);
   1.398 +	test(theAtaDrive.Format(fmtTestPos,KLongFormatInBytes)==KErrNone);
   1.399 + 	test(theAtaDrive.Read(fmtTestPos,KLongFormatInBytes,rdBuf)==KErrNone);
   1.400 +	wrBuf.Fill(0xFF,KLongFormatInBytes);
   1.401 +  	test(rdBuf.Compare(wrBuf)==0);
   1.402 +    // Check that surrounding sectors unaffected
   1.403 + 	test(theAtaDrive.Read((fmtTestPos-KAtaSectorSize),KAtaSectorSize,rdBuf)==KErrNone);
   1.404 +  	test(rdBuf.Compare(savBuf1)==0);
   1.405 + 	test(theAtaDrive.Read((fmtTestPos+KLongFormatInBytes),KAtaSectorSize,rdBuf)==KErrNone);
   1.406 +  	test(rdBuf.Compare(savBuf2)==0);
   1.407 +
   1.408 +	test.Next(_L("ATA drive: Format entire disk"));
   1.409 +	TFormatInfo fi;
   1.410 +	test.Printf(_L("Formatting "));
   1.411 +	TInt ret;
   1.412 +	while((ret=theAtaDrive.Format(fi))!=KErrEof)
   1.413 +		{
   1.414 +		ProgressBar((fi.i512ByteSectorsFormatted<<9),diskSize,11);
   1.415 +		test(ret==KErrNone);
   1.416 +		}
   1.417 +	test.Printf(_L("\r\nReading    "));
   1.418 +	for (i=0;i<diskSize;i+=len)
   1.419 +		{
   1.420 +		ProgressBar(i,diskSize,11);
   1.421 +		len=Min(KAtaSectorSize,(diskSize-i));
   1.422 +		rdBuf.Fill(0x55,len);
   1.423 + 		test(theAtaDrive.Read(i,len,rdBuf)==KErrNone);
   1.424 +		wrBuf.SetLength(len);
   1.425 +  		test(rdBuf.Compare(wrBuf)==0);
   1.426 +		}
   1.427 +
   1.428 +	TTime endTime;
   1.429 +	endTime.HomeTime();
   1.430 +	TTimeIntervalMicroSeconds elapsed=endTime.MicroSecondsFrom(startTime);
   1.431 +	test.Printf(_L("   (Elapsed time: %dmS)\r\n"),(elapsed.Int64()/1000));
   1.432 +
   1.433 +	if (!mediaChangeSupported)
   1.434 +		{
   1.435 +		// Remainder of tests involve media change so stop now
   1.436 +		test.End();
   1.437 +		return(0);
   1.438 +		}
   1.439 +	
   1.440 +	test.Next(_L("ATA drive: Media change"));
   1.441 +#if defined (__WINS__)
   1.442 +	test.Printf( _L("<<<Hit F5 - then any other key>>>\r\n"));
   1.443 +#else
   1.444 +	test.Printf( _L("<<<Generate Media change - then hit a key>>>\r\n"));
   1.445 +#endif
   1.446 +	test.Getch();
   1.447 +	User::After(300000);	// Allow 0.3s after power down for controller to detect door closed.
   1.448 +	test(ChangeFlag);
   1.449 +//	test(UserHal::SupplyInfo(supply2)==KErrNone);
   1.450 +//	test(supply2().iCurrentConsumptionMilliAmps==supply1().iCurrentConsumptionMilliAmps);
   1.451 +	__KHEAP_MARK;
   1.452 +
   1.453 +	test.Next(_L("ATA drive: Caps following media change"));
   1.454 +	test(theAtaDrive.Caps(infoPckg)==KErrNone);
   1.455 +	test(info.iType==EMediaHardDisk);
   1.456 +//	test(UserHal::SupplyInfo(supply2)==KErrNone);
   1.457 +//	test(supply2().iCurrentConsumptionMilliAmps==supply1().iCurrentConsumptionMilliAmps+KAtaIdleCurrentInMilliAmps);
   1.458 +
   1.459 +	test.Next(_L("ATA drive: Caps while OOM"));
   1.460 +	TInt err=KErrNoMemory;
   1.461 +	test.Printf(_L("Mount returns:"));
   1.462 +	for (TInt j=1; err!=KErrNone && j<16; j++)
   1.463 +		{
   1.464 +		theAtaDrive.ForceMediaChange();	// Generate media change
   1.465 +		User::After(300000);	// Allow 0.3s after power down for controller to detect door closed.
   1.466 +//		__KHEAP_MARK;
   1.467 +		__KHEAP_SETFAIL(RHeap::EDeterministic,j);
   1.468 +		err=theAtaDrive.Caps(infoPckg);
   1.469 +		test.Printf(_L("(%d)"),err);
   1.470 +		test(err==KErrNoMemory || err==KErrNone);
   1.471 +//		__KHEAP_MARKEND;		// fails because card functions only released by media change or power down
   1.472 +		__KHEAP_RESET;
   1.473 +		}
   1.474 +	test(err==KErrNone);
   1.475 +	test.Printf(_L("\r\n"));
   1.476 +	theAtaDrive.ForceMediaChange();	// Generate media change
   1.477 +	User::After(300000);	// Allow 0.3s after power down for controller to detect door closed.
   1.478 +	__KHEAP_MARKEND;		// test memory released after media change
   1.479 +
   1.480 +//	__KHEAP_MARK;
   1.481 +	test.Next(_L("ATA drive: Caps before power off"));
   1.482 +	test(theAtaDrive.Caps(infoPckg)==KErrNone);
   1.483 +	test(info.iType==EMediaHardDisk);
   1.484 +
   1.485 +	test.Next(_L("ATA drive: Machine power-off."));
   1.486 +	ChangeFlag=EFalse;
   1.487 +	RTimer timer;
   1.488 +	test(timer.CreateLocal()==KErrNone);
   1.489 +	TRequestStatus timerStat;
   1.490 +	TTime tim;
   1.491 +	tim.HomeTime();
   1.492 +	tim+=TTimeIntervalSeconds(8);
   1.493 +	timer.At(timerStat,tim);
   1.494 +	UserHal::SwitchOff();
   1.495 +	User::WaitForRequest(timerStat);
   1.496 +	test(!ChangeFlag);		// ie machine power off hasn't updated it
   1.497 +	timer.Close();
   1.498 +//	__KHEAP_MARKEND;		// test memory released on power off
   1.499 +
   1.500 +	test.Next(_L("ATA drive: Caps following power off"));
   1.501 +	test(theAtaDrive.Caps(infoPckg)==KErrNone);
   1.502 +	test(info.iType==EMediaHardDisk);
   1.503 +
   1.504 +	test.Next(_L("Starting 2nd thread"));
   1.505 +	SecThreadChangeFlag=EFalse;
   1.506 +	RThread thread;
   1.507 +	TRequestStatus stat;
   1.508 +	test(thread.Create(_L("Thread"),dontDisconnectThread,KDefaultStackSize,KHeapSize,KHeapSize,NULL)==KErrNone);
   1.509 +	thread.Logon(stat);
   1.510 +	thread.Resume();
   1.511 +	User::WaitForRequest(stat);
   1.512 +	test(stat==KErrNone);
   1.513 +	CLOSE_AND_WAIT(thread);
   1.514 +
   1.515 +	test.Next(_L("ATA drive: 2nd media change"));
   1.516 +	theAtaDrive.ForceMediaChange();		// Generate media change
   1.517 +	test(ChangeFlag);
   1.518 +	test(!SecThreadChangeFlag);	// Closed 2nd thread so shouldn't have been updated
   1.519 +
   1.520 +	b.Format(_L("Disconnect from local drive (%c:)"),DriveNumber+'C');
   1.521 +	test.Next(b);
   1.522 +	theAtaDrive.Disconnect();
   1.523 +
   1.524 +	test.End();
   1.525 +
   1.526 +#if defined (__WINS__)
   1.527 +	for (i=0;i<KMaxLocalDrives;i++)
   1.528 +		Drive[i].Disconnect();
   1.529 +#endif
   1.530 +	return(0);
   1.531 +	}
   1.532 +