os/kernelhwsrv/kerneltest/e32test/debug/t_perflogger.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) 2005-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
// Kernel Performance Logger test
sl@0
    15
// Uses helper LDD for performing actual logging from the kernel side.
sl@0
    16
// See 
sl@0
    17
// 
sl@0
    18
//
sl@0
    19
sl@0
    20
/**
sl@0
    21
 @file
sl@0
    22
*/
sl@0
    23
sl@0
    24
sl@0
    25
#include <e32std.h>
sl@0
    26
#include <e32std_private.h>
sl@0
    27
#include <e32cons.h>
sl@0
    28
#include <e32test.h>
sl@0
    29
#include <e32math.h>
sl@0
    30
sl@0
    31
sl@0
    32
#include "t_perflogger.h"
sl@0
    33
#include "t_perflogger_drv.h"
sl@0
    34
sl@0
    35
sl@0
    36
//-------------------------------------------------------------------------------------
sl@0
    37
sl@0
    38
//-- logging subcategoty test tags
sl@0
    39
const TUint8    KLogSubCat_UserThread   = 0x11;
sl@0
    40
const TUint8    KLogSubCat_KernelThread = 0x12;
sl@0
    41
const TUint8    KLogSubCat_ISR          = 0x13;
sl@0
    42
const TUint8    KLogSubCat_IDFC         = 0x14;
sl@0
    43
sl@0
    44
sl@0
    45
//-------------------------------------------------------------------------------------
sl@0
    46
sl@0
    47
RTest   test(_L("T_PerfLogger"));
sl@0
    48
TInt64  rndSeed;
sl@0
    49
sl@0
    50
//-------------------------------------------------------------------------------------
sl@0
    51
sl@0
    52
/**
sl@0
    53
Print out the logging record.
sl@0
    54
@param aTraceLayout unrolled trace record structure
sl@0
    55
*/
sl@0
    56
void  PrintTraceRecord(const TTraceLayout& aTraceLayout)
sl@0
    57
	{
sl@0
    58
    TBuf<256> printBuf;
sl@0
    59
    
sl@0
    60
    printBuf.Format(_L("Record: Size:%d, Flags:0x%02x, Cat:%d, SubCat:%d "), aTraceLayout.iSize, aTraceLayout.iFlags, aTraceLayout.iCategory, aTraceLayout.iSubCategory);
sl@0
    61
	
sl@0
    62
    TUint flags = aTraceLayout.iFlags;
sl@0
    63
	
sl@0
    64
    if(flags&(BTrace::EHeader2Present))
sl@0
    65
        printBuf.AppendFormat(_L("Header2:0x%08x "), aTraceLayout.iHeader2);
sl@0
    66
	
sl@0
    67
    if(flags & (BTrace::ETimestampPresent))
sl@0
    68
        printBuf.AppendFormat(_L("Timestamp:0x%x "), aTraceLayout.iTimestamp);
sl@0
    69
	
sl@0
    70
    if(flags & (BTrace::ETimestamp2Present))
sl@0
    71
        printBuf.AppendFormat(_L("Timestamp2:0x%x "), aTraceLayout.iTimestamp2);
sl@0
    72
	
sl@0
    73
    if(flags & (BTrace::EContextIdPresent))
sl@0
    74
        printBuf.AppendFormat(_L("Context:0x%08x "), aTraceLayout.iContext);
sl@0
    75
	
sl@0
    76
    if(flags & (BTrace::EPcPresent))
sl@0
    77
        printBuf.AppendFormat(_L("PC: 0x%08x "),  aTraceLayout.iPC);
sl@0
    78
	
sl@0
    79
    if(flags & (BTrace::EExtraPresent))
sl@0
    80
        printBuf.AppendFormat(_L("Extra: 0x%08x "),  aTraceLayout.iExtra);
sl@0
    81
	
sl@0
    82
    printBuf.Append(_L("| "));
sl@0
    83
    for(TInt i=0; i< aTraceLayout.iDataWords; ++i)
sl@0
    84
		{
sl@0
    85
        printBuf.AppendFormat(_L(" 0x%08x"), aTraceLayout.ipData[i]);    
sl@0
    86
		}
sl@0
    87
    
sl@0
    88
    printBuf.Append(_L("\n"));
sl@0
    89
    test.Printf(printBuf);
sl@0
    90
	
sl@0
    91
	}
