示例#1
0
void TestServerApi(TInt aFunctionNumber,
			TInt aTestType,TInt aArgCount, TExitDetails& aExitDetails)
	{
    
    TTestInfo testInfo;
	testInfo.iFunction = aFunctionNumber;
	testInfo.iType = aTestType;
	testInfo.iArgCount = aArgCount;
    
    RThread thread;	
    _LIT(KThreadName,"FuzzerThread" );
	TInt err = thread.Create(KThreadName,&FuzzServerL, KDefaultStackSize, NULL,&testInfo);
	TEST2(err, KErrNone);
	
	TRequestStatus threadStat;
	thread.Logon(threadStat);
	
	TBool jit = User::JustInTime();
	User::SetJustInTime(EFalse);
	
	thread.Resume();
	
	User::WaitForRequest(threadStat);
	
	User::SetJustInTime(jit);

	aExitDetails.iCategory = thread.ExitCategory();
	aExitDetails.iReason = thread.ExitReason();
	aExitDetails.iExitType = thread.ExitType();
	
	thread.Close();

	}
示例#2
0
GLDEF_C TInt E32Main()
{
    test.Title();
    test.Start(_L("Waiting..."));

    RUndertaker u;
    TInt r=u.Create();
    test(r==KErrNone);
    //to avoid RVCT4 warning of unreachable statement.
    volatile TInt forever = 0;
    while(forever)
    {
        TInt h;
        TRequestStatus s;
        r=u.Logon(s,h);
        test(r==KErrNone);
        User::WaitForRequest(s);
        RThread t;
        t.SetHandle(h);
        TBuf8<128> b;
        t.Context(b);
        TInt *pR=(TInt*)b.Ptr();
        TFullName tFullName = t.FullName();
        TExitCategoryName tExitCategory = t.ExitCategory();
        test.Printf(_L("Thread %S Exit %d %S %d\n"),&tFullName,t.ExitType(),&tExitCategory,t.ExitReason());
        test.Printf(_L("r0 =%08x r1 =%08x r2 =%08x r3 =%08x\n"),pR[0],pR[1],pR[2],pR[3]);
        test.Printf(_L("r4 =%08x r5 =%08x r6 =%08x r7 =%08x\n"),pR[4],pR[5],pR[6],pR[7]);
        test.Printf(_L("r8 =%08x r9 =%08x r10=%08x r11=%08x\n"),pR[8],pR[9],pR[10],pR[11]);
        test.Printf(_L("r12=%08x r13=%08x r14=%08x r15=%08x\n"),pR[12],pR[13],pR[14],pR[15]);
        test.Printf(_L("cps=%08x dac=%08x\n"),pR[16],pR[17]);
        t.Close();
    }
    return 0;
}
/**
Test framework to check for panic scenarios
It requires to create a separate thread so we can check the panic category and code.
*/
TInt StartSwpInvalidListInThreadL(CSsmValidSwpListTest* aSsmValidSwpListTest)
	{
	RThread thread;
	// Give each thread a unique name to avoid KErrAlreadyExists error on thread creation
	_LIT(KThreadNamePrefix, "SsmTestThread");

	RBuf threadName;
	CleanupClosePushL(threadName);
	threadName.CreateL(KThreadNamePrefix().Length() + 6); // 6 digit thread number
	threadName = KThreadNamePrefix;
	threadName.AppendNumFixedWidth(aSsmValidSwpListTest->Function(), EDecimal, 6);
	const TInt KMinHeapSize = 0xc800; // 50k - NOTE just an arbitrary value, please feel free to change it
	const TInt KMaxHeapSize = 0x19000; // 100k - NOTE just an arbitrary value, please feel free to change it
	User::LeaveIfError(thread.Create(threadName, ThreadStartSwpInvalidListFn, KDefaultStackSize, KMinHeapSize, KMaxHeapSize, aSsmValidSwpListTest));
	CleanupStack::PopAndDestroy(&threadName);
	TRequestStatus status;
	thread.Logon(status);
	TBool jit =	User::JustInTime();
	User::SetJustInTime(EFalse);
	thread.Resume();
	User::WaitForRequest(status);
	
	// always expecting a state transition engine panic
	TExitCategoryName category = thread.ExitCategory();
	if (category.Compare(KPanicSysStateMgr) != 0)
		{
		User::Leave(KTestInvalidPanicCategory);
		}
	const TInt exitReason = thread.ExitReason();
	thread.Close();
	User::SetJustInTime(jit);

	// return the exit reason for the caller to verify the expected panic value
	return exitReason;
	}
