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