sl@0
    92
sl@0
    93
//-------------------------------------------------------------------------------------
sl@0
    94
sl@0
    95
/**
sl@0
    96
	Get logging trace from the kernel trace engine and optionally check if it corresponds to the 
sl@0
    97
	TTestLogCtrl structure fields. Actually, the logging trace in our case shall be the result of the 
sl@0
    98
	test helper LDD worr, that in turn, is controlled by the data in TTestLogCtrl structure.
sl@0
    99
sl@0
   100
  @param  aTrace          ref. to the kernel trace engine LDD.
sl@0
   101
  @param  apControlStruct if not NULL obtained trace fields checked against fields of this structure.
sl@0
   102
  
sl@0
   103
*/
sl@0
   104
void GetParseRecordData(RBTrace& aTrace, const TTestLogCtrl* apControlStruct = NULL)
sl@0
   105
	{
sl@0
   106
    TUint8*         record;
sl@0
   107
    TTraceLayout    traceLayout;
sl@0
   108
	
sl@0
   109
	for(TInt i=0; ;++i)
sl@0
   110
		{
sl@0
   111
        //-- get raw trace record
sl@0
   112
        TInt dataSize = aTrace.GetData(record);
sl@0
   113
		
sl@0
   114
        if(i != 0 && !dataSize)
sl@0
   115
            break; //-- no more data
sl@0
   116
        
sl@0
   117
        //-- check if we get log data at all at the very beginning
sl@0
   118
        if(i == 0 && !dataSize)
sl@0
   119
			{
sl@0
   120
			if(!apControlStruct)
sl@0
   121
				{//-- it's ok, no check
sl@0
   122
                break;
sl@0
   123
				}
sl@0
   124
            else
sl@0
   125
				{//-- panic if there is no log data, but we are required to get some.
sl@0
   126
                if(apControlStruct->iLogsNum > 0)
sl@0
   127
					{
sl@0
   128
                    test.Printf(_L("GetParseRecordData() No trace data found!\n"));
sl@0
   129
                    test(0);
sl@0
   130
					}
sl@0
   131
				}
sl@0
   132
			}
sl@0
   133
        
sl@0
   134
		
sl@0
   135
        TUint8* end = record+dataSize;
sl@0
   136
        TUint8* currPos = record;
sl@0
   137
        TInt    nRecords = 0;
sl@0
   138
		TUint nBytes = 0;
sl@0
   139
		
sl@0
   140
        //-- parser the record, print out fields and optionally check the correspondence to the fields of the control structure.
sl@0
   141
        for(; currPos<end; currPos+=nBytes)
sl@0
   142
			{
sl@0
   143
            
sl@0
   144
            nBytes = ParseTraceRecord(currPos ,traceLayout);
sl@0
   145
            test(nBytes >0 );
sl@0
   146
            
sl@0
   147
            //-- skip possible loggings that we didn't make
sl@0
   148
            if(traceLayout.iCategory != BTrace::EKernPerfLog)
sl@0
   149
                continue;
sl@0
   150
            
sl@0
   151
            ++nRecords;
sl@0
   152
			
sl@0
   153
            //-- print the record out
sl@0
   154
            PrintTraceRecord(traceLayout);
sl@0
   155
sl@0
   156
			//-- check the obtained record structure
sl@0
   157
			if(apControlStruct)
sl@0
   158
				{
sl@0
   159
				test(traceLayout.iCategory    == apControlStruct->iCategory);
sl@0
   160
				test(traceLayout.iSubCategory == apControlStruct->iSubCategory);
sl@0
   161
				
sl@0
   162
				if(traceLayout.iDataWords > 1)  //-- we have at least 1 word of user data (1 is for TickCount)
sl@0
   163
					test(traceLayout.ipData[0] == apControlStruct->iUserData);
sl@0
   164
				
sl@0
   165
				if(traceLayout.iDataWords > 2)  //-- we have 2 words of user data (1 is for TickCount)
sl@0
   166
					test(traceLayout.ipData[1] == apControlStruct->iUserData2);
sl@0
   167
				
sl@0
   168
				}
sl@0
   169
            
sl@0
   170
			}
sl@0
   171
		
sl@0
   172
        //-- check number of trace records obtained
sl@0
   173
        if(apControlStruct)
sl@0
   174
			{
sl@0
   175
            test(nRecords == apControlStruct->iLogsNum);
sl@0
   176
			}
sl@0
   177
		
sl@0
   178
        //-- release data buffer.
sl@0
   179
        aTrace.DataUsed();
sl@0
   180
		}
sl@0
   181
	}
