sl@0
|
1 |
// Copyright (c) 1996-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 |
// e32test\system\t_exc.cpp
|
sl@0
|
15 |
// In WINS T_EXC should be run from the command line only.
|
sl@0
|
16 |
// T_EXC will not complete when run under the MSDEV debugger.
|
sl@0
|
17 |
// Overview:
|
sl@0
|
18 |
// Test and verify exception handling.
|
sl@0
|
19 |
// API Information:
|
sl@0
|
20 |
// User::SetExceptionHandler, User::RaiseException
|
sl@0
|
21 |
// Details:
|
sl@0
|
22 |
// - Create a global semaphore, verify success.
|
sl@0
|
23 |
// - Test exceptions with no handlers: verify that divide by zero and
|
sl@0
|
24 |
// User::RaiseException() panic as expected.
|
sl@0
|
25 |
// - Test exceptions with handlers: verify that divide by zero and
|
sl@0
|
26 |
// User::RaiseException() call their exception handlers as expected.
|
sl@0
|
27 |
// - Test exception raised in exception handler: verify divide by zero
|
sl@0
|
28 |
// causes exception and an exception in the exception handler causes
|
sl@0
|
29 |
// a panic.
|
sl@0
|
30 |
// - Verify the results are as expected when a thread causes a divide
|
sl@0
|
31 |
// by zero exception.
|
sl@0
|
32 |
// - Get context of interrupted thread, get context of thread waiting
|
sl@0
|
33 |
// for request, get context of suspended thread. Verify results are
|
sl@0
|
34 |
// as expected.
|
sl@0
|
35 |
// Platforms/Drives/Compatibility:
|
sl@0
|
36 |
// All.
|
sl@0
|
37 |
// Assumptions/Requirement/Pre-requisites:
|
sl@0
|
38 |
// Failures and causes:
|
sl@0
|
39 |
// Base Port information:
|
sl@0
|
40 |
//
|
sl@0
|
41 |
//
|
sl@0
|
42 |
|
sl@0
|
43 |
#include <e32test.h>
|
sl@0
|
44 |
#include <e32svr.h>
|
sl@0
|
45 |
#include "u32std.h"
|
sl@0
|
46 |
|
sl@0
|
47 |
#pragma warning( disable : 4723 ) // disable divide by zero warnings
|
sl@0
|
48 |
|
sl@0
|
49 |
#ifdef __MARM__
|
sl@0
|
50 |
void UndefinedInstruction();
|
sl@0
|
51 |
#endif
|
sl@0
|
52 |
|
sl@0
|
53 |
LOCAL_D RTest test(_L("T_EXC"));
|
sl@0
|
54 |
RDebug debug;
|
sl@0
|
55 |
|
sl@0
|
56 |
TInt gCount=0;
|
sl@0
|
57 |
RSemaphore gSem;
|
sl@0
|
58 |
TBool outsideExcSupported=ETrue;
|
sl@0
|
59 |
|
sl@0
|
60 |
void excHandler(TExcType /*aType*/)
|
sl@0
|
61 |
//
|
sl@0
|
62 |
// An exception handler that does nothing
|
sl@0
|
63 |
//
|
sl@0
|
64 |
{
|
sl@0
|
65 |
|
sl@0
|
66 |
gCount++;
|
sl@0
|
67 |
}
|
sl@0
|
68 |
|
sl@0
|
69 |
void excHandlerFault(TExcType aType)
|
sl@0
|
70 |
//
|
sl@0
|
71 |
// An exception handler that causes an exception
|
sl@0
|
72 |
//
|
sl@0
|
73 |
{
|
sl@0
|
74 |
debug.Print(_L("Handling exception %d and causing exception in handler"), aType);
|
sl@0
|
75 |
gCount++;
|
sl@0
|
76 |
|
sl@0
|
77 |
#ifdef __MARM__
|
sl@0
|
78 |
// There is no Divide By Zero exception on the Arm
|
sl@0
|
79 |
// Use undefined instruction instead
|
sl@0
|
80 |
UndefinedInstruction();
|
sl@0
|
81 |
#else
|
sl@0
|
82 |
// Cause a div by zero exception
|
sl@0
|
83 |
volatile int i=0;
|
sl@0
|
84 |
volatile int j=10;
|
sl@0
|
85 |
int l=j/i;
|
sl@0
|
86 |
for (i=0; i<l; i++)
|
sl@0
|
87 |
;
|
sl@0
|
88 |
#endif
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
TInt waitSemaphore(TAny *)
|
sl@0
|
92 |
//
|
sl@0
|
93 |
// Sleep
|
sl@0
|
94 |
//
|
sl@0
|
95 |
{
|
sl@0
|
96 |
RSemaphore s;
|
sl@0
|
97 |
TInt r=s.OpenGlobal(_L("A SEMAPHORE"));
|
sl@0
|
98 |
test(r==KErrNone);
|
sl@0
|
99 |
s.Wait();
|
sl@0
|
100 |
return KErrNone;
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
TInt garfield(TAny *)
|
sl@0
|
104 |
//
|
sl@0
|
105 |
// Sleep for a long time
|
sl@0
|
106 |
//
|
sl@0
|
107 |
{
|
sl@0
|
108 |
|
sl@0
|
109 |
User::After(10000000);
|
sl@0
|
110 |
return KErrNone;
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
TInt odie(TAny *)
|
sl@0
|
114 |
//
|
sl@0
|
115 |
// Run round in circles
|
sl@0
|
116 |
//
|
sl@0
|
117 |
{
|
sl@0
|
118 |
FOREVER
|
sl@0
|
119 |
;
|
sl@0
|
120 |
}
|
sl@0
|
121 |
|
sl@0
|
122 |
TInt divideByZero(TAny *)
|
sl@0
|
123 |
//
|
sl@0
|
124 |
// Divide by zero
|
sl@0
|
125 |
//
|
sl@0
|
126 |
{
|
sl@0
|
127 |
#ifdef __MARM__
|
sl@0
|
128 |
// There is no Divide By Zero exception on the Arm
|
sl@0
|
129 |
// Use undefined instruction instead
|
sl@0
|
130 |
UndefinedInstruction();
|
sl@0
|
131 |
return(KErrNone);
|
sl@0
|
132 |
#else
|
sl@0
|
133 |
#ifdef __WINS__
|
sl@0
|
134 |
#pragma warning( disable : 4189 ) // local variable is initialized but not referenced
|
sl@0
|
135 |
#endif
|
sl@0
|
136 |
volatile int i=0, j=10;
|
sl@0
|
137 |
volatile int l=j/i;
|
sl@0
|
138 |
FOREVER
|
sl@0
|
139 |
;
|
sl@0
|
140 |
#endif
|
sl@0
|
141 |
}
|
sl@0
|
142 |
#pragma warning( default : 4723 )
|
sl@0
|
143 |
|
sl@0
|
144 |
TInt raiseException(TAny *)
|
sl@0
|
145 |
//
|
sl@0
|
146 |
// Raise an exception
|
sl@0
|
147 |
//
|
sl@0
|
148 |
{
|
sl@0
|
149 |
|
sl@0
|
150 |
User::RaiseException(EExcIntegerDivideByZero);
|
sl@0
|
151 |
User::After(500000);
|
sl@0
|
152 |
return KErrNone;
|
sl@0
|
153 |
}
|
sl@0
|
154 |
|
sl@0
|
155 |
void test1()
|
sl@0
|
156 |
{
|
sl@0
|
157 |
|
sl@0
|
158 |
test.Start(_L("Create a thread (divideByZero)"));
|
sl@0
|
159 |
User::SetJustInTime(EFalse);
|
sl@0
|
160 |
RThread t;
|
sl@0
|
161 |
TRequestStatus s;
|
sl@0
|
162 |
TInt r;
|
sl@0
|
163 |
r=t.Create(_L("divideByZero"),divideByZero,KDefaultStackSize,KDefaultStackSize,KDefaultStackSize,NULL);
|
sl@0
|
164 |
test(r==KErrNone);
|
sl@0
|
165 |
t.Logon(s);
|
sl@0
|
166 |
test.Next(_L("Resume and wait for div by zero exception"));
|
sl@0
|
167 |
t.Resume();
|
sl@0
|
168 |
User::WaitForRequest(s);
|
sl@0
|
169 |
test.Printf(_L("Exit Type %d\r\n"),(TInt)t.ExitType());
|
sl@0
|
170 |
test(t.ExitType()==EExitPanic);
|
sl@0
|
171 |
test(t.ExitReason()==ECausedException);
|
sl@0
|
172 |
CLOSE_AND_WAIT(t);
|
sl@0
|
173 |
//
|
sl@0
|
174 |
|
sl@0
|
175 |
test.Next(_L("Create a thread (raiseException)"));
|
sl@0
|
176 |
r=t.Create(_L("raiseException"),raiseException,KDefaultStackSize,KDefaultStackSize,KDefaultStackSize,NULL);
|
sl@0
|
177 |
test(r==KErrNone);
|
sl@0
|
178 |
t.Logon(s);
|
sl@0
|
179 |
test.Next(_L("Resume, and wait for raise exception"));
|
sl@0
|
180 |
t.Resume();
|
sl@0
|
181 |
User::WaitForRequest(s);
|
sl@0
|
182 |
test(t.ExitType()==EExitPanic);
|
sl@0
|
183 |
test(t.ExitReason()==ECausedException);
|
sl@0
|
184 |
CLOSE_AND_WAIT(t);
|
sl@0
|
185 |
|
sl@0
|
186 |
test.End();
|
sl@0
|
187 |
}
|
sl@0
|
188 |
|
sl@0
|
189 |
TInt divideByZero2(TAny *)
|
sl@0
|
190 |
{
|
sl@0
|
191 |
#ifdef __MARM__
|
sl@0
|
192 |
// There is no Div By Zero exception on the Arm so we use a data abort instead
|
sl@0
|
193 |
User::SetExceptionHandler(&excHandler, KExceptionAbort|KExceptionFault|KExceptionUserInterrupt);
|
sl@0
|
194 |
#else
|
sl@0
|
195 |
User::SetExceptionHandler(&excHandler, KExceptionInteger);
|
sl@0
|
196 |
#endif
|
sl@0
|
197 |
return divideByZero(0);
|
sl@0
|
198 |
}
|
sl@0
|
199 |
|
sl@0
|
200 |
TInt raiseException2(TAny *)
|
sl@0
|
201 |
{
|
sl@0
|
202 |
User::SetExceptionHandler(&excHandler, KExceptionInteger);
|
sl@0
|
203 |
return raiseException(0);
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
void test2()
|
sl@0
|
207 |
{
|
sl@0
|
208 |
|
sl@0
|
209 |
test.Start(_L("Create a thread (odie)"));
|
sl@0
|
210 |
RThread t;
|
sl@0
|
211 |
TRequestStatus s;
|
sl@0
|
212 |
TInt r;
|
sl@0
|
213 |
|
sl@0
|
214 |
test.Next(_L("Create a thread (divideByZero)"));
|
sl@0
|
215 |
r=t.Create(_L("divideByZero"),divideByZero2,KDefaultStackSize,KDefaultStackSize,KDefaultStackSize,NULL);
|
sl@0
|
216 |
test(r==KErrNone);
|
sl@0
|
217 |
t.Logon(s);
|
sl@0
|
218 |
gCount=0;
|
sl@0
|
219 |
|
sl@0
|
220 |
test.Next(_L("Resume, and wait for 10 divide by zero exceptions"));
|
sl@0
|
221 |
t.Resume();
|
sl@0
|
222 |
while (gCount<10)
|
sl@0
|
223 |
User::After(500000);
|
sl@0
|
224 |
test(gCount>=10);
|
sl@0
|
225 |
test.Next(_L("Kill the thread"));
|
sl@0
|
226 |
t.Kill(666);
|
sl@0
|
227 |
User::WaitForRequest(s);
|
sl@0
|
228 |
test(t.ExitType()==EExitKill);
|
sl@0
|
229 |
test(t.ExitReason()==666);
|
sl@0
|
230 |
CLOSE_AND_WAIT(t);
|
sl@0
|
231 |
//
|
sl@0
|
232 |
test.Next(_L("Create a thread (raiseException2)"));
|
sl@0
|
233 |
r=t.Create(_L("raiseException2"),raiseException2,KDefaultStackSize,KDefaultStackSize,KDefaultStackSize,NULL);
|
sl@0
|
234 |
test(r==KErrNone);
|
sl@0
|
235 |
t.Logon(s);
|
sl@0
|
236 |
gCount=0;
|
sl@0
|
237 |
test.Next(_L("Resume"));
|
sl@0
|
238 |
t.Resume();
|
sl@0
|
239 |
test.Next(_L("Wait for thread to finish"));
|
sl@0
|
240 |
User::WaitForRequest(s);
|
sl@0
|
241 |
test.Next(_L("Test thread raised an exception on itself"));
|
sl@0
|
242 |
test(gCount==1);
|
sl@0
|
243 |
test(t.ExitType()==EExitKill);
|
sl@0
|
244 |
test(t.ExitReason()==KErrNone);
|
sl@0
|
245 |
CLOSE_AND_WAIT(t);
|
sl@0
|
246 |
|
sl@0
|
247 |
test.End();
|
sl@0
|
248 |
}
|
sl@0
|
249 |
|
sl@0
|
250 |
TInt divideByZero3(TAny *)
|
sl@0
|
251 |
{
|
sl@0
|
252 |
#ifdef __MARM__
|
sl@0
|
253 |
User::SetExceptionHandler(&excHandlerFault, KExceptionAbort|KExceptionFault|KExceptionUserInterrupt);
|
sl@0
|
254 |
#else
|
sl@0
|
255 |
User::SetExceptionHandler(&excHandlerFault, KExceptionInteger);
|
sl@0
|
256 |
#endif
|
sl@0
|
257 |
return divideByZero(0);
|
sl@0
|
258 |
}
|
sl@0
|
259 |
|
sl@0
|
260 |
void test3()
|
sl@0
|
261 |
{
|
sl@0
|
262 |
test.Start(_L("Create a thread (divideByZero3)"));
|
sl@0
|
263 |
RThread t;
|
sl@0
|
264 |
TRequestStatus s;
|
sl@0
|
265 |
TInt r;
|
sl@0
|
266 |
r=t.Create(_L("divideByZero3"),divideByZero3,KDefaultStackSize,KDefaultStackSize,KDefaultStackSize,NULL);
|
sl@0
|
267 |
test(r==KErrNone);
|
sl@0
|
268 |
t.Logon(s);
|
sl@0
|
269 |
gCount=0;
|
sl@0
|
270 |
test.Next(_L("Resume, and wait for thread to die"));
|
sl@0
|
271 |
t.Resume();
|
sl@0
|
272 |
User::WaitForRequest(s);
|
sl@0
|
273 |
test.Next(_L("Test thread raised one exception"));
|
sl@0
|
274 |
test(gCount==1);
|
sl@0
|
275 |
test.Next(_L("Test thread paniced on double exception"));
|
sl@0
|
276 |
test(t.ExitType()==EExitPanic);
|
sl@0
|
277 |
test(t.ExitReason()==ECausedException);
|
sl@0
|
278 |
CLOSE_AND_WAIT(t);
|
sl@0
|
279 |
//
|
sl@0
|
280 |
test.End();
|
sl@0
|
281 |
}
|
sl@0
|
282 |
|
sl@0
|
283 |
extern TInt dividebyzeroFn(TInt x)
|
sl@0
|
284 |
{
|
sl@0
|
285 |
volatile int i=x, j=10;
|
sl@0
|
286 |
volatile int l=j/i;
|
sl@0
|
287 |
for (i=0; i<l; i++)
|
sl@0
|
288 |
;
|
sl@0
|
289 |
return KErrNone;
|
sl@0
|
290 |
}
|
sl@0
|
291 |
|
sl@0
|
292 |
TInt dividebyzeroThread(TAny *)
|
sl@0
|
293 |
{
|
sl@0
|
294 |
return dividebyzeroFn(0);
|
sl@0
|
295 |
}
|
sl@0
|
296 |
|
sl@0
|
297 |
void testDivException()
|
sl@0
|
298 |
{
|
sl@0
|
299 |
RThread t;
|
sl@0
|
300 |
TRequestStatus s;
|
sl@0
|
301 |
test.Next(_L("Create divide by zero thread"));
|
sl@0
|
302 |
TInt r=t.Create(_L("drop dead"),dividebyzeroThread,KDefaultStackSize,KDefaultStackSize,KDefaultStackSize,NULL);
|
sl@0
|
303 |
test(r==KErrNone);
|
sl@0
|
304 |
t.Logon(s);
|
sl@0
|
305 |
test.Next(_L("Resume"));
|
sl@0
|
306 |
t.Resume();
|
sl@0
|
307 |
User::WaitForRequest(s);
|
sl@0
|
308 |
test.Next(_L("Test thread died because of EExcDivideByZero"));
|
sl@0
|
309 |
test(t.ExitType()==EExitPanic);
|
sl@0
|
310 |
test(t.ExitReason()==ECausedException);
|
sl@0
|
311 |
CLOSE_AND_WAIT(t);
|
sl@0
|
312 |
}
|
sl@0
|
313 |
|
sl@0
|
314 |
#ifndef __EPOC32__
|
sl@0
|
315 |
TInt ContextThread0(TAny *)
|
sl@0
|
316 |
{
|
sl@0
|
317 |
FOREVER;
|
sl@0
|
318 |
}
|
sl@0
|
319 |
#else
|
sl@0
|
320 |
TInt ContextThread0(TAny *);
|
sl@0
|
321 |
#endif
|
sl@0
|
322 |
|
sl@0
|
323 |
#ifndef __EPOC32__
|
sl@0
|
324 |
TInt ContextThread1(TAny *)
|
sl@0
|
325 |
{
|
sl@0
|
326 |
FOREVER;
|
sl@0
|
327 |
}
|
sl@0
|
328 |
#else
|
sl@0
|
329 |
TInt ContextThread1(TAny *);
|
sl@0
|
330 |
#endif
|
sl@0
|
331 |
|
sl@0
|
332 |
#ifndef __EPOC32__
|
sl@0
|
333 |
TInt ContextThread2(TAny *)
|
sl@0
|
334 |
{
|
sl@0
|
335 |
FOREVER;
|
sl@0
|
336 |
}
|
sl@0
|
337 |
#else
|
sl@0
|
338 |
TInt ContextThread2(TAny *);
|
sl@0
|
339 |
#endif
|
sl@0
|
340 |
|
sl@0
|
341 |
TUint32 RunContextThread(TThreadFunction aFunction, TUint32* aRegs)
|
sl@0
|
342 |
{
|
sl@0
|
343 |
#ifdef __EPOC32__
|
sl@0
|
344 |
TUint32 pc = (TUint32)aFunction((TAny*)0x80000000);
|
sl@0
|
345 |
#else
|
sl@0
|
346 |
TUint32 pc = 0;
|
sl@0
|
347 |
#endif
|
sl@0
|
348 |
RThread t;
|
sl@0
|
349 |
TRequestStatus s;
|
sl@0
|
350 |
TInt r=t.Create(_L("Context"),aFunction,KDefaultStackSize,NULL,NULL);
|
sl@0
|
351 |
test(r==KErrNone);
|
sl@0
|
352 |
t.Logon(s);
|
sl@0
|
353 |
t.Resume();
|
sl@0
|
354 |
User::After(100000);
|
sl@0
|
355 |
|
sl@0
|
356 |
TPtr8 buf((TUint8*)aRegs, 32*4, 32*4);
|
sl@0
|
357 |
TInt i;
|
sl@0
|
358 |
for (i=0; i<32; i++)
|
sl@0
|
359 |
aRegs[i]=0xbad00bad;
|
sl@0
|
360 |
t.Context(buf);
|
sl@0
|
361 |
if (buf.Length()==0)
|
sl@0
|
362 |
pc = 0; // not supported
|
sl@0
|
363 |
t.Kill(KErrNone);
|
sl@0
|
364 |
User::WaitForRequest(s);
|
sl@0
|
365 |
CLOSE_AND_WAIT(t);
|
sl@0
|
366 |
return pc;
|
sl@0
|
367 |
}
|
sl@0
|
368 |
|
sl@0
|
369 |
struct SRegValues
|
sl@0
|
370 |
{
|
sl@0
|
371 |
TUint32 iValidMask;
|
sl@0
|
372 |
TUint32 iValues[32];
|
sl@0
|
373 |
};
|
sl@0
|
374 |
|
sl@0
|
375 |
const TInt KNumContextTests = 3;
|
sl@0
|
376 |
|
sl@0
|
377 |
static const TThreadFunction ContextTestFn[KNumContextTests] =
|
sl@0
|
378 |
{
|
sl@0
|
379 |
&ContextThread0,
|
sl@0
|
380 |
&ContextThread1,
|
sl@0
|
381 |
&ContextThread2
|
sl@0
|
382 |
};
|
sl@0
|
383 |
|
sl@0
|
384 |
#if defined(__CPU_ARM)
|
sl@0
|
385 |
const TInt KPCIndex = 15;
|
sl@0
|
386 |
static const SRegValues ExpectedRegs[KNumContextTests] =
|
sl@0
|
387 |
{
|
sl@0
|
388 |
{0x1ffff,
|
sl@0
|
389 |
{ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0x00,
|
sl@0
|
390 |
0xa0000010, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
sl@0
|
391 |
}
|
sl@0
|
392 |
},
|
sl@0
|
393 |
{0x0eff0,
|
sl@0
|
394 |
{ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0x00,
|
sl@0
|
395 |
0xa0000010, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
sl@0
|
396 |
}
|
sl@0
|
397 |
},
|
sl@0
|
398 |
{0x0eff0,
|
sl@0
|
399 |
{ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0x00,
|
sl@0
|
400 |
0xa0000010, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
sl@0
|
401 |
}
|
sl@0
|
402 |
}
|
sl@0
|
403 |
};
|
sl@0
|
404 |
|
sl@0
|
405 |
static const TUint32 KRegValidBitsMask[32] =
|
sl@0
|
406 |
{
|
sl@0
|
407 |
0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu,
|
sl@0
|
408 |
0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu,
|
sl@0
|
409 |
0xf00000ffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu,
|
sl@0
|
410 |
0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu
|
sl@0
|
411 |
};
|
sl@0
|
412 |
|
sl@0
|
413 |
#elif defined(__CPU_X86)
|
sl@0
|
414 |
const TInt KPCIndex = 15;
|
sl@0
|
415 |
static const SRegValues ExpectedRegs[KNumContextTests] =
|
sl@0
|
416 |
{
|
sl@0
|
417 |
{0xe7ff,
|
sl@0
|
418 |
{ 0xaaaaaaaa, 0xbbbbbbbb, 0xcccccccc, 0xdddddddd, 0xe50e50e5, 0xeb0eb0eb, 0xe51e51e5, 0xed1ed1ed,
|
sl@0
|
419 |
0x0000001b, 0x00000023, 0x00000023, 0x00000023, 0x00000023, 0x00000023, 0x00000cd5, 0x00000000,
|
sl@0
|
420 |
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
sl@0
|
421 |
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
|
sl@0
|
422 |
}
|
sl@0
|
423 |
},
|
sl@0
|
424 |
{0xe7ff,
|
sl@0
|
425 |
{ 0x00000000, 0xbbbbbbbb, 0xcccccccc, 0xdddddddd, 0xe50e50e5, 0xeb0eb0eb, 0xe51e51e5, 0xed1ed1ed,
|
sl@0
|
426 |
0x0000001b, 0x00000023, 0x00000023, 0x00000023, 0x00000023, 0x00000023, 0x00000cd5, 0x00000000,
|
sl@0
|
427 |
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
sl@0
|
428 |
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
|
sl@0
|
429 |
}
|
sl@0
|
430 |
},
|
sl@0
|
431 |
{0xe7fa, // EAX=exec number, ECX trashed by preprocess handler
|
sl@0
|
432 |
{ 0xaaaaaaaa, 0xbbbbbbbb, 0xffff8001, 0xdddddddd, 0xe50e50e5, 0xeb0eb0eb, 0xe51e51e5, 0xed1ed1ed,
|
sl@0
|
433 |
0x0000001b, 0x00000023, 0x00000023, 0x00000023, 0x00000023, 0x00000023, 0x00000cd5, 0x00000000,
|
sl@0
|
434 |
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
sl@0
|
435 |
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
|
sl@0
|
436 |
}
|
sl@0
|
437 |
}
|
sl@0
|
438 |
};
|
sl@0
|
439 |
|
sl@0
|
440 |
static const TUint32 KRegValidBitsMask[32] =
|
sl@0
|
441 |
{
|
sl@0
|
442 |
0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu,
|
sl@0
|
443 |
0x0000ffffu, 0x0000ffffu, 0x0000ffffu, 0x0000ffffu, 0x0000ffffu, 0x0000ffffu, 0x00000cd5u, 0xffffffffu,
|
sl@0
|
444 |
0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu,
|
sl@0
|
445 |
0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu
|
sl@0
|
446 |
};
|
sl@0
|
447 |
|
sl@0
|
448 |
#endif
|
sl@0
|
449 |
|
sl@0
|
450 |
void CheckContextValues(TUint32* aRegs, const SRegValues& aExpected, TUint32 aPC)
|
sl@0
|
451 |
{
|
sl@0
|
452 |
test.Printf(_L("PC=%08x Context returned:\n"), aPC);
|
sl@0
|
453 |
TInt i;
|
sl@0
|
454 |
const TUint32* s = aRegs;
|
sl@0
|
455 |
for (i=0; i<8; ++i, s+=4)
|
sl@0
|
456 |
test.Printf(_L("%08x %08x %08x %08x\n"), s[0], s[1], s[2], s[3]);
|
sl@0
|
457 |
TUint32 v = aExpected.iValidMask;
|
sl@0
|
458 |
TBool ok = ETrue;
|
sl@0
|
459 |
for (i=0; i<32; ++i, v>>=1)
|
sl@0
|
460 |
{
|
sl@0
|
461 |
if (!(v&1))
|
sl@0
|
462 |
continue;
|
sl@0
|
463 |
TUint32 mask = KRegValidBitsMask[i];
|
sl@0
|
464 |
TUint32 actual = aRegs[i] & mask;
|
sl@0
|
465 |
TUint32 exp = (i == KPCIndex) ? aPC&mask : aExpected.iValues[i];
|
sl@0
|
466 |
if (actual != exp)
|
sl@0
|
467 |
{
|
sl@0
|
468 |
test.Printf(_L("%d: Expected %08x but got %08x\n"), i, exp, actual);
|
sl@0
|
469 |
ok = EFalse;
|
sl@0
|
470 |
}
|
sl@0
|
471 |
}
|
sl@0
|
472 |
test(ok);
|
sl@0
|
473 |
}
|
sl@0
|
474 |
|
sl@0
|
475 |
void testContext()
|
sl@0
|
476 |
{
|
sl@0
|
477 |
|
sl@0
|
478 |
TUint32 regs[32];
|
sl@0
|
479 |
|
sl@0
|
480 |
test.Next(_L("Get context of interrupted thread"));
|
sl@0
|
481 |
TInt tn;
|
sl@0
|
482 |
for (tn=0; tn<KNumContextTests; ++tn)
|
sl@0
|
483 |
{
|
sl@0
|
484 |
test.Printf(_L("Context test %d\n"), tn);
|
sl@0
|
485 |
TUint32 pc = RunContextThread(ContextTestFn[tn], regs);
|
sl@0
|
486 |
if (pc)
|
sl@0
|
487 |
{
|
sl@0
|
488 |
CheckContextValues(regs, ExpectedRegs[tn], pc);
|
sl@0
|
489 |
}
|
sl@0
|
490 |
}
|
sl@0
|
491 |
}
|
sl@0
|
492 |
|
sl@0
|
493 |
GLDEF_C TInt E32Main()
|
sl@0
|
494 |
//
|
sl@0
|
495 |
// __KHEAP_SETFAIL etc. not available in release mode, so don't test
|
sl@0
|
496 |
//
|
sl@0
|
497 |
{
|
sl@0
|
498 |
|
sl@0
|
499 |
test.Title();
|
sl@0
|
500 |
test.Start(_L("Create a semaphore"));
|
sl@0
|
501 |
TInt r=gSem.CreateGlobal(_L("A SEMAPHORE"),0);
|
sl@0
|
502 |
test(r==KErrNone);
|
sl@0
|
503 |
test.Next(_L("Test exceptions with no handlers"));
|
sl@0
|
504 |
test1();
|
sl@0
|
505 |
test.Next(_L("Test exceptions with handlers"));
|
sl@0
|
506 |
test2();
|
sl@0
|
507 |
test.Next(_L("Test exception raised in exception handler"));
|
sl@0
|
508 |
test3();
|
sl@0
|
509 |
test.Next(_L("Divide by zero exception"));
|
sl@0
|
510 |
testDivException();
|
sl@0
|
511 |
test.Next(_L("Test Context"));
|
sl@0
|
512 |
testContext();
|
sl@0
|
513 |
test.End();
|
sl@0
|
514 |
return(KErrNone);
|
sl@0
|
515 |
}
|