TExitDetails LaunchTestThread(const TDesC& aThreadName, TestFunction aFunction)
{
    RThread thread;
    thread.Create(aThreadName, &TestFunctionLauncher, KDefaultStackSize, NULL, (TAny*)aFunction);

    TRequestStatus threadStat;
    thread.Logon(threadStat);

    TBool jit = User::JustInTime();
    User::SetJustInTime(EFalse);

    thread.Resume();
    User::WaitForRequest(threadStat);

    User::SetJustInTime(jit);

    TExitDetails exitDetails;
    exitDetails.iCategory = thread.ExitCategory();
    exitDetails.iReason = thread.ExitReason();
    exitDetails.iExitType = thread.ExitType();

    thread.Close();

    return exitDetails;
}
示例#5
0
LOCAL_D void TestSelfSuspend(TOwnerType anOwnerType)
//
// Test running a thread that suspends itself.  This activity has 
// deadlocked the Emulator in the past
//
	{

	RThread suspendThread;
	TInt r;
	TRequestStatus s;
	TInt jit=User::JustInTime();
	test.Start(_L("Test running a thread which suspends itself"));
	test.Next(_L("Create the thread"));
	r=suspendThread.Create(KNullDesC,SuspendThread,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)NULL,anOwnerType);
	test(r==KErrNone);
	suspendThread.Logon(s);
	suspendThread.Resume();
	test.Next(_L("Wait a second"));
	User::After(1000000);
	User::SetJustInTime(EFalse);
	suspendThread.Panic(_L("FEDCBA9876543210fedcba"),999);
	User::WaitForRequest(s);
	User::SetJustInTime(jit);
	test(suspendThread.ExitType()==EExitPanic);
	test(suspendThread.ExitReason()==999);
	test(suspendThread.ExitCategory()==_L("FEDCBA9876543210"));
	CLOSE_AND_WAIT(suspendThread);
	test.End();
	}
示例#6
0
void CheckExit(TInt aThreadNum, RThread aThread)
	{
	TInt exitType=aThread.ExitType();
	TInt exitReason=aThread.ExitReason();
	TBuf<32> exitCat=aThread.ExitCategory();
	test.Printf(_L("Thread %d: %d,%d,%S\n"),aThreadNum,exitType,exitReason,&exitCat);
	test(exitType==EExitKill);
	test(exitReason==KErrNone);
	}
示例#7
0
void CTestList::SelectedL(TInt aIndex)
{
#if USE_PROCESS
    TThreadParams params;
    params.iIndex=aIndex;
    TName name;
    name.Format(_L("TimeTest-%x"),iCount++);
    params.iGroupId=Client()->iGroup->GroupWin()->Identifier();
    User::LeaveIfError(iTimeTest.Create(name,TimeThread,KDefaultStackSize*2,KHeapSize,KHeapSize,&params,EOwnerThread));
    TRequestStatus status;
    iTimeTest.Logon(status);
    __PROFILE_RESET(8);
    iTimeTest.Resume();
    User::WaitForRequest(status);
#else
    TThreadParams params;
    params.iIndex=aIndex;
    TimeThread(&params);
#endif
    TBuf<64> buf;
    TBuf<64> buf2;
    TBuf<64> buf3;
    CResultDialog *dialog=new(ELeave) CResultDialog(Client()->iGroup, iGc);
    dialog->ConstructLD();
#if USE_PROCESS
    if (status.Int()==KErrNone)
    {
#endif
#if !defined(__PROFILING__)
        buf=_L("Profiling information not available");
#else
        TProfile profile[6];
        __PROFILE_DISPLAY(6);
        for (TInt index=1; index<6; index++)
            AppendProfileNum(buf2,profile[index].iTime);
        for (TInt index2=1; index2<6; index2++)
            AppendProfileCount(buf3,profile[index2].iCount);
        buf.Format(_L("Time=%d.%2d"),profile[0].iTime/1000000,(profile[0].iTime%1000000)/10000);
#endif
        dialog->SetTitle(buf);
#if USE_PROCESS
    }
    else
    {
        dialog->SetTitle(_L("Error in test"));
        buf.Format(_L("Error=%d"),status.Int());
        buf2=iTimeTest.ExitCategory();
    }
#endif
    dialog->SetLine1(buf2);
    dialog->SetLine2(buf3);
    dialog->SetNumButtons(1);
    dialog->SetButtonText(0,_L("Okay"));
    if (dialog->Display()!=0)
        Panic(0);
}
LOCAL_C void RunTestThreadL()
	{
	__UHEAP_MARK;

	CopyPluginsL();

	_LIT(KThreadName, "RoguePluginTest");

	TBool jit = User::JustInTime();
	User::SetJustInTime(EFalse);

	TheTest.Start(KTestTitle);

	// Save the console because the created thread must use its own
	// console.
	CConsoleBase* savedConsole = TheTest.Console();

	RThread tt;
	TInt err = tt.Create(KThreadName, &ThreadFunc, KDefaultStackSize,
		KMinHeapSize, 0x100000, 0);
	User::LeaveIfError(err);

	TRequestStatus status;
	tt.Logon(status);
	tt.Resume();

	User::WaitForRequest(status);

	// restore console
	TheTest.SetConsole(savedConsole);

	TExitCategoryName exitcategory = tt.ExitCategory();
	TExitType exittype = tt.ExitType();
	TInt exitReason = tt.ExitReason();
	tt.Close();

	TheTest.Printf(_L("Thread exit type %d, reason %d, category %S"), exittype, exitReason, &exitcategory);

	User::SetJustInTime(jit);
	DeleteTestPlugin();

	// Check if tt thread passes this checkpoint
	TheTest(correctTypeCastPassed);

	// Check if tt thread die of KERN-EXEC.
	_LIT(KKernExec, "KERN-EXEC");
	TheTest(exitcategory.CompareF(KKernExec) == 0);

	TheTest.End();
	TheTest.Close();

	__UHEAP_MARKEND;
	}