sl@0
   182
sl@0
   183
sl@0
   184
//---------------------------------------------------------------------------------
sl@0
   185
sl@0
   186
/**
sl@0
   187
	Parse logging record, converting it from the raw representation to the unrolled data 
sl@0
   188
	structure.
sl@0
   189
sl@0
   190
	@param  apRecord     points to the buffer with the raw trace record
sl@0
   191
	@param  aTraceLayout here parsed record will bre returned
sl@0
   192
  
sl@0
   193
    @return sise of the record, bytes
sl@0
   194
*/
sl@0
   195
TUint  ParseTraceRecord(const TUint8* apRecord, TTraceLayout& aTraceLayout)
sl@0
   196
	{
sl@0
   197
    aTraceLayout.iSize          = apRecord[BTrace::ESizeIndex];    
sl@0
   198
    aTraceLayout.iFlags         = apRecord[BTrace::EFlagsIndex];
sl@0
   199
    aTraceLayout.iCategory      = apRecord[BTrace::ECategoryIndex];
sl@0
   200
    aTraceLayout.iSubCategory   = apRecord[BTrace::ESubCategoryIndex];
sl@0
   201
	
sl@0
   202
    const TUint flags= aTraceLayout.iFlags;   
sl@0
   203
	TInt size = aTraceLayout.iSize;
sl@0
   204
    const TUint32* pData = (const TUint32*)(apRecord+4);
sl@0
   205
	
sl@0
   206
    size -= 4; //-- count header
sl@0
   207
	
sl@0
   208
    //-- process header flags and appropriate fields of the record
sl@0
   209
    if(flags&(BTrace::EHeader2Present))
sl@0
   210
		{
sl@0
   211
        aTraceLayout.iHeader2 = *pData++;   
sl@0
   212
        size -= sizeof(TUint32);
sl@0
   213
        test(size >= 0);
sl@0
   214
		}
sl@0
   215
	
sl@0
   216
    if(flags & (BTrace::ETimestampPresent))
sl@0
   217
		{
sl@0
   218
        aTraceLayout.iTimestamp = *pData++;
sl@0
   219
        size -= sizeof(TUint32);
sl@0
   220
        test(size >= 0);
sl@0
   221
		}
sl@0
   222
	
sl@0
   223
    if(flags & (BTrace::ETimestamp2Present))
sl@0
   224
		{
sl@0
   225
        aTraceLayout.iTimestamp2 = *pData++;
sl@0
   226
        size -= sizeof(TUint32);
sl@0
   227
        test(size >= 0);
sl@0
   228
		}   
sl@0
   229
	
sl@0
   230
	if(flags & (BTrace::EContextIdPresent))
sl@0
   231
		{
sl@0
   232
		aTraceLayout.iContext = *pData++;
sl@0
   233
		size -= sizeof(TUint32);
sl@0
   234
        test(size >= 0);
sl@0
   235
		}
sl@0
   236
	
sl@0
   237
	if(flags & (BTrace::EPcPresent))
sl@0
   238
		{
sl@0
   239
		aTraceLayout.iPC = *pData++;	
sl@0
   240
		size -= sizeof(TUint32);
sl@0
   241
        test(size >= 0);
sl@0
   242
		}
sl@0
   243
	
sl@0
   244
	if(flags & (BTrace::EExtraPresent))
sl@0
   245
		{
sl@0
   246
		aTraceLayout.iExtra = *pData++;	
sl@0
   247
		size -= sizeof(TUint32);
sl@0
   248
        test(size >= 0);
sl@0
   249
		}
sl@0
   250
	
sl@0
   251
    //-- process user data if present
sl@0
   252
    test(size >= 0);
sl@0
   253
    test(size % sizeof(TUint32) == 0);
sl@0
   254
	
sl@0
   255
    aTraceLayout.iDataWords = size / sizeof(TUint32);
sl@0
   256
    aTraceLayout.ipData = (aTraceLayout.iDataWords!=0) ? pData : NULL;
sl@0
   257
	
sl@0
   258
    return aTraceLayout.iSize;
sl@0
   259
	}
