sl@0: // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\system\t_kucopy.cpp sl@0: // Test copying between kernel and user side. sl@0: // sl@0: // sl@0: sl@0: #define __E32TEST_EXTENSION__ sl@0: sl@0: #include sl@0: #include "d_kucopy.h" sl@0: #include "../mmu/mmudetect.h" sl@0: sl@0: //#define QUICK sl@0: sl@0: _LIT(KLddFileName,"D_KUCOPY.LDD"); sl@0: _LIT(KLitKernExec,"KERN-EXEC"); sl@0: sl@0: RTest test(_L("T_KUCOPY")); sl@0: RKUCopy KU; sl@0: TInt BufSize; sl@0: TInt RandSize; sl@0: TUint8* Buf1; sl@0: TUint8* Buf2; sl@0: TUint8* Random; sl@0: TBool KernProt=EFalse; sl@0: sl@0: _LIT8(KTest8_1,"1"); sl@0: _LIT8(KTest8_2,"Test2"); sl@0: _LIT8(KTest8_3,"extensionality emptyset pairset separation powerset unionset infinity foundation replacement choice"); sl@0: _LIT8(KTest8_4,"And darkness and decay and the red death held illimitable dominion over all."); sl@0: sl@0: _LIT16(KTest16_1,"39"); sl@0: _LIT16(KTest16_2,"Test16"); sl@0: _LIT16(KTest16_3,"extensionality emptyset pairset separation powerset unionset infinity foundation replacement choice."); sl@0: _LIT16(KTest16_4,"And darkness and decay and the red death held illimitable dominion over all."); sl@0: sl@0: static const TDesC8* const TestStrings8[]= sl@0: { sl@0: &KTest8_1, sl@0: &KTest8_2, sl@0: &KTest8_3, sl@0: &KTest8_4, sl@0: }; sl@0: sl@0: static const TDesC16* const TestStrings16[]= sl@0: { sl@0: &KTest16_1, sl@0: &KTest16_2, sl@0: &KTest16_3, sl@0: &KTest16_4, sl@0: }; sl@0: sl@0: #define NTESTS8 ((TInt)(sizeof(TestStrings8)/sizeof(const TDesC8*))) sl@0: #define NTESTS16 ((TInt)(sizeof(TestStrings16)/sizeof(const TDesC16*))) sl@0: sl@0: enum TTest sl@0: { sl@0: EPut, sl@0: EGet, sl@0: EPut32, sl@0: EGet32, sl@0: ESet, sl@0: EDesPut8, sl@0: EDesGet8, sl@0: EDesInfo8, sl@0: EDesPut16, sl@0: EDesGet16, sl@0: EDesInfo16, sl@0: }; sl@0: sl@0: void DoPutGetTest(TInt aSrcOffset, TInt aDestOffset, TInt aLen, TTest aTest) sl@0: { sl@0: // Use the first BufSize of random data as background, the rest as copy data. sl@0: // Use Buf1 as target sl@0: // test.Printf(_L("s=%4d d=%4d l=%4d t=%d\n"),aSrcOffset,aDestOffset,aLen,aTest); sl@0: switch (aTest) sl@0: { sl@0: case EPut: sl@0: Mem::Move(Buf1,Random,BufSize); sl@0: KU.Put(Buf1+aDestOffset,aSrcOffset+BufSize,aLen); sl@0: break; sl@0: case EGet: sl@0: KU.Get(Random+BufSize+aSrcOffset,aDestOffset,aLen); sl@0: KU.Read(Buf1); sl@0: break; sl@0: case EPut32: sl@0: Mem::Move(Buf1,Random,BufSize); sl@0: KU.Put32((TUint32*)(Buf1+aDestOffset),aSrcOffset+BufSize,aLen); sl@0: break; sl@0: case EGet32: sl@0: KU.Get32((const TUint32*)(Random+BufSize+aSrcOffset),aDestOffset,aLen); sl@0: KU.Read(Buf1); sl@0: break; sl@0: default: sl@0: User::Panic(_L("PutGetTest"),aTest); sl@0: } sl@0: sl@0: // Should now have: sl@0: // Buf1[0...aDestOffset-1]=Random[0...aDestOffset-1] sl@0: // Buf1[aDestOffset...aDestOffset+aLen-1]=Random[BufSize+aSrcOffset...BufSize+aSrcOffset+aLen-1] sl@0: // Buf1[aDestOffset+aLen...BufSize-1]=Random[aDestOffset+aLen...BufSize-1] sl@0: test(Mem::Compare(Buf1,aDestOffset,Random,aDestOffset)==0); sl@0: test(Mem::Compare(Buf1+aDestOffset,aLen,Random+BufSize+aSrcOffset,aLen)==0); sl@0: test(Mem::Compare(Buf1+aDestOffset+aLen,BufSize-aDestOffset-aLen,Random+aDestOffset+aLen,BufSize-aDestOffset-aLen)==0); sl@0: } sl@0: sl@0: void DoSetTest(TInt aOffset, TInt aLen, TUint8 aValue) sl@0: { sl@0: Mem::Move(Buf1,Random,BufSize); sl@0: KU.Set(Buf1+aOffset,aLen,aValue); sl@0: test(Mem::Compare(Buf1,aOffset,Random,aOffset)==0); sl@0: TUint8* p=Buf1+aOffset; sl@0: TUint8* pE=p+aLen; sl@0: while (p buf=*orig; sl@0: TestDesGet8(buf); // test EBuf sl@0: TPtrC8 ptrc(orig->Ptr(),orig->Length()); sl@0: TestDesGet8(ptrc); // test EPtrC sl@0: TPtr8 ptr((TUint8*)orig->Ptr(),orig->Length(),orig->Length()); sl@0: TestDesGet8(ptr); // test EPtr sl@0: HBufC8* pH=orig->Alloc(); sl@0: test(pH!=NULL); sl@0: TPtr8 bufCptr(pH->Des()); sl@0: TestDesGet8(bufCptr); // test EBufCPtr sl@0: User::Free(pH); sl@0: } sl@0: } sl@0: sl@0: void TestDesPut8(TDesC8& aDest, const TDesC8* aExtraDest, const TDesC8& aSrc) sl@0: { sl@0: KU.DesPut((TDes8&)aDest,aSrc); sl@0: test(aDest==aSrc); sl@0: if (aExtraDest) sl@0: test(*aExtraDest==aSrc); // for testing EBufCPtr sl@0: } sl@0: sl@0: void TestDesPut8() sl@0: { sl@0: TInt i; sl@0: for (i=0; i buf; sl@0: TestDesPut8(buf,NULL,*orig); // test EBuf sl@0: Mem::FillZ((TAny*)buf.Ptr(),256); sl@0: TPtr8 ptr((TUint8*)buf.Ptr(),0,256); sl@0: TestDesPut8(ptr,NULL,*orig); // test EPtr sl@0: HBufC8* pH=HBufC8::New(256); sl@0: test(pH!=NULL); sl@0: TPtr8 bufCptr(pH->Des()); sl@0: TestDesPut8(bufCptr,pH,*orig); // test EBufCPtr sl@0: User::Free(pH); sl@0: } sl@0: } sl@0: sl@0: void TestDesInfo8(const TDesC8& aDes, TInt aLength, TInt aMaxLength, const TUint8* aPtr) sl@0: { sl@0: SDesInfo info; sl@0: KU.DesInfo(aDes,info); sl@0: test(aLength==info.iLength); sl@0: test(aMaxLength==info.iMaxLength); sl@0: test((TAny*)aPtr==info.iPtr); sl@0: } sl@0: sl@0: void TestDesInfo8() sl@0: { sl@0: TInt i; sl@0: for (i=0; iLength(),-1,orig->Ptr()); // test EBufC sl@0: TBuf8<256> buf; sl@0: TestDesInfo8(buf,0,256,buf.Ptr()); // test EBuf sl@0: buf=*orig; sl@0: TestDesInfo8(buf,orig->Length(),256,buf.Ptr()); // test EBuf sl@0: TBuf8<203> buf2; sl@0: TestDesInfo8(buf2,0,203,buf2.Ptr()); // test EBuf sl@0: buf2=*orig; sl@0: TestDesInfo8(buf2,orig->Length(),203,buf2.Ptr()); // test EBuf sl@0: TPtrC8 ptrc(orig->Ptr(),orig->Length()); sl@0: TestDesInfo8(ptrc,orig->Length(),-1,orig->Ptr()); // test EPtrC sl@0: TPtr8 ptr((TUint8*)orig->Ptr(),orig->Length(),orig->Length()); sl@0: TestDesInfo8(ptr,orig->Length(),orig->Length(),orig->Ptr()); // test EPtr sl@0: HBufC8* pH=orig->Alloc(); sl@0: test(pH!=NULL); sl@0: TPtr8 bufCptr(pH->Des()); sl@0: TestDesInfo8(*pH,orig->Length(),-1,pH->Ptr()); sl@0: TestDesInfo8(bufCptr,orig->Length(),User::AllocLen(pH)-sizeof(TDesC8),pH->Ptr()); sl@0: User::Free(pH); sl@0: } sl@0: } sl@0: sl@0: void RunTestInThread(TThreadFunction aFn, TAny* aParameter, const TDesC* aPanicCat, TInt aExitCode, TInt aLine) sl@0: { sl@0: test.Printf(_L("Line %d\n"),aLine); sl@0: RThread t; sl@0: TInt r=t.Create(KNullDesC(),aFn,0x2000,NULL,aParameter); sl@0: test(r==KErrNone); sl@0: TRequestStatus s; sl@0: t.Logon(s); sl@0: t.Resume(); sl@0: User::WaitForRequest(s); sl@0: if (aPanicCat) sl@0: { sl@0: test(t.ExitType()==EExitPanic); sl@0: test(t.ExitCategory()==*aPanicCat); sl@0: test(t.ExitReason()==aExitCode); sl@0: } sl@0: else sl@0: { sl@0: test(t.ExitType()==EExitKill); sl@0: test(t.ExitReason()==aExitCode); sl@0: } sl@0: CLOSE_AND_WAIT(t); sl@0: } sl@0: sl@0: TInt DesGet8Thread(TAny* aPtr) sl@0: { sl@0: TBuf8<256> dest; sl@0: KU.DesGet(dest, *(const TDesC8*)aPtr); sl@0: return 0; sl@0: } sl@0: sl@0: TInt DesPut8Thread(TAny* aPtr) sl@0: { sl@0: KU.DesPut(*(TDes8*)aPtr,KTest8_4); sl@0: return 0; sl@0: } sl@0: sl@0: TInt DesInfo8Thread(TAny* aPtr) sl@0: { sl@0: SDesInfo info; sl@0: KU.DesInfo(*(TDesC8*)aPtr,info); sl@0: return 0; sl@0: } sl@0: sl@0: void TestErrors() sl@0: { sl@0: TBool jit=User::JustInTime(); sl@0: User::SetJustInTime(EFalse); sl@0: TUint8* Kern=KU.KernelBufferAddress(); sl@0: TUint x=0xffffffff; sl@0: TBuf8<256> ubuf; sl@0: TPtrC8 uptrc(Buf1,100); sl@0: TPtrC8 kptrc(Kern,1); sl@0: TPtr8 kptr(Kern,10,256); sl@0: RunTestInThread(DesGet8Thread,&x,&KLitKernExec,EKUDesInfoInvalidType,__LINE__); sl@0: RunTestInThread(DesGet8Thread,&ubuf,NULL,KErrNone,__LINE__); sl@0: RunTestInThread(DesGet8Thread,&ubuf,NULL,KErrNone,__LINE__); sl@0: if (KernProt) sl@0: { sl@0: RunTestInThread(DesGet8Thread,Kern,&KLitKernExec,ECausedException,__LINE__); sl@0: RunTestInThread(DesGet8Thread,&kptrc,&KLitKernExec,ECausedException,__LINE__); sl@0: RunTestInThread(DesGet8Thread,&kptr,&KLitKernExec,ECausedException,__LINE__); sl@0: } sl@0: RunTestInThread(DesPut8Thread,&x,&KLitKernExec,EKUDesInfoInvalidType,__LINE__); sl@0: RunTestInThread(DesPut8Thread,&ubuf,NULL,KErrNone,__LINE__); sl@0: RunTestInThread(DesPut8Thread,&uptrc,&KLitKernExec,EKUDesSetLengthInvalidType,__LINE__); sl@0: if (KernProt) sl@0: { sl@0: RunTestInThread(DesPut8Thread,Kern,&KLitKernExec,ECausedException,__LINE__); sl@0: RunTestInThread(DesPut8Thread,&kptrc,&KLitKernExec,EKUDesSetLengthInvalidType,__LINE__); sl@0: RunTestInThread(DesPut8Thread,&kptr,&KLitKernExec,ECausedException,__LINE__); sl@0: } sl@0: RunTestInThread(DesInfo8Thread,&x,&KLitKernExec,EKUDesInfoInvalidType,__LINE__); sl@0: RunTestInThread(DesInfo8Thread,&ubuf,NULL,KErrNone,__LINE__); sl@0: RunTestInThread(DesInfo8Thread,&uptrc,NULL,KErrNone,__LINE__); sl@0: RunTestInThread(DesInfo8Thread,&kptrc,NULL,KErrNone,__LINE__); sl@0: RunTestInThread(DesInfo8Thread,&kptr,NULL,KErrNone,__LINE__); sl@0: if (KernProt) sl@0: { sl@0: RunTestInThread(DesInfo8Thread,Kern,&KLitKernExec,ECausedException,__LINE__); sl@0: } sl@0: sl@0: User::SetJustInTime(jit); sl@0: } sl@0: sl@0: void RequestCompleteBadPointer(TUint aBadAddress) sl@0: { sl@0: TRequestStatus* badStatus = (TRequestStatus*)aBadAddress; sl@0: test.Printf(_L("Test Kern::RequestComplete to %08x\n"), aBadAddress); sl@0: KU.RequestComplete(badStatus); sl@0: test.Printf(_L("Test Kern::RequestComplete to %08x (in current thread)\n"), aBadAddress); sl@0: KU.RequestCompleteLocal(badStatus); sl@0: sl@0: // Check the thread hasn't been signalled sl@0: TRequestStatus status; sl@0: RTimer timer; sl@0: test_KErrNone(timer.CreateLocal()); sl@0: timer.After(status, 100000); // 100ms sl@0: test_Equal(KRequestPending, status.Int()); sl@0: User::WaitForAnyRequest(); sl@0: test_Equal(KErrNone, status.Int()); sl@0: timer.Close(); sl@0: sl@0: test.Printf(_L("Test Kern::QueueRequestComplete to %08x\n"), aBadAddress); sl@0: TInt r = KU.QueueRequestComplete(badStatus); sl@0: sl@0: // Kern::QueueRequestComplete will signal even if the pointer is bad, unless: sl@0: // - the pointer is null sl@0: // - the call to Setup returned an error sl@0: if (badStatus != NULL && r == KErrNone) sl@0: User::WaitForAnyRequest(); sl@0: } sl@0: sl@0: void TestRequestCompleteTrapped() sl@0: { sl@0: TRequestStatus status; sl@0: test.Printf(_L("Test Kern::RequestComplete to %08x\n"), &status); sl@0: status = KRequestPending; sl@0: KU.RequestComplete(&status); sl@0: User::WaitForRequest(status); sl@0: test_Equal(KErrNone, status.Int()); sl@0: sl@0: test.Printf(_L("Test Kern::RequestComplete to %08x (in current thread)\n"), &status); sl@0: status = KRequestPending; sl@0: KU.RequestCompleteLocal(&status); sl@0: User::WaitForRequest(status); sl@0: test_Equal(KErrNone, status.Int()); sl@0: sl@0: test.Printf(_L("Test Kern::QueueRequestComplete to %08x\n"), &status); sl@0: status = KRequestPending; sl@0: KU.QueueRequestComplete(&status); sl@0: User::WaitForRequest(status); sl@0: test_Equal(KErrNone, status.Int()); sl@0: sl@0: RequestCompleteBadPointer(0x00000000); sl@0: RequestCompleteBadPointer(0x00000001); sl@0: RequestCompleteBadPointer(0x00000004); sl@0: RequestCompleteBadPointer(0x00000008); sl@0: if (KernProt) sl@0: { sl@0: RequestCompleteBadPointer(0x80000000); sl@0: RequestCompleteBadPointer(0xfffffff0); sl@0: RequestCompleteBadPointer((TUint)KU.KernelBufferAddress()); sl@0: } sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: test.Title(); sl@0: test.Start(_L("Load LDD")); sl@0: TInt r=User::LoadLogicalDevice(KLddFileName); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: test.Next(_L("Open channel")); sl@0: r=KU.Open(); sl@0: test(r==KErrNone); sl@0: test.Next(_L("Create chunk")); sl@0: RChunk c; sl@0: r=c.CreateDisconnectedLocal(0,0,0x100000); sl@0: test(r==KErrNone); sl@0: BufSize=KU.Length(); sl@0: RandSize=KU.RandomLength(); sl@0: test.Printf(_L("BufSize=%x, RandSize=%x\n"),BufSize,RandSize); sl@0: r=c.Commit(0,BufSize); sl@0: test(r==KErrNone); sl@0: r=c.Commit(0x10000,BufSize); sl@0: test(r==KErrNone); sl@0: r=c.Commit(0x20000,RandSize); sl@0: test(r==KErrNone); sl@0: Buf1=c.Base(); sl@0: Buf2=c.Base()+0x10000; sl@0: Random=c.Base()+0x20000; sl@0: test.Printf(_L("Buf1 at %08x, Buf2 at %08x, Random at %08x\n"),Buf1,Buf2,Random); sl@0: Mem::Fill(Buf1,BufSize,0xb1); sl@0: Mem::Fill(Buf2,BufSize,0xb2); sl@0: Mem::Fill(Random,RandSize,0x8b); sl@0: KU.ReadRandom(Random); sl@0: sl@0: KernProt=HaveDirectKernProt(); sl@0: sl@0: #ifndef QUICK sl@0: TInt s; sl@0: TInt d; sl@0: TInt l; sl@0: test.Next(_L("Put/Get 1")); sl@0: for (l=1; l<300; l+=3) sl@0: { sl@0: test.Printf(_L("PG1: l=%d\n"),l); sl@0: for (s=0; s<=BufSize-l; s+=227) sl@0: { sl@0: for (d=0; d<=BufSize-l; d+=229) sl@0: { sl@0: DoPutGetTest(s,d,l,EPut); sl@0: DoPutGetTest(s,d,l,EGet); sl@0: } sl@0: } sl@0: } sl@0: sl@0: test.Next(_L("Put/Get 2")); sl@0: for (l=1; l<300; l+=3) sl@0: { sl@0: test.Printf(_L("PG2: l=%d\n"),l); sl@0: for (s=BufSize-l; s>=0; s-=227) sl@0: { sl@0: for (d=BufSize-l; d>=0; d-=229) sl@0: { sl@0: DoPutGetTest(s,d,l,EPut); sl@0: DoPutGetTest(s,d,l,EGet); sl@0: } sl@0: } sl@0: } sl@0: sl@0: test.Next(_L("Put32/Get32 1")); sl@0: for (l=4; l<300; l+=12) sl@0: { sl@0: test.Printf(_L("PG32,1: l=%d\n"),l); sl@0: for (s=0; s<=BufSize-l; s+=4*59) sl@0: { sl@0: for (d=0; d<=BufSize-l; d+=4*61) sl@0: { sl@0: DoPutGetTest(s,d,l,EPut32); sl@0: DoPutGetTest(s,d,l,EGet32); sl@0: } sl@0: } sl@0: } sl@0: sl@0: test.Next(_L("Put32/Get32 2")); sl@0: for (l=4; l<300; l+=12) sl@0: { sl@0: test.Printf(_L("PG32,2: l=%d\n"),l); sl@0: for (s=BufSize-l; s>=0; s-=4*59) sl@0: { sl@0: for (d=BufSize-l; d>=0; d-=4*61) sl@0: { sl@0: DoPutGetTest(s,d,l,EPut32); sl@0: DoPutGetTest(s,d,l,EGet32); sl@0: } sl@0: } sl@0: } sl@0: test.Next(_L("Set")); sl@0: for (l=1; l<300; l+=3) sl@0: { sl@0: test.Printf(_L("Set: l=%d\n"),l); sl@0: for (s=0; s<=BufSize-l; s+=83) sl@0: { sl@0: DoSetTest(s,l,0x1b); sl@0: DoSetTest(s,l,0xaa); sl@0: } sl@0: for (s=BufSize-l; s>=0; s-=79) sl@0: { sl@0: DoSetTest(s,l,0x1b); sl@0: DoSetTest(s,l,0xaa); sl@0: } sl@0: } sl@0: #endif sl@0: test.Next(_L("DesGet8")); sl@0: TestDesGet8(); sl@0: test.Next(_L("DesPut8")); sl@0: TestDesPut8(); sl@0: test.Next(_L("DesInfo8")); sl@0: TestDesInfo8(); sl@0: test.Next(_L("Errors")); sl@0: TestErrors(); sl@0: test.Next(_L("Test Kern::RequestComplete functions trapped")); sl@0: TestRequestCompleteTrapped(); sl@0: sl@0: c.Close(); sl@0: KU.Close(); sl@0: test.End(); sl@0: return 0; sl@0: } sl@0: sl@0: sl@0: sl@0: