sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\pccd\t_media.cpp sl@0: // Test the Compact Flash card (ATA) media driver sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include "u32std.h" sl@0: #include "../misc/prbs.h" sl@0: sl@0: const TInt KSectorSize=512; sl@0: sl@0: LOCAL_D RTest test(_L("T_MEDIA")); sl@0: LOCAL_D TBusLocalDrive TheDrive; sl@0: LOCAL_D TBool MediaChange=EFalse; sl@0: LOCAL_D TUint Seed[2]; sl@0: sl@0: LOCAL_D TUint8 Background1[64*KSectorSize]; sl@0: LOCAL_D TUint8 Background2[64*KSectorSize]; sl@0: LOCAL_D TUint8 Foreground1[64*KSectorSize]; sl@0: LOCAL_D TUint8 Foreground2[64*KSectorSize]; sl@0: LOCAL_D TUint8 VerifyBuffer[64*KSectorSize]; sl@0: sl@0: inline TUint RoundDownToSector(TUint aPos) sl@0: { return aPos&~0x1ff; } sl@0: inline TUint RoundUpToSector(TUint aPos) sl@0: { return (aPos+0x1ff)&~0x1ff; } sl@0: sl@0: LOCAL_C void TestPattern(TUint8* aBuf, TInt aLength) sl@0: { sl@0: while(aLength--) sl@0: *aBuf++=(TUint8)Random(Seed); sl@0: } sl@0: sl@0: LOCAL_C void Write(TUint aPos, TInt aLength, const TUint8* aBuffer) sl@0: { sl@0: TPtrC8 p(aBuffer,aLength); sl@0: TInt r=TheDrive.Write(aPos,p); sl@0: if (r!=KErrNone) sl@0: { sl@0: test.Printf(_L("Write failed with error %d\n"),r); sl@0: test.Printf(_L("Pos=%08x, Length=%x\n"),aPos,aLength); sl@0: test(0); sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void DebugDump(TUint aPos, TInt aLength, const TUint8* aBuf, const TDesC& aTitle) sl@0: { sl@0: RDebug::Print(aTitle); sl@0: TUint end=aPos+aLength; sl@0: TInt i; sl@0: TInt j=0; sl@0: while(aPos buf; sl@0: buf.NumFixedWidthUC(aPos,EHex,8); sl@0: buf+=_L(": "); sl@0: for (i=0; i<16; i++) sl@0: { sl@0: buf.AppendNumFixedWidthUC(aBuf[j+i],EHex,2); sl@0: buf+=_L(" "); sl@0: } sl@0: RDebug::Print(buf); sl@0: aPos+=16; sl@0: j+=16; sl@0: if ((aPos&(KSectorSize-1))==0) sl@0: RDebug::Print(_L("")); sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void Verify(TUint aPos, TInt aLength, const TUint8* aRef) sl@0: { sl@0: TPtr8 p(VerifyBuffer,0,64*KSectorSize); sl@0: TInt r=TheDrive.Read(aPos,aLength,p); sl@0: if (r!=KErrNone) sl@0: { sl@0: test.Printf(_L("Read failed with error %d\n"),r); sl@0: test.Printf(_L("Pos=%08x, Length=%x\n"),aPos,aLength); sl@0: test(0); sl@0: } sl@0: if (p.Length()!=aLength) sl@0: { sl@0: test.Printf(_L("Incorrect length after read: Was %08x Expected %08x\n"),p.Length(),aLength); sl@0: test.Printf(_L("Pos=%08x, Length=%x\n"),aPos,aLength); sl@0: test(0); sl@0: } sl@0: r=Mem::Compare(VerifyBuffer,aLength,aRef,aLength); sl@0: if (r==0) sl@0: return; sl@0: TInt i=0; sl@0: while(i for debug dump ")); sl@0: TInt k=test.Getch(); sl@0: if (k==EKeyEnter) sl@0: { sl@0: DebugDump(aPos,aLength,VerifyBuffer,_L("Actual:")); sl@0: DebugDump(aPos,aLength,aRef,_L("Expected:")); sl@0: } sl@0: test(0); sl@0: } sl@0: sl@0: LOCAL_C void DoTest(TUint aBasePos, TInt anOffset, TInt aSize) sl@0: { sl@0: TBuf<80> buf; sl@0: buf.Format(_L("Offset %3x Size %04x"),anOffset,aSize); sl@0: test.Next(buf); sl@0: TUint block1=aBasePos; sl@0: TUint block2=aBasePos+64*KSectorSize; sl@0: TUint totalSectorSize=RoundUpToSector(anOffset+aSize); sl@0: TestPattern(Background1,totalSectorSize); sl@0: TestPattern(Background2,totalSectorSize); sl@0: TestPattern(Foreground1,totalSectorSize); sl@0: TestPattern(Foreground2,totalSectorSize); sl@0: Write(block1,totalSectorSize,Background1); sl@0: Write(block2,totalSectorSize,Background2); sl@0: Verify(block1,totalSectorSize,Background1); sl@0: Verify(block2,totalSectorSize,Background2); sl@0: Write(block1+anOffset,aSize,Foreground1); sl@0: Write(block2+anOffset,aSize,Foreground2); sl@0: Mem::Copy(Background1+anOffset,Foreground1,aSize); sl@0: Mem::Copy(Background2+anOffset,Foreground2,aSize); sl@0: Verify(block1,totalSectorSize,Background1); sl@0: Verify(block2,totalSectorSize,Background2); sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: Seed[0]=0xadf85458; sl@0: Seed[1]=0; sl@0: test.Title(); sl@0: sl@0: TChar driveToTest; sl@0: sl@0: // Get the list of drives sl@0: TDriveInfoV1Buf diBuf; sl@0: UserHal::DriveInfo(diBuf); sl@0: TDriveInfoV1 &di=diBuf(); sl@0: TInt driveCount = di.iTotalSupportedDrives; sl@0: sl@0: test.Printf(_L("\nDRIVES USED AT PRESENT :\r\n")); sl@0: for (TInt i=0; i < driveCount; i++) sl@0: { sl@0: TBool flag=EFalse; sl@0: RLocalDrive d; sl@0: TInt r=d.Connect(i,flag); sl@0: //Not all the drives are used at present sl@0: if (r == KErrNotSupported) sl@0: continue; sl@0: sl@0: test.Printf(_L("%d : DRIVE NAME :%- 16S\r\n"), i, &di.iDriveName[i]); sl@0: } sl@0: sl@0: test.Printf(_L("\n<<>>\r\n")); sl@0: sl@0: driveToTest=(TUint)test.Getch(); sl@0: sl@0: TInt driveNumber=((TUint)driveToTest) - '0'; sl@0: sl@0: TBuf<0x100> buf; sl@0: buf.Format(_L("Connect to local drive (%d)"),driveNumber); sl@0: test.Start(buf); sl@0: sl@0: TInt r=TheDrive.Connect(driveNumber,MediaChange); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Get capabilities")); sl@0: TLocalDriveCapsV2 driveCaps; sl@0: TPckg capsPckg(driveCaps); sl@0: r=TheDrive.Caps(capsPckg); sl@0: test(r==KErrNone); sl@0: TUint driveSize=I64LOW(driveCaps.iSize); sl@0: test.Printf(_L("Drive size = %08x (%dK)\n"),driveSize,driveSize>>10); sl@0: test.Printf(_L("Media type = %d\n"),driveCaps.iType); sl@0: test.Printf(_L("Connection Bus = %d\n"),driveCaps.iConnectionBusType); sl@0: test.Printf(_L("Drive attributes = %08x\n"),driveCaps.iDriveAtt); sl@0: test.Printf(_L("Media attributes = %08x\n"),driveCaps.iMediaAtt); sl@0: test.Printf(_L("Base address = %08x\n"),driveCaps.iBaseAddress); sl@0: test.Printf(_L("File system ID = %08x\n"),driveCaps.iFileSystemId); sl@0: test.Printf(_L("Hidden sectors = %08x\n"),driveCaps.iHiddenSectors); sl@0: test.Printf(_L("Press any key...\n")); sl@0: test.Getch(); sl@0: TUint basePos=RoundDownToSector(driveSize)-128*KSectorSize; sl@0: test.Printf(_L("Base position = %08x\n"),basePos); sl@0: sl@0: TInt offset; sl@0: TInt size; sl@0: for (size=KSectorSize/4; size<=23*KSectorSize/2; size+=KSectorSize/4) sl@0: { sl@0: for (offset=0; offset