sysstatemgmt/systemstatemgr/test/testapps/src/ssmcletestproc.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 // usage: ssmtestprocwritetime.exe <output filename> [<timeout (seconds)> [<succeed on run number>]]    *
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @test
       
    21  @internalComponent - Internal Symbian test code
       
    22 */
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <f32file.h>
       
    26 #include <s32file.h>
       
    27 #include "ssmcletestapp.h"
       
    28 #include "ssmtestapps.h"
       
    29 #include "ssmdebug.h"
       
    30 
       
    31 
       
    32 static void RunL()
       
    33 	{
       
    34 	TSsmCleTestAppArgs args;
       
    35 	XSsmCleTestApp::GetCommandLineArgsL(args);
       
    36 	RFs fs;
       
    37 	User::LeaveIfError(fs.Connect());
       
    38 	CleanupClosePushL(fs);
       
    39 
       
    40 	
       
    41 	TInt count = XSsmCleTestApp::GetRunCountL(fs, args.iLogPrefix);
       
    42 	if (0 == count)
       
    43 		{
       
    44 		XSsmCleTestApp::WriteStartTimeL(fs, args.iLogPrefix);
       
    45 						
       
    46 		}
       
    47 	TInt newCount = XSsmCleTestApp::IncrementRunCountL(fs, args.iLogPrefix);
       
    48 		
       
    49 
       
    50 	if ((args.iSucceedOnRun == 0)  && (args.iWaitTime > 0))
       
    51 		{
       
    52 		User::After(args.iWaitTime * 1000); 
       
    53 						
       
    54 		}
       
    55 	
       
    56 	if ((args.iSucceedOnRun != 0) && (args.iSucceedOnRun > count) && (args.iWaitTime > 0))
       
    57 		{
       
    58 		User::After(args.iWaitTime * 1000); 
       
    59 		}
       
    60 
       
    61 	XSsmCleTestApp::WriteResultL(fs, args.iLogPrefix,args.iFailHow);
       
    62 
       
    63 	switch (args.iFailHow) //Other failure modes don't require special action
       
    64 		{
       
    65 		case EDontFail:
       
    66 			{
       
    67 			if ((args.iSucceedOnRun == 0) || ((args.iSucceedOnRun > 0) && (count >= args.iSucceedOnRun)))
       
    68 				{
       
    69 				RProcess::Rendezvous(KErrNone);
       
    70 				}
       
    71 			else
       
    72 				{
       
    73 				RProcess::Rendezvous(KErrBadRendezvousTest);
       
    74 				}
       
    75 			break;
       
    76 			}
       
    77 		case EPanic:
       
    78 			{
       
    79 			User::Panic(_L("SSMTEST"), KSsmCleTestPanic);
       
    80 			break;
       
    81 			}
       
    82 		case EBadRendezvous:
       
    83 			{
       
    84 			TBuf<KTestCommandLineMaxLength> prefix = KTestAppLogFileLoc();
       
    85 			XSsmCleTestApp::WriteResultL(fs, prefix, args.iFailHow);
       
    86 			RProcess::Rendezvous(KErrBadRendezvousTest);
       
    87 			break;
       
    88 			}
       
    89 		case ENoRendezvous:
       
    90 		case EMultipleTimeout:
       
    91 			{
       
    92 			User::After(10000000); // 10 seconds
       
    93 			break;
       
    94 			}
       
    95 		}
       
    96 	//Signalling the start of the application
       
    97 	RSemaphore sem;
       
    98 	TInt err = sem.OpenGlobal(KStartProcSignalSemaphore);
       
    99 	RDebug::Print(_L("KStartProcSignalSemaphore Opened with %d"), err);
       
   100 		
       
   101 	if(err == KErrNone)
       
   102 		{
       
   103 		sem.Signal();
       
   104 		sem.Close();
       
   105 		}
       
   106 	CleanupStack::PopAndDestroy(&fs);
       
   107 	}
       
   108 
       
   109 TInt E32Main()
       
   110 	{
       
   111 	__UHEAP_MARK;
       
   112 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
   113 	TInt r=KErrNoMemory;
       
   114 	if (cleanup)
       
   115 		{
       
   116 		TRAP(r,RunL());
       
   117 		delete cleanup;
       
   118 		}
       
   119 
       
   120 	__UHEAP_MARKEND;
       
   121 
       
   122 	//This process will return to the user and thus be terminated without cleaning up properly
       
   123 	//To avoid this we give a wait for request so that we can explicitly clean it up
       
   124 	TRequestStatus status = KRequestPending;
       
   125 	User::WaitForRequest(status);
       
   126 	return r;
       
   127 	}