示例#9
0
TInt ThreadFunc(TAny* anArgument)
	{
	CSharedData* mySharedData = reinterpret_cast<CSharedData*> (anArgument);
	
	RUndertaker u;
	u.Create();
	
	TRequestStatus status;
	TInt deadThread;
	
	TBool clientWaiting = ETrue;
	
	FOREVER
		{
		status = KRequestPending;
		u.Logon(status,deadThread);
		// wait for the next thread to die.
	
		if (clientWaiting)
			{
			// rendezvous with the client so that they know we're ready.
			// This guarantees that we will catch at least the first panic to 
			// occur (as long as we aren't closed before kernel tells us.
			RThread::Rendezvous(KErrNone);
			clientWaiting = EFalse;
			}

		User::WaitForRequest(status);
		// until we get back around to the top we are missing notifications now.
		// being high priority helps us, but still...
		// deal with this QUICKLY


		// get handle to the dead thread (this has already been marked for us in 
		// the kernel)
		RThread t;
		t.SetHandle(deadThread);
	
		if (t.ExitType() == EExitPanic)
			{
			// the other ways threads can die are uninteresting
			TTime now;
			now.UniversalTime();
			
			TThreadPanicDetails* tpd = new TThreadPanicDetails (t.Name(),
				t.ExitReason(),t.ExitCategory(),now);
			
			mySharedData->iPanicDetails.AppendL(tpd);
			}
		t.Close();
		}
	}
示例#10
0
void CSystemTestBase::HandleThreadExitL(RThread& aThread)
	{
	TExitType exitType=aThread.ExitType();
	if (exitType==EExitPanic)
		{
		CActiveScheduler::Stop();
		iExitReason = aThread.ExitReason();
		iExitCategory = aThread.ExitCategory();
		TBuf<100> iName(aThread.FullName());
		iLogger.WriteFormat(KPanicText, &iName, iExitReason, &iExitCategory);
		User::Panic(iExitCategory,iExitReason);
		}
	}
示例#11
0
/**
   @SYMTestCaseID APPFWK-APPARC-0071
 
   @SYMDEF PDEF100072 -- CApaWindowGroupName::SetAppUid() and FindByAppUid panic
 
   @SYMTestCaseDesc Test Launching of an application with unprotected application UID
  
   @SYMTestPriority High 
 
   @SYMTestStatus Implemented
  
   @SYMTestActions Prepare command line information to start an application using
   CApaCommandLine Apis.Call RApaLsSession::StartApp() to start an
   application defined by the command line information.\n
   Test the launching of application for following scenario:\n
   When Application specified by command line has unprotected application UID(negative uid).\n
   API Calls:\n	
   RApaLsSession::StartApp(const CApaCommandLine &aCommandLine, TThreadId &aThreadId);\n
  
   @SYMTestExpectedResults The test checks whether the thread has terminated with the exit reason KTUnProtectedAppTestPassed
 */
void CT_StartAppTestStep::TestStartApp8L()
	{
	INFO_PRINTF1(_L("Checking launching of an application which has unprotected UID"));
	CApaCommandLine* cmdLine=CApaCommandLine::NewLC();
	TFileName filename;
	_LIT(KAppFileName, "z:\\sys\\bin\\UnProctectedUidApp.exe");
	TFullName exePath(KAppFileName);
	filename = SearchAndReturnCompleteFileName(exePath);
	cmdLine->SetExecutableNameL(filename);
	
	TThreadId appThreadId(0U);
	TInt ret = iApaLsSession.StartApp(*cmdLine, appThreadId);
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupStack::PopAndDestroy(cmdLine); // cmdLine
	
	RThread appThread;
	User::LeaveIfError(appThread.Open(appThreadId));
	
	TRequestStatus logonRequestStatus;
	appThread.Logon(logonRequestStatus);

	// wait for UnProctectedUidApp.exe to terminate
	INFO_PRINTF1(_L("Waiting for application to terminate..."));
	User::WaitForRequest(logonRequestStatus);

	const TExitType exitType = appThread.ExitType();
	const TInt exitReason = appThread.ExitReason();
	TExitCategoryName categoryName = appThread.ExitCategory();
	appThread.Close();

	TBuf<50> msg;
	if (exitType == EExitPanic)
		{
		_LIT(KAppPanicInfo, "Application panic: %S %d");
		msg.Format(KAppPanicInfo, &categoryName, exitReason);
		}
	else
		{
		_LIT(KAppExitInfo, "Application exited with code %d");
		msg.Format(KAppExitInfo, exitReason);
		}
	INFO_PRINTF1(msg);

	TEST(logonRequestStatus == KTUnProtectedAppTestPassed);
	TEST(exitType == EExitKill);
	TEST(exitReason == KTUnProtectedAppTestPassed);
	INFO_PRINTF1(KCompleted);
	}
示例#12
0
static void ConfirmPanicReason(RThread aThread, TInt aExpectedReason)
/**
	Confirm that the supplied thread was panicked with KKmsClientPanicCat
	category and the supplied reason.

	@param	aThread			Thread whcih should have been panicked with the supplied reason.
	@param	aExpectedReason	Reason with which thread should have been panicked.
 */
	{
	TExitCategoryName exitCat = aThread.ExitCategory();
	test.Printf(_L("thread exit with type=%d, cat=\"%S\", reason=%d\n"), aThread.ExitType(), &exitCat, aThread.ExitReason());
	test(aThread.ExitType() == EExitPanic);
	test(exitCat == KKmsClientPanicCat);
	test(aThread.ExitReason() == aExpectedReason);
	}
示例#13
0
void LogOnPanicL(RThread& aTestThread)	
	{
	CTestScheduler* as = new(ELeave) CTestScheduler;
	CleanupStack::PushL(as);
	if (!as)
		{
		User::Panic(_L("Failed to create active scheduler"),KErrNoMemory);
		}
	CActiveScheduler::Install(as); // Install active scheduler
		
	// Initialise Comms, required in a minimal console environment
	CHTTPTestUtils::InitCommsL();

	// Force a connection to be held open keep NT RAS connected...
	CHTTPTestUtils::HoldOpenConnectionL();
	
	// Create the test engine
	CHttpTestEngine* engine=NULL;
	TRAPD(err,engine = CHttpTestEngine::NewL(KHttpTestTitle(), EFalse));
	if (err != KErrNone)
		{
		User::Panic(_L("T_HTTP_ENG"), err);
		}
	CleanupStack::PushL(engine);
	
	// Create log message
	TExitCategoryName panicName = aTestThread.ExitCategory();
	TInt panicNumber = aTestThread.ExitReason();
	HBufC* logMessage = HBufC::NewLC(KRtestFailureLabel().Length() + 
								   panicName.Length() +	
								   KMaxIntDesLen);
	TPtr logMessagePtr = logMessage->Des();
	logMessagePtr.Format(KRtestFailureLabel, &panicName, panicNumber);
			
	engine->Utils().LogIt(logMessagePtr);
	
	// Panic here so that nothing else is written to the log file
	User::Panic(panicName, panicNumber);
	
	// The code below provided for completenes, but should never be reached
	
	// Release the held open connection
	CHTTPTestUtils::ReleaseConnectionL();	
	
	CleanupStack::PopAndDestroy(3, as); //as, engine, logMessage
	}
示例#14
0
void DoTestThreadCpuTime3(TAny* aParam, TExitType aExpectedExitType, TInt aExpectedExitReason)
	{
	RThread thread;
	FailIfError(thread.Create(_L("TestThread"), ThreadFunction2, 1024, NULL, aParam));
	thread.Resume();
	TRequestStatus status;
	thread.Logon(status);
	User::WaitForRequest(status);

	TExitCategoryName exitCat = thread.ExitCategory();
	test.Printf(_L("Thread exit with type == %d, reason == %d, cat == %S\n"),
				thread.ExitType(), thread.ExitReason(), &exitCat);
	
	test(thread.ExitType() == aExpectedExitType);
	test(thread.ExitReason() == aExpectedExitReason);
	CLOSE_AND_WAIT(thread);
	}
示例#15
0
//Panic test.
//PanicTest function will create a new thread - panic thread, giving it a pointer to the function which has to
//be executed and the expectation is that the function will panic and kill the panic thread.
//PanicTest function will check the panic thread exit code, exit category and the panic code.
void PanicTest(TFunctor& aFunctor, TExitType aExpectedExitType, const TDesC& aExpectedCategory, TInt aExpectedPanicCode)
	{
	RThread thread;
	_LIT(KThreadName,"OsLayerPanicThread");
	TEST2(thread.Create(KThreadName, &ThreadFunc, 0x2000, 0x1000, 0x10000, (void*)&aFunctor, EOwnerThread), KErrNone);
	
	TRequestStatus status;
	thread.Logon(status);
	TEST2(status.Int(), KRequestPending);
	thread.Resume();
	User::WaitForRequest(status);
	User::SetJustInTime(ETrue);	// enable debugger panic handling

	TEST2(thread.ExitType(), aExpectedExitType);
	TEST(thread.ExitCategory() == aExpectedCategory);
	TEST2(thread.ExitReason(), aExpectedPanicCode);
	
	CLOSE_AND_WAIT(thread);
	}
void CCmnStateTest::StartThread(TInt aOption)
	{
	RThread thread;
	TRequestStatus stat;
	TBuf<32> threadNameBuf;
	// Give each thread a unique name to avoid KErrAlreadyExists error on thread creation
	_LIT(KThreadNameFormat, "CCmnStateTest%d");
	threadNameBuf.Format(KThreadNameFormat, aOption);
	TInt threadCreationVal = thread.Create(threadNameBuf,PanicTestThread,KDefaultStackSize,0x2000,0x20000,(TAny*)aOption);
	TEST(threadCreationVal==KErrNone);	

	TRequestStatus status;
	thread.Logon(status);
	TBool jit =	User::JustInTime();
	User::SetJustInTime(EFalse);
	thread.Resume();
	User::WaitForRequest(status);

	// we are always expecting the same panic category KPanicSsmCmn only in debug (doesn't panic in release -> hw testing)
	TExitCategoryName category = thread.ExitCategory();
#ifdef __WINS__
	TEST(category.Compare(KPanicSsmCmn) == 0);
	INFO_PRINTF4(_L("  *** Case %d: Panic ExitCategory is %S (expected was %S)"), aOption, &category, &KPanicSsmCmn);
#else
	TEST(category.Compare(_L("Kill")) == 0);
	INFO_PRINTF2(_L("  *** category = %S ***"),&category);
#endif	
	
	// we are always expecting the same panic reason in the format ECmnStateMaxValueX (doesn't panic in release -> hw testing)
	const TInt exitReason = thread.ExitReason();
#ifdef __WINS__
	TEST(exitReason >= ECmnStateMaxValue1);
	TEST(exitReason <= ECmnStateMaxValue4);
	INFO_PRINTF5(_L("  *** Case %d: Panic reason is %d (expected was in range [%d, %d]"), aOption, exitReason, ECmnStateMaxValue1, ECmnStateMaxValue4);
#else
	TEST(exitReason == KErrNone);
#endif	
	thread.Close();
	User::SetJustInTime(jit);
	}
GLDEF_C TInt E32Main()
    {
#ifdef __WINS__1
    RChunk heapc;
    
    TInt err=heapc.OpenGlobal(_L("jaikusettings_heap"), ETrue);
    if (err!=KErrNone) {
    	return CSensorRunner::RunSensorsInThread(0);
    }
	RThread thread;
	TInt heap=*(TInt*)heapc.Base();
	heapc.Close();
	err=thread.Create(_L("context_log2"), 
		&CSensorRunner::RunSensorsInThread, // thread's main function
		20*1024, /* stack */
		heap, /* min heap */
		heap, /* max heap */
		0,
		EOwnerProcess);
	if (err!=KErrNone) return err;
	thread.SetPriority(EPriorityNormal);
	TRequestStatus s;
	thread.Logon(s);
	thread.Resume();
	User::WaitForRequest(s);
	TExitCategoryName n=thread.ExitCategory();
	TInt reason=thread.ExitReason();
	TExitType exittype=thread.ExitType();
	thread.Close();
	if (exittype==EExitPanic) {
		User::Panic( n, reason);
	}
	return reason;
#else
    SwitchToBetterHeap(KHeap);

    return CSensorRunner::RunSensorsInThread(0);
#endif
}
示例#18
0
void RunTestInThread(TThreadFunction aFn, TAny* aParameter, const TDesC* aPanicCat, TInt aExitCode)
	{
	RThread t;
	TInt r=t.Create(KNullDesC(),aFn,0x2000,NULL,aParameter);
	test(r==KErrNone);
	TRequestStatus s;
	t.Logon(s);
	t.Resume();
	User::WaitForRequest(s);
	if (aPanicCat)
		{
		test(t.ExitType()==EExitPanic);
		test(t.ExitCategory()==*aPanicCat);
		test(t.ExitReason()==aExitCode);
		}
	else
		{
		test(t.ExitType()==EExitKill);
		test(t.ExitReason()==aExitCode);
		}
	CLOSE_AND_WAIT(t);
	}
void CSenUnderTakerWaiter::RunL()
    {
    if(iStatus == KErrDied)
        {
        RThread th;
        th.SetHandle(iDyingThreadNumber);
        TFullName name = th.FullName();
        TExitType type = th.ExitType();

        
        if(iDispatcherThreadID == th.Id())
            {
            //Notifies client that thread is died. Client has to restart the 
            //connection here.In this case client has to create new SC object.
            if(type == EExitKill)
                {
                if(iSenServiceConnectionImpl)
                    {
                    iSenServiceConnectionImpl->iErrorNumber = EExitKill;
                    iSenServiceConnectionImpl->iTxnId = -1;    
                    iSenServiceConnectionImpl->HandleMessageFromChildAOL(iStatus.Int());
                    }
                }
            else    // panic
                {
                TExitCategoryName categ = th.ExitCategory();
                if(iSenServiceConnectionImpl)
                    {
                    iSenServiceConnectionImpl->iErrorNumber = EExitPanic;
                    iSenServiceConnectionImpl->iTxnId = -1;
                    iSenServiceConnectionImpl->HandleMessageFromChildAOL(iStatus.Int());
                    }
                }
            }
        th.Close();
        StartWaiter();
        }           
    }
示例#20
0
void CCmdUndertaker::ProcessHandle(TInt aDeadThreadHandle)
	{
	RThread deadThread;
	deadThread.SetHandle(aDeadThreadHandle);
	TFullName name(deadThread.FullName());
	TExitType type = deadThread.ExitType();
	if (type != EExitKill || deadThread.ExitReason() != 0 || iAll)
		{
		Write(_L("Thread "));
		Write(name);
		Printf(_L(" (tid=%d) "), (TUint)deadThread.Id());
		}

	if (type == EExitPanic)
		{
		TExitCategoryName cat = deadThread.ExitCategory();
		Printf(_L("panicked with %S %d\r\n"), &cat, deadThread.ExitReason());
		}
	else if (type == EExitTerminate)
		{
		Printf(_L("terminated with reason %d\r\n"), deadThread.ExitReason());
		}
	else if (deadThread.ExitReason() != 0)
		{
		// We'll consider a kill with non-zero exit code as counting as abnormal
		Printf(_L("killed with reason %d\r\n"), deadThread.ExitReason());
		}
	else if (iAll)
		{
		Printf(_L("exited cleanly\r\n"));
		}
		
	if (!iLeakThreads)
		{
		deadThread.Close();
		}
	}
GLDEF_C TInt E32Main()
{
#ifdef AUTOMATIC_TEST_RUN
	User::After( 10*1000*1000 );
	RThread thread; TInt err;
	err=thread.Create(_L("unittests2"), 
		&RunTestsInThread, // thread's main function
		64*1024, /* stack */
		256*1024, /* min heap */
		2048*1024, /* max heap */
		0,
		EOwnerProcess);
	if (err!=KErrNone) return err;
	thread.SetPriority(EPriorityNormal);
	TRequestStatus s;
	thread.Logon(s);
	thread.Resume();
	User::WaitForRequest(s);
	TExitCategoryName n=thread.ExitCategory();
	TInt reason=thread.ExitReason();
	TExitType exittype=thread.ExitType();
	thread.Close();
	if (exittype==EExitPanic) {
		User::Panic( n, reason);
	}
	return reason;

#else
#  ifdef __WINS__
	TRAPD(dummy, User::Leave(-1));
	AllocateContextCommonExceptionData();
#  endif
	
	return EikStart::RunApplication(NewApplication);
#endif
}
示例#22
0
TInt DoZipDownload(RFile &aBootFile)
	{
	TZipInfo z;
	z.iRemain=FileSize;
	InitProgressBar(0,(TUint)FileSize,_L("LOAD"));
	TInt r=Initialise(z);
	CHECK(r);
	RThread t;
	t.SetHandle(z.iThreadHandle);

	while (z.iRemain && z.iThreadStatus==KRequestPending)
		{
		TRequestStatus dummy;
		TRequestStatus* pS=&dummy;

		r=ReadBlockToBuffer(z, aBootFile);
		if (r != KErrNone)
			{
			PrintToScreen(_L("FAULT: Unzip Error %d\r\n"),r);
			if (z.iFileBufW-z.iFileBufR==z.iFileBufSize)
				{
				PrintToScreen(_L("Check there is only one image\n\rin the zip file.\r\n"));
				}
			CHECK(r);
			}

		UpdateProgressBar(0,(TUint)(FileSize-z.iRemain));
		t.RequestComplete(pS,0);		// same process
		while(z.iHeaderDone==0 && z.iThreadStatus==KRequestPending)
			{
			DELAY(20000);
			}
		if (z.iHeaderDone==1 && z.iThreadStatus==KRequestPending)
			{
			// after reading first block, process the header
			ProcessHeader(z);
			}
		}	// while

	User::WaitForRequest(z.iThreadStatus);

	TInt exitType=t.ExitType();
	TInt exitReason=t.ExitReason();
	if (z.iRemain || exitType!=EExitKill || exitReason!=KErrNone)
		{
		TBuf<32> exitCat=t.ExitCategory();
		PrintToScreen(_L("Exit code %d,%d,%S\n"),exitType,exitReason,&exitCat);
		TEST(0);
		}

	PrintToScreen(_L("Unzip complete\r\n"));
	
	TUint8* pD=Buffer;
	TInt len=1024;

	r=ReadInputData(pD,len);
	TEST(r==KErrEof);


	DELAY(20000);

	Cleanup(z);
	return KErrNone;
	}
示例#23
0
void TestMovingRealtime(RPageMove& aPagemove, TUint8* aArray, TInt aSize, TTestFunction aFunc, TBool aCode, TBool aPaged=EFalse)
	{
	TThreadFunction threadFunc;
	TLinAddr pageAddr;
	RThread thread;
	TUint8* firstpage;
	thread.Open(RThread().Id());
	SPinThreadArgs threadArgs;
	threadArgs.iParentThread = thread;
	if (aCode)
		{
		pageAddr = (TLinAddr)aFunc;
		firstpage = (TUint8*)_ALIGN_DOWN(pageAddr, PageSize);
		threadArgs.iLinAddr = (TLinAddr)firstpage;
		threadFunc = RunCodeThread;
		threadArgs.iTestFunc = aFunc;
		test_Equal(KArbitraryNumber, aFunc());
		}
	else
		{
		pageAddr = (TLinAddr)aArray;
		firstpage = (TUint8*)_ALIGN_DOWN(pageAddr, PageSize);
		threadArgs.iLinAddr = (TLinAddr)aArray;
		threadFunc = ReadWriteByte;
		_T_PRINTF(_L("Fill the array with some data\n"));
		for (TInt i=0; i<aSize; i++) aArray[i] = i*i;
		}

	RMemoryTestLdd ldd;

	TMovingPinStage endStage = EMovingPinStages;
	if (gPinningSupported)
		{
		test_KErrNone(ldd.Open());
		test_KErrNone(ldd.CreateVirtualPinObject());
		test_KErrNone(ldd.CreatePhysicalPinObject());
		}
	else
		endStage = EVirtualPinning;

	for (TUint state = ENoPinning; state < (TUint)endStage; state++)
		{
		switch (state)
			{
			case ENoPinning:
				test.Printf(_L("Attempt to move pages while they are being accessed\n"));
				break;
			case EVirtualPinning:
				test.Printf(_L("Attempt to move pages while they are virtually pinned\n"));
				test_KErrNone(ldd.PinVirtualMemory((TLinAddr)firstpage, PageSize));

				break;
			case EPhysicalPinning:
				test.Printf(_L("Attempt to move pages while they are physically pinned\n"));
				test_KErrNone(ldd.PinPhysicalMemoryRO((TLinAddr)firstpage, PageSize));
				break;
			}
		for (	TUint realtimeState = User::ERealtimeStateOff; 
				realtimeState <= User::ERealtimeStateWarn; 
				realtimeState++)
			{
			ThreadDie = EFalse;
			RThread accessThread;
			TRequestStatus s;
			threadArgs.iRealtimeState = (User::TRealtimeState)realtimeState;
			test_KErrNone(accessThread.Create(_L("Realtime Thread"), threadFunc, KDefaultStackSize, NULL, &threadArgs));
			accessThread.Logon(s);
			TRequestStatus threadInitialised;
			accessThread.Rendezvous(threadInitialised);
			accessThread.Resume();

			_T_PRINTF(_L("wait for child\n"));
			User::WaitForRequest(threadInitialised);
			test_KErrNone(threadInitialised.Int());

			_T_PRINTF(_L("Move page repeatedly\n"));
			TBool success=EFalse, pagedOut=EFalse;
			TUint inuse=0;
			if (aCode)
				{
				test_Equal(KArbitraryNumber, aFunc());
				}
			else
				{
				*(volatile TUint8*)aArray = *aArray;
				}

			for (TInt i=0; i < Repitions; i++)
				{
				TInt r = aPagemove.TryMovingUserPage(firstpage, ETrue);
				if (i == 0)
					{
					_T_PRINTF(_L("signal to child\n"));
					RThread::Rendezvous(KErrNone);
					}
				switch (r)
					{
					case KErrInUse:
						inuse++;
						break;
					case KErrArgument:
						// The page was paged out, this should only happen for paged code.
						test(aPaged);
						pagedOut = ETrue;
						break;
					default:
						test_KErrNone(r);
						success=ETrue;
						break;
					}
				}
			ThreadDie = ETrue;
			User::WaitForRequest(s);
			test.Printf(_L("inuse %d\n"),inuse);
			switch (state)
				{
				case ENoPinning :
					test(success);
					if (EExitPanic == accessThread.ExitType())
						{
						test(accessThread.ExitCategory()==_L("KERN-EXEC"));
						test_Equal(EIllegalFunctionForRealtimeThread, accessThread.ExitReason());
						test(aPaged && realtimeState == User::ERealtimeStateOn);
						}
					else
						{
						test_Equal(EExitKill,accessThread.ExitType());
						test_KErrNone(accessThread.ExitReason());
						}
					// Ensure the page is paged in before we attempt to move it again with a different realtime state.
					if (aCode)
						{
						test_Equal(KArbitraryNumber, aFunc());
						}
					else
						{
						*(volatile TUint8*)aArray = *aArray;
						}
					break;				
				case EVirtualPinning :
					test(!aCode || !inuse);
					test(success);
					test(!pagedOut);
					test_Equal(EExitKill,accessThread.ExitType());
					test_KErrNone(accessThread.ExitReason());
					break;
				case EPhysicalPinning :
					test(!success);
					break;
				}
			accessThread.Close();
			}
		if (gPinningSupported)
			{
			// Unpin any pinned memory.
			test_KErrNone(ldd.UnpinVirtualMemory());
			test_KErrNone(ldd.UnpinPhysicalMemory());
			}

		_T_PRINTF(_L("Validate page data\n"));
		if (aCode)
			{
			test_Equal(KArbitraryNumber, aFunc());
			}
		else
			{
			for (TInt i=0; i<aSize; i++)
				test_Equal((TUint8)(i*i), aArray[i]);
			}
			
		}
	if (gPinningSupported)
		{
		test_KErrNone(ldd.DestroyVirtualPinObject());
		test_KErrNone(ldd.DestroyPhysicalPinObject());
		ldd.Close();
		}
	thread.Close();
	}
