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