Esempio n. 1
0
/**
 @SYMTestCaseID APPFWK-APPARC-0018

 @SYMPREQ PREQ1123

 @SYMTestCaseDesc The Test determines that a process is launched and terminated without any problem.\n

 @SYMTestPriority Low

 @SYMTestStatus Implemented

 @SYMTestActions. Creates and launches a process. No Child is created. Parent should launch properly, and on termination should die.
 API Calls:\n
 RProcess::Create(const TDesC &aFileName, const TDesC &aCommand, TOwnerType aType=EOwnerProcess);\n
 RProcess::Resume();
 RProcess::ExitType() const;
 RProcess::ExitReason() const;
 RProcess::Id() const;
 RProcess::Terminate(TInt aReason);
 
 @SYMTestExpectedResults Proper creation and termination.\n

 */
void CT_ProcStep::testParentWithoutAChildL(void)
	{
	TInt ret(0)	;

	//process
	RProcess parentProc;
	ret = parentProc.Create(KParentExe,KNullDesC);
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupClosePushL(parentProc);
	INFO_PRINTF2(_L("	Create Parent Process returned : %d"),ret);

	TUint64 parentProcId=parentProc.Id();
	INFO_PRINTF2(_L("	Process Id = 0x%lx "),parentProcId);

	INFO_PRINTF1(_L("	Run the Process "));
	parentProc.Resume();
	//Time for the parent process to launch itself
	User::After(5000000);

	TExitType exitType = parentProc.ExitType();
	TEST(exitType == EExitKill||exitType == EExitPending);
	if(exitType==EExitPending)
		{
		INFO_PRINTF1(_L("	Process running normally "));
		parentProc.Terminate(KTProcTerminatingParent);
		exitType = parentProc.ExitType();
		TEST(exitType==EExitTerminate);
		TInt exitReason = parentProc.ExitReason();
		TEST(exitReason == KTProcTerminatingParent);
		INFO_PRINTF1(_L("	Terminating the process "));
		}
	CleanupStack::PopAndDestroy(&parentProc);
	}
Esempio n. 2
0
void CWsTop::SessionExited(CWsClient *aClient)
	{
	if (iShuttingDown)
		{
		RProcess proc;
		TInt err=aClient->Client().Process(proc);
		if (err==KErrNone && proc.Id()!=RProcess().Id())
			proc.Kill(0);
		else
			const_cast<RThread&>(aClient->Client()).Kill(0);
		if (err==KErrNone)
			proc.Close();
		}
	else if (iHeapCheckMode!=EWsCheckHeapOnDisconnectModeNone && aClient==iTriggerHeapCheckOnClientExit)
		{
		if (iHeapCheckMode==EWsCheckHeapOnDisconnectModeOnce)
			{
			iHeapCheckMode=EWsCheckHeapOnDisconnectModeNone;
			}
		iTriggerHeapCheckOnClientExit=NULL;
		iDoHeapCheckAndRestart=ETrue;
		Exit();
		}
	if (iServer->SessionCount()==1 && iShellBootMode==EShellBootModeNoReboot && iShell==NULL)
		StartShell();
	}
Esempio n. 3
0
// ----------------------------------------------------------------------------
// Helper to get the window group ID associated with a process
// ----------------------------------------------------------------------------
//
EXPORT_C TInt MPXUser::FindWindowGroupIdL(
    TProcessId aProcId,
    RWsSession& aWsSession )
    {
    TInt wgId( KErrNotFound );
    RArray<RWsSession::TWindowGroupChainInfo> windowArray;
    CleanupClosePushL( windowArray );
    aWsSession.WindowGroupList( &windowArray );
    TInt wgCount( windowArray.Count() );

    for ( TInt i = 0; i < wgCount && wgId == KErrNotFound; i++ )
        {
        TThreadId threadId;
        User::LeaveIfError(
            aWsSession.GetWindowGroupClientThreadId(
                windowArray[i].iId, threadId ) );
        RThread thread;
        CleanupClosePushL( thread );
        User::LeaveIfError( thread.Open( threadId ));
        RProcess proc;
        CleanupClosePushL( proc );
        User::LeaveIfError( thread.Process( proc ));
        if ( proc.Id() == aProcId )
            {
            wgId = windowArray[i].iId;
            }
        CleanupStack::PopAndDestroy( &proc );
        CleanupStack::PopAndDestroy( &thread );
        }
    CleanupStack::PopAndDestroy( &windowArray );
    return wgId;
    }
Esempio n. 4
0
TInt CSignalServer::CheckForCapability(const RMessage2& aMessage)
	{
	RThread lThread;
	RProcess lProcess;
	TInt lRetVal = KErrGeneral;

	TInt lPid = aMessage.Int0();
	TInt lSigNo = aMessage.Int1();

	if(lSigNo != SIGKILL && lSigNo != SIGSTOP)
		return KErrNone;

	lRetVal = aMessage.Client(lThread);
	if(lRetVal!= KErrNone)
		return lRetVal;
	lRetVal = lThread.Process(lProcess);
	if(lRetVal!= KErrNone)
		return lRetVal;

	if(!lProcess.HasCapability(ECapabilityPowerMgmt) && lPid!=lProcess.Id())
		lRetVal = KErrGeneral;
	else
		lRetVal = KErrNone;

	lThread.Close();
	lProcess.Close();
	return lRetVal;
	}
Esempio n. 5
0
LoggingState::LoggingState() {
  RProcess me;
  User::LeaveIfError(me.Open(me.Id()));
  process_name_ = me.Name().Left(50);
  me.Close();
  User::LeaveIfError(logger_.Connect());
  logger_.CreateLog(_L("textdump"), _L("log.txt"), EFileLoggingModeAppend);
}
Esempio n. 6
0
void CListsStep::ListProcessesL()
/**
 * @return void
 * This tests we can succesfully list the processes and that the returned values make sense
 */
	{
	INFO_PRINTF1(_L("Lists Test Suite: ListProcesses") );

	if (TestStepResult()==EPass)
		{

		RProcessPointerList procList;
		TCleanupItem cleanupProcList(CTe_coredumpserverSuite::CleanupProcessList, (TAny*)&procList);
		CleanupStack::PushL(cleanupProcList);

		TRAPD( ret, iSess.GetProcessesL( procList ) );

		if( KErrNone != ret )
			{
			SetTestStepResult(EFail);
			ERR_PRINTF2(_L("Error %d from iSess.GetProcessesL()"), ret);
			return;
			}

		if( procList.Count() == 0 )
			{
			SetTestStepResult(EFail);
			ERR_PRINTF1(_L("Error : GetProcessesL() returned empty list") );
			return;
			}
		else
			{
			RProcess thisProc;
			TInt i;
			for( i=0; i < procList.Count(); i++ )
				{
				if( procList[i]->Id() == thisProc.Id() )
					{
					break;
					}
				}

			if( i == procList.Count() )
				{
				SetTestStepResult(EFail);
				ERR_PRINTF1(_L("Error : This process could not be found in GetProcessesL() list") );
				return;
				}
			}

		CleanupStack::PopAndDestroy();
		}
	}
