void CSimpleAppUi::CmdTestOutOfMemoryL() { // __ASSERT_ALWAYS(iContainer, CTestContainer::Panic(TContainerInalidPointer)); // Creates and deletes to bitmaps in order to allocate filename in the cache for FBserv CFbsBitmap* bitmap = iEikonEnv->CreateBitmapL(KTBmpAnimMBMFilePath/*Application()->BitmapStoreName()*/, 0); CFbsBitmap* mask = iEikonEnv->CreateBitmapL(KTBmpAnimMBMFilePath/*Application()->BitmapStoreName()*/, 1); delete bitmap; delete mask; iContainer->CancelAnimationL(EAllAnimations); TInt error = KErrNoMemory; iEikonEnv->BusyMsgL(_L("OOMemory Test")); __UHEAP_RESET; for(TInt fail=0; error != KErrNone; fail++) { __UHEAP_SETFAIL(RHeap::EFailNext, fail); // turn failure on __UHEAP_MARK; TRAP(error, iContainer->CreateAndRunAnimationL()); if ( (error != KErrNoMemory) && (error != KErrNone) ) User::Panic(_L("Memory Test"), error); REComSession::FinalClose(); __UHEAP_MARKEND; } __UHEAP_SETFAIL(RHeap::ENone, 0); // turn failure off iEikonEnv->BusyMsgCancel(); iEikonEnv->InfoMsg(_L("OOMemory test completed")); }
/** Test under OOM conditions. This is a wrapper function to call all test functions. @param aTestFunctionL Pointer to test function. @param aTestDesc test function name */ LOCAL_C void DoOOMTestL(ClassFuncPtrL aTestFunctionL, const TDesC& aTestDesc) { TheTest.Next(aTestDesc); TInt err = KErrNone; TInt tryCount = 0; do { __UHEAP_MARK; // find out the number of open handles TInt startProcessHandleCount; TInt startThreadHandleCount; RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount); TRAP(err, aTestFunctionL()); __UHEAP_SETFAIL(RHeap::ENone, 0); // check that no handles have leaked TInt endProcessHandleCount; TInt endThreadHandleCount; RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); TESTL(startProcessHandleCount == endProcessHandleCount); TESTL(startThreadHandleCount == endThreadHandleCount); __UHEAP_MARKEND; } while(err == KErrNoMemory); TESTL(err==KErrNone); TheTest.Printf(_L("- succeeded at heap failure rate of %i\n"), tryCount); }
/** @SYMTestCaseID GRAPHICS-FBSERV-0515 @SYMTestCaseDesc Tests memory allocation of CFontStore object @SYMTestActions CFontStore objects is created on the heap @SYMTestExpectedResults Test should pass */ void CTAlloc::FontStoreL() { INFO_PRINTF1(_L("CFontStore::NewL()\r\n")); for (TInt count = 1; ; count++) { __UHEAP_SETFAIL(RHeap::EDeterministic,count); __UHEAP_MARK; CFontStore* fs = NULL; TRAPD(ret,fs = CFontStore::NewL(&User::Heap())); if (ret == KErrNoMemory) { __UHEAP_MARKEND; } else if (ret == KErrNone) { delete fs; __UHEAP_MARKEND; __UHEAP_SETFAIL(RHeap::ENone,count); break; } else { __UHEAP_MARKEND; TEST2(ret, KErrNone); } } }
TVerdict CTestStepDevVideoPlayAllocFailNew::DoTestL() { iTestStepResult = EPass; TInt err = KErrNone; // Printing to the console and log file INFO_PRINTF1(_L("this is an Alloc Failure test of initialising CMMFDevVideoPlay with NewL()")); __UHEAP_MARK; TRAP( err, iDevVideoPlay = CMMFDevVideoPlay::NewL(*this) ); delete iDevVideoPlay; iDevVideoPlay = NULL; __UHEAP_MARKEND; if (err != KErrNone) return EFail; TInt failCount = 1; TBool completed = EFalse; TBool reachedEnd = EFalse; // Note: declare outside loop to help with debugging for(;;) { __UHEAP_SETFAIL(RHeap::EFailNext ,failCount); __MM_HEAP_MARK; TRAP( err, iDevVideoPlay = CMMFDevVideoPlay::NewL(*this); iDevVideoPlay->SelectDecoderL(KUidDevVideoTestDecodeHwDevice); iDevVideoPlay->SelectPostProcessorL(KUidDevVideoTestPostProcHwDevice); ); completed = EFalse; if (err == KErrNone) { TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test if (testAlloc==NULL) { reachedEnd = ETrue; failCount--; // -= 1; } else User::Free(testAlloc); } else if (err != KErrNoMemory) // bad error code completed = ETrue; // see if valid result and break if wrong - might be premature result if (iDevVideoPlay) { delete iDevVideoPlay; iDevVideoPlay = NULL; } completed = reachedEnd; __MM_HEAP_MARKEND; __UHEAP_SETFAIL(RHeap::ENone ,0); if (completed) break; // exit loop failCount++; }
void CT_CP949::OOMTestL() { INFO_PRINTF1(_L("OOM testing")); TInt err, tryCount = 0; do { __UHEAP_MARK; // find out the number of open handles TInt startProcessHandleCount; TInt startThreadHandleCount; RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); // Setting Heap failure for OOM test __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount); TRAP(err,TestL()); __UHEAP_SETFAIL(RHeap::ENone, 0); // check that no handles have leaked TInt endProcessHandleCount; TInt endThreadHandleCount; RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); test(startProcessHandleCount == endProcessHandleCount); test(startThreadHandleCount == endThreadHandleCount); __UHEAP_MARKEND; }while (err == KErrNoMemory); test(err == KErrNone); INFO_PRINTF2(_L("- server succeeded at heap failure rate of %i\n"), tryCount); }
/** @SYMTestCaseID GRAPHICS-FBSERV-0606 @SYMTestCaseDesc Tests Out Of Memory conditions for the CFbsRalCache class. @SYMTestActions Connects to the file server. Sets a macro that makes heap allocation fail after a certain number of heap allocations. Creates a CFbsRalCache object on the heap. Deletes the object. Closes the file server handle. @SYMTestExpectedResults Test should pass */ void CTRalc::TestOOMCondition() { RFs fileServer; TInt ret; ret = fileServer.Connect(); TEST(ret==KErrNone); INFO_PRINTF1(_L("Test of CFbsRalCache and OOM")); for (TInt count = 1; ; count++) { __UHEAP_SETFAIL(RHeap::EDeterministic,count); __UHEAP_MARK; CFbsRalCache* cache = 0; cache = CFbsRalCache::New(4, fileServer); if (cache == 0) { __UHEAP_MARKEND; } else { delete cache; __UHEAP_MARKEND; __UHEAP_SETFAIL(RHeap::ENone,count); break; } } fileServer.Close(); }
//This function attempts to execute sqlite3_prepare_v2() or sqlite3_prepare16_v2() in an "out of memory loop". //If the prepare call fails, the statement handle is expected to be NULL. void StmtHandleTest(TStmtType aStmtType) { TEST(TheSqliteDb != NULL); for(TInt failingAllocationNo=1;;++failingAllocationNo) { __UHEAP_SETFAIL(RHeap::EFailNext, failingAllocationNo); sqlite3_stmt* stmt = NULL; TInt err = SQLITE_NOMEM; if(aStmtType == EStmt8) { _LIT8(KSelectSqlZ,"SELECT * FROM A\x0"); err = sqlite3_prepare_v2(TheSqliteDb, (const char*)(KSelectSqlZ().Ptr()), -1, &stmt, NULL); } else { _LIT(KSelectSqlZ,"SELECT * FROM A\x0"); err = sqlite3_prepare16_v2(TheSqliteDb, (const char*)(KSelectSqlZ().Ptr()), -1, &stmt, NULL); } __UHEAP_SETFAIL(RHeap::ENone, 0); if(err != SQLITE_OK) {//The statement handle should be NULL if err is not SQLITE_OK TEST(!stmt); } else { TEST(stmt != NULL); sqlite3_finalize(stmt); break; } } }
/** @SYMTestCaseID UIF-ETUL-0010 @SYMREQ 7736 @SYMTestCaseDesc OOM test for CTulAddressStringTokenizer's NewL() and DoNewSearchL() methods. @SYMTestPriority High @SYMTestStatus Implemented @SYMTestActions Calls CTulAddressStringTokenizer's NewL() and DoNewSearchL() methods. @SYMTestExpectedResults Tests should complete without any memory leaks. */ void CT_AddressStringTokenizerStep::TestOOMForAddressStringTokenizer() { INFO_PRINTF1(_L("Start OOM test for Address String Tokenizer")); CTulAddressStringTokenizer* addressString = NULL; TInt count; TInt fail; //OOM test for CTulAddressStringTokenizer::NewL() method. for (fail = 1;; fail++) { __UHEAP_SETFAIL(RHeap::EDeterministic, fail); __UHEAP_MARK; TRAPD(err, addressString = CTulAddressStringTokenizer::NewL(KTextToBeParsedForEmailAndURL, CTulAddressStringTokenizer::EFindItemSearchURLBin)); TEST((err == KErrNone) || (err == KErrNoMemory)); if (err == KErrNone) { // Get count of found URL's count = addressString->ItemCount(); TEST(count == 2); delete addressString; addressString = NULL; __UHEAP_MARKEND; break; } __UHEAP_MARKEND; } //OOM test for CTulAddressStringTokenizer::DoNewSearchL() method. for (fail = 1; ; fail++) { __UHEAP_RESET; TRAPD(err, addressString = CTulAddressStringTokenizer::NewL(KTextToBeParsedForEmailAndURL, CTulAddressStringTokenizer::EFindItemSearchURLBin)); TEST(err == KErrNone); __UHEAP_SETFAIL(RHeap::EDeterministic, fail); __UHEAP_MARK; TRAP(err, count = addressString->CTulAddressStringTokenizer::DoNewSearchL(KTextToBeParsed, CTulAddressStringTokenizer::EFindItemSearchMailAddressBin)); TEST((err == KErrNone) || (err == KErrNoMemory)); if (err == KErrNone) { // Get count of found URL's count = addressString->ItemCount(); TEST(count == 1); delete addressString; __UHEAP_MARKEND; break; } else { delete addressString; __UHEAP_MARKEND; } } __UHEAP_RESET; INFO_PRINTF1(_L("OOM test for Address String Tokenizer Completed")); }
void DoInserts(TInt aProcId, TInt aRecId1, TInt aRecId2) { TEST(TheDb != 0); TTime now; now.UniversalTime(); TInt64 seed = now.Int64(); const TInt KMaxFailingAllocationNo = 20; TInt lockcnt = 0; for(TInt recno=0;recno<KTestRecordCnt;) { //Insert record 1 under OOM simulation TInt failingAllocationNo = Math::Rand(seed) % (KMaxFailingAllocationNo + 1); __UHEAP_SETFAIL(RHeap::EDeterministic, failingAllocationNo ); TBuf8<100> sql; sql.Format(_L8("INSERT INTO A VALUES(%d)"), aRecId1); TInt err = sqlite3_exec(TheDb, (const char*)sql.PtrZ(), 0, 0, 0); __UHEAP_SETFAIL(RHeap::ENone, 0); TEST(err == SQLITE_NOMEM || err == SQLITE_BUSY || err == SQLITE_OK); if(err == SQLITE_BUSY) { ++lockcnt; User::After(1); continue; } else if(err == SQLITE_OK) { ++recno; if((recno % 100) == 0) { RDebug::Print(_L("Process %d: %d records inserted.\r\n"), aProcId, recno); } continue; } //Insert record 2 sql.Format(_L8("INSERT INTO A VALUES(%d)"), aRecId2); err = sqlite3_exec(TheDb, (const char*)sql.PtrZ(), 0, 0, 0); TEST(err == SQLITE_BUSY || err == SQLITE_OK); if(err == SQLITE_BUSY) { ++lockcnt; User::After(1); continue; } //SQLITE_OK case ++recno; if((recno % 100) == 0) { RDebug::Print(_L("Process %d: %d records inserted.\r\n"), aProcId, recno); } } RDebug::Print(_L("Process %d inserted %d records. %d locks occured.\r\n"), aProcId, KTestRecordCnt, lockcnt); }
/** Wrapper function to call all OOM test functions @param testFuncL pointer to OOM test function @param aTestDesc test function name @param aOOMMode to enable/disable the OOM environment */ LOCAL_C void DoOOMSwiTestL(ClassSwiFuncPtrL aTestFuncL, const TDesC& aTestDesc,TBool aOOMMode) { TheTest.Next(aTestDesc); TInt err=KErrNone; TInt tryCount = 0; do { __UHEAP_MARK; //Initializing the server resources TServerResources::InitialiseL (); //Clear any files in the persist directory CleanupCDriveL(); TInt startProcessHandleCount; TInt startThreadHandleCount; RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); CenrepSwiOOMTest* theTest=CenrepSwiOOMTest::NewL(); CleanupStack::PushL(theTest); // Set up test (theTest->*aTestFuncL)(ETrue); if (aOOMMode) __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount); TRAP(err, (theTest->*aTestFuncL)(EFalse)); if (aOOMMode) __UHEAP_SETFAIL(RHeap::ENone, 0); if (err!=KErrNoMemory) TESTKErrNoneL(err); CleanupStack::PopAndDestroy(theTest); // check that no handles have leaked TInt endProcessHandleCount; TInt endThreadHandleCount; RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); TEST2L(startProcessHandleCount, endProcessHandleCount); TEST2L(startThreadHandleCount, endThreadHandleCount); //Freeing the server resources TServerResources::Close(); __UHEAP_MARKEND; } while(err == KErrNoMemory); TESTKErrNoneL(err); if (aOOMMode) TheTest.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount); }
/** Wrapper function to call all OOM test functions @param testFuncL pointer to OOM test function @param aTestDesc test function name */ LOCAL_C void DoOOMNoServReposL( FuncPtrL atestFuncL, const TDesC& aTestDesc, TBool aOOMMode) { TheTest.Next(aTestDesc); TInt err; TInt tryCount = 0; do { __UHEAP_MARK; //Initializing the server resources TServerResources::InitialiseL (); //Clear any files in the persist directory CleanupCDriveL(); // find out the number of open handles TInt startProcessHandleCount; TInt startThreadHandleCount; RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); (*atestFuncL)(ETrue); if (aOOMMode) __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount); TRAP(err, (*atestFuncL)(EFalse)); if (err!=KErrNoMemory) TESTKErrNoneL(err); if (aOOMMode) __UHEAP_SETFAIL(RHeap::ENone, 0); // check that no handles have leaked TInt endProcessHandleCount; TInt endThreadHandleCount; RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); TEST2L(startProcessHandleCount, endProcessHandleCount); TEST2L(startThreadHandleCount, endThreadHandleCount); //Freeing the server resources TServerResources::Close(); __UHEAP_MARKEND; } while(err == KErrNoMemory); TESTKErrNoneL(err); if (aOOMMode) TheTest.Printf(_L("- server succeeded at heap failure rate of %i\n"), tryCount); }
/** @SYMTestCaseID APPFWK-APPARC-0084 @SYMREQ REQ7736 @SYMTestCaseDesc OOM test for CApfMimeContentPolicy's NewL() and IsClosedFileL() methods. @SYMTestPriority High @SYMTestStatus Implemented @SYMTestActions Calls CApfMimeContentPolicy's NewL() and IsClosedFileL() methods under OOM conditions. @SYMTestExpectedResults Tests should complete without any memory leaks. */ void CT_MimeContentPolicyStep::CCPOOMTestL() { INFO_PRINTF1(_L("OOM test for CApfMimeContentPolicy")); CApfMimeContentPolicy* mimeContentPolicy = NULL; TInt fail = 0; for (fail = 1; ; fail++) { __UHEAP_SETFAIL(RHeap::EDeterministic, fail); __UHEAP_MARK; TRAPD(err, mimeContentPolicy = CApfMimeContentPolicy::NewLC(); CleanupStack::Pop(mimeContentPolicy)); TEST(err == KErrNone || err == KErrNoMemory); if (err == KErrNone) { delete mimeContentPolicy; __UHEAP_MARKEND; break; } __UHEAP_MARKEND; } __UHEAP_RESET; TRAPD(err, mimeContentPolicy = CApfMimeContentPolicy::NewL()); CleanupStack::PushL(mimeContentPolicy); TEST(err == KErrNone); TInt ret = KErrNone; for (fail = 1; ; fail++) { __UHEAP_SETFAIL(RHeap::EDeterministic, fail); __UHEAP_MARK; TRAP(err, ret = mimeContentPolicy->IsClosedFileL(KPathdm1)); TEST(err == KErrNone || err == KErrNoMemory); if (err == KErrNone) { INFO_PRINTF1(_L("OOM Test for IsClosedFileL Method")); TEST(ret); INFO_PRINTF2(_L("%S is Closed File"), &KPathdm1); CleanupStack::PopAndDestroy(mimeContentPolicy); __UHEAP_MARKEND; break; } __UHEAP_MARKEND; } __UHEAP_RESET; INFO_PRINTF1(_L("OOM test Completed")); }
/** Test CDictionaryFileStore construction, forcing a leave error at each possible stage of the process. @SYMTestCaseID SYSLIB-STORE-CT-1190 @SYMTestCaseDesc Tests for CDictionaryFileStore construction under low memory conditions. @SYMTestPriority High @SYMTestActions Attempt for construction under low memory conditions. @SYMTestExpectedResults Test must not fail @SYMREQ REQ0000 */ LOCAL_C void TestOOML() { test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1190 Construction under low memory conditions ")); TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive())); TParse dicFilePath; dicFilePath.Set(drive.Name(), &KDicFilePath, NULL); TheFs.Delete(dicFilePath.FullName()); // delete the file TInt failRate=0; for (failRate=1;;failRate++) { __UHEAP_SETFAIL(RHeap::EDeterministic,failRate); __UHEAP_MARK; TRAPD(ret, AddEntryL()); __UHEAP_MARKEND; if (ret==KErrNone) break; test (ret==KErrNoMemory); __UHEAP_RESET; test (!CheckEntryL()); } __UHEAP_RESET; test (CheckEntryL()); test.Printf(_L(" #allocs for update: %d\n"),failRate-1); // // tidy up }
////////////////////////////////////////////////////////////////////////////// // // Do the example // // Example to check robustness of class on OOM and attempt to provoke // memory leaks (orphans). ////////////////////////////////////////////////////////////////////////////// void doExampleL() { #if defined(_DEBUG) //only ever used in debug mode TInt failValue = 5; #endif // Startup the alloc failure tool to fail in the third cycle. // To test for alloc heaven: // // An even value for 'failValue' should provoke memory leak, // an odd value should not. __UHEAP_SETFAIL(RHeap::EDeterministic,failValue); for(TInt ii=1; ii<4; ii++) { // Display status information _LIT(KFormat3,"Cycle %d.\n"); console->Printf(KFormat3,ii); // Create new instance CCompound* myCompoundExample = CCompound::NewL(1,2); // Display the instance myCompoundExample->Display(); // Destroy the instance delete myCompoundExample; } }
void DoOOMTestL(TTestFunction aTestFunction) { TInt ret = KErrNoMemory; TInt failAt = 0; while(ret != KErrNone) { failAt += 1 + failAt/30; test.Printf(_L("OOM step: %d\n"), failAt); __UHEAP_SETFAIL(RHeap::EDeterministic, failAt); __UHEAP_MARK; TRAP(ret, aTestFunction(ETrue)); __UHEAP_MARKEND; __UHEAP_RESET; if (ret != KErrNoMemory && ret != KErrNone) { test.Printf(_L("OOM test failed: %d\n"),ret); } if (!(ret == KErrNoMemory || ret == KErrNone) ) { TRAP_IGNORE(CleanupFilesL() ); } test(ret == KErrNoMemory || ret == KErrNone); } }
//================================================================================ //oomAsynchronousL //================================================================================ void oomAsynchronousL(TDesC& aSourceFile, TDesC& aTargetFile) { test.Printf(_L("starting OOM test\n")); //reserve space on cleanup stack for(TInt i=0; i<1000; i++) { CleanupStack::PushL(&i); } CleanupStack::Pop(1000); TInt ret=KErrNoMemory; TInt failAt=0; while (ret!=KErrNone) { failAt++; __UHEAP_SETFAIL(RHeap::EDeterministic,failAt); __UHEAP_MARK; TRAP(ret, asynchronousL(aSourceFile, aTargetFile)); if (ret!=KErrNone) { __UHEAP_MARKEND; } __UHEAP_RESET; test(ret==KErrNoMemory||ret==KErrNone); test.Printf(_L(".")); } test.Printf(_L("asynchronous OOM test complete\n")); }
void CPersistenceTests::OomTestL() { test.Next(_L("ReadLC OOM test")); CContactItem* cnt = iCntTestImpl.ReadLC(1, *iMatchAll); POPD(cnt); TInt ret = 0; for(TInt i=1; i < 2000; ++i) { __UHEAP_SETFAIL(RHeap::EDeterministic, i); __UHEAP_MARK; TRAP(ret, CContactItem* cnt = iCntTestImpl.ReadLC(1, *iMatchAll); POPD(cnt); ); __UHEAP_MARKEND; __UHEAP_RESET; if (ret == KErrNone) { break; } else if (ret != KErrNoMemory) { TESTVALUE(ret, KErrNoMemory); break; } if (!(i % 100)) { test.Printf(_L("."), i/100); } }
void DoOOMTestL() { TheAlarmTest.Test().Printf(_L("starting OOM test\n")); //reserve space on cleanup stack for(TInt i=0; i<1000; i++) { CleanupStack::PushL(&i); } CleanupStack::Pop(1000); TInt ret=KErrNoMemory; TInt failAt=0; while (ret!=KErrNone) { failAt++; __UHEAP_SETFAIL(RHeap::EDeterministic,failAt); __UHEAP_MARK; TRAP(ret, DoTestsL()); if (ret!=KErrNone) { __UHEAP_MARKEND; } __UHEAP_RESET; TheAlarmTest(ret==KErrNoMemory||ret==KErrNone, __LINE__); } }
/** @SYMTestCaseID UIF-errorstep-TestOOML @SYMPREQ @SYMTestCaseDesc Performs OOM tests. @SYMTestPriority High @SYMTestStatus Implemented @SYMTestActions The method tests CEikErrorResolver::ResolveError() unnder OOM condition. The method finds the number of handles open for the thread & process before performimg tests. Then checks the threads heap while running tests on CEikErrorResolver::ResolveError() for all the defined errors. On completion of these tests the number of handles open for the thread & process are checked. @SYMTestExpectedResults The number of handles open for the thread & process at start and end should be same. */ void CAppTest::TestOOML() { iOOMTesting = ETrue; TInt error=KErrNoMemory; iAppUi->INFO_PRINTF1(_L("starting the OOM testing loop...")); TInt fail(0); for(fail=1;error!=KErrNone;fail++) { TInt pHCountStart=0; TInt tHCountStart=0; RThread().HandleCount(pHCountStart,tHCountStart); __UHEAP_SETFAIL(RHeap::EDeterministic, fail); __UHEAP_MARK; // for OOM purposes, we test one of the errors texts only TRAP(error, TestResolveSingleErrL(KCDriveTest1Err, KCDriveTestErr1Text, KNullUid)); iAppUi->TEST(error == KErrNoMemory || error == KErrNone); __UHEAP_MARKEND; TInt pHCountEnd=0; TInt tHCountEnd=0; RThread().HandleCount(pHCountEnd,tHCountEnd); iAppUi->TEST(pHCountStart == pHCountEnd && tHCountStart == tHCountEnd); __UHEAP_RESET; } iAppUi->INFO_PRINTF2(_L("OOM loop finished after '%d' attempts"), fail-1); iOOMTesting = EFalse; }
/* Retrives the geo value within the entry in out of memory conditions @param aEntry1 Pointer to the stored entry @param aGeoValue @test */ TInt CTestCalInterimApiSuiteStepBase::OOMGeoValueL(CCalEntry* aEntry, CCalGeoValue*& aGeoValue) { TInt tryCount = 1; TInt err = KErrNone; for ( ;; ) { __UHEAP_SETFAIL(RHeap::EDeterministic, tryCount); TRAP(err, aGeoValue = aEntry->GeoValueL()); if ( err==KErrNone ) { __UHEAP_RESET; INFO_PRINTF1(_L("OOM testing of CCalEntry::GeoValueL Api is done")); break; } if ( err != KErrNoMemory ) { __UHEAP_RESET; SetTestStepResult(EFail); break; } tryCount++; __UHEAP_RESET; } return err; }
void CT_StartAppTestStep::TestStartApp9L() { INFO_PRINTF1(_L("Test to check the StartApp API with forced memory failures...")); CApaCommandLine* cmdLn=CApaCommandLine::NewLC(); TFileName filename; TThreadId threadId(0); TInt fail; _LIT(KLitExePath,"\\sys\\bin\\texe.exe"); TFullName exePath(KLitExePath); filename = SearchAndReturnCompleteFileName(exePath); cmdLn->SetExecutableNameL(filename); TInt ret = KErrNoMemory; //Without the fix for the Incident INC104463, the OOM test causes panic //KERN-EXEC 56. for(fail=1; ret == KErrNoMemory; fail++) { __UHEAP_SETFAIL(RHeap::EDeterministic, fail); __UHEAP_MARK; ret = iApaLsSession.StartApp(*cmdLn, threadId); __UHEAP_MARKEND; __UHEAP_RESET; TEST((ret==KErrNoMemory || ret==KErrNone)); if(ret == KErrNone) { TEST(threadId.Id() != 0); } } INFO_PRINTF3(_L("Iteration count is %d and the value of return is %d "),fail-1 ,ret); CleanupStack::PopAndDestroy(cmdLn); INFO_PRINTF1(KCompleted); }
void CCalOOMTest::TestFindInstancesL(const TDesC& aFindStartTime, const TDesC& aFindEndTime, CalCommon::TCalViewFilter aFilter) { test.Next(_L("OOM tests for FindInstanceL")); _LIT(KSearchText, "summary"); TCalTime findSt; findSt.SetTimeLocalL(TTime(aFindStartTime)); TCalTime findEnd; findEnd.SetTimeLocalL(TTime(aFindEndTime)); CalCommon::TCalTimeRange range(findSt, findEnd); RPointerArray<CCalInstance> instances; CCalInstanceView::TCalSearchParams params(KSearchText, CalCommon::EFoldedTextSearch); CCalInstanceView& view = iTestLib->SynCGetInstanceViewL(); TInt tryCount = 1; TInt err = 0; // OOM LOOP for ( ;; ) { RDebug::Printf("%d", tryCount); instances.ResetAndDestroy(); __UHEAP_SETFAIL(RHeap::EFailNext, tryCount); __UHEAP_MARK; TRAP(err, view.FindInstanceL(instances, aFilter, range, params)); if( instances.Count()>0 ) { instances.ResetAndDestroy(); //we are responsible for Cleanup of this array } __UHEAP_MARKEND; if ( err==KErrNone ) { __UHEAP_RESET; RDebug::Printf("Memory allocation testing for FindInstance is done"); break; } test(err == KErrNoMemory); __UHEAP_SETFAIL(RHeap::ENone, 0); tryCount++; } // OOM LOOP }
/** Verify CMMFPtrBuffer OOM * Use case: N/A * @test Req. under test PREQ 10 */ TVerdict CTestStep_MMF_BASECL_U_0154::DoTestStepL( void ) { TVerdict verdict = EPass; __MM_HEAP_MARK; CMMFPtrBuffer* ptrBuffer = NULL; TInt KMaxFailRate = 100000; TBool complete = EFalse; TBool nullAlloc = EFalse; TInt failCount; for (failCount=1; !complete && failCount<KMaxFailRate; ++failCount) { __UHEAP_SETFAIL(RHeap::EFailNext, failCount); TRAPD(err, ptrBuffer = CMMFPtrBuffer::NewL()); if (err == KErrNone) {//need to check if next alloc fails TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test if (testAlloc==NULL) { nullAlloc = ETrue; } else { User::Free(testAlloc); complete = ETrue; } //check a databuffer has been created if (!ptrBuffer) { verdict = EFail; complete = ETrue; } else { delete ptrBuffer; ptrBuffer = NULL; } } else if (err != KErrNoMemory) { verdict = EFail; // bad error code complete = ETrue; } } if ((failCount >= KMaxFailRate-1) || (!nullAlloc))verdict = EFail; __UHEAP_RESET; delete ptrBuffer; __MM_HEAP_MARKEND; return verdict ; }
void GetResolvedDllInfo_OOMTestL() { TInt processHandlesS = 0; TInt threadHandlesS = 0; TInt processHandlesE = 0; TInt threadHandlesE = 0; RThread().HandleCount(processHandlesS, threadHandlesS); CEComServer* ecomServer = CEComServer::NewLC(); TClientRequest clientReq; RArray<TUid> extendedInterfaces; CleanupClosePushL(extendedInterfaces); RImplInfoArray* implInfoArray = ecomServer->ListImplementationsL(KCExampleInterfaceUid,extendedInterfaces,clientReq); CleanupStack::PopAndDestroy(&extendedInterfaces); TEST(implInfoArray->Count() > 0); for(TInt count=1;;++count) { // Setting Heap failure for OOM test __UHEAP_SETFAIL(RHeap::EDeterministic, count); __UHEAP_MARK; TEntry dllInfo; TUid dtorIdKey; TClientRequest clntRq; CImplementationInformation* info = (*implInfoArray)[0]; TRAPD(err, ecomServer->GetResolvedDllInfoL(info->ImplementationUid(), dllInfo, dtorIdKey, clntRq)); if(err == KErrNoMemory) { __UHEAP_MARKEND; } else if(err == KErrNone) { __UHEAP_MARKEND; RDebug::Print(_L("The test succeeded at heap failure rate=%d.\n"), count); break; } else { __UHEAP_MARKEND; TEST2(err, KErrNone); } __UHEAP_RESET; } __UHEAP_RESET; //implInfoArray should be deleted! The caller takes the ownership. if (implInfoArray!=NULL) { implInfoArray->Close(); delete implInfoArray; } CleanupStack::PopAndDestroy(ecomServer); RThread().HandleCount(processHandlesE, threadHandlesE); TEST(processHandlesS == processHandlesE); TEST(threadHandlesS == threadHandlesE); }
/** @SYMTestCaseID SYSLIB-ECOM-CT-3714 @SYMTestCaseDesc Tests CEComServer::ListImplementationsL with customer resolver. @SYMTestPriority High @SYMTestActions Calls ListImplementationsL(TUid,TUid,const RExtendedInterfacesArray&,const TClientRequest&) with customer resolver. @SYMTestExpectedResults No OOM errors. @SYMDEF DEF111196 */ void ListImplementations_OOMTest1L() { TInt processHandlesS = 0; TInt threadHandlesS = 0; TInt processHandlesE = 0; TInt threadHandlesE = 0; RThread().HandleCount(processHandlesS, threadHandlesS); for(TInt count=1;;++count) { CEComServer* ecomServer = CEComServer::NewLC(); // Setting Heap failure for OOM test __UHEAP_SETFAIL(RHeap::EDeterministic, count); __UHEAP_MARK; TUid resolverUid = {0x10009DD0}; TClientRequest clientReq; RArray<TUid> extendedInterfaces; CleanupClosePushL(extendedInterfaces); RImplInfoArray* ifArray=NULL; TRAPD(err, ifArray = ecomServer->ListImplementationsL(KCExampleInterfaceUid,resolverUid,extendedInterfaces,clientReq)); CleanupStack::PopAndDestroy(&extendedInterfaces); if (ifArray!=NULL) { ifArray->Close(); delete ifArray; } if(err == KErrNoMemory) { CleanupStack::PopAndDestroy(ecomServer); __UHEAP_MARKEND; } else if(err == KErrNone) { CleanupStack::PopAndDestroy(ecomServer); __UHEAP_MARKEND; //implInfoArray should not be deleted! The caller does not take the ownership. RDebug::Print(_L("The test succeeded at heap failure rate=%d.\n"), count); break; } else { CleanupStack::PopAndDestroy(ecomServer); __UHEAP_MARKEND; TEST2(err, KErrNone); } __UHEAP_RESET; } __UHEAP_RESET; //CleanupStack::PopAndDestroy(ecomServer); RThread().HandleCount(processHandlesE, threadHandlesE); TEST(processHandlesS == processHandlesE); TEST(threadHandlesS == threadHandlesE); }
void CPlTransMgrTest::OutOfMemoryUpdateTestL() { TInt ret=KErrNoMemory; TInt failAt=0; iTestNo = 0; while (ret!=KErrNone) { ++iTestNo; //if (iTestNo == 790) // TInt i = 0; TInt cntID = AddAndCommitContactL(); iPersistLayer->TransactionManager().StartTransactionL(); failAt++; __UHEAP_SETFAIL(RHeap::EDeterministic,failAt); __UHEAP_MARK; TRAPD(err, UpdateContactL(cntID)); if (err==KErrNone) { TRAP(err, iPersistLayer->TransactionManager().CommitCurrentTransactionL(0)); if (err==KErrNone) { test.Next(_L("-> TEST SUCCESS - Contact committed during OOM Test")); __UHEAP_RESET; return; } } __UHEAP_RESET; if (err!=KErrNoMemory && err!=KErrNone) { test.Printf(_L("Non standard error: %d\n"),err); } if (err == KErrNoMemory) { iPersistLayer->TransactionManager().RollbackCurrentTransactionL(0); // Close the database to allow recovery iPersistLayer->ContactsFileL().Close(); iPersistLayer->ContactsFileL().RecoverL(nsPlTransMgr::KFilename); // Has the contact changed? if (!CheckChangedFieldL(cntID)) { test.Printf(_L(" ->Correct result - Update rollback during OOM - Updated Contact NOT Found... Step: %d \n\r"),failAt); } else { test.Printf(_L(" ->Error - Update rollback during OOM - Updated Contact Found... Step: %d \n\r"),failAt); User::Leave(KErrNotFound); } } } }
/** Verify CMMFDescriptorBuffer ReAllocation OOM * Use case: N/A * @test Req. under test REQ172.7.25 */ TVerdict CTestStep_MMF_BASECL_U_0012::DoTestStepL( void ) { TVerdict verdict = EPass; __MM_HEAP_MARK; CMMFDescriptorBuffer* dataBuffer = NULL; dataBuffer = CMMFDescriptorBuffer::NewL(); TInt KMaxFailRate = 100000; TBool complete = EFalse; TBool nullAlloc = EFalse; TInt failCount; for (failCount=1; !complete && failCount<KMaxFailRate; ++failCount) { __UHEAP_SETFAIL(RHeap::EFailNext, failCount); TRAPD(err, dataBuffer->ReAllocBufferL(KMMFTestBufferSize)); if (err == KErrNone) {//need to ckeck if next alloc fails TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test if (testAlloc==NULL) { nullAlloc = ETrue; } else { User::Free(testAlloc); complete = ETrue; } //check a databuffer has been created and it has the realloced size if ((!dataBuffer) || (dataBuffer->Data().MaxLength() != (TInt)KMMFTestBufferSize)) { verdict = EFail; complete = ETrue; } } else if (err != KErrNoMemory) { verdict = EFail; // bad error code complete = ETrue; } } if ((failCount >= KMaxFailRate-1) || (!nullAlloc)) verdict = EFail; __UHEAP_RESET; delete dataBuffer; __MM_HEAP_MARKEND; return verdict ; }
void CTestCase::AllocFailureSimulation (TBool aSwitchedOn) { if (aSwitchedOn) { __UHEAP_SETFAIL (iAllocFailureType, iAllocFailureRate); } else { __UHEAP_RESET; } }
TVerdict COomTestStep::ImplOomTestL() /** Runs the test step under OOM Conditions checking that each heap allocation is fail safe. */ { // Pre and Post test heap cell allocation counts TInt cellCountAfter = 0; TInt cellCountBefore = 0; // The loop tests each heap allocation under out of memory conditions to determine whether // the test framework cleans up correctly without leaking memory. // // The 'for' loop terminates as soon as any of the following events occur: // a) The pre and post heap cell counts mismatch signalling a memory leakage // b) Any leave with an error code other than 'KErrNoMemory' // c) All heap allocations have been tested and the test returns 'KErrNone' for (TInt testCount = 0; ; ++testCount) { __UHEAP_MARK; __UHEAP_SETFAIL(RHeap::EDeterministic, testCount+1); cellCountBefore = User::CountAllocCells(); TRAPD(err, ImplTestStepL()); cellCountAfter = User::CountAllocCells(); __UHEAP_MARKEND; INFO_PRINTF3(_L("OOM Test %d: Status = %d"),testCount,err); if (err == KErrNone) { INFO_PRINTF1(_L("OOM Test Finished")); break; } else if(err == KErrNoMemory) { if (cellCountBefore != cellCountAfter) { ERR_PRINTF2(_L("OOM Test Result: Failed - Memory leakage on iteration %d"), testCount); ERR_PRINTF2(_L("Pre-Test Heap Cell Count: %d"), cellCountBefore); ERR_PRINTF2(_L("Post-Test Heap Cell Count: %d"), cellCountAfter); SetTestStepResult(EFail); break; } } else { User::Leave(err); break; } } return TestStepResult(); }
/** @SYMTestCaseID SYSLIB-ECOM-CT-0756 @SYMTestCaseDesc OOM Test for create and delete of CBackUpNotifier @SYMTestPriority High @SYMTestActions Check for handle leak after deletion of object. @SYMTestExpectedResults The test must not fail. @SYMREQ REQ0000 */ LOCAL_C void OOMCreateDeleteTest() { test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0756 OOM CreateDeleteTest ")); TInt err; TInt failAt = 1; __UNUSED_VAR(failAt); CBackUpNotifierTest* theTest = NULL; do { __UHEAP_MARK; // find out the number of open handles TInt startProcessHandleCount; TInt startThreadHandleCount; RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); __UHEAP_SETFAIL(RHeap::EDeterministic, failAt++); TRAP(err, theTest = CBackUpNotifierTest::NewL()); __UHEAP_SETFAIL(RHeap::ENone, 0); delete theTest; theTest = NULL; // check that no handles have leaked TInt endProcessHandleCount; TInt endThreadHandleCount; RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); test(startProcessHandleCount == endProcessHandleCount); test(startThreadHandleCount == endThreadHandleCount); __UHEAP_MARKEND; } while(err == KErrNoMemory); test.Printf(_L("- Succeeded at heap failure rate of %i\n"), failAt); test(err == KErrNone); }