diff -r 000000000000 -r bde4ae8d615e os/kernelhwsrv/kerneltest/e32test/pccd/t_atadr3.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os/kernelhwsrv/kerneltest/e32test/pccd/t_atadr3.cpp Fri Jun 15 03:10:57 2012 +0200 @@ -0,0 +1,464 @@ +// 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_atadr3.cpp +// Test the Compact Flash card (ATA) media driver +// +// + +#include +#include +#include +#include "u32std.h" +#include "../misc/prbs.h" + +//#define __USE_MUTEX__ +//#define __DISABLE_KILLER__ +#define SYSTEM ETrue + +const TInt KErrVerify=-100; + +const TInt KSectorSize=512; +const TInt KSectorShift=9; +const TInt KVerifyBlockSize=8; // in sectors + +LOCAL_D TBusLocalDrive WriterDrive; +LOCAL_D RTest test(_L("T_ATADR3")); +LOCAL_D TInt DriveNumber; +LOCAL_D TInt DriveSizeInSectors; +LOCAL_D RThread TheWriterThread; +LOCAL_D RThread TheKillerThread; +LOCAL_D RSemaphore Sem; +LOCAL_D TInt CurrentSector=0; +LOCAL_D TInt MediaChanges=0; +LOCAL_D TInt PowerDowns=0; +LOCAL_D TInt Kills=0; +LOCAL_D TInt SectorsWritten=0; +LOCAL_D TInt Aborts=0; +LOCAL_D TUint WritePattern=0; + +#ifdef __USE_MUTEX__ +LOCAL_D RMutex Mutex; +#define WAIT Mutex.Wait() +#define SIGNAL Mutex.Signal() +#else +#define WAIT +#define SIGNAL +#endif + +inline TUint RoundDownToSector(TUint aPos) + { return aPos&~0x1ff; } +inline TUint RoundUpToSector(TUint aPos) + { return (aPos+0x1ff)&~0x1ff; } + +LOCAL_C TInt WriteSectors(TBusLocalDrive& aDrive, TInt aSector, TInt aCount, TUint8* aBuf) + { + WAIT; + TInt r=KErrNotReady; + TInt pos=aSector<>8)&0xff); + TInt i; + for (i=0; i8 || n==0) + n=1; + if (n>remain) + n=remain; + if (n==1) + { + Write(WriterDrive,CurrentSector,1,pB); + ++WritePattern; + Write(WriterDrive,CurrentSector,1,pB+KSectorSize); + SectorsWritten+=2; + } + else + { + Write(WriterDrive,CurrentSector,n,pB); + SectorsWritten+=n; + } + CurrentSector+=n; + if (CurrentSector==DriveSizeInSectors) + { + CurrentSector=0; + ++WritePattern; + } + } + } + +LOCAL_C TInt KillerThread(TAny*) + { +/* + * SetSystem() API was removed by __SECURE_API__ + * "Systemize" will be implemented later calling a LDD which will set thread's "system" flag + RThread().SetSystem(SYSTEM); + */ + TUint seed[2]; + seed[0]=0xadf85458; + seed[1]=0; + TBusLocalDrive drive; + TBool medChg=EFalse; + TInt r=drive.Connect(DriveNumber,medChg); + if (r!=KErrNone) + User::Panic(_L("KILLER-CONNECT"),r); + RTimer timer; + r=timer.CreateLocal(); + if (r!=KErrNone) + User::Panic(_L("KILLER-TIMER"),r); + TInt action=0; + FOREVER + { + TUint x=Random(seed); + TUint ms=1000+(x&4095); + User::AfterHighRes(ms*1000); + switch (action) + { + case 0: +#ifndef __DISABLE_KILLER__ + drive.ForceMediaChange(); +#endif + ++MediaChanges; + break; + case 1: + { +#ifndef __DISABLE_KILLER__ + TTime now; + now.HomeTime(); + now+=TTimeIntervalSeconds(2); + TRequestStatus s; + timer.At(s,now); + UserHal::SwitchOff(); + User::WaitForRequest(s); + ++PowerDowns; +#endif + break; + } + case 2: +#ifndef __DISABLE_KILLER__ + TheWriterThread.Kill(0); +#endif + ++Kills; +#ifndef __DISABLE_KILLER__ + ++WritePattern; + Sem.Wait(); + TheWriterThread.SetPriority(EPriorityNormal); +#endif + break; + case 3: +#ifndef __DISABLE_KILLER__ + drive.ForceMediaChange(); +#endif + ++MediaChanges; +#ifndef __DISABLE_KILLER__ + x=Random(seed); + ms=50+(x&511); + User::AfterHighRes(ms*1000); + TheWriterThread.Kill(0); +#endif + ++Kills; +#ifndef __DISABLE_KILLER__ + ++WritePattern; + Sem.Wait(); + TheWriterThread.SetPriority(EPriorityNormal); +#endif + break; + case 4: + break; + } + if (++action==5) + action=0; +#ifndef __DISABLE_KILLER__ + TInt curr=CurrentSector; + TInt remain=DriveSizeInSectors-curr; + TInt n=(remain<8)?remain:8; + r=Verify(drive,curr,n); + if (r!=KErrNone) + User::Panic(_L("VERIFY"),r); +#endif + } + } + +LOCAL_C TInt CreateKillerThread() + { + TInt r=TheKillerThread.Create(_L("Killer"),KillerThread,0x2000,NULL,NULL); + if (r!=KErrNone) + return r; + TheKillerThread.SetPriority(EPriorityMore); + TheKillerThread.Resume(); + return KErrNone; + } + +LOCAL_C TInt CreateWriterThread() + { + FOREVER + { + TInt r=TheWriterThread.Create(_L("Writer"),WriterThread,0x2000,NULL,NULL); + if (r==KErrNone) + break; + if (r!=KErrAlreadyExists) + return r; + test.Printf(_L("Writer thread still exists\n")); + User::After(200000); + } + TheWriterThread.SetPriority(EPriorityLess); + TheWriterThread.Resume(); + return KErrNone; + } + +GLDEF_C TInt E32Main() + { +/* + * SetSystem() API was removed by __SECURE_API__ + * "Systemize" will be implemented later calling a LDD which will set thread's "system" flag + RThread().SetSystem(SYSTEM); + */ + WriterDrive.SetHandle(0); + test.Title(); + TInt drv=-1; + while (drv<0 || drv>=KMaxLocalDrives) + { + test.Printf(_L("\nSelect drive C-K: ")); + TChar c=(TUint)test.Getch(); + c.UpperCase(); + if (c.IsAlpha()) + drv=TUint(c)-'C'; + else + drv=-1; + } + TBuf<1> b; + b.SetLength(1); + b[0]=(TText)(drv+'C'); + test.Printf(_L("%S\n"),&b); + + TBuf<80> buf=_L("Connect to drive "); + buf+=b; + test.Start(buf); + TBusLocalDrive drive; + TBool medChg=EFalse; + TInt r=drive.Connect(drv,medChg); + test(r==KErrNone); + DriveNumber=drv; + + test.Next(_L("Get capabilities")); + TLocalDriveCapsV2 driveCaps; + TPckg capsPckg(driveCaps); + r=drive.Caps(capsPckg); + test(r==KErrNone); + TUint driveSize=I64LOW(driveCaps.iSize); + DriveSizeInSectors=(driveSize&~0xfff)>>KSectorShift; // round down to multiple of 8 sectors + test.Printf(_L("Drive size = %08x (%dK)\n"),driveSize,driveSize>>10); + test.Printf(_L("Media type = %d\n"),driveCaps.iType); + test.Printf(_L("Connection Bus = %d\n"),driveCaps.iConnectionBusType); + test.Printf(_L("Drive attributes = %08x\n"),driveCaps.iDriveAtt); + test.Printf(_L("Media attributes = %08x\n"),driveCaps.iMediaAtt); + test.Printf(_L("Base address = %08x\n"),driveCaps.iBaseAddress); + test.Printf(_L("File system ID = %08x\n"),driveCaps.iFileSystemId); + test.Printf(_L("Hidden sectors = %08x\n"),driveCaps.iHiddenSectors); + test.Printf(_L("Press any key...\n")); + test.Getch(); + +#ifdef __USE_MUTEX__ + test.Next(_L("Create mutex")); + r=Mutex.CreateLocal(); + test(r==KErrNone); +#endif + + test.Next(_L("Initialise drive")); + TInt sector; + for (sector=0; sector