Esempio n. 7
0
// ----------------------------------------------------------------------------
// Determines the owning process id of the thread
// ----------------------------------------------------------------------------
//
EXPORT_C TProcessId MPXUser::ProcessIdL(TThreadId aId)
    {
    RThread t;
    User::LeaveIfError(t.Open(aId));
    CleanupClosePushL(t);
    RProcess p;
    User::LeaveIfError(t.Process(p));
    TProcessId pid=p.Id();
    p.Close();
    CleanupStack::PopAndDestroy(&t);
    return pid;
    }
Esempio n. 8
0
// ----------------------------------------------------------------------------
// Searches process id for target selector plugin.
// When the player has been opened in a mode, which is bound to the same engine
// than certain application's engine, then need to fetch its process id.
// (As a reference for parameter aMode see MMPXPlaybackUtility modes.)
// Otherwise target selector plugin is notified wrongly about registered client
// and key events are not propagated to correct application.
// ----------------------------------------------------------------------------
//
static void FindProcessIdForTsp( TInt aMode, TProcessId& aProcessId )
    {
    TBool processFound( EFalse );
    TFindProcess processFinder;
    TFullName processName;

    while ( processFinder.Next( processName ) == KErrNone && !processFound )
        {
        RProcess process;
        TInt err = process.Open( processFinder );
        if( err == KErrNone )
            {
            if( process.SecureId().iId == aMode && process.ExitType() == EExitPending )
                {
                MPX_DEBUG4("FindProcessIdForTsp(): pid changed from %d to %d (mode 0x%x)",
                           TUint(aProcessId), TUint(process.Id()), aMode);
                aProcessId = process.Id();
                processFound = ETrue;
                }
            process.Close();
            }
        }
    }
// -----------------------------------------------------------------------------
// CIAUpdateSelfUpdaterCtrl::StartUpdaterProcessL()
// 
// -----------------------------------------------------------------------------
//	
void CIAUpdateSelfUpdaterCtrl::StartUpdaterProcessL()
    {
    IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterCtrl::StartUpdaterProcessL begin");

    // Start IAD Update
    // The application is started here by using process handle. 
    // This way we get the process id, which is required for the 
    // rendezvous listener.
    RProcess process;
    CleanupClosePushL( process );
    // Create the process
    User::LeaveIfError( 
        process.Create( IAUpdaterDefs::KIAUpdaterExe, KNullDesC ) );
    RendezvousListener().StartL( process.Id() );
    // Start executing the process.
    process.Resume();
    CleanupStack::PopAndDestroy( &process );

    IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterCtrl::StartUpdaterProcessL end");
    }
Esempio n. 10
0
void CPolicyTest::ConstructL(const TTestActionSpec& aTestActionSpec)
	{
	CTestAction::ConstructL(aTestActionSpec);
	iExpectedResult = KErrNone;

	User::LeaveIfError(iFs.Connect());

	RProcess thisProcess;
	User::LeaveIfError(thisProcess.Open(thisProcess.Id()));
	iProcessSecureId = thisProcess.SecureId();
	iProcessVendorId = thisProcess.VendorId();
	thisProcess.Close();
	
	SetTestExeL(Input::ParseElement(aTestActionSpec.iActionBody, KTestExeStart));
	Input::ParseCapabilitySetL(Input::ParseElement(aTestActionSpec.iActionBody, KExcludedCapsStart), iExcludedCaps);
	SetPolicyL(Input::ParseElement(aTestActionSpec.iActionBody, KPolicyStart));
	iPreActions = Input::ParseElement(aTestActionSpec.iActionBody, KPreActionsStart).AllocL();
	SetTestActionL(Input::ParseElement(aTestActionSpec.iActionBody, KPassAcionStart),
				   Input::ParseElement(aTestActionSpec.iActionBody, KFailAcionStart));
	iPostActions = Input::ParseElement(aTestActionSpec.iActionBody, KPostActionsStart).AllocL();
	}
Esempio n. 11
0
void CSetClientUid::PerformAction(TRequestStatus& aStatus)
	{
	switch (iState)
		{
		case EMain:
			{
			RProcess thisProcess;
			thisProcess.Open(thisProcess.Id());
			CleanupClosePushL(thisProcess);
			TUidType type = thisProcess.Type();
			TUidType newType(type[0], type[1], iUid);
			thisProcess.SetType(newType);
			CleanupStack::PopAndDestroy(); // thisProcess
			
			iState = EFinished;
			TRequestStatus* status = &aStatus;
			User::RequestComplete(status, KErrNone);
			break;
			}

		case EFinished:
			{
			TRequestStatus* status = &aStatus;
			User::RequestComplete(status, aStatus.Int());
			if (aStatus == iExpectedResult)
				{
				iResult = ETrue;
				}
			else
				{
				iResult = EFalse;
				}
			
			iActionState = EPostrequisite;
			}
			break;
		}
	}