sl@0
   260
sl@0
   261
//---------------------------------------------------------------------------------
sl@0
   262
//! @SYMTestCaseID          KBASE-T_PERFLOGGER-0055
sl@0
   263
//! @SYMTestType            UT
sl@0
   264
//! @SYMPREQ                PREQ1030
sl@0
   265
//! @SYMTestCaseDesc        Tests logging from different contexts: user thread, ISR, Kernel thread and IDFC. 
sl@0
   266
//!                         The main functionality is performed by test heller LDD, "d_perflogger_test" that acually calls the logging function from different contexts 
sl@0
   267
//!                         following the commands from user application.
sl@0
   268
//!
sl@0
   269
//! @SYMTestActions         0   setup the data structures that specify the logging parameters.
sl@0
   270
//!                         1   call RKPLoggerTestHelper::MakeLogFromUserThread() this is a synchronous operation. Performs logging from the user thread context.
sl@0
   271
//!                         1.1 Parse the log record data and ensure that the logged information matches the data we passed to the helper LDD.
sl@0
   272
//!
sl@0
   273
//!                         2   call RKPLoggerTestHelper::MakeLogFromISR() this is asynchronous operation. Performs logging from the ISR context.
sl@0
   274
//!                         2.1 Wait for operation to complete, validate the completion status.
sl@0
   275
//!                         2.2 Parse the log record data and ensure that the logged information matches the data we passed to the helper LDD.
sl@0
   276
//!
sl@0
   277
//!
sl@0
   278
//!                         3   call RKPLoggerTestHelper::MakeLogFromDFC() this is asynchronous operation. Performs logging from the Kernel thread context (DFC).
sl@0
   279
//!                         3.1 Wait for operation to complete, validate the completion status.
sl@0
   280
//!                         3.2 Parse the log record data and ensure that the logged information matches the data we passed to the helper LDD.
sl@0
   281
//!
sl@0
   282
//!                         4   call RKPLoggerTestHelper::MakeLogFromIDFC() this is asynchronous operation. Performs logging from the IDFC.
sl@0
   283
//!                         4.1 Wait for operation to complete, validate the completion status.
sl@0
   284
//!                         4.2 Parse the log record data and ensure that the logged information matches the data we passed to the helper LDD.
sl@0
   285
//!
sl@0
   286
//!                         5.  Make scattered overlapped logging from ISR, DFC & IDFC simultaneously, ensure that this work.
sl@0
   287
//!
sl@0
   288
//! @SYMTestExpectedResults return if the performace logger behaves as expected, panic otherwise
sl@0
   289
//! @SYMTestPriority        High
sl@0
   290
//! @SYMTestStatus          Implemented
sl@0
   291
//---------------------------------------------------------------------------------
sl@0
   292
