void TestServerPanic() { TRequestStatus status; test_KErrNone(TheSemaphore.CreateLocal(0)); RDebug::Printf("Main: start server"); RThread serverThread; test_KErrNone(serverThread.Create(_L("server"), ServerThread, 4096, NULL, NULL)); serverThread.Rendezvous(status); serverThread.Resume(); User::WaitForRequest(status); test_KErrNone(status.Int()); RDebug::Printf("Main: start client"); RProcess clientProcess; test_KErrNone(clientProcess.Create(KMyName, _L("client"))); clientProcess.Resume(); clientProcess.Logon(status); User::WaitForRequest(status); test_KErrNone(clientProcess.ExitReason()); test_Equal(EExitKill, clientProcess.ExitType()); RDebug::Printf("Main: kick server"); TheSemaphore.Signal(); RDebug::Printf("Main: wait for server to exit"); serverThread.Logon(status); User::WaitForRequest(status); test_KErrNone(serverThread.ExitReason()); test_Equal(EExitKill, serverThread.ExitType()); User::After(1); RDebug::Printf("Main: exit"); }
/** Initialises semaphores and call the tests */ void DoTests() { TInt r = 0; r = client.CreateLocal(0); TESTERROR(r); r = gSync.CreateLocal(0); TESTERROR(r); r = TheFs.SetSessionPath(gSessionPath); TESTERROR(r); r = TheFs.MkDirAll(gSessionPath); if (r != KErrNone && r != KErrAlreadyExists) { TESTERROR(r); } TheFs.ResourceCountMarkStart(); TRAP(r,CallTestsL()); if (r == KErrNone) TheFs.ResourceCountMarkEnd(); else { TESTERROR(r); } }
void CEraser::CreateL() // // Create new thread and wait for it to become ready // { iGoSignal.CreateLocal( 0 ); // initially blocked iWaitingSignal.CreateLocal( 0 ); // initially blocked iStop = EFalse; User::LeaveIfError( iThread.Create( _L("ERASER"), EraserThread, 2048, 2048, 65536, this ) ); test.Printf( _L("Eraser thread created\n") ); iThread.Resume(); test.Printf( _L("Waiting for thread to become ready\n") ); WaitForReady(); iWaitingSignal.Signal(); }
LOCAL_C void DoTestsL() { // Initialisation MainTest.Start(_L("@SYMTESTCaseID:PIM-T-CONCURRENT-0001 T_Concurrent")); // Create active scheduler (to run active objects) CActiveScheduler* scheduler = new (ELeave) CActiveScheduler(); CleanupStack::PushL(scheduler); CActiveScheduler::Install(scheduler); // Create main thread object, child thread and synchnising semaphore. sem.CreateLocal(0); CMainThread * ptr = CMainThread::NewL(); CleanupStack::PushL(ptr); ptr->LaunchChildThreadL(); // Run all the tests while (currentStep <= ETestsEnd) { switch(currentStep) { case ETestCreate: // create the db in shared mode and add a contact. ptr->TestCreateDatabaseL(); ptr->TestAddContactL(); break; case ETestOpen: // create the db in shared mode ptr->TestOpenDatabaseL(); ptr->TestAddContactL(); break; case ETestReplace: // create the db in shared mode ptr->TestReplaceDatabaseL(); ptr->TestAddContactL(); break; case ETestsEnd: break; default: break; } // end of switch // Run the child thread and let it access the shared session. ptr->ResumeChildThreadL(); sem.Wait(); ptr->CloseDatabaseSessionL(); currentStep++ ; } // end of while // Cleanup and close. sem.Close(); CleanupStack::PopAndDestroy(ptr); CleanupStack::PopAndDestroy(scheduler); }
void DoTestsL() { MainThreadCrS.CreateLocal(0); TheTest.Start(_L(" @SYMTestCaseID:PDS-EFM-CT-4058 Restore Query and Modification Response")); TestRestoreResponseL(); MainThreadCrS.Close(); }
GLDEF_C TInt E32Main() { RTest test(_L("T_SVRPINNING...main")); test.Title(); if (DPTest::Attributes() & DPTest::ERomPaging) test.Printf(_L("Rom paging supported\n")); if (DPTest::Attributes() & DPTest::ECodePaging) test.Printf(_L("Code paging supported\n")); if (DPTest::Attributes() & DPTest::EDataPaging) { test.Printf(_L("Data paging supported\n")); gDataPagingSupport = ETrue; } // Determine the data paging attribute. RProcess process; // Default to point to current process. gProcessPaged = process.DefaultDataPaged(); test.Printf(_L("Process data paged %x\n"), gProcessPaged); test.Start(_L("Test IPC message arguments pinning")); test_KErrNone(HAL::Get(HAL::EMemoryPageSize, gPageSize)); gPageMask = gPageSize - 1; test_Equal(KPageSize, gPageSize); // Disable JIT as we are testing panics and don't want the emulator to hang. TBool justInTime = User::JustInTime(); User::SetJustInTime(EFalse); TBool exitFailure = EFalse; for ( gServerPinningState = EServerDefault; gServerPinningState < EServerSetPinningTooLate && !exitFailure; gServerPinningState++) { // Create the server with the specified pinning mode. switch (gServerPinningState) { case EServerDefault : test.Next(_L("Test server with default pinning policy")); break; case EServerPinning : test.Next(_L("Test server with pinning policy")); break; case EServerNotPinning : test.Next(_L("Test server with not pinning policy")); break; } test_KErrNone(gSem.CreateLocal(0)); test_KErrNone(gSem1.CreateLocal(0)); // Create the server thread it needs to have a unpaged stack and heap. TThreadCreateInfo serverInfo(_L("Server Thread"), ServerThread, KDefaultStackSize, (TAny*)gServerPinningState); serverInfo.SetPaging(TThreadCreateInfo::EUnpaged); serverInfo.SetCreateHeap(KHeapMinSize, KHeapMaxSize); RThread serverThread; test_KErrNone(serverThread.Create(serverInfo)); TRequestStatus serverStat; serverThread.Logon(serverStat); serverThread.Resume(); // Wait for the server to start and then create a session to it. gSem.Wait(); RSession session; test_KErrNone(session.PublicCreateSession(_L("CTestServer"),5)); for ( TUint clientTest = CTestSession::ETestRdPinAll; clientTest <= CTestSession::ETestPinDefault && !exitFailure; clientTest++) { // Create the client thread it needs to have a paged stack and heap. TThreadCreateInfo clientInfo(_L("Client Thread"), ClientThread, 10 * gPageSize, (TAny*)clientTest); clientInfo.SetPaging(TThreadCreateInfo::EPaged); clientInfo.SetCreateHeap(KHeapMinSize, KHeapMaxSize); RThread clientThread; test_KErrNone(clientThread.Create(clientInfo)); TRequestStatus clientStat; clientThread.Logon(clientStat); clientThread.Resume(); // Wait for the client thread to end. User::WaitForRequest(clientStat); // If all the descriptor arguments were not pinned then the client // thread should have been panicked. TBool expectPanic = (clientTest == CTestSession::ETestRdPinAll || clientTest == CTestSession::ETestWrPinAll || clientTest == CTestSession::ETestPinOOM )? 0 : 1; expectPanic = !UpdateExpected(!expectPanic); TInt exitReason = clientThread.ExitReason(); TInt exitType = clientThread.ExitType(); if (expectPanic) { if (exitType != EExitPanic || exitReason != EIllegalFunctionForRealtimeThread || clientThread.ExitCategory() != _L("KERN-EXEC")) { test.Printf(_L("Thread didn't panic as expected\n")); exitFailure = ETrue; } } else { if (exitType != EExitKill || exitReason != KErrNone) { test.Printf(_L("Thread didn't exit gracefully as expected\n")); exitFailure = ETrue; } } test(!exitFailure); CLOSE_AND_WAIT(clientThread); } test.Next(_L("Test client sending message to closed server")); TThreadCreateInfo clientInfo(_L("Client Thread"), ClientThread, 10 * gPageSize, (TAny*)CTestSession::ETestDeadServer); clientInfo.SetPaging(TThreadCreateInfo::EPaged); clientInfo.SetCreateHeap(KHeapMinSize, KHeapMaxSize); RThread clientThread; test_KErrNone(clientThread.Create(clientInfo)); TRequestStatus clientStat; clientThread.Logon(clientStat); clientThread.Resume(); gSem.Wait(); // Signal to stop ActiveScheduler and wait for server to stop. session.PublicSendReceive(CTestSession::EStop, TIpcArgs()); session.Close(); User::WaitForRequest(serverStat); if (serverThread.ExitType() != EExitKill) { test.Printf(_L("!!Server thread did something bizarre %d\n"), serverThread.ExitReason()); } gSem1.Signal(); User::WaitForRequest(clientStat); test_Equal(EExitKill, clientThread.ExitType()); test_Equal(KErrServerTerminated, clientThread.ExitReason()); CLOSE_AND_WAIT(clientThread); CLOSE_AND_WAIT(serverThread); CLOSE_AND_WAIT(gSem); CLOSE_AND_WAIT(gSem1); } test.Next(_L("Test server setting pinning policy after server started")); RThread serverThread; test_KErrNone(serverThread.Create(_L("Server Thread"),ServerThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize, (TAny*)gServerPinningState)); TRequestStatus serverStat; serverThread.Logon(serverStat); serverThread.Resume(); // The server should have panicked with E32USER-CBase 106. User::WaitForRequest(serverStat); TInt exitReason = serverThread.ExitReason(); TInt exitType = serverThread.ExitType(); test_Equal(EExitPanic, exitType); test_Equal(ECServer2InvalidSetPin, exitReason); if (_L("E32USER-CBase") != serverThread.ExitCategory()) test(0); CLOSE_AND_WAIT(serverThread); test.End(); // Set JIT back to original state. User::SetJustInTime(justInTime); return (KErrNone); }
void* SemaphoreCreate(int Init) { RSemaphore p; p.CreateLocal(Init); return (void *)p.Handle(); }
// start run a test case void CTestExecutor::RunTestCaseL() { RSemaphore smphF; smphF.CreateLocal(0); RSemaphore smphN; smphN.CreateLocal(0); RArray<RThread> notiThreads; // list of handles of notification threads RPointerArray<CTimerLogger> loggerList; TUint16 count = 0; TUint16 option = iTestSetting.iOption; while (count < iTestSetting.iNumCli) { test(count < 16); iTestSetting.iOption = (TUint16)(option + count); // Put Thread ID in option TThreadParam param; param.iSetting = iTestSetting; param.iSmphFT = &smphF; param.iSmphNT = &smphN; TFileName logName; logName.FillZ(); if (gPerfMeasure) { logName.Append(gLogFilePath); if (iTestSetting.iNumCli == 1) logName.Append(_L("SingleClient")); else logName.AppendFormat(_L("MultiClient%02d"), count); logName.Append(gLogPostFix); } CTimerLogger* logger = CTimerLogger::NewL(logName); CleanupStack::PushL(logger); param.iLogger = logger; param.iLoggerArray = NULL; TUint operation = *iTestSetting.iOperationList; TBool numFilesVaries = EFalse; if (operation == EOpManyFiles || operation == EOpManyChanges || operation == EOpMixed) { numFilesVaries = ETrue; } logger->LogSettingDescription(iTestSetting.iNumFiles, iTestSetting.iNumCli, iTestSetting.iOption, numFilesVaries); loggerList.AppendL(logger); TBuf<20> threadName; threadName.AppendFormat(_L("NotificationThread%02d"), count); RThread notifyOp; notifyOp.Create(threadName, NotificationOperationThread, KDefaultStackSize, KMinHeapSize, KMaxHeapSize, ¶m); notiThreads.AppendL(notifyOp); notifyOp.Resume(); smphF.Wait(); // Wait for the parameters being properly passed CleanupStack::Pop(logger); count++; } gNotiThreads = notiThreads; if (iTestSetting.iNumCli == 0) // no notification { TFileName logName; logName.Append(gLogFilePath); logName.Append(_L("SingleClient")); logName.Append(gLogPostFix); CTimerLogger* logger = CTimerLogger::NewL(logName); CleanupStack::PushL(logger); logger->LogSettingDescription(iTestSetting.iNumFiles, iTestSetting.iNumCli, iTestSetting.iOption); loggerList.AppendL(logger); CleanupStack::Pop(logger); } TThreadParam paramFileOp; paramFileOp.iSetting = iTestSetting; paramFileOp.iSmphFT = &smphF; paramFileOp.iSmphNT = &smphN; paramFileOp.iLogger = NULL; paramFileOp.iLoggerArray = &loggerList; RThread fileOp; fileOp.Create(_L("FileOperationThread"), FileOperationThread, KDefaultStackSize, KMinHeapSize, KMaxHeapSize, ¶mFileOp); gFileThread = fileOp; fileOp.Resume(); TInt err; TRequestStatus status; fileOp.Logon(status); User::WaitForRequest(status); err = fileOp.ExitReason(); test(err == KErrNone); count = 0; while(count < notiThreads.Count()) { notiThreads[count].Logon(status); User::WaitForRequest(status); err = notiThreads[count].ExitReason(); test(err == KErrNone); count++; } CLOSE_AND_WAIT(fileOp); count = 0; while(count < notiThreads.Count()) { RThread thread = notiThreads[count]; CLOSE_AND_WAIT(thread); count++; } for (TInt i = 0; i < loggerList.Count(); i++) { loggerList[i]->LogAndPrint(_L("====================================================")); } smphN.Close(); smphF.Close(); loggerList.ResetAndDestroy(); loggerList.Close(); notiThreads.Reset(); notiThreads.Close(); }