Esempio n. 12
0
EXPORT_C int spawnv(int mode,const char * path,const char **argv)
{
	TText16 iPath16[KMaxFileName];
	char replacePath[KMaxFileName];
	
	/* replace / with // */
	strcpy(replacePath,path);
	char *temp = strchr(replacePath,'/');
	while (temp)
	{
		*temp = '\\';
		temp = strchr(replacePath,'/');
	} // end while
	
	// convert narrow char to wide char
	if(mbstowcs((wchar_t *)iPath16, replacePath, strlen(replacePath)+1) == (size_t)(-1))
	{
			return -1;
	}
	
	TBuf16<KMaxFileName> iCmdName16;
	
	iCmdName16.FillZ(KMaxFileName);
	
	iCmdName16.Copy(iPath16);
	
	TInt i;
	
	TInt iVal = 0;
	
	while(argv[iVal])
	{
		iVal++;
	}	//end while
		
	
	TBuf16<MAX_COMMAND_LINE_LENGTH> iArgv16;
	
	iArgv16.FillZ(MAX_COMMAND_LINE_LENGTH);
	
	iArgv16.SetLength(0);
	
	for(i = 0; i < iVal ; i++)
	{
		TText16 temp[MAX_COMMAND_LINE_LENGTH];
		
		if(mbstowcs((wchar_t *)temp, argv[i], strlen(argv[i])+1) == (size_t)(-1))
		{
				return -1;
		}
		
		TPtrC16 iTemp(temp,strlen(argv[i]));
		
		iArgv16.Append(iTemp);
		
		if(i != iVal-1)
			iArgv16.Append(L' ');
		
	} // end for
	
	RProcess iProcess;
	TRequestStatus iStatus;
	TInt iRetVal = iProcess.Create(iCmdName16,iArgv16);
		
	if(iRetVal != KErrNone)
	{
		switch(iRetVal)
		{
			case KErrNotFound : 	errno = ENOENT;
									break;
			case KErrNoMemory : 	errno = ENOMEM ;
									break;
			case KErrNotSupported : errno = ENOEXEC;
									break;
			case KErrBadName : 		errno = ENAMETOOLONG;
									break;
			default:   	 	 		break;
		}
		
		return -1;
	}
	
	if(mode == P_WAIT)
	{
		iProcess.Logon(iStatus);
		iProcess.Resume();
 		User::WaitForRequest(iStatus);
 		iProcess.Close();
 		return iStatus.Int();
	}
	else
	{
		iProcess.Resume();	
		return iProcess.Id();	
	}
}
Esempio n. 13
0
/**
 @SYMTestCaseID	APPFWK-APPARC-0015

 @SYMPREQ	PREQ1123

 @SYMTestCaseDesc The Test determines that the Child dies when its Parent is terminated.

 @SYMTestPriority Critical

 @SYMTestStatus Implemented

 @SYMTestActions. Creates and launches a process (parent). Creates another process (child) passing the first(parent) process ID.
 Launches the child process. Terminates parent and checks the existance of child process. The child should die.
 API Calls:\n
 RProcess::Create(const TDesC &aFileName, const TDesC &aCommand, TOwnerType aType=EOwnerProcess);\n
 RProcess::Resume();
 RProcess::ExitType() const;
 RProcess::ExitReason() const;
 RProcess::Id() const;
 CApaCommandLine::SetProcessEnvironmentL(RProcess &aProcess) const;
 CApaCommandLine::NewLC();
 CApaCommandLine::SetParentProcessId(TProcessId);

 @SYMTestExpectedResults Termination of child process automatically.\n

 */
void CT_ProcStep::testChildSetToTerminateL(void)
	{
	TInt ret(0);

	//commandline for parent process
	CApaCommandLine* parentProcCmdln=CApaCommandLine::NewLC();
	INFO_PRINTF1(_L("	CommandLine for Parent Process created "));

	//parent process
	RProcess parentProc;
	ret = parentProc.Create(KParentExe,KNullDesC);
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupClosePushL(parentProc);
	INFO_PRINTF2(_L("	Create Parent Process returned : %d"),ret);

	//attach commandline to parent process
	TRAP(ret,parentProcCmdln->SetProcessEnvironmentL(parentProc));
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	INFO_PRINTF1(_L("	Attach CommandLine to Process "));

	INFO_PRINTF1(_L("	Run Parent Process "));
	parentProc.Resume();
	//Time for the parent process to launch itself
	User::After(500000);

	//commandline for child process
	//Get parent process ID here
	TUint64 parentProcId = parentProc.Id();
	INFO_PRINTF2(_L("	Parent Process Id = 0x%lx "),parentProcId);

	CApaCommandLine* childProcCmdln=CApaCommandLine::NewLC();
	INFO_PRINTF1(_L("	CommandLine for Child Process created "));

	//setting the parent process ID to child
	childProcCmdln->SetParentProcessId(parentProcId);
	INFO_PRINTF1(_L("	Set ParentProcessId to Child "));

	//child process
	RProcess childProc;
	ret = childProc.Create(KChildOneExe,KNullDesC);
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupClosePushL(childProc);
	
	INFO_PRINTF2(_L("	Create Child Process returned : %d"),ret);

	//attach commandline to child process
	TRAP(ret,childProcCmdln->SetProcessEnvironmentL(childProc));
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	INFO_PRINTF1(_L("	Attach CommandLine to Process "));

	INFO_PRINTF1(_L("	Run Child Process "));
	childProc.Resume();
	//Time for the child process to launch itself
	User::After(500000);

	//child process Id is reqd to monitor if it gets killed on its parent's termination
	TUint64 childProcId = childProc.Id();
	INFO_PRINTF2(_L("	Child Process Id = 0x%lx "),childProcId);

	CChildProcess* childProcess=NULL;
	TRAP(ret, childProcess=CChildProcess::NewL(parentProc,childProcId));
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupStack::PushL(childProcess);

	TExitType exitType = parentProc.ExitType();
	TEST(exitType == EExitTerminate);
	TInt exitReason = parentProc.ExitReason();
	TEST(exitReason == 0);
	if(exitType==EExitTerminate && exitReason==0)
		{
		INFO_PRINTF1(_L("	Parent process is Terminated"));
		}
	
	exitType = childProc.ExitType();
	TEST(exitType == EExitTerminate);
	exitReason = childProc.ExitReason();
	TEST(exitReason == 0);
	if(exitType == EExitTerminate && exitReason==0)
		{
		INFO_PRINTF1(_L("	The child process is killed automatically ... "));
		}

	CleanupStack::PopAndDestroy(childProcess);
	CleanupStack::PopAndDestroy(&childProc);
	CleanupStack::PopAndDestroy(childProcCmdln);
	CleanupStack::PopAndDestroy(&parentProc);
	CleanupStack::PopAndDestroy(parentProcCmdln);
	}
Esempio n. 14
0
/**
 @SYMTestCaseID APPFWK-APPARC-0017

 @SYMPREQ PREQ1123

 @SYMTestCaseDesc Test determines that one Child remains and another terminates when their Parent terminates, based on their creation.

 @SYMTestPriority High

 @SYMTestStatus Implemented

 @SYMTestActions. Creates and launches a process (parent). Creates a process (child I) passing the first (parent) process ID.
 Creates a second process (child II) without passing the first (parent) process ID. Launches both the child processes.
 Terminates parent and checks the existance of both the child processes. Child I should die and Child II should remain alive.
 API Calls:\n
 RProcess::Create(const TDesC &aFileName, const TDesC &aCommand, TOwnerType aType=EOwnerProcess);\n
 RProcess::Resume();
 RProcess::ExitType() const;
 RProcess::ExitReason() const;
 RProcess::Id() const;
 RProcess::Terminate(TInt aReason);
 CApaCommandLine::SetProcessEnvironmentL(RProcess &aProcess) const;
 CApaCommandLine::NewLC();
 CApaCommandLine::SetParentProcessId(TProcessId);
 
 @SYMTestExpectedResults Termination of first child process and existence of the second.\n

 */
