author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 27 May 2010 14:17:14 +0300 | |
changeset 139 | 95f71bcdcdb7 |
parent 109 | b3a1d9898418 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 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 |
// f32test\server\t_ftrace.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
18 |
#define __E32TEST_EXTENSION__ |
0 | 19 |
#include <f32file.h> |
20 |
#include <f32tracedef.h> |
|
21 |
#include <e32test.h> |
|
22 |
#include "t_server.h" |
|
23 |
||
24 |
#include "../../../kernel/eka/include/d32btrace.h" |
|
25 |
#include "../../../kernel/eka/include/e32btrace.h" |
|
26 |
#include <utraceefsrv.h> |
|
27 |
||
28 |
RTest test(_L("T_FTRACE")); |
|
29 |
||
30 |
RBTrace Trace; |
|
31 |
||
32 |
void SetBTraceFilter(const TUint32* aNew,TUint32* aOld) |
|
33 |
{ |
|
34 |
TUint category = 0; |
|
35 |
do |
|
36 |
{ |
|
37 |
TUint32 newBits = *aNew++; |
|
38 |
TUint32 oldBits = 0; |
|
39 |
do |
|
40 |
{ |
|
41 |
oldBits >>= 1; |
|
42 |
if(Trace.SetFilter(category,newBits&1)) |
|
43 |
oldBits |= 0x80000000u; |
|
44 |
newBits >>= 1; |
|
45 |
++category; |
|
46 |
} |
|
47 |
while(category&31); |
|
48 |
if(aOld) |
|
49 |
*aOld++ = oldBits; |
|
50 |
} |
|
51 |
while(category<256); |
|
52 |
} |
|
53 |
||
54 |
||
55 |
||
56 |
//--------------------------------------------------------------------------------------------------------------------- |
|
57 |
//! @SYMTestCaseID KBASE-T_FTRACE-0001 |
|
58 |
//! @SYMTestCaseDesc Test File Server Tracing of RFile::Replace() |
|
59 |
//! @SYMTestType UT |
|
60 |
//! @SYMPREQ PREQ1617 |
|
61 |
//! @SYMTestPriority Medium |
|
62 |
//! @SYMTestActions |
|
63 |
//! 1. Call RFile::Replace() to create a file |
|
64 |
//! 2. Get trace data from BTrace and verify that the expected trace data is present |
|
65 |
//! |
|
66 |
//! @SYMTestExpectedResults |
|
67 |
//! 1. Trace data payload should be as expected, i.e. it should contain the file name, mode etc. |
|
68 |
//--------------------------------------------------------------------------------------------------------------------- |
|
69 |
void TestRFileReplace() |
|
70 |
{ |
|
71 |
test.Start(_L("Test trace output from creating a file")); |
|
72 |
RFile file; |
|
73 |
TFileName testFileName = _L("File.txt"); |
|
74 |
||
75 |
TheFs.Delete(testFileName); |
|
76 |
||
77 |
Trace.Empty(); |
|
78 |
||
79 |
TInt r = file.Replace(TheFs,testFileName,EFileStreamText); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
80 |
test_KErrNone(r); |
0 | 81 |
|
82 |
||
83 |
TBool funcInFound = EFalse; |
|
84 |
TBool funcOutFound = EFalse; |
|
85 |
||
86 |
TBuf8<1024> buf; |
|
87 |
for(;;) |
|
88 |
{ |
|
89 |
TUint8* record; |
|
90 |
TInt dataSize = Trace.GetData(record); |
|
91 |
if(!dataSize) |
|
92 |
break; |
|
93 |
TUint8* end = record+dataSize; |
|
94 |
||
95 |
while(record<end) |
|
96 |
{ |
|
97 |
TUint size = record[BTrace::ESizeIndex]; |
|
98 |
TUint flags = record[BTrace::EFlagsIndex]; |
|
99 |
TUint category = record[BTrace::ECategoryIndex]; |
|
100 |
TUint subCategory = record[BTrace::ESubCategoryIndex]; |
|
101 |
TUint8* data = record+4; |
|
102 |
size -= 4; |
|
103 |
||
104 |
buf.Zero(); |
|
105 |
if(flags&(BTrace::EHeader2Present)) |
|
106 |
{ |
|
107 |
data += 4; |
|
108 |
size -= 4; |
|
109 |
} |
|
110 |
||
111 |
if((flags&(BTrace::ETimestampPresent|BTrace::ETimestamp2Present))==(BTrace::ETimestampPresent|BTrace::ETimestamp2Present)) |
|
112 |
{ |
|
113 |
buf.AppendFormat(_L8("time:%08x:%08x "),((TUint32*)data)[1],*(TUint32*)data); |
|
114 |
data += 8; |
|
115 |
size -= 8; |
|
116 |
} |
|
117 |
else if(flags&(BTrace::ETimestampPresent|BTrace::ETimestamp2Present)) |
|
118 |
{ |
|
119 |
buf.AppendFormat(_L8("time:%08x "),*(TUint32*)data); |
|
120 |
data += 4; |
|
121 |
size -= 4; |
|
122 |
} |
|
123 |
||
124 |
if(flags&(BTrace::EContextIdPresent)) |
|
125 |
{ |
|
126 |
buf.AppendFormat(_L8("context:%08x "),*(TUint32*)data); |
|
127 |
data += 4; |
|
128 |
size -= 4; |
|
129 |
} |
|
130 |
else |
|
131 |
{ |
|
132 |
buf.AppendFormat(_L8(" ")); |
|
133 |
} |
|
134 |
||
135 |
if(flags&(BTrace::EPcPresent)) |
|
136 |
{ |
|
137 |
buf.AppendFormat(_L8("pc:%08x "),*(TUint32*)data); |
|
138 |
data += 4; |
|
139 |
size -= 4; |
|
140 |
} |
|
141 |
||
142 |
if(flags&(BTrace::EExtraPresent)) |
|
143 |
{ |
|
144 |
data += 4; |
|
145 |
size -= 4; |
|
146 |
} |
|
147 |
||
148 |
TUint32 data0 = (size>0) ? *(TUint32*)(data) : 0; |
|
149 |
TUint32 data1 = (size>4) ? *(TUint32*)(data+4) : 0; |
|
150 |
TPtrC8 des(0,0); |
|
151 |
if(size>=8) |
|
152 |
des.Set(data+8,size-8); |
|
153 |
||
154 |
buf.AppendFormat(_L8("size:%d flags:%02x cat:%d,%d data: "),size,flags,category,subCategory); |
|
155 |
for(TUint i=0; i<size; i+=4) |
|
156 |
buf.AppendFormat(_L8("%08x "),*(TUint32*)(data+i)); |
|
157 |
buf.Append('\r'); |
|
158 |
buf.Append('\n'); |
|
159 |
test(buf.MaxLength() >= (buf.Length()*2)); |
|
160 |
RDebug::RawPrint(buf.Expand()); |
|
161 |
||
162 |
||
163 |
if (category == UTF::EBorder && subCategory == 0 && data0 == EF32TraceUidEfsrv) |
|
164 |
{ |
|
165 |
if (data1 == UTraceModuleEfsrv::EFileReplace) |
|
166 |
{ |
|
167 |
TInt sessionHandle = (size>8) ? *(TUint32*)(data+8) : 0; |
|
168 |
TUint32 fileMode = (size>12) ? *(TUint32*)(data+12) : 0; |
|
169 |
TInt fileNameLen = (size>16) ? *(TUint32*)(data+16) : 0; |
|
170 |
fileNameLen/= 2; // convert to unicode length |
|
171 |
TText16* fileName = (TText16*) ((size>20) ? (data+20) : NULL); |
|
172 |
||
173 |
test(sessionHandle == TheFs.Handle()); |
|
174 |
test(fileMode == EFileStreamText); |
|
175 |
test(fileNameLen == testFileName.Length()); |
|
176 |
TPtrC16 fileNamePtr (fileName, fileNameLen); |
|
177 |
test(fileName != NULL); |
|
178 |
test(testFileName.Compare(fileNamePtr) == 0); |
|
179 |
funcInFound = ETrue; |
|
180 |
} |
|
181 |
else if (data1 == UTraceModuleEfsrv::EFileReplaceReturn) |
|
182 |
{ |
|
183 |
TInt retCode = (size>8) ? *(TUint32*)(data+8) : 0; |
|
184 |
TInt subsessionHandle = (size>12) ? *(TUint32*)(data+12) : 0; |
|
185 |
||
186 |
test(retCode == KErrNone); |
|
187 |
test(subsessionHandle == file.SubSessionHandle()); |
|
188 |
funcOutFound = ETrue; |
|
189 |
} |
|
190 |
} |
|
191 |
||
192 |
record = BTrace::NextRecord(record); |
|
193 |
} |
|
194 |
Trace.DataUsed(); |
|
195 |
} |
|
196 |
||
197 |
file.Close(); |
|
198 |
TheFs.Delete(testFileName); |
|
199 |
||
200 |
test (funcInFound); |
|
201 |
test (funcOutFound); |
|
202 |
} |
|
203 |
||
204 |
//--------------------------------------------------------------------------------------------------------------------- |
|
205 |
//! @SYMTestCaseID KBASE-T_FTRACE-0002 |
|
206 |
//! @SYMTestCaseDesc Test File Server Tracing of RFs::Rename() |
|
207 |
//! @SYMTestType UT |
|
208 |
//! @SYMPREQ PREQ1617 |
|
209 |
//! @SYMTestPriority Medium |
|
210 |
//! @SYMTestActions |
|
211 |
//! 1. Call RFile::Replace() to create a file |
|
212 |
//! 2. Close the file |
|
213 |
//! 3. Call RFs::Rename to rename the file |
|
214 |
//! 4. Get trace data from BTrace and verify that the expected trace data is present |
|
215 |
//! |
|
216 |
//! @SYMTestExpectedResults |
|
217 |
//! 1. Trace data payload should be as expected, i.e. it should contain both file names, etc. |
|
218 |
//--------------------------------------------------------------------------------------------------------------------- |
|
219 |
void TestRFsRename() |
|
220 |
{ |
|
221 |
test.Start(_L("Test trace output from renaming a file")); |
|
222 |
RFile file; |
|
223 |
TFileName testFileName1 = _L("File1.txt"); |
|
224 |
TFileName testFileName2 = _L("File2.txt"); |
|
225 |
||
226 |
TheFs.Delete(testFileName1); |
|
227 |
TheFs.Delete(testFileName2); |
|
228 |
||
229 |
TInt r = file.Replace(TheFs,testFileName1,EFileStreamText); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
230 |
test_Value(r, r == KErrNone || r == KErrAlreadyExists); |
0 | 231 |
file.Close(); |
232 |
||
233 |
Trace.Empty(); |
|
234 |
||
235 |
r = TheFs.Rename(testFileName1, testFileName2); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
236 |
test_KErrNone(r); |
0 | 237 |
|
238 |
||
239 |
TBool funcInFound = EFalse; |
|
240 |
TBool funcOutFound = EFalse; |
|
241 |
||
242 |
TBuf8<1024> buf; |
|
243 |
for(;;) |
|
244 |
{ |
|
245 |
TUint8* record; |
|
246 |
TInt dataSize = Trace.GetData(record); |
|
247 |
if(!dataSize) |
|
248 |
break; |
|
249 |
TUint8* end = record+dataSize; |
|
250 |
||
251 |
while(record<end) |
|
252 |
{ |
|
253 |
TUint size = record[BTrace::ESizeIndex]; |
|
254 |
TUint flags = record[BTrace::EFlagsIndex]; |
|
255 |
TUint category = record[BTrace::ECategoryIndex]; |
|
256 |
TUint subCategory = record[BTrace::ESubCategoryIndex]; |
|
257 |
TUint8* data = record+4; |
|
258 |
size -= 4; |
|
259 |
||
260 |
buf.Zero(); |
|
261 |
if(flags&(BTrace::EHeader2Present)) |
|
262 |
{ |
|
263 |
data += 4; |
|
264 |
size -= 4; |
|
265 |
} |
|
266 |
||
267 |
if((flags&(BTrace::ETimestampPresent|BTrace::ETimestamp2Present))==(BTrace::ETimestampPresent|BTrace::ETimestamp2Present)) |
|
268 |
{ |
|
269 |
buf.AppendFormat(_L8("time:%08x:%08x "),((TUint32*)data)[1],*(TUint32*)data); |
|
270 |
data += 8; |
|
271 |
size -= 8; |
|
272 |
} |
|
273 |
else if(flags&(BTrace::ETimestampPresent|BTrace::ETimestamp2Present)) |
|
274 |
{ |
|
275 |
buf.AppendFormat(_L8("time:%08x "),*(TUint32*)data); |
|
276 |
data += 4; |
|
277 |
size -= 4; |
|
278 |
} |
|
279 |
||
280 |
if(flags&(BTrace::EContextIdPresent)) |
|
281 |
{ |
|
282 |
buf.AppendFormat(_L8("context:%08x "),*(TUint32*)data); |
|
283 |
data += 4; |
|
284 |
size -= 4; |
|
285 |
} |
|
286 |
else |
|
287 |
{ |
|
288 |
buf.AppendFormat(_L8(" ")); |
|
289 |
} |
|
290 |
||
291 |
if(flags&(BTrace::EPcPresent)) |
|
292 |
{ |
|
293 |
buf.AppendFormat(_L8("pc:%08x "),*(TUint32*)data); |
|
294 |
data += 4; |
|
295 |
size -= 4; |
|
296 |
} |
|
297 |
||
298 |
if(flags&(BTrace::EExtraPresent)) |
|
299 |
{ |
|
300 |
data += 4; |
|
301 |
size -= 4; |
|
302 |
} |
|
303 |
||
304 |
TUint32 data0 = (size>0) ? *(TUint32*)(data) : 0; |
|
305 |
TUint32 data1 = (size>4) ? *(TUint32*)(data+4) : 0; |
|
306 |
TPtrC8 des(0,0); |
|
307 |
if(size>=8) |
|
308 |
des.Set(data+8,size-8); |
|
309 |
||
310 |
buf.AppendFormat(_L8("size:%d flags:%02x cat:%d,%d data: "),size,flags,category,subCategory); |
|
311 |
for(TUint i=0; i<size; i+=4) |
|
312 |
buf.AppendFormat(_L8("%08x "),*(TUint32*)(data+i)); |
|
313 |
buf.Append('\r'); |
|
314 |
buf.Append('\n'); |
|
315 |
test(buf.MaxLength() >= (buf.Length()*2)); |
|
316 |
RDebug::RawPrint(buf.Expand()); |
|
317 |
||
318 |
||
319 |
if (category == UTF::EBorder && subCategory == 0 && data0 == EF32TraceUidEfsrv) |
|
320 |
{ |
|
321 |
TUint8* recData = data+8; |
|
322 |
if (data1 == UTraceModuleEfsrv::EFsRename) |
|
323 |
{ |
|
324 |
TInt sessionHandle = *(TUint32*) recData; recData+= 4; |
|
325 |
||
326 |
TInt fileNameLen1 = *(TUint32*) recData; recData+= 4; |
|
327 |
TText16* fileName1 = (TText16*) recData; recData+= ((fileNameLen1 +4) & ~3); |
|
328 |
||
329 |
TInt fileNameLen2 = *(TUint32*) recData; recData+= 4; |
|
330 |
TText16* fileName2 = (TText16*) recData; recData+= fileNameLen2; |
|
331 |
||
332 |
fileNameLen1/= 2; // convert to unicode length |
|
333 |
fileNameLen2/= 2; // convert to unicode length |
|
334 |
||
335 |
||
336 |
test(sessionHandle == TheFs.Handle()); |
|
337 |
||
338 |
test(fileNameLen1 == testFileName1.Length()); |
|
339 |
TPtrC16 fileNamePtr1 (fileName1, fileNameLen1); |
|
340 |
test(fileName1 != NULL); |
|
341 |
test(testFileName1.Compare(fileNamePtr1) == 0); |
|
342 |
||
343 |
test(fileNameLen2 == testFileName2.Length()); |
|
344 |
TPtrC16 fileNamePtr2 (fileName2, fileNameLen2); |
|
345 |
test(fileName2 != NULL); |
|
346 |
test(testFileName2.Compare(fileNamePtr2) == 0); |
|
347 |
||
348 |
funcInFound = ETrue; |
|
349 |
} |
|
350 |
else if (data1 == UTraceModuleEfsrv::EFsRenameReturn) |
|
351 |
{ |
|
352 |
TInt retCode = (size>8) ? *(TUint32*)(data+8) : 0; |
|
353 |
||
354 |
test(retCode == KErrNone); |
|
355 |
||
356 |
funcOutFound = ETrue; |
|
357 |
} |
|
358 |
} |
|
359 |
||
360 |
record = BTrace::NextRecord(record); |
|
361 |
} |
|
362 |
Trace.DataUsed(); |
|
363 |
} |
|
364 |
||
365 |
||
366 |
test (funcInFound); |
|
367 |
test (funcOutFound); |
|
368 |
||
369 |
TheFs.Delete(testFileName1); |
|
370 |
TheFs.Delete(testFileName2); |
|
371 |
} |
|
372 |
||
373 |
void CallTestsL() |
|
374 |
{ |
|
375 |
||
376 |
// By default, file server trace-points are only compiled in in debug mode |
|
377 |
#if defined(_DEBUG) |
|
378 |
test.Title(); |
|
379 |
TInt r; |
|
380 |
||
381 |
test.Start(_L("Open LDD")); |
|
382 |
r = Trace.Open(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
383 |
test_KErrNone(r); |
0 | 384 |
|
385 |
||
386 |
TUint32 OldTraceFilter[8] = {0}; |
|
387 |
||
388 |
TUint savedMode = Trace.Mode(); |
|
389 |
SetBTraceFilter(OldTraceFilter,OldTraceFilter); |
|
390 |
||
391 |
Trace.ResizeBuffer(0x100000); |
|
392 |
Trace.Empty(); |
|
393 |
||
394 |
Trace.SetMode(RBTrace::EEnable | RBTrace::EFreeRunning); |
|
395 |
||
396 |
TBool b; |
|
397 |
// b = Trace.SetFilter(BTrace::EThreadIdentification, ETrue); |
|
398 |
// test(b >= 0); |
|
399 |
b = Trace.SetFilter(UTF::EPanic, ETrue); |
|
400 |
test(b >= 0); |
|
401 |
b = Trace.SetFilter(UTF::EError, ETrue); |
|
402 |
test(b >= 0); |
|
403 |
b = Trace.SetFilter(UTF::EBorder, ETrue); |
|
404 |
test(b >= 0); |
|
405 |
||
406 |
b = Trace.SetFilter2(EF32TraceUidEfsrv, ETrue); |
|
407 |
test(b >= 0); |
|
408 |
||
409 |
TestRFileReplace(); |
|
410 |
TestRFsRename(); |
|
411 |
||
412 |
// restore trace settings... |
|
413 |
Trace.SetMode(0); |
|
414 |
SetBTraceFilter(OldTraceFilter,OldTraceFilter); |
|
415 |
Trace.SetMode(savedMode); |
|
416 |
||
417 |
||
418 |
test.Next(_L("Close LDD")); |
|
419 |
Trace.Close(); |
|
420 |
||
421 |
test.End(); |
|
422 |
#endif |
|
423 |
} |
|
424 |