First public contribution.
1 // Copyright (c) 1999-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\system\t_kucopy.cpp
15 // Test copying between kernel and user side.
19 #define __E32TEST_EXTENSION__
23 #include "../mmu/mmudetect.h"
27 _LIT(KLddFileName,"D_KUCOPY.LDD");
28 _LIT(KLitKernExec,"KERN-EXEC");
30 RTest test(_L("T_KUCOPY"));
37 TBool KernProt=EFalse;
40 _LIT8(KTest8_2,"Test2");
41 _LIT8(KTest8_3,"extensionality emptyset pairset separation powerset unionset infinity foundation replacement choice");
42 _LIT8(KTest8_4,"And darkness and decay and the red death held illimitable dominion over all.");
44 _LIT16(KTest16_1,"39");
45 _LIT16(KTest16_2,"Test16");
46 _LIT16(KTest16_3,"extensionality emptyset pairset separation powerset unionset infinity foundation replacement choice.");
47 _LIT16(KTest16_4,"And darkness and decay and the red death held illimitable dominion over all.");
49 static const TDesC8* const TestStrings8[]=
57 static const TDesC16* const TestStrings16[]=
65 #define NTESTS8 ((TInt)(sizeof(TestStrings8)/sizeof(const TDesC8*)))
66 #define NTESTS16 ((TInt)(sizeof(TestStrings16)/sizeof(const TDesC16*)))
83 void DoPutGetTest(TInt aSrcOffset, TInt aDestOffset, TInt aLen, TTest aTest)
85 // Use the first BufSize of random data as background, the rest as copy data.
87 // test.Printf(_L("s=%4d d=%4d l=%4d t=%d\n"),aSrcOffset,aDestOffset,aLen,aTest);
91 Mem::Move(Buf1,Random,BufSize);
92 KU.Put(Buf1+aDestOffset,aSrcOffset+BufSize,aLen);
95 KU.Get(Random+BufSize+aSrcOffset,aDestOffset,aLen);
99 Mem::Move(Buf1,Random,BufSize);
100 KU.Put32((TUint32*)(Buf1+aDestOffset),aSrcOffset+BufSize,aLen);
103 KU.Get32((const TUint32*)(Random+BufSize+aSrcOffset),aDestOffset,aLen);
107 User::Panic(_L("PutGetTest"),aTest);
111 // Buf1[0...aDestOffset-1]=Random[0...aDestOffset-1]
112 // Buf1[aDestOffset...aDestOffset+aLen-1]=Random[BufSize+aSrcOffset...BufSize+aSrcOffset+aLen-1]
113 // Buf1[aDestOffset+aLen...BufSize-1]=Random[aDestOffset+aLen...BufSize-1]
114 test(Mem::Compare(Buf1,aDestOffset,Random,aDestOffset)==0);
115 test(Mem::Compare(Buf1+aDestOffset,aLen,Random+BufSize+aSrcOffset,aLen)==0);
116 test(Mem::Compare(Buf1+aDestOffset+aLen,BufSize-aDestOffset-aLen,Random+aDestOffset+aLen,BufSize-aDestOffset-aLen)==0);
119 void DoSetTest(TInt aOffset, TInt aLen, TUint8 aValue)
121 Mem::Move(Buf1,Random,BufSize);
122 KU.Set(Buf1+aOffset,aLen,aValue);
123 test(Mem::Compare(Buf1,aOffset,Random,aOffset)==0);
124 TUint8* p=Buf1+aOffset;
128 test(Mem::Compare(Buf1+aOffset+aLen,BufSize-aOffset-aLen,Random+aOffset+aLen,BufSize-aOffset-aLen)==0);
131 void TestDesGet8(const TDesC8& aSrc)
133 TPtr8 dest(Buf2,0,BufSize);
134 KU.DesGet(dest,aSrc);
141 for (i=0; i<NTESTS8; ++i)
143 const TDesC8* orig=TestStrings8[i];
144 TestDesGet8(*orig); // test EBufC
145 TBuf8<256> buf=*orig;
146 TestDesGet8(buf); // test EBuf
147 TPtrC8 ptrc(orig->Ptr(),orig->Length());
148 TestDesGet8(ptrc); // test EPtrC
149 TPtr8 ptr((TUint8*)orig->Ptr(),orig->Length(),orig->Length());
150 TestDesGet8(ptr); // test EPtr
151 HBufC8* pH=orig->Alloc();
153 TPtr8 bufCptr(pH->Des());
154 TestDesGet8(bufCptr); // test EBufCPtr
159 void TestDesPut8(TDesC8& aDest, const TDesC8* aExtraDest, const TDesC8& aSrc)
161 KU.DesPut((TDes8&)aDest,aSrc);
164 test(*aExtraDest==aSrc); // for testing EBufCPtr
170 for (i=0; i<NTESTS8; ++i)
172 const TDesC8* orig=TestStrings8[i];
174 TestDesPut8(buf,NULL,*orig); // test EBuf
175 Mem::FillZ((TAny*)buf.Ptr(),256);
176 TPtr8 ptr((TUint8*)buf.Ptr(),0,256);
177 TestDesPut8(ptr,NULL,*orig); // test EPtr
178 HBufC8* pH=HBufC8::New(256);
180 TPtr8 bufCptr(pH->Des());
181 TestDesPut8(bufCptr,pH,*orig); // test EBufCPtr
186 void TestDesInfo8(const TDesC8& aDes, TInt aLength, TInt aMaxLength, const TUint8* aPtr)
189 KU.DesInfo(aDes,info);
190 test(aLength==info.iLength);
191 test(aMaxLength==info.iMaxLength);
192 test((TAny*)aPtr==info.iPtr);
198 for (i=0; i<NTESTS8; ++i)
200 const TDesC8* orig=TestStrings8[i];
201 TestDesInfo8(*orig,orig->Length(),-1,orig->Ptr()); // test EBufC
203 TestDesInfo8(buf,0,256,buf.Ptr()); // test EBuf
205 TestDesInfo8(buf,orig->Length(),256,buf.Ptr()); // test EBuf
207 TestDesInfo8(buf2,0,203,buf2.Ptr()); // test EBuf
209 TestDesInfo8(buf2,orig->Length(),203,buf2.Ptr()); // test EBuf
210 TPtrC8 ptrc(orig->Ptr(),orig->Length());
211 TestDesInfo8(ptrc,orig->Length(),-1,orig->Ptr()); // test EPtrC
212 TPtr8 ptr((TUint8*)orig->Ptr(),orig->Length(),orig->Length());
213 TestDesInfo8(ptr,orig->Length(),orig->Length(),orig->Ptr()); // test EPtr
214 HBufC8* pH=orig->Alloc();
216 TPtr8 bufCptr(pH->Des());
217 TestDesInfo8(*pH,orig->Length(),-1,pH->Ptr());
218 TestDesInfo8(bufCptr,orig->Length(),User::AllocLen(pH)-sizeof(TDesC8),pH->Ptr());
223 void RunTestInThread(TThreadFunction aFn, TAny* aParameter, const TDesC* aPanicCat, TInt aExitCode, TInt aLine)
225 test.Printf(_L("Line %d\n"),aLine);
227 TInt r=t.Create(KNullDesC(),aFn,0x2000,NULL,aParameter);
232 User::WaitForRequest(s);
235 test(t.ExitType()==EExitPanic);
236 test(t.ExitCategory()==*aPanicCat);
237 test(t.ExitReason()==aExitCode);
241 test(t.ExitType()==EExitKill);
242 test(t.ExitReason()==aExitCode);
247 TInt DesGet8Thread(TAny* aPtr)
250 KU.DesGet(dest, *(const TDesC8*)aPtr);
254 TInt DesPut8Thread(TAny* aPtr)
256 KU.DesPut(*(TDes8*)aPtr,KTest8_4);
260 TInt DesInfo8Thread(TAny* aPtr)
263 KU.DesInfo(*(TDesC8*)aPtr,info);
269 TBool jit=User::JustInTime();
270 User::SetJustInTime(EFalse);
271 TUint8* Kern=KU.KernelBufferAddress();
274 TPtrC8 uptrc(Buf1,100);
275 TPtrC8 kptrc(Kern,1);
276 TPtr8 kptr(Kern,10,256);
277 RunTestInThread(DesGet8Thread,&x,&KLitKernExec,EKUDesInfoInvalidType,__LINE__);
278 RunTestInThread(DesGet8Thread,&ubuf,NULL,KErrNone,__LINE__);
279 RunTestInThread(DesGet8Thread,&ubuf,NULL,KErrNone,__LINE__);
282 RunTestInThread(DesGet8Thread,Kern,&KLitKernExec,ECausedException,__LINE__);
283 RunTestInThread(DesGet8Thread,&kptrc,&KLitKernExec,ECausedException,__LINE__);
284 RunTestInThread(DesGet8Thread,&kptr,&KLitKernExec,ECausedException,__LINE__);
286 RunTestInThread(DesPut8Thread,&x,&KLitKernExec,EKUDesInfoInvalidType,__LINE__);
287 RunTestInThread(DesPut8Thread,&ubuf,NULL,KErrNone,__LINE__);
288 RunTestInThread(DesPut8Thread,&uptrc,&KLitKernExec,EKUDesSetLengthInvalidType,__LINE__);
291 RunTestInThread(DesPut8Thread,Kern,&KLitKernExec,ECausedException,__LINE__);
292 RunTestInThread(DesPut8Thread,&kptrc,&KLitKernExec,EKUDesSetLengthInvalidType,__LINE__);
293 RunTestInThread(DesPut8Thread,&kptr,&KLitKernExec,ECausedException,__LINE__);
295 RunTestInThread(DesInfo8Thread,&x,&KLitKernExec,EKUDesInfoInvalidType,__LINE__);
296 RunTestInThread(DesInfo8Thread,&ubuf,NULL,KErrNone,__LINE__);
297 RunTestInThread(DesInfo8Thread,&uptrc,NULL,KErrNone,__LINE__);
298 RunTestInThread(DesInfo8Thread,&kptrc,NULL,KErrNone,__LINE__);
299 RunTestInThread(DesInfo8Thread,&kptr,NULL,KErrNone,__LINE__);
302 RunTestInThread(DesInfo8Thread,Kern,&KLitKernExec,ECausedException,__LINE__);
305 User::SetJustInTime(jit);
308 void RequestCompleteBadPointer(TUint aBadAddress)
310 TRequestStatus* badStatus = (TRequestStatus*)aBadAddress;
311 test.Printf(_L("Test Kern::RequestComplete to %08x\n"), aBadAddress);
312 KU.RequestComplete(badStatus);
313 test.Printf(_L("Test Kern::RequestComplete to %08x (in current thread)\n"), aBadAddress);
314 KU.RequestCompleteLocal(badStatus);
316 // Check the thread hasn't been signalled
317 TRequestStatus status;
319 test_KErrNone(timer.CreateLocal());
320 timer.After(status, 100000); // 100ms
321 test_Equal(KRequestPending, status.Int());
322 User::WaitForAnyRequest();
323 test_Equal(KErrNone, status.Int());
326 test.Printf(_L("Test Kern::QueueRequestComplete to %08x\n"), aBadAddress);
327 TInt r = KU.QueueRequestComplete(badStatus);
329 // Kern::QueueRequestComplete will signal even if the pointer is bad, unless:
330 // - the pointer is null
331 // - the call to Setup returned an error
332 if (badStatus != NULL && r == KErrNone)
333 User::WaitForAnyRequest();
336 void TestRequestCompleteTrapped()
338 TRequestStatus status;
339 test.Printf(_L("Test Kern::RequestComplete to %08x\n"), &status);
340 status = KRequestPending;
341 KU.RequestComplete(&status);
342 User::WaitForRequest(status);
343 test_Equal(KErrNone, status.Int());
345 test.Printf(_L("Test Kern::RequestComplete to %08x (in current thread)\n"), &status);
346 status = KRequestPending;
347 KU.RequestCompleteLocal(&status);
348 User::WaitForRequest(status);
349 test_Equal(KErrNone, status.Int());
351 test.Printf(_L("Test Kern::QueueRequestComplete to %08x\n"), &status);
352 status = KRequestPending;
353 KU.QueueRequestComplete(&status);
354 User::WaitForRequest(status);
355 test_Equal(KErrNone, status.Int());
357 RequestCompleteBadPointer(0x00000000);
358 RequestCompleteBadPointer(0x00000001);
359 RequestCompleteBadPointer(0x00000004);
360 RequestCompleteBadPointer(0x00000008);
363 RequestCompleteBadPointer(0x80000000);
364 RequestCompleteBadPointer(0xfffffff0);
365 RequestCompleteBadPointer((TUint)KU.KernelBufferAddress());
369 GLDEF_C TInt E32Main()
372 test.Start(_L("Load LDD"));
373 TInt r=User::LoadLogicalDevice(KLddFileName);
374 test(r==KErrNone || r==KErrAlreadyExists);
375 test.Next(_L("Open channel"));
378 test.Next(_L("Create chunk"));
380 r=c.CreateDisconnectedLocal(0,0,0x100000);
383 RandSize=KU.RandomLength();
384 test.Printf(_L("BufSize=%x, RandSize=%x\n"),BufSize,RandSize);
385 r=c.Commit(0,BufSize);
387 r=c.Commit(0x10000,BufSize);
389 r=c.Commit(0x20000,RandSize);
392 Buf2=c.Base()+0x10000;
393 Random=c.Base()+0x20000;
394 test.Printf(_L("Buf1 at %08x, Buf2 at %08x, Random at %08x\n"),Buf1,Buf2,Random);
395 Mem::Fill(Buf1,BufSize,0xb1);
396 Mem::Fill(Buf2,BufSize,0xb2);
397 Mem::Fill(Random,RandSize,0x8b);
398 KU.ReadRandom(Random);
400 KernProt=HaveDirectKernProt();
406 test.Next(_L("Put/Get 1"));
407 for (l=1; l<300; l+=3)
409 test.Printf(_L("PG1: l=%d\n"),l);
410 for (s=0; s<=BufSize-l; s+=227)
412 for (d=0; d<=BufSize-l; d+=229)
414 DoPutGetTest(s,d,l,EPut);
415 DoPutGetTest(s,d,l,EGet);
420 test.Next(_L("Put/Get 2"));
421 for (l=1; l<300; l+=3)
423 test.Printf(_L("PG2: l=%d\n"),l);
424 for (s=BufSize-l; s>=0; s-=227)
426 for (d=BufSize-l; d>=0; d-=229)
428 DoPutGetTest(s,d,l,EPut);
429 DoPutGetTest(s,d,l,EGet);
434 test.Next(_L("Put32/Get32 1"));
435 for (l=4; l<300; l+=12)
437 test.Printf(_L("PG32,1: l=%d\n"),l);
438 for (s=0; s<=BufSize-l; s+=4*59)
440 for (d=0; d<=BufSize-l; d+=4*61)
442 DoPutGetTest(s,d,l,EPut32);
443 DoPutGetTest(s,d,l,EGet32);
448 test.Next(_L("Put32/Get32 2"));
449 for (l=4; l<300; l+=12)
451 test.Printf(_L("PG32,2: l=%d\n"),l);
452 for (s=BufSize-l; s>=0; s-=4*59)
454 for (d=BufSize-l; d>=0; d-=4*61)
456 DoPutGetTest(s,d,l,EPut32);
457 DoPutGetTest(s,d,l,EGet32);
461 test.Next(_L("Set"));
462 for (l=1; l<300; l+=3)
464 test.Printf(_L("Set: l=%d\n"),l);
465 for (s=0; s<=BufSize-l; s+=83)
470 for (s=BufSize-l; s>=0; s-=79)
477 test.Next(_L("DesGet8"));
479 test.Next(_L("DesPut8"));
481 test.Next(_L("DesInfo8"));
483 test.Next(_L("Errors"));
485 test.Next(_L("Test Kern::RequestComplete functions trapped"));
486 TestRequestCompleteTrapped();