void CT_ProcStep::testTwoChildsOneToTerminateAndOtherToRemainL(void)
	{
	TInt ret(0);
	TExitType exitType;

	//commandline for parent process
	CApaCommandLine* parentProcCmdln=CApaCommandLine::NewLC();
	INFO_PRINTF1(_L("	CommandLine for Parent Process created "));

	//parent process
	RProcess parentProc;
	ret = parentProc.Create(KParentExe,KNullDesC);
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupClosePushL(parentProc);
	INFO_PRINTF2(_L("	Create Parent Process returned : %d"),ret);

	//attach commandline to parent process
	TRAP(ret,parentProcCmdln->SetProcessEnvironmentL(parentProc));
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	INFO_PRINTF1(_L("	Attach CommandLine to Process "));

	INFO_PRINTF1(_L("	Run Parent Process "));
	parentProc.Resume();
	//Time for the parent process to launch itself
	User::After(500000);

	//commandline for child process
	//Get parent process ID here
	TUint64 parentProcId = parentProc.Id();
	INFO_PRINTF2(_L("	Parent Process Id = 0x%lx"),parentProcId);

	//For Child ONE
	CApaCommandLine* childProcOneCmdln=CApaCommandLine::NewLC();
	INFO_PRINTF1(_L("	CommandLine for Child One created "));

	//setting the parent process ID to child I
	childProcOneCmdln->SetParentProcessId(parentProcId);
	INFO_PRINTF1(_L("	Set ParentProcessId to Child One "));

	//child process ONE
	RProcess childProcOne;
	ret = childProcOne.Create(KChildOneExe,KNullDesC);
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupClosePushL(childProcOne);
	
	INFO_PRINTF2(_L("	Create Child One returned : %d"),ret);

	//attach commandline to child process
	TRAP(ret,childProcOneCmdln->SetProcessEnvironmentL(childProcOne));
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	INFO_PRINTF1(_L("	Attach CommandLine of Child One to its Process "));

	INFO_PRINTF1(_L("	Run Child One "));
	childProcOne.Resume();
	//Time for the child one to launch itself
	User::After(500000);

	//child process Id is reqd to monitor if it gets killed on its parent's termination
	TUint64 childProcOneId = childProcOne.Id();
	INFO_PRINTF2(_L("	Child One Id = 0x%lx "),childProcOneId);

	//For Child TWO
	CApaCommandLine* childProcTwoCmdln=CApaCommandLine::NewLC();
	INFO_PRINTF1(_L("	CommandLine for Child Two created "));

	//child process TWO
	RProcess childProcTwo;
	ret = childProcTwo.Create(KChildTwoExe,KNullDesC);
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupClosePushL(childProcTwo);
	
	INFO_PRINTF2(_L("	Create Child Two returned : %d"),ret);

	//attach commandline to child process
	TRAP(ret,childProcTwoCmdln->SetProcessEnvironmentL(childProcTwo));
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	INFO_PRINTF1(_L("	Attach CommandLine of Child Two to its Process "));

	INFO_PRINTF1(_L("	Run Child Two "));
	childProcTwo.Resume();
	//Time for the child one to launch itself
	User::After(500000);

	//child II process Id is reqd to monitor if it gets killed on its parent's termination
	TUint64 childProcTwoId = childProcTwo.Id();
	INFO_PRINTF2(_L("	Child Two Id = 0x%lx "),childProcTwoId);

	CChildProcess* childProcess=NULL;
	TRAP(ret, childProcess=CChildProcess::NewL(parentProc,childProcOneId));
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupStack::PushL(childProcess);

	exitType = parentProc.ExitType();
	TEST(exitType == EExitTerminate);
	TInt exitReason = parentProc.ExitReason();
	TEST(exitReason == 0);
	if(exitType==EExitTerminate && exitReason==0)
		{
		INFO_PRINTF1(_L("	Parent process is Terminated"));
		}
	
	exitType = childProcOne.ExitType();
	TEST(exitType == EExitTerminate);
	exitReason = childProcOne.ExitReason();
	TEST(exitReason == 0);
	if(exitType==EExitTerminate && exitReason==0)
		{
		INFO_PRINTF1(_L("	Child I is killed automatically ... "));
		}

	//Wait and see if child II terminates automatically...
	User::After(10000000);

	exitType = childProcTwo.ExitType();
	TEST(exitType == EExitPending);
	if(exitType==EExitPending)
		{
		INFO_PRINTF1(_L("	Child II running successfully"));
		childProcTwo.Terminate(KTProcTerminatingChildII);
		exitType = childProcTwo.ExitType();
		TEST(exitType==EExitTerminate);
		exitReason = childProcTwo.ExitReason();
		TEST(exitReason == KTProcTerminatingChildII);
		INFO_PRINTF1(_L("	So Terminated it manually ..."));
		}

	CleanupStack::PopAndDestroy(childProcess);
	CleanupStack::PopAndDestroy(&childProcTwo);
	CleanupStack::PopAndDestroy(childProcTwoCmdln);
	CleanupStack::PopAndDestroy(&childProcOne);
	CleanupStack::PopAndDestroy(childProcOneCmdln);
	CleanupStack::PopAndDestroy(&parentProc);
	CleanupStack::PopAndDestroy(parentProcCmdln);
	}
Esempio n. 15
0
/**
 @SYMTestCaseID APPFWK-APPARC-0019

 @SYMPREQ PREQ1123

 @SYMTestCaseDesc The Test determines that more than one Child for a parent terminate on their Parent's termination.

 @SYMTestPriority Medium

 @SYMTestStatus Implemented

 @SYMTestActions. Creates and launches a process (parent). Creates 3 processes (child I,II,III) passing the first (parent) process ID.
 Launches all the 3 processes. Terminates parent and checks the existance of the child processes. All 3 children should die.
 API Calls:\n
 RProcess::Create(const TDesC &aFileName, const TDesC &aCommand, TOwnerType aType=EOwnerProcess);\n
 RProcess::Resume();
 RProcess::ExitType() const;
 RProcess::ExitReason() const;
 RProcess::Id() const;
 RProcess::Terminate(TInt aReason);
 CApaCommandLine::SetProcessEnvironmentL(RProcess &aProcess) const;
 CApaCommandLine::NewLC();
 CApaCommandLine::SetParentProcessId(TProcessId);
 
 @SYMTestExpectedResults Termination of all child processes automatically.\n

 */
