1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/tauto/TBUFFERSECURITY.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,457 @@
1.4 +// Copyright (c) 2006-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 "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 +// DEF075471 buffer security test
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file
1.23 + @test
1.24 + @internalComponent - Internal Symbian test code
1.25 +*/
1.26 +
1.27 +#include "TBUFFERSECURITY.H"
1.28 +#include "graphics/windowserverconstants.h"
1.29 +
1.30 +//Set this #define in buffersecurity.h to add extra logging to this test case (useful when debugging a test fail)
1.31 +//#define _TBUFS_LOGGING
1.32 +
1.33 +//Set this #define in buffersecurity.h to initiate a long running soak test, this should be done periodically
1.34 +//#define _TBUFS_TEST_SOAK_TEST
1.35 +
1.36 +
1.37 +
1.38 +LOCAL_C TInt TestWsThreadFunc(TAny* aPtr)
1.39 + {
1.40 + TTestThreadData* data = (TTestThreadData*)aPtr;
1.41 + RWsSession ws;
1.42 +
1.43 + TInt err=ws.Connect();
1.44 + if (err!=KErrNone)
1.45 + return(err);
1.46 + ws.TestWrite(ws.WsHandle(), data->iOpCode, data->iData, data->iDataLength);
1.47 + ws.Flush();
1.48 + ws.Close();
1.49 +
1.50 + return(KErrNone);
1.51 + }
1.52 +
1.53 +LOCAL_C TInt TestAnimDllThreadFunc(TInt aInt, TAny* /*aPtr*/)
1.54 + {
1.55 + TBool useTestWrite = (TBool)aInt;
1.56 +
1.57 + RWsSession ws;
1.58 + TInt err=ws.Connect();
1.59 + if (err != KErrNone)
1.60 + return (err);
1.61 + if (useTestWrite)
1.62 + {
1.63 + TUint32 data[2];
1.64 + data[0] = 200;
1.65 + data[1] = 4;
1.66 + ws.TestWrite(ws.WsHandle(), EWsClOpCreateAnimDll, REINTERPRET_CAST(TUint8*,data), 8);
1.67 + ws.Flush();
1.68 + }
1.69 + else
1.70 + {
1.71 + RAnimDll animDll(ws);
1.72 + const TPtrC filename(REINTERPRET_CAST(TUint16*,4),200);
1.73 + animDll.Load(filename);
1.74 + animDll.Close();
1.75 + }
1.76 + ws.Close();
1.77 +
1.78 + return(KErrNone);
1.79 + }
1.80 +
1.81 +TInt RTestIpcSession::Connect()
1.82 + {
1.83 + TVersion v(KWservMajorVersionNumber,KWservMinorVersionNumber,KWservBuildVersionNumber);
1.84 + TInt err = CreateSession(KWSERVServerName,v);
1.85 + if (err == KErrNone)
1.86 + {
1.87 + err=iWsHandle=SendReceive(EWservMessInit,TIpcArgs());
1.88 + }
1.89 + return err;
1.90 + }
1.91 +
1.92 +TInt RTestIpcSession::SendBadBuffer()
1.93 + {
1.94 + TIpcArgs ipcArgs;
1.95 + TUint32 iData[2];
1.96 + iData[0] = 200;
1.97 + iData[1] = 4;
1.98 + ipcArgs.Set(KBufferMessageSlot,&iData);
1.99 + return SendReceive(EWservMessCommandBuffer,ipcArgs);
1.100 + }
1.101 +
1.102 +LOCAL_C TInt TestIpcThreadFunc(TInt /*aInt*/, TAny* /*aPtr*/)
1.103 + {
1.104 + RTestIpcSession server;
1.105 +
1.106 + TInt handle=server.Connect();
1.107 + if (handle >= KErrNone)
1.108 + server.SendBadBuffer();
1.109 +
1.110 + return(KErrNone);
1.111 + }
1.112 +
1.113 +
1.114 +CTBufferSecurity::CTBufferSecurity(CTestStep* aStep):
1.115 + CTWsGraphicsBase(aStep)
1.116 + {
1.117 + }
1.118 +
1.119 +CTBufferSecurity::~CTBufferSecurity()
1.120 + {
1.121 + }
1.122 +
1.123 +void CTBufferSecurity::ConstructL()
1.124 + {
1.125 + RProperty securityTesting;
1.126 + TInt err=securityTesting.Attach(KUidWServSecurityTesting,EWServSecTestBufferSecurity);
1.127 + User::LeaveIfError(err);
1.128 + err=securityTesting.Define(KUidWServSecurityTesting,EWServSecTestBufferSecurity,RProperty::EInt,KAllowAllPolicy,KWriteDeviceDataMgmtPolicy);
1.129 + if (err!=KErrAlreadyExists)
1.130 + User::LeaveIfError(err);
1.131 + TInt value = ETrue;
1.132 + err = securityTesting.Set(value);
1.133 + User::LeaveIfError(err);
1.134 + }
1.135 +
1.136 +void CTBufferSecurity::TestWsBufferL(TInt aOpCode, TUint aDataFill, TBool aEightBit)
1.137 + {
1.138 + // create a new thread in which to test each of the TWsClientOpCode values
1.139 + // so if the thread is panicked the test will not fail.
1.140 + RThread testThread;
1.141 + TTestThreadData data;
1.142 + TRequestStatus status;
1.143 + TUint8 storeData[KTestDataMax];
1.144 + TTestDataStore store;
1.145 + store.any=storeData;
1.146 +
1.147 + //collect initial values
1.148 + for (TInt count = 0; count < KTestDataMax; count++)
1.149 + storeData[count] = 0;
1.150 + switch (aOpCode)
1.151 + {
1.152 + case EWsClOpHeapSetFail:
1.153 + store.heapSetFail->type = RAllocator::ENone;
1.154 + break;
1.155 + case EWsClOpSetPointerCursorArea:
1.156 + store.cursorArea->area = TheClient->iWs.PointerCursorArea();
1.157 + break;
1.158 + case EWsClOpRawEvent:
1.159 + //skip switch off (would need a timer to turn it back on again)
1.160 + if (aDataFill == TRawEvent::ESwitchOff)
1.161 + aDataFill = TRawEvent::ENone;
1.162 + break;
1.163 +#if defined(__WINS__)
1.164 + case EWsClOpSimulateXyInput:
1.165 + *store.xyInputType = EXYInputMouse;
1.166 + break;
1.167 +#endif
1.168 + }
1.169 +
1.170 + data.iOpCode = aOpCode;
1.171 + if (aEightBit)
1.172 + {
1.173 + for (TInt count = 0; count < KTestDataMax; count++)
1.174 + data.iData[count] = (TUint8)aDataFill;
1.175 + }
1.176 + else
1.177 + {
1.178 + for (TInt count = 0; count < KTestDataMax32; count++)
1.179 + data.iData32[count] = aDataFill;
1.180 + }
1.181 + data.iDataLength = KTestDataMax;
1.182 + _LIT(KThreadNameFormat,"BufSecTestWsThread-%d-%d");
1.183 + HBufC* threadName = HBufC::NewLC(KThreadNameFormat().Size() + 32);
1.184 + TPtr threadNamePtr(threadName->Des());
1.185 + threadNamePtr.Format(KThreadNameFormat(), aOpCode, aDataFill);
1.186 + TInt err = testThread.Create(threadNamePtr, TestWsThreadFunc,KDefaultStackSize,KPanicThreadHeapSize,KPanicThreadHeapSize,(TAny*)&data,EOwnerThread);
1.187 +
1.188 + if (err != KErrNone)
1.189 + {
1.190 + User::After(100000);
1.191 + err = testThread.Create(threadNamePtr,TestWsThreadFunc,KDefaultStackSize,KPanicThreadHeapSize,KPanicThreadHeapSize,(TAny*)&data,EOwnerThread);
1.192 + }
1.193 + CleanupStack::PopAndDestroy(threadName);
1.194 + testThread.Logon(status);
1.195 + User::SetJustInTime(EFalse);
1.196 + testThread.Resume();
1.197 + User::WaitForRequest(status);
1.198 + User::SetJustInTime(ETrue);
1.199 +#ifdef _TBUFS_LOGGING
1.200 + TLogMessageText logMessageText;
1.201 + TBufSStartLogText("TestWsBufferL");
1.202 + logMessageText.Format(_L(" OpCode(%d), ExitReason: %d"),aOpCode,testThread.ExitReason());
1.203 + TBufSLogFormat(logMessageText);
1.204 +#endif
1.205 +
1.206 + testThread.Close();
1.207 + //reset some values to sensible ones
1.208 + switch (aOpCode)
1.209 + {
1.210 + case EWsClOpHeapSetFail:
1.211 + case EWsClOpSetPointerCursorArea:
1.212 +#if defined(__WINS__)
1.213 + case EWsClOpSimulateXyInput:
1.214 +#endif
1.215 + RThread resetThread;
1.216 + TheClient->iWs.TestWrite(TheClient->iWs.WsHandle(), data.iOpCode, storeData, data.iDataLength);
1.217 + TheClient->iWs.Flush();
1.218 + break;
1.219 + }
1.220 + }
1.221 +
1.222 +void CTBufferSecurity::TestBadStringAnimDllL()
1.223 + {
1.224 + TEST(iTest->TestPanicL(&TestAnimDllThreadFunc,3,EFalse,NULL,KLitKernExec));
1.225 + }
1.226 +
1.227 +void CTBufferSecurity::TestBadStringL()
1.228 + {
1.229 + TEST(iTest->TestWsPanicL(&TestAnimDllThreadFunc,EWservPanicBufferPtr,ETrue,NULL));
1.230 + }
1.231 +
1.232 +void CTBufferSecurity::TestBadIpcL()
1.233 + {
1.234 + TEST(iTest->TestWsPanicL(&TestIpcThreadFunc,EWservPanicDescriptor,1));
1.235 + }
1.236 +
1.237 +void CTBufferSecurity::RunTestCaseL(TInt /*aCurTestCase*/)
1.238 + {
1.239 + TInt ii;
1.240 + ((CTBufferSecurityStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
1.241 + switch(++iTest->iState)
1.242 + {
1.243 + case 1:
1.244 + ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0022"));
1.245 + _LIT(KBuffSecTestBadIpcL,"TestBadIpcL");
1.246 + iTest->LogSubTest(KBuffSecTestBadIpcL);
1.247 + TestBadIpcL();
1.248 + break;
1.249 + case 2:
1.250 +/**
1.251 +@SYMTestCaseID GRAPHICS-WSERV-0549
1.252 +*/
1.253 + ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0549"));
1.254 + _LIT(KBuffSecTestBadStringLRAnimDll,"TestBadStringL use RAnimDll");
1.255 + iTest->LogSubTest(KBuffSecTestBadStringLRAnimDll);
1.256 + TestBadStringAnimDllL();
1.257 + break;
1.258 + case 3:
1.259 +/**
1.260 +@SYMTestCaseID GRAPHICS-WSERV-0550
1.261 +*/
1.262 + ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0550"));
1.263 + _LIT(KBuffSecTestBadStringLTestWrite,"TestBadStringL use TestWrite");
1.264 + iTest->LogSubTest(KBuffSecTestBadStringLTestWrite);
1.265 + TestBadStringL();
1.266 + break;
1.267 +#ifdef _TBUFS_TEST_SOAK_TEST
1.268 + case 4:
1.269 +/**
1.270 +@SYMTestCaseID GRAPHICS-WSERV-0551
1.271 +*/
1.272 + ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0551"));
1.273 + _LIT(KBuffSecTestWsBufferLSoak8bit,"TestWsBufferL Soak 8bit");
1.274 + iTest->LogSubTest(KBuffSecTestWsBufferLSoak8bit);
1.275 + for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
1.276 + {
1.277 + TUint8 soak8=0;//gets set as KMaxTUint8 on first iteration
1.278 + do
1.279 + {
1.280 + --soak8;
1.281 + TestWsBufferL(ii,soak8);
1.282 + }
1.283 + while (soak8>0);
1.284 + }
1.285 + break;
1.286 + case 5:
1.287 +/**
1.288 +@SYMTestCaseID GRAPHICS-WSERV-0552
1.289 +*/
1.290 + ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0552"));
1.291 + _LIT(KBuffSecTestWsBufferLSoak32bit,"TestWsBufferL Soak 32bit");
1.292 + iTest->LogSubTest(KBuffSecTestWsBufferLSoak32bit);
1.293 + for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
1.294 + {
1.295 + TUint32 soak32=0;//gets set as KMaxTUint8 on first iteration
1.296 + do
1.297 + {
1.298 + --soak32;
1.299 + TestWsBufferL(ii,soak32,EFalse);
1.300 + }
1.301 + while (soak32>0);
1.302 + }
1.303 + break;
1.304 +#else
1.305 + case 4:
1.306 +/**
1.307 +@SYMTestCaseID GRAPHICS-WSERV-0553
1.308 +*/
1.309 + ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0553"));
1.310 + _LIT(KBuffSecTestWsBufferL0,"TestWsBufferL 0");
1.311 + iTest->LogSubTest(KBuffSecTestWsBufferL0);
1.312 + for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
1.313 + {
1.314 + TestWsBufferL(ii,0);
1.315 + }
1.316 + break;
1.317 + case 5:
1.318 +/**
1.319 +@SYMTestCaseID GRAPHICS-WSERV-0554
1.320 +*/
1.321 + ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0554"));
1.322 + _LIT(KBuffSecTestWsBufferL5,"TestWsBufferL 5");
1.323 + iTest->LogSubTest(KBuffSecTestWsBufferL5);
1.324 + for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
1.325 + {
1.326 + TestWsBufferL(ii,5);
1.327 + }
1.328 + break;
1.329 + case 6:
1.330 +/**
1.331 +@SYMTestCaseID GRAPHICS-WSERV-0555
1.332 +*/
1.333 + ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0555"));
1.334 + _LIT(KBuffSecTestWsBufferL32,"TestWsBufferL 32");
1.335 + iTest->LogSubTest(KBuffSecTestWsBufferL32);
1.336 + for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
1.337 + {
1.338 + TestWsBufferL(ii,32);
1.339 + }
1.340 + break;
1.341 + case 7:
1.342 +/**
1.343 +@SYMTestCaseID GRAPHICS-WSERV-0556
1.344 +*/
1.345 + ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0556"));
1.346 + _LIT(KBuffSecTestWsBufferL64,"TestWsBufferL 64");
1.347 + iTest->LogSubTest(KBuffSecTestWsBufferL64);
1.348 + for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
1.349 + {
1.350 + TestWsBufferL(ii,64);
1.351 + }
1.352 + break;
1.353 + case 8:
1.354 +/**
1.355 +@SYMTestCaseID GRAPHICS-WSERV-0557
1.356 +*/
1.357 + ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0557"));
1.358 + _LIT(KBuffSecTestWsBufferL128,"TestWsBufferL 128");
1.359 + iTest->LogSubTest(KBuffSecTestWsBufferL128);
1.360 + for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
1.361 + {
1.362 + TestWsBufferL(ii,128);
1.363 + }
1.364 + break;
1.365 + case 9:
1.366 +/**
1.367 +@SYMTestCaseID GRAPHICS-WSERV-0558
1.368 +*/
1.369 + ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0558"));
1.370 + _LIT(KBuffSecTestWsBufferL255,"TestWsBufferL 255");
1.371 + iTest->LogSubTest(KBuffSecTestWsBufferL255);
1.372 + for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
1.373 + {
1.374 + TestWsBufferL(ii,255);
1.375 + }
1.376 + break;
1.377 + case 10:
1.378 +/**
1.379 +@SYMTestCaseID GRAPHICS-WSERV-0559
1.380 +*/
1.381 + ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0559"));
1.382 + _LIT(KBuffSecTestWsBufferL325,"TestWsBufferL 32-5");
1.383 + iTest->LogSubTest(KBuffSecTestWsBufferL325);
1.384 + for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
1.385 + {
1.386 + TestWsBufferL(ii,5,EFalse);
1.387 + }
1.388 + break;
1.389 + case 11:
1.390 +/**
1.391 +@SYMTestCaseID GRAPHICS-WSERV-0560
1.392 +*/
1.393 + ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0560"));
1.394 + _LIT(KBuffSecTestWsBufferL32128,"TestWsBufferL 32-128");
1.395 + iTest->LogSubTest(KBuffSecTestWsBufferL32128);
1.396 + for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
1.397 + {
1.398 + TestWsBufferL(ii,128,EFalse);
1.399 + }
1.400 + break;
1.401 + case 12:
1.402 +/**
1.403 +@SYMTestCaseID GRAPHICS-WSERV-0561
1.404 +*/
1.405 + ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0561"));
1.406 + _LIT(KBuffSecTestWsBufferL32512,"TestWsBufferL 32-512");
1.407 + iTest->LogSubTest(KBuffSecTestWsBufferL32512);
1.408 + for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
1.409 + {
1.410 + TestWsBufferL(ii,512,EFalse);
1.411 + }
1.412 + break;
1.413 + case 13:
1.414 +/**
1.415 +@SYMTestCaseID GRAPHICS-WSERV-0562
1.416 +*/
1.417 + ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0562"));
1.418 + _LIT(KBuffSecTestWsBufferL320x01234567,"TestWsBufferL 32-0x01234567");
1.419 + iTest->LogSubTest(KBuffSecTestWsBufferL320x01234567);
1.420 + for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
1.421 + {
1.422 + TestWsBufferL(ii,0x01234567,EFalse);
1.423 + }
1.424 + break;
1.425 + case 14:
1.426 +/**
1.427 +@SYMTestCaseID GRAPHICS-WSERV-0563
1.428 +*/
1.429 + ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0563"));
1.430 + _LIT(KBuffSecTestWsBufferL320x89abcdef,"TestWsBufferL 32-0x89abcdef");
1.431 + iTest->LogSubTest(KBuffSecTestWsBufferL320x89abcdef);
1.432 + for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
1.433 + {
1.434 + TestWsBufferL(ii,0x89abcdef,EFalse);
1.435 + }
1.436 + break;
1.437 + case 15:
1.438 +/**
1.439 +@SYMTestCaseID GRAPHICS-WSERV-0564
1.440 +*/
1.441 + ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0564"));
1.442 + _LIT(KBuffSecTestWsBufferL320xCCCCCCCC,"TestWsBufferL 32-0xCCCCCCCC");
1.443 + iTest->LogSubTest(KBuffSecTestWsBufferL320xCCCCCCCC);
1.444 + for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
1.445 + {
1.446 + TestWsBufferL(ii,0xCCCCCCCC,EFalse);
1.447 + }
1.448 + break;
1.449 +#endif
1.450 + default:
1.451 + ((CTBufferSecurityStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1.452 + ((CTBufferSecurityStep*)iStep)->CloseTMSGraphicsStep();
1.453 + TInt err = RProperty::Set(KUidWServSecurityTesting,EWServSecTestBufferSecurity,EFalse);
1.454 + User::LeaveIfError(err);
1.455 + TestComplete();
1.456 + }
1.457 + ((CTBufferSecurityStep*)iStep)->RecordTestResultL();
1.458 + }
1.459 +
1.460 +__WS_CONSTRUCT_STEP__(BufferSecurity)