sl@0
|
1 |
// Copyright (c) 1995-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\dll\t_tdlla.cpp
|
sl@0
|
15 |
// Overview:
|
sl@0
|
16 |
// Test static data in DLLs
|
sl@0
|
17 |
// API Information:
|
sl@0
|
18 |
// RLibrary
|
sl@0
|
19 |
// Details:
|
sl@0
|
20 |
// - Test statically linked DLLs with static data and verify results.
|
sl@0
|
21 |
// - Load a dynamically loadable DLL, check DLL data, verify results.
|
sl@0
|
22 |
// - Load a dynamically loadable DLL in another thread, check DLL data,
|
sl@0
|
23 |
// verify results.
|
sl@0
|
24 |
// - Load a DLL that is statically linked to the test process, check
|
sl@0
|
25 |
// DLL data, verify results.
|
sl@0
|
26 |
// - Load in a different thread a DLL that is statically linked to the
|
sl@0
|
27 |
// test process, check DLL data, verify results.
|
sl@0
|
28 |
// Platforms/Drives/Compatibility:
|
sl@0
|
29 |
// All.
|
sl@0
|
30 |
// Assumptions/Requirement/Pre-requisites:
|
sl@0
|
31 |
// Failures and causes:
|
sl@0
|
32 |
// Base Port information:
|
sl@0
|
33 |
//
|
sl@0
|
34 |
//
|
sl@0
|
35 |
|
sl@0
|
36 |
#include <e32test.h>
|
sl@0
|
37 |
#include <e32svr.h>
|
sl@0
|
38 |
|
sl@0
|
39 |
#include "../mmu/mmudetect.h"
|
sl@0
|
40 |
|
sl@0
|
41 |
LOCAL_D RTest test(_L("T_TDLLA"));
|
sl@0
|
42 |
TInt InitialisedData=0x7c99103b;
|
sl@0
|
43 |
TInt ZeroInitialisedData[32];
|
sl@0
|
44 |
|
sl@0
|
45 |
IMPORT_C TInt Function3();
|
sl@0
|
46 |
IMPORT_C TInt Function4();
|
sl@0
|
47 |
IMPORT_C void SetDll3Data(TInt);
|
sl@0
|
48 |
IMPORT_C TInt GetDll3Data();
|
sl@0
|
49 |
|
sl@0
|
50 |
_LIT(KExeCommandLine,"2");
|
sl@0
|
51 |
_LIT(KDll1Name,"T_DLLA1");
|
sl@0
|
52 |
_LIT(KDll2Name,"T_DLLA2");
|
sl@0
|
53 |
_LIT(KDll3Name,"T_DLLA3");
|
sl@0
|
54 |
|
sl@0
|
55 |
typedef TFullName& (*PFRFN)();
|
sl@0
|
56 |
TFullName& DllA1ProcessName(RLibrary lib)
|
sl@0
|
57 |
{
|
sl@0
|
58 |
|
sl@0
|
59 |
PFRFN f=(PFRFN)lib.Lookup(3);
|
sl@0
|
60 |
return (*f)();
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
TFullName& DllA1ThreadName(RLibrary lib)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
|
sl@0
|
66 |
PFRFN f=(PFRFN)lib.Lookup(4);
|
sl@0
|
67 |
return (*f)();
|
sl@0
|
68 |
}
|
sl@0
|
69 |
|
sl@0
|
70 |
void Kick(RThread aThread)
|
sl@0
|
71 |
{
|
sl@0
|
72 |
TRequestStatus s;
|
sl@0
|
73 |
TRequestStatus* pS=&s;
|
sl@0
|
74 |
aThread.RequestComplete(pS,0);
|
sl@0
|
75 |
}
|
sl@0
|
76 |
|
sl@0
|
77 |
RSemaphore gThreadSem;
|
sl@0
|
78 |
TInt Thread1(TAny* a)
|
sl@0
|
79 |
{
|
sl@0
|
80 |
TInt r=KErrNone;
|
sl@0
|
81 |
const TDesC& name=*(const TDesC*)a;
|
sl@0
|
82 |
RLibrary lib;
|
sl@0
|
83 |
r=lib.Load(name);
|
sl@0
|
84 |
if (r!=KErrNone)
|
sl@0
|
85 |
return r;
|
sl@0
|
86 |
gThreadSem.Signal();
|
sl@0
|
87 |
User::WaitForAnyRequest();
|
sl@0
|
88 |
lib.Close();
|
sl@0
|
89 |
return KErrNone;
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
TInt Thread2(TAny* a)
|
sl@0
|
93 |
{
|
sl@0
|
94 |
TInt r=KErrNone;
|
sl@0
|
95 |
const TDesC& name=*(const TDesC*)a;
|
sl@0
|
96 |
RLibrary lib;
|
sl@0
|
97 |
r=lib.Load(name);
|
sl@0
|
98 |
if (r!=KErrNone)
|
sl@0
|
99 |
return r;
|
sl@0
|
100 |
gThreadSem.Signal();
|
sl@0
|
101 |
User::WaitForAnyRequest();
|
sl@0
|
102 |
return KErrNone;
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
LOCAL_D TInt ProcessEntryCount=0;
|
sl@0
|
106 |
LOCAL_D TInt ExportCallCount=0;
|
sl@0
|
107 |
EXPORT_C void ExportedFunction()
|
sl@0
|
108 |
{
|
sl@0
|
109 |
++ExportCallCount;
|
sl@0
|
110 |
}
|
sl@0
|
111 |
|
sl@0
|
112 |
void SpawnExe()
|
sl@0
|
113 |
{
|
sl@0
|
114 |
#ifdef __EPOC32__
|
sl@0
|
115 |
test.Printf(_L("SpawnExe()\n"));
|
sl@0
|
116 |
if (User::CommandLineLength()!=0)
|
sl@0
|
117 |
{
|
sl@0
|
118 |
test.Printf(_L("This is second EXE\n"));
|
sl@0
|
119 |
return;
|
sl@0
|
120 |
}
|
sl@0
|
121 |
RProcess p;
|
sl@0
|
122 |
TInt r=p.Create(RProcess().FileName(), KExeCommandLine);
|
sl@0
|
123 |
test(r==KErrNone);
|
sl@0
|
124 |
TFullName aFullName = p.FullName();
|
sl@0
|
125 |
test.Printf(_L("Second EXE: %S\n"),&aFullName);
|
sl@0
|
126 |
TRequestStatus s;
|
sl@0
|
127 |
p.Logon(s);
|
sl@0
|
128 |
p.Resume();
|
sl@0
|
129 |
User::WaitForRequest(s);
|
sl@0
|
130 |
TExitCategoryName aExitCategory = p.ExitCategory();
|
sl@0
|
131 |
test.Printf(_L("Second EXE: %d,%d,%S\n"),p.ExitType(),p.ExitReason(),&aExitCategory);
|
sl@0
|
132 |
CLOSE_AND_WAIT(p);
|
sl@0
|
133 |
#endif
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
GLDEF_C TInt E32Main()
|
sl@0
|
137 |
//
|
sl@0
|
138 |
// Test static data in dlls
|
sl@0
|
139 |
//
|
sl@0
|
140 |
{
|
sl@0
|
141 |
|
sl@0
|
142 |
// Turn off evil lazy dll unloading
|
sl@0
|
143 |
RLoader l;
|
sl@0
|
144 |
test(l.Connect()==KErrNone);
|
sl@0
|
145 |
test(l.CancelLazyDllUnload()==KErrNone);
|
sl@0
|
146 |
l.Close();
|
sl@0
|
147 |
|
sl@0
|
148 |
test(InitialisedData==0x7c99103b);
|
sl@0
|
149 |
++InitialisedData;
|
sl@0
|
150 |
TInt i;
|
sl@0
|
151 |
for (i=0; i<31; ++i)
|
sl@0
|
152 |
test(ZeroInitialisedData[i]==0);
|
sl@0
|
153 |
for (i=0; i<31; ++i)
|
sl@0
|
154 |
ZeroInitialisedData[i]=(i+487)*(i+487);
|
sl@0
|
155 |
if (++ProcessEntryCount!=1)
|
sl@0
|
156 |
User::Panic(_L("PROC_REENT"),ProcessEntryCount);
|
sl@0
|
157 |
|
sl@0
|
158 |
test.Title();
|
sl@0
|
159 |
test.Start(_L("Test statically linked dlls with static data"));
|
sl@0
|
160 |
|
sl@0
|
161 |
test(Function3()==3);
|
sl@0
|
162 |
test(Function4()==4);
|
sl@0
|
163 |
SetDll3Data(101);
|
sl@0
|
164 |
test(GetDll3Data()==101);
|
sl@0
|
165 |
SetDll3Data(105);
|
sl@0
|
166 |
test(GetDll3Data()==105);
|
sl@0
|
167 |
|
sl@0
|
168 |
test.Next(_L("Load T_DLLA1"));
|
sl@0
|
169 |
|
sl@0
|
170 |
RLibrary lib;
|
sl@0
|
171 |
TInt r=lib.Load(KDll1Name);
|
sl@0
|
172 |
test(r==KErrNone);
|
sl@0
|
173 |
TLibraryFunction f=lib.Lookup(1);
|
sl@0
|
174 |
test((*f)()==KErrNone);
|
sl@0
|
175 |
f=lib.Lookup(2);
|
sl@0
|
176 |
test((*f)()==1);
|
sl@0
|
177 |
|
sl@0
|
178 |
test.Printf(_L("DLLA1 Process Name %S\n"),&DllA1ProcessName(lib));
|
sl@0
|
179 |
test.Printf(_L("DLLA1 Thread Name %S\n"),&DllA1ThreadName(lib));
|
sl@0
|
180 |
test(DllA1ProcessName(lib)==RProcess().FullName());
|
sl@0
|
181 |
test(DllA1ThreadName(lib)==RThread().FullName());
|
sl@0
|
182 |
|
sl@0
|
183 |
test.Next(_L("Unload"));
|
sl@0
|
184 |
lib.Close();
|
sl@0
|
185 |
|
sl@0
|
186 |
test.Next(_L("Load again"));
|
sl@0
|
187 |
r=lib.Load(KDll1Name);
|
sl@0
|
188 |
test(r==KErrNone);
|
sl@0
|
189 |
test.Next(_L("Check Dll data"));
|
sl@0
|
190 |
f=lib.Lookup(1);
|
sl@0
|
191 |
test((*f)()==KErrNone);
|
sl@0
|
192 |
f=lib.Lookup(2);
|
sl@0
|
193 |
test((*f)()==1);
|
sl@0
|
194 |
test((*f)()==2);
|
sl@0
|
195 |
test((*f)()==3);
|
sl@0
|
196 |
test.Next(_L("Close"));
|
sl@0
|
197 |
lib.Close();
|
sl@0
|
198 |
|
sl@0
|
199 |
test.Next(_L("Loading T_DLLA1 again in another thread"));
|
sl@0
|
200 |
r=gThreadSem.CreateLocal(0);
|
sl@0
|
201 |
RThread t;
|
sl@0
|
202 |
r=t.Create(_L("Thread1"), Thread1, KDefaultStackSize, NULL, (TAny*)&KDll1Name);
|
sl@0
|
203 |
test(r==KErrNone);
|
sl@0
|
204 |
t.SetPriority(EPriorityMore);
|
sl@0
|
205 |
TRequestStatus stat;
|
sl@0
|
206 |
t.Logon(stat);
|
sl@0
|
207 |
t.Resume();
|
sl@0
|
208 |
gThreadSem.Wait();
|
sl@0
|
209 |
|
sl@0
|
210 |
test.Next(_L("Load again"));
|
sl@0
|
211 |
r=lib.Load(KDll1Name);
|
sl@0
|
212 |
test(r==KErrNone);
|
sl@0
|
213 |
test.Printf(_L("DLLA1 Process Name %S\n"),&DllA1ProcessName(lib));
|
sl@0
|
214 |
test.Printf(_L("DLLA1 Thread Name %S\n"),&DllA1ThreadName(lib));
|
sl@0
|
215 |
test(DllA1ProcessName(lib)==RProcess().FullName());
|
sl@0
|
216 |
test(DllA1ThreadName(lib)==t.FullName());
|
sl@0
|
217 |
test.Next(_L("Check Dll data"));
|
sl@0
|
218 |
f=lib.Lookup(1);
|
sl@0
|
219 |
test((*f)()==KErrNone);
|
sl@0
|
220 |
f=lib.Lookup(2);
|
sl@0
|
221 |
test((*f)()==1);
|
sl@0
|
222 |
test((*f)()==2);
|
sl@0
|
223 |
test((*f)()==3);
|
sl@0
|
224 |
|
sl@0
|
225 |
Kick(t);
|
sl@0
|
226 |
User::WaitForRequest(stat);
|
sl@0
|
227 |
test(stat==KErrNone);
|
sl@0
|
228 |
test(t.ExitType()==EExitKill);
|
sl@0
|
229 |
|
sl@0
|
230 |
SpawnExe();
|
sl@0
|
231 |
|
sl@0
|
232 |
test.Printf(_L("DLLA1 Process Name %S\n"),&DllA1ProcessName(lib));
|
sl@0
|
233 |
test.Printf(_L("DLLA1 Thread Name %S\n"),&DllA1ThreadName(lib));
|
sl@0
|
234 |
test(DllA1ProcessName(lib)==RProcess().FullName());
|
sl@0
|
235 |
test(DllA1ThreadName(lib)==t.FullName());
|
sl@0
|
236 |
test((*f)()==4);
|
sl@0
|
237 |
test((*f)()==5);
|
sl@0
|
238 |
test((*f)()==6);
|
sl@0
|
239 |
|
sl@0
|
240 |
CLOSE_AND_WAIT(t);
|
sl@0
|
241 |
test.Next(_L("Close"));
|
sl@0
|
242 |
lib.Close();
|
sl@0
|
243 |
|
sl@0
|
244 |
test.Next(_L("Load a dll that this process is statically linked to"));
|
sl@0
|
245 |
r=lib.Load(KDll3Name);
|
sl@0
|
246 |
test.Printf(_L("Returns %d\n"),r);
|
sl@0
|
247 |
test(r==KErrNone);
|
sl@0
|
248 |
test(GetDll3Data()==105);
|
sl@0
|
249 |
|
sl@0
|
250 |
test.Next(_L("Close it"));
|
sl@0
|
251 |
lib.Close();
|
sl@0
|
252 |
test(GetDll3Data()==105);
|
sl@0
|
253 |
|
sl@0
|
254 |
test.Next(_L("Load a dll that is statically linked to this process"));
|
sl@0
|
255 |
test(ExportCallCount==0);
|
sl@0
|
256 |
r=lib.Load(KDll2Name);
|
sl@0
|
257 |
test(r==KErrNone);
|
sl@0
|
258 |
test(InitialisedData==0x7c99103c);
|
sl@0
|
259 |
for (i=0; i<31; ++i)
|
sl@0
|
260 |
test(ZeroInitialisedData[i]==(i+487)*(i+487));
|
sl@0
|
261 |
test(ExportCallCount==1);
|
sl@0
|
262 |
test.Next(_L("Close it"));
|
sl@0
|
263 |
lib.Close();
|
sl@0
|
264 |
test(ExportCallCount==2);
|
sl@0
|
265 |
|
sl@0
|
266 |
test.Next(_L("Load it in a different thread"));
|
sl@0
|
267 |
r=t.Create(_L("Thread1"), Thread1, KDefaultStackSize, NULL, (TAny*)&KDll2Name);
|
sl@0
|
268 |
test(r==KErrNone);
|
sl@0
|
269 |
t.SetPriority(EPriorityMore);
|
sl@0
|
270 |
t.Logon(stat);
|
sl@0
|
271 |
t.Resume();
|
sl@0
|
272 |
gThreadSem.Wait();
|
sl@0
|
273 |
test(ExportCallCount==3);
|
sl@0
|
274 |
Kick(t);
|
sl@0
|
275 |
User::WaitForRequest(stat);
|
sl@0
|
276 |
test(stat==KErrNone);
|
sl@0
|
277 |
test(t.ExitType()==EExitKill);
|
sl@0
|
278 |
test(ExportCallCount==4);
|
sl@0
|
279 |
CLOSE_AND_WAIT(t);
|
sl@0
|
280 |
|
sl@0
|
281 |
r=t.Create(_L("Thread2"), Thread2, KDefaultStackSize, NULL, (TAny*)&KDll2Name);
|
sl@0
|
282 |
test(r==KErrNone);
|
sl@0
|
283 |
t.SetPriority(EPriorityMore);
|
sl@0
|
284 |
t.Logon(stat);
|
sl@0
|
285 |
t.Resume();
|
sl@0
|
286 |
gThreadSem.Wait();
|
sl@0
|
287 |
test(ExportCallCount==5);
|
sl@0
|
288 |
SpawnExe();
|
sl@0
|
289 |
Kick(t);
|
sl@0
|
290 |
User::WaitForRequest(stat);
|
sl@0
|
291 |
test(stat==KErrNone);
|
sl@0
|
292 |
test(t.ExitType()==EExitKill);
|
sl@0
|
293 |
test(ExportCallCount==6);
|
sl@0
|
294 |
CLOSE_AND_WAIT(t);
|
sl@0
|
295 |
|
sl@0
|
296 |
test.Next(_L("Test loading twice"));
|
sl@0
|
297 |
RDebug::Print(_L("Loading T_DLLA1.DLL"));
|
sl@0
|
298 |
r=lib.Load(KDll1Name);
|
sl@0
|
299 |
test(r==KErrNone);
|
sl@0
|
300 |
f=lib.Lookup(1);
|
sl@0
|
301 |
test((*f)()==KErrNone);
|
sl@0
|
302 |
f=lib.Lookup(2);
|
sl@0
|
303 |
test((*f)()==1);
|
sl@0
|
304 |
test(DllA1ProcessName(lib)==RProcess().FullName());
|
sl@0
|
305 |
test(DllA1ThreadName(lib)==RThread().FullName());
|
sl@0
|
306 |
RLibrary lib2;
|
sl@0
|
307 |
RDebug::Print(_L("Loading T_DLLA1.DLL again"));
|
sl@0
|
308 |
r=lib2.Load(KDll1Name);
|
sl@0
|
309 |
test(r==KErrNone);
|
sl@0
|
310 |
f=lib2.Lookup(2);
|
sl@0
|
311 |
test((*f)()==2);
|
sl@0
|
312 |
test(DllA1ProcessName(lib2)==RProcess().FullName());
|
sl@0
|
313 |
test(DllA1ThreadName(lib2)==RThread().FullName());
|
sl@0
|
314 |
|
sl@0
|
315 |
test.Next(_L("Close One"));
|
sl@0
|
316 |
RDebug::Print(_L("Closing T_DLLA1"));
|
sl@0
|
317 |
lib.Close();
|
sl@0
|
318 |
f=lib2.Lookup(2);
|
sl@0
|
319 |
test((*f)()==3);
|
sl@0
|
320 |
test(DllA1ProcessName(lib2)==RProcess().FullName());
|
sl@0
|
321 |
test(DllA1ThreadName(lib2)==RThread().FullName());
|
sl@0
|
322 |
|
sl@0
|
323 |
test.Next(_L("Close Two"));
|
sl@0
|
324 |
RDebug::Print(_L("Closing T_DLLA1 again"));
|
sl@0
|
325 |
lib2.Close();
|
sl@0
|
326 |
test(GetDll3Data()==105);
|
sl@0
|
327 |
|
sl@0
|
328 |
test.End();
|
sl@0
|
329 |
return(KErrNone);
|
sl@0
|
330 |
}
|
sl@0
|
331 |
|