void CT_ProcStep::testAllChildsSetToTerminateL(void)
	{
	TInt ret(0);

	//commandline for parent process
	CApaCommandLine* parentProcCmdln=CApaCommandLine::NewLC();
	INFO_PRINTF1(_L("	CommandLine for Parent Process created "));

	//parent process
	RProcess parentProc;
	ret = parentProc.Create(KParentExe,KNullDesC);
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupClosePushL(parentProc);
	INFO_PRINTF2(_L("	Create Parent Process returned : %d"),ret);

	//attach commandline to parent process
	TRAP(ret,parentProcCmdln->SetProcessEnvironmentL(parentProc));
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	INFO_PRINTF1(_L("	Attach CommandLine to Process "));

	INFO_PRINTF1(_L("	Run Parent Process "));
	parentProc.Resume();
	//Time for the parent process to launch itself
	User::After(500000);

	//Get parent process ID here
	TUint64 parentProcId = parentProc.Id();
	INFO_PRINTF2(_L("	Parent Process Id = 0x%lx "),parentProcId);

	//Child I
	CApaCommandLine* childProcOneCmdln=CApaCommandLine::NewLC();
	INFO_PRINTF1(_L("	CommandLine for Child One created "));

	//setting the parent process ID to child
	childProcOneCmdln->SetParentProcessId(parentProcId);
	INFO_PRINTF1(_L("	Set ParentProcessId to Child One "));

	//Child process I
	RProcess childProcOne;
	ret = childProcOne.Create(KChildOneExe,KNullDesC);
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupClosePushL(childProcOne);
	
	INFO_PRINTF2(_L("	Create Child One returned : %d"),ret);

	//attach commandline to child process
	TRAP(ret,childProcOneCmdln->SetProcessEnvironmentL(childProcOne));
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	INFO_PRINTF1(_L("	Attach CommandLine of Child One to its Process "));

	INFO_PRINTF1(_L("	Run Child One "));
	TRequestStatus childOnestatus;
	childProcOne.Rendezvous(childOnestatus);
	childProcOne.Resume();
	//Wait for the child process to launch itself
	User::WaitForRequest(childOnestatus);

	//child process Id is reqd to monitor if it gets killed on its parent's termination
	TUint64 childProcOneId = childProcOne.Id();
	INFO_PRINTF2(_L("	Child One Id = 0x%lx "),childProcOneId);

	//Child II
	CApaCommandLine* childProcTwoCmdln=CApaCommandLine::NewLC();
	INFO_PRINTF1(_L("	CommandLine for Child Two created "));

	//setting the parent process ID to child
	childProcTwoCmdln->SetParentProcessId(parentProcId);
	INFO_PRINTF1(_L("	Set ParentProcessId to Child Two "));

	//child process II
	RProcess childProcTwo;
	ret = childProcTwo.Create(KChildTwoExe,KNullDesC);
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupClosePushL(childProcTwo);
	
	INFO_PRINTF2(_L("	Create Child Two returned : %d"),ret);

	//attach commandline to child process
	TRAP(ret,childProcTwoCmdln->SetProcessEnvironmentL(childProcTwo));
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	INFO_PRINTF1(_L("	Attach CommandLine of Child Two to its Process "));

	INFO_PRINTF1(_L("	Run Child Two "));
	TRequestStatus childTwostatus;
	childProcTwo.Rendezvous(childTwostatus);
	childProcTwo.Resume();
	//Wait for the child process to launch itself
	User::WaitForRequest(childTwostatus);

	//child process Id is reqd to monitor if it gets killed on its parent's termination
	TUint64 childProcTwoId = childProcTwo.Id();
	INFO_PRINTF2(_L("	Child Two Id = 0x%lx "),childProcTwoId);

	//Child III
	CApaCommandLine* childProcThreeCmdln=CApaCommandLine::NewLC();
	INFO_PRINTF1(_L("	CommandLine for Child Three created "));

	//setting the parent process ID to child
	childProcThreeCmdln->SetParentProcessId(parentProcId);
	INFO_PRINTF1(_L("	Set ParentProcessId to Child Three "));

	//child process III
	RProcess childProcThree;
	ret = childProcThree.Create(KChildThreeExe,KNullDesC);
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupClosePushL(childProcThree);
	
	INFO_PRINTF2(_L("	Create Child Three returned : %d"),ret);

	//attach commandline to child process
	TRAP(ret,childProcThreeCmdln->SetProcessEnvironmentL(childProcThree));
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	INFO_PRINTF1(_L("	Attach CommandLine of Child Three to its Process "));

	TRequestStatus childThreestatus;
	childProcThree.Rendezvous(childThreestatus);
	childProcThree.Resume();

	//Wait for the child process to launch itself
	User::WaitForRequest(childThreestatus);

	//child process Id is reqd to monitor if it gets killed on its parent's termination
	TUint64 childProcThreeId = childProcThree.Id();
	INFO_PRINTF2(_L("	Child Three Id = 0x%lx "),childProcThreeId);

	CChildProcess* childProcess=NULL;
	TRAP(ret, childProcess=CChildProcess::NewL(parentProc,childProcOneId));
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupStack::PushL(childProcess);

	TExitType exitType = parentProc.ExitType();
	TEST(exitType == EExitTerminate);
	TInt exitReason = parentProc.ExitReason();
	TEST(exitReason == 0);
	INFO_PRINTF3(_L("	Parent process - Exit Type = %d, Exit Reason = %d"), exitType, exitReason);
	if(exitType == EExitTerminate && exitReason == 0)
		{
		INFO_PRINTF1(_L("	Parent process is Terminated "));
		}

	exitType = childProcOne.ExitType();
	TEST(exitType == EExitTerminate);
	exitReason = childProcOne.ExitReason();
	TEST(exitReason == 0);
	INFO_PRINTF3(_L("	Child I process - Exit Type = %d, Exit Reason = %d"), exitType, exitReason);
	if(exitType == EExitTerminate && exitReason == 0)
		{
		INFO_PRINTF1(_L("	Child I is killed "));
		}
	
	childProcTwo.Logon(childTwostatus);
	User::WaitForRequest(childTwostatus);
	exitType = childProcTwo.ExitType();
	TEST(exitType == EExitTerminate);
	exitReason = childProcTwo.ExitReason();
	TEST(exitReason == 0);
	INFO_PRINTF3(_L("	Child II process - Exit Type = %d, Exit Reason = %d"), exitType, exitReason);
	if(exitType == EExitTerminate && exitReason == 0)
		{
		INFO_PRINTF1(_L("	Child II is killed "));
		}

	//Wait to close the child process
	childProcThree.Logon(childThreestatus);
	User::WaitForRequest(childThreestatus);
	exitType = childProcThree.ExitType();
	TEST(exitType == EExitTerminate);
	exitReason = childProcThree.ExitReason();
	TEST(exitReason == 0);
	INFO_PRINTF3(_L("	Child III process - Exit Type = %d, Exit Reason = %d"), exitType, exitReason);
	if(exitType == EExitTerminate && exitReason == 0)
		{
		INFO_PRINTF1(_L("	Child III is killed "));
		}

	CleanupStack::PopAndDestroy(childProcess);
	CleanupStack::PopAndDestroy(&childProcThree);
	CleanupStack::PopAndDestroy(childProcThreeCmdln);
	CleanupStack::PopAndDestroy(&childProcTwo);
	CleanupStack::PopAndDestroy(childProcTwoCmdln);
	CleanupStack::PopAndDestroy(&childProcOne);
	CleanupStack::PopAndDestroy(childProcOneCmdln);
	CleanupStack::PopAndDestroy(&parentProc);
	CleanupStack::PopAndDestroy(parentProcCmdln);
	}
