Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\server\t_ftrace.cpp
19 #include <f32tracedef.h>
23 #include "../../../kernel/eka/include/d32btrace.h"
24 #include "../../../kernel/eka/include/e32btrace.h"
25 #include <utraceefsrv.h>
27 RTest test(_L("T_FTRACE"));
31 void SetBTraceFilter(const TUint32* aNew,TUint32* aOld)
36 TUint32 newBits = *aNew++;
41 if(Trace.SetFilter(category,newBits&1))
42 oldBits |= 0x80000000u;
55 //---------------------------------------------------------------------------------------------------------------------
56 //! @SYMTestCaseID KBASE-T_FTRACE-0001
57 //! @SYMTestCaseDesc Test File Server Tracing of RFile::Replace()
60 //! @SYMTestPriority Medium
62 //! 1. Call RFile::Replace() to create a file
63 //! 2. Get trace data from BTrace and verify that the expected trace data is present
65 //! @SYMTestExpectedResults
66 //! 1. Trace data payload should be as expected, i.e. it should contain the file name, mode etc.
67 //---------------------------------------------------------------------------------------------------------------------
68 void TestRFileReplace()
70 test.Start(_L("Test trace output from creating a file"));
72 TFileName testFileName = _L("File.txt");
74 TheFs.Delete(testFileName);
78 TInt r = file.Replace(TheFs,testFileName,EFileStreamText);
82 TBool funcInFound = EFalse;
83 TBool funcOutFound = EFalse;
89 TInt dataSize = Trace.GetData(record);
92 TUint8* end = record+dataSize;
96 TUint size = record[BTrace::ESizeIndex];
97 TUint flags = record[BTrace::EFlagsIndex];
98 TUint category = record[BTrace::ECategoryIndex];
99 TUint subCategory = record[BTrace::ESubCategoryIndex];
100 TUint8* data = record+4;
104 if(flags&(BTrace::EHeader2Present))
110 if((flags&(BTrace::ETimestampPresent|BTrace::ETimestamp2Present))==(BTrace::ETimestampPresent|BTrace::ETimestamp2Present))
112 buf.AppendFormat(_L8("time:%08x:%08x "),((TUint32*)data)[1],*(TUint32*)data);
116 else if(flags&(BTrace::ETimestampPresent|BTrace::ETimestamp2Present))
118 buf.AppendFormat(_L8("time:%08x "),*(TUint32*)data);
123 if(flags&(BTrace::EContextIdPresent))
125 buf.AppendFormat(_L8("context:%08x "),*(TUint32*)data);
131 buf.AppendFormat(_L8(" "));
134 if(flags&(BTrace::EPcPresent))
136 buf.AppendFormat(_L8("pc:%08x "),*(TUint32*)data);
141 if(flags&(BTrace::EExtraPresent))
147 TUint32 data0 = (size>0) ? *(TUint32*)(data) : 0;
148 TUint32 data1 = (size>4) ? *(TUint32*)(data+4) : 0;
151 des.Set(data+8,size-8);
153 buf.AppendFormat(_L8("size:%d flags:%02x cat:%d,%d data: "),size,flags,category,subCategory);
154 for(TUint i=0; i<size; i+=4)
155 buf.AppendFormat(_L8("%08x "),*(TUint32*)(data+i));
158 test(buf.MaxLength() >= (buf.Length()*2));
159 RDebug::RawPrint(buf.Expand());
162 if (category == UTF::EBorder && subCategory == 0 && data0 == EF32TraceUidEfsrv)
164 if (data1 == UTraceModuleEfsrv::EFileReplace)
166 TInt sessionHandle = (size>8) ? *(TUint32*)(data+8) : 0;
167 TUint32 fileMode = (size>12) ? *(TUint32*)(data+12) : 0;
168 TInt fileNameLen = (size>16) ? *(TUint32*)(data+16) : 0;
169 fileNameLen/= 2; // convert to unicode length
170 TText16* fileName = (TText16*) ((size>20) ? (data+20) : NULL);
172 test(sessionHandle == TheFs.Handle());
173 test(fileMode == EFileStreamText);
174 test(fileNameLen == testFileName.Length());
175 TPtrC16 fileNamePtr (fileName, fileNameLen);
176 test(fileName != NULL);
177 test(testFileName.Compare(fileNamePtr) == 0);
180 else if (data1 == UTraceModuleEfsrv::EFileReplaceReturn)
182 TInt retCode = (size>8) ? *(TUint32*)(data+8) : 0;
183 TInt subsessionHandle = (size>12) ? *(TUint32*)(data+12) : 0;
185 test(retCode == KErrNone);
186 test(subsessionHandle == file.SubSessionHandle());
187 funcOutFound = ETrue;
191 record = BTrace::NextRecord(record);
197 TheFs.Delete(testFileName);
203 //---------------------------------------------------------------------------------------------------------------------
204 //! @SYMTestCaseID KBASE-T_FTRACE-0002
205 //! @SYMTestCaseDesc Test File Server Tracing of RFs::Rename()
207 //! @SYMPREQ PREQ1617
208 //! @SYMTestPriority Medium
210 //! 1. Call RFile::Replace() to create a file
211 //! 2. Close the file
212 //! 3. Call RFs::Rename to rename the file
213 //! 4. Get trace data from BTrace and verify that the expected trace data is present
215 //! @SYMTestExpectedResults
216 //! 1. Trace data payload should be as expected, i.e. it should contain both file names, etc.
217 //---------------------------------------------------------------------------------------------------------------------
220 test.Start(_L("Test trace output from renaming a file"));
222 TFileName testFileName1 = _L("File1.txt");
223 TFileName testFileName2 = _L("File2.txt");
225 TheFs.Delete(testFileName1);
226 TheFs.Delete(testFileName2);
228 TInt r = file.Replace(TheFs,testFileName1,EFileStreamText);
229 test(r==KErrNone || KErrAlreadyExists);
234 r = TheFs.Rename(testFileName1, testFileName2);
238 TBool funcInFound = EFalse;
239 TBool funcOutFound = EFalse;
245 TInt dataSize = Trace.GetData(record);
248 TUint8* end = record+dataSize;
252 TUint size = record[BTrace::ESizeIndex];
253 TUint flags = record[BTrace::EFlagsIndex];
254 TUint category = record[BTrace::ECategoryIndex];
255 TUint subCategory = record[BTrace::ESubCategoryIndex];
256 TUint8* data = record+4;
260 if(flags&(BTrace::EHeader2Present))
266 if((flags&(BTrace::ETimestampPresent|BTrace::ETimestamp2Present))==(BTrace::ETimestampPresent|BTrace::ETimestamp2Present))
268 buf.AppendFormat(_L8("time:%08x:%08x "),((TUint32*)data)[1],*(TUint32*)data);
272 else if(flags&(BTrace::ETimestampPresent|BTrace::ETimestamp2Present))
274 buf.AppendFormat(_L8("time:%08x "),*(TUint32*)data);
279 if(flags&(BTrace::EContextIdPresent))
281 buf.AppendFormat(_L8("context:%08x "),*(TUint32*)data);
287 buf.AppendFormat(_L8(" "));
290 if(flags&(BTrace::EPcPresent))
292 buf.AppendFormat(_L8("pc:%08x "),*(TUint32*)data);
297 if(flags&(BTrace::EExtraPresent))
303 TUint32 data0 = (size>0) ? *(TUint32*)(data) : 0;
304 TUint32 data1 = (size>4) ? *(TUint32*)(data+4) : 0;
307 des.Set(data+8,size-8);
309 buf.AppendFormat(_L8("size:%d flags:%02x cat:%d,%d data: "),size,flags,category,subCategory);
310 for(TUint i=0; i<size; i+=4)
311 buf.AppendFormat(_L8("%08x "),*(TUint32*)(data+i));
314 test(buf.MaxLength() >= (buf.Length()*2));
315 RDebug::RawPrint(buf.Expand());
318 if (category == UTF::EBorder && subCategory == 0 && data0 == EF32TraceUidEfsrv)
320 TUint8* recData = data+8;
321 if (data1 == UTraceModuleEfsrv::EFsRename)
323 TInt sessionHandle = *(TUint32*) recData; recData+= 4;
325 TInt fileNameLen1 = *(TUint32*) recData; recData+= 4;
326 TText16* fileName1 = (TText16*) recData; recData+= ((fileNameLen1 +4) & ~3);
328 TInt fileNameLen2 = *(TUint32*) recData; recData+= 4;
329 TText16* fileName2 = (TText16*) recData; recData+= fileNameLen2;
331 fileNameLen1/= 2; // convert to unicode length
332 fileNameLen2/= 2; // convert to unicode length
335 test(sessionHandle == TheFs.Handle());
337 test(fileNameLen1 == testFileName1.Length());
338 TPtrC16 fileNamePtr1 (fileName1, fileNameLen1);
339 test(fileName1 != NULL);
340 test(testFileName1.Compare(fileNamePtr1) == 0);
342 test(fileNameLen2 == testFileName2.Length());
343 TPtrC16 fileNamePtr2 (fileName2, fileNameLen2);
344 test(fileName2 != NULL);
345 test(testFileName2.Compare(fileNamePtr2) == 0);
349 else if (data1 == UTraceModuleEfsrv::EFsRenameReturn)
351 TInt retCode = (size>8) ? *(TUint32*)(data+8) : 0;
353 test(retCode == KErrNone);
355 funcOutFound = ETrue;
359 record = BTrace::NextRecord(record);
368 TheFs.Delete(testFileName1);
369 TheFs.Delete(testFileName2);
375 // By default, file server trace-points are only compiled in in debug mode
380 test.Start(_L("Open LDD"));
385 TUint32 OldTraceFilter[8] = {0};
387 TUint savedMode = Trace.Mode();
388 SetBTraceFilter(OldTraceFilter,OldTraceFilter);
390 Trace.ResizeBuffer(0x100000);
393 Trace.SetMode(RBTrace::EEnable | RBTrace::EFreeRunning);
396 // b = Trace.SetFilter(BTrace::EThreadIdentification, ETrue);
398 b = Trace.SetFilter(UTF::EPanic, ETrue);
400 b = Trace.SetFilter(UTF::EError, ETrue);
402 b = Trace.SetFilter(UTF::EBorder, ETrue);
405 b = Trace.SetFilter2(EF32TraceUidEfsrv, ETrue);
411 // restore trace settings...
413 SetBTraceFilter(OldTraceFilter,OldTraceFilter);
414 Trace.SetMode(savedMode);
417 test.Next(_L("Close LDD"));