sl@0
|
1 |
// Copyright (c) 2001-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\secure\t_sthread.cpp
|
sl@0
|
15 |
// Overview:
|
sl@0
|
16 |
// Test the platform security aspects of the RThread class
|
sl@0
|
17 |
// API Information:
|
sl@0
|
18 |
// RThread
|
sl@0
|
19 |
// Details:
|
sl@0
|
20 |
// - Test renaming the current thread and renaming a thread from
|
sl@0
|
21 |
// another thread. Verify results are as expected.
|
sl@0
|
22 |
// - Test resuming a thread from a different process and from the
|
sl@0
|
23 |
// process that created the thread. Verify results are as expected.
|
sl@0
|
24 |
// - Verify that other processes can not suspend a thread and that the
|
sl@0
|
25 |
// creating process can.
|
sl@0
|
26 |
// - Perform a variety of tests on killing, terminating and panicking
|
sl@0
|
27 |
// a thread. Verify results are as expected.
|
sl@0
|
28 |
// - Test setting thread priority in a variety of ways, verify results
|
sl@0
|
29 |
// are as expected. Includes ensuring real-time priorities are
|
sl@0
|
30 |
// unavailable to processes without capability ProtServ.
|
sl@0
|
31 |
// - Test RequestComplete and RequestSignal on a thread in a variety
|
sl@0
|
32 |
// of ways, verify results are as expected.
|
sl@0
|
33 |
// - Test SetProcessPriority on a thread in a variety of ways, verify
|
sl@0
|
34 |
// results are as expected.
|
sl@0
|
35 |
// - Test the Heap, ExceptionHandler, SetExceptionHandler,
|
sl@0
|
36 |
// ModifyExceptionMask, RaiseException, IsExceptionHandled,
|
sl@0
|
37 |
// SetProtected and SetSystem methods. Verify results as expected.
|
sl@0
|
38 |
// Platforms/Drives/Compatibility:
|
sl@0
|
39 |
// All.
|
sl@0
|
40 |
// Assumptions/Requirement/Pre-requisites:
|
sl@0
|
41 |
// Failures and causes:
|
sl@0
|
42 |
// Base Port information:
|
sl@0
|
43 |
//
|
sl@0
|
44 |
//
|
sl@0
|
45 |
|
sl@0
|
46 |
#include <e32test.h>
|
sl@0
|
47 |
|
sl@0
|
48 |
LOCAL_D RTest test(_L("T_STHREAD"));
|
sl@0
|
49 |
|
sl@0
|
50 |
_LIT(KSyncMutex,"T_STHREAD-sync-mutex");
|
sl@0
|
51 |
RMutex SyncMutex;
|
sl@0
|
52 |
|
sl@0
|
53 |
void Wait()
|
sl@0
|
54 |
{
|
sl@0
|
55 |
RMutex syncMutex;
|
sl@0
|
56 |
if(syncMutex.OpenGlobal(KSyncMutex)!=KErrNone)
|
sl@0
|
57 |
User::Invariant();
|
sl@0
|
58 |
syncMutex.Wait();
|
sl@0
|
59 |
syncMutex.Signal();
|
sl@0
|
60 |
syncMutex.Close();
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
enum TTestProcessFunctions
|
sl@0
|
64 |
{
|
sl@0
|
65 |
ETestProcessResume,
|
sl@0
|
66 |
ETestProcessSuspend,
|
sl@0
|
67 |
ETestProcessKill,
|
sl@0
|
68 |
ETestProcessTerminate,
|
sl@0
|
69 |
ETestProcessPanic,
|
sl@0
|
70 |
ETestProcessRequestComplete,
|
sl@0
|
71 |
ETestProcessRequestSignal,
|
sl@0
|
72 |
ETestProcessPriorityControlOff,
|
sl@0
|
73 |
ETestProcessPriorityControlOn,
|
sl@0
|
74 |
ETestProcessSetPriority,
|
sl@0
|
75 |
ETestProcessSetPrioritiesWithoutProtServ,
|
sl@0
|
76 |
ETestProcessSetPrioritiesWithProtServ
|
sl@0
|
77 |
};
|
sl@0
|
78 |
|
sl@0
|
79 |
#include "testprocess.h"
|
sl@0
|
80 |
|
sl@0
|
81 |
_LIT(KTestPanicCategory,"TEST PANIC");
|
sl@0
|
82 |
_LIT(KTestThreadName,"TestName");
|
sl@0
|
83 |
|
sl@0
|
84 |
|
sl@0
|
85 |
class RTestThread : public RThread
|
sl@0
|
86 |
{
|
sl@0
|
87 |
public:
|
sl@0
|
88 |
void Create(TThreadFunction aFunction,TAny* aArg=0);
|
sl@0
|
89 |
};
|
sl@0
|
90 |
|
sl@0
|
91 |
volatile TInt TestThreadCount = 0;
|
sl@0
|
92 |
|
sl@0
|
93 |
TInt TestThreadNull(TAny*)
|
sl@0
|
94 |
{
|
sl@0
|
95 |
++TestThreadCount;
|
sl@0
|
96 |
Wait();
|
sl@0
|
97 |
return KErrNone;
|
sl@0
|
98 |
}
|
sl@0
|
99 |
|
sl@0
|
100 |
void RTestThread::Create(TThreadFunction aFunction,TAny* aArg)
|
sl@0
|
101 |
{
|
sl@0
|
102 |
TInt r=RThread::Create(_L("TestThread"),aFunction,KDefaultStackSize,KDefaultStackSize,KDefaultStackSize,aArg);
|
sl@0
|
103 |
test(r==KErrNone);
|
sl@0
|
104 |
}
|
sl@0
|
105 |
|
sl@0
|
106 |
|
sl@0
|
107 |
// these priorities are available to any process
|
sl@0
|
108 |
void TestSetNormalApplicationPriorities(RThread& aThread)
|
sl@0
|
109 |
{
|
sl@0
|
110 |
TThreadPriority priority = aThread.Priority(); // save priority to restore before return
|
sl@0
|
111 |
aThread.SetPriority(EPriorityAbsoluteVeryLow);
|
sl@0
|
112 |
test(aThread.Priority()==EPriorityAbsoluteVeryLow);
|
sl@0
|
113 |
aThread.SetPriority(EPriorityAbsoluteLowNormal);
|
sl@0
|
114 |
test(aThread.Priority()==EPriorityAbsoluteLowNormal);
|
sl@0
|
115 |
aThread.SetPriority(EPriorityAbsoluteLow);
|
sl@0
|
116 |
test(aThread.Priority()==EPriorityAbsoluteLow);
|
sl@0
|
117 |
aThread.SetPriority(EPriorityAbsoluteBackgroundNormal);
|
sl@0
|
118 |
test(aThread.Priority()==EPriorityAbsoluteBackgroundNormal);
|
sl@0
|
119 |
aThread.SetPriority(EPriorityAbsoluteBackground);
|
sl@0
|
120 |
test(aThread.Priority()==EPriorityAbsoluteBackground);
|
sl@0
|
121 |
aThread.SetPriority(EPriorityAbsoluteForegroundNormal);
|
sl@0
|
122 |
test(aThread.Priority()==EPriorityAbsoluteForegroundNormal);
|
sl@0
|
123 |
aThread.SetPriority(EPriorityAbsoluteForeground);
|
sl@0
|
124 |
test(aThread.Priority()==EPriorityAbsoluteForeground);
|
sl@0
|
125 |
aThread.SetPriority(EPriorityAbsoluteHighNormal);
|
sl@0
|
126 |
test(aThread.Priority()==EPriorityAbsoluteHighNormal);
|
sl@0
|
127 |
aThread.SetPriority(EPriorityAbsoluteHigh);
|
sl@0
|
128 |
test(aThread.Priority()==EPriorityAbsoluteHigh);
|
sl@0
|
129 |
aThread.SetPriority(priority);
|
sl@0
|
130 |
}
|
sl@0
|
131 |
|
sl@0
|
132 |
TInt TestThreadSetPriority(TAny* aArg)
|
sl@0
|
133 |
{
|
sl@0
|
134 |
RThread thisThread;
|
sl@0
|
135 |
thisThread.SetPriority((TThreadPriority)(reinterpret_cast<TInt>(aArg)));
|
sl@0
|
136 |
return KErrNone;
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
void TestSetPriorityPanic(TThreadPriority aPriority)
|
sl@0
|
140 |
{
|
sl@0
|
141 |
RTestThread thread;
|
sl@0
|
142 |
TRequestStatus status;
|
sl@0
|
143 |
thread.Create(TestThreadSetPriority, reinterpret_cast<TAny*>(aPriority));
|
sl@0
|
144 |
thread.Logon(status);
|
sl@0
|
145 |
thread.Resume();
|
sl@0
|
146 |
User::WaitForRequest(status);
|
sl@0
|
147 |
test(thread.ExitType()==EExitPanic);
|
sl@0
|
148 |
test(thread.ExitCategory()==_L("KERN-EXEC"));
|
sl@0
|
149 |
test(thread.ExitReason()==46);
|
sl@0
|
150 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
151 |
}
|
sl@0
|
152 |
|
sl@0
|
153 |
void TestSetPrioritySuccess(TThreadPriority aPriority)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
RTestThread thread;
|
sl@0
|
156 |
TRequestStatus status;
|
sl@0
|
157 |
thread.Create(TestThreadSetPriority, reinterpret_cast<TAny*>(aPriority));
|
sl@0
|
158 |
thread.Logon(status);
|
sl@0
|
159 |
thread.Resume();
|
sl@0
|
160 |
User::WaitForRequest(status);
|
sl@0
|
161 |
test(thread.Priority()==aPriority);
|
sl@0
|
162 |
test(thread.ExitCategory()==_L("Kill"));
|
sl@0
|
163 |
test(thread.ExitReason()==0);
|
sl@0
|
164 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
TInt DoTestProcess(TInt aTestNum,TInt aArg1,TInt aArg2)
|
sl@0
|
168 |
{
|
sl@0
|
169 |
RThread thread;
|
sl@0
|
170 |
TInt r;
|
sl@0
|
171 |
|
sl@0
|
172 |
switch(aTestNum)
|
sl@0
|
173 |
{
|
sl@0
|
174 |
|
sl@0
|
175 |
case ETestProcessResume:
|
sl@0
|
176 |
{
|
sl@0
|
177 |
r = thread.Open(aArg1);
|
sl@0
|
178 |
if(r==KErrNone)
|
sl@0
|
179 |
thread.Resume(); // Should panic us
|
sl@0
|
180 |
return r;
|
sl@0
|
181 |
}
|
sl@0
|
182 |
|
sl@0
|
183 |
case ETestProcessSuspend:
|
sl@0
|
184 |
{
|
sl@0
|
185 |
r = thread.Open(aArg1);
|
sl@0
|
186 |
if(r==KErrNone)
|
sl@0
|
187 |
thread.Suspend(); // Should panic us
|
sl@0
|
188 |
return r;
|
sl@0
|
189 |
}
|
sl@0
|
190 |
|
sl@0
|
191 |
case ETestProcessKill:
|
sl@0
|
192 |
{
|
sl@0
|
193 |
r = thread.Open(aArg1);
|
sl@0
|
194 |
if(r==KErrNone)
|
sl@0
|
195 |
thread.Kill(999); // Should panic us
|
sl@0
|
196 |
return r;
|
sl@0
|
197 |
}
|
sl@0
|
198 |
|
sl@0
|
199 |
case ETestProcessTerminate:
|
sl@0
|
200 |
{
|
sl@0
|
201 |
r = thread.Open(aArg1);
|
sl@0
|
202 |
if(r==KErrNone)
|
sl@0
|
203 |
thread.Terminate(999); // Should panic us
|
sl@0
|
204 |
return r;
|
sl@0
|
205 |
}
|
sl@0
|
206 |
|
sl@0
|
207 |
case ETestProcessPanic:
|
sl@0
|
208 |
{
|
sl@0
|
209 |
r = thread.Open(aArg1);
|
sl@0
|
210 |
if(r==KErrNone)
|
sl@0
|
211 |
thread.Panic(KTestPanicCategory,999); // Should panic us
|
sl@0
|
212 |
return r;
|
sl@0
|
213 |
}
|
sl@0
|
214 |
|
sl@0
|
215 |
case ETestProcessSetPriority:
|
sl@0
|
216 |
{
|
sl@0
|
217 |
r = thread.Open(aArg1);
|
sl@0
|
218 |
if(r==KErrNone)
|
sl@0
|
219 |
thread.SetPriority((TThreadPriority)aArg2);
|
sl@0
|
220 |
return r;
|
sl@0
|
221 |
}
|
sl@0
|
222 |
|
sl@0
|
223 |
case ETestProcessRequestComplete:
|
sl@0
|
224 |
{
|
sl@0
|
225 |
r = thread.Open(aArg1);
|
sl@0
|
226 |
if(r==KErrNone)
|
sl@0
|
227 |
{
|
sl@0
|
228 |
// use a local request status because Thread::RequestComplete is
|
sl@0
|
229 |
// implemented to write to it in our context
|
sl@0
|
230 |
TRequestStatus myStatus;
|
sl@0
|
231 |
TRequestStatus* status = &myStatus;
|
sl@0
|
232 |
thread.RequestComplete(status,KErrNone);
|
sl@0
|
233 |
}
|
sl@0
|
234 |
return r;
|
sl@0
|
235 |
}
|
sl@0
|
236 |
|
sl@0
|
237 |
case ETestProcessRequestSignal:
|
sl@0
|
238 |
{
|
sl@0
|
239 |
r = thread.Open(aArg1);
|
sl@0
|
240 |
if(r==KErrNone)
|
sl@0
|
241 |
thread.RequestSignal();
|
sl@0
|
242 |
return r;
|
sl@0
|
243 |
}
|
sl@0
|
244 |
|
sl@0
|
245 |
case ETestProcessPriorityControlOn:
|
sl@0
|
246 |
User::SetPriorityControl(ETrue);
|
sl@0
|
247 |
// fall through...
|
sl@0
|
248 |
case ETestProcessPriorityControlOff:
|
sl@0
|
249 |
RProcess::Rendezvous(RThread().Id());
|
sl@0
|
250 |
Wait();
|
sl@0
|
251 |
return KErrNone;
|
sl@0
|
252 |
|
sl@0
|
253 |
case ETestProcessSetPrioritiesWithoutProtServ:
|
sl@0
|
254 |
{
|
sl@0
|
255 |
RThread thread;
|
sl@0
|
256 |
TestSetNormalApplicationPriorities(thread);
|
sl@0
|
257 |
TestSetPriorityPanic(EPriorityAbsoluteRealTime1);
|
sl@0
|
258 |
TestSetPriorityPanic(EPriorityAbsoluteRealTime2);
|
sl@0
|
259 |
TestSetPriorityPanic(EPriorityAbsoluteRealTime3);
|
sl@0
|
260 |
TestSetPriorityPanic(EPriorityAbsoluteRealTime4);
|
sl@0
|
261 |
TestSetPriorityPanic(EPriorityAbsoluteRealTime5);
|
sl@0
|
262 |
TestSetPriorityPanic(EPriorityAbsoluteRealTime6);
|
sl@0
|
263 |
TestSetPriorityPanic(EPriorityAbsoluteRealTime7);
|
sl@0
|
264 |
TestSetPriorityPanic(EPriorityAbsoluteRealTime8);
|
sl@0
|
265 |
return KErrNone;
|
sl@0
|
266 |
}
|
sl@0
|
267 |
|
sl@0
|
268 |
case ETestProcessSetPrioritiesWithProtServ:
|
sl@0
|
269 |
{
|
sl@0
|
270 |
RThread thread;
|
sl@0
|
271 |
TestSetNormalApplicationPriorities(thread);
|
sl@0
|
272 |
TestSetPrioritySuccess(EPriorityAbsoluteRealTime1);
|
sl@0
|
273 |
TestSetPrioritySuccess(EPriorityAbsoluteRealTime2);
|
sl@0
|
274 |
TestSetPrioritySuccess(EPriorityAbsoluteRealTime3);
|
sl@0
|
275 |
TestSetPrioritySuccess(EPriorityAbsoluteRealTime4);
|
sl@0
|
276 |
TestSetPrioritySuccess(EPriorityAbsoluteRealTime5);
|
sl@0
|
277 |
TestSetPrioritySuccess(EPriorityAbsoluteRealTime6);
|
sl@0
|
278 |
TestSetPrioritySuccess(EPriorityAbsoluteRealTime7);
|
sl@0
|
279 |
TestSetPrioritySuccess(EPriorityAbsoluteRealTime8);
|
sl@0
|
280 |
return KErrNone;
|
sl@0
|
281 |
}
|
sl@0
|
282 |
|
sl@0
|
283 |
default:
|
sl@0
|
284 |
User::Panic(_L("T_STHREAD"),1);
|
sl@0
|
285 |
}
|
sl@0
|
286 |
|
sl@0
|
287 |
return KErrNone;
|
sl@0
|
288 |
}
|
sl@0
|
289 |
|
sl@0
|
290 |
|
sl@0
|
291 |
|
sl@0
|
292 |
void TestThreadForPlatformSecurityTrap(TThreadFunction aFunction)
|
sl@0
|
293 |
{
|
sl@0
|
294 |
TBool jit = User::JustInTime();
|
sl@0
|
295 |
TRequestStatus logonStatus;
|
sl@0
|
296 |
RTestThread thread;
|
sl@0
|
297 |
thread.Create(aFunction,(TAny*)(TUint)RThread().Id());
|
sl@0
|
298 |
thread.Logon(logonStatus);
|
sl@0
|
299 |
User::SetJustInTime(EFalse);
|
sl@0
|
300 |
thread.Resume();
|
sl@0
|
301 |
User::WaitForRequest(logonStatus);
|
sl@0
|
302 |
User::SetJustInTime(jit);
|
sl@0
|
303 |
test(thread.ExitType()==EExitPanic);
|
sl@0
|
304 |
test(logonStatus==EPlatformSecurityTrap);
|
sl@0
|
305 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
306 |
}
|
sl@0
|
307 |
|
sl@0
|
308 |
|
sl@0
|
309 |
void TestProcessForPlatformSecurityTrap(TTestProcessFunctions aFunction)
|
sl@0
|
310 |
{
|
sl@0
|
311 |
TRequestStatus logonStatus2;
|
sl@0
|
312 |
RTestProcess process;
|
sl@0
|
313 |
process.Create(~0u,aFunction,RThread().Id(),EPriorityAbsoluteLow);
|
sl@0
|
314 |
process.Logon(logonStatus2);
|
sl@0
|
315 |
process.Resume();
|
sl@0
|
316 |
User::WaitForRequest(logonStatus2);
|
sl@0
|
317 |
test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
|
sl@0
|
318 |
test(logonStatus2==EPlatformSecurityTrap);
|
sl@0
|
319 |
CLOSE_AND_WAIT(process);
|
sl@0
|
320 |
}
|
sl@0
|
321 |
|
sl@0
|
322 |
|
sl@0
|
323 |
void TestRename()
|
sl@0
|
324 |
{
|
sl@0
|
325 |
TName name;
|
sl@0
|
326 |
|
sl@0
|
327 |
test.Start(_L("Renaming the current thread"));
|
sl@0
|
328 |
name = RThread().Name();
|
sl@0
|
329 |
name.SetLength(KTestThreadName().Length());
|
sl@0
|
330 |
test(name.CompareF(KTestThreadName)!=0);
|
sl@0
|
331 |
User::RenameThread(KTestThreadName);
|
sl@0
|
332 |
name = RThread().Name();
|
sl@0
|
333 |
name.SetLength(KTestThreadName().Length());
|
sl@0
|
334 |
test(name.CompareF(KTestThreadName)==0);
|
sl@0
|
335 |
|
sl@0
|
336 |
|
sl@0
|
337 |
test.End();
|
sl@0
|
338 |
}
|
sl@0
|
339 |
|
sl@0
|
340 |
|
sl@0
|
341 |
|
sl@0
|
342 |
void TestResume()
|
sl@0
|
343 |
{
|
sl@0
|
344 |
RTestProcess process;
|
sl@0
|
345 |
RTestThread thread;
|
sl@0
|
346 |
TRequestStatus logonStatus;
|
sl@0
|
347 |
TInt testCount = TestThreadCount;
|
sl@0
|
348 |
|
sl@0
|
349 |
test.Start(_L("Try to get another process to resume one we've created"));
|
sl@0
|
350 |
thread.Create(TestThreadNull);
|
sl@0
|
351 |
process.Create(~0u,ETestProcessResume,thread.Id());
|
sl@0
|
352 |
process.Logon(logonStatus);
|
sl@0
|
353 |
process.Resume();
|
sl@0
|
354 |
User::WaitForRequest(logonStatus);
|
sl@0
|
355 |
test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
|
sl@0
|
356 |
test(logonStatus==EPlatformSecurityTrap);
|
sl@0
|
357 |
User::After(1000000); // Give time for thread to run (if it had been resumed)...
|
sl@0
|
358 |
test(TestThreadCount==testCount); // it shouldn't have, so count will be unchanged.
|
sl@0
|
359 |
|
sl@0
|
360 |
test.Next(_L("Test resuming a thread we've created"));
|
sl@0
|
361 |
thread.Logon(logonStatus);
|
sl@0
|
362 |
test(logonStatus==KRequestPending);
|
sl@0
|
363 |
thread.Resume();
|
sl@0
|
364 |
User::WaitForRequest(logonStatus);
|
sl@0
|
365 |
test(logonStatus==KErrNone);
|
sl@0
|
366 |
test(TestThreadCount==testCount+1); // Thread should have run and incremented the count
|
sl@0
|
367 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
368 |
CLOSE_AND_WAIT(process);
|
sl@0
|
369 |
|
sl@0
|
370 |
test.End();
|
sl@0
|
371 |
}
|
sl@0
|
372 |
|
sl@0
|
373 |
|
sl@0
|
374 |
|
sl@0
|
375 |
TInt TestThreadCounting(TAny*)
|
sl@0
|
376 |
{
|
sl@0
|
377 |
RThread().SetPriority(EPriorityAbsoluteVeryLow);
|
sl@0
|
378 |
for(;;)
|
sl@0
|
379 |
++TestThreadCount;
|
sl@0
|
380 |
}
|
sl@0
|
381 |
|
sl@0
|
382 |
TBool IsTestThreadRunning()
|
sl@0
|
383 |
{
|
sl@0
|
384 |
// Thread should have been busy incrementing the count if it is running
|
sl@0
|
385 |
TInt testCount = TestThreadCount;
|
sl@0
|
386 |
User::After(100000);
|
sl@0
|
387 |
if(testCount!=TestThreadCount)
|
sl@0
|
388 |
return ETrue;
|
sl@0
|
389 |
User::After(1000000);
|
sl@0
|
390 |
return testCount!=TestThreadCount;
|
sl@0
|
391 |
}
|
sl@0
|
392 |
|
sl@0
|
393 |
void TestSuspend()
|
sl@0
|
394 |
{
|
sl@0
|
395 |
RTestProcess process;
|
sl@0
|
396 |
RTestThread thread;
|
sl@0
|
397 |
TRequestStatus logonStatus;
|
sl@0
|
398 |
|
sl@0
|
399 |
test.Start(_L("Creating a never ending thread..."));
|
sl@0
|
400 |
thread.Create(TestThreadCounting);
|
sl@0
|
401 |
thread.Resume();
|
sl@0
|
402 |
test(IsTestThreadRunning()); // Thread should still be running
|
sl@0
|
403 |
|
sl@0
|
404 |
test.Next(_L("Checking other process can't supspend it"));
|
sl@0
|
405 |
process.Create(~0u,ETestProcessSuspend,thread.Id());
|
sl@0
|
406 |
process.Logon(logonStatus);
|
sl@0
|
407 |
process.Resume();
|
sl@0
|
408 |
User::WaitForRequest(logonStatus);
|
sl@0
|
409 |
test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
|
sl@0
|
410 |
test(logonStatus==EPlatformSecurityTrap);
|
sl@0
|
411 |
test(IsTestThreadRunning()); // Thread should still be running
|
sl@0
|
412 |
|
sl@0
|
413 |
test.Next(_L("Test suspending a thread in same process"));
|
sl@0
|
414 |
thread.Logon(logonStatus);
|
sl@0
|
415 |
thread.Suspend();
|
sl@0
|
416 |
test(!IsTestThreadRunning()); // Thread should have stopped...
|
sl@0
|
417 |
test(logonStatus==KRequestPending); // but not have died
|
sl@0
|
418 |
thread.LogonCancel(logonStatus);
|
sl@0
|
419 |
User::WaitForRequest(logonStatus);
|
sl@0
|
420 |
|
sl@0
|
421 |
test.Next(_L("Kill thread"));
|
sl@0
|
422 |
thread.Kill(0);
|
sl@0
|
423 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
424 |
CLOSE_AND_WAIT(process);
|
sl@0
|
425 |
|
sl@0
|
426 |
test.End();
|
sl@0
|
427 |
}
|
sl@0
|
428 |
|
sl@0
|
429 |
|
sl@0
|
430 |
|
sl@0
|
431 |
TInt TestThreadKillSelf(TAny* )
|
sl@0
|
432 |
{
|
sl@0
|
433 |
RThread().Kill(999);
|
sl@0
|
434 |
return KErrGeneral;
|
sl@0
|
435 |
}
|
sl@0
|
436 |
|
sl@0
|
437 |
TInt TestThreadTerminateSelf(TAny*)
|
sl@0
|
438 |
{
|
sl@0
|
439 |
RThread().Terminate(999);
|
sl@0
|
440 |
return KErrGeneral;
|
sl@0
|
441 |
}
|
sl@0
|
442 |
|
sl@0
|
443 |
TInt TestThreadPanicSelf(TAny*)
|
sl@0
|
444 |
{
|
sl@0
|
445 |
RThread().Panic(KTestPanicCategory,999);
|
sl@0
|
446 |
return KErrGeneral;
|
sl@0
|
447 |
}
|
sl@0
|
448 |
|
sl@0
|
449 |
void TestKill()
|
sl@0
|
450 |
{
|
sl@0
|
451 |
RTestProcess process;
|
sl@0
|
452 |
RTestThread thread;
|
sl@0
|
453 |
TRequestStatus logonStatus;
|
sl@0
|
454 |
TRequestStatus logonStatus2;
|
sl@0
|
455 |
TBool jit = User::JustInTime();
|
sl@0
|
456 |
|
sl@0
|
457 |
// Test RProcess::Kill()
|
sl@0
|
458 |
|
sl@0
|
459 |
test.Start(_L("Test killing an un-resumed thread created by us"));
|
sl@0
|
460 |
thread.Create(TestThreadNull);
|
sl@0
|
461 |
thread.Logon(logonStatus);
|
sl@0
|
462 |
thread.Kill(999);
|
sl@0
|
463 |
User::WaitForRequest(logonStatus);
|
sl@0
|
464 |
test(thread.ExitType()==EExitKill);
|
sl@0
|
465 |
test(logonStatus==999);
|
sl@0
|
466 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
467 |
|
sl@0
|
468 |
test.Next(_L("Test killing a resumed thread created by us"));
|
sl@0
|
469 |
thread.Create(TestThreadNull);
|
sl@0
|
470 |
thread.Logon(logonStatus);
|
sl@0
|
471 |
SyncMutex.Wait();
|
sl@0
|
472 |
thread.Resume();
|
sl@0
|
473 |
thread.Kill(999);
|
sl@0
|
474 |
SyncMutex.Signal();
|
sl@0
|
475 |
User::WaitForRequest(logonStatus);
|
sl@0
|
476 |
test(thread.ExitType()==EExitKill);
|
sl@0
|
477 |
test(logonStatus==999);
|
sl@0
|
478 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
479 |
|
sl@0
|
480 |
test.Next(_L("Try killing un-resumed thread not created by self"));
|
sl@0
|
481 |
thread.Create(TestThreadNull);
|
sl@0
|
482 |
process.Create(~0u,ETestProcessKill,thread.Id());
|
sl@0
|
483 |
thread.Logon(logonStatus2);
|
sl@0
|
484 |
process.Logon(logonStatus);
|
sl@0
|
485 |
process.Resume();
|
sl@0
|
486 |
User::WaitForRequest(logonStatus);
|
sl@0
|
487 |
test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
|
sl@0
|
488 |
test(logonStatus==EPlatformSecurityTrap);
|
sl@0
|
489 |
test(logonStatus2==KRequestPending); // the thread should still be alive
|
sl@0
|
490 |
thread.Resume();
|
sl@0
|
491 |
User::WaitForRequest(logonStatus2);
|
sl@0
|
492 |
test(logonStatus2==KErrNone);
|
sl@0
|
493 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
494 |
CLOSE_AND_WAIT(process);
|
sl@0
|
495 |
|
sl@0
|
496 |
test.Next(_L("Try killing resumed thread not created by self"));
|
sl@0
|
497 |
thread.Create(TestThreadNull);
|
sl@0
|
498 |
process.Create(~0u,ETestProcessKill,thread.Id());
|
sl@0
|
499 |
thread.Logon(logonStatus2);
|
sl@0
|
500 |
process.Logon(logonStatus);
|
sl@0
|
501 |
SyncMutex.Wait();
|
sl@0
|
502 |
thread.Resume();
|
sl@0
|
503 |
process.Resume();
|
sl@0
|
504 |
User::WaitForRequest(logonStatus);
|
sl@0
|
505 |
test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
|
sl@0
|
506 |
test(logonStatus==EPlatformSecurityTrap);
|
sl@0
|
507 |
test(logonStatus2==KRequestPending); // the thread should still be alive
|
sl@0
|
508 |
SyncMutex.Signal();
|
sl@0
|
509 |
User::WaitForRequest(logonStatus2);
|
sl@0
|
510 |
test(logonStatus2==KErrNone);
|
sl@0
|
511 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
512 |
CLOSE_AND_WAIT(process);
|
sl@0
|
513 |
|
sl@0
|
514 |
test.Next(_L("Test a thread killing itself"));
|
sl@0
|
515 |
thread.Create(TestThreadKillSelf);
|
sl@0
|
516 |
thread.Logon(logonStatus);
|
sl@0
|
517 |
thread.Resume();
|
sl@0
|
518 |
User::WaitForRequest(logonStatus);
|
sl@0
|
519 |
test(thread.ExitType()==EExitKill);
|
sl@0
|
520 |
test(logonStatus==999);
|
sl@0
|
521 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
522 |
|
sl@0
|
523 |
// Test RProcess::Teminate()
|
sl@0
|
524 |
|
sl@0
|
525 |
test.Next(_L("Test terminating an un-resumed thread created by us"));
|
sl@0
|
526 |
thread.Create(TestThreadNull);
|
sl@0
|
527 |
thread.Logon(logonStatus);
|
sl@0
|
528 |
thread.Terminate(999);
|
sl@0
|
529 |
User::WaitForRequest(logonStatus);
|
sl@0
|
530 |
test(thread.ExitType()==EExitTerminate);
|
sl@0
|
531 |
test(logonStatus==999);
|
sl@0
|
532 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
533 |
|
sl@0
|
534 |
test.Next(_L("Test terminating a resumed thread created by us"));
|
sl@0
|
535 |
thread.Create(TestThreadNull);
|
sl@0
|
536 |
thread.Logon(logonStatus);
|
sl@0
|
537 |
SyncMutex.Wait();
|
sl@0
|
538 |
thread.Resume();
|
sl@0
|
539 |
thread.Terminate(999);
|
sl@0
|
540 |
SyncMutex.Signal();
|
sl@0
|
541 |
User::WaitForRequest(logonStatus);
|
sl@0
|
542 |
test(thread.ExitType()==EExitTerminate);
|
sl@0
|
543 |
test(logonStatus==999);
|
sl@0
|
544 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
545 |
|
sl@0
|
546 |
test.Next(_L("Try terminating un-resumed thread not created by self"));
|
sl@0
|
547 |
thread.Create(TestThreadNull);
|
sl@0
|
548 |
process.Create(~0u,ETestProcessTerminate,thread.Id());
|
sl@0
|
549 |
thread.Logon(logonStatus2);
|
sl@0
|
550 |
process.Logon(logonStatus);
|
sl@0
|
551 |
process.Resume();
|
sl@0
|
552 |
User::WaitForRequest(logonStatus);
|
sl@0
|
553 |
test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
|
sl@0
|
554 |
test(logonStatus==EPlatformSecurityTrap);
|
sl@0
|
555 |
test(logonStatus2==KRequestPending); // the thread should still be alive
|
sl@0
|
556 |
thread.Resume();
|
sl@0
|
557 |
User::WaitForRequest(logonStatus2);
|
sl@0
|
558 |
test(logonStatus2==KErrNone);
|
sl@0
|
559 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
560 |
CLOSE_AND_WAIT(process);
|
sl@0
|
561 |
|
sl@0
|
562 |
test.Next(_L("Try terminating resumed thread not created by self"));
|
sl@0
|
563 |
thread.Create(TestThreadNull);
|
sl@0
|
564 |
process.Create(~0u,ETestProcessTerminate,thread.Id());
|
sl@0
|
565 |
thread.Logon(logonStatus2);
|
sl@0
|
566 |
process.Logon(logonStatus);
|
sl@0
|
567 |
SyncMutex.Wait();
|
sl@0
|
568 |
thread.Resume();
|
sl@0
|
569 |
process.Resume();
|
sl@0
|
570 |
User::WaitForRequest(logonStatus);
|
sl@0
|
571 |
test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
|
sl@0
|
572 |
test(logonStatus==EPlatformSecurityTrap);
|
sl@0
|
573 |
test(logonStatus2==KRequestPending); // the thread should still be alive
|
sl@0
|
574 |
SyncMutex.Signal();
|
sl@0
|
575 |
User::WaitForRequest(logonStatus2);
|
sl@0
|
576 |
test(logonStatus2==KErrNone);
|
sl@0
|
577 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
578 |
CLOSE_AND_WAIT(process);
|
sl@0
|
579 |
|
sl@0
|
580 |
test.Next(_L("Test a thread terminating itself"));
|
sl@0
|
581 |
thread.Create(TestThreadTerminateSelf);
|
sl@0
|
582 |
thread.Logon(logonStatus);
|
sl@0
|
583 |
thread.Resume();
|
sl@0
|
584 |
User::WaitForRequest(logonStatus);
|
sl@0
|
585 |
test(thread.ExitType()==EExitTerminate);
|
sl@0
|
586 |
test(logonStatus==999);
|
sl@0
|
587 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
588 |
|
sl@0
|
589 |
// Test RProcess::Panic()
|
sl@0
|
590 |
|
sl@0
|
591 |
test.Next(_L("Test panicking an un-resumed thread created by us"));
|
sl@0
|
592 |
thread.Create(TestThreadNull);
|
sl@0
|
593 |
thread.Logon(logonStatus);
|
sl@0
|
594 |
User::SetJustInTime(EFalse);
|
sl@0
|
595 |
thread.Panic(KTestPanicCategory,999);
|
sl@0
|
596 |
User::WaitForRequest(logonStatus);
|
sl@0
|
597 |
User::SetJustInTime(jit);
|
sl@0
|
598 |
test(thread.ExitType()==EExitPanic);
|
sl@0
|
599 |
test(logonStatus==999);
|
sl@0
|
600 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
601 |
|
sl@0
|
602 |
test.Next(_L("Test panicking a resumed thread created by us"));
|
sl@0
|
603 |
thread.Create(TestThreadNull);
|
sl@0
|
604 |
thread.Logon(logonStatus);
|
sl@0
|
605 |
SyncMutex.Wait();
|
sl@0
|
606 |
thread.Resume();
|
sl@0
|
607 |
User::SetJustInTime(EFalse);
|
sl@0
|
608 |
thread.Panic(KTestPanicCategory,999);
|
sl@0
|
609 |
SyncMutex.Signal();
|
sl@0
|
610 |
User::WaitForRequest(logonStatus);
|
sl@0
|
611 |
User::SetJustInTime(jit);
|
sl@0
|
612 |
test(thread.ExitType()==EExitPanic);
|
sl@0
|
613 |
test(logonStatus==999);
|
sl@0
|
614 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
615 |
|
sl@0
|
616 |
test.Next(_L("Try panicking un-resumed thread not created by self"));
|
sl@0
|
617 |
thread.Create(TestThreadNull);
|
sl@0
|
618 |
process.Create(~0u,ETestProcessPanic,thread.Id());
|
sl@0
|
619 |
thread.Logon(logonStatus2);
|
sl@0
|
620 |
process.Logon(logonStatus);
|
sl@0
|
621 |
process.Resume();
|
sl@0
|
622 |
User::WaitForRequest(logonStatus);
|
sl@0
|
623 |
test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
|
sl@0
|
624 |
test(logonStatus==EPlatformSecurityTrap);
|
sl@0
|
625 |
test(logonStatus2==KRequestPending); // the thread should still be alive
|
sl@0
|
626 |
thread.Resume();
|
sl@0
|
627 |
User::WaitForRequest(logonStatus2);
|
sl@0
|
628 |
test(logonStatus2==KErrNone);
|
sl@0
|
629 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
630 |
CLOSE_AND_WAIT(process);
|
sl@0
|
631 |
|
sl@0
|
632 |
test.Next(_L("Try panicking resumed thread not created by self"));
|
sl@0
|
633 |
thread.Create(TestThreadNull);
|
sl@0
|
634 |
process.Create(~0u,ETestProcessPanic,thread.Id());
|
sl@0
|
635 |
thread.Logon(logonStatus2);
|
sl@0
|
636 |
process.Logon(logonStatus);
|
sl@0
|
637 |
SyncMutex.Wait();
|
sl@0
|
638 |
thread.Resume();
|
sl@0
|
639 |
process.Resume();
|
sl@0
|
640 |
User::WaitForRequest(logonStatus);
|
sl@0
|
641 |
test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
|
sl@0
|
642 |
test(logonStatus==EPlatformSecurityTrap);
|
sl@0
|
643 |
test(logonStatus2==KRequestPending); // the thread should still be alive
|
sl@0
|
644 |
SyncMutex.Signal();
|
sl@0
|
645 |
User::WaitForRequest(logonStatus2);
|
sl@0
|
646 |
test(logonStatus2==KErrNone);
|
sl@0
|
647 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
648 |
CLOSE_AND_WAIT(process);
|
sl@0
|
649 |
|
sl@0
|
650 |
test.Next(_L("Test a thread panicking itself"));
|
sl@0
|
651 |
thread.Create(TestThreadPanicSelf);
|
sl@0
|
652 |
thread.Logon(logonStatus);
|
sl@0
|
653 |
User::SetJustInTime(EFalse);
|
sl@0
|
654 |
thread.Resume();
|
sl@0
|
655 |
User::WaitForRequest(logonStatus);
|
sl@0
|
656 |
User::SetJustInTime(jit);
|
sl@0
|
657 |
test(thread.ExitType()==EExitPanic);
|
sl@0
|
658 |
test(logonStatus==999);
|
sl@0
|
659 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
660 |
|
sl@0
|
661 |
//
|
sl@0
|
662 |
|
sl@0
|
663 |
test.End();
|
sl@0
|
664 |
}
|
sl@0
|
665 |
|
sl@0
|
666 |
|
sl@0
|
667 |
//---------------------------------------------
|
sl@0
|
668 |
//! @SYMTestCaseID KBASE-T_STHREAD-0120
|
sl@0
|
669 |
//! @SYMTestCaseDesc Set thread priority
|
sl@0
|
670 |
//! @SYMTestType UT
|
sl@0
|
671 |
//! @SYMREQ historical, enhanced under PREQ955
|
sl@0
|
672 |
//! @SYMTestActions Test setting all thread priority values to threads in this process,
|
sl@0
|
673 |
//! and in another process, resumed and not.
|
sl@0
|
674 |
//! @SYMTestExpectedResults Confirm can set and get "normal application" thread priorities
|
sl@0
|
675 |
//! for threads in this process, whether resumed or not. Confirm thread is panicked
|
sl@0
|
676 |
//! if attempts to set priority of thread in another process. Confirm can set and get
|
sl@0
|
677 |
//! "real-time" thread priorities if this process has ProtServ capability, and that
|
sl@0
|
678 |
//! calling thread is panicked if not.
|
sl@0
|
679 |
//! @SYMTestPriority Critical
|
sl@0
|
680 |
//! @SYMTestStatus Implemented
|
sl@0
|
681 |
//---------------------------------------------
|
sl@0
|
682 |
void TestSetPriority()
|
sl@0
|
683 |
{
|
sl@0
|
684 |
RTestThread thread;
|
sl@0
|
685 |
RTestProcess process;
|
sl@0
|
686 |
TRequestStatus logonStatus;
|
sl@0
|
687 |
TRequestStatus logonStatus2;
|
sl@0
|
688 |
|
sl@0
|
689 |
test.Start(_L("Test changing our own threads priority"));
|
sl@0
|
690 |
TestSetNormalApplicationPriorities(thread);
|
sl@0
|
691 |
|
sl@0
|
692 |
test.Next(_L("Test changing priority of un-resumed thread in our process"));
|
sl@0
|
693 |
thread.Create(TestThreadNull);
|
sl@0
|
694 |
thread.Logon(logonStatus);
|
sl@0
|
695 |
TestSetNormalApplicationPriorities(thread);
|
sl@0
|
696 |
|
sl@0
|
697 |
test.Next(_L("Test changing priority of resumed thread in our process"));
|
sl@0
|
698 |
SyncMutex.Wait();
|
sl@0
|
699 |
thread.Resume();
|
sl@0
|
700 |
TestSetNormalApplicationPriorities(thread);
|
sl@0
|
701 |
SyncMutex.Signal();
|
sl@0
|
702 |
User::WaitForRequest(logonStatus);
|
sl@0
|
703 |
test(logonStatus==KErrNone);
|
sl@0
|
704 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
705 |
|
sl@0
|
706 |
test.Next(_L("Try changing priority of an un-resumed thread in other process"));
|
sl@0
|
707 |
thread.Create(TestThreadNull);
|
sl@0
|
708 |
thread.Logon(logonStatus);
|
sl@0
|
709 |
thread.SetPriority(EPriorityAbsoluteHigh);
|
sl@0
|
710 |
process.Create(~0u,ETestProcessSetPriority,thread.Id(),EPriorityAbsoluteLow);
|
sl@0
|
711 |
process.Logon(logonStatus2);
|
sl@0
|
712 |
process.Resume();
|
sl@0
|
713 |
User::WaitForRequest(logonStatus2);
|
sl@0
|
714 |
test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
|
sl@0
|
715 |
test(logonStatus2==EPlatformSecurityTrap);
|
sl@0
|
716 |
test(thread.Priority()==EPriorityAbsoluteHigh); // Priority should be unaltered
|
sl@0
|
717 |
|
sl@0
|
718 |
test.Next(_L("Try changing priority of a resumed thread in other process"));
|
sl@0
|
719 |
process.Create(~0u,ETestProcessSetPriority,thread.Id(),EPriorityAbsoluteLow);
|
sl@0
|
720 |
process.Logon(logonStatus2);
|
sl@0
|
721 |
SyncMutex.Wait();
|
sl@0
|
722 |
thread.Resume();
|
sl@0
|
723 |
process.Resume();
|
sl@0
|
724 |
User::WaitForRequest(logonStatus2);
|
sl@0
|
725 |
test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
|
sl@0
|
726 |
test(logonStatus2==EPlatformSecurityTrap);
|
sl@0
|
727 |
test(thread.Priority()==EPriorityAbsoluteHigh); // Priority should be unaltered
|
sl@0
|
728 |
SyncMutex.Signal();
|
sl@0
|
729 |
User::WaitForRequest(logonStatus);
|
sl@0
|
730 |
test(logonStatus==KErrNone);
|
sl@0
|
731 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
732 |
|
sl@0
|
733 |
test.Next(_L("Test setting thread priorities without ECapabilityProtServ"));
|
sl@0
|
734 |
process.Create(~(1u<<ECapabilityProtServ), ETestProcessSetPrioritiesWithoutProtServ);
|
sl@0
|
735 |
process.Run();
|
sl@0
|
736 |
|
sl@0
|
737 |
test.Next(_L("Test setting thread priorities with ECapabilityProtServ"));
|
sl@0
|
738 |
process.Create(1<<ECapabilityProtServ, ETestProcessSetPrioritiesWithProtServ);
|
sl@0
|
739 |
process.Run();
|
sl@0
|
740 |
|
sl@0
|
741 |
test.End();
|
sl@0
|
742 |
}
|
sl@0
|
743 |
|
sl@0
|
744 |
|
sl@0
|
745 |
TRequestStatus TestRequest;
|
sl@0
|
746 |
|
sl@0
|
747 |
TInt TestThreadRequestComplete(TAny* aArg)
|
sl@0
|
748 |
{
|
sl@0
|
749 |
RThread thread;
|
sl@0
|
750 |
TInt r = thread.Open((TInt)aArg);
|
sl@0
|
751 |
if(r==KErrNone)
|
sl@0
|
752 |
{
|
sl@0
|
753 |
TRequestStatus* status = &TestRequest;
|
sl@0
|
754 |
thread.RequestComplete(status,KErrNone);
|
sl@0
|
755 |
}
|
sl@0
|
756 |
return r;
|
sl@0
|
757 |
}
|
sl@0
|
758 |
|
sl@0
|
759 |
void TestRequestComplete()
|
sl@0
|
760 |
{
|
sl@0
|
761 |
RTestThread thread;
|
sl@0
|
762 |
RTestProcess process;
|
sl@0
|
763 |
TRequestStatus logonStatus;
|
sl@0
|
764 |
|
sl@0
|
765 |
test.Start(_L("Test RequestComplete on thread in current process"));
|
sl@0
|
766 |
TestRequest = KRequestPending;
|
sl@0
|
767 |
thread.Create(TestThreadRequestComplete,(TAny*)(TUint)RThread().Id());
|
sl@0
|
768 |
thread.Logon(logonStatus);
|
sl@0
|
769 |
thread.Resume();
|
sl@0
|
770 |
User::WaitForRequest(TestRequest);
|
sl@0
|
771 |
test(TestRequest==KErrNone);
|
sl@0
|
772 |
User::WaitForRequest(logonStatus);
|
sl@0
|
773 |
test(logonStatus==KErrNone);
|
sl@0
|
774 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
775 |
|
sl@0
|
776 |
test.Next(_L("Test RequestComplete on with NULL request pointer"));
|
sl@0
|
777 |
test(RThread().RequestCount()==0); // No signals
|
sl@0
|
778 |
TRequestStatus* nullReq = 0;
|
sl@0
|
779 |
RThread().RequestComplete(nullReq,0);
|
sl@0
|
780 |
test(RThread().RequestCount()==0); // No signals
|
sl@0
|
781 |
|
sl@0
|
782 |
test.Next(_L("Test RequestComplete on thread in different process"));
|
sl@0
|
783 |
TestRequest = KRequestPending;
|
sl@0
|
784 |
process.Create(~0u,ETestProcessRequestComplete,RThread().Id(),(TInt)&TestRequest);
|
sl@0
|
785 |
process.Logon(logonStatus);
|
sl@0
|
786 |
process.Resume();
|
sl@0
|
787 |
User::WaitForRequest(logonStatus);
|
sl@0
|
788 |
test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
|
sl@0
|
789 |
test(logonStatus==EPlatformSecurityTrap);
|
sl@0
|
790 |
test(TestRequest==KRequestPending);
|
sl@0
|
791 |
CLOSE_AND_WAIT(process);
|
sl@0
|
792 |
|
sl@0
|
793 |
test.End();
|
sl@0
|
794 |
}
|
sl@0
|
795 |
|
sl@0
|
796 |
|
sl@0
|
797 |
|
sl@0
|
798 |
TInt TestThreadRequestSignal(TAny* aArg)
|
sl@0
|
799 |
{
|
sl@0
|
800 |
RThread thread;
|
sl@0
|
801 |
TInt r = thread.Open((TInt)aArg);
|
sl@0
|
802 |
if(r==KErrNone)
|
sl@0
|
803 |
thread.RequestSignal();
|
sl@0
|
804 |
return r;
|
sl@0
|
805 |
}
|
sl@0
|
806 |
|
sl@0
|
807 |
void TestRequestSignal()
|
sl@0
|
808 |
{
|
sl@0
|
809 |
RTestThread thread;
|
sl@0
|
810 |
RTestProcess process;
|
sl@0
|
811 |
TRequestStatus logonStatus;
|
sl@0
|
812 |
TInt count;
|
sl@0
|
813 |
|
sl@0
|
814 |
test.Start(_L("Test RequestSignal on thread in current process"));
|
sl@0
|
815 |
thread.Create(TestThreadRequestSignal,(TAny*)(TUint)RThread().Id());
|
sl@0
|
816 |
thread.Logon(logonStatus);
|
sl@0
|
817 |
count = RThread().RequestCount();
|
sl@0
|
818 |
test(count==0); // No signals yet
|
sl@0
|
819 |
thread.Resume();
|
sl@0
|
820 |
User::WaitForRequest(logonStatus);
|
sl@0
|
821 |
test(logonStatus==KErrNone);
|
sl@0
|
822 |
count = RThread().RequestCount();
|
sl@0
|
823 |
test(count==1); // We should have been signalled
|
sl@0
|
824 |
User::WaitForAnyRequest(); // eat signal
|
sl@0
|
825 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
826 |
|
sl@0
|
827 |
test.Next(_L("Test RequestSignal on thread in different process"));
|
sl@0
|
828 |
process.Create(~0u,ETestProcessRequestSignal,RThread().Id(),0);
|
sl@0
|
829 |
process.Logon(logonStatus);
|
sl@0
|
830 |
process.Resume();
|
sl@0
|
831 |
User::WaitForRequest(logonStatus);
|
sl@0
|
832 |
test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
|
sl@0
|
833 |
test(logonStatus==EPlatformSecurityTrap);
|
sl@0
|
834 |
count = RThread().RequestCount();
|
sl@0
|
835 |
test(count==0); // We shouldn't have been signalled
|
sl@0
|
836 |
CLOSE_AND_WAIT(process);
|
sl@0
|
837 |
|
sl@0
|
838 |
test.End();
|
sl@0
|
839 |
}
|
sl@0
|
840 |
|
sl@0
|
841 |
|
sl@0
|
842 |
|
sl@0
|
843 |
void TestSetProcessPriority()
|
sl@0
|
844 |
{
|
sl@0
|
845 |
RTestThread thread;
|
sl@0
|
846 |
RTestProcess process;
|
sl@0
|
847 |
TProcessPriority priority;
|
sl@0
|
848 |
TRequestStatus rendezvousStatus;
|
sl@0
|
849 |
TRequestStatus logonStatus;
|
sl@0
|
850 |
TInt r;
|
sl@0
|
851 |
|
sl@0
|
852 |
test.Start(_L("Test changing our own process priority"));
|
sl@0
|
853 |
priority = process.Priority();
|
sl@0
|
854 |
thread.SetProcessPriority(EPriorityLow);
|
sl@0
|
855 |
test(process.Priority()==EPriorityLow);
|
sl@0
|
856 |
thread.SetProcessPriority(EPriorityBackground);
|
sl@0
|
857 |
test(process.Priority()==EPriorityBackground);
|
sl@0
|
858 |
thread.SetProcessPriority(EPriorityForeground);
|
sl@0
|
859 |
test(process.Priority()==EPriorityForeground);
|
sl@0
|
860 |
thread.SetProcessPriority(priority);
|
sl@0
|
861 |
|
sl@0
|
862 |
test.Next(_L("Try changing other process's priority (no priority-control enabled)"));
|
sl@0
|
863 |
process.Create(~0u,ETestProcessPriorityControlOff);
|
sl@0
|
864 |
process.Rendezvous(rendezvousStatus);
|
sl@0
|
865 |
process.Logon(logonStatus);
|
sl@0
|
866 |
SyncMutex.Wait();
|
sl@0
|
867 |
process.Resume();
|
sl@0
|
868 |
User::WaitForRequest(rendezvousStatus); // Process has started
|
sl@0
|
869 |
r = thread.Open(rendezvousStatus.Int()); // Process returned Id of main thread as status value
|
sl@0
|
870 |
test(r==KErrNone);
|
sl@0
|
871 |
priority = process.Priority();
|
sl@0
|
872 |
thread.SetProcessPriority(EPriorityLow);
|
sl@0
|
873 |
test(process.Priority()==priority); // priority shouldn't have changed
|
sl@0
|
874 |
thread.SetProcessPriority(EPriorityBackground);
|
sl@0
|
875 |
test(process.Priority()==priority); // priority shouldn't have changed
|
sl@0
|
876 |
thread.SetProcessPriority(EPriorityForeground);
|
sl@0
|
877 |
test(process.Priority()==priority); // priority shouldn't have changed
|
sl@0
|
878 |
test(logonStatus==KRequestPending); // wait for process to end
|
sl@0
|
879 |
SyncMutex.Signal();
|
sl@0
|
880 |
User::WaitForRequest(logonStatus);
|
sl@0
|
881 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
882 |
CLOSE_AND_WAIT(process);
|
sl@0
|
883 |
|
sl@0
|
884 |
test.Next(_L("Try changing other process's priority (priority-control enabled)"));
|
sl@0
|
885 |
process.Create(~0u,ETestProcessPriorityControlOn);
|
sl@0
|
886 |
process.Rendezvous(rendezvousStatus);
|
sl@0
|
887 |
process.Logon(logonStatus);
|
sl@0
|
888 |
SyncMutex.Wait();
|
sl@0
|
889 |
process.Resume();
|
sl@0
|
890 |
User::WaitForRequest(rendezvousStatus); // Process has started
|
sl@0
|
891 |
r = thread.Open(rendezvousStatus.Int()); // Process returned Id of main thread as status value
|
sl@0
|
892 |
test(r==KErrNone);
|
sl@0
|
893 |
priority = process.Priority();
|
sl@0
|
894 |
thread.SetProcessPriority(EPriorityForeground);
|
sl@0
|
895 |
test(process.Priority()==EPriorityForeground);
|
sl@0
|
896 |
thread.SetProcessPriority(EPriorityBackground);
|
sl@0
|
897 |
test(process.Priority()==EPriorityBackground);
|
sl@0
|
898 |
thread.SetProcessPriority(EPriorityForeground);
|
sl@0
|
899 |
test(process.Priority()==EPriorityForeground);
|
sl@0
|
900 |
thread.SetProcessPriority(EPriorityLow);
|
sl@0
|
901 |
test(process.Priority()==EPriorityForeground); // should still be foreground priority
|
sl@0
|
902 |
thread.SetProcessPriority(priority);
|
sl@0
|
903 |
test(logonStatus==KRequestPending); // wait for process to end
|
sl@0
|
904 |
SyncMutex.Signal();
|
sl@0
|
905 |
User::WaitForRequest(logonStatus);
|
sl@0
|
906 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
907 |
CLOSE_AND_WAIT(process);
|
sl@0
|
908 |
|
sl@0
|
909 |
test.End();
|
sl@0
|
910 |
}
|
sl@0
|
911 |
|
sl@0
|
912 |
|
sl@0
|
913 |
|
sl@0
|
914 |
GLDEF_C TInt E32Main()
|
sl@0
|
915 |
{
|
sl@0
|
916 |
TBuf16<512> cmd;
|
sl@0
|
917 |
User::CommandLine(cmd);
|
sl@0
|
918 |
if(cmd.Length() && TChar(cmd[0]).IsDigit())
|
sl@0
|
919 |
{
|
sl@0
|
920 |
TInt function = -1;
|
sl@0
|
921 |
TInt arg1 = -1;
|
sl@0
|
922 |
TInt arg2 = -1;
|
sl@0
|
923 |
TLex lex(cmd);
|
sl@0
|
924 |
|
sl@0
|
925 |
lex.Val(function);
|
sl@0
|
926 |
lex.SkipSpace();
|
sl@0
|
927 |
lex.Val(arg1);
|
sl@0
|
928 |
lex.SkipSpace();
|
sl@0
|
929 |
lex.Val(arg2);
|
sl@0
|
930 |
return DoTestProcess(function,arg1,arg2);
|
sl@0
|
931 |
}
|
sl@0
|
932 |
|
sl@0
|
933 |
test.Title();
|
sl@0
|
934 |
|
sl@0
|
935 |
if((!PlatSec::ConfigSetting(PlatSec::EPlatSecProcessIsolation))||(!PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement)))
|
sl@0
|
936 |
{
|
sl@0
|
937 |
test.Start(_L("TESTS NOT RUN - PlatSecProcessIsolation is not enforced"));
|
sl@0
|
938 |
test.End();
|
sl@0
|
939 |
return 0;
|
sl@0
|
940 |
}
|
sl@0
|
941 |
|
sl@0
|
942 |
test(SyncMutex.CreateGlobal(KSyncMutex)==KErrNone);
|
sl@0
|
943 |
|
sl@0
|
944 |
test.Start(_L("Test Rename"));
|
sl@0
|
945 |
TestRename();
|
sl@0
|
946 |
|
sl@0
|
947 |
test.Next(_L("Test Resume"));
|
sl@0
|
948 |
TestResume();
|
sl@0
|
949 |
|
sl@0
|
950 |
test.Next(_L("Test Suspend"));
|
sl@0
|
951 |
TestSuspend();
|
sl@0
|
952 |
|
sl@0
|
953 |
test.Next(_L("Test Kill, Panic and Teminate"));
|
sl@0
|
954 |
TestKill();
|
sl@0
|
955 |
|
sl@0
|
956 |
test.Next(_L("Test SetPriority"));
|
sl@0
|
957 |
TestSetPriority();
|
sl@0
|
958 |
|
sl@0
|
959 |
test.Next(_L("Test RequestComplete"));
|
sl@0
|
960 |
TestRequestComplete();
|
sl@0
|
961 |
|
sl@0
|
962 |
test.Next(_L("Test RequestSignal"));
|
sl@0
|
963 |
TestRequestSignal();
|
sl@0
|
964 |
|
sl@0
|
965 |
test.Next(_L("Test SetProcessPriority"));
|
sl@0
|
966 |
TestSetProcessPriority();
|
sl@0
|
967 |
|
sl@0
|
968 |
|
sl@0
|
969 |
SyncMutex.Close();
|
sl@0
|
970 |
test.End();
|
sl@0
|
971 |
|
sl@0
|
972 |
return(0);
|
sl@0
|
973 |
}
|
sl@0
|
974 |
|