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