void TestPerfLogger(RBTrace &aTrace)
sl@0
   293
	{
sl@0
   294
    TInt    nRes;
sl@0
   295
    
sl@0
   296
    const TUint32   KLogUserData  = 0xBAAABEEF; //-- just for testing
sl@0
   297
    const TUint32   KLogUserData2 = 0x11FFDDCC; //-- just for testing
sl@0
   298
	
sl@0
   299
	
sl@0
   300
    test.Next(_L("testing kernel performance logger functionality\n"));
sl@0
   301
	
sl@0
   302
    RKPLoggerTestHelper testHelperLDD;  //-- helper test driver
sl@0
   303
    CleanupClosePushL(testHelperLDD);
sl@0
   304
	
sl@0
   305
    nRes = testHelperLDD.Open(TVersion(1,0,1)); //-- open test helper ldd for a logger
sl@0
   306
    test(nRes == KErrNone);
sl@0
   307
	
sl@0
   308
    //---
sl@0
   309
    TTestLogCtrl   logCtrl_UserThread;
sl@0
   310
    TTestLogCtrl   logCtrl_ISR;
sl@0
   311
    TTestLogCtrl   logCtrl_DFC;
sl@0
   312
    TTestLogCtrl   logCtrl_IDFC;
sl@0
   313
	
sl@0
   314
	
sl@0
   315
    TRequestStatus rqStatLogFromISR;
sl@0
   316
    TRequestStatus rqStatLogFromDFC;
sl@0
   317
    TRequestStatus rqStatLogFromIDFC;
sl@0
   318
	
sl@0
   319
	
sl@0
   320
    //-- setup log control structures
sl@0
   321
    logCtrl_UserThread.iLogsNum     = 3;
sl@0
   322
    logCtrl_UserThread.iCategory    = BTrace::EKernPerfLog;
sl@0
   323
    logCtrl_UserThread.iSubCategory = KLogSubCat_UserThread;
sl@0
   324
    logCtrl_UserThread.iUserData    = KLogUserData;
sl@0
   325
    logCtrl_UserThread.iUserData2   = KLogUserData2;
sl@0
   326
	
sl@0
   327
	
sl@0
   328
    logCtrl_ISR.iLogsNum        = 3;
sl@0
   329
    logCtrl_ISR.iCategory       = BTrace::EKernPerfLog;
sl@0
   330
    logCtrl_ISR.iSubCategory    = KLogSubCat_ISR;
sl@0
   331
    logCtrl_ISR.iUserData       = KLogUserData;
sl@0
   332
    logCtrl_ISR.iUserData2      = KLogUserData2;
sl@0
   333
	
sl@0
   334
	
sl@0
   335
    logCtrl_DFC.iLogsNum        = 3;
sl@0
   336
    logCtrl_DFC.iCategory       = BTrace::EKernPerfLog;
sl@0
   337
    logCtrl_DFC.iSubCategory    = KLogSubCat_KernelThread;
sl@0
   338
    logCtrl_DFC.iUserData       = KLogUserData;
sl@0
   339
    logCtrl_DFC.iUserData2      = KLogUserData2;
sl@0
   340
	
sl@0
   341
	
sl@0
   342
    logCtrl_IDFC.iLogsNum       = 3;
sl@0
   343
    logCtrl_IDFC.iCategory      = BTrace::EKernPerfLog;
sl@0
   344
    logCtrl_IDFC.iSubCategory   = KLogSubCat_IDFC;
sl@0
   345
    logCtrl_IDFC.iUserData      = KLogUserData;
sl@0
   346
    logCtrl_IDFC.iUserData2     = KLogUserData2;
sl@0
   347
	
sl@0
   348
	
sl@0
   349
	
sl@0
   350
    test.Printf(_L("Testing logging from user thread\n"));
sl@0
   351
    //============================================================
sl@0
   352
    //-- 1. make logging from user thread, this is a synchronous operation
sl@0
   353
    nRes = testHelperLDD.MakeLogFromUserThread(logCtrl_UserThread);
sl@0
   354
    test(nRes == KErrNone);
sl@0
   355
	
sl@0
   356
    //-- 1.1 check the results
sl@0
   357
    GetParseRecordData(aTrace, &logCtrl_UserThread);
sl@0
   358
	
sl@0
   359
	
sl@0
   360
    test.Printf(_L("Testing logging from ISR\n"));
sl@0
   361
    //============================================================
sl@0
   362
    //-- 2. make logging from ISR, this is asynchronous operation
sl@0
   363
    testHelperLDD.MakeLogFromISR(rqStatLogFromISR, logCtrl_ISR);
sl@0
   364
    User::WaitForRequest(rqStatLogFromISR);
sl@0
   365
    test(rqStatLogFromISR.Int() == KErrNone);
sl@0
   366
	
sl@0
   367
    //-- 2.1 check the results
sl@0
   368
    GetParseRecordData(aTrace, &logCtrl_ISR);
sl@0
   369
	
sl@0
   370
    test.Printf(_L("Testing logging from DFC\n"));
sl@0
   371
    //============================================================
sl@0
   372
    //-- 3. make logging from DFC kennel thread, this is asynchronous operation
sl@0
   373
    testHelperLDD.MakeLogFromDFC(rqStatLogFromDFC, logCtrl_DFC);
sl@0
   374
    User::WaitForRequest(rqStatLogFromDFC);
sl@0
   375
    test(rqStatLogFromDFC.Int() == KErrNone);
sl@0
   376
	
sl@0
   377
    //-- 3.1 check the results
sl@0
   378
    GetParseRecordData(aTrace, &logCtrl_DFC);
sl@0
   379
	
sl@0
   380
    test.Printf(_L("Testing logging from IDFC\n"));
sl@0
   381
    //============================================================
sl@0
   382
    //-- 4. make logging from IDFC, this is asynchronous operation
sl@0
   383
    testHelperLDD.MakeLogFromIDFC(rqStatLogFromIDFC, logCtrl_IDFC);
sl@0
   384
    User::WaitForRequest(rqStatLogFromIDFC);
sl@0
   385
    test(rqStatLogFromIDFC.Int() == KErrNone);
sl@0
   386
	
sl@0
   387
    //-- 4.1 check the results
sl@0
   388
    GetParseRecordData(aTrace, &logCtrl_IDFC);
sl@0
   389
	
sl@0
   390
	
sl@0
   391
    test.Printf(_L("Testing overlapped logging from ISR, DFC & IDFC\n"));
sl@0
   392
    //============================================================
sl@0
   393
    //-- 5. make logging from ISR, DFC and IDFC simultaneously
sl@0
   394
	
sl@0
   395
    //-- use random numbers for number and period of loggings  
sl@0
   396
    logCtrl_ISR.iLogsNum        = URnd(16)+1;
sl@0
   397
    logCtrl_ISR.iLogPeriodTick  = URnd(20)+1;
sl@0
   398
	
sl@0
   399
    logCtrl_DFC.iLogsNum        = URnd(16)+1;
sl@0
   400
    logCtrl_DFC.iLogPeriodTick  = URnd(20)+1;
sl@0
   401
	
sl@0
   402
    logCtrl_IDFC.iLogsNum       = URnd(16)+1;
sl@0
   403
    logCtrl_IDFC.iLogPeriodTick = URnd(20)+1;
sl@0
   404
	
sl@0
   405
    //-- start logging
sl@0
   406
    testHelperLDD.MakeLogFromISR(rqStatLogFromISR, logCtrl_ISR);
sl@0
   407
    testHelperLDD.MakeLogFromDFC(rqStatLogFromDFC, logCtrl_DFC);
sl@0
   408
    testHelperLDD.MakeLogFromIDFC(rqStatLogFromIDFC, logCtrl_IDFC);
sl@0
   409
	
sl@0
   410
    //-- wait for logging to finish
sl@0
   411
    User::WaitForRequest(rqStatLogFromISR);
sl@0
   412
    User::WaitForRequest(rqStatLogFromDFC);
sl@0
   413
    User::WaitForRequest(rqStatLogFromIDFC);
sl@0
   414
	
sl@0
   415
    GetParseRecordData(aTrace);
sl@0
   416
	
sl@0
   417
	
sl@0
   418
    CleanupStack::PopAndDestroy(1); //-- testHelperLDD
sl@0
   419
	
sl@0
   420
}
sl@0
   421