Esempio n. 16
0
/**
 @SYMTestCaseID APPFWK-APPARC-0020

 @SYMPREQ PREQ1123

 @SYMTestCaseDesc The Test determines that more than one Child for a Parent remain alive on their parent's termination.

 @SYMTestPriority Medium

 @SYMTestStatus Implemented

 @SYMTestActions. Creates and launches a process (parent). Creates 3 processes (child I,II,III) without passing the first (parent) process ID.
 Launches all the 3 processes. Terminates parent and checks the existance of the child processes. All 3 children should remain alive.
 API Calls:\n
 RProcess::Create(const TDesC &aFileName, const TDesC &aCommand, TOwnerType aType=EOwnerProcess);\n
 RProcess::Resume();
 RProcess::ExitType() const;
 RProcess::ExitReason() const;
 RProcess::Id() const;
 RProcess::Terminate(TInt aReason);
 CApaCommandLine::SetProcessEnvironmentL(RProcess &aProcess) const;
 CApaCommandLine::NewLC();
 
 @SYMTestExpectedResults Existence of all child processes.\n

 */
void CT_ProcStep::testNoChildSetToTerminateL(void)
	{
	TInt ret(0);

	//commandline for parent process
	CApaCommandLine* parentProcCmdln=CApaCommandLine::NewLC();
	INFO_PRINTF1(_L("	CommandLine for Parent Process created "));

	//parent process
	RProcess parentProc;
	ret = parentProc.Create(KParentExe,KNullDesC);
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupClosePushL(parentProc);
	INFO_PRINTF2(_L("	Create Parent Process returned : %d"),ret);

	//attach commandline to parent process
	TRAP(ret,parentProcCmdln->SetProcessEnvironmentL(parentProc));
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	INFO_PRINTF1(_L("	Attach CommandLine to Process "));

	INFO_PRINTF1(_L("	Run Parent Process "));
	parentProc.Resume();
	//Time for the parent process to launch itself
	User::After(500000);

	//commandline for child process
	//Get parent process ID here
	TUint64 parentProcId = parentProc.Id();
	INFO_PRINTF2(_L("	Parent Process Id = 0x%lx "),parentProcId);

	//Child I
	CApaCommandLine* childProcOneCmdln=CApaCommandLine::NewLC();
	INFO_PRINTF1(_L("	CommandLine for Child One created "));

	//child process
	RProcess childProcOne;
	ret = childProcOne.Create(KChildOneExe,KNullDesC);
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupClosePushL(childProcOne);
	
	INFO_PRINTF2(_L("	Create Child One returned : %d"),ret);

	//attach commandline to child process
	TRAP(ret,childProcOneCmdln->SetProcessEnvironmentL(childProcOne));
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	INFO_PRINTF1(_L("	Attach CommandLine of Child One to its Process "));

	childProcOne.Resume();

	//Time for the child process to launch itself
	User::After(1000000);

	//child process Id is reqd to monitor if it gets killed on its parent's termination
	TUint64 childProcOneId = childProcOne.Id();
	INFO_PRINTF2(_L("	Child Process Id = 0x%lx "),childProcOneId);

	//Child II
	CApaCommandLine* childProcTwoCmdln=CApaCommandLine::NewLC();
	INFO_PRINTF1(_L("	CommandLine for Child Two created "));

	//child process
	RProcess childProcTwo;
	ret = childProcTwo.Create(KChildTwoExe,KNullDesC);
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupClosePushL(childProcTwo);
	
	INFO_PRINTF2(_L("	Create Child Two returned : %d "),ret);

	//attach commandline to child process
	TRAP(ret,childProcTwoCmdln->SetProcessEnvironmentL(childProcTwo));
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	INFO_PRINTF1(_L("	Attach CommandLine of Child Two to its Process "));

	INFO_PRINTF1(_L("	Run Child Two "));
	childProcTwo.Resume();
	//Time for the child process to launch itself
	User::After(1000000);

	//child process Id is reqd to monitor if it gets killed on its parent's termination
	TUint64 childProcTwoId = childProcTwo.Id();
	INFO_PRINTF2(_L("	Child Two Id = 0x%lx "),childProcTwoId);

	//Child III
	CApaCommandLine* childProcThreeCmdln=CApaCommandLine::NewLC();
	INFO_PRINTF1(_L("	CommandLine for Child Three created "));

	//child process
	RProcess childProcThree;
	ret = childProcThree.Create(KChildThreeExe,KNullDesC);
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupClosePushL(childProcThree);
	
	INFO_PRINTF2(_L("	Create Child Three returned : %d"),ret);

	//attach commandline to child process
	TRAP(ret,childProcThreeCmdln->SetProcessEnvironmentL(childProcThree));
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	INFO_PRINTF1(_L("	Attach CommandLine of Child Three to its Process "));

	childProcThree.Resume();

	//Time for the child process to launch itself
	User::After(1000000);

	//child process Id is reqd to monitor if it gets killed on its parent's termination
	TUint64 childProcThreeId = childProcThree.Id();
	INFO_PRINTF2(_L("	Child Three Id = 0x%lx "),childProcThreeId);

	parentProc.Terminate(KTProcTerminatingParent);
	TExitType exitType = parentProc.ExitType();
	TEST(exitType == EExitTerminate);
	TInt exitReason = parentProc.ExitReason();
	TEST(exitReason == KTProcTerminatingParent);
	INFO_PRINTF1(_L("	Terminating parent process "));

	//Time for the child processes to terminate if they really do
	User::After(500000);

	exitType = childProcOne.ExitType();
	TEST(exitType == EExitPending);
	if(exitType == EExitPending)
		{
		INFO_PRINTF1(_L("	Child I is still running "));
		INFO_PRINTF1(_L("	So Terminating it manually ... "));
		childProcOne.Terminate(KTProcTerminatingChildI);
		exitType = childProcOne.ExitType();
		TEST(exitType==EExitTerminate);
		exitReason = childProcOne.ExitReason();
		TEST(exitReason == KTProcTerminatingChildI);
		}

	exitType = childProcTwo.ExitType();
	TEST(exitType == EExitPending);
	if(exitType == EExitPending)
		{
		INFO_PRINTF1(_L("	Child II is still running "));
		INFO_PRINTF1(_L("	So Terminating it manually ... "));
		childProcTwo.Terminate(KTProcTerminatingChildII);
		exitType = childProcTwo.ExitType();
		TEST(exitType==EExitTerminate);
		exitReason = childProcTwo.ExitReason();
		TEST(exitReason == KTProcTerminatingChildII);
		}

	exitType = childProcThree.ExitType();
	TEST(exitType == EExitPending);
	if(exitType == EExitPending)
		{
		INFO_PRINTF1(_L("	Child III is still running "));
		INFO_PRINTF1(_L("	So Terminating it manually ... "));
		childProcThree.Terminate(KTProcTerminatingChildIII);
		exitType = childProcThree.ExitType();
		TEST(exitType==EExitTerminate);
		exitReason = childProcThree.ExitReason();
		TEST(exitReason == KTProcTerminatingChildIII);
		}

	CleanupStack::PopAndDestroy(&childProcThree);
	CleanupStack::PopAndDestroy(childProcThreeCmdln);
	CleanupStack::PopAndDestroy(&childProcTwo);
	CleanupStack::PopAndDestroy(childProcTwoCmdln);
	CleanupStack::PopAndDestroy(&childProcOne);
	CleanupStack::PopAndDestroy(childProcOneCmdln);
	CleanupStack::PopAndDestroy(&parentProc);
	CleanupStack::PopAndDestroy(parentProcCmdln);
	}
