dbgsrv/coredumpserver/test/automatictests/tcds_app/src/utracestep.cpp
changeset 0 c6b0df440bee
equal deleted inserted replaced
-1:000000000000 0:c6b0df440bee
       
     1 // Copyright (c) 2005-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 // Example CTestStep derived implementation
       
    15 //
       
    16 
       
    17 
       
    18 
       
    19 /**
       
    20  @file SELFStep.cpp
       
    21  @internalTechnology
       
    22 */
       
    23 #include "utracestep.h"
       
    24 #include "tcoredumpserversuitedefs.h"
       
    25 #include "tcoredumpserverSuiteServer.h"
       
    26 #include <crashdatasave.h>
       
    27 #include <s32file.h>
       
    28 #include <e32property.h>
       
    29 
       
    30 CUTraceStep::~CUTraceStep()
       
    31 /**
       
    32  * Destructor
       
    33  */
       
    34 	{
       
    35 	}
       
    36 
       
    37 CUTraceStep::CUTraceStep()
       
    38 /**
       
    39  * Constructor
       
    40  */
       
    41 	{
       
    42 	// **MUST** call SetTestStepName in the constructor as the controlling
       
    43 	// framework uses the test step name immediately following construction to set
       
    44 	// up the step's unique logging ID.
       
    45 	SetTestStepName (KUTraceUserSide);
       
    46 	}
       
    47 
       
    48 TVerdict CUTraceStep::doTestStepPreambleL()
       
    49 /**
       
    50  * @return - TVerdict code
       
    51  * Override of base class virtual
       
    52  */
       
    53 	{
       
    54 	TInt ret = KErrNone;
       
    55 	ret = iSess.Connect ();
       
    56 	if ( ret != KErrNone)
       
    57 		{
       
    58 		SetTestStepResult ( EFail);
       
    59 		INFO_PRINTF2 (_L ("Error %d from iSess->Connect()/n"), ret);
       
    60 		}
       
    61 	else
       
    62 		{
       
    63 		SetTestStepResult (EPass);
       
    64 		}
       
    65 
       
    66 	ret = iFs.Connect ();
       
    67 	if ( ret != KErrNone)
       
    68 		{
       
    69 		SetTestStepResult ( EFail);
       
    70 		INFO_PRINTF2 (_L ("Error %d from iFs->Connect()/n"), ret);
       
    71 		}
       
    72 	else
       
    73 		{
       
    74 		SetTestStepResult (EPass);
       
    75 		}
       
    76 
       
    77 	return TestStepResult ();
       
    78 	}
       
    79 
       
    80 void CUTraceStep::ClientAppL()
       
    81 /**
       
    82  * @return void
       
    83  * This calls each stage of the test
       
    84  */
       
    85 	{
       
    86 	INFO_PRINTF1 (_L ("Starting UTrace User Side Test Suite"));
       
    87 	TestTraceDataL ();
       
    88 
       
    89 	}
       
    90 
       
    91 void CUTraceStep::TestTraceDataL()
       
    92 	{
       
    93 	_LIT (KCrashFileName, "c:\\trace");
       
    94 	HandleCrashL (KCrashFileName);
       
    95 	}
       
    96 
       
    97 void CUTraceStep::HandleCrashL(const TDesC& aFileName)
       
    98 /**
       
    99  * @return void
       
   100  * Tests handling a crash
       
   101  */
       
   102 	{
       
   103 
       
   104 	if ( TestStepResult ()==EPass)
       
   105 		{
       
   106 		_LIT (KCrashAppParam, "-d1 -t");
       
   107 
       
   108 		INFO_PRINTF3 (_L ("The CrashApp Param is %S, The Filename is is %S"),
       
   109 				&KCrashAppParam, &aFileName);
       
   110 
       
   111 		//Start the process that we intend to crash....
       
   112 		RProcess crashProcess;
       
   113 		CleanupClosePushL (crashProcess);
       
   114 
       
   115 		TInt ret = crashProcess.Create ( KCrashAppFileName, KCrashAppParam);
       
   116 		if ( ret != KErrNone)
       
   117 			{
       
   118 			INFO_PRINTF2 (
       
   119 					_L ("Error %d from RProcess.Create(z:\\sys\\bin\\crashapp.exe)/n"),
       
   120 					ret);
       
   121 			SetTestStepResult (EFail);
       
   122 			User::Leave (ret);
       
   123 			}
       
   124 
       
   125 		LoadUTraceFormatterL ();
       
   126 		LoadFileWriterL ();
       
   127 
       
   128 		//configure cds and writer
       
   129 		_LIT ( KFilePathPrompt, "not_important");
       
   130 
       
   131 		INFO_PRINTF1 (_L ("Configuring CDS"));
       
   132 		DoConfigureL (2, CDS_UID.iUid, COptionConfig::ECoreDumpServer,
       
   133 				COptionConfig::ETUInt, KPostCrashEventActionPrompt, 1,
       
   134 				KNullDesC, 4, KNullDesC, 0);
       
   135 
       
   136 		INFO_PRINTF1 (_L ("Configuring File Writer"));
       
   137 		DoConfigureL ((TInt)(CCrashDataSave::ECoreFilePath), WRITER_UID.iUid,
       
   138 				COptionConfig::EWriterPlugin, COptionConfig::ETFileName,
       
   139 				KFilePathPrompt, 1, KNullDesC, 0, aFileName, 0);
       
   140 
       
   141 		// Observe the process and wait for a crash
       
   142 		INFO_PRINTF1 (_L ("Observing bad boy crash app"));
       
   143 		TRAP (ret, iSess.ObservationRequestL ( KCrashAppFileName,
       
   144 				KCrashAppFileName, ETrue));
       
   145 		if ( ret != KErrNone)
       
   146 			{
       
   147 			INFO_PRINTF2 (
       
   148 					_L ("Error %d iSess.ObservationRequestL(z:\\sys\\bin\\crashapp.exe)\n"),
       
   149 					ret);
       
   150 			SetTestStepResult (EFail);
       
   151 			User::Leave ( ret);
       
   152 			}
       
   153 
       
   154 		//start the crash process
       
   155 		crashProcess.Resume ();
       
   156 		CleanupStack::PopAndDestroy (&crashProcess); //this is for crashProcess
       
   157 
       
   158 		//Monitor the progress of the crash file being generated...
       
   159 		MonitorProgressL ();
       
   160 		User::After (5000000);
       
   161 
       
   162 		//Check dump has been generated...and valid
       
   163 		CDir *fileList = NULL;
       
   164 		TFindFile fileFinder(iFs);
       
   165 		TRAP (ret, fileList = CTe_coredumpserverSuite::DoesFileExistL (
       
   166 				aFileName, fileFinder));
       
   167 
       
   168 		if ( (ret != KErrNone) || (fileList == NULL))
       
   169 			{
       
   170 			INFO_PRINTF2 (_L ("Expected crash file was not generated:  %d"),
       
   171 					ret);
       
   172 			SetTestStepResult (EFail);
       
   173 			User::Leave ( ret);
       
   174 			}
       
   175 
       
   176 		CleanupStack::PushL (fileList);
       
   177 		for (TInt i = 0; i < fileList->Count (); i++)
       
   178 			{
       
   179 			TParse fullName;
       
   180 			fullName.Set ((*fileList)[i].iName, &fileFinder.File(), NULL);
       
   181 			VerifyTraceDataL (fullName.FullName ());
       
   182 			INFO_PRINTF2 (_L ("Deleting %S"), &fullName.FullName ());
       
   183 			User::LeaveIfError (iFs.Delete (fullName.FullName ()));
       
   184 			}
       
   185 		CleanupStack::PopAndDestroy (fileList);
       
   186 
       
   187 		INFO_PRINTF1 (_L ("Expected trace crash file was generated and parsed successfully"));
       
   188 
       
   189 		}
       
   190 
       
   191 	}
       
   192 
       
   193 void CUTraceStep::MonitorProgressL()
       
   194 	{
       
   195 	RProperty crashProgress;
       
   196 	User::LeaveIfError (crashProgress.Attach (KCoreDumpServUid, ECrashProgress));
       
   197 
       
   198 	TBuf<50> crashProg;
       
   199 
       
   200 	TRequestStatus status;
       
   201 	crashProgress.Subscribe (status);
       
   202 	User::WaitForRequest (status);
       
   203 	//Subscribe for next one again...
       
   204 	crashProgress.Subscribe (status);
       
   205 
       
   206 	//First one should be the start string = "-"
       
   207 	User::LeaveIfError (crashProgress.Get (crashProg));
       
   208 	if ( crashProg != KStartOfUTraceProc)
       
   209 		{
       
   210 		INFO_PRINTF1 (_L ("UTRACE formatter has not started processing the data"));
       
   211 		}
       
   212 
       
   213 	INFO_PRINTF1 (_L ("UTRACE formatter has started processing the data"));
       
   214 	INFO_PRINTF1 (_L ("Waiting to be notified of the timeout of the processing. A timeout here is a fail"));
       
   215 	//Now we wait until its finished
       
   216 	do
       
   217 		{
       
   218 		User::WaitForRequest (status);
       
   219 		crashProgress.Subscribe (status);
       
   220 
       
   221 		User::LeaveIfError (crashProgress.Get (crashProg));
       
   222 		}
       
   223 	while (crashProg != KEndOfProcessing);
       
   224 
       
   225 	INFO_PRINTF1 (_L ("UTRACE formatter has finished processing the data"));
       
   226 	}
       
   227 
       
   228 void CUTraceStep::DoConfigureL(const TUint32& aIndex, const TUint32& aUID,
       
   229 		const COptionConfig::TParameterSource& aSource,
       
   230 		const COptionConfig::TOptionType& aType, const TDesC& aPrompt,
       
   231 		const TUint32& aNumOptions, const TDesC& aOptions, const TInt32& aVal,
       
   232 		const TDesC& aStrValue, const TUint aInstance)
       
   233 /**
       
   234  * @return void
       
   235  * @param aIndex Internal index to the component that owns the object
       
   236  * @param aUID UID of the component that owns the object
       
   237  * @param aSource Type of component that owns the object
       
   238  * @param aType Type of parameter
       
   239  * @param aPrompt Prompt to present to user 
       
   240  * @param aNumOptions Number of options that the parameter can be set to. Only applies if type is ETMultiEntryEnum.
       
   241  * @param aOptions Comma separated list of options. Applies to ETMultiEntryEnum and ETBool
       
   242  * @param aVal Integer value. Applies to ETInt, ETUInt, ETBool
       
   243  * @param aStrValue String value. Applies to ETString, ETFileName, ETMultiEntry, ETBool
       
   244  */
       
   245 	{
       
   246 	COptionConfig * config;
       
   247 
       
   248 	config = COptionConfig::NewL ( aIndex, aUID, aSource, aType, aPrompt,
       
   249 			aNumOptions, aOptions, aVal, aStrValue);
       
   250 
       
   251 	CleanupStack::PushL (config);
       
   252 
       
   253 	config->Instance (aInstance);
       
   254 
       
   255 	//Configure now...
       
   256 	TRAPD (ret, iSess.SetConfigParameterL (*config));
       
   257 	if ( ret != KErrNone)
       
   258 		{
       
   259 		INFO_PRINTF2 (_L ("Error %d changing param/n"), ret);
       
   260 		SetTestStepResult (EFail);
       
   261 		User::Leave (ret);
       
   262 		}
       
   263 
       
   264 	CleanupStack::PopAndDestroy (config);
       
   265 	}
       
   266 
       
   267 void CUTraceStep::LoadUTraceFormatterL()
       
   268 /**
       
   269  * @return void
       
   270  * Utility function to load the UTRACE formatter
       
   271  */
       
   272 	{
       
   273 
       
   274 	INFO_PRINTF1 (_L ("Attempting to load UTRACE Plugin"));
       
   275 
       
   276 	TPluginRequest req;
       
   277 	req.iPluginType = TPluginRequest::EFormatter;
       
   278 	req.iLoad = ETrue;
       
   279 	req.iUid = UTRACE_UID;
       
   280 
       
   281 	// Should be allowed to load utrace formatter
       
   282 	TRAPD (ret, iSess.PluginRequestL ( req));
       
   283 	if ( ret != KErrNone)
       
   284 		{
       
   285 		ERR_PRINTF2 (_L ("Failed to load writer plugin, error = %d"), ret);
       
   286 		SetTestStepResult (EFail);
       
   287 		User::Leave (ret);
       
   288 		}
       
   289 
       
   290 	}
       
   291 
       
   292 void CUTraceStep::LoadFileWriterL()
       
   293 	{
       
   294 	TPluginRequest req;
       
   295 	TUid writerUid = WRITER_UID;
       
   296 	req.iUid = writerUid;
       
   297 	req.iPluginType = TPluginRequest::EWriter;
       
   298 	req.iLoad = ETrue;
       
   299 
       
   300 	TRAPD (ret, iSess.PluginRequestL ( req));
       
   301 	if ( ret != KErrNone)
       
   302 		{
       
   303 		ERR_PRINTF2 (_L ("Failed to load writer plugin, error = %d"), ret);
       
   304 		SetTestStepResult (EFail);
       
   305 		User::Leave (ret);
       
   306 		}
       
   307 
       
   308 	}
       
   309 
       
   310 TVerdict CUTraceStep::doTestStepL()
       
   311 /**
       
   312  * @return - TVerdict code
       
   313  * Override of base class pure virtual
       
   314  * Our implementation only gets called if the base class doTestStepPreambleL() did
       
   315  * not leave. That being the case, the current test result value will be EPass.
       
   316  */
       
   317 	{
       
   318 	if ( TestStepResult ()==EPass)
       
   319 		{
       
   320 		TInt ret = KErrNone;
       
   321 
       
   322 		__UHEAP_MARK;
       
   323 
       
   324 		TRAP (ret, ClientAppL ());
       
   325 		if ( KErrNone != ret)
       
   326 			{
       
   327 			SetTestStepResult (EFail);
       
   328 			INFO_PRINTF2 (
       
   329 					_L ("Error %d from CTestFormatterUserSideStep->ClientAppL()"),
       
   330 					ret);
       
   331 			}
       
   332 
       
   333 		__UHEAP_MARKEND;
       
   334 
       
   335 		}
       
   336 	return TestStepResult ();
       
   337 	}
       
   338 
       
   339 TVerdict CUTraceStep::doTestStepPostambleL()
       
   340 /**
       
   341  * @return - TVerdict code
       
   342  * Override of base class virtual
       
   343  */
       
   344 	{
       
   345 	iSess.Disconnect ();
       
   346 	User::After (10000000); //ensure we give enough time for session to close
       
   347 	iFs.Close ();
       
   348 	return EPass;
       
   349 	}
       
   350 
       
   351 void CUTraceStep::VerifyTraceDataL(const TDesC& aFullFilename)
       
   352 	{
       
   353 	INFO_PRINTF2 (_L ("VerifyTraceDataL (Not Implemented) The Filename is is %S"),
       
   354 			 &aFullFilename);
       
   355 
       
   356 	}
       
   357