示例#1
0
/**  Reads the file that is being written

*/
void TestReadingWhileWritingSameFile() 
{
	TInt r = 0;
	TF32TestTimer timer;
	
	timer.Start();
	
	// Sync test
	TBuf<20> buf = _L("Big Write IV");
	r = gBig.Create(buf, WriteBigFile, KDefaultStackSize, KHeapSize, KMaxHeapSize, NULL);
	TEST(r == KErrNone);

	buf = _L("Read IV");
	r = gSmall.Create(buf, ReadBigFile, KDefaultStackSize, KHeapSize, KMaxHeapSize, NULL);
	TEST(r == KErrNone);
	
	gBig.Resume();
	gSmall.Resume();
	
	CLIENTWAIT();
	CLIENTWAIT();
	
	CLOSE_AND_WAIT(gBig);
	CLOSE_AND_WAIT(gSmall);
	
	TTimeIntervalMicroSeconds timeTaken = gTestTimer.Time();
	test.Printf(_L("\nSync write finished %d ms before the read ended\n"),TF32TestTimer::TimeInMilliSeconds(timeTaken));
	
}
示例#2
0
/** Starts two concurrent client sessions in different directories

*/
LOCAL_C void DoTest2(TThreadFunction aFunction)
	{
	gKillMe = EFalse;

	TBuf<20> buf = _L("Speedy");
	buf.AppendNum(ThreadCount++);
	gT1 = ThreadCount;
	TInt r = gSpeedy.Create(buf, aFunction, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
	FailIfError(r);

	buf = _L("Speedy");
	buf.AppendNum(ThreadCount++);
	gT2 = ThreadCount;
	r = gSpeedyII.Create(buf, DeleteEntryAccess2, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
	FailIfError(r);

 	gSpeedy.SetPriority(EPriorityLess);
    gSpeedyII.SetPriority(EPriorityLess);
	
	gSpeedy.Resume();
	gSpeedyII.Resume();
	
	client.Wait();
	client.Wait();
	}
示例#3
0
static TInt StartServer()
//
// Start the server process or thread
//
	{
	const TUidType serverUid(KNullUid,KNullUid,KServerUid3);

#ifdef __CDLSERVER_NO_PROCESSES__
	//
	// In EKA1 WINS the server is a DLL, the exported entrypoint returns a TInt
	// which represents the real entry-point for the server thread
	//
	RLibrary lib;
	TInt r=lib.Load(KCdlServerDllImg,serverUid);
	if (r!=KErrNone)
		return r;
	TLibraryFunction ordinal1=lib.Lookup(1);
	TThreadFunction serverFunc=reinterpret_cast<TThreadFunction>(ordinal1());
	//
	// To deal with the unique thread (+semaphore!) naming in EPOC, and that we may
	// be trying to restart a server that has just exited we attempt to create a
	// unique thread name for the server.
	// This uses Math::Random() to generate a 32-bit random number for the name
	//
	TName name(KCdlServerName);
	name.AppendNum(Math::Random(),EHex);
	RThread server;
	r=server.Create(name,serverFunc,
					KCdlServerStackSize,
					NULL,&lib,NULL,
					KCdlServerInitHeapSize,KCdlServerMaxHeapSize,EOwnerProcess);
	lib.Close();	// if successful, server thread has handle to library now
#else
	//
	// EPOC and EKA2 is easy, we just create a new server process. Simultaneous launching
	// of two such processes should be detected when the second one attempts to
	// create the server object, failing with KErrAlreadyExists.
	//
	RProcess server;
	TInt r=server.Create(KCdlServerExeImg,KNullDesC,serverUid);
#endif
	if (r!=KErrNone)
		return r;
	TRequestStatus stat;
	server.Rendezvous(stat);
	if (stat!=KRequestPending)
		server.Kill(0);		// abort startup
	else
		server.Resume();	// logon OK - start the server
	User::WaitForRequest(stat);		// wait for start or death
	// we can't use the 'exit reason' if the server panicked as this
	// is the panic 'reason' and may be '0' which cannot be distinguished
	// from KErrNone
	r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
	server.Close();
	return r;
	}
示例#4
0
/** Writes a small file while writing a big one

*/
void TestWritingWhileWriting() 
{
	TInt r = 0;

	// Sync test
	TBuf<20> buf = _L("Big Write II");
	r = gBig.Create(buf, WriteBigFile, KDefaultStackSize, KHeapSize, KMaxHeapSize, NULL);
	TEST(r == KErrNone);

	buf = _L("Small Write II");
	r = gSmall.Create(buf, WriteSmallFile, KDefaultStackSize, KHeapSize, KMaxHeapSize, NULL);
	TEST(r==KErrNone);
	
	gBig.Resume();
	gSmall.Resume();

	CLIENTWAIT();
	CLIENTWAIT();
	
	gBig.Close();
	gSmall.Close();
	
	TTimeIntervalMicroSeconds timeTaken = gTestTimer.Time();
	test.Printf(_L("\nSync write done %d ms before the big write ended\n"), gTestTimer.TimeInMilliSeconds());
	#if !defined(__WINS__)
		// If this condition fails, it means that writing the sync file while 
        // fairscheduling a small sync write takes too long		
		test(timeTaken > 0);
	#endif 

	// Async test 
	TRequestStatus status[KWaitRequestsTableSize];
	TRequestStatus status2[1];
	RFile bigFile, smallFile;

	WriteFileAsync(TheFs, bigFile, gBigFile, gBigFileSize, KBigBlockSize, status); 
	WriteFileAsync(TheFs,smallFile, gSmallFile,gSmallFileSize,KBlockSize,status2);
	WaitForAll(status2,gSmallFileSize, KBlockSize);
    TF32TestTimer timer;
	timer.Start();
	WaitForAll(status, gBigFileSize, KBigBlockSize);
	timer.Stop();
	
	timeTaken = timer.Time();
	test.Printf(_L("\nAsync write done %d ms before the big write ended\n"),timer.TimeInMilliSeconds());
	#if !defined(__WINS__)
	if (!Is_HVFS(TheFs, gDrive))
		{
		// If this condition fails, it means that writing the async file while fairscheduling a small async write takes too long
		test.Printf(_L("gTotalTimeAsync[0] = %d , gTotalTimeAsync[1] = %d\n"),gTotalTimeAsync[0],gTotalTimeAsync[1] );
		test(timeTaken > 0);
		}
	#endif
	bigFile.Close();
	smallFile.Close();	
}
// -----------------------------------------------------------------------------
// MceServerStarter::CreateServerProcess
// -----------------------------------------------------------------------------
//
TInt MceServerStarter::CreateServerProcess (RSemaphore& aSemaphore)
	{
	const TUidType serverUid (KNullUid, KNullUid, KServerUid3);


#if ((defined (__WINS__) || defined(__WINSCW__)) && !defined (EKA2))

	RLibrary lib;
    RETURN_IF_ERROR (lib.Load(KMceServerFilename,serverUid))

    //  Get the WinsMain function
	TLibraryFunction functionWinsMain = lib.Lookup (1);

    //  Call it and cast the result to a thread function
	TThreadFunction serverThreadFunction = 
        reinterpret_cast<TThreadFunction> (functionWinsMain());

	TName threadName (KSipServerName);

	// Append a random number to make it unique
	threadName.AppendNum (Math::Random(), EHex);

	RThread server;
    TInt err = server.Create (threadName,
                              serverThreadFunction, // thread's main function
                              KDefaultStackSize,
                              NULL,
                              &lib,
                              NULL,
                              KServerMinHeapSize,
                              KServerMaxHeapSize,
                              EOwnerProcess );

	lib.Close ();	// if successful, server thread has handle to library now
    RETURN_IF_ERROR (err)

	server.SetPriority (EPriorityMore);

#else // HW build

	RProcess server;
	RETURN_IF_ERROR (server.Create( KMceServerName, KNullDesC, serverUid ) )

#endif


	server.Resume ();
	aSemaphore.Wait();
	TInt exitReason = server.ExitReason();
	server.Close ();

    return exitReason;
	}
示例#6
0
static void TestRUpsSubsessionDeathL()
	{
	RThread thd;
	TRequestStatus thdStatus;
	User::LeaveIfError(thd.Create(_L("MyThread"), ThreadFunction, 4096, 4096, 4096, 0, EOwnerThread));
//	thd.SetHandle(666);
	thd.Rendezvous(thdStatus);
	thd.Kill(KErrAbort);
	User::WaitForRequest(thdStatus);

	test.Start(_L("Testing RUpsSubsession"));
	RUpsSubsession clientSubsession;
	TInt r = clientSubsession.Initialise(sTestSession, thd);
	test(r == KErrNone);

	test.Next(_L("Query with dead thread id"));
	TServiceId serviceId = {43};
	TUpsDecision dec = EUpsDecYes;
	TRequestStatus rs;
	thd.Close();
	clientSubsession.Authorise(EFalse, serviceId, _L("req1"), dec, rs);
	User::WaitForRequest(rs);
	test(rs == KErrNone);
	test(dec == EUpsDecNo);

	
	clientSubsession.Close();
	test.End();
	}
示例#7
0
TInt RConsoleProxy::DoConnect(TServerParams* aParams, const TDesC& aThreadNameBase, TInt aStackSize, TInt aHeapMinSize, TInt aHeapMaxSize, RServer2& aServer, RThread& aServerThread)
	{
	TName threadName;
	RThread server;
	TInt threadId = 0;
	_LIT(KThreadIdFmt, "%08x");
	TInt err;
	do
		{
		threadName = aThreadNameBase.Left(threadName.MaxLength()-8);
		threadName.AppendFormat(KThreadIdFmt, threadId);
		err = server.Create(threadName, &ServerThreadFunction, aStackSize, aHeapMinSize, aHeapMaxSize, aParams);
		++threadId;
		} while (err==KErrAlreadyExists);
	if (err!=KErrNone) return err;
	
	TRequestStatus rendezvous;
	server.Rendezvous(rendezvous);
	if (rendezvous == KRequestPending)
		{
		server.Resume();
		}
	User::WaitForRequest(rendezvous);
	err = rendezvous.Int();
	if (server.ExitType() != EExitPending && err >= 0) err = KErrDied;
	if (err==KErrNone)
		{
		err = Connect(aParams->iServer);
		}
	aServer = aParams->iServer;
	aServerThread = server;
	return err;
	}
// ----------------------------------------------------------------------------
// CSIPClientResolver::CreateWorkerThreadL
// ----------------------------------------------------------------------------
//   
void CSIPClientResolver::CreateWorkerThreadL()
    {
    TName threadName(KWorkerThreadName);
    // Append a random number to make the name unique
    const TInt KThreadIdWidth = 10;
    threadName.AppendNumFixedWidthUC(Math::Random(), EHex, KThreadIdWidth);
    RThread thread;
    TInt err = thread.Create(threadName,
                             WorkerThreadFunction,
                             KDefaultStackSize,
                             NULL, // Use the same heap as the main thread
                             this);
    User::LeaveIfError(err);
    TRequestStatus status;
    thread.Logon(status);
    thread.Resume();
    User::WaitForRequest(status);
    TExitType exitType = thread.ExitType();
    thread.Close();
    if (exitType == EExitPanic)
        {
        User::Leave(KErrGeneral);
        }
    User::LeaveIfError(status.Int());
    }
示例#9
0
LOCAL_C void RunTest(TInt aSize)
	{
	const TInt KTestRunUs = KTestRunSeconds * 1000000;

	RThread t;
	TInt r=t.Create(KNullDesC,TestThread,0x1000,NULL,(TAny*)aSize);
	test(r==KErrNone);
	t.SetPriority(EPriorityLess);
	TRequestStatus s;
	t.Logon(s);
	t.Resume();
	ServerSem.Wait();
	test(Server.Handle() != KNullHandle);

	RMySession sess;
	TRequestStatus stat;
	test(sess.Connect(Server,stat) == KErrNone);
	User::WaitForRequest(stat);	// connected

	Count=0;
	TPtr8 des((TUint8*)Dest, 0, aSize);
	sess.Test(des);
	User::After(KTestRunUs);
	t.Kill(0);
	User::WaitForRequest(s);
	sess.Close();
	Server.Close();
	CLOSE_AND_WAIT(t);

	TInt us=10*KTestRunUs/Count;
	test.Printf(_L("%5d byte writes: %8d/%ds %4d.%01dus\n"),aSize,Count,KTestRunSeconds,us/10,us%10);
	}
示例#10
0
/**
	@SYMTestCaseID
	GRAPHICS-FBSERV-0593

	@SYMTestCaseDesc
	Tests the cleaning when a thead is panicing.

	@SYMTestActions
	Creates a bitmap. Checks the resource count. Creates
	a thread with high priority. Unlocks the heap and locks
	it back again. Disables just-in-time debugging. Waits for 
	he thead to complete its execution. The created thread creates
	its own cleanup stack and connects to a FbsSession. It creates 
	three bitmaps and duplicates one of them to the other. 
	A FbsTypefaceStore object is created on the heap an 
	GetNearestFontToDesignHeightInPixel is called on it. Disconnect
	from the FbsSession. The thread is paniced and terminated. The
	function that created the thread now continues its execution by
	checking the exit reason for the thread. Closes the thead. Enables
	just-in-time again. Locks the heap and unlocks it again.
	Checks the resource count. Deletes scan line buffer. The
	heap is checked for memory leaks.	
	
	@SYMTestExpectedResults
	Test should pass
*/
void CTClean::DeadThread()
	{
	__UHEAP_MARK;
	CFbsBitmapEx bmp;
	TInt ret=bmp.Create(TSize(100,100),EGray16);
	TEST(ret==KErrNone);
	TInt rc=iFbs->ResourceCount();
	TEST(rc==1);
	RThread thrd;
	TRequestStatus stat;
	thrd.Create(_L("ctt"),CleanupTestThread,KDefaultStackSize,0x8000,0x8000,this);
	thrd.SetPriority(EPriorityMuchMore);
	thrd.Logon(stat);
	User::SetJustInTime(EFalse);
	bmp.LockHeap();
	bmp.UnlockHeap();
	thrd.Resume();
	User::WaitForRequest(stat);
	ret = thrd.ExitReason();
	thrd.Close();
	User::SetJustInTime(ETrue);
	TEST(ret == KErrNone);
	INFO_PRINTF1(_L("About to lock heap\r\n"));
	bmp.LockHeap();
	bmp.UnlockHeap();
	rc=iFbs->ResourceCount();
	TEST(rc==1);
	DeleteScanLineBuffer();
	__UHEAP_MARKEND;
	}
/**
@SYMTestCaseID          PDS-EFM-CT-4058
@SYMTestCaseDesc        Querying and modifying a feature during restore operation. 
                        Verify that a response is returned from the server during restore.
@SYMTestPriority        High
@SYMTestActions         Start simulating restore operation
                        Create a thread that will:
                        Modify a feature and verify that a response (KErrServerBusy) is received 
                        Query a feature and verify that a response is received (doesn't matter what the result is)
                        The thread should finished in less than 2 seconds.
                        Otherwise the test fail.          
@SYMTestExpectedResults Test must not fail
@SYMREQ                 
*/  
void TestRestoreResponseL()
    {
        _LIT(KThreadName, "RstTh");
        featMgrIsResponsive = EFalse;
        
        CFeatMgrBURSim* simulate = CFeatMgrBURSim::NewLC();
        RThread testThread;
        TRequestStatus testStatus;
        CleanupClosePushL( testThread );
        
        //Needs to ensure server is started before simulating backup operation
        RFeatureControl rfc;
        TTEST2( rfc.Connect(), KErrNone ); //This will start the server if not already started
        rfc.Close();
        
        simulate->Simulate_CheckRegFileL();
        
        // Simulate a restore
        RDebug::Print(_L("Simulating Restore of FeatMgr\r\n"));
        simulate->Simulate_StartRestoreL();

        TEST2( testThread.Create(KThreadName, &TestThreadL, 0x2000, 0x1000, 0x10000, NULL, EOwnerProcess), KErrNone );
        testThread.Logon(testStatus);
        TEST2( testStatus.Int(), KRequestPending );
        testThread.Resume();
        // Wait for 1.5 second for the query thread to finish. 
        RDebug::Print(_L("+++:MainThread: Wait for query and modification completion...\r\n"));
        MainThreadCrS.Wait(threadTimeout);
        // If query is responsive within the 1.5 second frame the following check should pass.
        TEST (featMgrIsResponsive);
        simulate->Simulate_EndRestoreL();
        
        CleanupStack::PopAndDestroy(&testThread);
        CleanupStack::PopAndDestroy(simulate);
    }
示例#12
0
void TestCommitDecommit(RPageMove& pagemove, RChunk& aChunk)
	{
	test.Printf(_L("Attempt to move a page while it is being committed and decommited\n"));
	RThread thread;
	TRequestStatus s;
	test_KErrNone(thread.Create(_L("CommitDecommit"), &CommitDecommit, KDefaultStackSize, NULL, (TAny*)&aChunk));
	thread.Logon(s);
	thread.SetPriority(EPriorityMore);
	thread.Resume();

	TUint8* firstpage=(TUint8*)_ALIGN_DOWN((TLinAddr)aChunk.Base(), PageSize);
	for (TInt i=0; i < Repitions; i++)
		{
		TInt r = pagemove.TryMovingUserPage(firstpage, ETrue);
		// Allow all valid return codes as we are only testing that this doesn't 
		// crash the kernel and the page could be commited, paged out or decommited
		// at any one time.
		test_Value(r, r <= KErrNone);
		}

	thread.Kill(KErrNone);
	User::WaitForRequest(s);
	test_Equal(EExitKill,thread.ExitType());
	test_KErrNone(thread.ExitReason());
	thread.Close();
	}
/**
 * Auxiliary function for TestCaseID TAppLangSTARTER_doTestStepL
 *
 * This method creates the server thread by invoking RThread::Create() and calls
 * CMessageServServer::ThreadFunction() to start the Message Server.
 *
 */
TInt CTestApplicationLanguageStep::StartThread()
    {
	TInt res=KErrNone;
	// create server - if one of this name does not already exist
	TFindServer findCountServer(KMessageServerName);
	TFullName name;
	if (findCountServer.Next(name)!=KErrNone) // we don't exist already
		{
		RThread thread;
		semaphore.CreateLocal(0); // create a semaphore so we know when thread finished
		res=thread.Create(KMessageServerName,   // create new server thread
			CMessageServServer::ThreadFunction, // thread's main function
			KDefaultStackSize,
			KDefaultHeapSize,
			KDefaultHeapSize,
			this // passed as TAny* argument to thread function
			);

		if (res==KErrNone) // thread created ok - now start it going
			{
			thread.SetPriority(EPriorityNormal);
			thread.Resume(); // start it going
			semaphore.Wait(); // wait until it's initialized
			thread.Close(); // we're no longer interested in the other thread
			}
		else // thread not created ok
			{
			thread.Close(); // therefore we've no further interest in it
			}

		semaphore.Close();
		}

    return res;
    }
TTestObject::~TTestObject()
	{
	RDebug::Printf("t_destruct_slave destructor called\n");
	if (iTestType == ETestRecursive)
		{
		// Start child thread passing this thread's id
		MainThreadId = RThread().Id();
		RThread childThread;
		test_KErrNone(childThread.Create(_L("ChildThread"), ChildThread, 4096, NULL, (TAny*)iTestType));
		TRequestStatus status;
		childThread.Rendezvous(status);
		childThread.Resume();

		// Wait for child to open handle on this thread
		User::WaitForRequest(status);
		test_KErrNone(status.Int());
		childThread.Close();

		// Set this thread non-critical
		User::SetCritical(User::ENotCritical);
		}
	else if (iTestType == ETestDestructorExits)
		{
		User::Exit(iTestType);
		}

	RMsgQueue<TMessage> messageQueue;
	TInt r = messageQueue.OpenGlobal(KMessageQueueName);
	if (r != KErrNone)
		Panic(r);
	messageQueue.Send(EMessageDestruct);
	if (r != KErrNone)
		Panic(r);
	}
// EKA2 much simpler
// Just an E32Main and a MainL()
LOCAL_C void MainL()
/**
 * Much simpler, uses the new Rendezvous() call to sync with the client
 */
 	{
	// Leave the hooks in for platform security
#if (defined __DATA_CAGING__)
	RProcess().DataCaging(RProcess::EDataCagingOn);
	RProcess().SecureApi(RProcess::ESecureApiOn);
#endif
	CActiveScheduler* sched=NULL;
	sched=new(ELeave) CActiveScheduler;
	CActiveScheduler::Install(sched);
	CMMFAudioServer* server = NULL;
	TRAPD(err,server = CMMFAudioServer::NewL());

	// Start BT audio server in its own thread here...
	// Assume that the server's not been started already
	// 
	RThread btServerThread;
	TThreadFunction btServerThreadFunc = CA2dpBTHeadsetAudioIfServer::StartThread;
	TName btServerName(KA2DPAudioServerName);


	err = btServerThread.Create(btServerName, btServerThreadFunc, KBTAudioServerStackSize,
								KBTAudioServerInitHeapSize, KBTAudioServerMaxHeapSize,
								NULL, EOwnerProcess);	// NULL => not passing any params to thread

	if(!err)
		{
		// Synchronise with the server
		TRequestStatus reqStatus;
		btServerThread.Rendezvous(reqStatus);

		if (reqStatus != KRequestPending)
			{
			btServerThread.Kill(0);
			}
		else 
			{
			// Start the thread
			btServerThread.Resume();
			// Server will call the reciprocal static synchronise call
			}
		User::WaitForRequest(reqStatus); // wait for start or death
		}
		
	if(!err)
		{
		// Sync with the client and enter the active scheduler
		RProcess::Rendezvous(KErrNone);
		sched->Start();
		}
	
	btServerThread.Close();
		
	delete server;
	delete sched;	
	
	}
示例#16
0
void TestPanic(TPanicFunc aFunc, TInt aExpectedReason)
/**
	Creates a new thread, runs the supplied function in its context,
	and confirms that it is panicked with category KKmsClientPanicCat
	and the supplied reason.

	@param	aFunc			Function to call in context of new thread.
	@param	aExpectedReason	The newly-created thread is expected to be panicked
							with this reason.
 */
	{
	test.Printf(_L("TestPanic: KmsLdd %d\n"), aExpectedReason);
	
	RThread thd;
	TInt r = thd.Create(
		_L("KmsTestTestPanic"), TestPanicEntrypoint,
		KDefaultStackSize, KMinHeapSize, KMinHeapSize, 
		(TAny*) aFunc);
	test(r == KErrNone);
	
	TRequestStatus rs;
	thd.Rendezvous(rs);
	test(rs == KRequestPending);
	TInt jit = User::JustInTime();
	User::SetJustInTime(EFalse);
	thd.Resume();
	
	User::WaitForRequest(rs);
	User::SetJustInTime(jit);
	ConfirmPanicReason(thd, aExpectedReason);
	thd.Close();
	}
示例#17
0
// main loop
//
GLDEF_C TInt E32Main()
    {  
	__UHEAP_MARK;  
	CTrapCleanup* theCleanup = CTrapCleanup::New(); // Install exception handler  
	
	// Create a new thread for running tests in
	RThread testThread;
	TInt err = testThread.Create(KTestThreadName, TestEntryPoint, KDefaultStackSize,  
							 KMinHeapSize, KMaxHeapSize, NULL);
	if(err == KErrNone)
		{
		testThread.Resume();	
		}
	else
		{
		return err;
		}
	
	// Kick off test thread and wait for it to exit
	TRequestStatus tStat;
	testThread.Logon(tStat);
	User::WaitForRequest(tStat);
	
	// Log if paniced
	if(testThread.ExitType() == EExitPanic)
		{
		TRAP_IGNORE(LogOnPanicL(testThread));	
		}
	
	testThread.Close();
	delete theCleanup;		
	__UHEAP_MARKEND;		
	return KErrNone;
	}
示例#18
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();

	}
示例#19
0
/* 
 * Creates a Thread that modifies its code in a tight loop while the main
 * thread moves the functions page around
 */
LOCAL_C TInt TestCodeModificationAsync(RPageMove& pagemove)
	{
	TInt ret;
	RThread CodeThread;
	TRequestStatus s;

	
	/* Create the Thread to modify the code segment */
	test_KErrNone(CodeThread.Create(_L("TestCodeAsync"), TestCodeAsync, KDefaultStackSize, NULL, NULL));
	CodeThread.Logon(s);
	CodeThread.SetPriority(EPriorityMore);
	CodeThread.Resume();

	TestCodeSetupDrive(CodeThread);

	/* Loop trying to move the code page while the thread (CodeThread) modifies it */
	for (TInt i=0; i<Repitions; i++)
		{
		test_KErrNone(pagemove.TryMovingUserPage((TAny*)TestCodeModFunc));
		}

	CodeThread.Kill(KErrNone);
	User::WaitForRequest(s);
	test_Equal(EExitKill, CodeThread.ExitType());
	test_KErrNone(CodeThread.ExitReason());
	CodeThread.Close();

	ret = TestCodeModFunc();
	test(ret == 1 || ret == 2);

	return KErrNone;
	}
示例#20
0
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");
	}