sl@0
   422
sl@0
   423
//---------------------------------------------------------------------------------
sl@0
   424
//! @SYMTestCaseID          KBASE-T_PERFLOGGER-0056
sl@0
   425
//! @SYMTestType            UT
sl@0
   426
//! @SYMPREQ                PREQ1030
sl@0
   427
//! @SYMTestCaseDesc        Test of PERF_LOG0, PERF_LOG1, PERF_LOG macros performed by helper LDD
sl@0
   428
//! @SYMTestActions         Calls helper LDD API that in turn implies using PERF_LOG0, PERF_LOG1, PERF_LOG macros by helper LDD
sl@0
   429
//! @SYMTestExpectedResults return if the performace logger behaves as expected, panic otherwise
sl@0
   430
//! @SYMTestPriority        High
sl@0
   431
//! @SYMTestStatus          Implemented
sl@0
   432
//---------------------------------------------------------------------------------
sl@0
   433
void TestMacros(RBTrace &aTrace)
sl@0
   434
	{
sl@0
   435
    TInt    nRes;
sl@0
   436
    
sl@0
   437
    const TUint32   KLogUserData  = 0xBAAABEEF; //-- just for testing
sl@0
   438
    const TUint32   KLogUserData2 = 0x11FFDDCC; //-- just for testing
sl@0
   439
	
sl@0
   440
	
sl@0
   441
    test.Next(_L("Unit test for different macros\n"));
sl@0
   442
	
sl@0
   443
    RKPLoggerTestHelper testHelperLDD;  //-- helper test driver
sl@0
   444
    CleanupClosePushL(testHelperLDD);
sl@0
   445
	
sl@0
   446
    nRes = testHelperLDD.Open(TVersion(1,0,1)); //-- open test helper ldd for a logger
sl@0
   447
    test(nRes == KErrNone);
sl@0
   448
	
sl@0
   449
    //---
sl@0
   450
    TTestLogCtrl   logCtrl;
sl@0
   451
	
sl@0
   452
    //-- setup log control structures
sl@0
   453
    logCtrl.iLogsNum     = 1;
sl@0
   454
    logCtrl.iCategory    = BTrace::EKernPerfLog;
sl@0
   455
    logCtrl.iSubCategory = KLogSubCat_UserThread;
sl@0
   456
    logCtrl.iUserData    = KLogUserData;
sl@0
   457
    logCtrl.iUserData2   = KLogUserData2;
sl@0
   458
	
sl@0
   459
    //-- make logging from user thread using different macros, PERF_LOG0, PERF_LOG1, PERF_LOG 
sl@0
   460
    //-- see the helper driver
sl@0
   461
    nRes = testHelperLDD.TestDifferentMacros(logCtrl);
sl@0
   462
    test(nRes == KErrNone);
sl@0
   463
	
sl@0
   464
    //-- print out the results
sl@0
   465
    GetParseRecordData(aTrace);
sl@0
   466
	
sl@0
   467
	
sl@0
   468
    CleanupStack::PopAndDestroy(1); //-- testHelperLDD
sl@0
   469
	
sl@0
   470
	}
