systemhealthmanagement/systemhealthmgr/test/tsysmon/src/tsysmon_stepselfmoncancel.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 <sysmonclisess.h>
       
    23 #include <startupproperties.h>
       
    24 #include <ssm/ssmstartupproperties.h>
       
    25 #include "testprocgoodsession.h"
       
    26 #include "tsysmon_stepselfmoncancel.h"
       
    27 
       
    28 CStepSelfMonCancel::CStepSelfMonCancel()
       
    29 	{
       
    30 	SetTestStepName(KCTestCaseSelfMonCancel);
       
    31 	}
       
    32 /**
       
    33 Old Test CaseID 		APPFWK-SYSMON-0008
       
    34 New Test CaseID 		DEVSRVS-SHMA-SYSMON-0008
       
    35  */
       
    36 
       
    37 TVerdict CStepSelfMonCancel::doTestStepL()
       
    38 	{
       
    39 	INFO_PRINTF1(_L("TEST APPFWK-SYSMON-0008"));
       
    40 	
       
    41 	INFO_PRINTF1(_L("Going to start a process"));
       
    42 	RSysMonSession sysmon;
       
    43 	CleanupClosePushL(sysmon);
       
    44 	sysmon.OpenL();
       
    45 
       
    46 	RProcess process;
       
    47 	CleanupClosePushL(process);
       
    48 	User::LeaveIfError(process.Create(KTestProcGood, KLaunchServerCommandLineOption));
       
    49 	ResumeL(process);
       
    50 
       
    51 	INFO_PRINTF1(_L("Going to request process monitoring using startupproperties"));
       
    52 	CStartupProperties* prop = CStartupProperties::NewLC(KTestProcGood, KLaunchServerCommandLineOption);
       
    53 	prop->SetStartMethod(EWaitForStart);	
       
    54 	prop->SetMonitored(ETrue);
       
    55 	prop->SetNoOfRetries(1); 
       
    56 	
       
    57 	TRAPD(err, sysmon.MonitorL(*prop, process)); 
       
    58 	TESTEL(err == KErrNone, err);
       
    59 
       
    60 	DoTestMonitorL(process);
       
    61 	
       
    62 	CleanupStack::PopAndDestroy(prop);
       
    63 	CleanupStack::Pop(&process);
       
    64 
       
    65 	CleanupClosePushL(process);
       
    66 	User::LeaveIfError(process.Create(KTestProcGood, KLaunchServerCommandLineOption));
       
    67 	ResumeL(process);
       
    68 
       
    69 	INFO_PRINTF1(_L("Going to request process monitoring using ssmstartupproperties"));
       
    70 	CSsmStartupProperties* ssmProp = CSsmStartupProperties::NewLC(KTestProcGood, KLaunchServerCommandLineOption);
       
    71 	ssmProp->SetExecutionBehaviour(ESsmWaitForSignal);
       
    72 	TSsmMonitorInfo monitorInfo;
       
    73 	monitorInfo.iRestartPolicy = ESsmIgnoreOnFailure;
       
    74 	monitorInfo.iRestartMode = 0;
       
    75 	monitorInfo.iTimeout = 0;
       
    76 	monitorInfo.iRetries = 1;
       
    77 	ssmProp->SetMonitorInfoL(monitorInfo);
       
    78 	
       
    79 	TRAP(err, sysmon.MonitorL(*ssmProp, process)); 
       
    80 	TESTEL(err == KErrNone, err);
       
    81 
       
    82 	DoTestMonitorL(process);
       
    83 	
       
    84 	CleanupStack::PopAndDestroy(ssmProp);
       
    85 	CleanupStack::PopAndDestroy(&process);
       
    86 	CleanupStack::PopAndDestroy(&sysmon);
       
    87 
       
    88 	INFO_PRINTF1(_L("Test complete"));		
       
    89 	return TestStepResult();	
       
    90 	}
       
    91 
       
    92 void CStepSelfMonCancel::DoTestMonitorL(RProcess& aProc)
       
    93 	{
       
    94 	INFO_PRINTF1(_L("Monitoring is now setup, we will now make a request to cancel monitoring."));
       
    95 	RTestProcGoodSession server;
       
    96 	User::LeaveIfError(server.Connect());
       
    97 	TEST(KErrNone == server.CancelMonitor());
       
    98 	server.Close();
       
    99 
       
   100 	//Now, killing the process will not cause sysmon to restart after KWaitTime
       
   101 	TEST(Exists(KTestProcGood));
       
   102 	aProc.Kill(KErrNone);
       
   103 	TEST(EFalse == Exists(KTestProcGood));
       
   104 	INFO_PRINTF1(_L("Killed monitored process."));
       
   105 
       
   106 	INFO_PRINTF1(_L("Going to sleep for 16 seconds."));		
       
   107 	User::After(KThrottleTime + 1000000);
       
   108 
       
   109 	INFO_PRINTF1(_L("Check that the process wasn't restarted"));		
       
   110 	TEST(EFalse == Exists(KTestProcGood));
       
   111 	}
       
   112