1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/system/t_kucopy.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,496 @@
1.4 +// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\system\t_kucopy.cpp
1.18 +// Test copying between kernel and user side.
1.19 +//
1.20 +//
1.21 +
1.22 +#define __E32TEST_EXTENSION__
1.23 +
1.24 +#include <e32test.h>
1.25 +#include "d_kucopy.h"
1.26 +#include "../mmu/mmudetect.h"
1.27 +
1.28 +//#define QUICK
1.29 +
1.30 +_LIT(KLddFileName,"D_KUCOPY.LDD");
1.31 +_LIT(KLitKernExec,"KERN-EXEC");
1.32 +
1.33 +RTest test(_L("T_KUCOPY"));
1.34 +RKUCopy KU;
1.35 +TInt BufSize;
1.36 +TInt RandSize;
1.37 +TUint8* Buf1;
1.38 +TUint8* Buf2;
1.39 +TUint8* Random;
1.40 +TBool KernProt=EFalse;
1.41 +
1.42 +_LIT8(KTest8_1,"1");
1.43 +_LIT8(KTest8_2,"Test2");
1.44 +_LIT8(KTest8_3,"extensionality emptyset pairset separation powerset unionset infinity foundation replacement choice");
1.45 +_LIT8(KTest8_4,"And darkness and decay and the red death held illimitable dominion over all.");
1.46 +
1.47 +_LIT16(KTest16_1,"39");
1.48 +_LIT16(KTest16_2,"Test16");
1.49 +_LIT16(KTest16_3,"extensionality emptyset pairset separation powerset unionset infinity foundation replacement choice.");
1.50 +_LIT16(KTest16_4,"And darkness and decay and the red death held illimitable dominion over all.");
1.51 +
1.52 +static const TDesC8* const TestStrings8[]=
1.53 + {
1.54 + &KTest8_1,
1.55 + &KTest8_2,
1.56 + &KTest8_3,
1.57 + &KTest8_4,
1.58 + };
1.59 +
1.60 +static const TDesC16* const TestStrings16[]=
1.61 + {
1.62 + &KTest16_1,
1.63 + &KTest16_2,
1.64 + &KTest16_3,
1.65 + &KTest16_4,
1.66 + };
1.67 +
1.68 +#define NTESTS8 ((TInt)(sizeof(TestStrings8)/sizeof(const TDesC8*)))
1.69 +#define NTESTS16 ((TInt)(sizeof(TestStrings16)/sizeof(const TDesC16*)))
1.70 +
1.71 +enum TTest
1.72 + {
1.73 + EPut,
1.74 + EGet,
1.75 + EPut32,
1.76 + EGet32,
1.77 + ESet,
1.78 + EDesPut8,
1.79 + EDesGet8,
1.80 + EDesInfo8,
1.81 + EDesPut16,
1.82 + EDesGet16,
1.83 + EDesInfo16,
1.84 + };
1.85 +
1.86 +void DoPutGetTest(TInt aSrcOffset, TInt aDestOffset, TInt aLen, TTest aTest)
1.87 + {
1.88 + // Use the first BufSize of random data as background, the rest as copy data.
1.89 + // Use Buf1 as target
1.90 +// test.Printf(_L("s=%4d d=%4d l=%4d t=%d\n"),aSrcOffset,aDestOffset,aLen,aTest);
1.91 + switch (aTest)
1.92 + {
1.93 + case EPut:
1.94 + Mem::Move(Buf1,Random,BufSize);
1.95 + KU.Put(Buf1+aDestOffset,aSrcOffset+BufSize,aLen);
1.96 + break;
1.97 + case EGet:
1.98 + KU.Get(Random+BufSize+aSrcOffset,aDestOffset,aLen);
1.99 + KU.Read(Buf1);
1.100 + break;
1.101 + case EPut32:
1.102 + Mem::Move(Buf1,Random,BufSize);
1.103 + KU.Put32((TUint32*)(Buf1+aDestOffset),aSrcOffset+BufSize,aLen);
1.104 + break;
1.105 + case EGet32:
1.106 + KU.Get32((const TUint32*)(Random+BufSize+aSrcOffset),aDestOffset,aLen);
1.107 + KU.Read(Buf1);
1.108 + break;
1.109 + default:
1.110 + User::Panic(_L("PutGetTest"),aTest);
1.111 + }
1.112 +
1.113 + // Should now have:
1.114 + // Buf1[0...aDestOffset-1]=Random[0...aDestOffset-1]
1.115 + // Buf1[aDestOffset...aDestOffset+aLen-1]=Random[BufSize+aSrcOffset...BufSize+aSrcOffset+aLen-1]
1.116 + // Buf1[aDestOffset+aLen...BufSize-1]=Random[aDestOffset+aLen...BufSize-1]
1.117 + test(Mem::Compare(Buf1,aDestOffset,Random,aDestOffset)==0);
1.118 + test(Mem::Compare(Buf1+aDestOffset,aLen,Random+BufSize+aSrcOffset,aLen)==0);
1.119 + test(Mem::Compare(Buf1+aDestOffset+aLen,BufSize-aDestOffset-aLen,Random+aDestOffset+aLen,BufSize-aDestOffset-aLen)==0);
1.120 + }
1.121 +
1.122 +void DoSetTest(TInt aOffset, TInt aLen, TUint8 aValue)
1.123 + {
1.124 + Mem::Move(Buf1,Random,BufSize);
1.125 + KU.Set(Buf1+aOffset,aLen,aValue);
1.126 + test(Mem::Compare(Buf1,aOffset,Random,aOffset)==0);
1.127 + TUint8* p=Buf1+aOffset;
1.128 + TUint8* pE=p+aLen;
1.129 + while (p<pE)
1.130 + test(*p++==aValue);
1.131 + test(Mem::Compare(Buf1+aOffset+aLen,BufSize-aOffset-aLen,Random+aOffset+aLen,BufSize-aOffset-aLen)==0);
1.132 + }
1.133 +
1.134 +void TestDesGet8(const TDesC8& aSrc)
1.135 + {
1.136 + TPtr8 dest(Buf2,0,BufSize);
1.137 + KU.DesGet(dest,aSrc);
1.138 + test(dest==aSrc);
1.139 + }
1.140 +
1.141 +void TestDesGet8()
1.142 + {
1.143 + TInt i;
1.144 + for (i=0; i<NTESTS8; ++i)
1.145 + {
1.146 + const TDesC8* orig=TestStrings8[i];
1.147 + TestDesGet8(*orig); // test EBufC
1.148 + TBuf8<256> buf=*orig;
1.149 + TestDesGet8(buf); // test EBuf
1.150 + TPtrC8 ptrc(orig->Ptr(),orig->Length());
1.151 + TestDesGet8(ptrc); // test EPtrC
1.152 + TPtr8 ptr((TUint8*)orig->Ptr(),orig->Length(),orig->Length());
1.153 + TestDesGet8(ptr); // test EPtr
1.154 + HBufC8* pH=orig->Alloc();
1.155 + test(pH!=NULL);
1.156 + TPtr8 bufCptr(pH->Des());
1.157 + TestDesGet8(bufCptr); // test EBufCPtr
1.158 + User::Free(pH);
1.159 + }
1.160 + }
1.161 +
1.162 +void TestDesPut8(TDesC8& aDest, const TDesC8* aExtraDest, const TDesC8& aSrc)
1.163 + {
1.164 + KU.DesPut((TDes8&)aDest,aSrc);
1.165 + test(aDest==aSrc);
1.166 + if (aExtraDest)
1.167 + test(*aExtraDest==aSrc); // for testing EBufCPtr
1.168 + }
1.169 +
1.170 +void TestDesPut8()
1.171 + {
1.172 + TInt i;
1.173 + for (i=0; i<NTESTS8; ++i)
1.174 + {
1.175 + const TDesC8* orig=TestStrings8[i];
1.176 + TBuf8<256> buf;
1.177 + TestDesPut8(buf,NULL,*orig); // test EBuf
1.178 + Mem::FillZ((TAny*)buf.Ptr(),256);
1.179 + TPtr8 ptr((TUint8*)buf.Ptr(),0,256);
1.180 + TestDesPut8(ptr,NULL,*orig); // test EPtr
1.181 + HBufC8* pH=HBufC8::New(256);
1.182 + test(pH!=NULL);
1.183 + TPtr8 bufCptr(pH->Des());
1.184 + TestDesPut8(bufCptr,pH,*orig); // test EBufCPtr
1.185 + User::Free(pH);
1.186 + }
1.187 + }
1.188 +
1.189 +void TestDesInfo8(const TDesC8& aDes, TInt aLength, TInt aMaxLength, const TUint8* aPtr)
1.190 + {
1.191 + SDesInfo info;
1.192 + KU.DesInfo(aDes,info);
1.193 + test(aLength==info.iLength);
1.194 + test(aMaxLength==info.iMaxLength);
1.195 + test((TAny*)aPtr==info.iPtr);
1.196 + }
1.197 +
1.198 +void TestDesInfo8()
1.199 + {
1.200 + TInt i;
1.201 + for (i=0; i<NTESTS8; ++i)
1.202 + {
1.203 + const TDesC8* orig=TestStrings8[i];
1.204 + TestDesInfo8(*orig,orig->Length(),-1,orig->Ptr()); // test EBufC
1.205 + TBuf8<256> buf;
1.206 + TestDesInfo8(buf,0,256,buf.Ptr()); // test EBuf
1.207 + buf=*orig;
1.208 + TestDesInfo8(buf,orig->Length(),256,buf.Ptr()); // test EBuf
1.209 + TBuf8<203> buf2;
1.210 + TestDesInfo8(buf2,0,203,buf2.Ptr()); // test EBuf
1.211 + buf2=*orig;
1.212 + TestDesInfo8(buf2,orig->Length(),203,buf2.Ptr()); // test EBuf
1.213 + TPtrC8 ptrc(orig->Ptr(),orig->Length());
1.214 + TestDesInfo8(ptrc,orig->Length(),-1,orig->Ptr()); // test EPtrC
1.215 + TPtr8 ptr((TUint8*)orig->Ptr(),orig->Length(),orig->Length());
1.216 + TestDesInfo8(ptr,orig->Length(),orig->Length(),orig->Ptr()); // test EPtr
1.217 + HBufC8* pH=orig->Alloc();
1.218 + test(pH!=NULL);
1.219 + TPtr8 bufCptr(pH->Des());
1.220 + TestDesInfo8(*pH,orig->Length(),-1,pH->Ptr());
1.221 + TestDesInfo8(bufCptr,orig->Length(),User::AllocLen(pH)-sizeof(TDesC8),pH->Ptr());
1.222 + User::Free(pH);
1.223 + }
1.224 + }
1.225 +
1.226 +void RunTestInThread(TThreadFunction aFn, TAny* aParameter, const TDesC* aPanicCat, TInt aExitCode, TInt aLine)
1.227 + {
1.228 + test.Printf(_L("Line %d\n"),aLine);
1.229 + RThread t;
1.230 + TInt r=t.Create(KNullDesC(),aFn,0x2000,NULL,aParameter);
1.231 + test(r==KErrNone);
1.232 + TRequestStatus s;
1.233 + t.Logon(s);
1.234 + t.Resume();
1.235 + User::WaitForRequest(s);
1.236 + if (aPanicCat)
1.237 + {
1.238 + test(t.ExitType()==EExitPanic);
1.239 + test(t.ExitCategory()==*aPanicCat);
1.240 + test(t.ExitReason()==aExitCode);
1.241 + }
1.242 + else
1.243 + {
1.244 + test(t.ExitType()==EExitKill);
1.245 + test(t.ExitReason()==aExitCode);
1.246 + }
1.247 + CLOSE_AND_WAIT(t);
1.248 + }
1.249 +
1.250 +TInt DesGet8Thread(TAny* aPtr)
1.251 + {
1.252 + TBuf8<256> dest;
1.253 + KU.DesGet(dest, *(const TDesC8*)aPtr);
1.254 + return 0;
1.255 + }
1.256 +
1.257 +TInt DesPut8Thread(TAny* aPtr)
1.258 + {
1.259 + KU.DesPut(*(TDes8*)aPtr,KTest8_4);
1.260 + return 0;
1.261 + }
1.262 +
1.263 +TInt DesInfo8Thread(TAny* aPtr)
1.264 + {
1.265 + SDesInfo info;
1.266 + KU.DesInfo(*(TDesC8*)aPtr,info);
1.267 + return 0;
1.268 + }
1.269 +
1.270 +void TestErrors()
1.271 + {
1.272 + TBool jit=User::JustInTime();
1.273 + User::SetJustInTime(EFalse);
1.274 + TUint8* Kern=KU.KernelBufferAddress();
1.275 + TUint x=0xffffffff;
1.276 + TBuf8<256> ubuf;
1.277 + TPtrC8 uptrc(Buf1,100);
1.278 + TPtrC8 kptrc(Kern,1);
1.279 + TPtr8 kptr(Kern,10,256);
1.280 + RunTestInThread(DesGet8Thread,&x,&KLitKernExec,EKUDesInfoInvalidType,__LINE__);
1.281 + RunTestInThread(DesGet8Thread,&ubuf,NULL,KErrNone,__LINE__);
1.282 + RunTestInThread(DesGet8Thread,&ubuf,NULL,KErrNone,__LINE__);
1.283 + if (KernProt)
1.284 + {
1.285 + RunTestInThread(DesGet8Thread,Kern,&KLitKernExec,ECausedException,__LINE__);
1.286 + RunTestInThread(DesGet8Thread,&kptrc,&KLitKernExec,ECausedException,__LINE__);
1.287 + RunTestInThread(DesGet8Thread,&kptr,&KLitKernExec,ECausedException,__LINE__);
1.288 + }
1.289 + RunTestInThread(DesPut8Thread,&x,&KLitKernExec,EKUDesInfoInvalidType,__LINE__);
1.290 + RunTestInThread(DesPut8Thread,&ubuf,NULL,KErrNone,__LINE__);
1.291 + RunTestInThread(DesPut8Thread,&uptrc,&KLitKernExec,EKUDesSetLengthInvalidType,__LINE__);
1.292 + if (KernProt)
1.293 + {
1.294 + RunTestInThread(DesPut8Thread,Kern,&KLitKernExec,ECausedException,__LINE__);
1.295 + RunTestInThread(DesPut8Thread,&kptrc,&KLitKernExec,EKUDesSetLengthInvalidType,__LINE__);
1.296 + RunTestInThread(DesPut8Thread,&kptr,&KLitKernExec,ECausedException,__LINE__);
1.297 + }
1.298 + RunTestInThread(DesInfo8Thread,&x,&KLitKernExec,EKUDesInfoInvalidType,__LINE__);
1.299 + RunTestInThread(DesInfo8Thread,&ubuf,NULL,KErrNone,__LINE__);
1.300 + RunTestInThread(DesInfo8Thread,&uptrc,NULL,KErrNone,__LINE__);
1.301 + RunTestInThread(DesInfo8Thread,&kptrc,NULL,KErrNone,__LINE__);
1.302 + RunTestInThread(DesInfo8Thread,&kptr,NULL,KErrNone,__LINE__);
1.303 + if (KernProt)
1.304 + {
1.305 + RunTestInThread(DesInfo8Thread,Kern,&KLitKernExec,ECausedException,__LINE__);
1.306 + }
1.307 +
1.308 + User::SetJustInTime(jit);
1.309 + }
1.310 +
1.311 +void RequestCompleteBadPointer(TUint aBadAddress)
1.312 + {
1.313 + TRequestStatus* badStatus = (TRequestStatus*)aBadAddress;
1.314 + test.Printf(_L("Test Kern::RequestComplete to %08x\n"), aBadAddress);
1.315 + KU.RequestComplete(badStatus);
1.316 + test.Printf(_L("Test Kern::RequestComplete to %08x (in current thread)\n"), aBadAddress);
1.317 + KU.RequestCompleteLocal(badStatus);
1.318 +
1.319 + // Check the thread hasn't been signalled
1.320 + TRequestStatus status;
1.321 + RTimer timer;
1.322 + test_KErrNone(timer.CreateLocal());
1.323 + timer.After(status, 100000); // 100ms
1.324 + test_Equal(KRequestPending, status.Int());
1.325 + User::WaitForAnyRequest();
1.326 + test_Equal(KErrNone, status.Int());
1.327 + timer.Close();
1.328 +
1.329 + test.Printf(_L("Test Kern::QueueRequestComplete to %08x\n"), aBadAddress);
1.330 + TInt r = KU.QueueRequestComplete(badStatus);
1.331 +
1.332 + // Kern::QueueRequestComplete will signal even if the pointer is bad, unless:
1.333 + // - the pointer is null
1.334 + // - the call to Setup returned an error
1.335 + if (badStatus != NULL && r == KErrNone)
1.336 + User::WaitForAnyRequest();
1.337 + }
1.338 +
1.339 +void TestRequestCompleteTrapped()
1.340 + {
1.341 + TRequestStatus status;
1.342 + test.Printf(_L("Test Kern::RequestComplete to %08x\n"), &status);
1.343 + status = KRequestPending;
1.344 + KU.RequestComplete(&status);
1.345 + User::WaitForRequest(status);
1.346 + test_Equal(KErrNone, status.Int());
1.347 +
1.348 + test.Printf(_L("Test Kern::RequestComplete to %08x (in current thread)\n"), &status);
1.349 + status = KRequestPending;
1.350 + KU.RequestCompleteLocal(&status);
1.351 + User::WaitForRequest(status);
1.352 + test_Equal(KErrNone, status.Int());
1.353 +
1.354 + test.Printf(_L("Test Kern::QueueRequestComplete to %08x\n"), &status);
1.355 + status = KRequestPending;
1.356 + KU.QueueRequestComplete(&status);
1.357 + User::WaitForRequest(status);
1.358 + test_Equal(KErrNone, status.Int());
1.359 +
1.360 + RequestCompleteBadPointer(0x00000000);
1.361 + RequestCompleteBadPointer(0x00000001);
1.362 + RequestCompleteBadPointer(0x00000004);
1.363 + RequestCompleteBadPointer(0x00000008);
1.364 + if (KernProt)
1.365 + {
1.366 + RequestCompleteBadPointer(0x80000000);
1.367 + RequestCompleteBadPointer(0xfffffff0);
1.368 + RequestCompleteBadPointer((TUint)KU.KernelBufferAddress());
1.369 + }
1.370 + }
1.371 +
1.372 +GLDEF_C TInt E32Main()
1.373 + {
1.374 + test.Title();
1.375 + test.Start(_L("Load LDD"));
1.376 + TInt r=User::LoadLogicalDevice(KLddFileName);
1.377 + test(r==KErrNone || r==KErrAlreadyExists);
1.378 + test.Next(_L("Open channel"));
1.379 + r=KU.Open();
1.380 + test(r==KErrNone);
1.381 + test.Next(_L("Create chunk"));
1.382 + RChunk c;
1.383 + r=c.CreateDisconnectedLocal(0,0,0x100000);
1.384 + test(r==KErrNone);
1.385 + BufSize=KU.Length();
1.386 + RandSize=KU.RandomLength();
1.387 + test.Printf(_L("BufSize=%x, RandSize=%x\n"),BufSize,RandSize);
1.388 + r=c.Commit(0,BufSize);
1.389 + test(r==KErrNone);
1.390 + r=c.Commit(0x10000,BufSize);
1.391 + test(r==KErrNone);
1.392 + r=c.Commit(0x20000,RandSize);
1.393 + test(r==KErrNone);
1.394 + Buf1=c.Base();
1.395 + Buf2=c.Base()+0x10000;
1.396 + Random=c.Base()+0x20000;
1.397 + test.Printf(_L("Buf1 at %08x, Buf2 at %08x, Random at %08x\n"),Buf1,Buf2,Random);
1.398 + Mem::Fill(Buf1,BufSize,0xb1);
1.399 + Mem::Fill(Buf2,BufSize,0xb2);
1.400 + Mem::Fill(Random,RandSize,0x8b);
1.401 + KU.ReadRandom(Random);
1.402 +
1.403 + KernProt=HaveDirectKernProt();
1.404 +
1.405 +#ifndef QUICK
1.406 + TInt s;
1.407 + TInt d;
1.408 + TInt l;
1.409 + test.Next(_L("Put/Get 1"));
1.410 + for (l=1; l<300; l+=3)
1.411 + {
1.412 + test.Printf(_L("PG1: l=%d\n"),l);
1.413 + for (s=0; s<=BufSize-l; s+=227)
1.414 + {
1.415 + for (d=0; d<=BufSize-l; d+=229)
1.416 + {
1.417 + DoPutGetTest(s,d,l,EPut);
1.418 + DoPutGetTest(s,d,l,EGet);
1.419 + }
1.420 + }
1.421 + }
1.422 +
1.423 + test.Next(_L("Put/Get 2"));
1.424 + for (l=1; l<300; l+=3)
1.425 + {
1.426 + test.Printf(_L("PG2: l=%d\n"),l);
1.427 + for (s=BufSize-l; s>=0; s-=227)
1.428 + {
1.429 + for (d=BufSize-l; d>=0; d-=229)
1.430 + {
1.431 + DoPutGetTest(s,d,l,EPut);
1.432 + DoPutGetTest(s,d,l,EGet);
1.433 + }
1.434 + }
1.435 + }
1.436 +
1.437 + test.Next(_L("Put32/Get32 1"));
1.438 + for (l=4; l<300; l+=12)
1.439 + {
1.440 + test.Printf(_L("PG32,1: l=%d\n"),l);
1.441 + for (s=0; s<=BufSize-l; s+=4*59)
1.442 + {
1.443 + for (d=0; d<=BufSize-l; d+=4*61)
1.444 + {
1.445 + DoPutGetTest(s,d,l,EPut32);
1.446 + DoPutGetTest(s,d,l,EGet32);
1.447 + }
1.448 + }
1.449 + }
1.450 +
1.451 + test.Next(_L("Put32/Get32 2"));
1.452 + for (l=4; l<300; l+=12)
1.453 + {
1.454 + test.Printf(_L("PG32,2: l=%d\n"),l);
1.455 + for (s=BufSize-l; s>=0; s-=4*59)
1.456 + {
1.457 + for (d=BufSize-l; d>=0; d-=4*61)
1.458 + {
1.459 + DoPutGetTest(s,d,l,EPut32);
1.460 + DoPutGetTest(s,d,l,EGet32);
1.461 + }
1.462 + }
1.463 + }
1.464 + test.Next(_L("Set"));
1.465 + for (l=1; l<300; l+=3)
1.466 + {
1.467 + test.Printf(_L("Set: l=%d\n"),l);
1.468 + for (s=0; s<=BufSize-l; s+=83)
1.469 + {
1.470 + DoSetTest(s,l,0x1b);
1.471 + DoSetTest(s,l,0xaa);
1.472 + }
1.473 + for (s=BufSize-l; s>=0; s-=79)
1.474 + {
1.475 + DoSetTest(s,l,0x1b);
1.476 + DoSetTest(s,l,0xaa);
1.477 + }
1.478 + }
1.479 +#endif
1.480 + test.Next(_L("DesGet8"));
1.481 + TestDesGet8();
1.482 + test.Next(_L("DesPut8"));
1.483 + TestDesPut8();
1.484 + test.Next(_L("DesInfo8"));
1.485 + TestDesInfo8();
1.486 + test.Next(_L("Errors"));
1.487 + TestErrors();
1.488 + test.Next(_L("Test Kern::RequestComplete functions trapped"));
1.489 + TestRequestCompleteTrapped();
1.490 +
1.491 + c.Close();
1.492 + KU.Close();
1.493 + test.End();
1.494 + return 0;
1.495 + }
1.496 +
1.497 +
1.498 +
1.499 +