sl@0: // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\server\t_ftrace.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "t_server.h" sl@0: sl@0: #include "../../../kernel/eka/include/d32btrace.h" sl@0: #include "../../../kernel/eka/include/e32btrace.h" sl@0: #include sl@0: sl@0: RTest test(_L("T_FTRACE")); sl@0: sl@0: RBTrace Trace; sl@0: sl@0: void SetBTraceFilter(const TUint32* aNew,TUint32* aOld) sl@0: { sl@0: TUint category = 0; sl@0: do sl@0: { sl@0: TUint32 newBits = *aNew++; sl@0: TUint32 oldBits = 0; sl@0: do sl@0: { sl@0: oldBits >>= 1; sl@0: if(Trace.SetFilter(category,newBits&1)) sl@0: oldBits |= 0x80000000u; sl@0: newBits >>= 1; sl@0: ++category; sl@0: } sl@0: while(category&31); sl@0: if(aOld) sl@0: *aOld++ = oldBits; sl@0: } sl@0: while(category<256); sl@0: } sl@0: sl@0: sl@0: sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-T_FTRACE-0001 sl@0: //! @SYMTestCaseDesc Test File Server Tracing of RFile::Replace() sl@0: //! @SYMTestType UT sl@0: //! @SYMPREQ PREQ1617 sl@0: //! @SYMTestPriority Medium sl@0: //! @SYMTestActions sl@0: //! 1. Call RFile::Replace() to create a file sl@0: //! 2. Get trace data from BTrace and verify that the expected trace data is present sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. Trace data payload should be as expected, i.e. it should contain the file name, mode etc. sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: void TestRFileReplace() sl@0: { sl@0: test.Start(_L("Test trace output from creating a file")); sl@0: RFile file; sl@0: TFileName testFileName = _L("File.txt"); sl@0: sl@0: TheFs.Delete(testFileName); sl@0: sl@0: Trace.Empty(); sl@0: sl@0: TInt r = file.Replace(TheFs,testFileName,EFileStreamText); sl@0: test(r==KErrNone); sl@0: sl@0: sl@0: TBool funcInFound = EFalse; sl@0: TBool funcOutFound = EFalse; sl@0: sl@0: TBuf8<1024> buf; sl@0: for(;;) sl@0: { sl@0: TUint8* record; sl@0: TInt dataSize = Trace.GetData(record); sl@0: if(!dataSize) sl@0: break; sl@0: TUint8* end = record+dataSize; sl@0: sl@0: while(record0) ? *(TUint32*)(data) : 0; sl@0: TUint32 data1 = (size>4) ? *(TUint32*)(data+4) : 0; sl@0: TPtrC8 des(0,0); sl@0: if(size>=8) sl@0: des.Set(data+8,size-8); sl@0: sl@0: buf.AppendFormat(_L8("size:%d flags:%02x cat:%d,%d data: "),size,flags,category,subCategory); sl@0: for(TUint i=0; i= (buf.Length()*2)); sl@0: RDebug::RawPrint(buf.Expand()); sl@0: sl@0: sl@0: if (category == UTF::EBorder && subCategory == 0 && data0 == EF32TraceUidEfsrv) sl@0: { sl@0: if (data1 == UTraceModuleEfsrv::EFileReplace) sl@0: { sl@0: TInt sessionHandle = (size>8) ? *(TUint32*)(data+8) : 0; sl@0: TUint32 fileMode = (size>12) ? *(TUint32*)(data+12) : 0; sl@0: TInt fileNameLen = (size>16) ? *(TUint32*)(data+16) : 0; sl@0: fileNameLen/= 2; // convert to unicode length sl@0: TText16* fileName = (TText16*) ((size>20) ? (data+20) : NULL); sl@0: sl@0: test(sessionHandle == TheFs.Handle()); sl@0: test(fileMode == EFileStreamText); sl@0: test(fileNameLen == testFileName.Length()); sl@0: TPtrC16 fileNamePtr (fileName, fileNameLen); sl@0: test(fileName != NULL); sl@0: test(testFileName.Compare(fileNamePtr) == 0); sl@0: funcInFound = ETrue; sl@0: } sl@0: else if (data1 == UTraceModuleEfsrv::EFileReplaceReturn) sl@0: { sl@0: TInt retCode = (size>8) ? *(TUint32*)(data+8) : 0; sl@0: TInt subsessionHandle = (size>12) ? *(TUint32*)(data+12) : 0; sl@0: sl@0: test(retCode == KErrNone); sl@0: test(subsessionHandle == file.SubSessionHandle()); sl@0: funcOutFound = ETrue; sl@0: } sl@0: } sl@0: sl@0: record = BTrace::NextRecord(record); sl@0: } sl@0: Trace.DataUsed(); sl@0: } sl@0: sl@0: file.Close(); sl@0: TheFs.Delete(testFileName); sl@0: sl@0: test (funcInFound); sl@0: test (funcOutFound); sl@0: } sl@0: sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-T_FTRACE-0002 sl@0: //! @SYMTestCaseDesc Test File Server Tracing of RFs::Rename() sl@0: //! @SYMTestType UT sl@0: //! @SYMPREQ PREQ1617 sl@0: //! @SYMTestPriority Medium sl@0: //! @SYMTestActions sl@0: //! 1. Call RFile::Replace() to create a file sl@0: //! 2. Close the file sl@0: //! 3. Call RFs::Rename to rename the file sl@0: //! 4. Get trace data from BTrace and verify that the expected trace data is present sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. Trace data payload should be as expected, i.e. it should contain both file names, etc. sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: void TestRFsRename() sl@0: { sl@0: test.Start(_L("Test trace output from renaming a file")); sl@0: RFile file; sl@0: TFileName testFileName1 = _L("File1.txt"); sl@0: TFileName testFileName2 = _L("File2.txt"); sl@0: sl@0: TheFs.Delete(testFileName1); sl@0: TheFs.Delete(testFileName2); sl@0: sl@0: TInt r = file.Replace(TheFs,testFileName1,EFileStreamText); sl@0: test(r==KErrNone || KErrAlreadyExists); sl@0: file.Close(); sl@0: sl@0: Trace.Empty(); sl@0: sl@0: r = TheFs.Rename(testFileName1, testFileName2); sl@0: test(r==KErrNone); sl@0: sl@0: sl@0: TBool funcInFound = EFalse; sl@0: TBool funcOutFound = EFalse; sl@0: sl@0: TBuf8<1024> buf; sl@0: for(;;) sl@0: { sl@0: TUint8* record; sl@0: TInt dataSize = Trace.GetData(record); sl@0: if(!dataSize) sl@0: break; sl@0: TUint8* end = record+dataSize; sl@0: sl@0: while(record0) ? *(TUint32*)(data) : 0; sl@0: TUint32 data1 = (size>4) ? *(TUint32*)(data+4) : 0; sl@0: TPtrC8 des(0,0); sl@0: if(size>=8) sl@0: des.Set(data+8,size-8); sl@0: sl@0: buf.AppendFormat(_L8("size:%d flags:%02x cat:%d,%d data: "),size,flags,category,subCategory); sl@0: for(TUint i=0; i= (buf.Length()*2)); sl@0: RDebug::RawPrint(buf.Expand()); sl@0: sl@0: sl@0: if (category == UTF::EBorder && subCategory == 0 && data0 == EF32TraceUidEfsrv) sl@0: { sl@0: TUint8* recData = data+8; sl@0: if (data1 == UTraceModuleEfsrv::EFsRename) sl@0: { sl@0: TInt sessionHandle = *(TUint32*) recData; recData+= 4; sl@0: sl@0: TInt fileNameLen1 = *(TUint32*) recData; recData+= 4; sl@0: TText16* fileName1 = (TText16*) recData; recData+= ((fileNameLen1 +4) & ~3); sl@0: sl@0: TInt fileNameLen2 = *(TUint32*) recData; recData+= 4; sl@0: TText16* fileName2 = (TText16*) recData; recData+= fileNameLen2; sl@0: sl@0: fileNameLen1/= 2; // convert to unicode length sl@0: fileNameLen2/= 2; // convert to unicode length sl@0: sl@0: sl@0: test(sessionHandle == TheFs.Handle()); sl@0: sl@0: test(fileNameLen1 == testFileName1.Length()); sl@0: TPtrC16 fileNamePtr1 (fileName1, fileNameLen1); sl@0: test(fileName1 != NULL); sl@0: test(testFileName1.Compare(fileNamePtr1) == 0); sl@0: sl@0: test(fileNameLen2 == testFileName2.Length()); sl@0: TPtrC16 fileNamePtr2 (fileName2, fileNameLen2); sl@0: test(fileName2 != NULL); sl@0: test(testFileName2.Compare(fileNamePtr2) == 0); sl@0: sl@0: funcInFound = ETrue; sl@0: } sl@0: else if (data1 == UTraceModuleEfsrv::EFsRenameReturn) sl@0: { sl@0: TInt retCode = (size>8) ? *(TUint32*)(data+8) : 0; sl@0: sl@0: test(retCode == KErrNone); sl@0: sl@0: funcOutFound = ETrue; sl@0: } sl@0: } sl@0: sl@0: record = BTrace::NextRecord(record); sl@0: } sl@0: Trace.DataUsed(); sl@0: } sl@0: sl@0: sl@0: test (funcInFound); sl@0: test (funcOutFound); sl@0: sl@0: TheFs.Delete(testFileName1); sl@0: TheFs.Delete(testFileName2); sl@0: } sl@0: sl@0: void CallTestsL() sl@0: { sl@0: sl@0: // By default, file server trace-points are only compiled in in debug mode sl@0: #if defined(_DEBUG) sl@0: test.Title(); sl@0: TInt r; sl@0: sl@0: test.Start(_L("Open LDD")); sl@0: r = Trace.Open(); sl@0: test(r == KErrNone); sl@0: sl@0: sl@0: TUint32 OldTraceFilter[8] = {0}; sl@0: sl@0: TUint savedMode = Trace.Mode(); sl@0: SetBTraceFilter(OldTraceFilter,OldTraceFilter); sl@0: sl@0: Trace.ResizeBuffer(0x100000); sl@0: Trace.Empty(); sl@0: sl@0: Trace.SetMode(RBTrace::EEnable | RBTrace::EFreeRunning); sl@0: sl@0: TBool b; sl@0: // b = Trace.SetFilter(BTrace::EThreadIdentification, ETrue); sl@0: // test(b >= 0); sl@0: b = Trace.SetFilter(UTF::EPanic, ETrue); sl@0: test(b >= 0); sl@0: b = Trace.SetFilter(UTF::EError, ETrue); sl@0: test(b >= 0); sl@0: b = Trace.SetFilter(UTF::EBorder, ETrue); sl@0: test(b >= 0); sl@0: sl@0: b = Trace.SetFilter2(EF32TraceUidEfsrv, ETrue); sl@0: test(b >= 0); sl@0: sl@0: TestRFileReplace(); sl@0: TestRFsRename(); sl@0: sl@0: // restore trace settings... sl@0: Trace.SetMode(0); sl@0: SetBTraceFilter(OldTraceFilter,OldTraceFilter); sl@0: Trace.SetMode(savedMode); sl@0: sl@0: sl@0: test.Next(_L("Close LDD")); sl@0: Trace.Close(); sl@0: sl@0: test.End(); sl@0: #endif sl@0: } sl@0: