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_tdll12.cpp
16 // Test DLL Thread Local Storage data and DLL Global data access.
20 // - Test that the local storage of two different DLLs, when accessed from
21 // two different threads is unique. Verify that results are as expected.
22 // - Test the access of DLL Global data including Alloc, Read and Write. Test
23 // the protection of the global data. Verify results are as expected.
24 // Platforms/Drives/Compatibility:
26 // Assumptions/Requirement/Pre-requisites:
27 // Failures and causes:
28 // Base Port information:
33 #include "../mmu/mmudetect.h"
35 const TInt KHeapSize=0x2000;
37 LOCAL_D RTest test(_L("T_TDLL12"));
39 TBool KernProt=EFalse;
45 KernProt=HaveDirectKernProt();
47 TUint32 mm_attr=MemModelAttributes();
48 TUint32 mm_type=mm_attr & EMemModelTypeMask;
51 case EMemModelTypeDirect:
52 Garbage=(TUint8*)0xa8000000;
54 case EMemModelTypeMoving:
55 Garbage=(TUint8*)0x60f00000;
57 case EMemModelTypeMultiple:
58 Garbage=(TUint8*)0xfe000000;
60 case EMemModelTypeFlexible:
61 Garbage=(TUint8*)0x8ff00000;
63 case EMemModelTypeEmul:
64 Garbage=(TUint8*)0xf0000000;
72 void RunTestInThread(TThreadFunction aFn, TAny* aParameter, const TDesC* aPanicCat, TInt aExitCode)
75 TInt r=t.Create(KNullDesC(),aFn,0x2000,NULL,aParameter);
80 User::WaitForRequest(s);
83 test(t.ExitType()==EExitPanic);
84 test(t.ExitCategory()==*aPanicCat);
85 test(t.ExitReason()==aExitCode);
89 test(t.ExitType()==EExitKill);
90 test(t.ExitReason()==aExitCode);
95 TInt GlobalReadThread(TAny* a)
97 return TestDll1::GlobalRead(122,*(TDes8*)a);
100 TInt GlobalWriteThread(TAny* a)
102 return TestDll1::GlobalWrite(0,*(TDes8*)a);
105 _LIT(KLitKernExec,"KERN-EXEC");
106 void TestProtection()
108 test.Next(_L("Test protection"));
109 TBool jit=User::JustInTime();
110 User::SetJustInTime(EFalse);
113 TPtrC8 uptrc(ubuf.Ptr(),11);
114 TPtr8 uptr((TUint8*)ubuf.Ptr(),1,20);
115 TPtrC8 kptrc(Kern,1);
116 TPtr8 kptr(Kern,10,256);
117 TPtrC8 gptrc(Garbage,1);
118 TPtr8 gptr(Garbage,10,256);
119 RunTestInThread(GlobalReadThread,&x,&KLitKernExec,EKUDesInfoInvalidType);
120 RunTestInThread(GlobalReadThread,&ubuf,NULL,KErrNone);
121 RunTestInThread(GlobalReadThread,&uptr,NULL,KErrNone);
122 RunTestInThread(GlobalReadThread,&uptrc,&KLitKernExec,EKUDesInfoInvalidType);
123 RunTestInThread(GlobalReadThread,&kptrc,&KLitKernExec,EKUDesInfoInvalidType);
124 RunTestInThread(GlobalReadThread,&gptrc,&KLitKernExec,EKUDesInfoInvalidType);
125 RunTestInThread(GlobalReadThread,&gptr,&KLitKernExec,ECausedException);
128 RunTestInThread(GlobalReadThread,Kern,&KLitKernExec,ECausedException);
129 RunTestInThread(GlobalReadThread,&kptr,&KLitKernExec,ECausedException);
131 RunTestInThread(GlobalWriteThread,&x,&KLitKernExec,EKUDesInfoInvalidType);
132 RunTestInThread(GlobalWriteThread,&ubuf,NULL,KErrNone);
133 RunTestInThread(GlobalWriteThread,&uptr,NULL,KErrNone);
134 RunTestInThread(GlobalWriteThread,&uptrc,NULL,KErrNone);
135 RunTestInThread(GlobalWriteThread,&gptrc,&KLitKernExec,ECausedException);
136 RunTestInThread(GlobalWriteThread,&gptr,&KLitKernExec,ECausedException);
139 RunTestInThread(GlobalWriteThread,Kern,&KLitKernExec,ECausedException);
140 RunTestInThread(GlobalWriteThread,&kptrc,&KLitKernExec,ECausedException);
141 RunTestInThread(GlobalWriteThread,&kptr,&KLitKernExec,ECausedException);
143 User::SetJustInTime(jit);
146 LOCAL_C TInt Dll1Thread2(TAny* /*anArg*/)
148 // The entry point for thread2.
152 test(TestDll1::Attach(ETrue)==KErrNone);
153 test((TUint)TestDll1::Data()==0x12345678);
154 TestDll1::SetData(0xfedcba98);
155 test((TUint)TestDll1::Data()==0xfedcba98);
156 test(TestDll1::Attach(EFalse)==KErrNone);
160 LOCAL_C TInt Dll2Thread2(TAny* /*anArg*/)
162 // The entry point for thread2.
166 test(TestDll2::Attach(ETrue)==KErrNone);
167 test((TUint)TestDll2::Data()==0xABCDABCD);
168 TestDll2::SetData(0x12341234);
169 test((TUint)TestDll2::Data()==0x12341234);
170 test(TestDll2::Attach(EFalse)==KErrNone);
174 void testGlobalAlloc()
181 test.Start(_L("Test Dll::GlobalAlloc"));
183 test(TestDll1::GlobalAllocated()==EFalse);
184 test(TestDll2::GlobalAllocated()==EFalse);
185 r=TestDll2::GlobalAlloc(0);
187 r=TestDll1::GlobalAlloc(256);
189 test(TestDll1::GlobalAllocated());
190 test(TestDll2::GlobalAllocated()==EFalse);
191 r=TestDll2::GlobalAlloc(256);
193 test(TestDll1::GlobalAllocated());
194 test(TestDll2::GlobalAllocated());
196 test.Next(_L("Write"));
200 buf100.SetLength(0x100);
201 for (i=0; i<256; i++)
202 buf100[i]=(TText8)('A'+i%26);
203 r=TestDll1::GlobalWrite(0, buf100);
206 r=TestDll2::GlobalWrite(0, buf100);
209 test.Next(_L("Read"));
211 r=TestDll1::GlobalRead(0, buf100);
213 for (i=0; i<256; i++)
214 test(buf100[i]=='A'+i%26);
216 r=TestDll2::GlobalRead(0, buf100);
218 for (i=0; i<256; i++)
219 test(buf100[i]=='X');
221 test.Next(_L("Realloc"));
222 r=TestDll1::GlobalAlloc(128);
224 test(TestDll1::GlobalAllocated());
225 test(TestDll2::GlobalAllocated());
226 test.Next(_L("Read"));
227 r=TestDll1::GlobalRead(0,buf100);
228 for (i=0; i<128; i++)
229 test(buf100[i]=='A'+i%26);
230 test(buf100.Length()==128);
231 r=TestDll2::GlobalRead(0,buf100);
233 for (i=0; i<256; i++)
234 test(buf100[i]=='X');
235 test(buf100.Length()==256);
237 test.Next(_L("Read @ pos"));
238 // Read from position
239 r=TestDll1::GlobalRead(1, buf100);
241 test(buf100.Length()==127);
242 for (i=0; i<127; i++)
243 test(buf100[i]=='A'+(i+1)%26);
244 test.Next(_L("Write @ pos"));
245 buf100=_L8("LALALALALALA");
246 r=TestDll1::GlobalWrite(5, buf100);
248 buf100=_L8("POPOPOPOPO");
249 r=TestDll2::GlobalWrite(4, buf100);
251 r=TestDll1::GlobalRead(0, buf100);
252 buf100.SetLength(20);
253 test(buf100==_L8("ABCDELALALALALALARST"));
254 r=TestDll2::GlobalRead(0, buf100);
255 buf100.SetLength(20);
256 test(buf100==_L8("XXXXPOPOPOPOPOXXXXXX"));
260 test.Next(_L("Free Global Alloc"));
261 r=TestDll1::GlobalAlloc(0);
263 test(TestDll1::GlobalAllocated()==EFalse);
264 test(TestDll2::GlobalAllocated());
266 r=TestDll2::GlobalWrite(0, _L8("WEEEEEEEEEE"));
268 r=TestDll2::GlobalRead(0, buf100);
269 buf100.SetLength(11);
270 test(buf100==_L8("WEEEEEEEEEE"));
271 r=TestDll1::GlobalAlloc(0);
273 r=TestDll2::GlobalAlloc(0);
275 test(TestDll1::GlobalAllocated()==EFalse);
276 test(TestDll2::GlobalAllocated()==EFalse);
281 GLDEF_C TInt E32Main()
283 // Test DLL Thread Local Storage data.
290 test.Start(_L("Dll1 Thread 1"));
291 test(TestDll1::Attach(ETrue)==KErrNone);
292 test((TUint)TestDll1::Data()==0x12345678);
293 TestDll1::SetData(0x87654321);
294 test((TUint)TestDll1::Data()==0x87654321);
296 test.Next(_L("Dll1 Thread 2"));
298 TInt r=t.Create(_L("Dll1 Thread2"),Dll1Thread2,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
300 TRequestStatus tStat;
302 test(tStat==KRequestPending);
304 User::WaitForRequest(tStat);
305 test(tStat==KErrNone);
307 test.Next(_L("Dll1 Thread 1 again"));
308 test((TUint)TestDll1::Data()==0x87654321);
309 TestDll1::SetData(0x12345678);
310 test((TUint)TestDll1::Data()==0x12345678);
312 test(TestDll1::Attach(EFalse)==KErrNone);
314 test.Next(_L("Dll2 Thread 1"));
315 test(TestDll2::Attach(ETrue)==KErrNone);
316 test((TUint)TestDll2::Data()==0xABCDABCD);
317 TestDll2::SetData(0xDCBADCBA);
318 test((TUint)TestDll2::Data()==0xDCBADCBA);
320 test.Next(_L("Dll2 Thread 2"));
321 r=t.Create(_L("Dll2 Thread2"),Dll2Thread2,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
324 test(tStat==KRequestPending);
326 User::WaitForRequest(tStat);
327 test(tStat==KErrNone);
329 test.Next(_L("Dll2 Thread 1 again"));
330 test((TUint)TestDll2::Data()==0xDCBADCBA);
331 TestDll2::SetData(0xABCDABCD);
332 test((TUint)TestDll2::Data()==0xABCDABCD);
334 test(TestDll2::Attach(EFalse)==KErrNone);
336 test.Next(_L("Dll1 Thread 1"));
337 test(TestDll1::Attach(ETrue)==KErrNone);
338 test((TUint)TestDll1::Data()==0x12345678);
339 TestDll1::SetData(0x87654321);
340 test((TUint)TestDll1::Data()==0x87654321);
342 test.Next(_L("Dll2 Thread 1"));
343 test(TestDll2::Attach(ETrue)==KErrNone);
344 test((TUint)TestDll2::Data()==0xABCDABCD);
345 TestDll2::SetData(0xDCBADCBA);
346 test((TUint)TestDll2::Data()==0xDCBADCBA);
348 test((TUint)TestDll1::Data()==0x87654321);
349 TestDll1::SetData(0x12345678);
350 test((TUint)TestDll1::Data()==0x12345678);
352 test((TUint)TestDll2::Data()==0xDCBADCBA);
353 TestDll2::SetData(0xABCDABCD);
354 test((TUint)TestDll2::Data()==0xABCDABCD);
356 test(TestDll1::Attach(EFalse)==KErrNone);
357 test(TestDll2::Attach(EFalse)==KErrNone);