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_chnot.cpp
|
sl@0
|
15 |
// Tests RChangeNotifier class
|
sl@0
|
16 |
// Overview:
|
sl@0
|
17 |
// Tests RChangeNotifier class
|
sl@0
|
18 |
// API Information:
|
sl@0
|
19 |
// RChangeNotifier
|
sl@0
|
20 |
// Details:
|
sl@0
|
21 |
// - Create a RChangeNotifier object and verify the logon status is
|
sl@0
|
22 |
// as expected.
|
sl@0
|
23 |
// - Call the Logon and LogonCancel methods, verify results are as
|
sl@0
|
24 |
// expected.
|
sl@0
|
25 |
// - Test for the correct midnight crossover notifier results in a
|
sl@0
|
26 |
// variety of situations: DST On, DST Off, various time offsets
|
sl@0
|
27 |
// and various dates.
|
sl@0
|
28 |
// - Test various locale changes and verify that the notifier response
|
sl@0
|
29 |
// is as expected.
|
sl@0
|
30 |
// - Test the notification of the death of a thread and check that
|
sl@0
|
31 |
// results are as expected. Check for normal exit, kill exit,
|
sl@0
|
32 |
// terminate exit and panic exit.
|
sl@0
|
33 |
// Platforms/Drives/Compatibility:
|
sl@0
|
34 |
// All.
|
sl@0
|
35 |
// Assumptions/Requirement/Pre-requisites:
|
sl@0
|
36 |
// Failures and causes:
|
sl@0
|
37 |
// Base Port information:
|
sl@0
|
38 |
//
|
sl@0
|
39 |
//
|
sl@0
|
40 |
|
sl@0
|
41 |
#define __E32TEST_EXTENSION__
|
sl@0
|
42 |
#include <e32test.h>
|
sl@0
|
43 |
#include <e32hal.h>
|
sl@0
|
44 |
#include <e32svr.h>
|
sl@0
|
45 |
#include <u32hal.h>
|
sl@0
|
46 |
#include <e32def.h>
|
sl@0
|
47 |
#include <e32def_private.h>
|
sl@0
|
48 |
|
sl@0
|
49 |
RTest test(_L("T_CHNOT"));
|
sl@0
|
50 |
|
sl@0
|
51 |
RChangeNotifier notifier;
|
sl@0
|
52 |
|
sl@0
|
53 |
void TestStat(const TRequestStatus& aStat, TInt aValue)
|
sl@0
|
54 |
{
|
sl@0
|
55 |
if (aStat.Int()!=aValue)
|
sl@0
|
56 |
{
|
sl@0
|
57 |
test.Printf(_L("Got %08x Expected %08x\n"),aStat.Int(),aValue);
|
sl@0
|
58 |
test(0);
|
sl@0
|
59 |
}
|
sl@0
|
60 |
}
|
sl@0
|
61 |
|
sl@0
|
62 |
void TestCreate()
|
sl@0
|
63 |
{
|
sl@0
|
64 |
notifier.Create();
|
sl@0
|
65 |
TRequestStatus stat;
|
sl@0
|
66 |
notifier.Logon(stat);
|
sl@0
|
67 |
|
sl@0
|
68 |
// Expect all except EChangesLowMemory
|
sl@0
|
69 |
TUint expected =
|
sl@0
|
70 |
EChangesLocale |
|
sl@0
|
71 |
EChangesMidnightCrossover |
|
sl@0
|
72 |
EChangesThreadDeath |
|
sl@0
|
73 |
EChangesPowerStatus |
|
sl@0
|
74 |
EChangesSystemTime |
|
sl@0
|
75 |
EChangesFreeMemory |
|
sl@0
|
76 |
EChangesOutOfMemory |
|
sl@0
|
77 |
EChangesThrashLevel;
|
sl@0
|
78 |
|
sl@0
|
79 |
test(stat==expected);
|
sl@0
|
80 |
}
|
sl@0
|
81 |
|
sl@0
|
82 |
void TestLogonLogoff()
|
sl@0
|
83 |
{
|
sl@0
|
84 |
TRequestStatus stat;
|
sl@0
|
85 |
notifier.LogonCancel();
|
sl@0
|
86 |
notifier.Logon(stat);
|
sl@0
|
87 |
TestStat(stat,KRequestPending);
|
sl@0
|
88 |
notifier.LogonCancel();
|
sl@0
|
89 |
TestStat(stat,KErrCancel);
|
sl@0
|
90 |
notifier.LogonCancel();
|
sl@0
|
91 |
TestStat(stat,KErrCancel);
|
sl@0
|
92 |
}
|
sl@0
|
93 |
|
sl@0
|
94 |
void DoTestMidnight()
|
sl@0
|
95 |
{
|
sl@0
|
96 |
TTime time;
|
sl@0
|
97 |
time.HomeTime();
|
sl@0
|
98 |
TDateTime dateTime=time.DateTime();
|
sl@0
|
99 |
dateTime.SetHour(23);
|
sl@0
|
100 |
dateTime.SetMinute(59);
|
sl@0
|
101 |
dateTime.SetSecond(58);
|
sl@0
|
102 |
dateTime.SetMicroSecond(700000);
|
sl@0
|
103 |
time=dateTime;
|
sl@0
|
104 |
TRequestStatus stat;
|
sl@0
|
105 |
TInt r=notifier.Logon(stat);
|
sl@0
|
106 |
test(r==KErrNone);
|
sl@0
|
107 |
TestStat(stat,KRequestPending);
|
sl@0
|
108 |
test(User::SetHomeTime(time)==KErrNone);
|
sl@0
|
109 |
time.HomeTime();
|
sl@0
|
110 |
TDateTime dateTime2=time.DateTime();
|
sl@0
|
111 |
User::WaitForRequest(stat);
|
sl@0
|
112 |
TestStat(stat,EChangesSystemTime);
|
sl@0
|
113 |
r=notifier.Logon(stat);
|
sl@0
|
114 |
test(r==KErrNone);
|
sl@0
|
115 |
User::WaitForRequest(stat);
|
sl@0
|
116 |
time.HomeTime();
|
sl@0
|
117 |
TestStat(stat,EChangesMidnightCrossover);
|
sl@0
|
118 |
dateTime2=time.DateTime();
|
sl@0
|
119 |
test(dateTime2.Second()==0);
|
sl@0
|
120 |
test(dateTime2.Minute()==0);
|
sl@0
|
121 |
test(dateTime2.Hour()==0);
|
sl@0
|
122 |
if (dateTime2.Month()==dateTime.Month())
|
sl@0
|
123 |
test(dateTime2.Day()==dateTime.Day()+1);
|
sl@0
|
124 |
else
|
sl@0
|
125 |
test(dateTime2.Day()==0);
|
sl@0
|
126 |
time=dateTime;
|
sl@0
|
127 |
r=notifier.Logon(stat);
|
sl@0
|
128 |
test(r==KErrNone);
|
sl@0
|
129 |
TestStat(stat,KRequestPending);
|
sl@0
|
130 |
test(User::SetHomeTime(time)==KErrNone);
|
sl@0
|
131 |
User::WaitForRequest(stat);
|
sl@0
|
132 |
TestStat(stat,(EChangesSystemTime|EChangesMidnightCrossover));
|
sl@0
|
133 |
time=dateTime2;
|
sl@0
|
134 |
r=notifier.Logon(stat);
|
sl@0
|
135 |
test(r==KErrNone);
|
sl@0
|
136 |
TestStat(stat,KRequestPending);
|
sl@0
|
137 |
test(User::SetHomeTime(time)==KErrNone);
|
sl@0
|
138 |
User::WaitForRequest(stat);
|
sl@0
|
139 |
TestStat(stat,(EChangesSystemTime|EChangesMidnightCrossover));
|
sl@0
|
140 |
|
sl@0
|
141 |
// Check that a change of secure time also triggers notification, even though the user time is unchanged
|
sl@0
|
142 |
r = notifier.Logon(stat);
|
sl@0
|
143 |
test(r == KErrNone);
|
sl@0
|
144 |
TestStat(stat, KRequestPending);
|
sl@0
|
145 |
if ((r = time.HomeTimeSecure()) == KErrNone)
|
sl@0
|
146 |
r = User::SetHomeTimeSecure(time+TTimeIntervalSeconds(60));
|
sl@0
|
147 |
if (r == KErrNone)
|
sl@0
|
148 |
{
|
sl@0
|
149 |
test(User::SetHomeTimeSecure(time) == KErrNone);
|
sl@0
|
150 |
r = EChangesSystemTime;
|
sl@0
|
151 |
}
|
sl@0
|
152 |
else
|
sl@0
|
153 |
{
|
sl@0
|
154 |
RDebug::Printf("WARNING: Secure clock change test skipped because secure time could not be changed!");
|
sl@0
|
155 |
notifier.LogonCancel();
|
sl@0
|
156 |
r = KErrCancel;
|
sl@0
|
157 |
}
|
sl@0
|
158 |
User::WaitForRequest(stat);
|
sl@0
|
159 |
TestStat(stat, r);
|
sl@0
|
160 |
}
|
sl@0
|
161 |
|
sl@0
|
162 |
void SetOffsetForMidnight(TTime time,TTimeIntervalSeconds offset)
|
sl@0
|
163 |
{
|
sl@0
|
164 |
test(User::SetHomeTime(time)==KErrNone);
|
sl@0
|
165 |
User::SetUTCOffset(offset);
|
sl@0
|
166 |
// No longer need next line, as we now only get one notification
|
sl@0
|
167 |
// User::After(999999);//So, if time has gone backwards, midnight crossover has been noticed
|
sl@0
|
168 |
TRequestStatus stat;
|
sl@0
|
169 |
notifier.Logon(stat);
|
sl@0
|
170 |
User::WaitForRequest(stat);
|
sl@0
|
171 |
test(stat.Int()&(EChangesSystemTime|EChangesLocale));
|
sl@0
|
172 |
}
|
sl@0
|
173 |
|
sl@0
|
174 |
void TestMidnightCrossover()
|
sl@0
|
175 |
{
|
sl@0
|
176 |
TTimeIntervalSeconds offset=User::UTCOffset();
|
sl@0
|
177 |
TTime time;
|
sl@0
|
178 |
time.HomeTime();
|
sl@0
|
179 |
test.Start(_L("Normal"));
|
sl@0
|
180 |
DoTestMidnight();
|
sl@0
|
181 |
test.Next(_L("Now offset 0"));
|
sl@0
|
182 |
SetOffsetForMidnight(time,0);
|
sl@0
|
183 |
DoTestMidnight();
|
sl@0
|
184 |
test.Next(_L("Now offset +30"));
|
sl@0
|
185 |
SetOffsetForMidnight(time,30);
|
sl@0
|
186 |
DoTestMidnight();
|
sl@0
|
187 |
test.Next(_L("Now offset -30"));
|
sl@0
|
188 |
SetOffsetForMidnight(time,-30);
|
sl@0
|
189 |
DoTestMidnight();
|
sl@0
|
190 |
test.Next(_L("Now offset +60"));
|
sl@0
|
191 |
SetOffsetForMidnight(time,60);
|
sl@0
|
192 |
DoTestMidnight();
|
sl@0
|
193 |
test.Next(_L("Now offset -60"));
|
sl@0
|
194 |
SetOffsetForMidnight(time,-60);
|
sl@0
|
195 |
DoTestMidnight();
|
sl@0
|
196 |
test.Next(_L("Now offset +120"));
|
sl@0
|
197 |
SetOffsetForMidnight(time,120);
|
sl@0
|
198 |
DoTestMidnight();
|
sl@0
|
199 |
test.Next(_L("Now offset -120"));
|
sl@0
|
200 |
SetOffsetForMidnight(time,-120);
|
sl@0
|
201 |
DoTestMidnight();
|
sl@0
|
202 |
//
|
sl@0
|
203 |
TTime time1998=TDateTime(1998,EFebruary,2,3,4,5,6);
|
sl@0
|
204 |
test.Next(_L("1998 offset 0"));
|
sl@0
|
205 |
SetOffsetForMidnight(time1998,0);
|
sl@0
|
206 |
DoTestMidnight();
|
sl@0
|
207 |
test.Next(_L("1998 offset +30"));
|
sl@0
|
208 |
SetOffsetForMidnight(time1998,30);
|
sl@0
|
209 |
DoTestMidnight();
|
sl@0
|
210 |
test.Next(_L("1998 offset -30"));
|
sl@0
|
211 |
SetOffsetForMidnight(time1998,-30);
|
sl@0
|
212 |
DoTestMidnight();
|
sl@0
|
213 |
test.Next(_L("1998 offset +60"));
|
sl@0
|
214 |
SetOffsetForMidnight(time1998,60);
|
sl@0
|
215 |
DoTestMidnight();
|
sl@0
|
216 |
test.Next(_L("1998 offset -60"));
|
sl@0
|
217 |
SetOffsetForMidnight(time1998,-60);
|
sl@0
|
218 |
DoTestMidnight();
|
sl@0
|
219 |
test.Next(_L("1998 offset +120"));
|
sl@0
|
220 |
SetOffsetForMidnight(time1998,120);
|
sl@0
|
221 |
DoTestMidnight();
|
sl@0
|
222 |
test.Next(_L("1998 offset -120"));
|
sl@0
|
223 |
SetOffsetForMidnight(time1998,-120);
|
sl@0
|
224 |
DoTestMidnight();
|
sl@0
|
225 |
//
|
sl@0
|
226 |
TTime time1999=TDateTime(1999,EDecember,30,3,4,5,6);
|
sl@0
|
227 |
test.Next(_L("1999 offset 0"));
|
sl@0
|
228 |
SetOffsetForMidnight(time1999,0);
|
sl@0
|
229 |
DoTestMidnight();
|
sl@0
|
230 |
TTime now;
|
sl@0
|
231 |
now.HomeTime();
|
sl@0
|
232 |
test(now.DateTime().Year()==2000);
|
sl@0
|
233 |
test(now.DateTime().Month()==EJanuary);
|
sl@0
|
234 |
test.Next(_L("1999 offset +30"));
|
sl@0
|
235 |
SetOffsetForMidnight(time1999,30);
|
sl@0
|
236 |
DoTestMidnight();
|
sl@0
|
237 |
now.HomeTime();
|
sl@0
|
238 |
test(now.DateTime().Year()==2000);
|
sl@0
|
239 |
test(now.DateTime().Month()==EJanuary);
|
sl@0
|
240 |
test.Next(_L("1999 offset -30"));
|
sl@0
|
241 |
SetOffsetForMidnight(time1999,-30);
|
sl@0
|
242 |
DoTestMidnight();
|
sl@0
|
243 |
now.HomeTime();
|
sl@0
|
244 |
test(now.DateTime().Year()==2000);
|
sl@0
|
245 |
test(now.DateTime().Month()==EJanuary);
|
sl@0
|
246 |
test.Next(_L("1999 offset +60"));
|
sl@0
|
247 |
SetOffsetForMidnight(time1999,60);
|
sl@0
|
248 |
DoTestMidnight();
|
sl@0
|
249 |
now.HomeTime();
|
sl@0
|
250 |
test(now.DateTime().Year()==2000);
|
sl@0
|
251 |
test(now.DateTime().Month()==EJanuary);
|
sl@0
|
252 |
test.Next(_L("1999 offset -60"));
|
sl@0
|
253 |
SetOffsetForMidnight(time1999,-60);
|
sl@0
|
254 |
DoTestMidnight();
|
sl@0
|
255 |
now.HomeTime();
|
sl@0
|
256 |
test(now.DateTime().Year()==2000);
|
sl@0
|
257 |
test(now.DateTime().Month()==EJanuary);
|
sl@0
|
258 |
test.Next(_L("1999 offset +120"));
|
sl@0
|
259 |
SetOffsetForMidnight(time1999,120);
|
sl@0
|
260 |
DoTestMidnight();
|
sl@0
|
261 |
now.HomeTime();
|
sl@0
|
262 |
test(now.DateTime().Year()==2000);
|
sl@0
|
263 |
test(now.DateTime().Month()==EJanuary);
|
sl@0
|
264 |
test.Next(_L("1999 offset -120"));
|
sl@0
|
265 |
SetOffsetForMidnight(time1999,-120);
|
sl@0
|
266 |
DoTestMidnight();
|
sl@0
|
267 |
now.HomeTime();
|
sl@0
|
268 |
test(now.DateTime().Year()==2000);
|
sl@0
|
269 |
test(now.DateTime().Month()==EJanuary);
|
sl@0
|
270 |
//
|
sl@0
|
271 |
TTime time2002=TDateTime(2002,EAugust,30,3,4,5,6);
|
sl@0
|
272 |
test.Next(_L("2002 offset 0"));
|
sl@0
|
273 |
SetOffsetForMidnight(time2002,0);
|
sl@0
|
274 |
DoTestMidnight();
|
sl@0
|
275 |
test.Next(_L("2002 offset +30"));
|
sl@0
|
276 |
SetOffsetForMidnight(time2002,30);
|
sl@0
|
277 |
DoTestMidnight();
|
sl@0
|
278 |
test.Next(_L("2002 offset -30"));
|
sl@0
|
279 |
SetOffsetForMidnight(time2002,-30);
|
sl@0
|
280 |
DoTestMidnight();
|
sl@0
|
281 |
test.Next(_L("2002 offset +60"));
|
sl@0
|
282 |
SetOffsetForMidnight(time2002,60);
|
sl@0
|
283 |
DoTestMidnight();
|
sl@0
|
284 |
test.Next(_L("2002 offset -60"));
|
sl@0
|
285 |
SetOffsetForMidnight(time2002,-60);
|
sl@0
|
286 |
DoTestMidnight();
|
sl@0
|
287 |
test.Next(_L("2002 offset +120"));
|
sl@0
|
288 |
SetOffsetForMidnight(time2002,120);
|
sl@0
|
289 |
DoTestMidnight();
|
sl@0
|
290 |
test.Next(_L("2002 offset -120"));
|
sl@0
|
291 |
SetOffsetForMidnight(time2002,-120);
|
sl@0
|
292 |
DoTestMidnight();
|
sl@0
|
293 |
//
|
sl@0
|
294 |
SetOffsetForMidnight(time,offset);
|
sl@0
|
295 |
test.End();
|
sl@0
|
296 |
}
|
sl@0
|
297 |
|
sl@0
|
298 |
void TestLocaleChanges()
|
sl@0
|
299 |
{
|
sl@0
|
300 |
TRequestStatus stat;
|
sl@0
|
301 |
notifier.Logon(stat);
|
sl@0
|
302 |
TestStat(stat,KRequestPending);
|
sl@0
|
303 |
TLocale locale;
|
sl@0
|
304 |
locale.Set();
|
sl@0
|
305 |
User::WaitForRequest(stat);
|
sl@0
|
306 |
TestStat(stat,EChangesLocale);
|
sl@0
|
307 |
}
|
sl@0
|
308 |
|
sl@0
|
309 |
void TestOffsetChanges()
|
sl@0
|
310 |
{
|
sl@0
|
311 |
TTimeIntervalSeconds oldOffset = User::UTCOffset();
|
sl@0
|
312 |
User::SetUTCOffset(0);
|
sl@0
|
313 |
|
sl@0
|
314 |
TRequestStatus stat;
|
sl@0
|
315 |
TTime time;
|
sl@0
|
316 |
time.HomeTime();
|
sl@0
|
317 |
TDateTime dateTime=time.DateTime();
|
sl@0
|
318 |
dateTime.SetHour(23);
|
sl@0
|
319 |
dateTime.SetMinute(30);
|
sl@0
|
320 |
dateTime.SetSecond(0);
|
sl@0
|
321 |
dateTime.SetMicroSecond(0);
|
sl@0
|
322 |
time=dateTime;
|
sl@0
|
323 |
test(User::SetHomeTime(time)==KErrNone);
|
sl@0
|
324 |
notifier.Logon(stat);
|
sl@0
|
325 |
User::WaitForRequest(stat);
|
sl@0
|
326 |
TestStat(stat,(EChangesSystemTime));
|
sl@0
|
327 |
|
sl@0
|
328 |
notifier.Logon(stat);
|
sl@0
|
329 |
TestStat(stat,KRequestPending);
|
sl@0
|
330 |
User::SetUTCOffset(3600);
|
sl@0
|
331 |
User::WaitForRequest(stat);
|
sl@0
|
332 |
TestStat(stat,(EChangesSystemTime|EChangesLocale|EChangesMidnightCrossover));
|
sl@0
|
333 |
User::SetUTCOffset(oldOffset);
|
sl@0
|
334 |
notifier.Logon(stat);
|
sl@0
|
335 |
User::WaitForRequest(stat);
|
sl@0
|
336 |
}
|
sl@0
|
337 |
|
sl@0
|
338 |
const TInt retValue=65432;
|
sl@0
|
339 |
const TInt killValue=2081953;
|
sl@0
|
340 |
const TInt terminateValue=512123;
|
sl@0
|
341 |
const TInt panicValue=1257671;
|
sl@0
|
342 |
const TInt KHeapSize=0x200;
|
sl@0
|
343 |
|
sl@0
|
344 |
TInt ThreadCode(TAny* aReturnImmetiateFlag)
|
sl@0
|
345 |
{
|
sl@0
|
346 |
if(!aReturnImmetiateFlag)
|
sl@0
|
347 |
User::After(60000000); // wait a minute, (effectively forever as far as the test goes).
|
sl@0
|
348 |
return retValue;
|
sl@0
|
349 |
}
|
sl@0
|
350 |
|
sl@0
|
351 |
void TestThreadDeath()
|
sl@0
|
352 |
{
|
sl@0
|
353 |
test.Start(_L("Normal Exit"));
|
sl@0
|
354 |
RThread thread;
|
sl@0
|
355 |
TInt r=thread.Create(_L("T_CHNOT ThreadCode"),ThreadCode,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)ETrue);
|
sl@0
|
356 |
test(r==KErrNone);
|
sl@0
|
357 |
__KHEAP_MARK;
|
sl@0
|
358 |
TRequestStatus threadStat;
|
sl@0
|
359 |
thread.Logon(threadStat);
|
sl@0
|
360 |
TRequestStatus stat;
|
sl@0
|
361 |
notifier.Logon(stat);
|
sl@0
|
362 |
TestStat(stat,KRequestPending);
|
sl@0
|
363 |
thread.Resume();
|
sl@0
|
364 |
User::WaitForRequest(stat);
|
sl@0
|
365 |
TestStat(stat,EChangesThreadDeath);
|
sl@0
|
366 |
test(threadStat==retValue);
|
sl@0
|
367 |
test(thread.ExitReason()==retValue);
|
sl@0
|
368 |
test(thread.ExitType()==EExitKill);
|
sl@0
|
369 |
test(thread.ExitCategory()==_L("Kill"));
|
sl@0
|
370 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
371 |
__KHEAP_MARKEND;
|
sl@0
|
372 |
|
sl@0
|
373 |
test.Next(_L("Kill"));
|
sl@0
|
374 |
r=thread.Create(_L("T_CHNOT ThreadCode"),ThreadCode,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
|
sl@0
|
375 |
test(r==KErrNone);
|
sl@0
|
376 |
thread.Logon(threadStat);
|
sl@0
|
377 |
notifier.Logon(stat);
|
sl@0
|
378 |
TestStat(stat,KRequestPending);
|
sl@0
|
379 |
thread.Resume();
|
sl@0
|
380 |
thread.Kill(killValue);
|
sl@0
|
381 |
User::WaitForRequest(stat);
|
sl@0
|
382 |
TestStat(stat,EChangesThreadDeath);
|
sl@0
|
383 |
test(threadStat==killValue);
|
sl@0
|
384 |
test(thread.ExitReason()==killValue);
|
sl@0
|
385 |
test(thread.ExitType()==EExitKill);
|
sl@0
|
386 |
test(thread.ExitCategory()==_L("Kill"));
|
sl@0
|
387 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
388 |
|
sl@0
|
389 |
test.Next(_L("Terminate"));
|
sl@0
|
390 |
r=thread.Create(_L("T_CHNOT ThreadCode"),ThreadCode,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
|
sl@0
|
391 |
test(r==KErrNone);
|
sl@0
|
392 |
thread.Logon(threadStat);
|
sl@0
|
393 |
notifier.Logon(stat);
|
sl@0
|
394 |
TestStat(stat,KRequestPending);
|
sl@0
|
395 |
thread.Resume();
|
sl@0
|
396 |
thread.Terminate(terminateValue);
|
sl@0
|
397 |
User::WaitForRequest(stat);
|
sl@0
|
398 |
TestStat(stat,EChangesThreadDeath);
|
sl@0
|
399 |
test(threadStat==terminateValue);
|
sl@0
|
400 |
test(thread.ExitReason()==terminateValue);
|
sl@0
|
401 |
test(thread.ExitType()==EExitTerminate);
|
sl@0
|
402 |
test(thread.ExitCategory()==_L("Terminate"));
|
sl@0
|
403 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
404 |
|
sl@0
|
405 |
test.Next(_L("Panic"));
|
sl@0
|
406 |
r=thread.Create(_L("T_CHNOT ThreadCode"),ThreadCode,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
|
sl@0
|
407 |
test(r==KErrNone);
|
sl@0
|
408 |
thread.Logon(threadStat);
|
sl@0
|
409 |
notifier.Logon(stat);
|
sl@0
|
410 |
TestStat(stat,KRequestPending);
|
sl@0
|
411 |
TBool justInTime=User::JustInTime();
|
sl@0
|
412 |
User::SetJustInTime(EFalse);
|
sl@0
|
413 |
thread.Resume();
|
sl@0
|
414 |
thread.Panic(_L("Testing panic"),panicValue);
|
sl@0
|
415 |
User::WaitForRequest(stat);
|
sl@0
|
416 |
User::SetJustInTime(justInTime);
|
sl@0
|
417 |
TestStat(stat,EChangesThreadDeath);
|
sl@0
|
418 |
test(threadStat==panicValue);
|
sl@0
|
419 |
test(thread.ExitReason()==panicValue);
|
sl@0
|
420 |
test(thread.ExitType()==EExitPanic);
|
sl@0
|
421 |
test(thread.ExitCategory()==_L("Testing panic"));
|
sl@0
|
422 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
423 |
test.End();
|
sl@0
|
424 |
}
|
sl@0
|
425 |
|
sl@0
|
426 |
void TestCloseWhilstPending()
|
sl@0
|
427 |
{
|
sl@0
|
428 |
test_KErrNone(notifier.Create());
|
sl@0
|
429 |
TRequestStatus stat;
|
sl@0
|
430 |
test_KErrNone(notifier.Logon(stat));
|
sl@0
|
431 |
User::WaitForRequest(stat);
|
sl@0
|
432 |
test_KErrNone(notifier.Logon(stat));
|
sl@0
|
433 |
notifier.Close();
|
sl@0
|
434 |
test_Equal(KErrGeneral,stat.Int());
|
sl@0
|
435 |
}
|
sl@0
|
436 |
|
sl@0
|
437 |
void TestCloseAndCompleteRace()
|
sl@0
|
438 |
{
|
sl@0
|
439 |
RThread().SetPriority(EPriorityRealTime);
|
sl@0
|
440 |
|
sl@0
|
441 |
// setup notifier2
|
sl@0
|
442 |
RChangeNotifier notifier2;
|
sl@0
|
443 |
test_KErrNone(notifier2.Create());
|
sl@0
|
444 |
TRequestStatus stat2;
|
sl@0
|
445 |
test_KErrNone(notifier2.Logon(stat2));
|
sl@0
|
446 |
User::WaitForRequest(stat2);
|
sl@0
|
447 |
test_KErrNone(notifier2.Logon(stat2));
|
sl@0
|
448 |
|
sl@0
|
449 |
// setup notifier
|
sl@0
|
450 |
test_KErrNone(notifier.Create());
|
sl@0
|
451 |
TRequestStatus stat;
|
sl@0
|
452 |
test_KErrNone(notifier.Logon(stat));
|
sl@0
|
453 |
User::WaitForRequest(stat);
|
sl@0
|
454 |
test_KErrNone(notifier.Logon(stat));
|
sl@0
|
455 |
|
sl@0
|
456 |
// create and kill a thread so notifiers get signaled
|
sl@0
|
457 |
RThread thread;
|
sl@0
|
458 |
test_KErrNone(thread.Create(_L("T_CHNOT ThreadCode"),ThreadCode,KDefaultStackSize,KHeapSize,KHeapSize,NULL));
|
sl@0
|
459 |
thread.Kill(0);
|
sl@0
|
460 |
|
sl@0
|
461 |
// wait for notifier2
|
sl@0
|
462 |
User::WaitForRequest(stat2);
|
sl@0
|
463 |
|
sl@0
|
464 |
// as this thread is realtime priority, then (on unicore systems) it has preempted
|
sl@0
|
465 |
// kernel supervisor thread after it completed 'notifier2' but before it completed
|
sl@0
|
466 |
// 'notifier'. if we close both notifiers now we trigger a race conidition which
|
sl@0
|
467 |
// previousely caused a null pointer dereference in the kernel...
|
sl@0
|
468 |
notifier.Close();
|
sl@0
|
469 |
notifier2.Close();
|
sl@0
|
470 |
|
sl@0
|
471 |
User::WaitForRequest(stat);
|
sl@0
|
472 |
TInt result = stat.Int();
|
sl@0
|
473 |
|
sl@0
|
474 |
// expect KErrGeneral from closing notifier, or on SMP probably EChangesThreadDeath as
|
sl@0
|
475 |
// the notifier had time to complete
|
sl@0
|
476 |
const TInt numCpus = UserSvr::HalFunction(EHalGroupKernel, EKernelHalNumLogicalCpus, 0, 0);
|
sl@0
|
477 |
if(numCpus==1 || result!=EChangesThreadDeath)
|
sl@0
|
478 |
test_Equal(KErrGeneral,result);
|
sl@0
|
479 |
|
sl@0
|
480 |
RThread().SetPriority(EPriorityNormal);
|
sl@0
|
481 |
thread.Close();
|
sl@0
|
482 |
}
|
sl@0
|
483 |
|
sl@0
|
484 |
TInt E32Main()
|
sl@0
|
485 |
{
|
sl@0
|
486 |
|
sl@0
|
487 |
User::After(1000000);//So WINS doesn't give an instant power-status change;
|
sl@0
|
488 |
test.Start(_L("Create"));
|
sl@0
|
489 |
TestCreate();
|
sl@0
|
490 |
|
sl@0
|
491 |
test.Next(_L("Close"));
|
sl@0
|
492 |
notifier.Close();
|
sl@0
|
493 |
|
sl@0
|
494 |
test.Next(_L("Create"));
|
sl@0
|
495 |
TestCreate();
|
sl@0
|
496 |
|
sl@0
|
497 |
test.Next(_L("Logon/Logoff"));
|
sl@0
|
498 |
TestLogonLogoff();
|
sl@0
|
499 |
|
sl@0
|
500 |
test.Next(_L("Midnight crossover"));
|
sl@0
|
501 |
TestMidnightCrossover();
|
sl@0
|
502 |
|
sl@0
|
503 |
test.Next(_L("Locale changes"));
|
sl@0
|
504 |
TestLocaleChanges();
|
sl@0
|
505 |
|
sl@0
|
506 |
test.Next(_L("Offset changes"));
|
sl@0
|
507 |
TestOffsetChanges();
|
sl@0
|
508 |
|
sl@0
|
509 |
test.Next(_L("Thread death"));
|
sl@0
|
510 |
TestThreadDeath();
|
sl@0
|
511 |
|
sl@0
|
512 |
test.Next(_L("Close"));
|
sl@0
|
513 |
notifier.Close();
|
sl@0
|
514 |
|
sl@0
|
515 |
test.Next(_L("Close whilst pending"));
|
sl@0
|
516 |
TestCloseWhilstPending();
|
sl@0
|
517 |
|
sl@0
|
518 |
test.Next(_L("Race between Close and complete"));
|
sl@0
|
519 |
TestCloseAndCompleteRace();
|
sl@0
|
520 |
|
sl@0
|
521 |
test.End();
|
sl@0
|
522 |
return KErrNone;
|
sl@0
|
523 |
}
|