/**
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;
	}
示例#22
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();
	}
TInt CTSISHelperStepBase::startSisHelper(Swi::TSisHelperStartParams& aParams)
	{
	// To deal with the unique thread (+semaphore!) naming in Symbian OS, and
	// that we may be trying to restart a server that has just exited we 
	// attempt to create a unique thread name for the server
	TName name(Swi::KSisHelperServerName);
	name.AppendNum(Math::Random(), EHex);
	RThread server;
	const TInt KSisHelperServerStackSize=0x2000;
	const TInt KSisHelperServerInitHeapSize=0x1000;
	const TInt KSisHelperServerMaxHeapSize=0x1000000;
	TInt err=server.Create(name, sisHelperThreadFunction, 
		KSisHelperServerStackSize, KSisHelperServerInitHeapSize, 
		KSisHelperServerMaxHeapSize, static_cast<TAny*>(&aParams), 
		EOwnerProcess);
	if (err!=KErrNone)
		return err;
	
	// The following code is the same whether the server runs in a new thread 
	// or process
	TRequestStatus stat;
	server.Rendezvous(stat);
	if (stat!=KRequestPending)
		server.Kill(0); // abort startup
	else
		server.Resume(); // logon OK, start the server
	User::WaitForRequest(stat); // wait for start or death
	
	// we can't use the 'exit reason' if the server panicked as this is the 
	// panic 'reason' and may be 0 which cannot be distinguished from KErrNone
	err=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
	server.Close();
	return err;
	}
示例#24
0
TInt CTimesliceTestThread::Construct(TUint32 aId, TInt aCpu, TInt aSlice, CircBuf* aBuf)
	{
	iId = aId;
	iCpu = aCpu;
	iSlice = aSlice;
	iBuf = aBuf;

	TInt r = HAL::Get(HAL::EFastCounterFrequency, (TInt&)iFreq);
	if (r!=KErrNone)
		return r;
	iThresh = iFreq / 3000;
	if (iThresh < 10)
		iThresh = 10;
	iThresh2 = iFreq;
	TBuf<16> name = _L("TSThrd");
	name.AppendNum(iId);
	r = iThread.Create(name, &ThreadFunc, 0x1000, NULL, this);
	if (r!=KErrNone)
		return r;
	iThread.Logon(iExitStatus);
	if (iExitStatus != KRequestPending)
		{
		iThread.Kill(0);
		iThread.Close();
		iThread.SetHandle(0);
		return iExitStatus.Int();
		}
	return KErrNone;
	}
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;
}
示例#26
0
/**
Intended Usage	: Capture the PANIC that occurs in the thread.
@param			: aName The name to be assigned to this thread.
@param			: aFunction The function which causes the panic.
*/
LOCAL_C void ThreadPanicTest(const TDesC& aName,TThreadFunction aFunction)
{
    TheTest.Next(aName);
    TRequestStatus threadStatus;
    RThread thread;
    TBool jit;
    jit=User::JustInTime();
    User::SetJustInTime(EFalse);

    for (TInt i = EIterFunctionDriveUnit; i <= EIterFunctionIsRemovable; i++)
    {
        TIteratorFunctionToTest func = static_cast<TIteratorFunctionToTest>(i);
        TInt err=thread.Create(aName,aFunction,KDefaultStackSize,KMinHeapSize,KMinHeapSize, &func);
        TESTL(err==KErrNone);

        thread.Logon(threadStatus);
        thread.Resume();
        User::WaitForRequest(threadStatus);

        //Now check why the thread Exit
        TExitType exitType = thread.ExitType();
        TInt exitReason = thread.ExitReason();
        TheTest.Printf(_L("PanicTest: exitType %d, reason %d\n"), exitType, exitReason);

        TESTL(exitType == EExitPanic);
        TESTL(exitReason == KPanicIndexOutOfBound);
        thread.Close();
    }

    User::SetJustInTime(jit);
}
示例#27
0
TInt64 runTest(TThreadFunction aFunction,const TDesC& aTitle)
    {

    RThread thread;
	TInt r=thread.Create(aTitle,aFunction,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
	if(r!=KErrNone)
		{
		test.Printf(_L("Failed to create thread with error %d\n"),r);
		return(r);
		}
    thread.Resume();
    User::After(1000000);
    count=0;
    User::After(KAverageOverInSeconds*1000000);
    TInt64 result=count;

	barrier = a;
	if (!barrier)
		barrier = c;
	barrier = b;
	if (!barrier)
		barrier = a;
	barrier = c;
	if (!barrier)
		barrier = b;

	thread.Kill(0);
	thread.Close();
	result*=KNumberOfCalculationsPerLoop;
	result/=KAverageOverInSeconds;
	r=I64INT(result);
    test.Printf(_L("%S executed %d in 1 second\n"),&aTitle,r);
    return(result);
    }
/**
@SYMTestCaseID		SYSLIB-ECOM-CT-3163
@SYMTestCaseDesc 	Verify the startup behaviour of the ECOM server under OOM conditions
@SYMTestPriority 	High
@SYMTestActions  	Generate an OOM condition.
					Create a new thread which will launch the ECOM server.
					Wait for the thread to exit and check the thread exit type
					and reason to verify behaviour.
@SYMTestExpectedResults The test must not fail.
@SYMDEF DEF094675
*/
void StartServer_OOMTest()
	{

	_LIT(KStartThreadName,"Server Start Thread");

	//Create a new thread to launch the ECOM server
	RThread testThread;
	testThread.Create(KStartThreadName, ServerStartThreadEntryL,
				KDefaultStackSize,KMinHeapSize,KMinHeapSize,NULL);
	TRequestStatus status;
	testThread.Logon(status);
	testThread.Resume();

	//Wait for the thread to exit
	User::WaitForRequest(status);

	//Obtain exit type and reason for test thread
	TExitType exitType = testThread.ExitType();
	TInt exitReason = testThread.ExitReason();

	//close the thread handle
	testThread.Close();

	//Verify the exit reason and exit code
	//Exit type is TExitType::EExitKill when E32Main() exit normally
	TEST(exitType == EExitKill);
	TEST(exitReason == KErrNoMemory);

	}
示例#29
0
TInt CAnvltestListener::StartThread(void)
    {

    TInt res = KErrNone;
    //RThread anvlThread;
    RThread *anvlThread;

    anvlThread = &iAnvlThread;
    iOriThreadId = RThread().Id();

    res = anvlThread->Create(ANVL_THREAD_NAME,
                            CAnvltestListener::ThreadFunction,
                            KDefaultStackSize,
                            KAnvlDefaultHeapSize,
                            KAnvlDefaultHeapSize,
                            this                // passed as TAny* argument to thread function
                           );

    if ( res == KErrNone )                      // thread created ok - now start it going
        {
        anvlThread->SetPriority(KAnvlThreadPriority);
        anvlThread->Resume();
        // anvlThread->Close();
        }
    else                                        // thread not created ok
        {
        anvlThread->Close();
        }

    return res;

    };
/**
Static function used to create and start CSsmSwpPolicyServer
@return KErrAlreadyExists if the server is already running
*/
EXPORT_C TInt CSsmSwpPolicyServer::StartSsmSwpPolicySrv(const TDesC& aServerName)
	{
	TAny* threadParam = reinterpret_cast<TAny*>(const_cast<TDesC*>(&aServerName));

	// Create a Unique name for the thread name
	TName name(aServerName);
	_LIT(KUnderScore, "_");
	name.Append(KUnderScore);
	name.AppendNum(Math::Random(), EHex);

	const TInt KSsmPolicySrvMinHeapSize = 0x2000;	// 8kB
	const TInt KSsmPolicySrvMaxHeapSize = 10 * KSsmPolicySrvMinHeapSize;
	RThread srvThread;
	TInt err = srvThread.Create(name, &CSsmSwpPolicyServer::SsmSwpPolicySrvThreadFn, 
								 KDefaultStackSize, KSsmPolicySrvMinHeapSize, KSsmPolicySrvMaxHeapSize, 
								 threadParam, EOwnerProcess);

	DEBUGPRINT2(_L("CSsmSwpPolicyServer: SsmSwpPolicyServer created with %d") ,err);
	if(KErrNone == err)
		{
		TRequestStatus trs;
	
		srvThread.Rendezvous(trs);
		srvThread.Resume();
		
		User::WaitForRequest(trs);	
		err = trs.Int();
		srvThread.Close();
		}

	return err;
	}