sl@0: // Copyright (c) 2006-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 "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: // DEF075471 buffer security test sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent - Internal Symbian test code sl@0: */ sl@0: sl@0: #include "TBUFFERSECURITY.H" sl@0: #include "graphics/windowserverconstants.h" sl@0: sl@0: //Set this #define in buffersecurity.h to add extra logging to this test case (useful when debugging a test fail) sl@0: //#define _TBUFS_LOGGING sl@0: sl@0: //Set this #define in buffersecurity.h to initiate a long running soak test, this should be done periodically sl@0: //#define _TBUFS_TEST_SOAK_TEST sl@0: sl@0: sl@0: sl@0: LOCAL_C TInt TestWsThreadFunc(TAny* aPtr) sl@0: { sl@0: TTestThreadData* data = (TTestThreadData*)aPtr; sl@0: RWsSession ws; sl@0: sl@0: TInt err=ws.Connect(); sl@0: if (err!=KErrNone) sl@0: return(err); sl@0: ws.TestWrite(ws.WsHandle(), data->iOpCode, data->iData, data->iDataLength); sl@0: ws.Flush(); sl@0: ws.Close(); sl@0: sl@0: return(KErrNone); sl@0: } sl@0: sl@0: LOCAL_C TInt TestAnimDllThreadFunc(TInt aInt, TAny* /*aPtr*/) sl@0: { sl@0: TBool useTestWrite = (TBool)aInt; sl@0: sl@0: RWsSession ws; sl@0: TInt err=ws.Connect(); sl@0: if (err != KErrNone) sl@0: return (err); sl@0: if (useTestWrite) sl@0: { sl@0: TUint32 data[2]; sl@0: data[0] = 200; sl@0: data[1] = 4; sl@0: ws.TestWrite(ws.WsHandle(), EWsClOpCreateAnimDll, REINTERPRET_CAST(TUint8*,data), 8); sl@0: ws.Flush(); sl@0: } sl@0: else sl@0: { sl@0: RAnimDll animDll(ws); sl@0: const TPtrC filename(REINTERPRET_CAST(TUint16*,4),200); sl@0: animDll.Load(filename); sl@0: animDll.Close(); sl@0: } sl@0: ws.Close(); sl@0: sl@0: return(KErrNone); sl@0: } sl@0: sl@0: TInt RTestIpcSession::Connect() sl@0: { sl@0: TVersion v(KWservMajorVersionNumber,KWservMinorVersionNumber,KWservBuildVersionNumber); sl@0: TInt err = CreateSession(KWSERVServerName,v); sl@0: if (err == KErrNone) sl@0: { sl@0: err=iWsHandle=SendReceive(EWservMessInit,TIpcArgs()); sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: TInt RTestIpcSession::SendBadBuffer() sl@0: { sl@0: TIpcArgs ipcArgs; sl@0: TUint32 iData[2]; sl@0: iData[0] = 200; sl@0: iData[1] = 4; sl@0: ipcArgs.Set(KBufferMessageSlot,&iData); sl@0: return SendReceive(EWservMessCommandBuffer,ipcArgs); sl@0: } sl@0: sl@0: LOCAL_C TInt TestIpcThreadFunc(TInt /*aInt*/, TAny* /*aPtr*/) sl@0: { sl@0: RTestIpcSession server; sl@0: sl@0: TInt handle=server.Connect(); sl@0: if (handle >= KErrNone) sl@0: server.SendBadBuffer(); sl@0: sl@0: return(KErrNone); sl@0: } sl@0: sl@0: sl@0: CTBufferSecurity::CTBufferSecurity(CTestStep* aStep): sl@0: CTWsGraphicsBase(aStep) sl@0: { sl@0: } sl@0: sl@0: CTBufferSecurity::~CTBufferSecurity() sl@0: { sl@0: } sl@0: sl@0: void CTBufferSecurity::ConstructL() sl@0: { sl@0: RProperty securityTesting; sl@0: TInt err=securityTesting.Attach(KUidWServSecurityTesting,EWServSecTestBufferSecurity); sl@0: User::LeaveIfError(err); sl@0: err=securityTesting.Define(KUidWServSecurityTesting,EWServSecTestBufferSecurity,RProperty::EInt,KAllowAllPolicy,KWriteDeviceDataMgmtPolicy); sl@0: if (err!=KErrAlreadyExists) sl@0: User::LeaveIfError(err); sl@0: TInt value = ETrue; sl@0: err = securityTesting.Set(value); sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: void CTBufferSecurity::TestWsBufferL(TInt aOpCode, TUint aDataFill, TBool aEightBit) sl@0: { sl@0: // create a new thread in which to test each of the TWsClientOpCode values sl@0: // so if the thread is panicked the test will not fail. sl@0: RThread testThread; sl@0: TTestThreadData data; sl@0: TRequestStatus status; sl@0: TUint8 storeData[KTestDataMax]; sl@0: TTestDataStore store; sl@0: store.any=storeData; sl@0: sl@0: //collect initial values sl@0: for (TInt count = 0; count < KTestDataMax; count++) sl@0: storeData[count] = 0; sl@0: switch (aOpCode) sl@0: { sl@0: case EWsClOpHeapSetFail: sl@0: store.heapSetFail->type = RAllocator::ENone; sl@0: break; sl@0: case EWsClOpSetPointerCursorArea: sl@0: store.cursorArea->area = TheClient->iWs.PointerCursorArea(); sl@0: break; sl@0: case EWsClOpRawEvent: sl@0: //skip switch off (would need a timer to turn it back on again) sl@0: if (aDataFill == TRawEvent::ESwitchOff) sl@0: aDataFill = TRawEvent::ENone; sl@0: break; sl@0: #if defined(__WINS__) sl@0: case EWsClOpSimulateXyInput: sl@0: *store.xyInputType = EXYInputMouse; sl@0: break; sl@0: #endif sl@0: } sl@0: sl@0: data.iOpCode = aOpCode; sl@0: if (aEightBit) sl@0: { sl@0: for (TInt count = 0; count < KTestDataMax; count++) sl@0: data.iData[count] = (TUint8)aDataFill; sl@0: } sl@0: else sl@0: { sl@0: for (TInt count = 0; count < KTestDataMax32; count++) sl@0: data.iData32[count] = aDataFill; sl@0: } sl@0: data.iDataLength = KTestDataMax; sl@0: _LIT(KThreadNameFormat,"BufSecTestWsThread-%d-%d"); sl@0: HBufC* threadName = HBufC::NewLC(KThreadNameFormat().Size() + 32); sl@0: TPtr threadNamePtr(threadName->Des()); sl@0: threadNamePtr.Format(KThreadNameFormat(), aOpCode, aDataFill); sl@0: TInt err = testThread.Create(threadNamePtr, TestWsThreadFunc,KDefaultStackSize,KPanicThreadHeapSize,KPanicThreadHeapSize,(TAny*)&data,EOwnerThread); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: User::After(100000); sl@0: err = testThread.Create(threadNamePtr,TestWsThreadFunc,KDefaultStackSize,KPanicThreadHeapSize,KPanicThreadHeapSize,(TAny*)&data,EOwnerThread); sl@0: } sl@0: CleanupStack::PopAndDestroy(threadName); sl@0: testThread.Logon(status); sl@0: User::SetJustInTime(EFalse); sl@0: testThread.Resume(); sl@0: User::WaitForRequest(status); sl@0: User::SetJustInTime(ETrue); sl@0: #ifdef _TBUFS_LOGGING sl@0: TLogMessageText logMessageText; sl@0: TBufSStartLogText("TestWsBufferL"); sl@0: logMessageText.Format(_L(" OpCode(%d), ExitReason: %d"),aOpCode,testThread.ExitReason()); sl@0: TBufSLogFormat(logMessageText); sl@0: #endif sl@0: sl@0: testThread.Close(); sl@0: //reset some values to sensible ones sl@0: switch (aOpCode) sl@0: { sl@0: case EWsClOpHeapSetFail: sl@0: case EWsClOpSetPointerCursorArea: sl@0: #if defined(__WINS__) sl@0: case EWsClOpSimulateXyInput: sl@0: #endif sl@0: RThread resetThread; sl@0: TheClient->iWs.TestWrite(TheClient->iWs.WsHandle(), data.iOpCode, storeData, data.iDataLength); sl@0: TheClient->iWs.Flush(); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CTBufferSecurity::TestBadStringAnimDllL() sl@0: { sl@0: TEST(iTest->TestPanicL(&TestAnimDllThreadFunc,3,EFalse,NULL,KLitKernExec)); sl@0: } sl@0: sl@0: void CTBufferSecurity::TestBadStringL() sl@0: { sl@0: TEST(iTest->TestWsPanicL(&TestAnimDllThreadFunc,EWservPanicBufferPtr,ETrue,NULL)); sl@0: } sl@0: sl@0: void CTBufferSecurity::TestBadIpcL() sl@0: { sl@0: TEST(iTest->TestWsPanicL(&TestIpcThreadFunc,EWservPanicDescriptor,1)); sl@0: } sl@0: sl@0: void CTBufferSecurity::RunTestCaseL(TInt /*aCurTestCase*/) sl@0: { sl@0: TInt ii; sl@0: ((CTBufferSecurityStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); sl@0: switch(++iTest->iState) sl@0: { sl@0: case 1: sl@0: ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0022")); sl@0: _LIT(KBuffSecTestBadIpcL,"TestBadIpcL"); sl@0: iTest->LogSubTest(KBuffSecTestBadIpcL); sl@0: TestBadIpcL(); sl@0: break; sl@0: case 2: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0549 sl@0: */ sl@0: ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0549")); sl@0: _LIT(KBuffSecTestBadStringLRAnimDll,"TestBadStringL use RAnimDll"); sl@0: iTest->LogSubTest(KBuffSecTestBadStringLRAnimDll); sl@0: TestBadStringAnimDllL(); sl@0: break; sl@0: case 3: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0550 sl@0: */ sl@0: ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0550")); sl@0: _LIT(KBuffSecTestBadStringLTestWrite,"TestBadStringL use TestWrite"); sl@0: iTest->LogSubTest(KBuffSecTestBadStringLTestWrite); sl@0: TestBadStringL(); sl@0: break; sl@0: #ifdef _TBUFS_TEST_SOAK_TEST sl@0: case 4: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0551 sl@0: */ sl@0: ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0551")); sl@0: _LIT(KBuffSecTestWsBufferLSoak8bit,"TestWsBufferL Soak 8bit"); sl@0: iTest->LogSubTest(KBuffSecTestWsBufferLSoak8bit); sl@0: for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++) sl@0: { sl@0: TUint8 soak8=0;//gets set as KMaxTUint8 on first iteration sl@0: do sl@0: { sl@0: --soak8; sl@0: TestWsBufferL(ii,soak8); sl@0: } sl@0: while (soak8>0); sl@0: } sl@0: break; sl@0: case 5: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0552 sl@0: */ sl@0: ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0552")); sl@0: _LIT(KBuffSecTestWsBufferLSoak32bit,"TestWsBufferL Soak 32bit"); sl@0: iTest->LogSubTest(KBuffSecTestWsBufferLSoak32bit); sl@0: for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++) sl@0: { sl@0: TUint32 soak32=0;//gets set as KMaxTUint8 on first iteration sl@0: do sl@0: { sl@0: --soak32; sl@0: TestWsBufferL(ii,soak32,EFalse); sl@0: } sl@0: while (soak32>0); sl@0: } sl@0: break; sl@0: #else sl@0: case 4: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0553 sl@0: */ sl@0: ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0553")); sl@0: _LIT(KBuffSecTestWsBufferL0,"TestWsBufferL 0"); sl@0: iTest->LogSubTest(KBuffSecTestWsBufferL0); sl@0: for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++) sl@0: { sl@0: TestWsBufferL(ii,0); sl@0: } sl@0: break; sl@0: case 5: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0554 sl@0: */ sl@0: ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0554")); sl@0: _LIT(KBuffSecTestWsBufferL5,"TestWsBufferL 5"); sl@0: iTest->LogSubTest(KBuffSecTestWsBufferL5); sl@0: for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++) sl@0: { sl@0: TestWsBufferL(ii,5); sl@0: } sl@0: break; sl@0: case 6: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0555 sl@0: */ sl@0: ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0555")); sl@0: _LIT(KBuffSecTestWsBufferL32,"TestWsBufferL 32"); sl@0: iTest->LogSubTest(KBuffSecTestWsBufferL32); sl@0: for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++) sl@0: { sl@0: TestWsBufferL(ii,32); sl@0: } sl@0: break; sl@0: case 7: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0556 sl@0: */ sl@0: ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0556")); sl@0: _LIT(KBuffSecTestWsBufferL64,"TestWsBufferL 64"); sl@0: iTest->LogSubTest(KBuffSecTestWsBufferL64); sl@0: for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++) sl@0: { sl@0: TestWsBufferL(ii,64); sl@0: } sl@0: break; sl@0: case 8: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0557 sl@0: */ sl@0: ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0557")); sl@0: _LIT(KBuffSecTestWsBufferL128,"TestWsBufferL 128"); sl@0: iTest->LogSubTest(KBuffSecTestWsBufferL128); sl@0: for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++) sl@0: { sl@0: TestWsBufferL(ii,128); sl@0: } sl@0: break; sl@0: case 9: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0558 sl@0: */ sl@0: ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0558")); sl@0: _LIT(KBuffSecTestWsBufferL255,"TestWsBufferL 255"); sl@0: iTest->LogSubTest(KBuffSecTestWsBufferL255); sl@0: for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++) sl@0: { sl@0: TestWsBufferL(ii,255); sl@0: } sl@0: break; sl@0: case 10: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0559 sl@0: */ sl@0: ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0559")); sl@0: _LIT(KBuffSecTestWsBufferL325,"TestWsBufferL 32-5"); sl@0: iTest->LogSubTest(KBuffSecTestWsBufferL325); sl@0: for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++) sl@0: { sl@0: TestWsBufferL(ii,5,EFalse); sl@0: } sl@0: break; sl@0: case 11: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0560 sl@0: */ sl@0: ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0560")); sl@0: _LIT(KBuffSecTestWsBufferL32128,"TestWsBufferL 32-128"); sl@0: iTest->LogSubTest(KBuffSecTestWsBufferL32128); sl@0: for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++) sl@0: { sl@0: TestWsBufferL(ii,128,EFalse); sl@0: } sl@0: break; sl@0: case 12: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0561 sl@0: */ sl@0: ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0561")); sl@0: _LIT(KBuffSecTestWsBufferL32512,"TestWsBufferL 32-512"); sl@0: iTest->LogSubTest(KBuffSecTestWsBufferL32512); sl@0: for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++) sl@0: { sl@0: TestWsBufferL(ii,512,EFalse); sl@0: } sl@0: break; sl@0: case 13: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0562 sl@0: */ sl@0: ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0562")); sl@0: _LIT(KBuffSecTestWsBufferL320x01234567,"TestWsBufferL 32-0x01234567"); sl@0: iTest->LogSubTest(KBuffSecTestWsBufferL320x01234567); sl@0: for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++) sl@0: { sl@0: TestWsBufferL(ii,0x01234567,EFalse); sl@0: } sl@0: break; sl@0: case 14: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0563 sl@0: */ sl@0: ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0563")); sl@0: _LIT(KBuffSecTestWsBufferL320x89abcdef,"TestWsBufferL 32-0x89abcdef"); sl@0: iTest->LogSubTest(KBuffSecTestWsBufferL320x89abcdef); sl@0: for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++) sl@0: { sl@0: TestWsBufferL(ii,0x89abcdef,EFalse); sl@0: } sl@0: break; sl@0: case 15: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0564 sl@0: */ sl@0: ((CTBufferSecurityStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0564")); sl@0: _LIT(KBuffSecTestWsBufferL320xCCCCCCCC,"TestWsBufferL 32-0xCCCCCCCC"); sl@0: iTest->LogSubTest(KBuffSecTestWsBufferL320xCCCCCCCC); sl@0: for(ii = EWsClOpDisconnect; ii < EWsClOpLastEnumValue; ii++) sl@0: { sl@0: TestWsBufferL(ii,0xCCCCCCCC,EFalse); sl@0: } sl@0: break; sl@0: #endif sl@0: default: sl@0: ((CTBufferSecurityStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); sl@0: ((CTBufferSecurityStep*)iStep)->CloseTMSGraphicsStep(); sl@0: TInt err = RProperty::Set(KUidWServSecurityTesting,EWServSecTestBufferSecurity,EFalse); sl@0: User::LeaveIfError(err); sl@0: TestComplete(); sl@0: } sl@0: ((CTBufferSecurityStep*)iStep)->RecordTestResultL(); sl@0: } sl@0: sl@0: __WS_CONSTRUCT_STEP__(BufferSecurity)