0
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32test\demandpaging\t_tbus_datapaging.cpp
|
|
15 |
// Functional tests for data paging.
|
|
16 |
// 002 ???
|
|
17 |
// 003 ???
|
|
18 |
//
|
|
19 |
|
|
20 |
//! @SYMTestCaseID KBASE-T_TBUS_DATAPAGING
|
|
21 |
//! @SYMTestType UT
|
|
22 |
//! @SYMPREQ ???
|
|
23 |
//! @SYMTestCaseDesc Data Paging functional tests with TBusLocalDrive.
|
|
24 |
//! @SYMTestActions 001 ???
|
|
25 |
//! @SYMTestExpectedResults All tests should pass.
|
|
26 |
//! @SYMTestPriority High
|
|
27 |
//! @SYMTestStatus Implementation on-going
|
|
28 |
|
|
29 |
#define __E32TEST_EXTENSION__
|
|
30 |
#include <e32test.h>
|
|
31 |
#include <dptest.h>
|
|
32 |
#include <e32hal.h>
|
|
33 |
#include <u32exec.h>
|
|
34 |
#include <e32svr.h>
|
|
35 |
#include <e32panic.h>
|
|
36 |
#include "u32std.h"
|
|
37 |
|
|
38 |
#include <f32file.h>
|
|
39 |
#include <f32dbg.h>
|
|
40 |
#include <f32fsys.h>
|
|
41 |
|
|
42 |
#include "t_dpcmn.h"
|
|
43 |
#include "../secure/d_sldd.h"
|
|
44 |
#include "../mmu/mmudetect.h"
|
|
45 |
|
|
46 |
const TInt KMaxLengthOfStoreMapping = 16 + sizeof(TInt32) + KMaxMediaPassword;
|
|
47 |
const TInt KMaxPersistentStore(TPasswordStore::EMaxPasswordLength+KMaxLengthOfStoreMapping);
|
|
48 |
typedef TBuf8<KMaxPersistentStore> TPersistentStore;
|
|
49 |
|
|
50 |
RChunk gMyChunk;
|
|
51 |
TUint gOffset = 0;
|
|
52 |
TUint8* gData = NULL;
|
|
53 |
const TUint8 KClearValue = 0xed;
|
|
54 |
const TUint KChunkSizeInPages = 64; // 64 * 4096 = 256K
|
|
55 |
const TInt KTestBufLen=256;
|
|
56 |
|
|
57 |
|
|
58 |
#define __DECLARE_VAR_IN_CHUNK(type, varRef) \
|
|
59 |
type varRef = *(type*) (gData+gOffset); \
|
|
60 |
gOffset += Max(gPageSize, sizeof(type)); \
|
|
61 |
test(gOffset <= gPageSize * KChunkSizeInPages);
|
|
62 |
|
|
63 |
#define __DECLARE_AND_INIT_VAR_IN_CHUNK(type, var) \
|
|
64 |
type &var = *(type*) (gData+gOffset); \
|
|
65 |
var = type(); \
|
|
66 |
gOffset += Max(gPageSize, sizeof(type)); \
|
|
67 |
test(gOffset <= gPageSize * KChunkSizeInPages);
|
|
68 |
|
|
69 |
|
|
70 |
#define __DECLARE_ARRAY_IN_CHUNK(type, var, size) \
|
|
71 |
type *var = (type*) (gData+gOffset); \
|
|
72 |
gOffset += Max(gPageSize, (sizeof(type) * size)); \
|
|
73 |
test(gOffset <= gPageSize * KChunkSizeInPages);
|
|
74 |
|
|
75 |
#define __FLUSH_AND_CALL_API_METHOD(return, function) \
|
|
76 |
DPTest::FlushCache(); \
|
|
77 |
return = function;
|
|
78 |
|
|
79 |
|
|
80 |
LOCAL_D RFs TheFs;
|
|
81 |
TInt gFsDriveNumber = -1;
|
|
82 |
|
|
83 |
RTest test(_L("T_TBUS_DATAPAGING"));
|
|
84 |
_LIT(KChunkName, "t_datapaging chunk");
|
|
85 |
|
|
86 |
const TUint KDriveAttMask = KDriveAttLocal | KDriveAttRom | KDriveAttInternal | KDriveAttRemovable | KDriveAttRemote;
|
|
87 |
const TUint KMediaAttMask = KMediaAttVariableSize | KMediaAttDualDensity | KMediaAttLockable | KMediaAttLocked | KMediaAttHasPassword | KMediaAttReadWhileWrite;
|
|
88 |
|
|
89 |
void CreatePagedChunk(TInt aSizeInPages, TInt aWipeByte = -1)
|
|
90 |
{
|
|
91 |
test_Equal(0,gMyChunk.Handle());
|
|
92 |
|
|
93 |
TChunkCreateInfo createInfo;
|
|
94 |
TInt size = aSizeInPages * gPageSize;
|
|
95 |
createInfo.SetNormal(size, size);
|
|
96 |
createInfo.SetPaging(TChunkCreateInfo::EPaged);
|
|
97 |
createInfo.SetOwner(EOwnerProcess);
|
|
98 |
createInfo.SetGlobal(KChunkName);
|
|
99 |
if (aWipeByte != -1)
|
|
100 |
createInfo.SetClearByte(aWipeByte);
|
|
101 |
test_KErrNone(gMyChunk.Create(createInfo));
|
|
102 |
test(gMyChunk.IsPaged()); // this is only ever called if data paging is supported
|
|
103 |
|
|
104 |
gData = gMyChunk.Base();
|
|
105 |
}
|
|
106 |
|
|
107 |
TInt TestDriveConnectAndCaps(TBusLocalDrive &aDrive, TInt &aLocalDriveNumber)
|
|
108 |
{
|
|
109 |
|
|
110 |
test.Next(_L("Test Drive Connect And Caps"));
|
|
111 |
|
|
112 |
__DECLARE_VAR_IN_CHUNK(TInt, &r);
|
|
113 |
|
|
114 |
test.Printf(_L("changeFlag...\n"));
|
|
115 |
__DECLARE_VAR_IN_CHUNK(TBool, &changeFlag);
|
|
116 |
changeFlag = EFalse;
|
|
117 |
|
|
118 |
test.Printf(_L("call aDrive.Connect()...\n"));
|
|
119 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.Connect(aLocalDriveNumber,changeFlag));
|
|
120 |
|
|
121 |
test.Printf(_L("r:%d\n"),r);
|
|
122 |
test_Equal(KErrNone, r);
|
|
123 |
|
|
124 |
test.Printf(_L("call aDrive.Caps()...\n"));
|
|
125 |
__DECLARE_VAR_IN_CHUNK(TLocalDriveCapsV5, &driveCaps);
|
|
126 |
|
|
127 |
TPckg<TLocalDriveCapsV5> capsPckg(driveCaps);
|
|
128 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.Caps(capsPckg));
|
|
129 |
|
|
130 |
test_Equal(KErrNone, r);
|
|
131 |
test.Printf(_L("r:%d\n"),r);
|
|
132 |
test.Printf(_L("driveCaps.iDriveAtt :0x%08x\n"), driveCaps.iDriveAtt);
|
|
133 |
test.Printf(_L("driveCaps.iSize :%ld\n"), driveCaps.iSize);
|
|
134 |
test.Printf(_L("driveCaps.iSerialNumLength :%d\n"), driveCaps.iSerialNumLength);
|
|
135 |
|
|
136 |
return I64LOW(driveCaps.iSize);
|
|
137 |
}
|
|
138 |
|
|
139 |
void TestDriveSizeRelatedMethods(TBusLocalDrive &aDrive, TInt aNewSize, TInt aOldSize)
|
|
140 |
{
|
|
141 |
TInt r;
|
|
142 |
|
|
143 |
test.Next(_L("Test Drive Size Related Methods"));
|
|
144 |
test.Printf(_L("newDriveSize...\n"));
|
|
145 |
__DECLARE_VAR_IN_CHUNK(TInt, &newDriveSize);
|
|
146 |
newDriveSize = aNewSize;
|
|
147 |
|
|
148 |
test.Printf(_L("call aDrive.Enlarge()...\n"));
|
|
149 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.Enlarge(newDriveSize));
|
|
150 |
test.Printf(_L("r:%d\n"),r);
|
|
151 |
test((KErrNone == r) || (KErrNotSupported == r) || (KErrNotReady == r));
|
|
152 |
if(r != KErrNone )
|
|
153 |
{
|
|
154 |
test.Printf(_L("errInfo...\n"));
|
|
155 |
__DECLARE_ARRAY_IN_CHUNK(TUint8, errInfo, KTestBufLen);
|
|
156 |
|
|
157 |
TPtr8 pErrInfoBuff(errInfo, KTestBufLen);
|
|
158 |
|
|
159 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.GetLastErrorInfo(pErrInfoBuff));
|
|
160 |
test.Printf(_L("r:%d\n"),r);
|
|
161 |
test((KErrNone == r) || (KErrNotSupported == r));
|
|
162 |
}
|
|
163 |
|
|
164 |
|
|
165 |
test.Printf(_L("call aDrive.ReduceSize()...\n"));
|
|
166 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.ReduceSize(0, aOldSize));
|
|
167 |
test((KErrNone == r) || (KErrNotSupported == r) || (KErrNotReady == r));
|
|
168 |
|
|
169 |
}
|
|
170 |
|
|
171 |
void TestWriteReadRelatedMethods(TBusLocalDrive &aDrive)
|
|
172 |
{
|
|
173 |
|
|
174 |
test.Next(_L("Test Write & Read Related Methods"));
|
|
175 |
|
|
176 |
__DECLARE_VAR_IN_CHUNK(TInt, &r);
|
|
177 |
|
|
178 |
test.Printf(_L("msgHandle...\n"));
|
|
179 |
__DECLARE_VAR_IN_CHUNK(TInt, &msgHandle);
|
|
180 |
msgHandle = KLocalMessageHandle;
|
|
181 |
|
|
182 |
|
|
183 |
__DECLARE_VAR_IN_CHUNK(TUint, &i);
|
|
184 |
test.Printf(_L("wrBuf...\n"));
|
|
185 |
TBuf8<KTestBufLen> wrBuf(KTestBufLen);
|
|
186 |
for (i=0 ; i<(TUint)KTestBufLen ; i++)
|
|
187 |
wrBuf[i]=(TUint8)i;
|
|
188 |
|
|
189 |
|
|
190 |
test.Printf(_L("wrBuf2...\n"));
|
|
191 |
__DECLARE_ARRAY_IN_CHUNK(TUint8, wrBuf2, KTestBufLen);
|
|
192 |
|
|
193 |
test.Printf(_L("fill wrBuf2...\n"));
|
|
194 |
for (i=0 ; i<(TUint)KTestBufLen ; i++)
|
|
195 |
wrBuf2[i]=(TUint8)i;
|
|
196 |
|
|
197 |
TPtr8 pWrBuf2(wrBuf2, KTestBufLen, KTestBufLen);
|
|
198 |
|
|
199 |
test.Printf(_L("rdBuf...\n"));
|
|
200 |
TBuf8<KTestBufLen> rdBuf(KTestBufLen);
|
|
201 |
|
|
202 |
|
|
203 |
test.Printf(_L("rdBuf2...\n"));
|
|
204 |
__DECLARE_ARRAY_IN_CHUNK(TUint8, rdBuf2, KTestBufLen);
|
|
205 |
|
|
206 |
TPtr8 pRdBuf2(rdBuf2, KTestBufLen);
|
|
207 |
|
|
208 |
test.Printf(_L("call aDrive.Write()...\n"));
|
|
209 |
rdBuf.Fill(0,KTestBufLen);
|
|
210 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.Write(0,KTestBufLen,&wrBuf,msgHandle,0));
|
|
211 |
test_Equal(KErrNone, r);
|
|
212 |
|
|
213 |
|
|
214 |
test.Printf(_L("call aDrive.Read()...\n"));
|
|
215 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.Read(0,KTestBufLen,&rdBuf,msgHandle,0));
|
|
216 |
test_Equal(KErrNone, r);
|
|
217 |
|
|
218 |
for (i=0 ; i<(TUint)KTestBufLen ; i++)
|
|
219 |
test_Equal(wrBuf[i], rdBuf[i]);
|
|
220 |
|
|
221 |
test.Printf(_L("call aDrive.Write()...\n"));
|
|
222 |
pRdBuf2.Fill(0,KTestBufLen);
|
|
223 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.Write(0,pWrBuf2));
|
|
224 |
test_Equal(KErrNone, r);
|
|
225 |
|
|
226 |
|
|
227 |
test.Printf(_L("call aDrive.Read()...\n"));
|
|
228 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.Read(0,KTestBufLen, pRdBuf2));
|
|
229 |
test_Equal(KErrNone, r);
|
|
230 |
|
|
231 |
for (i=0 ; i<(TUint)KTestBufLen ; i++)
|
|
232 |
test_Equal(wrBuf2[i], rdBuf2[i]);
|
|
233 |
|
|
234 |
}
|
|
235 |
|
|
236 |
void TestPasswordRelatedMethods(TBusLocalDrive &aDrive)
|
|
237 |
{
|
|
238 |
TInt r;
|
|
239 |
|
|
240 |
test.Next(_L("Test Password Related Methods"));
|
|
241 |
//__DECLARE_VAR_IN_CHUNK(TPersistentStore, &wStore);
|
|
242 |
|
|
243 |
TPersistentStore* pstoreAB;
|
|
244 |
test((pstoreAB = new TPersistentStore) != 0);
|
|
245 |
TPersistentStore& wStore = *pstoreAB;
|
|
246 |
|
|
247 |
//__DECLARE_AND_INIT_VAR_IN_CHUNK(TPersistentStore, wStore);
|
|
248 |
|
|
249 |
// Password related API methods call
|
|
250 |
test.Printf(_L("call aDrive.WritePasswordData() to clear passwords...\n"));
|
|
251 |
__DECLARE_VAR_IN_CHUNK(TInt, &passwordStoreLength);
|
|
252 |
|
|
253 |
TBuf8<1> nulSt;
|
|
254 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.WritePasswordData(nulSt));
|
|
255 |
test( r == KErrNone);// empty
|
|
256 |
|
|
257 |
test.Printf(_L("call aDrive.PasswordStoreLengthInBytes()...\n"));
|
|
258 |
__FLUSH_AND_CALL_API_METHOD(passwordStoreLength, aDrive.PasswordStoreLengthInBytes());
|
|
259 |
|
|
260 |
test.Printf(_L("passwordStoreLength:%d\n"), passwordStoreLength);
|
|
261 |
test_Equal(0, passwordStoreLength);
|
|
262 |
|
|
263 |
|
|
264 |
test.Printf(_L("call aDrive.ErasePassword()...\n"));
|
|
265 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.ErasePassword());
|
|
266 |
test.Printf(_L("r:%d\n"),r);
|
|
267 |
|
|
268 |
|
|
269 |
test.Printf(_L("wStore.Size():%d\n"),wStore.Size());
|
|
270 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.WritePasswordData(wStore));
|
|
271 |
|
|
272 |
test.Printf(_L("r:%d\n"),r);
|
|
273 |
test((KErrNone == r)); // || (KErrCorrupt == r)); // TO-DO Why Corrupt???
|
|
274 |
|
|
275 |
__FLUSH_AND_CALL_API_METHOD(passwordStoreLength, aDrive.PasswordStoreLengthInBytes());
|
|
276 |
|
|
277 |
test.Printf(_L("passwordStoreLength:%d\n"), passwordStoreLength);
|
|
278 |
test((r == KErrNone ? (wStore.Size() == passwordStoreLength) : (0 == passwordStoreLength) ));
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
test.Printf(_L("Set and store a password...\n"));
|
|
283 |
TDes8 &st = wStore;
|
|
284 |
TMediaPassword a((const TUint8*) "CID0ccccccccccc#");
|
|
285 |
TUint8 passLen[sizeof(TInt32)];
|
|
286 |
passLen[0] = 0;
|
|
287 |
passLen[1] = 0;
|
|
288 |
passLen[2] = 0;
|
|
289 |
passLen[3] = 16;
|
|
290 |
|
|
291 |
//test.Printf(_L("Password3:'%S'\n"), &a);
|
|
292 |
|
|
293 |
st.Append(a);
|
|
294 |
st.Append(passLen, sizeof(TInt32));
|
|
295 |
st.Append(a);
|
|
296 |
|
|
297 |
test.Printf(_L("wStore.Size():%d\n"),wStore.Size());
|
|
298 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.WritePasswordData(wStore));
|
|
299 |
|
|
300 |
test.Printf(_L("r:%d\n"),r);
|
|
301 |
test((KErrNone == r));
|
|
302 |
|
|
303 |
__FLUSH_AND_CALL_API_METHOD(passwordStoreLength, aDrive.PasswordStoreLengthInBytes());
|
|
304 |
|
|
305 |
test.Printf(_L("passwordStoreLength:%d\n"), passwordStoreLength);
|
|
306 |
test((r == KErrNone ? (wStore.Size() == passwordStoreLength) : (0 == passwordStoreLength) ));
|
|
307 |
|
|
308 |
test.Printf(_L("call aDrive.ErasePassword()...\n"));
|
|
309 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.ErasePassword());
|
|
310 |
test.Printf(_L("r:%d\n"),r);
|
|
311 |
|
|
312 |
test.Printf(_L("call aDrive.WritePasswordData() to set password again...\n"));
|
|
313 |
test.Printf(_L("wStore.Size():%d\n"),wStore.Size());
|
|
314 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.WritePasswordData(wStore));
|
|
315 |
|
|
316 |
test.Printf(_L("r:%d\n"),r);
|
|
317 |
test((KErrNone == r));
|
|
318 |
|
|
319 |
__FLUSH_AND_CALL_API_METHOD(passwordStoreLength, aDrive.PasswordStoreLengthInBytes());
|
|
320 |
|
|
321 |
test.Printf(_L("passwordStoreLength:%d\n"), passwordStoreLength);
|
|
322 |
test((r == KErrNone ? (wStore.Size() == passwordStoreLength) : (0 == passwordStoreLength) ));
|
|
323 |
|
|
324 |
|
|
325 |
// Finally erase password
|
|
326 |
test.Printf(_L("call aDrive.WritePasswordData() to erase password...\n"));
|
|
327 |
wStore.Zero(); // empty password store
|
|
328 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.WritePasswordData(wStore))
|
|
329 |
test( r == KErrNone);// Clear
|
|
330 |
|
|
331 |
__FLUSH_AND_CALL_API_METHOD(passwordStoreLength, aDrive.PasswordStoreLengthInBytes());
|
|
332 |
|
|
333 |
test.Printf(_L("passwordStoreLength:%d\n"), passwordStoreLength);
|
|
334 |
test((r == KErrNone ? (wStore.Size() == passwordStoreLength) : (0 == passwordStoreLength) ));
|
|
335 |
|
|
336 |
|
|
337 |
|
|
338 |
// Test SetPassword
|
|
339 |
TMediaPassword nul(nulSt);
|
|
340 |
|
|
341 |
test.Printf(_L("call aDrive.SetPassword()...\n"));
|
|
342 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.SetPassword(nul, a, EFalse));
|
|
343 |
test.Printf(_L("r:%d\n"),r);
|
|
344 |
test_Equal(KErrNone, r);
|
|
345 |
|
|
346 |
// Erase Password
|
|
347 |
test.Printf(_L("call aDrive.ErasePassword()...\n"));
|
|
348 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.ErasePassword());
|
|
349 |
test.Printf(_L("r:%d\n"),r);
|
|
350 |
|
|
351 |
|
|
352 |
test.Printf(_L("call aDrive.SetPassword()...\n"));
|
|
353 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.SetPassword(nul, a, EFalse));
|
|
354 |
test.Printf(_L("r:%d\n"),r);
|
|
355 |
test_Equal(KErrNone, r);
|
|
356 |
|
|
357 |
// Erase Clear
|
|
358 |
test.Printf(_L("call aDrive.Clear()...\n"));
|
|
359 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.Clear(a));
|
|
360 |
test.Printf(_L("r:%d\n"),r);
|
|
361 |
|
|
362 |
|
|
363 |
test.Printf(_L("call aDrive.SetPassword() to clear again...\n"));
|
|
364 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.SetPassword(a, nul, EFalse));
|
|
365 |
test.Printf(_L("r:%d\n"),r);
|
|
366 |
test_Equal(KErrAccessDenied, r);
|
|
367 |
|
|
368 |
|
|
369 |
// Finally erase password
|
|
370 |
test.Printf(_L("call aDrive.WritePasswordData() to erase password...\n"));
|
|
371 |
wStore.Zero(); // empty password store
|
|
372 |
__FLUSH_AND_CALL_API_METHOD(r, aDrive.WritePasswordData(wStore))
|
|
373 |
test( r == KErrNone);// Clear
|
|
374 |
|
|
375 |
__FLUSH_AND_CALL_API_METHOD(passwordStoreLength, aDrive.PasswordStoreLengthInBytes());
|
|
376 |
|
|
377 |
test.Printf(_L("passwordStoreLength:%d\n"), passwordStoreLength);
|
|
378 |
test((r == KErrNone ? (wStore.Size() == passwordStoreLength) : (0 == passwordStoreLength) ));
|
|
379 |
|
|
380 |
}
|
|
381 |
|
|
382 |
void TestFormatRelatedMethods(TBusLocalDrive &aDrive, TInt aSize )
|
|
383 |
{
|
|
384 |
test.Next(_L("Test Format Related Methods"));
|
|
385 |
|
|
386 |
test.Printf(_L("call aDrive.Format(TFormatInfo)...\n"));
|
|
387 |
__DECLARE_AND_INIT_VAR_IN_CHUNK(TFormatInfo, fi);
|
|
388 |
__DECLARE_VAR_IN_CHUNK(TInt, &ret);
|
|
389 |
__DECLARE_VAR_IN_CHUNK(TInt, &attempt);
|
|
390 |
|
|
391 |
__FLUSH_AND_CALL_API_METHOD(ret, aDrive.Format(fi));
|
|
392 |
test.Printf(_L("ret:%d\n"),ret);
|
|
393 |
while(ret!=KErrEof)
|
|
394 |
{
|
|
395 |
if( ret == KErrNotReady )
|
|
396 |
{
|
|
397 |
attempt = 100;
|
|
398 |
while( (ret= aDrive.Format(fi)) == KErrNotReady && --attempt)
|
|
399 |
{
|
|
400 |
test.Printf(_L("attempt:%d\n"),attempt);
|
|
401 |
User::After(1000000);
|
|
402 |
}
|
|
403 |
test(attempt);
|
|
404 |
}
|
|
405 |
else
|
|
406 |
{
|
|
407 |
test(ret==KErrNone);
|
|
408 |
ret= aDrive.Format(fi);
|
|
409 |
}
|
|
410 |
}
|
|
411 |
|
|
412 |
|
|
413 |
test.Printf(_L("call aDrive.Format(pos, length)...\n"));
|
|
414 |
User::After(1000000);
|
|
415 |
|
|
416 |
__DECLARE_VAR_IN_CHUNK(TInt64, &pos);
|
|
417 |
pos = 0;
|
|
418 |
__DECLARE_VAR_IN_CHUNK(TInt, &length);
|
|
419 |
length = aSize;
|
|
420 |
|
|
421 |
attempt = 100;
|
|
422 |
__FLUSH_AND_CALL_API_METHOD(ret, aDrive.Format(pos, length));
|
|
423 |
while( ret == KErrNotReady && --attempt)
|
|
424 |
{
|
|
425 |
User::After(1000000);
|
|
426 |
ret= aDrive.Format(pos, length);
|
|
427 |
}
|
|
428 |
test(attempt);
|
|
429 |
test_Equal(KErrNone, ret);
|
|
430 |
|
|
431 |
test.Printf(_L("End of TestFormatRelatedMethods)...\n"));
|
|
432 |
}
|
|
433 |
|
|
434 |
void RestoreDriveState(void)
|
|
435 |
{
|
|
436 |
TBuf<3> bfDrv;
|
|
437 |
|
|
438 |
const TText KDrvLtr = 'A' + gFsDriveNumber;
|
|
439 |
|
|
440 |
bfDrv.Append(KDrvLtr);
|
|
441 |
_LIT(KBP, ":\\");
|
|
442 |
bfDrv.Append(KBP);
|
|
443 |
|
|
444 |
|
|
445 |
TheFs.Connect();
|
|
446 |
RFormat fmt;
|
|
447 |
TInt count;
|
|
448 |
|
|
449 |
test(fmt.Open(TheFs, bfDrv, EHighDensity, count) == KErrNone);
|
|
450 |
while (count > 0)
|
|
451 |
{
|
|
452 |
test.Printf(_L("\rfmt:%d "), count);
|
|
453 |
test(fmt.Next(count) == KErrNone);
|
|
454 |
}
|
|
455 |
test.Printf(_L("\n"));
|
|
456 |
fmt.Close();
|
|
457 |
|
|
458 |
TheFs.Close();
|
|
459 |
}
|
|
460 |
|
|
461 |
|
|
462 |
TInt FindDataPagingDrive()
|
|
463 |
/**
|
|
464 |
Find the drive containing a swap partition.
|
|
465 |
|
|
466 |
@return Local drive identifier.
|
|
467 |
*/
|
|
468 |
{
|
|
469 |
TInt drive = KErrNotFound;
|
|
470 |
|
|
471 |
test.Printf(_L("Searching for data paging drive:\n"));
|
|
472 |
|
|
473 |
for(TInt i = 0; i < KMaxLocalDrives && drive < 0; ++i)
|
|
474 |
{
|
|
475 |
RLocalDrive d;
|
|
476 |
TBool change = EFalse;
|
|
477 |
|
|
478 |
if(d.Connect(i, change) == KErrNone)
|
|
479 |
{
|
|
480 |
TLocalDriveCapsV4 dc;
|
|
481 |
TPckg<TLocalDriveCapsV4> capsPack(dc);
|
|
482 |
|
|
483 |
if(d.Caps(capsPack) == KErrNone)
|
|
484 |
{
|
|
485 |
if ((dc.iMediaAtt & KMediaAttPageable) &&
|
|
486 |
(dc.iPartitionType == KPartitionTypePagedData))
|
|
487 |
{
|
|
488 |
test.Printf(_L("Found swap partition on local drive %d\n"), i);
|
|
489 |
drive = i;
|
|
490 |
|
|
491 |
TPageDeviceInfo pageDeviceInfo;
|
|
492 |
|
|
493 |
TPtr8 pageDeviceInfoBuf((TUint8*) &pageDeviceInfo, sizeof(pageDeviceInfo));
|
|
494 |
pageDeviceInfoBuf.FillZ();
|
|
495 |
|
|
496 |
TInt r = d.QueryDevice(RLocalDrive::EQueryPageDeviceInfo, pageDeviceInfoBuf);
|
|
497 |
|
|
498 |
test.Printf(_L("EQueryPageDeviceInfo on local drive %d returned %d\n"), i, r);
|
|
499 |
}
|
|
500 |
}
|
|
501 |
d.Close();
|
|
502 |
}
|
|
503 |
}
|
|
504 |
return drive;
|
|
505 |
}
|
|
506 |
|
|
507 |
TDes& GetSerialNumber(TLocalDriveCapsV5& aCaps)
|
|
508 |
{
|
|
509 |
static TBuf16<80> serialNumBuf;
|
|
510 |
|
|
511 |
serialNumBuf.SetLength(0);
|
|
512 |
|
|
513 |
for (TUint n=0; n<aCaps.iSerialNumLength; n+=16)
|
|
514 |
{
|
|
515 |
for (TUint m=n; m<n+16; m++)
|
|
516 |
{
|
|
517 |
TBuf16<3> hexBuf;
|
|
518 |
hexBuf.Format(_L("%02X "), aCaps.iSerialNum[m]);
|
|
519 |
serialNumBuf.Append(hexBuf);
|
|
520 |
}
|
|
521 |
}
|
|
522 |
|
|
523 |
return serialNumBuf;
|
|
524 |
}
|
|
525 |
|
|
526 |
TDes& GetSerialNumber(TMediaSerialNumber& aSerialNum)
|
|
527 |
{
|
|
528 |
static TBuf16<80> serialNumBuf;
|
|
529 |
|
|
530 |
serialNumBuf.SetLength(0);
|
|
531 |
|
|
532 |
TInt len = aSerialNum.Length();
|
|
533 |
for (TInt n=0; n<len; n+=16)
|
|
534 |
{
|
|
535 |
for (TInt m=n; m<n+16; m++)
|
|
536 |
{
|
|
537 |
TBuf16<3> hexBuf;
|
|
538 |
hexBuf.Format(_L("%02X "), aSerialNum[m]);
|
|
539 |
serialNumBuf.Append(hexBuf);
|
|
540 |
}
|
|
541 |
}
|
|
542 |
|
|
543 |
return serialNumBuf;
|
|
544 |
}
|
|
545 |
|
|
546 |
TPtrC GetMediaType(TMediaType aType)
|
|
547 |
{
|
|
548 |
switch(aType)
|
|
549 |
{
|
|
550 |
case EMediaNotPresent: return _L("NotPresent");
|
|
551 |
case EMediaUnknown: return _L("Unknown");
|
|
552 |
case EMediaFloppy: return _L("Floppy");
|
|
553 |
case EMediaHardDisk: return _L("HardDisk");
|
|
554 |
case EMediaCdRom: return _L("CdRom");
|
|
555 |
case EMediaRam: return _L("Ram");
|
|
556 |
case EMediaFlash: return _L("Flash");
|
|
557 |
case EMediaRom: return _L("Rom");
|
|
558 |
case EMediaRemote: return _L("Remote");
|
|
559 |
case EMediaNANDFlash: return _L("NANDFlash");
|
|
560 |
case EMediaRotatingMedia : return _L("RotatingMedia ");
|
|
561 |
default:return _L("Unrecognised");
|
|
562 |
}
|
|
563 |
}
|
|
564 |
|
|
565 |
TPtrC GetFileSystemId(TUint aFileSystemId)
|
|
566 |
{
|
|
567 |
switch(aFileSystemId)
|
|
568 |
{
|
|
569 |
case KDriveFileSysFAT: return _L("FAT");
|
|
570 |
case KDriveFileSysROM: return _L("ROM");
|
|
571 |
case KDriveFileSysLFFS: return _L("LFFS");
|
|
572 |
case KDriveFileSysROFS: return _L("ROFS");
|
|
573 |
case KDriveFileNone: return _L("None");
|
|
574 |
default:return _L("Unrecognised");
|
|
575 |
}
|
|
576 |
}
|
|
577 |
|
|
578 |
|
|
579 |
|
|
580 |
// Find a drive which contains the swap partition; if this succeeds, find and return the FAT drive on the same media.
|
|
581 |
// This isn't fool-proof as it works by comparing media types/drive attributes/media attributes/serial numbers
|
|
582 |
TInt FindFatDriveOnDataPagingMedia()
|
|
583 |
{
|
|
584 |
TInt dataPagingDrive = FindDataPagingDrive();
|
|
585 |
if (dataPagingDrive == KErrNotFound)
|
|
586 |
return KErrNotFound;
|
|
587 |
|
|
588 |
TInt fatDriveNumber = KErrNotFound;
|
|
589 |
|
|
590 |
test.Printf(_L("Finding Fat drive on datapaging media...\n"));
|
|
591 |
|
|
592 |
RLocalDrive dpDrive;
|
|
593 |
TBool change = EFalse;
|
|
594 |
|
|
595 |
TInt r = dpDrive.Connect(dataPagingDrive, change);
|
|
596 |
test(r == KErrNone);
|
|
597 |
TLocalDriveCapsV5 dpDriveCaps;
|
|
598 |
TPckg<TLocalDriveCapsV5> capsPack(dpDriveCaps);
|
|
599 |
r = dpDrive.Caps(capsPack);
|
|
600 |
test(r == KErrNone);
|
|
601 |
TPtrC8 dpDriveSerialNum(dpDriveCaps.iSerialNum, dpDriveCaps.iSerialNumLength);
|
|
602 |
dpDrive.Close();
|
|
603 |
|
|
604 |
TPtrC mediaType = GetMediaType(dpDriveCaps.iType);
|
|
605 |
TPtrC fileSystemId = GetFileSystemId(dpDriveCaps.iFileSystemId);
|
|
606 |
test.Printf(_L("Swap Drive %2d Type %S DriveAtt 0x%x MediaAtt 0x%x FileSysId %S SerialNum %S\n"),
|
|
607 |
dataPagingDrive, &mediaType, dpDriveCaps.iDriveAtt, dpDriveCaps.iMediaAtt, &fileSystemId, &GetSerialNumber(dpDriveCaps));
|
|
608 |
|
|
609 |
// swap partition should be hidden
|
|
610 |
test (dpDriveCaps.iDriveAtt & KDriveAttHidden);
|
|
611 |
|
|
612 |
// search for a FAT drive on the same media by searching for a drive which has
|
|
613 |
// 'similar' drive & media attributes as the the swap drive
|
|
614 |
|
|
615 |
dpDriveCaps.iDriveAtt&= KDriveAttMask;
|
|
616 |
dpDriveCaps.iMediaAtt&= KMediaAttMask;
|
|
617 |
|
|
618 |
for (TInt i = 0; i < KMaxLocalDrives /*&& fatDriveNumber == KErrNotFound*/; ++i)
|
|
619 |
{
|
|
620 |
RLocalDrive d;
|
|
621 |
TBool change = EFalse;
|
|
622 |
|
|
623 |
if(d.Connect(i, change) == KErrNone)
|
|
624 |
{
|
|
625 |
TLocalDriveCapsV5 caps;
|
|
626 |
TPckg<TLocalDriveCapsV5> capsPack(caps);
|
|
627 |
|
|
628 |
r = d.Caps(capsPack);
|
|
629 |
if (r != KErrNone)
|
|
630 |
continue;
|
|
631 |
|
|
632 |
TPtrC8 localSerialNum(caps.iSerialNum, caps.iSerialNumLength);
|
|
633 |
TPtrC mediaType = GetMediaType(caps.iType);
|
|
634 |
TPtrC fileSystemId = GetFileSystemId(caps.iFileSystemId);
|
|
635 |
test.Printf(_L("Drive %2d Type %S DriveAtt 0x%x MediaAtt 0x%x FileSysId %S SerialNum %S\n"),
|
|
636 |
i, &mediaType, caps.iDriveAtt, caps.iMediaAtt, &fileSystemId, &GetSerialNumber(caps));
|
|
637 |
|
|
638 |
// Turn off bits which may be different
|
|
639 |
caps.iDriveAtt&= KDriveAttMask;
|
|
640 |
caps.iMediaAtt&= KMediaAttMask;
|
|
641 |
|
|
642 |
if ((caps.iType == dpDriveCaps.iType) &&
|
|
643 |
(caps.iDriveAtt == dpDriveCaps.iDriveAtt) &&
|
|
644 |
(caps.iMediaAtt == dpDriveCaps.iMediaAtt) &&
|
|
645 |
(localSerialNum.Compare(dpDriveSerialNum) == 0) &&
|
|
646 |
(caps.iFileSystemId == KDriveFileSysFAT))
|
|
647 |
{
|
|
648 |
if (fatDriveNumber == KErrNotFound)
|
|
649 |
fatDriveNumber = i;
|
|
650 |
}
|
|
651 |
d.Close();
|
|
652 |
}
|
|
653 |
}
|
|
654 |
|
|
655 |
|
|
656 |
return fatDriveNumber;
|
|
657 |
}
|
|
658 |
|
|
659 |
|
|
660 |
// Find and return the File Server drive number (0-25) corresponing to the passed local drive number
|
|
661 |
// This isn't fool-proof as it works by comparing media types/drive attributes/media attributes/serial numbers
|
|
662 |
TInt FindFsDriveNumber(TInt aLocalDriveNumber)
|
|
663 |
{
|
|
664 |
TInt fsDriveNumber = KErrNotFound;
|
|
665 |
|
|
666 |
RLocalDrive dpDrive;
|
|
667 |
TBool change = EFalse;
|
|
668 |
|
|
669 |
TInt r = dpDrive.Connect(aLocalDriveNumber, change);
|
|
670 |
test(r == KErrNone);
|
|
671 |
TLocalDriveCapsV5 dpDriveCaps;
|
|
672 |
TPckg<TLocalDriveCapsV5> capsPack(dpDriveCaps);
|
|
673 |
r = dpDrive.Caps(capsPack);
|
|
674 |
test(r == KErrNone);
|
|
675 |
TPtrC8 dpDriveSerialNum(dpDriveCaps.iSerialNum, dpDriveCaps.iSerialNumLength);
|
|
676 |
dpDrive.Close();
|
|
677 |
|
|
678 |
dpDriveCaps.iDriveAtt&= KDriveAttMask;
|
|
679 |
dpDriveCaps.iMediaAtt&= KMediaAttMask;
|
|
680 |
|
|
681 |
RFs fs;
|
|
682 |
r = fs.Connect();
|
|
683 |
test(r == KErrNone);
|
|
684 |
|
|
685 |
TDriveInfo di;
|
|
686 |
|
|
687 |
for (TInt n=0; n<KMaxDrives /* && fsDriveNumber == KErrNotFound*/; n++)
|
|
688 |
{
|
|
689 |
r = fs.Drive(di, n);
|
|
690 |
|
|
691 |
TMediaSerialNumber serialNum;
|
|
692 |
fs.GetMediaSerialNumber(serialNum, n);
|
|
693 |
|
|
694 |
TFSName fsName;
|
|
695 |
fs.FileSystemName(fsName, n);
|
|
696 |
|
|
697 |
if (r != KErrNone )
|
|
698 |
continue;
|
|
699 |
|
|
700 |
TPtrC mediaType = GetMediaType(di.iType);
|
|
701 |
test.Printf(_L("Drive %C Type %S DriveAtt 0x%x MediaAtt 0x%x FileSysId %S SerialNum %S\n"),
|
|
702 |
'A' + n, &mediaType, di.iDriveAtt, di.iMediaAtt, &fsName, &GetSerialNumber(serialNum));
|
|
703 |
|
|
704 |
di.iDriveAtt&= KDriveAttMask;
|
|
705 |
di.iMediaAtt&= KMediaAttMask;
|
|
706 |
|
|
707 |
if ((di.iType == dpDriveCaps.iType) &&
|
|
708 |
(di.iDriveAtt == dpDriveCaps.iDriveAtt) &&
|
|
709 |
(di.iMediaAtt == dpDriveCaps.iMediaAtt) &&
|
|
710 |
(serialNum.Compare(dpDriveSerialNum) == 0))
|
|
711 |
{
|
|
712 |
if (fsDriveNumber == KErrNotFound)
|
|
713 |
fsDriveNumber = n;
|
|
714 |
}
|
|
715 |
}
|
|
716 |
|
|
717 |
fs.Close();
|
|
718 |
|
|
719 |
return fsDriveNumber;
|
|
720 |
}
|
|
721 |
|
|
722 |
TInt E32Main()
|
|
723 |
{
|
|
724 |
|
|
725 |
// To use in command line
|
|
726 |
TBool callPasswordRelated = EFalse;
|
|
727 |
|
|
728 |
TBuf<256> cmdline;
|
|
729 |
User::CommandLine(cmdline);
|
|
730 |
TLex lex(cmdline);
|
|
731 |
|
|
732 |
FOREVER
|
|
733 |
{
|
|
734 |
TPtrC token=lex.NextToken();
|
|
735 |
if(token.Length() != 0)
|
|
736 |
{
|
|
737 |
if (token == _L("-p"))
|
|
738 |
{
|
|
739 |
callPasswordRelated = ETrue;
|
|
740 |
}
|
|
741 |
else
|
|
742 |
test.Printf(_L("Unknown argument '%S' was ignored.\n"), &token);
|
|
743 |
}
|
|
744 |
else
|
|
745 |
break;
|
|
746 |
|
|
747 |
}
|
|
748 |
|
|
749 |
test.Title();
|
|
750 |
TInt r;
|
|
751 |
|
|
752 |
test.Start(_L("Verify the global and this process's data paging attributes"));
|
|
753 |
test_KErrNone(GetGlobalPolicies());
|
|
754 |
|
|
755 |
if (IsDataPagingSupported())
|
|
756 |
{
|
|
757 |
test.Printf(_L("Data paging supported\n"));
|
|
758 |
}
|
|
759 |
else
|
|
760 |
{// The system doesn't support data paging so this process shouldn't be
|
|
761 |
// data paged.
|
|
762 |
test.Printf(_L("Data paging not supported\n"));
|
|
763 |
test_Equal(EFalse, gProcessPaged);
|
|
764 |
test.End();
|
|
765 |
return 0;
|
|
766 |
}
|
|
767 |
|
|
768 |
r = UserHal::PageSizeInBytes(gPageSize);
|
|
769 |
test_KErrNone(r);
|
|
770 |
|
|
771 |
TInt fatDriveNumber = FindFatDriveOnDataPagingMedia();
|
|
772 |
if (fatDriveNumber == KErrNotFound)
|
|
773 |
{
|
|
774 |
test.Printf(_L("Could not find FAT partition on data paging media\n"));
|
|
775 |
test(0);
|
|
776 |
}
|
|
777 |
gFsDriveNumber = FindFsDriveNumber(fatDriveNumber);
|
|
778 |
if (gFsDriveNumber == KErrNotFound)
|
|
779 |
{
|
|
780 |
test.Printf(_L("Could not File Server drive\n"));
|
|
781 |
test(0);
|
|
782 |
}
|
|
783 |
|
|
784 |
test.Printf(_L("Found FAT drive on %C: (local drive #%d) on data paging media\n"), 'A'+gFsDriveNumber, fatDriveNumber);
|
|
785 |
|
|
786 |
// User::SetDebugMask(0x10000000); //KMMU2
|
|
787 |
// User::SetDebugMask(0x40000000, 1); //KPAGING
|
|
788 |
|
|
789 |
test.Next(_L("Create a paged chunk"));
|
|
790 |
CreatePagedChunk(KChunkSizeInPages, KClearValue);
|
|
791 |
|
|
792 |
test.Next(_L("Chunk created, declare variables"));
|
|
793 |
|
|
794 |
__DECLARE_VAR_IN_CHUNK(TBusLocalDrive, &drive)
|
|
795 |
TInt driveSize = TestDriveConnectAndCaps(drive, fatDriveNumber);
|
|
796 |
|
|
797 |
TestDriveSizeRelatedMethods(drive, 0x00001000, driveSize);
|
|
798 |
|
|
799 |
TestWriteReadRelatedMethods(drive);
|
|
800 |
|
|
801 |
TestFormatRelatedMethods(drive, driveSize);
|
|
802 |
|
|
803 |
if(callPasswordRelated)
|
|
804 |
{
|
|
805 |
TestPasswordRelatedMethods(drive);
|
|
806 |
}
|
|
807 |
|
|
808 |
//Disconnect drive
|
|
809 |
test.Next(_L("call aDrive.Disconnect()..."));
|
|
810 |
DPTest::FlushCache();
|
|
811 |
drive.Disconnect();
|
|
812 |
|
|
813 |
gMyChunk.Close();
|
|
814 |
|
|
815 |
RestoreDriveState();
|
|
816 |
|
|
817 |
test.End();
|
|
818 |
|
|
819 |
User::SetDebugMask(0x00000000); // No debug info
|
|
820 |
User::SetDebugMask(0x00000000, 1); //No KPAGING
|
|
821 |
return 0;
|
|
822 |
}
|