sl@0
   471
sl@0
   472
//---------------------------------------------------------------------------------
sl@0
   473
void MainL(void)
sl@0
   474
	{
sl@0
   475
    test.Start(_L("Kern Perf Logger tests"));
sl@0
   476
    Initialise();
sl@0
   477
	
sl@0
   478
	
sl@0
   479
    RBTrace trace;
sl@0
   480
	TInt error = trace.Open();
sl@0
   481
    test(error == KErrNone);
sl@0
   482
	
sl@0
   483
	trace.Empty();
sl@0
   484
	trace.SetFilter(BTrace::EThreadIdentification,0);
sl@0
   485
	
sl@0
   486
    
sl@0
   487
    
sl@0
   488
    //-- actually, for hardware platforms, the testing category and trace enabling 
sl@0
   489
    //-- may be set up in appropriate "header.iby" file
sl@0
   490
    trace.SetMode(RBTrace::EEnable);
sl@0
   491
    trace.SetFilter(BTrace::EKernPerfLog, ETrue);
sl@0
   492
    
sl@0
   493
    //-- unit-test for PERF_LOG macros
sl@0
   494
    TestMacros(trace);
sl@0
   495
	
sl@0
   496
    //-- functionality test
sl@0
   497
    TestPerfLogger(trace); 
sl@0
   498
	
sl@0
   499
    trace.Close();
sl@0
   500
	
sl@0
   501
    Finalise();
sl@0
   502
	test.End();
sl@0
   503
	}
