os/kernelhwsrv/kerneltest/e32test/debug/d_kern_msg.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/debug/d_kern_msg.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,194 @@
     1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// LDD for testing nanokernel debug trace bits
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +//#undef __REMOVE_PLATSEC_DIAGNOSTICS__
    1.22 +#include "platform.h"
    1.23 +#include <kernel/kern_priv.h>
    1.24 +#include "u32std.h"
    1.25 +#include "d_kern_msg.h"
    1.26 +
    1.27 +
    1.28 +const TInt KMajorVersionNumber=0;
    1.29 +const TInt KMinorVersionNumber=1;
    1.30 +const TInt KBuildVersionNumber=1;
    1.31 +
    1.32 +class DKernMsgTestFactory : public DLogicalDevice
    1.33 +//
    1.34 +// Kernel msg test LDD factory
    1.35 +//
    1.36 +	{
    1.37 +public:
    1.38 +	DKernMsgTestFactory();
    1.39 +	virtual TInt Install();						//overriding pure virtual
    1.40 +	virtual void GetCaps(TDes8& aDes) const;	//overriding pure virtual
    1.41 +	virtual TInt Create(DLogicalChannelBase*& aChannel);	//overriding pure virtual
    1.42 +	};
    1.43 +
    1.44 +class DKernMsgTest : public DLogicalChannelBase
    1.45 +//
    1.46 +// Trace test LDD channel
    1.47 +//
    1.48 +	{
    1.49 +public:
    1.50 +	DKernMsgTest();
    1.51 +	~DKernMsgTest();
    1.52 +protected:
    1.53 +	virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
    1.54 +	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
    1.55 +
    1.56 +private:
    1.57 +	DThread* iClient;
    1.58 +	TInt iShotNumber;
    1.59 +	TInt iCurShot;
    1.60 +	NTimer iNTimer;
    1.61 +	static void NTimerCallBack(TAny*);
    1.62 +	};
    1.63 +
    1.64 +
    1.65 +DECLARE_STANDARD_LDD()
    1.66 +	{
    1.67 +	//=== load
    1.68 +    return new DKernMsgTestFactory;
    1.69 +    }
    1.70 +
    1.71 +DKernMsgTestFactory::DKernMsgTestFactory()
    1.72 +//
    1.73 +// Constructor
    1.74 +//
    1.75 +    {
    1.76 +	//=== load
    1.77 +    iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
    1.78 +    }
    1.79 +
    1.80 +TInt DKernMsgTestFactory::Create(DLogicalChannelBase*& aChannel)
    1.81 +//
    1.82 +// Create a new DNKTraceTest on this logical device
    1.83 +//
    1.84 +    {
    1.85 +	//=== open
    1.86 +	aChannel=new DKernMsgTest;
    1.87 +    return aChannel?KErrNone:KErrNoMemory;
    1.88 +    }
    1.89 +
    1.90 +TInt DKernMsgTestFactory::Install()
    1.91 +//
    1.92 +// Install the LDD - overriding pure virtual
    1.93 +//
    1.94 +    {
    1.95 +	//=== load
    1.96 +    return SetName(&KLddName);
    1.97 +    }
    1.98 +
    1.99 +
   1.100 +void DKernMsgTestFactory::GetCaps(TDes8& aDes) const
   1.101 +//
   1.102 +// Get capabilities - overriding pure virtual
   1.103 +//
   1.104 +    {
   1.105 +    TCapsTraceTestV01 b;
   1.106 +    b.iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
   1.107 +    Kern::InfoCopy(aDes,(TUint8*)&b,sizeof(b));
   1.108 +    }
   1.109 +
   1.110 +DKernMsgTest::DKernMsgTest()
   1.111 +	: iNTimer(NTimerCallBack, this)
   1.112 +//
   1.113 +// Constructor
   1.114 +//
   1.115 +	//=== open
   1.116 +    {
   1.117 +	// Get pointer to client threads DThread object
   1.118 +	iClient=&Kern::CurrentThread();
   1.119 +
   1.120 +	// Open a reference on client thread so it's control block can't dissapear until
   1.121 +	// this driver has finished with it.
   1.122 +	// Note, this call to Open can't fail since its the thread we are currently running in
   1.123 +	iClient->Open();
   1.124 +    }
   1.125 +
   1.126 +/**
   1.127 +  Destructor
   1.128 +*/
   1.129 +DKernMsgTest::~DKernMsgTest()
   1.130 +	{
   1.131 +	iNTimer.Cancel();
   1.132 +	// Close our reference on the client thread
   1.133 +	Kern::SafeClose((DObject*&)iClient,NULL);
   1.134 +	}
   1.135 +
   1.136 +TInt DKernMsgTest::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
   1.137 +//
   1.138 +// Create channel
   1.139 +//
   1.140 +    {
   1.141 +
   1.142 +	//=== open
   1.143 +    if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
   1.144 +    	return KErrNotSupported;
   1.145 +	return KErrNone;
   1.146 +	}
   1.147 +
   1.148 +TInt DKernMsgTest::Request(TInt aReqNo, TAny* a1, TAny*)
   1.149 +	{
   1.150 +	TInt r=KErrNotSupported;
   1.151 +	switch (aReqNo)
   1.152 +		{
   1.153 +		case RKernMsgTest::EControlKDebug:
   1.154 +			{
   1.155 +
   1.156 +			TBuf8<1024> msg;
   1.157 +			
   1.158 +			TInt ret=Kern::ThreadDesRead(iClient,a1,msg,0,0);
   1.159 +			if (ret != KErrNone)
   1.160 +				return ret;
   1.161 +
   1.162 +			*((char*)msg.Ptr() + msg.Length()) = '\0';
   1.163 +
   1.164 +			Kern::Printf("%s", msg.Ptr());
   1.165 +			r = Kern::CurrentThread().iId;
   1.166 +
   1.167 +			}
   1.168 +			break;
   1.169 +		case RKernMsgTest::EControlIsrContextTest:
   1.170 +			{
   1.171 +			iShotNumber = (TInt) a1;
   1.172 +
   1.173 +			iCurShot = 0;
   1.174 +
   1.175 +			iNTimer.OneShot(5);
   1.176 +			
   1.177 +			r = KErrNone; 
   1.178 +			}
   1.179 +			break;
   1.180 +
   1.181 +		default:
   1.182 +			break;
   1.183 +		}
   1.184 +	return r;
   1.185 +	}
   1.186 +
   1.187 +void DKernMsgTest::NTimerCallBack(TAny* ptr)
   1.188 +	{
   1.189 +	DKernMsgTest* p = (DKernMsgTest*) ptr;
   1.190 +
   1.191 +	if (p->iCurShot++ == p->iShotNumber)
   1.192 +		return;
   1.193 +
   1.194 +	Kern::Printf("%d", p->iCurShot);
   1.195 +	
   1.196 +	p->iNTimer.Again(10);
   1.197 +	}