os/kernelhwsrv/kerneltest/e32test/debug/d_kern_msg.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
// LDD for testing nanokernel debug trace bits
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
//#undef __REMOVE_PLATSEC_DIAGNOSTICS__
sl@0
    19
#include "platform.h"
sl@0
    20
#include <kernel/kern_priv.h>
sl@0
    21
#include "u32std.h"
sl@0
    22
#include "d_kern_msg.h"
sl@0
    23
sl@0
    24
sl@0
    25
const TInt KMajorVersionNumber=0;
sl@0
    26
const TInt KMinorVersionNumber=1;
sl@0
    27
const TInt KBuildVersionNumber=1;
sl@0
    28
sl@0
    29
class DKernMsgTestFactory : public DLogicalDevice
sl@0
    30
//
sl@0
    31
// Kernel msg test LDD factory
sl@0
    32
//
sl@0
    33
	{
sl@0
    34
public:
sl@0
    35
	DKernMsgTestFactory();
sl@0
    36
	virtual TInt Install();						//overriding pure virtual
sl@0
    37
	virtual void GetCaps(TDes8& aDes) const;	//overriding pure virtual
sl@0
    38
	virtual TInt Create(DLogicalChannelBase*& aChannel);	//overriding pure virtual
sl@0
    39
	};
sl@0
    40
sl@0
    41
class DKernMsgTest : public DLogicalChannelBase
sl@0
    42
//
sl@0
    43
// Trace test LDD channel
sl@0
    44
//
sl@0
    45
	{
sl@0
    46
public:
sl@0
    47
	DKernMsgTest();
sl@0
    48
	~DKernMsgTest();
sl@0
    49
protected:
sl@0
    50
	virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
sl@0
    51
	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
sl@0
    52
sl@0
    53
private:
sl@0
    54
	DThread* iClient;
sl@0
    55
	TInt iShotNumber;
sl@0
    56
	TInt iCurShot;
sl@0
    57
	NTimer iNTimer;
sl@0
    58
	static void NTimerCallBack(TAny*);
sl@0
    59
	};
sl@0
    60
sl@0
    61
sl@0
    62
DECLARE_STANDARD_LDD()
sl@0
    63
	{
sl@0
    64
	//=== load
sl@0
    65
    return new DKernMsgTestFactory;
sl@0
    66
    }
sl@0
    67
sl@0
    68
DKernMsgTestFactory::DKernMsgTestFactory()
sl@0
    69
//
sl@0
    70
// Constructor
sl@0
    71
//
sl@0
    72
    {
sl@0
    73
	//=== load
sl@0
    74
    iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
sl@0
    75
    }
sl@0
    76
sl@0
    77
TInt DKernMsgTestFactory::Create(DLogicalChannelBase*& aChannel)
sl@0
    78
//
sl@0
    79
// Create a new DNKTraceTest on this logical device
sl@0
    80
//
sl@0
    81
    {
sl@0
    82
	//=== open
sl@0
    83
	aChannel=new DKernMsgTest;
sl@0
    84
    return aChannel?KErrNone:KErrNoMemory;
sl@0
    85
    }
sl@0
    86
sl@0
    87
TInt DKernMsgTestFactory::Install()
sl@0
    88
//
sl@0
    89
// Install the LDD - overriding pure virtual
sl@0
    90
//
sl@0
    91
    {
sl@0
    92
	//=== load
sl@0
    93
    return SetName(&KLddName);
sl@0
    94
    }
sl@0
    95
sl@0
    96
sl@0
    97
void DKernMsgTestFactory::GetCaps(TDes8& aDes) const
sl@0
    98
//
sl@0
    99
// Get capabilities - overriding pure virtual
sl@0
   100
//
sl@0
   101
    {
sl@0
   102
    TCapsTraceTestV01 b;
sl@0
   103
    b.iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
sl@0
   104
    Kern::InfoCopy(aDes,(TUint8*)&b,sizeof(b));
sl@0
   105
    }