static TInt CatalogsUndertaker()
    {
    DLTRACEIN((""));

    TFullName catalogsThreadName;
    TInt err = User::GetDesParameter( 15, catalogsThreadName );
    
    if( err != KErrNone )
        {
        DLERROR(( "Failed to read parameter slot 15, error %d", err ));
        catalogsThreadName = KNullDesC();
        }
    else
        {
        DLINFO(( _L("Read catalogs thread name: %S"), &catalogsThreadName ));
        }

    RUndertaker undertaker;
    TRequestStatus status;
    TInt deadThreadHandleNumber;

    undertaker.Create();

    for( ;; )
        {
        undertaker.Logon( status, deadThreadHandleNumber );
        User::WaitForRequest( status );

        RThread deadThread;
        deadThread.SetHandle( deadThreadHandleNumber );

        const TDesC* type;

        switch( deadThread.ExitType() )
            {
            case EExitKill:
                type = &KExitTypeKill;
                break;

            case EExitTerminate:
                type = &KExitTypeTerminate;
                break;

            case EExitPanic:
                type = &KExitTypePanic;
                break;

            default:
                type = &KExitTypeUnknown;
                DLERROR(( "Exit type: %d", (TInt)deadThread.ExitType() ));
                break;
            }


        DLWARNING(( _L("THREAD %S DEATH observed! %S %S %d"), 
            &deadThread.FullName(),
            type,
            &deadThread.ExitCategory(),
            deadThread.ExitReason() ));
        
        type = type; // to suppress compiler warning

        if( catalogsThreadName == deadThread.FullName() )
            {
            DLERROR(( "Catalogs server thread killed, undertaker exits" ));
            deadThread.Close();
            break;
            }

        deadThread.Close();

        }

    undertaker.Close();
    DLTRACEOUT(("KErrNone"));

    return KErrNone;
    }
示例#25
0
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);
	}
TInt CTe_locsrvSuiteStepBase::DoPanicTestL(TThreadFunction aThreadFunction, TExitCategoryName aExpectedExitCat,
                  TInt aExpectedExitReason, TTimeIntervalMicroSeconds32 aTimeoutValue)

{
#ifdef __WINS__
    User::SetJustInTime(EFalse);
    CleanupStack::PushL(TCleanupItem(TurnJITBackOn));
#endif
    RThread panickingThread;

    SPanicThreadFunctionData threadData;
    threadData.iPanicFunction = aThreadFunction;
    threadData.iPtr = NULL;

    // check that thread does not already exist
    TInt result = KErrNone;
    TBuf<24> threadName(KPanicThreadName);
    
    result = panickingThread.Create(
                threadName,
                PanicThreadFunction,
                KDefaultStackSize,
                KTestHeapMinSize,
                KTestHeapMaxSize,
                &threadData,
                EOwnerProcess);

    CheckExpectedResult(result, KErrNone, KUnexpectedErrorCreatingPanicThread);
    User::LeaveIfError(result);

    CleanupClosePushL(panickingThread);

    RTimer timeoutTimer;
    User::LeaveIfError(timeoutTimer.CreateLocal());
    CleanupClosePushL(timeoutTimer);

    TRequestStatus timerStatus;
    timeoutTimer.After(timerStatus, aTimeoutValue);

    TRequestStatus threadStatus;

    panickingThread.Rendezvous(threadStatus);
    if (threadStatus != KRequestPending)
        {
        // logon failed - thread is not yet running, so cannot have terminated
        User::WaitForRequest(threadStatus);              // eat signal
        panickingThread.Kill(threadStatus.Int());        // abort startup
        }
    else
        {
        panickingThread.Resume();
        User::WaitForRequest(threadStatus, timerStatus);
        }

    TInt exitReason = KErrNone;
    if (threadStatus == KRequestPending)
    {
        ERR_PRINTF1(KThreadDidntDieKillIt);
        panickingThread.Kill(KErrTimedOut);
        User::WaitForRequest(threadStatus);
    }
    else // (timerStatus == KRequestPending)
    {
        // stop timer
        timeoutTimer.Cancel();
        User::WaitForRequest(timerStatus);
    }

    exitReason = panickingThread.ExitReason();
    TExitCategoryName exitCat = panickingThread.ExitCategory();
    
    switch(panickingThread.ExitType()) 
    {
        case EExitKill:
            INFO_PRINTF2(KThreadWasKilled, exitReason);
            break;
        case EExitTerminate:
            INFO_PRINTF2(KThreadWasTerminated, exitReason);
            break;
        case EExitPanic:
            // check exit reasons
            if (exitCat.Compare(aExpectedExitCat) != 0)
                {
                INFO_PRINTF3(KUnexpectedPanicCategory, &exitCat, &aExpectedExitCat);
                }
            CheckExpectedResult(exitReason, aExpectedExitReason, KUnexpectedPanicReason);
            break;
        default:
            CheckExpectedResult((TInt)EExitPanic, threadStatus.Int(), KUnexpectedThreadExitType);
            break;
    }

    CleanupStack::PopAndDestroy(&timeoutTimer);
    CleanupStack::PopAndDestroy(&panickingThread);
#ifdef __WINS__
    CleanupStack::PopAndDestroy();  //TurnJITBackOn
#endif
    // wait a bit to make sure this thread is over
    const TTimeIntervalMicroSeconds32 KThreadDelay = 1000 * 1000; // 1 s
    User::After(KThreadDelay);

    return exitReason;
}