Update contrib.
1 // Copyright (c) 2006-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 "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 // DEF075471 buffer security test
21 @internalComponent - Internal Symbian test code
24 #include "TBUFFERSECURITY.H"
25 #include "graphics/windowserverconstants.h"
27 //Set this #define in buffersecurity.h to add extra logging to this test case (useful when debugging a test fail)
28 //#define _TBUFS_LOGGING
30 //Set this #define in buffersecurity.h to initiate a long running soak test, this should be done periodically
31 //#define _TBUFS_TEST_SOAK_TEST
35 LOCAL_C TInt TestWsThreadFunc(TAny* aPtr)
37 TTestThreadData* data = (TTestThreadData*)aPtr;
40 TInt err=ws.Connect();
43 ws.TestWrite(ws.WsHandle(), data->iOpCode, data->iData, data->iDataLength);
50 LOCAL_C TInt TestAnimDllThreadFunc(TInt aInt, TAny* /*aPtr*/)
52 TBool useTestWrite = (TBool)aInt;
55 TInt err=ws.Connect();
63 ws.TestWrite(ws.WsHandle(), EWsClOpCreateAnimDll, REINTERPRET_CAST(TUint8*,data), 8);
69 const TPtrC filename(REINTERPRET_CAST(TUint16*,4),200);
70 animDll.Load(filename);
78 TInt RTestIpcSession::Connect()
80 TVersion v(KWservMajorVersionNumber,KWservMinorVersionNumber,KWservBuildVersionNumber);
81 TInt err = CreateSession(KWSERVServerName,v);
84 err=iWsHandle=SendReceive(EWservMessInit,TIpcArgs());
89 TInt RTestIpcSession::SendBadBuffer()
95 ipcArgs.Set(KBufferMessageSlot,&iData);
96 return SendReceive(EWservMessCommandBuffer,ipcArgs);
99 LOCAL_C TInt TestIpcThreadFunc(TInt /*aInt*/, TAny* /*aPtr*/)
101 RTestIpcSession server;
103 TInt handle=server.Connect();
104 if (handle >= KErrNone)
105 server.SendBadBuffer();
111 CTBufferSecurity::CTBufferSecurity(CTestStep* aStep):
112 CTWsGraphicsBase(aStep)
116 CTBufferSecurity::~CTBufferSecurity()
120 void CTBufferSecurity::ConstructL()
122 RProperty securityTesting;
123 TInt err=securityTesting.Attach(KUidWServSecurityTesting,EWServSecTestBufferSecurity);
124 User::LeaveIfError(err);
125 err=securityTesting.Define(KUidWServSecurityTesting,EWServSecTestBufferSecurity,RProperty::EInt,KAllowAllPolicy,KWriteDeviceDataMgmtPolicy);
126 if (err!=KErrAlreadyExists)
127 User::LeaveIfError(err);
129 err = securityTesting.Set(value);
130 User::LeaveIfError(err);
133 void CTBufferSecurity::TestWsBufferL(TInt aOpCode, TUint aDataFill, TBool aEightBit)
135 // create a new thread in which to test each of the TWsClientOpCode values
136 // so if the thread is panicked the test will not fail.
138 TTestThreadData data;
139 TRequestStatus status;
140 TUint8 storeData[KTestDataMax];
141 TTestDataStore store;
144 //collect initial values
145 for (TInt count = 0; count < KTestDataMax; count++)
146 storeData[count] = 0;
149 case EWsClOpHeapSetFail:
150 store.heapSetFail->type = RAllocator::ENone;
152 case EWsClOpSetPointerCursorArea:
153 store.cursorArea->area = TheClient->iWs.PointerCursorArea();
155 case EWsClOpRawEvent:
156 //skip switch off (would need a timer to turn it back on again)
157 if (aDataFill == TRawEvent::ESwitchOff)
158 aDataFill = TRawEvent::ENone;
160 #if defined(__WINS__)
161 case EWsClOpSimulateXyInput:
162 *store.xyInputType = EXYInputMouse;
167 data.iOpCode = aOpCode;
170 for (TInt count = 0; count < KTestDataMax; count++)
171 data.iData[count] = (TUint8)aDataFill;
175 for (TInt count = 0; count < KTestDataMax32; count++)
176 data.iData32[count] = aDataFill;
178 data.iDataLength = KTestDataMax;
179 _LIT(KThreadNameFormat,"BufSecTestWsThread-%d-%d");
180 HBufC* threadName = HBufC::NewLC(KThreadNameFormat().Size() + 32);
181 TPtr threadNamePtr(threadName->Des());
182 threadNamePtr.Format(KThreadNameFormat(), aOpCode, aDataFill);
183 TInt err = testThread.Create(threadNamePtr, TestWsThreadFunc,KDefaultStackSize,KPanicThreadHeapSize,KPanicThreadHeapSize,(TAny*)&data,EOwnerThread);
188 err = testThread.Create(threadNamePtr,TestWsThreadFunc,KDefaultStackSize,KPanicThreadHeapSize,KPanicThreadHeapSize,(TAny*)&data,EOwnerThread);
190 CleanupStack::PopAndDestroy(threadName);
191 testThread.Logon(status);
192 User::SetJustInTime(EFalse);
194 User::WaitForRequest(status);
195 User::SetJustInTime(ETrue);
196 #ifdef _TBUFS_LOGGING
197 TLogMessageText logMessageText;
198 TBufSStartLogText("TestWsBufferL");
199 logMessageText.Format(_L(" OpCode(%d), ExitReason: %d"),aOpCode,testThread.ExitReason());
200 TBufSLogFormat(logMessageText);
204 //reset some values to sensible ones
207 case EWsClOpHeapSetFail:
208 case EWsClOpSetPointerCursorArea:
209 #if defined(__WINS__)
210 case EWsClOpSimulateXyInput:
213 TheClient->iWs.TestWrite(TheClient->iWs.WsHandle(), data.iOpCode, storeData, data.iDataLength);
214 TheClient->iWs.Flush();
219 void CTBufferSecurity::TestBadStringAnimDllL()
221 TEST(iTest->TestPanicL(&TestAnimDllThreadFunc,3,EFalse,NULL,KLitKernExec));
224 void CTBufferSecurity::TestBadStringL()
226 TEST(iTest->TestWsPanicL(&TestAnimDllThreadFunc,EWservPanicBufferPtr,ETrue,NULL));
229 void CTBufferSecurity::TestBadIpcL()
231 TEST(iTest->TestWsPanicL(&TestIpcThreadFunc,EWservPanicDescriptor,1));
234 void CTBufferSecurity::RunTestCaseL(TInt /*aCurTestCase*/)
237 ((CTBufferSecurityStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
238 switch(++iTest->iState)
241 ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0022"));
242 _LIT(KBuffSecTestBadIpcL,"TestBadIpcL");
243 iTest->LogSubTest(KBuffSecTestBadIpcL);
248 @SYMTestCaseID GRAPHICS-WSERV-0549
250 ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0549"));
251 _LIT(KBuffSecTestBadStringLRAnimDll,"TestBadStringL use RAnimDll");
252 iTest->LogSubTest(KBuffSecTestBadStringLRAnimDll);
253 TestBadStringAnimDllL();
257 @SYMTestCaseID GRAPHICS-WSERV-0550
259 ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0550"));
260 _LIT(KBuffSecTestBadStringLTestWrite,"TestBadStringL use TestWrite");
261 iTest->LogSubTest(KBuffSecTestBadStringLTestWrite);
264 #ifdef _TBUFS_TEST_SOAK_TEST
267 @SYMTestCaseID GRAPHICS-WSERV-0551
269 ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0551"));
270 _LIT(KBuffSecTestWsBufferLSoak8bit,"TestWsBufferL Soak 8bit");
271 iTest->LogSubTest(KBuffSecTestWsBufferLSoak8bit);
272 for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
274 TUint8 soak8=0;//gets set as KMaxTUint8 on first iteration
278 TestWsBufferL(ii,soak8);
285 @SYMTestCaseID GRAPHICS-WSERV-0552
287 ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0552"));
288 _LIT(KBuffSecTestWsBufferLSoak32bit,"TestWsBufferL Soak 32bit");
289 iTest->LogSubTest(KBuffSecTestWsBufferLSoak32bit);
290 for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
292 TUint32 soak32=0;//gets set as KMaxTUint8 on first iteration
296 TestWsBufferL(ii,soak32,EFalse);
304 @SYMTestCaseID GRAPHICS-WSERV-0553
306 ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0553"));
307 _LIT(KBuffSecTestWsBufferL0,"TestWsBufferL 0");
308 iTest->LogSubTest(KBuffSecTestWsBufferL0);
309 for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
316 @SYMTestCaseID GRAPHICS-WSERV-0554
318 ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0554"));
319 _LIT(KBuffSecTestWsBufferL5,"TestWsBufferL 5");
320 iTest->LogSubTest(KBuffSecTestWsBufferL5);
321 for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
328 @SYMTestCaseID GRAPHICS-WSERV-0555
330 ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0555"));
331 _LIT(KBuffSecTestWsBufferL32,"TestWsBufferL 32");
332 iTest->LogSubTest(KBuffSecTestWsBufferL32);
333 for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
335 TestWsBufferL(ii,32);
340 @SYMTestCaseID GRAPHICS-WSERV-0556
342 ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0556"));
343 _LIT(KBuffSecTestWsBufferL64,"TestWsBufferL 64");
344 iTest->LogSubTest(KBuffSecTestWsBufferL64);
345 for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
347 TestWsBufferL(ii,64);
352 @SYMTestCaseID GRAPHICS-WSERV-0557
354 ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0557"));
355 _LIT(KBuffSecTestWsBufferL128,"TestWsBufferL 128");
356 iTest->LogSubTest(KBuffSecTestWsBufferL128);
357 for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
359 TestWsBufferL(ii,128);
364 @SYMTestCaseID GRAPHICS-WSERV-0558
366 ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0558"));
367 _LIT(KBuffSecTestWsBufferL255,"TestWsBufferL 255");
368 iTest->LogSubTest(KBuffSecTestWsBufferL255);
369 for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
371 TestWsBufferL(ii,255);
376 @SYMTestCaseID GRAPHICS-WSERV-0559
378 ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0559"));
379 _LIT(KBuffSecTestWsBufferL325,"TestWsBufferL 32-5");
380 iTest->LogSubTest(KBuffSecTestWsBufferL325);
381 for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
383 TestWsBufferL(ii,5,EFalse);
388 @SYMTestCaseID GRAPHICS-WSERV-0560
390 ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0560"));
391 _LIT(KBuffSecTestWsBufferL32128,"TestWsBufferL 32-128");
392 iTest->LogSubTest(KBuffSecTestWsBufferL32128);
393 for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
395 TestWsBufferL(ii,128,EFalse);
400 @SYMTestCaseID GRAPHICS-WSERV-0561
402 ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0561"));
403 _LIT(KBuffSecTestWsBufferL32512,"TestWsBufferL 32-512");
404 iTest->LogSubTest(KBuffSecTestWsBufferL32512);
405 for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
407 TestWsBufferL(ii,512,EFalse);
412 @SYMTestCaseID GRAPHICS-WSERV-0562
414 ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0562"));
415 _LIT(KBuffSecTestWsBufferL320x01234567,"TestWsBufferL 32-0x01234567");
416 iTest->LogSubTest(KBuffSecTestWsBufferL320x01234567);
417 for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
419 TestWsBufferL(ii,0x01234567,EFalse);
424 @SYMTestCaseID GRAPHICS-WSERV-0563
426 ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0563"));
427 _LIT(KBuffSecTestWsBufferL320x89abcdef,"TestWsBufferL 32-0x89abcdef");
428 iTest->LogSubTest(KBuffSecTestWsBufferL320x89abcdef);
429 for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
431 TestWsBufferL(ii,0x89abcdef,EFalse);
436 @SYMTestCaseID GRAPHICS-WSERV-0564
438 ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0564"));
439 _LIT(KBuffSecTestWsBufferL320xCCCCCCCC,"TestWsBufferL 32-0xCCCCCCCC");
440 iTest->LogSubTest(KBuffSecTestWsBufferL320xCCCCCCCC);
441 for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++)
443 TestWsBufferL(ii,0xCCCCCCCC,EFalse);
448 ((CTBufferSecurityStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
449 ((CTBufferSecurityStep*)iStep)->CloseTMSGraphicsStep();
450 TInt err = RProperty::Set(KUidWServSecurityTesting,EWServSecTestBufferSecurity,EFalse);
451 User::LeaveIfError(err);
454 ((CTBufferSecurityStep*)iStep)->RecordTestResultL();
457 __WS_CONSTRUCT_STEP__(BufferSecurity)