sysstatemgmt/systemstarter/test/tsysmon/src/tsysmon_stepbase.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code
       
    20 */
       
    21 
       
    22 #include <apacmdln.h>
       
    23 #include <apgcli.h>
       
    24 #include <sysmonclisess.h>
       
    25 #include <startupproperties.h>
       
    26 #include "testprocgoodsession.h"
       
    27 #include "tsysmon_stepbase.h"
       
    28 
       
    29 /** 
       
    30 Waits for the process to rendevouz, then resumes it.
       
    31 */
       
    32 void CTestStepBase::ResumeL(RProcess& aProcess)
       
    33 	{
       
    34 	TRequestStatus status;
       
    35 	aProcess.Rendezvous(status);
       
    36 	if (status == KRequestPending)
       
    37 		{
       
    38 		aProcess.Resume();
       
    39 		}
       
    40 	else
       
    41 		{
       
    42 		aProcess.Kill(KErrGeneral);
       
    43 		TESTEL(EFalse, status.Int());
       
    44 		}
       
    45 	
       
    46 	User::WaitForRequest(status);
       
    47 	INFO_PRINTF1(_L("Process started"));
       
    48 	}
       
    49 
       
    50 /**
       
    51 Connects to sysmon and request monitoring of aProcess using aProp.
       
    52 */
       
    53 void CTestStepBase::MonitorL(const RProcess& aProcess, const CStartupProperties& aProp)
       
    54 	{	
       
    55 	RSysMonSession sess;
       
    56 	sess.OpenL();
       
    57 	CleanupClosePushL(sess);
       
    58 	TRAPD(err, sess.MonitorL(aProp, aProcess));
       
    59 	TESTL(err == KErrNone);	
       
    60 	CleanupStack::PopAndDestroy(&sess);
       
    61 	INFO_PRINTF1(_L("Monitoring initiated"));
       
    62 	}		
       
    63 
       
    64 /**
       
    65 Creates and resumes aProcess with file=KTestProcGood args=KLaunchServerCommandLineOption, 
       
    66 then sets up monitoring with aStartMethod and 1 retry.
       
    67 */
       
    68 void CTestStepBase::StartAndMonitorL(RProcess& aProcess, TStartMethod aStartMethod)
       
    69 	{
       
    70 	//Start a process that launch a CServer2
       
    71 	INFO_PRINTF1(_L("Going start a process"));
       
    72 	User::LeaveIfError(aProcess.Create(KTestProcGood, KLaunchServerCommandLineOption));
       
    73 	ResumeL(aProcess);
       
    74 	
       
    75 	//Setup monitoring	
       
    76 	INFO_PRINTF1(_L("Going to request process monitoring"));
       
    77 	CStartupProperties* prop = CStartupProperties::NewLC(KTestProcGood, KLaunchServerCommandLineOption);
       
    78 	prop->SetMonitored(ETrue);
       
    79 	prop->SetStartupType(EStartProcess);
       
    80 	prop->SetStartMethod(aStartMethod);
       
    81 	prop->SetNoOfRetries(1);
       
    82 	MonitorL(aProcess, *prop);	
       
    83 	CleanupStack::PopAndDestroy(prop);
       
    84 	
       
    85 	//Assert that the server is running
       
    86 	RTestProcGoodSession server;
       
    87 	TInt err = server.Connect();
       
    88 	TEST(KErrNone == err);
       
    89 	if(KErrNone == err)
       
    90 		{
       
    91 		INFO_PRINTF1(_L("Asserted that server is running"));		
       
    92 		}
       
    93 	server.Close();
       
    94 	}
       
    95 
       
    96 /**
       
    97 Launch native application aAppName using an unconnected RApaLsSession
       
    98 */
       
    99 void CTestStepBase::StartViewlessBgApplicationL(const TDesC& aAppName, TThreadId& aTreadId, TRequestStatus& aRequestStatus)
       
   100 	{
       
   101 	RApaLsSession apa;
       
   102 	TThreadId threadId;
       
   103 	CApaCommandLine* const cmdLine = CApaCommandLine::NewLC();
       
   104 	cmdLine->SetExecutableNameL(aAppName);
       
   105 	cmdLine->SetCommandL(EApaCommandBackgroundAndWithoutViews);
       
   106 	User::LeaveIfError(apa.StartApp(*cmdLine, aTreadId, &aRequestStatus));
       
   107 	CleanupStack::PopAndDestroy(cmdLine);
       
   108 	}
       
   109 
       
   110 /**
       
   111 Asserts that at least one process starting with the name aProcessName is running.
       
   112 */
       
   113 TBool CTestStepBase::Exists(const TDesC& aProcessName)
       
   114 	{	
       
   115 	TPtrC ptr(aProcessName);
       
   116 	ptr.Set( ptr.Ptr(), ptr.Find(_L(".")) );
       
   117 	TFullName procSerchTerm( ptr );
       
   118 	procSerchTerm += _L("*");
       
   119 
       
   120 	TFindProcess find(procSerchTerm);
       
   121 	TFullName name;
       
   122 	TBool found = EFalse;
       
   123 	while(find.Next(name)==KErrNone)
       
   124 		{
       
   125 		RProcess process;
       
   126 		const TInt err = process.Open(find);
       
   127 		if (err == KErrNone)
       
   128 			{
       
   129 			if (process.ExitType() == EExitPending)
       
   130 				{
       
   131 				found = ETrue;
       
   132 				process.Close(); 
       
   133 				break;
       
   134 				}
       
   135 			process.Close(); 
       
   136 			}
       
   137 		}
       
   138 	return found;
       
   139 	}