// ----------------------------------------------------------------------------------------
// CTerminalControlServer::GetRunningProcessesL
// ----------------------------------------------------------------------------------------
CBufFlat* CTerminalControlServer::GetRunningProcessesL( )
{
    RDEBUG("CTerminalControlServer::GetRunningProcessesL");

    TFullName    processName;
    TFindProcess findProcess;
    CBufFlat *buffer = CBufFlat::NewL(128);
    iProcessInfoArray->Reset();

    while( KErrNone == findProcess.Next( processName ) )
    {
        TTcProcessInfo info;
        RProcess process;

        if( KErrNone == process.Open( findProcess ) )
        {
            //
            // Add process information to local array
            //
            info.iProcessName = processName;
            info.iFileName    = process.FileName();

            info.iHandle      = process.Handle();
            info.iId          = process.Id();
            info.iSecureId    = process.SecureId();

            info.iProtected   = EFalse;

            process.GetMemoryInfo( info.iMemoryInfo );

            User::IsRomAddress( info.iCodeInRom, (TAny*)(info.iMemoryInfo.iCodeBase) );
            if( !info.iCodeInRom )
            {
                User::IsRomAddress( info.iCodeInRom, (TAny*)(info.iMemoryInfo.iCodeBase) );
            }

            iProcessInfoArray->AppendL( info );

            //
            // Add process also to return buffer
            //
            /*
            TInt appendPosition = buffer->Size();
            if(iProcessInfoArray->Count() >= 2)
                {
                TBuf8<sizeof(info.iProcessName)> proName;
                proName.Copy(info.iProcessName);
                buffer->InsertL(appendPosition, _L8("/"));
                buffer->InsertL(appendPosition+1, proName);
                }
            else
                {
                TBuf8<sizeof(info.iProcessName)> proName;
                proName.Copy(info.iProcessName);
                buffer->InsertL(appendPosition, proName);
                }
            }

            */

            // Enumerate names from 1
            TInt appendPosition = buffer->Size();
            TBuf8<MAX_NUMBER_OF_DIGITS_IN_10BASE_INT64> numBuf;
            TBuf8<sizeof(KFormatProcessNamePrefix)+20> nameBuf;

            numBuf.Num(iProcessInfoArray->Count());
            nameBuf.Zero();
            nameBuf.Append(KFormatProcessNamePrefix);
            nameBuf.Append(numBuf);

            if(iProcessInfoArray->Count() >= 2)
            {
                buffer->InsertL(appendPosition, _L8("/"));
                buffer->InsertL(appendPosition+1, nameBuf);
            }
            else
            {
                buffer->InsertL(appendPosition, nameBuf);
            }
        }
    }
    /*
    	TUint32 flags = Exec::ProcessFlags(KCurrentProcessHandle);
    	if (flags & KProcessFlagSystemPermanent)
    		return ESystemPermanent;
    	if (flags & KProcessFlagSystemCritical)
    		return ESystemCritical;
    	if (flags & KThreadFlagProcessPermanent)
    		return EAllThreadsCritical;
    	return ENotCritical;
    */
    return buffer;
}
Esempio n. 18
0
/**
 @SYMTestCaseID APPFWK-APPARC-0022

 @SYMPREQ PREQ1123

 @SYMTestCaseDesc The Test determines that the child doesn't receive its parent process ID correctly, when not set during its creation.

 @SYMTestPriority Medium

 @SYMTestStatus Implemented

 @SYMTestActions. Creates and launches a process (parent). Creates another process (child) without setting any parent.
 Parent Process Id is passed to child through SetParameter API. Launches the child process. Child obtains the parent process Id from within.
 Child compares both the Id's. The Id's should not match each other.
 API Calls:\n
 RProcess::Create(const TDesC &aFileName, const TDesC &aCommand, TOwnerType aType=EOwnerProcess);\n
 RProcess::Resume();
 RProcess::ExitType() const;
 RProcess::ExitReason() const;
 RProcess::Id() const;
 RProcess::SetParameter(TInt aSlot, TInt aData);
 CApaCommandLine::SetProcessEnvironmentL(RProcess &aProcess) const;
 CApaCommandLine::NewLC();
 RFile::Open(RFs &aFs, const TDesC &aName, TUint aFileMode);
 RFile::Read(TInt aPos, TDes8 &aDes) const;
 RFile::Close();
 RFs::Connect(TInt aMessageSlots=KFileServerDefaultMessageSlots);
 RFs::Delete(const TDesC &aName);
 RFs::Close();
 @SYMTestExpectedResults Id received by child process should not match its parent process Id.\n

 */
