|
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 // e32test\nkern\t_nktrace.cpp |
|
15 // Overview: |
|
16 // Test the KTRACE macros and debug mask related functions. |
|
17 // API Information: |
|
18 // UserSvr::DebugMask(), User::SetDebugMask, KDebugMask(), KDebugNum() |
|
19 // Details: |
|
20 // Set debug masks and verify they are as expected. Test using |
|
21 // UserSvr::DebugMask() & User::SetDebugMask(). |
|
22 // In a kernel level LDD, test the kernel functions using |
|
23 // KDebugMask() & KDebugNum(). |
|
24 // |
|
25 // |
|
26 |
|
27 #include <e32test.h> |
|
28 #include <e32svr.h> |
|
29 #include "nk_trace.h" |
|
30 #include "d_nktrace.h" |
|
31 |
|
32 LOCAL_D RTest test(_L("T_NKTRACE")); |
|
33 |
|
34 void Wait(TInt aSeconds) |
|
35 { |
|
36 while (aSeconds>0) |
|
37 { |
|
38 --aSeconds; |
|
39 User::After(1000000); |
|
40 test.Printf(_L(".")); |
|
41 } |
|
42 } |
|
43 |
|
44 GLDEF_C TInt E32Main() |
|
45 { |
|
46 test.Title(); |
|
47 |
|
48 test.Start(_L("Load LDD")); |
|
49 TInt r=User::LoadLogicalDevice(_L("D_NKTRACE")); |
|
50 test(r==KErrNone || r==KErrAlreadyExists); |
|
51 test.Next(_L("Open channel")); |
|
52 RNKTraceTest traceSys; |
|
53 r=traceSys.Open(); |
|
54 test(r==KErrNone); |
|
55 |
|
56 // verify access to debug mask 0, with and without argument |
|
57 TUint32 initial[8]; |
|
58 TInt i; |
|
59 |
|
60 for (i=0; i<8; i++) |
|
61 initial[i]= UserSvr::DebugMask(i); |
|
62 |
|
63 test.Printf(_L("initial DebugMask value = 0x%08x\n"), initial[0]); |
|
64 TUint32 m = UserSvr::DebugMask(); |
|
65 test(m==initial[0]); |
|
66 User::SetDebugMask(~m); |
|
67 m = UserSvr::DebugMask(0); |
|
68 test(m!=initial[0]); |
|
69 test(m==~initial[0]); |
|
70 |
|
71 // set and verify each of the 8 debug masks |
|
72 User::SetDebugMask(0x12340000, 0); |
|
73 User::SetDebugMask(0x12341111, 1); |
|
74 User::SetDebugMask(0x12342222, 2); |
|
75 User::SetDebugMask(0x12343333, 3); |
|
76 User::SetDebugMask(0x12344444, 4); |
|
77 User::SetDebugMask(0x12345555, 5); |
|
78 User::SetDebugMask(0x12346666, 6); |
|
79 User::SetDebugMask(0x12347777, 7); |
|
80 |
|
81 m = UserSvr::DebugMask(0); |
|
82 test(m==0x12340000); |
|
83 m = UserSvr::DebugMask(1); |
|
84 test(m==0x12341111); |
|
85 m = UserSvr::DebugMask(2); |
|
86 test(m==0x12342222); |
|
87 m = UserSvr::DebugMask(3); |
|
88 test(m==0x12343333); |
|
89 m = UserSvr::DebugMask(4); |
|
90 test(m==0x12344444); |
|
91 m = UserSvr::DebugMask(5); |
|
92 test(m==0x12345555); |
|
93 m = UserSvr::DebugMask(6); |
|
94 test(m==0x12346666); |
|
95 m = UserSvr::DebugMask(7); |
|
96 test(m==0x12347777); |
|
97 |
|
98 // verify correct results when no index argument is given |
|
99 User::SetDebugMask(0xC0000000); |
|
100 m = UserSvr::DebugMask(); |
|
101 test.Printf(_L("UserSvr::DebugMask = 0x%08x\n"), m); |
|
102 test(m==0xC0000000); |
|
103 |
|
104 User::SetDebugMask(0x80000000); |
|
105 m = UserSvr::DebugMask(); |
|
106 test.Printf(_L("UserSvr::DebugMask = 0x%08x\n"), m); |
|
107 test(m==0x80000000); |
|
108 |
|
109 test.Next(_L("Test the Kernel level code...")); |
|
110 User::SetDebugMask(0xC0000000, 0); // set bits 30 & 31 |
|
111 User::SetDebugMask(0x00000008, 1); // set bit 35 |
|
112 User::SetDebugMask(0x00000010, 2); // set bit 68 |
|
113 User::SetDebugMask(0x00000020, 3); // set bit 101 |
|
114 User::SetDebugMask(0x00000100, 4); // set bit 136 |
|
115 User::SetDebugMask(0x00001000, 5); // set bit 172 |
|
116 User::SetDebugMask(0x00000001, 6); // set bit 192 |
|
117 User::SetDebugMask(0x00000040, 7); // set bit 230 |
|
118 |
|
119 // test the KTRACE_OPT macros in server code |
|
120 r=traceSys.KTrace(RNKTraceTest::ETestKTrace); |
|
121 |
|
122 // test the KDebugMask() and KDebugNum() functions in server code |
|
123 r=traceSys.KDebug(RNKTraceTest::ETestKTrace); |
|
124 |
|
125 test.Printf(_L("Kern::Printf() output goes\n")); |
|
126 test.Printf(_L("to the serial port or the \n")); |
|
127 test.Printf(_L("file epocwind.out when \n")); |
|
128 test.Printf(_L("tested on the emulator. \n")); |
|
129 test.Printf(_L("The following results\n")); |
|
130 test.Printf(_L("should be displayed:\n")); |
|
131 |
|
132 test.Printf(_L("Test __KTRACE_OPT macros\n")); |
|
133 test.Printf(_L("KALWAYS\n")); |
|
134 test.Printf(_L("KPANIC\n")); |
|
135 test.Printf(_L("KSCRATCH\n")); |
|
136 test.Printf(_L("Debug bit 35 is set\n")); |
|
137 test.Printf(_L("Debug bit 68 is set\n")); |
|
138 test.Printf(_L("Debug bit 101 is set\n")); |
|
139 test.Printf(_L("Debug bit 136 is set\n")); |
|
140 test.Printf(_L("Debug bit 172 is set\n")); |
|
141 test.Printf(_L("Debug bit 192 is set\n")); |
|
142 test.Printf(_L("Debug bit 230 is set\n")); |
|
143 test.Printf(_L("KTRACE_ALL returned true\n")); |
|
144 |
|
145 // Wait for a while, or for a key press |
|
146 test.Printf(_L("Press a key to continue...")); |
|
147 TRequestStatus keyStat; |
|
148 test.Console()->Read(keyStat); |
|
149 RTimer timer; |
|
150 test(timer.CreateLocal()==KErrNone); |
|
151 TRequestStatus timerStat; |
|
152 timer.After(timerStat,10*1000000); |
|
153 User::WaitForRequest(timerStat,keyStat); |
|
154 TInt key; |
|
155 if(keyStat!=KRequestPending) |
|
156 key = test.Console()->KeyCode(); |
|
157 timer.Cancel(); |
|
158 test.Console()->ReadCancel(); |
|
159 User::WaitForAnyRequest(); |
|
160 |
|
161 test.Printf(_L("\n")); |
|
162 test.Printf(_L("KDebug tests (0)\n")); |
|
163 test.Printf(_L("KDebugMask() = 0xc0000000\n")); |
|
164 test.Printf(_L("KDebugNum(30) = 1\n")); |
|
165 test.Printf(_L("KDebugNum(31) = 1\n")); |
|
166 test.Printf(_L("KDebugNum(3) = 0\n")); |
|
167 test.Printf(_L("KDebugNum(9) = 0\n")); |
|
168 test.Printf(_L("KDebugNum(10000) = 0\n")); |
|
169 test.Printf(_L("KDebugNum(-1) = 1\n")); |
|
170 test.Printf(_L("KDebugNum(-2) = 0\n")); |
|
171 test.Printf(_L("KDebugNum(35) = 1\n")); |
|
172 test.Printf(_L("KDebugNum(36) = 0\n")); |
|
173 test.Printf(_L("KDebugNum(101) = 1\n")); |
|
174 test.Printf(_L("KDebugNum(192) = 1\n")); |
|
175 test.Printf(_L("KDebugNum(230) = 1\n")); |
|
176 |
|
177 // set the debug masks back to the original state |
|
178 for (i=0; i<8; i++) |
|
179 User::SetDebugMask(initial[i], i); |
|
180 |
|
181 m = UserSvr::DebugMask(0); |
|
182 test(m==initial[0]); |
|
183 m = UserSvr::DebugMask(1); |
|
184 test(m==initial[1]); |
|
185 m = UserSvr::DebugMask(2); |
|
186 test(m==initial[2]); |
|
187 m = UserSvr::DebugMask(3); |
|
188 test(m==initial[3]); |
|
189 m = UserSvr::DebugMask(4); |
|
190 test(m==initial[4]); |
|
191 m = UserSvr::DebugMask(5); |
|
192 test(m==initial[5]); |
|
193 m = UserSvr::DebugMask(6); |
|
194 test(m==initial[6]); |
|
195 m = UserSvr::DebugMask(7); |
|
196 test(m==initial[7]); |
|
197 |
|
198 test.End(); |
|
199 |
|
200 return(0); |
|
201 } |
|
202 |