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