void CT_ProcStep::testIdNotAvailableToChildL(void)
	{
	TInt ret(0);
	TInt exitReason(0);
	
	//commandline for parent process
	CApaCommandLine* parentProcCmdln=CApaCommandLine::NewLC();
	INFO_PRINTF1(_L("	CommandLine for Parent Process created "));

	//parent process
	RProcess parentProc;
	ret = parentProc.Create(KParentExe,KNullDesC);
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupClosePushL(parentProc);
	INFO_PRINTF2(_L("	Create Parent Process returned : %d"),ret);

	//attach commandline to parent process
	TRAP(ret,parentProcCmdln->SetProcessEnvironmentL(parentProc));
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	INFO_PRINTF1(_L("	Attach CommandLine to Process "));

	INFO_PRINTF1(_L("	Run Parent Process "));
	parentProc.Resume();
	//Time for the parent process to launch itself
	User::After(500000);

	//commandline for child process
	//Get parent process ID here
	TUint64 parentProcId = parentProc.Id();
	INFO_PRINTF2(_L("	Parent Process Id = 0x%lx "),parentProcId);

	CApaCommandLine* childProcCmdln=CApaCommandLine::NewLC();
	INFO_PRINTF1(_L("	CommandLine for Child Process created "));
	
	//child process
	RProcess childProc;
	ret = childProc.Create(KChildThreeExe,KNullDesC);
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupClosePushL(childProc);
	
	INFO_PRINTF2(_L("	Create Child Process returned : %d"),ret);

	//attach commandline to child process
	TRAP(ret,childProcCmdln->SetProcessEnvironmentL(childProc));
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	INFO_PRINTF1(_L("	Attach CommandLine to Process "));

	//Setting the parent process Id in an environment slot for the child to receive.
	ret = childProc.SetParameter(12,parentProcId);
	TEST(ret == KErrNone);
	INFO_PRINTF2(_L("	Set the Parent Process Id - 0x%lx to Child through SetParameter API in Slot 12 "),parentProcId);

	INFO_PRINTF1(_L("	Run Child Process "));
	TRequestStatus status;
	childProc.Rendezvous(status);
	childProc.Resume();
	//Wait for the child process to launch itself
	User::WaitForRequest(status);

	RFs fs;
	RFile file;
	ret = fs.Connect();
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	INFO_PRINTF1(_L("	Create File server session "));

	ret = file.Open(fs,KFilePath,EFileWrite | EFileShareAny);
	TEST(ret == KErrNone);
	if(ret == KErrNone)
		{
		INFO_PRINTF1(_L("	File opened successfully "));
		TBuf8<5> readData;
		file.Read(0,readData);
		TBuf8<5> result(KTResultFail); 
		TEST(result==readData);
		if(result==readData)
			{
			INFO_PRINTF1(_L("	Child did not receive the parent process ID as intended..."));
			}
		else
			{
			INFO_PRINTF1(_L("	Child received the Wrong parent process ID ..."));
			}
		file.Close();
		fs.Delete(KFilePath);
		fs.Close();
		INFO_PRINTF1(_L("	File Close & Delete and Session Close "));
		}

	TExitType exitType = parentProc.ExitType();
	TEST(exitType == EExitPending);
	if(exitType == EExitPending)
		{
		INFO_PRINTF1(_L("	Parent is still running "));
		INFO_PRINTF1(_L("	So Terminating it manually ... "));
		parentProc.Terminate(KTProcTerminatingParent);
		exitType = parentProc.ExitType();
		TEST(exitType==EExitTerminate);
		exitReason = parentProc.ExitReason();
		TEST(exitReason == KTProcTerminatingParent);
		}

	exitType = childProc.ExitType();
	TEST(exitType == EExitPending);
	if(exitType == EExitPending)
		{
		INFO_PRINTF1(_L("	Child is still running "));
		INFO_PRINTF1(_L("	So Terminating it manually ... "));
		childProc.Terminate(KTProcTerminatingChildIII);
		exitType = childProc.ExitType();
		TEST(exitType==EExitTerminate);
		exitReason = childProc.ExitReason();
		TEST(exitReason == KTProcTerminatingChildIII);
		}

	CleanupStack::PopAndDestroy(&childProc);
	CleanupStack::PopAndDestroy(childProcCmdln);
	CleanupStack::PopAndDestroy(&parentProc);
	CleanupStack::PopAndDestroy(parentProcCmdln);
	}
Esempio n. 19
0
void CSignalServer::ServiceL(const RMessage2& aMessage)
	{
	TInt lPid = 0;
	TOeProcessHdl lTmpHdl;
	TInt lIndex = 0;
	TUint8 lSignal = 0;
	RThread lClientThread;
	RProcess lProcess;

	switch (aMessage.Function ())
		{
		//if this query is related to message Q, call
		//ServiceL of message Q handler
		case ESendSignal:
			if(CheckForCapability(aMessage) != KErrNone)
				aMessage.Complete(KErrPermissionDenied);
			else
				{
				// serialize data
				lPid = aMessage.Int0();
				lSignal = aMessage.Int1();

				lTmpHdl.mPid = lPid;
				lIndex = iProcessHdlList.Find(lTmpHdl,TIdentityRelation<TOeProcessHdl>(TOeProcessHdl::MatchByPid));

				if(lIndex == KErrNotFound)
					aMessage.Complete(KErrGeneral);
				else
					{
					TSignalMessage lMsg;
					lMsg.mType = TSignalMessage::ESignal;
					lMsg.mSignal = lSignal;
					TBuf8<KSigMsgLength> lMsgBuf;
					lMsg.Marshall(lMsgBuf);

					iProcessHdlList[lIndex].mPipe.WriteBlocking(lMsgBuf,KSigMsgLength);
					aMessage.Complete (KErrNone);
					}
				}
			break;
		case ESendSignalValue:
			if(CheckForCapability(aMessage) != KErrNone)
				aMessage.Complete(KErrPermissionDenied);
			else
				{
				// serialize data
				lPid = aMessage.Int0();
				lSignal = aMessage.Int1();
				TUint32 lValue = (TUint32)aMessage.Int2();
				lTmpHdl.mPid = lPid;

				lIndex = iProcessHdlList.Find(lTmpHdl,TIdentityRelation<TOeProcessHdl>(TOeProcessHdl::MatchByPid));
				if(lIndex == KErrNotFound)
					aMessage.Complete(KErrGeneral);
				else
					{
					TSignalMessage lMsg;
					lMsg.mType = TSignalMessage::ESignalValuePair;
					lMsg.mSigVal.mSignal = lSignal;
					lMsg.mSigVal.mValue = lValue;
					TBuf8<KSigMsgLength> lMsgBuf;
					lMsg.Marshall(lMsgBuf);

					iProcessHdlList[lIndex].mPipe.WriteBlocking(lMsgBuf,KSigMsgLength);
					aMessage.Complete (KErrNone);
					}
				}
			break;
		case ESendPipe:
			aMessage.Client(lClientThread);
			lClientThread.Process(lProcess);
			lPid = lProcess.Id();

			lTmpHdl.mPid = lPid;
			lIndex = iProcessHdlList.Find(lTmpHdl,TIdentityRelation<TOeProcessHdl>(TOeProcessHdl::MatchByPid));
			if(lIndex == KErrNotFound)
				{
				TOeProcessHdl lHdl;
				lHdl.mPid = lPid;
				lHdl.mPipe.Open(aMessage,0);
				iProcessHdlList.Append(lHdl);
				aMessage.Complete(KErrNone);
				}
			else
				{
				if(iProcessHdlList[lIndex].mPipe.Open(aMessage,0)!=KErrNone)
					aMessage.Complete(KErrGeneral);
				else
					aMessage.Complete(KErrNone);
				}

			lProcess.Close();
			lClientThread.Close();
			break;
		default:
			aMessage.Complete(KErrNotSupported);
			break;
		}
		return;
	}