sl@0: // Copyright (c) 2008-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\demandpaging\t_tbus_datapaging.cpp sl@0: // Functional tests for data paging. sl@0: // 002 ??? sl@0: // 003 ??? sl@0: // sl@0: sl@0: //! @SYMTestCaseID KBASE-T_TBUS_DATAPAGING sl@0: //! @SYMTestType UT sl@0: //! @SYMPREQ ??? sl@0: //! @SYMTestCaseDesc Data Paging functional tests with TBusLocalDrive. sl@0: //! @SYMTestActions 001 ??? sl@0: //! @SYMTestExpectedResults All tests should pass. sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implementation on-going sl@0: sl@0: #define __E32TEST_EXTENSION__ sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "u32std.h" sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "t_dpcmn.h" sl@0: #include "../secure/d_sldd.h" sl@0: #include "../mmu/mmudetect.h" sl@0: sl@0: const TInt KMaxLengthOfStoreMapping = 16 + sizeof(TInt32) + KMaxMediaPassword; sl@0: const TInt KMaxPersistentStore(TPasswordStore::EMaxPasswordLength+KMaxLengthOfStoreMapping); sl@0: typedef TBuf8 TPersistentStore; sl@0: sl@0: RChunk gMyChunk; sl@0: TUint gOffset = 0; sl@0: TUint8* gData = NULL; sl@0: const TUint8 KClearValue = 0xed; sl@0: const TUint KChunkSizeInPages = 64; // 64 * 4096 = 256K sl@0: const TInt KTestBufLen=256; sl@0: sl@0: sl@0: #define __DECLARE_VAR_IN_CHUNK(type, varRef) \ sl@0: type varRef = *(type*) (gData+gOffset); \ sl@0: gOffset += Max(gPageSize, sizeof(type)); \ sl@0: test(gOffset <= gPageSize * KChunkSizeInPages); sl@0: sl@0: #define __DECLARE_AND_INIT_VAR_IN_CHUNK(type, var) \ sl@0: type &var = *(type*) (gData+gOffset); \ sl@0: var = type(); \ sl@0: gOffset += Max(gPageSize, sizeof(type)); \ sl@0: test(gOffset <= gPageSize * KChunkSizeInPages); sl@0: sl@0: sl@0: #define __DECLARE_ARRAY_IN_CHUNK(type, var, size) \ sl@0: type *var = (type*) (gData+gOffset); \ sl@0: gOffset += Max(gPageSize, (sizeof(type) * size)); \ sl@0: test(gOffset <= gPageSize * KChunkSizeInPages); sl@0: sl@0: #define __FLUSH_AND_CALL_API_METHOD(return, function) \ sl@0: DPTest::FlushCache(); \ sl@0: return = function; sl@0: sl@0: sl@0: LOCAL_D RFs TheFs; sl@0: TInt gFsDriveNumber = -1; sl@0: sl@0: RTest test(_L("T_TBUS_DATAPAGING")); sl@0: _LIT(KChunkName, "t_datapaging chunk"); sl@0: sl@0: const TUint KDriveAttMask = KDriveAttLocal | KDriveAttRom | KDriveAttRemote; sl@0: const TUint KMediaAttMask = KMediaAttVariableSize | KMediaAttDualDensity | KMediaAttLockable | KMediaAttLocked | KMediaAttHasPassword | KMediaAttReadWhileWrite; sl@0: sl@0: void CreatePagedChunk(TInt aSizeInPages, TInt aWipeByte = -1) sl@0: { sl@0: test_Equal(0,gMyChunk.Handle()); sl@0: sl@0: TChunkCreateInfo createInfo; sl@0: TInt size = aSizeInPages * gPageSize; sl@0: createInfo.SetNormal(size, size); sl@0: createInfo.SetPaging(TChunkCreateInfo::EPaged); sl@0: createInfo.SetOwner(EOwnerProcess); sl@0: createInfo.SetGlobal(KChunkName); sl@0: if (aWipeByte != -1) sl@0: createInfo.SetClearByte(aWipeByte); sl@0: test_KErrNone(gMyChunk.Create(createInfo)); sl@0: test(gMyChunk.IsPaged()); // this is only ever called if data paging is supported sl@0: sl@0: gData = gMyChunk.Base(); sl@0: } sl@0: sl@0: TInt TestDriveConnectAndCaps(TBusLocalDrive &aDrive, TInt &aLocalDriveNumber) sl@0: { sl@0: sl@0: test.Next(_L("Test Drive Connect And Caps")); sl@0: sl@0: __DECLARE_VAR_IN_CHUNK(TInt, &r); sl@0: sl@0: test.Printf(_L("changeFlag...\n")); sl@0: __DECLARE_VAR_IN_CHUNK(TBool, &changeFlag); sl@0: changeFlag = EFalse; sl@0: sl@0: test.Printf(_L("call aDrive.Connect()...\n")); sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.Connect(aLocalDriveNumber,changeFlag)); sl@0: sl@0: test.Printf(_L("r:%d\n"),r); sl@0: test_Equal(KErrNone, r); sl@0: sl@0: test.Printf(_L("call aDrive.Caps()...\n")); sl@0: __DECLARE_VAR_IN_CHUNK(TLocalDriveCapsV5, &driveCaps); sl@0: sl@0: TPckg capsPckg(driveCaps); sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.Caps(capsPckg)); sl@0: sl@0: test_Equal(KErrNone, r); sl@0: test.Printf(_L("r:%d\n"),r); sl@0: test.Printf(_L("driveCaps.iDriveAtt :0x%08x\n"), driveCaps.iDriveAtt); sl@0: test.Printf(_L("driveCaps.iSize :%ld\n"), driveCaps.iSize); sl@0: test.Printf(_L("driveCaps.iSerialNumLength :%d\n"), driveCaps.iSerialNumLength); sl@0: sl@0: return I64LOW(driveCaps.iSize); sl@0: } sl@0: sl@0: void TestDriveSizeRelatedMethods(TBusLocalDrive &aDrive, TInt aNewSize, TInt aOldSize) sl@0: { sl@0: TInt r; sl@0: sl@0: test.Next(_L("Test Drive Size Related Methods")); sl@0: test.Printf(_L("newDriveSize...\n")); sl@0: __DECLARE_VAR_IN_CHUNK(TInt, &newDriveSize); sl@0: newDriveSize = aNewSize; sl@0: sl@0: test.Printf(_L("call aDrive.Enlarge()...\n")); sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.Enlarge(newDriveSize)); sl@0: test.Printf(_L("r:%d\n"),r); sl@0: test((KErrNone == r) || (KErrNotSupported == r) || (KErrNotReady == r)); sl@0: if(r != KErrNone ) sl@0: { sl@0: test.Printf(_L("errInfo...\n")); sl@0: __DECLARE_ARRAY_IN_CHUNK(TUint8, errInfo, KTestBufLen); sl@0: sl@0: TPtr8 pErrInfoBuff(errInfo, KTestBufLen); sl@0: sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.GetLastErrorInfo(pErrInfoBuff)); sl@0: test.Printf(_L("r:%d\n"),r); sl@0: test((KErrNone == r) || (KErrNotSupported == r)); sl@0: } sl@0: sl@0: sl@0: test.Printf(_L("call aDrive.ReduceSize()...\n")); sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.ReduceSize(0, aOldSize)); sl@0: test((KErrNone == r) || (KErrNotSupported == r) || (KErrNotReady == r)); sl@0: sl@0: } sl@0: sl@0: void TestWriteReadRelatedMethods(TBusLocalDrive &aDrive) sl@0: { sl@0: sl@0: test.Next(_L("Test Write & Read Related Methods")); sl@0: sl@0: __DECLARE_VAR_IN_CHUNK(TInt, &r); sl@0: sl@0: test.Printf(_L("msgHandle...\n")); sl@0: __DECLARE_VAR_IN_CHUNK(TInt, &msgHandle); sl@0: msgHandle = KLocalMessageHandle; sl@0: sl@0: sl@0: __DECLARE_VAR_IN_CHUNK(TUint, &i); sl@0: test.Printf(_L("wrBuf...\n")); sl@0: TBuf8 wrBuf(KTestBufLen); sl@0: for (i=0 ; i<(TUint)KTestBufLen ; i++) sl@0: wrBuf[i]=(TUint8)i; sl@0: sl@0: sl@0: test.Printf(_L("wrBuf2...\n")); sl@0: __DECLARE_ARRAY_IN_CHUNK(TUint8, wrBuf2, KTestBufLen); sl@0: sl@0: test.Printf(_L("fill wrBuf2...\n")); sl@0: for (i=0 ; i<(TUint)KTestBufLen ; i++) sl@0: wrBuf2[i]=(TUint8)i; sl@0: sl@0: TPtr8 pWrBuf2(wrBuf2, KTestBufLen, KTestBufLen); sl@0: sl@0: test.Printf(_L("rdBuf...\n")); sl@0: TBuf8 rdBuf(KTestBufLen); sl@0: sl@0: sl@0: test.Printf(_L("rdBuf2...\n")); sl@0: __DECLARE_ARRAY_IN_CHUNK(TUint8, rdBuf2, KTestBufLen); sl@0: sl@0: TPtr8 pRdBuf2(rdBuf2, KTestBufLen); sl@0: sl@0: test.Printf(_L("call aDrive.Write()...\n")); sl@0: rdBuf.Fill(0,KTestBufLen); sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.Write(0,KTestBufLen,&wrBuf,msgHandle,0)); sl@0: test_Equal(KErrNone, r); sl@0: sl@0: sl@0: test.Printf(_L("call aDrive.Read()...\n")); sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.Read(0,KTestBufLen,&rdBuf,msgHandle,0)); sl@0: test_Equal(KErrNone, r); sl@0: sl@0: for (i=0 ; i<(TUint)KTestBufLen ; i++) sl@0: test_Equal(wrBuf[i], rdBuf[i]); sl@0: sl@0: test.Printf(_L("call aDrive.Write()...\n")); sl@0: pRdBuf2.Fill(0,KTestBufLen); sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.Write(0,pWrBuf2)); sl@0: test_Equal(KErrNone, r); sl@0: sl@0: sl@0: test.Printf(_L("call aDrive.Read()...\n")); sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.Read(0,KTestBufLen, pRdBuf2)); sl@0: test_Equal(KErrNone, r); sl@0: sl@0: for (i=0 ; i<(TUint)KTestBufLen ; i++) sl@0: test_Equal(wrBuf2[i], rdBuf2[i]); sl@0: sl@0: } sl@0: sl@0: void TestPasswordRelatedMethods(TBusLocalDrive &aDrive) sl@0: { sl@0: TInt r; sl@0: sl@0: test.Next(_L("Test Password Related Methods")); sl@0: //__DECLARE_VAR_IN_CHUNK(TPersistentStore, &wStore); sl@0: sl@0: TPersistentStore* pstoreAB; sl@0: test((pstoreAB = new TPersistentStore) != 0); sl@0: TPersistentStore& wStore = *pstoreAB; sl@0: sl@0: //__DECLARE_AND_INIT_VAR_IN_CHUNK(TPersistentStore, wStore); sl@0: sl@0: // Password related API methods call sl@0: test.Printf(_L("call aDrive.WritePasswordData() to clear passwords...\n")); sl@0: __DECLARE_VAR_IN_CHUNK(TInt, &passwordStoreLength); sl@0: sl@0: TBuf8<1> nulSt; sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.WritePasswordData(nulSt)); sl@0: test( r == KErrNone);// empty sl@0: sl@0: test.Printf(_L("call aDrive.PasswordStoreLengthInBytes()...\n")); sl@0: __FLUSH_AND_CALL_API_METHOD(passwordStoreLength, aDrive.PasswordStoreLengthInBytes()); sl@0: sl@0: test.Printf(_L("passwordStoreLength:%d\n"), passwordStoreLength); sl@0: test_Equal(0, passwordStoreLength); sl@0: sl@0: sl@0: test.Printf(_L("call aDrive.ErasePassword()...\n")); sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.ErasePassword()); sl@0: test.Printf(_L("r:%d\n"),r); sl@0: sl@0: sl@0: test.Printf(_L("wStore.Size():%d\n"),wStore.Size()); sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.WritePasswordData(wStore)); sl@0: sl@0: test.Printf(_L("r:%d\n"),r); sl@0: test((KErrNone == r)); // || (KErrCorrupt == r)); // TO-DO Why Corrupt??? sl@0: sl@0: __FLUSH_AND_CALL_API_METHOD(passwordStoreLength, aDrive.PasswordStoreLengthInBytes()); sl@0: sl@0: test.Printf(_L("passwordStoreLength:%d\n"), passwordStoreLength); sl@0: test((r == KErrNone ? (wStore.Size() == passwordStoreLength) : (0 == passwordStoreLength) )); sl@0: sl@0: sl@0: sl@0: test.Printf(_L("Set and store a password...\n")); sl@0: TDes8 &st = wStore; sl@0: TMediaPassword a((const TUint8*) "CID0ccccccccccc#"); sl@0: TUint8 passLen[sizeof(TInt32)]; sl@0: passLen[0] = 0; sl@0: passLen[1] = 0; sl@0: passLen[2] = 0; sl@0: passLen[3] = 16; sl@0: sl@0: //test.Printf(_L("Password3:'%S'\n"), &a); sl@0: sl@0: st.Append(a); sl@0: st.Append(passLen, sizeof(TInt32)); sl@0: st.Append(a); sl@0: sl@0: test.Printf(_L("wStore.Size():%d\n"),wStore.Size()); sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.WritePasswordData(wStore)); sl@0: sl@0: test.Printf(_L("r:%d\n"),r); sl@0: test((KErrNone == r)); sl@0: sl@0: __FLUSH_AND_CALL_API_METHOD(passwordStoreLength, aDrive.PasswordStoreLengthInBytes()); sl@0: sl@0: test.Printf(_L("passwordStoreLength:%d\n"), passwordStoreLength); sl@0: test((r == KErrNone ? (wStore.Size() == passwordStoreLength) : (0 == passwordStoreLength) )); sl@0: sl@0: test.Printf(_L("call aDrive.ErasePassword()...\n")); sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.ErasePassword()); sl@0: test.Printf(_L("r:%d\n"),r); sl@0: sl@0: test.Printf(_L("call aDrive.WritePasswordData() to set password again...\n")); sl@0: test.Printf(_L("wStore.Size():%d\n"),wStore.Size()); sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.WritePasswordData(wStore)); sl@0: sl@0: test.Printf(_L("r:%d\n"),r); sl@0: test((KErrNone == r)); sl@0: sl@0: __FLUSH_AND_CALL_API_METHOD(passwordStoreLength, aDrive.PasswordStoreLengthInBytes()); sl@0: sl@0: test.Printf(_L("passwordStoreLength:%d\n"), passwordStoreLength); sl@0: test((r == KErrNone ? (wStore.Size() == passwordStoreLength) : (0 == passwordStoreLength) )); sl@0: sl@0: sl@0: // Finally erase password sl@0: test.Printf(_L("call aDrive.WritePasswordData() to erase password...\n")); sl@0: wStore.Zero(); // empty password store sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.WritePasswordData(wStore)) sl@0: test( r == KErrNone);// Clear sl@0: sl@0: __FLUSH_AND_CALL_API_METHOD(passwordStoreLength, aDrive.PasswordStoreLengthInBytes()); sl@0: sl@0: test.Printf(_L("passwordStoreLength:%d\n"), passwordStoreLength); sl@0: test((r == KErrNone ? (wStore.Size() == passwordStoreLength) : (0 == passwordStoreLength) )); sl@0: sl@0: sl@0: sl@0: // Test SetPassword sl@0: TMediaPassword nul(nulSt); sl@0: sl@0: test.Printf(_L("call aDrive.SetPassword()...\n")); sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.SetPassword(nul, a, EFalse)); sl@0: test.Printf(_L("r:%d\n"),r); sl@0: test_Equal(KErrNone, r); sl@0: sl@0: // Erase Password sl@0: test.Printf(_L("call aDrive.ErasePassword()...\n")); sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.ErasePassword()); sl@0: test.Printf(_L("r:%d\n"),r); sl@0: sl@0: sl@0: test.Printf(_L("call aDrive.SetPassword()...\n")); sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.SetPassword(nul, a, EFalse)); sl@0: test.Printf(_L("r:%d\n"),r); sl@0: test_Equal(KErrNone, r); sl@0: sl@0: // Erase Clear sl@0: test.Printf(_L("call aDrive.Clear()...\n")); sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.Clear(a)); sl@0: test.Printf(_L("r:%d\n"),r); sl@0: sl@0: sl@0: test.Printf(_L("call aDrive.SetPassword() to clear again...\n")); sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.SetPassword(a, nul, EFalse)); sl@0: test.Printf(_L("r:%d\n"),r); sl@0: test_Equal(KErrAccessDenied, r); sl@0: sl@0: sl@0: // Finally erase password sl@0: test.Printf(_L("call aDrive.WritePasswordData() to erase password...\n")); sl@0: wStore.Zero(); // empty password store sl@0: __FLUSH_AND_CALL_API_METHOD(r, aDrive.WritePasswordData(wStore)) sl@0: test( r == KErrNone);// Clear sl@0: sl@0: __FLUSH_AND_CALL_API_METHOD(passwordStoreLength, aDrive.PasswordStoreLengthInBytes()); sl@0: sl@0: test.Printf(_L("passwordStoreLength:%d\n"), passwordStoreLength); sl@0: test((r == KErrNone ? (wStore.Size() == passwordStoreLength) : (0 == passwordStoreLength) )); sl@0: sl@0: } sl@0: sl@0: void TestFormatRelatedMethods(TBusLocalDrive &aDrive, TInt aSize ) sl@0: { sl@0: test.Next(_L("Test Format Related Methods")); sl@0: sl@0: test.Printf(_L("call aDrive.Format(TFormatInfo)...\n")); sl@0: __DECLARE_AND_INIT_VAR_IN_CHUNK(TFormatInfo, fi); sl@0: __DECLARE_VAR_IN_CHUNK(TInt, &ret); sl@0: __DECLARE_VAR_IN_CHUNK(TInt, &attempt); sl@0: sl@0: __FLUSH_AND_CALL_API_METHOD(ret, aDrive.Format(fi)); sl@0: test.Printf(_L("ret:%d\n"),ret); sl@0: while(ret!=KErrEof) sl@0: { sl@0: if( ret == KErrNotReady ) sl@0: { sl@0: attempt = 100; sl@0: while( (ret= aDrive.Format(fi)) == KErrNotReady && --attempt) sl@0: { sl@0: test.Printf(_L("attempt:%d\n"),attempt); sl@0: User::After(1000000); sl@0: } sl@0: test(attempt); sl@0: } sl@0: else sl@0: { sl@0: test(ret==KErrNone); sl@0: ret= aDrive.Format(fi); sl@0: } sl@0: } sl@0: sl@0: sl@0: test.Printf(_L("call aDrive.Format(pos, length)...\n")); sl@0: User::After(1000000); sl@0: sl@0: __DECLARE_VAR_IN_CHUNK(TInt64, &pos); sl@0: pos = 0; sl@0: __DECLARE_VAR_IN_CHUNK(TInt, &length); sl@0: length = aSize; sl@0: sl@0: attempt = 100; sl@0: __FLUSH_AND_CALL_API_METHOD(ret, aDrive.Format(pos, length)); sl@0: while( ret == KErrNotReady && --attempt) sl@0: { sl@0: User::After(1000000); sl@0: ret= aDrive.Format(pos, length); sl@0: } sl@0: test(attempt); sl@0: test_Equal(KErrNone, ret); sl@0: sl@0: test.Printf(_L("End of TestFormatRelatedMethods)...\n")); sl@0: } sl@0: sl@0: void RestoreDriveState(void) sl@0: { sl@0: TBuf<3> bfDrv; sl@0: sl@0: const TText KDrvLtr = 'A' + gFsDriveNumber; sl@0: sl@0: bfDrv.Append(KDrvLtr); sl@0: _LIT(KBP, ":\\"); sl@0: bfDrv.Append(KBP); sl@0: sl@0: sl@0: TheFs.Connect(); sl@0: RFormat fmt; sl@0: TInt count; sl@0: sl@0: test(fmt.Open(TheFs, bfDrv, EHighDensity, count) == KErrNone); sl@0: while (count > 0) sl@0: { sl@0: test.Printf(_L("\rfmt:%d "), count); sl@0: test(fmt.Next(count) == KErrNone); sl@0: } sl@0: test.Printf(_L("\n")); sl@0: fmt.Close(); sl@0: sl@0: TheFs.Close(); sl@0: } sl@0: sl@0: sl@0: TInt FindDataPagingDrive() sl@0: /** sl@0: Find the drive containing a swap partition. sl@0: sl@0: @return Local drive identifier. sl@0: */ sl@0: { sl@0: TInt drive = KErrNotFound; sl@0: sl@0: test.Printf(_L("Searching for data paging drive:\n")); sl@0: sl@0: for(TInt i = 0; i < KMaxLocalDrives && drive < 0; ++i) sl@0: { sl@0: RLocalDrive d; sl@0: TBool change = EFalse; sl@0: sl@0: if(d.Connect(i, change) == KErrNone) sl@0: { sl@0: TLocalDriveCapsV4 dc; sl@0: TPckg capsPack(dc); sl@0: sl@0: if(d.Caps(capsPack) == KErrNone) sl@0: { sl@0: if ((dc.iMediaAtt & KMediaAttPageable) && sl@0: (dc.iPartitionType == KPartitionTypePagedData)) sl@0: { sl@0: test.Printf(_L("Found swap partition on local drive %d\n"), i); sl@0: drive = i; sl@0: sl@0: TPageDeviceInfo pageDeviceInfo; sl@0: sl@0: TPtr8 pageDeviceInfoBuf((TUint8*) &pageDeviceInfo, sizeof(pageDeviceInfo)); sl@0: pageDeviceInfoBuf.FillZ(); sl@0: sl@0: TInt r = d.QueryDevice(RLocalDrive::EQueryPageDeviceInfo, pageDeviceInfoBuf); sl@0: sl@0: test.Printf(_L("EQueryPageDeviceInfo on local drive %d returned %d\n"), i, r); sl@0: } sl@0: } sl@0: d.Close(); sl@0: } sl@0: } sl@0: return drive; sl@0: } sl@0: sl@0: TDes& GetSerialNumber(TLocalDriveCapsV5& aCaps) sl@0: { sl@0: static TBuf16<80> serialNumBuf; sl@0: sl@0: serialNumBuf.SetLength(0); sl@0: sl@0: for (TUint n=0; n hexBuf; sl@0: hexBuf.Format(_L("%02X "), aCaps.iSerialNum[m]); sl@0: serialNumBuf.Append(hexBuf); sl@0: } sl@0: } sl@0: sl@0: return serialNumBuf; sl@0: } sl@0: sl@0: TDes& GetSerialNumber(TMediaSerialNumber& aSerialNum) sl@0: { sl@0: static TBuf16<80> serialNumBuf; sl@0: sl@0: serialNumBuf.SetLength(0); sl@0: sl@0: TInt len = aSerialNum.Length(); sl@0: for (TInt n=0; n hexBuf; sl@0: hexBuf.Format(_L("%02X "), aSerialNum[m]); sl@0: serialNumBuf.Append(hexBuf); sl@0: } sl@0: } sl@0: sl@0: return serialNumBuf; sl@0: } sl@0: sl@0: TPtrC GetMediaType(TMediaType aType) sl@0: { sl@0: switch(aType) sl@0: { sl@0: case EMediaNotPresent: return _L("NotPresent"); sl@0: case EMediaUnknown: return _L("Unknown"); sl@0: case EMediaFloppy: return _L("Floppy"); sl@0: case EMediaHardDisk: return _L("HardDisk"); sl@0: case EMediaCdRom: return _L("CdRom"); sl@0: case EMediaRam: return _L("Ram"); sl@0: case EMediaFlash: return _L("Flash"); sl@0: case EMediaRom: return _L("Rom"); sl@0: case EMediaRemote: return _L("Remote"); sl@0: case EMediaNANDFlash: return _L("NANDFlash"); sl@0: case EMediaRotatingMedia : return _L("RotatingMedia "); sl@0: default:return _L("Unrecognised"); sl@0: } sl@0: } sl@0: sl@0: TPtrC GetFileSystemId(TUint aFileSystemId) sl@0: { sl@0: switch(aFileSystemId) sl@0: { sl@0: case KDriveFileSysFAT: return _L("FAT"); sl@0: case KDriveFileSysROM: return _L("ROM"); sl@0: case KDriveFileSysLFFS: return _L("LFFS"); sl@0: case KDriveFileSysROFS: return _L("ROFS"); sl@0: case KDriveFileNone: return _L("None"); sl@0: default:return _L("Unrecognised"); sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: // Find a drive which contains the swap partition; if this succeeds, find and return the FAT drive on the same media. sl@0: // This isn't fool-proof as it works by comparing media types/drive attributes/media attributes/serial numbers sl@0: TInt FindFatDriveOnDataPagingMedia() sl@0: { sl@0: TInt dataPagingDrive = FindDataPagingDrive(); sl@0: if (dataPagingDrive == KErrNotFound) sl@0: return KErrNotFound; sl@0: sl@0: TInt fatDriveNumber = KErrNotFound; sl@0: sl@0: test.Printf(_L("Finding Fat drive on datapaging media...\n")); sl@0: sl@0: RLocalDrive dpDrive; sl@0: TBool change = EFalse; sl@0: sl@0: TInt r = dpDrive.Connect(dataPagingDrive, change); sl@0: test(r == KErrNone); sl@0: TLocalDriveCapsV5 dpDriveCaps; sl@0: TPckg capsPack(dpDriveCaps); sl@0: r = dpDrive.Caps(capsPack); sl@0: test(r == KErrNone); sl@0: TPtrC8 dpDriveSerialNum(dpDriveCaps.iSerialNum, dpDriveCaps.iSerialNumLength); sl@0: dpDrive.Close(); sl@0: sl@0: TPtrC mediaType = GetMediaType(dpDriveCaps.iType); sl@0: TPtrC fileSystemId = GetFileSystemId(dpDriveCaps.iFileSystemId); sl@0: test.Printf(_L("Swap Drive %2d Type %S DriveAtt 0x%x MediaAtt 0x%x FileSysId %S SerialNum %S\n"), sl@0: dataPagingDrive, &mediaType, dpDriveCaps.iDriveAtt, dpDriveCaps.iMediaAtt, &fileSystemId, &GetSerialNumber(dpDriveCaps)); sl@0: sl@0: // swap partition should be hidden sl@0: test (dpDriveCaps.iDriveAtt & KDriveAttHidden); sl@0: sl@0: // search for a FAT drive on the same media by searching for a drive which has sl@0: // 'similar' drive & media attributes as the the swap drive sl@0: sl@0: dpDriveCaps.iDriveAtt&= KDriveAttMask; sl@0: dpDriveCaps.iMediaAtt&= KMediaAttMask; sl@0: sl@0: for (TInt i = 0; i < KMaxLocalDrives /*&& fatDriveNumber == KErrNotFound*/; ++i) sl@0: { sl@0: RLocalDrive d; sl@0: TBool change = EFalse; sl@0: sl@0: if(d.Connect(i, change) == KErrNone) sl@0: { sl@0: TLocalDriveCapsV5 caps; sl@0: TPckg capsPack(caps); sl@0: sl@0: r = d.Caps(capsPack); sl@0: if (r != KErrNone) sl@0: continue; sl@0: sl@0: TPtrC8 localSerialNum(caps.iSerialNum, caps.iSerialNumLength); sl@0: TPtrC mediaType = GetMediaType(caps.iType); sl@0: TPtrC fileSystemId = GetFileSystemId(caps.iFileSystemId); sl@0: test.Printf(_L("Drive %2d Type %S DriveAtt 0x%x MediaAtt 0x%x FileSysId %S SerialNum %S\n"), sl@0: i, &mediaType, caps.iDriveAtt, caps.iMediaAtt, &fileSystemId, &GetSerialNumber(caps)); sl@0: sl@0: // Turn off bits which may be different sl@0: caps.iDriveAtt&= KDriveAttMask; sl@0: caps.iMediaAtt&= KMediaAttMask; sl@0: sl@0: if ((caps.iType == dpDriveCaps.iType) && sl@0: (caps.iDriveAtt == dpDriveCaps.iDriveAtt) && sl@0: (caps.iMediaAtt == dpDriveCaps.iMediaAtt) && sl@0: (localSerialNum.Compare(dpDriveSerialNum) == 0) && sl@0: (caps.iFileSystemId == KDriveFileSysFAT)) sl@0: { sl@0: if (fatDriveNumber == KErrNotFound) sl@0: fatDriveNumber = i; sl@0: } sl@0: d.Close(); sl@0: } sl@0: } sl@0: sl@0: sl@0: return fatDriveNumber; sl@0: } sl@0: sl@0: sl@0: // Find and return the File Server drive number (0-25) corresponing to the passed local drive number sl@0: // This isn't fool-proof as it works by comparing media types/drive attributes/media attributes/serial numbers sl@0: TInt FindFsDriveNumber(TInt aLocalDriveNumber) sl@0: { sl@0: TInt fsDriveNumber = KErrNotFound; sl@0: sl@0: RLocalDrive dpDrive; sl@0: TBool change = EFalse; sl@0: sl@0: TInt r = dpDrive.Connect(aLocalDriveNumber, change); sl@0: test(r == KErrNone); sl@0: TLocalDriveCapsV5 dpDriveCaps; sl@0: TPckg capsPack(dpDriveCaps); sl@0: r = dpDrive.Caps(capsPack); sl@0: test(r == KErrNone); sl@0: TPtrC8 dpDriveSerialNum(dpDriveCaps.iSerialNum, dpDriveCaps.iSerialNumLength); sl@0: dpDrive.Close(); sl@0: sl@0: dpDriveCaps.iDriveAtt&= KDriveAttMask; sl@0: dpDriveCaps.iMediaAtt&= KMediaAttMask; sl@0: sl@0: RFs fs; sl@0: r = fs.Connect(); sl@0: test(r == KErrNone); sl@0: sl@0: TDriveInfo di; sl@0: sl@0: for (TInt n=0; n cmdline; sl@0: User::CommandLine(cmdline); sl@0: TLex lex(cmdline); sl@0: sl@0: FOREVER sl@0: { sl@0: TPtrC token=lex.NextToken(); sl@0: if(token.Length() != 0) sl@0: { sl@0: if (token == _L("-p")) sl@0: { sl@0: callPasswordRelated = ETrue; sl@0: } sl@0: else sl@0: test.Printf(_L("Unknown argument '%S' was ignored.\n"), &token); sl@0: } sl@0: else sl@0: break; sl@0: sl@0: } sl@0: sl@0: test.Title(); sl@0: TInt r; sl@0: sl@0: test.Start(_L("Verify the global and this process's data paging attributes")); sl@0: test_KErrNone(GetGlobalPolicies()); sl@0: sl@0: if (IsDataPagingSupported()) sl@0: { sl@0: test.Printf(_L("Data paging supported\n")); sl@0: } sl@0: else sl@0: {// The system doesn't support data paging so this process shouldn't be sl@0: // data paged. sl@0: test.Printf(_L("Data paging not supported\n")); sl@0: test_Equal(EFalse, gProcessPaged); sl@0: test.End(); sl@0: return 0; sl@0: } sl@0: sl@0: r = UserHal::PageSizeInBytes(gPageSize); sl@0: test_KErrNone(r); sl@0: sl@0: TInt fatDriveNumber = FindFatDriveOnDataPagingMedia(); sl@0: if (fatDriveNumber == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Could not find FAT partition on data paging media\n")); sl@0: test(0); sl@0: } sl@0: gFsDriveNumber = FindFsDriveNumber(fatDriveNumber); sl@0: if (gFsDriveNumber == KErrNotFound) sl@0: { sl@0: test.Printf(_L("Could not File Server drive\n")); sl@0: test(0); sl@0: } sl@0: sl@0: test.Printf(_L("Found FAT drive on %C: (local drive #%d) on data paging media\n"), 'A'+gFsDriveNumber, fatDriveNumber); sl@0: sl@0: // User::SetDebugMask(0x10000000); //KMMU2 sl@0: // User::SetDebugMask(0x40000000, 1); //KPAGING sl@0: sl@0: test.Next(_L("Create a paged chunk")); sl@0: CreatePagedChunk(KChunkSizeInPages, KClearValue); sl@0: sl@0: test.Next(_L("Chunk created, declare variables")); sl@0: sl@0: __DECLARE_VAR_IN_CHUNK(TBusLocalDrive, &drive) sl@0: TInt driveSize = TestDriveConnectAndCaps(drive, fatDriveNumber); sl@0: sl@0: TestDriveSizeRelatedMethods(drive, 0x00001000, driveSize); sl@0: sl@0: TestWriteReadRelatedMethods(drive); sl@0: sl@0: TestFormatRelatedMethods(drive, driveSize); sl@0: sl@0: if(callPasswordRelated) sl@0: { sl@0: TestPasswordRelatedMethods(drive); sl@0: } sl@0: sl@0: //Disconnect drive sl@0: test.Next(_L("call aDrive.Disconnect()...")); sl@0: DPTest::FlushCache(); sl@0: drive.Disconnect(); sl@0: sl@0: gMyChunk.Close(); sl@0: sl@0: RestoreDriveState(); sl@0: sl@0: test.End(); sl@0: sl@0: User::SetDebugMask(0x00000000); // No debug info sl@0: User::SetDebugMask(0x00000000, 1); //No KPAGING sl@0: return 0; sl@0: }