1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/demandpaging/t_tbus_datapaging.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,822 @@
1.4 +// Copyright (c) 2008-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\demandpaging\t_tbus_datapaging.cpp
1.18 +// Functional tests for data paging.
1.19 +// 002 ???
1.20 +// 003 ???
1.21 +//
1.22 +
1.23 +//! @SYMTestCaseID KBASE-T_TBUS_DATAPAGING
1.24 +//! @SYMTestType UT
1.25 +//! @SYMPREQ ???
1.26 +//! @SYMTestCaseDesc Data Paging functional tests with TBusLocalDrive.
1.27 +//! @SYMTestActions 001 ???
1.28 +//! @SYMTestExpectedResults All tests should pass.
1.29 +//! @SYMTestPriority High
1.30 +//! @SYMTestStatus Implementation on-going
1.31 +
1.32 +#define __E32TEST_EXTENSION__
1.33 +#include <e32test.h>
1.34 +#include <dptest.h>
1.35 +#include <e32hal.h>
1.36 +#include <u32exec.h>
1.37 +#include <e32svr.h>
1.38 +#include <e32panic.h>
1.39 +#include "u32std.h"
1.40 +
1.41 +#include <f32file.h>
1.42 +#include <f32dbg.h>
1.43 +#include <f32fsys.h>
1.44 +
1.45 +#include "t_dpcmn.h"
1.46 +#include "../secure/d_sldd.h"
1.47 +#include "../mmu/mmudetect.h"
1.48 +
1.49 +const TInt KMaxLengthOfStoreMapping = 16 + sizeof(TInt32) + KMaxMediaPassword;
1.50 +const TInt KMaxPersistentStore(TPasswordStore::EMaxPasswordLength+KMaxLengthOfStoreMapping);
1.51 +typedef TBuf8<KMaxPersistentStore> TPersistentStore;
1.52 +
1.53 +RChunk gMyChunk;
1.54 +TUint gOffset = 0;
1.55 +TUint8* gData = NULL;
1.56 +const TUint8 KClearValue = 0xed;
1.57 +const TUint KChunkSizeInPages = 64; // 64 * 4096 = 256K
1.58 +const TInt KTestBufLen=256;
1.59 +
1.60 +
1.61 +#define __DECLARE_VAR_IN_CHUNK(type, varRef) \
1.62 + type varRef = *(type*) (gData+gOffset); \
1.63 + gOffset += Max(gPageSize, sizeof(type)); \
1.64 + test(gOffset <= gPageSize * KChunkSizeInPages);
1.65 +
1.66 +#define __DECLARE_AND_INIT_VAR_IN_CHUNK(type, var) \
1.67 + type &var = *(type*) (gData+gOffset); \
1.68 + var = type(); \
1.69 + gOffset += Max(gPageSize, sizeof(type)); \
1.70 + test(gOffset <= gPageSize * KChunkSizeInPages);
1.71 +
1.72 +
1.73 +#define __DECLARE_ARRAY_IN_CHUNK(type, var, size) \
1.74 + type *var = (type*) (gData+gOffset); \
1.75 + gOffset += Max(gPageSize, (sizeof(type) * size)); \
1.76 + test(gOffset <= gPageSize * KChunkSizeInPages);
1.77 +
1.78 +#define __FLUSH_AND_CALL_API_METHOD(return, function) \
1.79 + DPTest::FlushCache(); \
1.80 + return = function;
1.81 +
1.82 +
1.83 +LOCAL_D RFs TheFs;
1.84 +TInt gFsDriveNumber = -1;
1.85 +
1.86 +RTest test(_L("T_TBUS_DATAPAGING"));
1.87 +_LIT(KChunkName, "t_datapaging chunk");
1.88 +
1.89 +const TUint KDriveAttMask = KDriveAttLocal | KDriveAttRom | KDriveAttRemote;
1.90 +const TUint KMediaAttMask = KMediaAttVariableSize | KMediaAttDualDensity | KMediaAttLockable | KMediaAttLocked | KMediaAttHasPassword | KMediaAttReadWhileWrite;
1.91 +
1.92 +void CreatePagedChunk(TInt aSizeInPages, TInt aWipeByte = -1)
1.93 + {
1.94 + test_Equal(0,gMyChunk.Handle());
1.95 +
1.96 + TChunkCreateInfo createInfo;
1.97 + TInt size = aSizeInPages * gPageSize;
1.98 + createInfo.SetNormal(size, size);
1.99 + createInfo.SetPaging(TChunkCreateInfo::EPaged);
1.100 + createInfo.SetOwner(EOwnerProcess);
1.101 + createInfo.SetGlobal(KChunkName);
1.102 + if (aWipeByte != -1)
1.103 + createInfo.SetClearByte(aWipeByte);
1.104 + test_KErrNone(gMyChunk.Create(createInfo));
1.105 + test(gMyChunk.IsPaged()); // this is only ever called if data paging is supported
1.106 +
1.107 + gData = gMyChunk.Base();
1.108 + }
1.109 +
1.110 +TInt TestDriveConnectAndCaps(TBusLocalDrive &aDrive, TInt &aLocalDriveNumber)
1.111 + {
1.112 +
1.113 + test.Next(_L("Test Drive Connect And Caps"));
1.114 +
1.115 + __DECLARE_VAR_IN_CHUNK(TInt, &r);
1.116 +
1.117 + test.Printf(_L("changeFlag...\n"));
1.118 + __DECLARE_VAR_IN_CHUNK(TBool, &changeFlag);
1.119 + changeFlag = EFalse;
1.120 +
1.121 + test.Printf(_L("call aDrive.Connect()...\n"));
1.122 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.Connect(aLocalDriveNumber,changeFlag));
1.123 +
1.124 + test.Printf(_L("r:%d\n"),r);
1.125 + test_Equal(KErrNone, r);
1.126 +
1.127 + test.Printf(_L("call aDrive.Caps()...\n"));
1.128 + __DECLARE_VAR_IN_CHUNK(TLocalDriveCapsV5, &driveCaps);
1.129 +
1.130 + TPckg<TLocalDriveCapsV5> capsPckg(driveCaps);
1.131 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.Caps(capsPckg));
1.132 +
1.133 + test_Equal(KErrNone, r);
1.134 + test.Printf(_L("r:%d\n"),r);
1.135 + test.Printf(_L("driveCaps.iDriveAtt :0x%08x\n"), driveCaps.iDriveAtt);
1.136 + test.Printf(_L("driveCaps.iSize :%ld\n"), driveCaps.iSize);
1.137 + test.Printf(_L("driveCaps.iSerialNumLength :%d\n"), driveCaps.iSerialNumLength);
1.138 +
1.139 + return I64LOW(driveCaps.iSize);
1.140 + }
1.141 +
1.142 +void TestDriveSizeRelatedMethods(TBusLocalDrive &aDrive, TInt aNewSize, TInt aOldSize)
1.143 + {
1.144 + TInt r;
1.145 +
1.146 + test.Next(_L("Test Drive Size Related Methods"));
1.147 + test.Printf(_L("newDriveSize...\n"));
1.148 + __DECLARE_VAR_IN_CHUNK(TInt, &newDriveSize);
1.149 + newDriveSize = aNewSize;
1.150 +
1.151 + test.Printf(_L("call aDrive.Enlarge()...\n"));
1.152 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.Enlarge(newDriveSize));
1.153 + test.Printf(_L("r:%d\n"),r);
1.154 + test((KErrNone == r) || (KErrNotSupported == r) || (KErrNotReady == r));
1.155 + if(r != KErrNone )
1.156 + {
1.157 + test.Printf(_L("errInfo...\n"));
1.158 + __DECLARE_ARRAY_IN_CHUNK(TUint8, errInfo, KTestBufLen);
1.159 +
1.160 + TPtr8 pErrInfoBuff(errInfo, KTestBufLen);
1.161 +
1.162 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.GetLastErrorInfo(pErrInfoBuff));
1.163 + test.Printf(_L("r:%d\n"),r);
1.164 + test((KErrNone == r) || (KErrNotSupported == r));
1.165 + }
1.166 +
1.167 +
1.168 + test.Printf(_L("call aDrive.ReduceSize()...\n"));
1.169 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.ReduceSize(0, aOldSize));
1.170 + test((KErrNone == r) || (KErrNotSupported == r) || (KErrNotReady == r));
1.171 +
1.172 + }
1.173 +
1.174 +void TestWriteReadRelatedMethods(TBusLocalDrive &aDrive)
1.175 + {
1.176 +
1.177 + test.Next(_L("Test Write & Read Related Methods"));
1.178 +
1.179 + __DECLARE_VAR_IN_CHUNK(TInt, &r);
1.180 +
1.181 + test.Printf(_L("msgHandle...\n"));
1.182 + __DECLARE_VAR_IN_CHUNK(TInt, &msgHandle);
1.183 + msgHandle = KLocalMessageHandle;
1.184 +
1.185 +
1.186 + __DECLARE_VAR_IN_CHUNK(TUint, &i);
1.187 + test.Printf(_L("wrBuf...\n"));
1.188 + TBuf8<KTestBufLen> wrBuf(KTestBufLen);
1.189 + for (i=0 ; i<(TUint)KTestBufLen ; i++)
1.190 + wrBuf[i]=(TUint8)i;
1.191 +
1.192 +
1.193 + test.Printf(_L("wrBuf2...\n"));
1.194 + __DECLARE_ARRAY_IN_CHUNK(TUint8, wrBuf2, KTestBufLen);
1.195 +
1.196 + test.Printf(_L("fill wrBuf2...\n"));
1.197 + for (i=0 ; i<(TUint)KTestBufLen ; i++)
1.198 + wrBuf2[i]=(TUint8)i;
1.199 +
1.200 + TPtr8 pWrBuf2(wrBuf2, KTestBufLen, KTestBufLen);
1.201 +
1.202 + test.Printf(_L("rdBuf...\n"));
1.203 + TBuf8<KTestBufLen> rdBuf(KTestBufLen);
1.204 +
1.205 +
1.206 + test.Printf(_L("rdBuf2...\n"));
1.207 + __DECLARE_ARRAY_IN_CHUNK(TUint8, rdBuf2, KTestBufLen);
1.208 +
1.209 + TPtr8 pRdBuf2(rdBuf2, KTestBufLen);
1.210 +
1.211 + test.Printf(_L("call aDrive.Write()...\n"));
1.212 + rdBuf.Fill(0,KTestBufLen);
1.213 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.Write(0,KTestBufLen,&wrBuf,msgHandle,0));
1.214 + test_Equal(KErrNone, r);
1.215 +
1.216 +
1.217 + test.Printf(_L("call aDrive.Read()...\n"));
1.218 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.Read(0,KTestBufLen,&rdBuf,msgHandle,0));
1.219 + test_Equal(KErrNone, r);
1.220 +
1.221 + for (i=0 ; i<(TUint)KTestBufLen ; i++)
1.222 + test_Equal(wrBuf[i], rdBuf[i]);
1.223 +
1.224 + test.Printf(_L("call aDrive.Write()...\n"));
1.225 + pRdBuf2.Fill(0,KTestBufLen);
1.226 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.Write(0,pWrBuf2));
1.227 + test_Equal(KErrNone, r);
1.228 +
1.229 +
1.230 + test.Printf(_L("call aDrive.Read()...\n"));
1.231 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.Read(0,KTestBufLen, pRdBuf2));
1.232 + test_Equal(KErrNone, r);
1.233 +
1.234 + for (i=0 ; i<(TUint)KTestBufLen ; i++)
1.235 + test_Equal(wrBuf2[i], rdBuf2[i]);
1.236 +
1.237 + }
1.238 +
1.239 +void TestPasswordRelatedMethods(TBusLocalDrive &aDrive)
1.240 + {
1.241 + TInt r;
1.242 +
1.243 + test.Next(_L("Test Password Related Methods"));
1.244 + //__DECLARE_VAR_IN_CHUNK(TPersistentStore, &wStore);
1.245 +
1.246 + TPersistentStore* pstoreAB;
1.247 + test((pstoreAB = new TPersistentStore) != 0);
1.248 + TPersistentStore& wStore = *pstoreAB;
1.249 +
1.250 + //__DECLARE_AND_INIT_VAR_IN_CHUNK(TPersistentStore, wStore);
1.251 +
1.252 + // Password related API methods call
1.253 + test.Printf(_L("call aDrive.WritePasswordData() to clear passwords...\n"));
1.254 + __DECLARE_VAR_IN_CHUNK(TInt, &passwordStoreLength);
1.255 +
1.256 + TBuf8<1> nulSt;
1.257 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.WritePasswordData(nulSt));
1.258 + test( r == KErrNone);// empty
1.259 +
1.260 + test.Printf(_L("call aDrive.PasswordStoreLengthInBytes()...\n"));
1.261 + __FLUSH_AND_CALL_API_METHOD(passwordStoreLength, aDrive.PasswordStoreLengthInBytes());
1.262 +
1.263 + test.Printf(_L("passwordStoreLength:%d\n"), passwordStoreLength);
1.264 + test_Equal(0, passwordStoreLength);
1.265 +
1.266 +
1.267 + test.Printf(_L("call aDrive.ErasePassword()...\n"));
1.268 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.ErasePassword());
1.269 + test.Printf(_L("r:%d\n"),r);
1.270 +
1.271 +
1.272 + test.Printf(_L("wStore.Size():%d\n"),wStore.Size());
1.273 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.WritePasswordData(wStore));
1.274 +
1.275 + test.Printf(_L("r:%d\n"),r);
1.276 + test((KErrNone == r)); // || (KErrCorrupt == r)); // TO-DO Why Corrupt???
1.277 +
1.278 + __FLUSH_AND_CALL_API_METHOD(passwordStoreLength, aDrive.PasswordStoreLengthInBytes());
1.279 +
1.280 + test.Printf(_L("passwordStoreLength:%d\n"), passwordStoreLength);
1.281 + test((r == KErrNone ? (wStore.Size() == passwordStoreLength) : (0 == passwordStoreLength) ));
1.282 +
1.283 +
1.284 +
1.285 + test.Printf(_L("Set and store a password...\n"));
1.286 + TDes8 &st = wStore;
1.287 + TMediaPassword a((const TUint8*) "CID0ccccccccccc#");
1.288 + TUint8 passLen[sizeof(TInt32)];
1.289 + passLen[0] = 0;
1.290 + passLen[1] = 0;
1.291 + passLen[2] = 0;
1.292 + passLen[3] = 16;
1.293 +
1.294 + //test.Printf(_L("Password3:'%S'\n"), &a);
1.295 +
1.296 + st.Append(a);
1.297 + st.Append(passLen, sizeof(TInt32));
1.298 + st.Append(a);
1.299 +
1.300 + test.Printf(_L("wStore.Size():%d\n"),wStore.Size());
1.301 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.WritePasswordData(wStore));
1.302 +
1.303 + test.Printf(_L("r:%d\n"),r);
1.304 + test((KErrNone == r));
1.305 +
1.306 + __FLUSH_AND_CALL_API_METHOD(passwordStoreLength, aDrive.PasswordStoreLengthInBytes());
1.307 +
1.308 + test.Printf(_L("passwordStoreLength:%d\n"), passwordStoreLength);
1.309 + test((r == KErrNone ? (wStore.Size() == passwordStoreLength) : (0 == passwordStoreLength) ));
1.310 +
1.311 + test.Printf(_L("call aDrive.ErasePassword()...\n"));
1.312 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.ErasePassword());
1.313 + test.Printf(_L("r:%d\n"),r);
1.314 +
1.315 + test.Printf(_L("call aDrive.WritePasswordData() to set password again...\n"));
1.316 + test.Printf(_L("wStore.Size():%d\n"),wStore.Size());
1.317 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.WritePasswordData(wStore));
1.318 +
1.319 + test.Printf(_L("r:%d\n"),r);
1.320 + test((KErrNone == r));
1.321 +
1.322 + __FLUSH_AND_CALL_API_METHOD(passwordStoreLength, aDrive.PasswordStoreLengthInBytes());
1.323 +
1.324 + test.Printf(_L("passwordStoreLength:%d\n"), passwordStoreLength);
1.325 + test((r == KErrNone ? (wStore.Size() == passwordStoreLength) : (0 == passwordStoreLength) ));
1.326 +
1.327 +
1.328 + // Finally erase password
1.329 + test.Printf(_L("call aDrive.WritePasswordData() to erase password...\n"));
1.330 + wStore.Zero(); // empty password store
1.331 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.WritePasswordData(wStore))
1.332 + test( r == KErrNone);// Clear
1.333 +
1.334 + __FLUSH_AND_CALL_API_METHOD(passwordStoreLength, aDrive.PasswordStoreLengthInBytes());
1.335 +
1.336 + test.Printf(_L("passwordStoreLength:%d\n"), passwordStoreLength);
1.337 + test((r == KErrNone ? (wStore.Size() == passwordStoreLength) : (0 == passwordStoreLength) ));
1.338 +
1.339 +
1.340 +
1.341 + // Test SetPassword
1.342 + TMediaPassword nul(nulSt);
1.343 +
1.344 + test.Printf(_L("call aDrive.SetPassword()...\n"));
1.345 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.SetPassword(nul, a, EFalse));
1.346 + test.Printf(_L("r:%d\n"),r);
1.347 + test_Equal(KErrNone, r);
1.348 +
1.349 + // Erase Password
1.350 + test.Printf(_L("call aDrive.ErasePassword()...\n"));
1.351 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.ErasePassword());
1.352 + test.Printf(_L("r:%d\n"),r);
1.353 +
1.354 +
1.355 + test.Printf(_L("call aDrive.SetPassword()...\n"));
1.356 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.SetPassword(nul, a, EFalse));
1.357 + test.Printf(_L("r:%d\n"),r);
1.358 + test_Equal(KErrNone, r);
1.359 +
1.360 + // Erase Clear
1.361 + test.Printf(_L("call aDrive.Clear()...\n"));
1.362 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.Clear(a));
1.363 + test.Printf(_L("r:%d\n"),r);
1.364 +
1.365 +
1.366 + test.Printf(_L("call aDrive.SetPassword() to clear again...\n"));
1.367 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.SetPassword(a, nul, EFalse));
1.368 + test.Printf(_L("r:%d\n"),r);
1.369 + test_Equal(KErrAccessDenied, r);
1.370 +
1.371 +
1.372 + // Finally erase password
1.373 + test.Printf(_L("call aDrive.WritePasswordData() to erase password...\n"));
1.374 + wStore.Zero(); // empty password store
1.375 + __FLUSH_AND_CALL_API_METHOD(r, aDrive.WritePasswordData(wStore))
1.376 + test( r == KErrNone);// Clear
1.377 +
1.378 + __FLUSH_AND_CALL_API_METHOD(passwordStoreLength, aDrive.PasswordStoreLengthInBytes());
1.379 +
1.380 + test.Printf(_L("passwordStoreLength:%d\n"), passwordStoreLength);
1.381 + test((r == KErrNone ? (wStore.Size() == passwordStoreLength) : (0 == passwordStoreLength) ));
1.382 +
1.383 + }
1.384 +
1.385 +void TestFormatRelatedMethods(TBusLocalDrive &aDrive, TInt aSize )
1.386 + {
1.387 + test.Next(_L("Test Format Related Methods"));
1.388 +
1.389 + test.Printf(_L("call aDrive.Format(TFormatInfo)...\n"));
1.390 + __DECLARE_AND_INIT_VAR_IN_CHUNK(TFormatInfo, fi);
1.391 + __DECLARE_VAR_IN_CHUNK(TInt, &ret);
1.392 + __DECLARE_VAR_IN_CHUNK(TInt, &attempt);
1.393 +
1.394 + __FLUSH_AND_CALL_API_METHOD(ret, aDrive.Format(fi));
1.395 + test.Printf(_L("ret:%d\n"),ret);
1.396 + while(ret!=KErrEof)
1.397 + {
1.398 + if( ret == KErrNotReady )
1.399 + {
1.400 + attempt = 100;
1.401 + while( (ret= aDrive.Format(fi)) == KErrNotReady && --attempt)
1.402 + {
1.403 + test.Printf(_L("attempt:%d\n"),attempt);
1.404 + User::After(1000000);
1.405 + }
1.406 + test(attempt);
1.407 + }
1.408 + else
1.409 + {
1.410 + test(ret==KErrNone);
1.411 + ret= aDrive.Format(fi);
1.412 + }
1.413 + }
1.414 +
1.415 +
1.416 + test.Printf(_L("call aDrive.Format(pos, length)...\n"));
1.417 + User::After(1000000);
1.418 +
1.419 + __DECLARE_VAR_IN_CHUNK(TInt64, &pos);
1.420 + pos = 0;
1.421 + __DECLARE_VAR_IN_CHUNK(TInt, &length);
1.422 + length = aSize;
1.423 +
1.424 + attempt = 100;
1.425 + __FLUSH_AND_CALL_API_METHOD(ret, aDrive.Format(pos, length));
1.426 + while( ret == KErrNotReady && --attempt)
1.427 + {
1.428 + User::After(1000000);
1.429 + ret= aDrive.Format(pos, length);
1.430 + }
1.431 + test(attempt);
1.432 + test_Equal(KErrNone, ret);
1.433 +
1.434 + test.Printf(_L("End of TestFormatRelatedMethods)...\n"));
1.435 + }
1.436 +
1.437 +void RestoreDriveState(void)
1.438 + {
1.439 + TBuf<3> bfDrv;
1.440 +
1.441 + const TText KDrvLtr = 'A' + gFsDriveNumber;
1.442 +
1.443 + bfDrv.Append(KDrvLtr);
1.444 + _LIT(KBP, ":\\");
1.445 + bfDrv.Append(KBP);
1.446 +
1.447 +
1.448 + TheFs.Connect();
1.449 + RFormat fmt;
1.450 + TInt count;
1.451 +
1.452 + test(fmt.Open(TheFs, bfDrv, EHighDensity, count) == KErrNone);
1.453 + while (count > 0)
1.454 + {
1.455 + test.Printf(_L("\rfmt:%d "), count);
1.456 + test(fmt.Next(count) == KErrNone);
1.457 + }
1.458 + test.Printf(_L("\n"));
1.459 + fmt.Close();
1.460 +
1.461 + TheFs.Close();
1.462 + }
1.463 +
1.464 +
1.465 +TInt FindDataPagingDrive()
1.466 +/**
1.467 +Find the drive containing a swap partition.
1.468 +
1.469 +@return Local drive identifier.
1.470 +*/
1.471 + {
1.472 + TInt drive = KErrNotFound;
1.473 +
1.474 + test.Printf(_L("Searching for data paging drive:\n"));
1.475 +
1.476 + for(TInt i = 0; i < KMaxLocalDrives && drive < 0; ++i)
1.477 + {
1.478 + RLocalDrive d;
1.479 + TBool change = EFalse;
1.480 +
1.481 + if(d.Connect(i, change) == KErrNone)
1.482 + {
1.483 + TLocalDriveCapsV4 dc;
1.484 + TPckg<TLocalDriveCapsV4> capsPack(dc);
1.485 +
1.486 + if(d.Caps(capsPack) == KErrNone)
1.487 + {
1.488 + if ((dc.iMediaAtt & KMediaAttPageable) &&
1.489 + (dc.iPartitionType == KPartitionTypePagedData))
1.490 + {
1.491 + test.Printf(_L("Found swap partition on local drive %d\n"), i);
1.492 + drive = i;
1.493 +
1.494 + TPageDeviceInfo pageDeviceInfo;
1.495 +
1.496 + TPtr8 pageDeviceInfoBuf((TUint8*) &pageDeviceInfo, sizeof(pageDeviceInfo));
1.497 + pageDeviceInfoBuf.FillZ();
1.498 +
1.499 + TInt r = d.QueryDevice(RLocalDrive::EQueryPageDeviceInfo, pageDeviceInfoBuf);
1.500 +
1.501 + test.Printf(_L("EQueryPageDeviceInfo on local drive %d returned %d\n"), i, r);
1.502 + }
1.503 + }
1.504 + d.Close();
1.505 + }
1.506 + }
1.507 + return drive;
1.508 + }
1.509 +
1.510 +TDes& GetSerialNumber(TLocalDriveCapsV5& aCaps)
1.511 + {
1.512 + static TBuf16<80> serialNumBuf;
1.513 +
1.514 + serialNumBuf.SetLength(0);
1.515 +
1.516 + for (TUint n=0; n<aCaps.iSerialNumLength; n+=16)
1.517 + {
1.518 + for (TUint m=n; m<n+16; m++)
1.519 + {
1.520 + TBuf16<3> hexBuf;
1.521 + hexBuf.Format(_L("%02X "), aCaps.iSerialNum[m]);
1.522 + serialNumBuf.Append(hexBuf);
1.523 + }
1.524 + }
1.525 +
1.526 + return serialNumBuf;
1.527 + }
1.528 +
1.529 +TDes& GetSerialNumber(TMediaSerialNumber& aSerialNum)
1.530 + {
1.531 + static TBuf16<80> serialNumBuf;
1.532 +
1.533 + serialNumBuf.SetLength(0);
1.534 +
1.535 + TInt len = aSerialNum.Length();
1.536 + for (TInt n=0; n<len; n+=16)
1.537 + {
1.538 + for (TInt m=n; m<n+16; m++)
1.539 + {
1.540 + TBuf16<3> hexBuf;
1.541 + hexBuf.Format(_L("%02X "), aSerialNum[m]);
1.542 + serialNumBuf.Append(hexBuf);
1.543 + }
1.544 + }
1.545 +
1.546 + return serialNumBuf;
1.547 + }
1.548 +
1.549 +TPtrC GetMediaType(TMediaType aType)
1.550 + {
1.551 + switch(aType)
1.552 + {
1.553 + case EMediaNotPresent: return _L("NotPresent");
1.554 + case EMediaUnknown: return _L("Unknown");
1.555 + case EMediaFloppy: return _L("Floppy");
1.556 + case EMediaHardDisk: return _L("HardDisk");
1.557 + case EMediaCdRom: return _L("CdRom");
1.558 + case EMediaRam: return _L("Ram");
1.559 + case EMediaFlash: return _L("Flash");
1.560 + case EMediaRom: return _L("Rom");
1.561 + case EMediaRemote: return _L("Remote");
1.562 + case EMediaNANDFlash: return _L("NANDFlash");
1.563 + case EMediaRotatingMedia : return _L("RotatingMedia ");
1.564 + default:return _L("Unrecognised");
1.565 + }
1.566 + }
1.567 +
1.568 +TPtrC GetFileSystemId(TUint aFileSystemId)
1.569 + {
1.570 + switch(aFileSystemId)
1.571 + {
1.572 + case KDriveFileSysFAT: return _L("FAT");
1.573 + case KDriveFileSysROM: return _L("ROM");
1.574 + case KDriveFileSysLFFS: return _L("LFFS");
1.575 + case KDriveFileSysROFS: return _L("ROFS");
1.576 + case KDriveFileNone: return _L("None");
1.577 + default:return _L("Unrecognised");
1.578 + }
1.579 + }
1.580 +
1.581 +
1.582 +
1.583 +// Find a drive which contains the swap partition; if this succeeds, find and return the FAT drive on the same media.
1.584 +// This isn't fool-proof as it works by comparing media types/drive attributes/media attributes/serial numbers
1.585 +TInt FindFatDriveOnDataPagingMedia()
1.586 + {
1.587 + TInt dataPagingDrive = FindDataPagingDrive();
1.588 + if (dataPagingDrive == KErrNotFound)
1.589 + return KErrNotFound;
1.590 +
1.591 + TInt fatDriveNumber = KErrNotFound;
1.592 +
1.593 + test.Printf(_L("Finding Fat drive on datapaging media...\n"));
1.594 +
1.595 + RLocalDrive dpDrive;
1.596 + TBool change = EFalse;
1.597 +
1.598 + TInt r = dpDrive.Connect(dataPagingDrive, change);
1.599 + test(r == KErrNone);
1.600 + TLocalDriveCapsV5 dpDriveCaps;
1.601 + TPckg<TLocalDriveCapsV5> capsPack(dpDriveCaps);
1.602 + r = dpDrive.Caps(capsPack);
1.603 + test(r == KErrNone);
1.604 + TPtrC8 dpDriveSerialNum(dpDriveCaps.iSerialNum, dpDriveCaps.iSerialNumLength);
1.605 + dpDrive.Close();
1.606 +
1.607 + TPtrC mediaType = GetMediaType(dpDriveCaps.iType);
1.608 + TPtrC fileSystemId = GetFileSystemId(dpDriveCaps.iFileSystemId);
1.609 + test.Printf(_L("Swap Drive %2d Type %S DriveAtt 0x%x MediaAtt 0x%x FileSysId %S SerialNum %S\n"),
1.610 + dataPagingDrive, &mediaType, dpDriveCaps.iDriveAtt, dpDriveCaps.iMediaAtt, &fileSystemId, &GetSerialNumber(dpDriveCaps));
1.611 +
1.612 + // swap partition should be hidden
1.613 + test (dpDriveCaps.iDriveAtt & KDriveAttHidden);
1.614 +
1.615 + // search for a FAT drive on the same media by searching for a drive which has
1.616 + // 'similar' drive & media attributes as the the swap drive
1.617 +
1.618 + dpDriveCaps.iDriveAtt&= KDriveAttMask;
1.619 + dpDriveCaps.iMediaAtt&= KMediaAttMask;
1.620 +
1.621 + for (TInt i = 0; i < KMaxLocalDrives /*&& fatDriveNumber == KErrNotFound*/; ++i)
1.622 + {
1.623 + RLocalDrive d;
1.624 + TBool change = EFalse;
1.625 +
1.626 + if(d.Connect(i, change) == KErrNone)
1.627 + {
1.628 + TLocalDriveCapsV5 caps;
1.629 + TPckg<TLocalDriveCapsV5> capsPack(caps);
1.630 +
1.631 + r = d.Caps(capsPack);
1.632 + if (r != KErrNone)
1.633 + continue;
1.634 +
1.635 + TPtrC8 localSerialNum(caps.iSerialNum, caps.iSerialNumLength);
1.636 + TPtrC mediaType = GetMediaType(caps.iType);
1.637 + TPtrC fileSystemId = GetFileSystemId(caps.iFileSystemId);
1.638 + test.Printf(_L("Drive %2d Type %S DriveAtt 0x%x MediaAtt 0x%x FileSysId %S SerialNum %S\n"),
1.639 + i, &mediaType, caps.iDriveAtt, caps.iMediaAtt, &fileSystemId, &GetSerialNumber(caps));
1.640 +
1.641 + // Turn off bits which may be different
1.642 + caps.iDriveAtt&= KDriveAttMask;
1.643 + caps.iMediaAtt&= KMediaAttMask;
1.644 +
1.645 + if ((caps.iType == dpDriveCaps.iType) &&
1.646 + (caps.iDriveAtt == dpDriveCaps.iDriveAtt) &&
1.647 + (caps.iMediaAtt == dpDriveCaps.iMediaAtt) &&
1.648 + (localSerialNum.Compare(dpDriveSerialNum) == 0) &&
1.649 + (caps.iFileSystemId == KDriveFileSysFAT))
1.650 + {
1.651 + if (fatDriveNumber == KErrNotFound)
1.652 + fatDriveNumber = i;
1.653 + }
1.654 + d.Close();
1.655 + }
1.656 + }
1.657 +
1.658 +
1.659 + return fatDriveNumber;
1.660 + }
1.661 +
1.662 +
1.663 +// Find and return the File Server drive number (0-25) corresponing to the passed local drive number
1.664 +// This isn't fool-proof as it works by comparing media types/drive attributes/media attributes/serial numbers
1.665 +TInt FindFsDriveNumber(TInt aLocalDriveNumber)
1.666 + {
1.667 + TInt fsDriveNumber = KErrNotFound;
1.668 +
1.669 + RLocalDrive dpDrive;
1.670 + TBool change = EFalse;
1.671 +
1.672 + TInt r = dpDrive.Connect(aLocalDriveNumber, change);
1.673 + test(r == KErrNone);
1.674 + TLocalDriveCapsV5 dpDriveCaps;
1.675 + TPckg<TLocalDriveCapsV5> capsPack(dpDriveCaps);
1.676 + r = dpDrive.Caps(capsPack);
1.677 + test(r == KErrNone);
1.678 + TPtrC8 dpDriveSerialNum(dpDriveCaps.iSerialNum, dpDriveCaps.iSerialNumLength);
1.679 + dpDrive.Close();
1.680 +
1.681 + dpDriveCaps.iDriveAtt&= KDriveAttMask;
1.682 + dpDriveCaps.iMediaAtt&= KMediaAttMask;
1.683 +
1.684 + RFs fs;
1.685 + r = fs.Connect();
1.686 + test(r == KErrNone);
1.687 +
1.688 + TDriveInfo di;
1.689 +
1.690 + for (TInt n=0; n<KMaxDrives /* && fsDriveNumber == KErrNotFound*/; n++)
1.691 + {
1.692 + r = fs.Drive(di, n);
1.693 +
1.694 + TMediaSerialNumber serialNum;
1.695 + fs.GetMediaSerialNumber(serialNum, n);
1.696 +
1.697 + TFSName fsName;
1.698 + fs.FileSystemName(fsName, n);
1.699 +
1.700 + if (r != KErrNone )
1.701 + continue;
1.702 +
1.703 + TPtrC mediaType = GetMediaType(di.iType);
1.704 + test.Printf(_L("Drive %C Type %S DriveAtt 0x%x MediaAtt 0x%x FileSysId %S SerialNum %S\n"),
1.705 + 'A' + n, &mediaType, di.iDriveAtt, di.iMediaAtt, &fsName, &GetSerialNumber(serialNum));
1.706 +
1.707 + di.iDriveAtt&= KDriveAttMask;
1.708 + di.iMediaAtt&= KMediaAttMask;
1.709 +
1.710 + if ((di.iType == dpDriveCaps.iType) &&
1.711 + (di.iDriveAtt == dpDriveCaps.iDriveAtt) &&
1.712 + (di.iMediaAtt == dpDriveCaps.iMediaAtt) &&
1.713 + (serialNum.Compare(dpDriveSerialNum) == 0))
1.714 + {
1.715 + if (fsDriveNumber == KErrNotFound)
1.716 + fsDriveNumber = n;
1.717 + }
1.718 + }
1.719 +
1.720 + fs.Close();
1.721 +
1.722 + return fsDriveNumber;
1.723 + }
1.724 +
1.725 +TInt E32Main()
1.726 + {
1.727 +
1.728 + // To use in command line
1.729 + TBool callPasswordRelated = EFalse;
1.730 +
1.731 + TBuf<256> cmdline;
1.732 + User::CommandLine(cmdline);
1.733 + TLex lex(cmdline);
1.734 +
1.735 + FOREVER
1.736 + {
1.737 + TPtrC token=lex.NextToken();
1.738 + if(token.Length() != 0)
1.739 + {
1.740 + if (token == _L("-p"))
1.741 + {
1.742 + callPasswordRelated = ETrue;
1.743 + }
1.744 + else
1.745 + test.Printf(_L("Unknown argument '%S' was ignored.\n"), &token);
1.746 + }
1.747 + else
1.748 + break;
1.749 +
1.750 + }
1.751 +
1.752 + test.Title();
1.753 + TInt r;
1.754 +
1.755 + test.Start(_L("Verify the global and this process's data paging attributes"));
1.756 + test_KErrNone(GetGlobalPolicies());
1.757 +
1.758 + if (IsDataPagingSupported())
1.759 + {
1.760 + test.Printf(_L("Data paging supported\n"));
1.761 + }
1.762 + else
1.763 + {// The system doesn't support data paging so this process shouldn't be
1.764 + // data paged.
1.765 + test.Printf(_L("Data paging not supported\n"));
1.766 + test_Equal(EFalse, gProcessPaged);
1.767 + test.End();
1.768 + return 0;
1.769 + }
1.770 +
1.771 + r = UserHal::PageSizeInBytes(gPageSize);
1.772 + test_KErrNone(r);
1.773 +
1.774 + TInt fatDriveNumber = FindFatDriveOnDataPagingMedia();
1.775 + if (fatDriveNumber == KErrNotFound)
1.776 + {
1.777 + test.Printf(_L("Could not find FAT partition on data paging media\n"));
1.778 + test(0);
1.779 + }
1.780 + gFsDriveNumber = FindFsDriveNumber(fatDriveNumber);
1.781 + if (gFsDriveNumber == KErrNotFound)
1.782 + {
1.783 + test.Printf(_L("Could not File Server drive\n"));
1.784 + test(0);
1.785 + }
1.786 +
1.787 + test.Printf(_L("Found FAT drive on %C: (local drive #%d) on data paging media\n"), 'A'+gFsDriveNumber, fatDriveNumber);
1.788 +
1.789 +// User::SetDebugMask(0x10000000); //KMMU2
1.790 +// User::SetDebugMask(0x40000000, 1); //KPAGING
1.791 +
1.792 + test.Next(_L("Create a paged chunk"));
1.793 + CreatePagedChunk(KChunkSizeInPages, KClearValue);
1.794 +
1.795 + test.Next(_L("Chunk created, declare variables"));
1.796 +
1.797 + __DECLARE_VAR_IN_CHUNK(TBusLocalDrive, &drive)
1.798 + TInt driveSize = TestDriveConnectAndCaps(drive, fatDriveNumber);
1.799 +
1.800 + TestDriveSizeRelatedMethods(drive, 0x00001000, driveSize);
1.801 +
1.802 + TestWriteReadRelatedMethods(drive);
1.803 +
1.804 + TestFormatRelatedMethods(drive, driveSize);
1.805 +
1.806 + if(callPasswordRelated)
1.807 + {
1.808 + TestPasswordRelatedMethods(drive);
1.809 + }
1.810 +
1.811 + //Disconnect drive
1.812 + test.Next(_L("call aDrive.Disconnect()..."));
1.813 + DPTest::FlushCache();
1.814 + drive.Disconnect();
1.815 +
1.816 + gMyChunk.Close();
1.817 +
1.818 + RestoreDriveState();
1.819 +
1.820 + test.End();
1.821 +
1.822 + User::SetDebugMask(0x00000000); // No debug info
1.823 + User::SetDebugMask(0x00000000, 1); //No KPAGING
1.824 + return 0;
1.825 + }