traceservices/tracefw/utf_trace_api/unit_test/devicedriver/src/utracedrv.cpp
changeset 0 08ec8eefde2f
child 23 26645d81f48d
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32\drivers\trace\btrace.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <kern_priv.h>
       
    19 #include <platform.h>
       
    20 #include <d32utrace.h>
       
    21 #include <e32utrace.h>
       
    22 
       
    23 
       
    24 //
       
    25 // Device driver
       
    26 //
       
    27 
       
    28 class DUTraceFactory : public DLogicalDevice
       
    29 	{
       
    30 public:
       
    31 	virtual TInt Install();
       
    32 	virtual void GetCaps(TDes8& aDes) const;
       
    33 	virtual TInt Create(DLogicalChannelBase*& aChannel);
       
    34 	};
       
    35 
       
    36 
       
    37 class DUTraceChannel : public DLogicalChannelBase
       
    38 	{
       
    39 public:
       
    40 	DUTraceChannel();
       
    41 	virtual ~DUTraceChannel();
       
    42 	//	Inherited from DObject
       
    43 	virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
       
    44 	// Inherited from DLogicalChannelBase
       
    45 	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
       
    46 	virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
       
    47 	//
       
    48 	static void WaitCallback(TAny* aSelf);
       
    49 
       
    50 	TInt TestTraces(TInt& aFailed);
       
    51 	TInt KernelBench();
       
    52 private:
       
    53 	DThread* iClient;
       
    54 	TRequestStatus*	iWaitRequest;
       
    55 	TDfc iWaitDfc;
       
    56 	};
       
    57 
       
    58 
       
    59 //
       
    60 // DBTraceFactory
       
    61 //
       
    62 
       
    63 TInt DUTraceFactory::Install()
       
    64 	{
       
    65 	return SetName(&RUTrace::Name());
       
    66 	}
       
    67 
       
    68 void DUTraceFactory::GetCaps(TDes8& aDes) const
       
    69 	{
       
    70 	Kern::InfoCopy(aDes,0,0);
       
    71 	}
       
    72 
       
    73 TInt DUTraceFactory::Create(DLogicalChannelBase*& aChannel)
       
    74 	{
       
    75 	aChannel=new DUTraceChannel();
       
    76 	if(!aChannel)
       
    77 		return KErrNoMemory;
       
    78 	return KErrNone;
       
    79 	}
       
    80 
       
    81 
       
    82 //
       
    83 // DBTraceChannel
       
    84 //
       
    85 
       
    86 DUTraceChannel::DUTraceChannel()
       
    87 	: iWaitDfc(WaitCallback,this,Kern::DfcQue1(),7)
       
    88 	{
       
    89 	}
       
    90 
       
    91 DUTraceChannel::~DUTraceChannel()
       
    92 	{
       
    93 	}
       
    94 
       
    95 TInt DUTraceChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
       
    96 	{
       
    97 	iClient = &Kern::CurrentThread();
       
    98 	return KErrNone;
       
    99 	}
       
   100 
       
   101 
       
   102 TInt DUTraceChannel::RequestUserHandle(DThread* aThread, TOwnerType aType)
       
   103 	{
       
   104 	if (aType!=EOwnerThread || aThread!=iClient)
       
   105 		return KErrAccessDenied;
       
   106 	return KErrNone;
       
   107 	}
       
   108 
       
   109 void DUTraceChannel::WaitCallback(TAny* aSelf)
       
   110 	{
       
   111 	Kern::RequestComplete(((DUTraceChannel*)aSelf)->iClient,((DUTraceChannel*)aSelf)->iWaitRequest,KErrNone);
       
   112 	}
       
   113 
       
   114 TInt DUTraceChannel::Request(TInt aReqNo, TAny* a1, TAny* /*a2*/)
       
   115 	{
       
   116 	TInt r = KErrNone;
       
   117 	switch(aReqNo)
       
   118 		{
       
   119 	case RUTrace::ETestUTrace:
       
   120 		{
       
   121 		r = TestTraces((TInt&)a1);
       
   122 		return r;
       
   123 		}
       
   124 	default:
       
   125 		break;
       
   126 		}
       
   127 	return KErrNotSupported;
       
   128 	}
       
   129 
       
   130 TInt DUTraceChannel::TestTraces(TInt& aFailed)
       
   131 	{
       
   132 	_LIT(KAnyBuf, "Kernel side, my any buf string size");
       
   133 	TBufC<16> BufPtr(KAnyBuf);
       
   134 	aFailed = 0;
       
   135 	TBool logged = EFalse;
       
   136 	for(TInt pc = 0; pc <= 1; pc++)
       
   137 		{
       
   138 		for(TInt context = 0; context <= 1; context++)
       
   139 			{
       
   140 			TUTrace trace(KDebug, KBinary, context,pc);
       
   141 			logged = trace.Trace();
       
   142 			if(!logged) aFailed++;
       
   143 			trace.Trace(333);
       
   144 			if(!logged) aFailed++;
       
   145 			trace.Trace(333,444);
       
   146 			if(!logged) aFailed++;
       
   147 			trace.Trace(333,444,555);
       
   148 			if(!logged) aFailed++;
       
   149 			trace.Trace(BufPtr.Ptr(), BufPtr.Size());
       
   150 			if(!logged) aFailed++;
       
   151 			trace.Printf("dfgfdgf");
       
   152 			if(!logged) aFailed++;
       
   153 
       
   154 			logged = TUTrace::TracePrimary(KDebug, KBinary, context,pc);
       
   155 			if(!logged) aFailed++;
       
   156 			logged = TUTrace::TracePrimary(KDebug, KBinary, context,pc,333);
       
   157 			if(!logged) aFailed++;
       
   158 			logged = TUTrace::TracePrimary(KDebug, KBinary, context,pc,333,444);
       
   159 			if(!logged) aFailed++;
       
   160 			logged = TUTrace::TracePrimary(KDebug, KBinary, context,pc,333,444,555);
       
   161 			if(!logged) aFailed++;
       
   162 			logged = TUTrace::TracePrimary(KDebug, KBinary, context,pc,&KAnyBuf, sizeof(KAnyBuf));
       
   163 			if(!logged) aFailed++;
       
   164 			logged = TUTrace::PrintfPrimary(KDebug, context,pc,"dfgfdgf");
       
   165 			if(!logged) aFailed++;
       
   166 
       
   167 			TUint32 secondary = 3333;
       
   168 			logged = TUTrace::Trace(KDebug, secondary, KBinary, context,pc);
       
   169 			if(!logged) aFailed++;
       
   170 			logged = TUTrace::Trace(KDebug, secondary, KBinary, context,pc,333);
       
   171 			if(!logged) aFailed++;
       
   172 			logged = TUTrace::Trace(KDebug, secondary, KBinary, context,pc,333,444);
       
   173 			if(!logged) aFailed++;
       
   174 			logged = TUTrace::Trace(KDebug, secondary, KBinary, context,pc,&KAnyBuf, sizeof(KAnyBuf));
       
   175 			if(!logged) aFailed++;
       
   176 			}
       
   177 		}
       
   178 	return logged;
       
   179 	}
       
   180 TInt DUTraceChannel::KernelBench()
       
   181 	{
       
   182 	return 0;
       
   183 	}
       
   184 
       
   185 
       
   186 DECLARE_STANDARD_LDD()
       
   187 {
       
   188 	return new DUTraceFactory;
       
   189 }
       
   190