sl@0
   504
sl@0
   505
sl@0
   506
//---------------------------------------------------------------------------------
sl@0
   507
//! @SYMTestCaseID          KBASE-T_PERFLOGGER-0162
sl@0
   508
//! @SYMTestType            UT
sl@0
   509
//! @SYMPREQ                PREQ1030
sl@0
   510
//! @SYMTestCaseDesc        Load test helper LDD and check the result
sl@0
   511
//! @SYMTestActions         load specified LDD by calling User::LoadLogicalDevice()
sl@0
   512
//! @SYMTestExpectedResults return if helper LDD is loaded OK, panic otherwise
sl@0
   513
//! @SYMTestPriority        High
sl@0
   514
//! @SYMTestStatus          Implemented
sl@0
   515
//---------------------------------------------------------------------------------
sl@0
   516
void Initialise()
sl@0
   517
	{
sl@0
   518
    rndSeed = Math::Random();
sl@0
   519
    
sl@0
   520
    //-- load device drivers 
sl@0
   521
    TInt nRes;
sl@0
   522
	
sl@0
   523
    test.Printf(_L("Loading test helper LDD...\n"));
sl@0
   524
    nRes = User::LoadLogicalDevice(KPLoggerHelperTestDrv);
sl@0
   525
    test(nRes == KErrNone || nRes == KErrAlreadyExists);
sl@0
   526
	}
sl@0
   527
sl@0
   528
/** Finalise environment */
sl@0
   529
void Finalise(void)
sl@0
   530
	{
sl@0
   531
	}
sl@0
   532
sl@0
   533
sl@0
   534
sl@0
   535
/**
sl@0
   536
    Main 	
sl@0
   537
*/
sl@0
   538
GLDEF_C TInt E32Main() 
sl@0
   539
	{
sl@0
   540
	CTrapCleanup* cleanup=CTrapCleanup::New() ; // get clean-up stack
sl@0
   541
    
sl@0
   542
	TRAPD(r,MainL());
sl@0
   543
	
sl@0
   544
    delete cleanup ; // destroy clean-up stack
sl@0
   545
	
sl@0
   546
    return r;
sl@0
   547
	
sl@0
   548
	}
sl@0
   549
sl@0
   550
//-------------------------------------------------------------------------------------
sl@0
   551
sl@0
   552
TUint URnd(TUint aMin, TUint aMax)
sl@0
   553
	{
sl@0
   554
    test(aMin < aMax);
sl@0
   555
    TUint uRes;
sl@0
   556
	
sl@0
   557
    do
sl@0
   558
		{
sl@0
   559
        uRes = Math::Rand(rndSeed) % aMax;
sl@0
   560
		}while(uRes < aMin);
sl@0
   561
		
sl@0
   562
		return uRes;
sl@0
   563
	}
sl@0
   564
sl@0
   565
TUint URnd(TUint aMax)
sl@0
   566
	{
sl@0
   567
    return Math::Rand(rndSeed) % aMax;
sl@0
   568
	}
sl@0
   569
sl@0
   570
sl@0
   571
sl@0
   572
sl@0
   573
sl@0
   574
sl@0
   575
sl@0
   576
sl@0
   577
sl@0
   578
sl@0
   579