sl@0
|
1 |
// Copyright (c) 2007-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\misc\t_destruct_slave.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#define __E32TEST_EXTENSION__
|
sl@0
|
19 |
|
sl@0
|
20 |
#include <e32std.h>
|
sl@0
|
21 |
#include <e32std_private.h>
|
sl@0
|
22 |
#include <e32test.h>
|
sl@0
|
23 |
#include <e32debug.h>
|
sl@0
|
24 |
#include <e32msgqueue.h>
|
sl@0
|
25 |
|
sl@0
|
26 |
#include "t_destruct.h"
|
sl@0
|
27 |
|
sl@0
|
28 |
_LIT(KDynamicDll, "t_destruct_dll2");
|
sl@0
|
29 |
|
sl@0
|
30 |
class TTestObject
|
sl@0
|
31 |
{
|
sl@0
|
32 |
public:
|
sl@0
|
33 |
TTestType iTestType;
|
sl@0
|
34 |
public:
|
sl@0
|
35 |
TTestObject();
|
sl@0
|
36 |
~TTestObject();
|
sl@0
|
37 |
};
|
sl@0
|
38 |
|
sl@0
|
39 |
RTest test(_L("t_desruct_slave"));
|
sl@0
|
40 |
TThreadId MainThreadId;
|
sl@0
|
41 |
TTestObject GlobalObjectWithDestructor;
|
sl@0
|
42 |
|
sl@0
|
43 |
void Panic(TInt aReason)
|
sl@0
|
44 |
{
|
sl@0
|
45 |
User::Panic(_L("t_destruct_slave"), aReason);
|
sl@0
|
46 |
}
|
sl@0
|
47 |
|
sl@0
|
48 |
TInt ExitThread(TAny*)
|
sl@0
|
49 |
{
|
sl@0
|
50 |
return KErrNone;
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
TInt PanicThread(TAny*)
|
sl@0
|
54 |
{
|
sl@0
|
55 |
Panic(KErrNone);
|
sl@0
|
56 |
return KErrNone;
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
TInt LoopThread(TAny*)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
// Open handle on dynamic DLL in this thread
|
sl@0
|
62 |
RLibrary library;
|
sl@0
|
63 |
test_KErrNone(library.Load(KDynamicDll));
|
sl@0
|
64 |
for (;;)
|
sl@0
|
65 |
;
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
TInt ChildThread(TAny* aArg)
|
sl@0
|
69 |
{
|
sl@0
|
70 |
TInt testType = (TInt)aArg;
|
sl@0
|
71 |
RThread mainThread;
|
sl@0
|
72 |
TInt r = mainThread.Open(MainThreadId);
|
sl@0
|
73 |
if (r != KErrNone)
|
sl@0
|
74 |
return r;
|
sl@0
|
75 |
// Open handle on dynamic DLL in this thread
|
sl@0
|
76 |
RLibrary library;
|
sl@0
|
77 |
test_KErrNone(library.Load(KDynamicDll));
|
sl@0
|
78 |
RThread().Rendezvous(KErrNone);
|
sl@0
|
79 |
TRequestStatus status;
|
sl@0
|
80 |
mainThread.Logon(status);
|
sl@0
|
81 |
User::WaitForRequest(status);
|
sl@0
|
82 |
if (mainThread.ExitType() != EExitKill)
|
sl@0
|
83 |
return KErrGeneral;
|
sl@0
|
84 |
if (mainThread.ExitReason() != KErrNone)
|
sl@0
|
85 |
return mainThread.ExitReason();
|
sl@0
|
86 |
mainThread.Close();
|
sl@0
|
87 |
if (testType != ETestRecursive)
|
sl@0
|
88 |
{
|
sl@0
|
89 |
RMsgQueue<TMessage> messageQueue;
|
sl@0
|
90 |
r = messageQueue.OpenGlobal(KMessageQueueName);
|
sl@0
|
91 |
if (r != KErrNone)
|
sl@0
|
92 |
return r;
|
sl@0
|
93 |
r = messageQueue.Send(EMessagePreDestruct);
|
sl@0
|
94 |
if (r != KErrNone)
|
sl@0
|
95 |
return r;
|
sl@0
|
96 |
}
|
sl@0
|
97 |
return testType;
|
sl@0
|
98 |
}
|
sl@0
|
99 |
|
sl@0
|
100 |
TInt PermanentThread(TAny* aArg)
|
sl@0
|
101 |
{
|
sl@0
|
102 |
TInt testType = (TInt)aArg;
|
sl@0
|
103 |
// Open handle on dynamic DLL in this thread
|
sl@0
|
104 |
RLibrary library;
|
sl@0
|
105 |
TInt r = library.Load(KDynamicDll);
|
sl@0
|
106 |
if (r != KErrNone)
|
sl@0
|
107 |
return r;
|
sl@0
|
108 |
RMsgQueue<TMessage> messageQueue;
|
sl@0
|
109 |
r = messageQueue.OpenGlobal(KMessageQueueName);
|
sl@0
|
110 |
if (r != KErrNone)
|
sl@0
|
111 |
return r;
|
sl@0
|
112 |
r = messageQueue.Send(EMessagePreDestruct);
|
sl@0
|
113 |
if (r != KErrNone)
|
sl@0
|
114 |
return r;
|
sl@0
|
115 |
messageQueue.Close();
|
sl@0
|
116 |
User::SetCritical(User::EProcessPermanent);
|
sl@0
|
117 |
User::Exit(testType);
|
sl@0
|
118 |
return KErrGeneral;
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
TTestObject::TTestObject()
|
sl@0
|
122 |
{
|
sl@0
|
123 |
RDebug::Printf("t_destruct_slave constructor called\n");
|
sl@0
|
124 |
RMsgQueue<TMessage> messageQueue;
|
sl@0
|
125 |
TInt r = messageQueue.OpenGlobal(KMessageQueueName);
|
sl@0
|
126 |
if (r != KErrNone)
|
sl@0
|
127 |
Panic(r);
|
sl@0
|
128 |
messageQueue.Send(EMessageConstruct);
|
sl@0
|
129 |
if (r != KErrNone)
|
sl@0
|
130 |
Panic(r);
|
sl@0
|
131 |
}
|
sl@0
|
132 |
|
sl@0
|
133 |
TTestObject::~TTestObject()
|
sl@0
|
134 |
{
|
sl@0
|
135 |
RDebug::Printf("t_destruct_slave destructor called\n");
|
sl@0
|
136 |
if (iTestType == ETestRecursive)
|
sl@0
|
137 |
{
|
sl@0
|
138 |
// Start child thread passing this thread's id
|
sl@0
|
139 |
MainThreadId = RThread().Id();
|
sl@0
|
140 |
RThread childThread;
|
sl@0
|
141 |
test_KErrNone(childThread.Create(_L("ChildThread"), ChildThread, 4096, NULL, (TAny*)iTestType));
|
sl@0
|
142 |
TRequestStatus status;
|
sl@0
|
143 |
childThread.Rendezvous(status);
|
sl@0
|
144 |
childThread.Resume();
|
sl@0
|
145 |
|
sl@0
|
146 |
// Wait for child to open handle on this thread
|
sl@0
|
147 |
User::WaitForRequest(status);
|
sl@0
|
148 |
test_KErrNone(status.Int());
|
sl@0
|
149 |
childThread.Close();
|
sl@0
|
150 |
|
sl@0
|
151 |
// Set this thread non-critical
|
sl@0
|
152 |
User::SetCritical(User::ENotCritical);
|
sl@0
|
153 |
}
|
sl@0
|
154 |
else if (iTestType == ETestDestructorExits)
|
sl@0
|
155 |
{
|
sl@0
|
156 |
User::Exit(iTestType);
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
RMsgQueue<TMessage> messageQueue;
|
sl@0
|
160 |
TInt r = messageQueue.OpenGlobal(KMessageQueueName);
|
sl@0
|
161 |
if (r != KErrNone)
|
sl@0
|
162 |
Panic(r);
|
sl@0
|
163 |
messageQueue.Send(EMessageDestruct);
|
sl@0
|
164 |
if (r != KErrNone)
|
sl@0
|
165 |
Panic(r);
|
sl@0
|
166 |
}
|
sl@0
|
167 |
|
sl@0
|
168 |
TInt E32Main()
|
sl@0
|
169 |
{
|
sl@0
|
170 |
StaticMain();
|
sl@0
|
171 |
|
sl@0
|
172 |
RBuf cmd;
|
sl@0
|
173 |
test_KErrNone(cmd.Create(User::CommandLineLength()));
|
sl@0
|
174 |
User::CommandLine(cmd);
|
sl@0
|
175 |
|
sl@0
|
176 |
TLex lex(cmd);
|
sl@0
|
177 |
TTestType type;
|
sl@0
|
178 |
test_KErrNone(lex.Val((TInt&)type));
|
sl@0
|
179 |
GlobalObjectWithDestructor.iTestType = type;
|
sl@0
|
180 |
|
sl@0
|
181 |
RMsgQueue<TMessage> messageQueue;
|
sl@0
|
182 |
test_KErrNone(messageQueue.OpenGlobal(KMessageQueueName));
|
sl@0
|
183 |
|
sl@0
|
184 |
// Dynamically load DLL with global data
|
sl@0
|
185 |
RLibrary library;
|
sl@0
|
186 |
test_KErrNone(library.Load(KDynamicDll));
|
sl@0
|
187 |
|
sl@0
|
188 |
switch(type)
|
sl@0
|
189 |
{
|
sl@0
|
190 |
case ETestMainThreadReturn:
|
sl@0
|
191 |
test_KErrNone(messageQueue.Send(EMessagePreDestruct));
|
sl@0
|
192 |
return type;
|
sl@0
|
193 |
|
sl@0
|
194 |
case ETestMainThreadExit:
|
sl@0
|
195 |
test_KErrNone(messageQueue.Send(EMessagePreDestruct));
|
sl@0
|
196 |
User::Exit(type);
|
sl@0
|
197 |
break;
|
sl@0
|
198 |
|
sl@0
|
199 |
case ETestChildThreadReturn:
|
sl@0
|
200 |
{
|
sl@0
|
201 |
// Start child thread passing this thread's id
|
sl@0
|
202 |
MainThreadId = RThread().Id();
|
sl@0
|
203 |
RThread childThread;
|
sl@0
|
204 |
test_KErrNone(childThread.Create(_L("ChildThread"), ChildThread, 4096, NULL, (TAny*)type));
|
sl@0
|
205 |
TRequestStatus status;
|
sl@0
|
206 |
childThread.Rendezvous(status);
|
sl@0
|
207 |
childThread.Resume();
|
sl@0
|
208 |
|
sl@0
|
209 |
User::After(1);
|
sl@0
|
210 |
|
sl@0
|
211 |
// Wait for child to open handle on this thread
|
sl@0
|
212 |
User::WaitForRequest(status);
|
sl@0
|
213 |
test_KErrNone(status.Int());
|
sl@0
|
214 |
childThread.Close();
|
sl@0
|
215 |
|
sl@0
|
216 |
// Set this thread non-critical and exit
|
sl@0
|
217 |
User::SetCritical(User::ENotCritical);
|
sl@0
|
218 |
}
|
sl@0
|
219 |
break;
|
sl@0
|
220 |
|
sl@0
|
221 |
case ETestOtherThreadExit:
|
sl@0
|
222 |
{
|
sl@0
|
223 |
RThread childThread;
|
sl@0
|
224 |
test_KErrNone(childThread.Create(_L("ChildThread"), ExitThread, 4096, NULL, (TAny*)type));
|
sl@0
|
225 |
childThread.Resume();
|
sl@0
|
226 |
TRequestStatus status;
|
sl@0
|
227 |
childThread.Logon(status);
|
sl@0
|
228 |
User::WaitForRequest(status);
|
sl@0
|
229 |
test_KErrNone(status.Int());
|
sl@0
|
230 |
childThread.Close();
|
sl@0
|
231 |
test_KErrNone(messageQueue.Send(EMessagePreDestruct));
|
sl@0
|
232 |
}
|
sl@0
|
233 |
return type;
|
sl@0
|
234 |
|
sl@0
|
235 |
case ETestOtherThreadPanic:
|
sl@0
|
236 |
{
|
sl@0
|
237 |
RThread childThread;
|
sl@0
|
238 |
test_KErrNone(childThread.Create(_L("ChildThread"), PanicThread, 4096, NULL, (TAny*)type));
|
sl@0
|
239 |
childThread.Resume();
|
sl@0
|
240 |
TRequestStatus status;
|
sl@0
|
241 |
childThread.Logon(status);
|
sl@0
|
242 |
User::WaitForRequest(status);
|
sl@0
|
243 |
test_KErrNone(status.Int());
|
sl@0
|
244 |
childThread.Close();
|
sl@0
|
245 |
test_KErrNone(messageQueue.Send(EMessagePreDestruct));
|
sl@0
|
246 |
}
|
sl@0
|
247 |
return type;
|
sl@0
|
248 |
|
sl@0
|
249 |
case ETestOtherThreadRunning:
|
sl@0
|
250 |
{
|
sl@0
|
251 |
RThread childThread;
|
sl@0
|
252 |
test_KErrNone(childThread.Create(_L("ChildThread"), LoopThread, 4096, NULL, (TAny*)type));
|
sl@0
|
253 |
childThread.Resume();
|
sl@0
|
254 |
childThread.Close();
|
sl@0
|
255 |
test_KErrNone(messageQueue.Send(EMessagePreDestruct));
|
sl@0
|
256 |
}
|
sl@0
|
257 |
return type;
|
sl@0
|
258 |
|
sl@0
|
259 |
case ETestPermanentThreadExit:
|
sl@0
|
260 |
{
|
sl@0
|
261 |
RThread childThread;
|
sl@0
|
262 |
test_KErrNone(childThread.Create(_L("ChildThread"), PermanentThread, 4096, NULL, (TAny*)type));
|
sl@0
|
263 |
childThread.Resume();
|
sl@0
|
264 |
TRequestStatus status;
|
sl@0
|
265 |
childThread.Logon(status);
|
sl@0
|
266 |
User::WaitForRequest(status);
|
sl@0
|
267 |
test_KErrNone(status.Int());
|
sl@0
|
268 |
childThread.Close();
|
sl@0
|
269 |
}
|
sl@0
|
270 |
break;
|
sl@0
|
271 |
|
sl@0
|
272 |
case ETestRecursive:
|
sl@0
|
273 |
test_KErrNone(messageQueue.Send(EMessagePreDestruct));
|
sl@0
|
274 |
break;
|
sl@0
|
275 |
|
sl@0
|
276 |
case ETestDestructorExits:
|
sl@0
|
277 |
test_KErrNone(messageQueue.Send(EMessagePreDestruct));
|
sl@0
|
278 |
break;
|
sl@0
|
279 |
|
sl@0
|
280 |
case ETestLastThreadPanic:
|
sl@0
|
281 |
test_KErrNone(messageQueue.Send(EMessagePreDestruct));
|
sl@0
|
282 |
Panic(type);
|
sl@0
|
283 |
break;
|
sl@0
|
284 |
|
sl@0
|
285 |
default:
|
sl@0
|
286 |
test(EFalse);
|
sl@0
|
287 |
}
|
sl@0
|
288 |
return KErrNone;
|
sl@0
|
289 |
}
|