os/kernelhwsrv/kerneltest/e32test/pccd/t_media.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_media.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,224 @@
     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_media.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 "u32std.h"
    1.25 +#include "../misc/prbs.h"
    1.26 +
    1.27 +const TInt KSectorSize=512;
    1.28 +
    1.29 +LOCAL_D RTest test(_L("T_MEDIA"));
    1.30 +LOCAL_D TBusLocalDrive TheDrive;
    1.31 +LOCAL_D TBool MediaChange=EFalse;
    1.32 +LOCAL_D TUint Seed[2];
    1.33 +
    1.34 +LOCAL_D TUint8 Background1[64*KSectorSize];
    1.35 +LOCAL_D TUint8 Background2[64*KSectorSize];
    1.36 +LOCAL_D TUint8 Foreground1[64*KSectorSize];
    1.37 +LOCAL_D TUint8 Foreground2[64*KSectorSize];
    1.38 +LOCAL_D TUint8 VerifyBuffer[64*KSectorSize];
    1.39 +
    1.40 +inline TUint RoundDownToSector(TUint aPos)
    1.41 +	{ return aPos&~0x1ff; }
    1.42 +inline TUint RoundUpToSector(TUint aPos)
    1.43 +	{ return (aPos+0x1ff)&~0x1ff; }
    1.44 +
    1.45 +LOCAL_C void TestPattern(TUint8* aBuf, TInt aLength)
    1.46 +	{
    1.47 +	while(aLength--)
    1.48 +		*aBuf++=(TUint8)Random(Seed);
    1.49 +	}
    1.50 +
    1.51 +LOCAL_C void Write(TUint aPos, TInt aLength, const TUint8* aBuffer)
    1.52 +	{
    1.53 +	TPtrC8 p(aBuffer,aLength);
    1.54 +	TInt r=TheDrive.Write(aPos,p);
    1.55 +	if (r!=KErrNone)
    1.56 +		{
    1.57 +		test.Printf(_L("Write failed with error %d\n"),r);
    1.58 +		test.Printf(_L("Pos=%08x, Length=%x\n"),aPos,aLength);
    1.59 +		test(0);
    1.60 +		}
    1.61 +	}
    1.62 +
    1.63 +LOCAL_C void DebugDump(TUint aPos, TInt aLength, const TUint8* aBuf, const TDesC& aTitle)
    1.64 +	{
    1.65 +	RDebug::Print(aTitle);
    1.66 +	TUint end=aPos+aLength;
    1.67 +	TInt i;
    1.68 +	TInt j=0;
    1.69 +	while(aPos<end)
    1.70 +		{
    1.71 +		TBuf<80> buf;
    1.72 +		buf.NumFixedWidthUC(aPos,EHex,8);
    1.73 +		buf+=_L(": ");
    1.74 +		for (i=0; i<16; i++)
    1.75 +			{
    1.76 +			buf.AppendNumFixedWidthUC(aBuf[j+i],EHex,2);
    1.77 +			buf+=_L(" ");
    1.78 +			}
    1.79 +		RDebug::Print(buf);
    1.80 +		aPos+=16;
    1.81 +		j+=16;
    1.82 +		if ((aPos&(KSectorSize-1))==0)
    1.83 +			RDebug::Print(_L(""));
    1.84 +		}
    1.85 +	}
    1.86 +
    1.87 +LOCAL_C void Verify(TUint aPos, TInt aLength, const TUint8* aRef)
    1.88 +	{
    1.89 +	TPtr8 p(VerifyBuffer,0,64*KSectorSize);
    1.90 +	TInt r=TheDrive.Read(aPos,aLength,p);
    1.91 +	if (r!=KErrNone)
    1.92 +		{
    1.93 +		test.Printf(_L("Read failed with error %d\n"),r);
    1.94 +		test.Printf(_L("Pos=%08x, Length=%x\n"),aPos,aLength);
    1.95 +		test(0);
    1.96 +		}
    1.97 +	if (p.Length()!=aLength)
    1.98 +		{
    1.99 +		test.Printf(_L("Incorrect length after read: Was %08x Expected %08x\n"),p.Length(),aLength);
   1.100 +		test.Printf(_L("Pos=%08x, Length=%x\n"),aPos,aLength);
   1.101 +		test(0);
   1.102 +		}
   1.103 +	r=Mem::Compare(VerifyBuffer,aLength,aRef,aLength);
   1.104 +	if (r==0)
   1.105 +		return;
   1.106 +	TInt i=0;
   1.107 +	while(i<aLength && VerifyBuffer[i]==aRef[i])
   1.108 +		i++;
   1.109 +	test.Printf(_L("Verify error: aPos=%08x, aLength=%08x\n"),aPos,aLength);
   1.110 +	test.Printf(_L("First difference at offset %x\n"),i);
   1.111 +	test.Printf(_L("Press <ENTER> for debug dump "));
   1.112 +	TInt k=test.Getch();
   1.113 +	if (k==EKeyEnter)
   1.114 +		{
   1.115 +		DebugDump(aPos,aLength,VerifyBuffer,_L("Actual:"));
   1.116 +		DebugDump(aPos,aLength,aRef,_L("Expected:"));
   1.117 +		}
   1.118 +	test(0);
   1.119 +	}
   1.120 +
   1.121 +LOCAL_C void DoTest(TUint aBasePos, TInt anOffset, TInt aSize)
   1.122 +	{
   1.123 +	TBuf<80> buf;
   1.124 +	buf.Format(_L("Offset %3x Size %04x"),anOffset,aSize);
   1.125 +	test.Next(buf);
   1.126 +	TUint block1=aBasePos;
   1.127 +	TUint block2=aBasePos+64*KSectorSize;
   1.128 +	TUint totalSectorSize=RoundUpToSector(anOffset+aSize);
   1.129 +	TestPattern(Background1,totalSectorSize);
   1.130 +	TestPattern(Background2,totalSectorSize);
   1.131 +	TestPattern(Foreground1,totalSectorSize);
   1.132 +	TestPattern(Foreground2,totalSectorSize);
   1.133 +	Write(block1,totalSectorSize,Background1);
   1.134 +	Write(block2,totalSectorSize,Background2);
   1.135 +	Verify(block1,totalSectorSize,Background1);
   1.136 +	Verify(block2,totalSectorSize,Background2);
   1.137 +	Write(block1+anOffset,aSize,Foreground1);
   1.138 +	Write(block2+anOffset,aSize,Foreground2);
   1.139 +	Mem::Copy(Background1+anOffset,Foreground1,aSize);
   1.140 +	Mem::Copy(Background2+anOffset,Foreground2,aSize);
   1.141 +	Verify(block1,totalSectorSize,Background1);
   1.142 +	Verify(block2,totalSectorSize,Background2);
   1.143 +	}
   1.144 +
   1.145 +GLDEF_C TInt E32Main()
   1.146 +	{
   1.147 +	Seed[0]=0xadf85458;
   1.148 +	Seed[1]=0;
   1.149 +	test.Title();
   1.150 +	
   1.151 +	TChar driveToTest;
   1.152 +
   1.153 +	// Get the list of drives
   1.154 +	TDriveInfoV1Buf diBuf;
   1.155 +	UserHal::DriveInfo(diBuf);
   1.156 +	TDriveInfoV1 &di=diBuf();
   1.157 +	TInt driveCount = di.iTotalSupportedDrives;
   1.158 +	
   1.159 +	test.Printf(_L("\nDRIVES USED AT PRESENT :\r\n"));
   1.160 +	for (TInt i=0; i < driveCount; i++)
   1.161 +		{
   1.162 +		TBool flag=EFalse;
   1.163 +		RLocalDrive d;
   1.164 +		TInt r=d.Connect(i,flag);
   1.165 +		//Not all the drives are used at present
   1.166 +		if (r == KErrNotSupported)
   1.167 +			continue;
   1.168 +
   1.169 +		test.Printf(_L("%d : DRIVE NAME  :%- 16S\r\n"), i, &di.iDriveName[i]);
   1.170 +		}
   1.171 +
   1.172 +	test.Printf(_L("\n<<<Hit required drive number to continue>>>\r\n"));
   1.173 +
   1.174 +	driveToTest=(TUint)test.Getch();
   1.175 +	
   1.176 +	TInt driveNumber=((TUint)driveToTest) - '0';
   1.177 +
   1.178 +	TBuf<0x100> buf;
   1.179 +	buf.Format(_L("Connect to local drive (%d)"),driveNumber);
   1.180 +	test.Start(buf);
   1.181 +	
   1.182 +	TInt r=TheDrive.Connect(driveNumber,MediaChange);
   1.183 +	test(r==KErrNone);
   1.184 +	
   1.185 +	test.Next(_L("Get capabilities"));
   1.186 +	TLocalDriveCapsV2 driveCaps;
   1.187 +	TPckg<TLocalDriveCapsV2> capsPckg(driveCaps);
   1.188 +	r=TheDrive.Caps(capsPckg);
   1.189 +	test(r==KErrNone);
   1.190 +	TUint driveSize=I64LOW(driveCaps.iSize);
   1.191 +	test.Printf(_L("Drive size       = %08x (%dK)\n"),driveSize,driveSize>>10);
   1.192 +	test.Printf(_L("Media type       = %d\n"),driveCaps.iType);
   1.193 +	test.Printf(_L("Connection Bus   = %d\n"),driveCaps.iConnectionBusType);
   1.194 +	test.Printf(_L("Drive attributes = %08x\n"),driveCaps.iDriveAtt);
   1.195 +	test.Printf(_L("Media attributes = %08x\n"),driveCaps.iMediaAtt);
   1.196 +	test.Printf(_L("Base address     = %08x\n"),driveCaps.iBaseAddress);
   1.197 +	test.Printf(_L("File system ID   = %08x\n"),driveCaps.iFileSystemId);
   1.198 +	test.Printf(_L("Hidden sectors   = %08x\n"),driveCaps.iHiddenSectors);
   1.199 +	test.Printf(_L("Press any key...\n"));
   1.200 +	test.Getch();
   1.201 +	TUint basePos=RoundDownToSector(driveSize)-128*KSectorSize;
   1.202 +	test.Printf(_L("Base position    = %08x\n"),basePos);
   1.203 +
   1.204 +	TInt offset;
   1.205 +	TInt size;
   1.206 +	for (size=KSectorSize/4; size<=23*KSectorSize/2; size+=KSectorSize/4)
   1.207 +		{
   1.208 +		for (offset=0; offset<KSectorSize; offset+=KSectorSize/2)
   1.209 +			{
   1.210 +			DoTest(basePos,offset,size);
   1.211 +			}
   1.212 +		}
   1.213 +
   1.214 +	for (size=12*KSectorSize; size<=33*KSectorSize; size+=KSectorSize/2)
   1.215 +		{
   1.216 +		for (offset=0; offset<KSectorSize; offset+=KSectorSize/2)
   1.217 +			{
   1.218 +			DoTest(basePos,offset,size);
   1.219 +			}
   1.220 +		}
   1.221 +
   1.222 +	buf.Format(_L("Disconnect from local drive (%d)"),driveNumber);
   1.223 +	test.Next(buf);
   1.224 +	TheDrive.Disconnect();
   1.225 +	test.End();
   1.226 +	return 0;
   1.227 +	}