sl@0
   106
sl@0
   107
DKernMsgTest::DKernMsgTest()
sl@0
   108
	: iNTimer(NTimerCallBack, this)
sl@0
   109
//
sl@0
   110
// Constructor
sl@0
   111
//
sl@0
   112
	//=== open
sl@0
   113
    {
sl@0
   114
	// Get pointer to client threads DThread object
sl@0
   115
	iClient=&Kern::CurrentThread();
sl@0
   116
sl@0
   117
	// Open a reference on client thread so it's control block can't dissapear until
sl@0
   118
	// this driver has finished with it.
sl@0
   119
	// Note, this call to Open can't fail since its the thread we are currently running in
sl@0
   120
	iClient->Open();
sl@0
   121
    }
sl@0
   122
sl@0
   123
/**
sl@0
   124
  Destructor
sl@0
   125
*/
sl@0
   126
DKernMsgTest::~DKernMsgTest()
sl@0
   127
	{
sl@0
   128
	iNTimer.Cancel();
sl@0
   129
	// Close our reference on the client thread
sl@0
   130
	Kern::SafeClose((DObject*&)iClient,NULL);
sl@0
   131
	}
sl@0
   132
sl@0
   133
TInt DKernMsgTest::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
sl@0
   134
//
sl@0
   135
// Create channel
sl@0
   136
//
sl@0
   137
    {
sl@0
   138
sl@0
   139
	//=== open
sl@0
   140
    if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
sl@0
   141
    	return KErrNotSupported;
sl@0
   142
	return KErrNone;
sl@0
   143
	}
sl@0
   144
sl@0
   145
TInt DKernMsgTest::Request(TInt aReqNo, TAny* a1, TAny*)
sl@0
   146
	{
sl@0
   147
	TInt r=KErrNotSupported;
sl@0
   148
	switch (aReqNo)
sl@0
   149
		{
sl@0
   150
		case RKernMsgTest::EControlKDebug:
sl@0
   151
			{
sl@0
   152
sl@0
   153
			TBuf8<1024> msg;
sl@0
   154
			
sl@0
   155
			TInt ret=Kern::ThreadDesRead(iClient,a1,msg,0,0);
sl@0
   156
			if (ret != KErrNone)
sl@0
   157
				return ret;
sl@0
   158
sl@0
   159
			*((char*)msg.Ptr() + msg.Length()) = '\0';
sl@0
   160
sl@0
   161
			Kern::Printf("%s", msg.Ptr());
sl@0
   162
			r = Kern::CurrentThread().iId;
sl@0
   163
sl@0
   164
			}
sl@0
   165
			break;
sl@0
   166
		case RKernMsgTest::EControlIsrContextTest:
sl@0
   167
			{
sl@0
   168
			iShotNumber = (TInt) a1;
sl@0
   169
sl@0
   170
			iCurShot = 0;
sl@0
   171
sl@0
   172
			iNTimer.OneShot(5);
sl@0
   173
			
sl@0
   174
			r = KErrNone; 
sl@0
   175
			}
sl@0
   176
			break;
sl@0
   177
sl@0
   178
		default:
sl@0
   179
			break;
sl@0
   180
		}
sl@0
   181
	return r;
sl@0
   182
	}
sl@0
   183
sl@0
   184
void DKernMsgTest::NTimerCallBack(TAny* ptr)
sl@0
   185
	{
sl@0
   186
	DKernMsgTest* p = (DKernMsgTest*) ptr;
sl@0
   187
sl@0
   188
	if (p->iCurShot++ == p->iShotNumber)
sl@0
   189
		return;
sl@0
   190
sl@0
   191
	Kern::Printf("%d", p->iCurShot);
sl@0
   192
	
sl@0
   193
	p->iNTimer.Again(10);
sl@0
   194
	}