Update contrib.
1 // Copyright (c) 1995-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\dll\t_tdlla.cpp
16 // Test static data in DLLs
20 // - Test statically linked DLLs with static data and verify results.
21 // - Load a dynamically loadable DLL, check DLL data, verify results.
22 // - Load a dynamically loadable DLL in another thread, check DLL data,
24 // - Load a DLL that is statically linked to the test process, check
25 // DLL data, verify results.
26 // - Load in a different thread a DLL that is statically linked to the
27 // test process, check DLL data, verify results.
28 // Platforms/Drives/Compatibility:
30 // Assumptions/Requirement/Pre-requisites:
31 // Failures and causes:
32 // Base Port information:
39 #include "../mmu/mmudetect.h"
41 LOCAL_D RTest test(_L("T_TDLLA"));
42 TInt InitialisedData=0x7c99103b;
43 TInt ZeroInitialisedData[32];
45 IMPORT_C TInt Function3();
46 IMPORT_C TInt Function4();
47 IMPORT_C void SetDll3Data(TInt);
48 IMPORT_C TInt GetDll3Data();
50 _LIT(KExeCommandLine,"2");
51 _LIT(KDll1Name,"T_DLLA1");
52 _LIT(KDll2Name,"T_DLLA2");
53 _LIT(KDll3Name,"T_DLLA3");
55 typedef TFullName& (*PFRFN)();
56 TFullName& DllA1ProcessName(RLibrary lib)
59 PFRFN f=(PFRFN)lib.Lookup(3);
63 TFullName& DllA1ThreadName(RLibrary lib)
66 PFRFN f=(PFRFN)lib.Lookup(4);
70 void Kick(RThread aThread)
73 TRequestStatus* pS=&s;
74 aThread.RequestComplete(pS,0);
77 RSemaphore gThreadSem;
81 const TDesC& name=*(const TDesC*)a;
87 User::WaitForAnyRequest();
95 const TDesC& name=*(const TDesC*)a;
101 User::WaitForAnyRequest();
105 LOCAL_D TInt ProcessEntryCount=0;
106 LOCAL_D TInt ExportCallCount=0;
107 EXPORT_C void ExportedFunction()
115 test.Printf(_L("SpawnExe()\n"));
116 if (User::CommandLineLength()!=0)
118 test.Printf(_L("This is second EXE\n"));
122 TInt r=p.Create(RProcess().FileName(), KExeCommandLine);
124 TFullName aFullName = p.FullName();
125 test.Printf(_L("Second EXE: %S\n"),&aFullName);
129 User::WaitForRequest(s);
130 TExitCategoryName aExitCategory = p.ExitCategory();
131 test.Printf(_L("Second EXE: %d,%d,%S\n"),p.ExitType(),p.ExitReason(),&aExitCategory);
136 GLDEF_C TInt E32Main()
138 // Test static data in dlls
142 // Turn off evil lazy dll unloading
144 test(l.Connect()==KErrNone);
145 test(l.CancelLazyDllUnload()==KErrNone);
148 test(InitialisedData==0x7c99103b);
152 test(ZeroInitialisedData[i]==0);
154 ZeroInitialisedData[i]=(i+487)*(i+487);
155 if (++ProcessEntryCount!=1)
156 User::Panic(_L("PROC_REENT"),ProcessEntryCount);
159 test.Start(_L("Test statically linked dlls with static data"));
161 test(Function3()==3);
162 test(Function4()==4);
164 test(GetDll3Data()==101);
166 test(GetDll3Data()==105);
168 test.Next(_L("Load T_DLLA1"));
171 TInt r=lib.Load(KDll1Name);
173 TLibraryFunction f=lib.Lookup(1);
174 test((*f)()==KErrNone);
178 test.Printf(_L("DLLA1 Process Name %S\n"),&DllA1ProcessName(lib));
179 test.Printf(_L("DLLA1 Thread Name %S\n"),&DllA1ThreadName(lib));
180 test(DllA1ProcessName(lib)==RProcess().FullName());
181 test(DllA1ThreadName(lib)==RThread().FullName());
183 test.Next(_L("Unload"));
186 test.Next(_L("Load again"));
187 r=lib.Load(KDll1Name);
189 test.Next(_L("Check Dll data"));
191 test((*f)()==KErrNone);
196 test.Next(_L("Close"));
199 test.Next(_L("Loading T_DLLA1 again in another thread"));
200 r=gThreadSem.CreateLocal(0);
202 r=t.Create(_L("Thread1"), Thread1, KDefaultStackSize, NULL, (TAny*)&KDll1Name);
204 t.SetPriority(EPriorityMore);
210 test.Next(_L("Load again"));
211 r=lib.Load(KDll1Name);
213 test.Printf(_L("DLLA1 Process Name %S\n"),&DllA1ProcessName(lib));
214 test.Printf(_L("DLLA1 Thread Name %S\n"),&DllA1ThreadName(lib));
215 test(DllA1ProcessName(lib)==RProcess().FullName());
216 test(DllA1ThreadName(lib)==t.FullName());
217 test.Next(_L("Check Dll data"));
219 test((*f)()==KErrNone);
226 User::WaitForRequest(stat);
227 test(stat==KErrNone);
228 test(t.ExitType()==EExitKill);
232 test.Printf(_L("DLLA1 Process Name %S\n"),&DllA1ProcessName(lib));
233 test.Printf(_L("DLLA1 Thread Name %S\n"),&DllA1ThreadName(lib));
234 test(DllA1ProcessName(lib)==RProcess().FullName());
235 test(DllA1ThreadName(lib)==t.FullName());
241 test.Next(_L("Close"));
244 test.Next(_L("Load a dll that this process is statically linked to"));
245 r=lib.Load(KDll3Name);
246 test.Printf(_L("Returns %d\n"),r);
248 test(GetDll3Data()==105);
250 test.Next(_L("Close it"));
252 test(GetDll3Data()==105);
254 test.Next(_L("Load a dll that is statically linked to this process"));
255 test(ExportCallCount==0);
256 r=lib.Load(KDll2Name);
258 test(InitialisedData==0x7c99103c);
260 test(ZeroInitialisedData[i]==(i+487)*(i+487));
261 test(ExportCallCount==1);
262 test.Next(_L("Close it"));
264 test(ExportCallCount==2);
266 test.Next(_L("Load it in a different thread"));
267 r=t.Create(_L("Thread1"), Thread1, KDefaultStackSize, NULL, (TAny*)&KDll2Name);
269 t.SetPriority(EPriorityMore);
273 test(ExportCallCount==3);
275 User::WaitForRequest(stat);
276 test(stat==KErrNone);
277 test(t.ExitType()==EExitKill);
278 test(ExportCallCount==4);
281 r=t.Create(_L("Thread2"), Thread2, KDefaultStackSize, NULL, (TAny*)&KDll2Name);
283 t.SetPriority(EPriorityMore);
287 test(ExportCallCount==5);
290 User::WaitForRequest(stat);
291 test(stat==KErrNone);
292 test(t.ExitType()==EExitKill);
293 test(ExportCallCount==6);
296 test.Next(_L("Test loading twice"));
297 RDebug::Print(_L("Loading T_DLLA1.DLL"));
298 r=lib.Load(KDll1Name);
301 test((*f)()==KErrNone);
304 test(DllA1ProcessName(lib)==RProcess().FullName());
305 test(DllA1ThreadName(lib)==RThread().FullName());
307 RDebug::Print(_L("Loading T_DLLA1.DLL again"));
308 r=lib2.Load(KDll1Name);
312 test(DllA1ProcessName(lib2)==RProcess().FullName());
313 test(DllA1ThreadName(lib2)==RThread().FullName());
315 test.Next(_L("Close One"));
316 RDebug::Print(_L("Closing T_DLLA1"));
320 test(DllA1ProcessName(lib2)==RProcess().FullName());
321 test(DllA1ThreadName(lib2)==RThread().FullName());
323 test.Next(_L("Close Two"));
324 RDebug::Print(_L("Closing T_DLLA1 again"));
326 test(GetDll3Data()==105);