os/persistentdata/loggingservices/eventlogger/test/src/t_logservIPC.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2008-2010 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 #include <e32test.h>
    18 #include <e32math.h>
    19 #include "LogCliServShared.h"
    20 #include "logservpanic.h"
    21 #include "logpackage.h"
    22 #include "t_logutil.h"
    23 
    24 RTest	TheTest(_L("t_logservipc"));
    25 
    26 _LIT(KServerName, "!LogServ");
    27 _LIT(KServerProcess, "LogServ");
    28 
    29 ///////////////////////////////////////////////////////////////////////////////////////
    30 //
    31 
    32 struct TTestInfo
    33 	{
    34 	TInt iFunction;
    35 	TInt iType;
    36 	TInt iArgCount;
    37 	};
    38 
    39 struct TExitDetails
    40 	{
    41 	TExitCategoryName iCategory;
    42 	TExitType iExitType;
    43 	TInt iReason;
    44 	};
    45 
    46 const TInt KAsynchDelay = 500000;
    47 
    48 const TInt KFunctionNumbers [] = {ELogOperationCancel,
    49 								ELogOperationGetResult,
    50 								ELogOperationInitiate,
    51 								ELogNotify,
    52 								ELogNotifyCancel,
    53 								ELogViewCreate,
    54 								ELogViewDelete,
    55 								ELogViewCount,
    56 								ELogViewOperationInitiate,
    57 								ELogViewChangeNotificationsRequest,
    58 								ELogViewChangeNotificationsCancel,
    59 								ELogViewFetchChanges,
    60 								ELogViewNotifyLockStatusChange,
    61 								ELogViewNotifyLockStatusChangeCancel,
    62 								ELogNotifyExtended,
    63 								ELogNotifyExtendedCancel};
    64 
    65 const TInt KNumFunctions = sizeof(KFunctionNumbers)/sizeof(KFunctionNumbers[0]);
    66 
    67 //===============================================================================
    68 
    69 TBool IsFunctionAsynchronous(TInt aFunc)
    70 	{
    71 	TBool asynch = EFalse;
    72 	switch(aFunc)
    73 		{			
    74 		case ELogOperationInitiate:
    75 		case ELogNotify:
    76 		case ELogViewOperationInitiate:
    77 		case ELogViewChangeNotificationsRequest:
    78 		case ELogViewNotifyLockStatusChange:
    79 		case ELogNotifyExtended:
    80 			asynch = ETrue;
    81 			break;
    82 			
    83 		default:
    84 			break;
    85 		}
    86 	return asynch;
    87 	}
    88 
    89 class RIpcFuzzTest : public RSessionBase
    90 {
    91 public: // Constructors and destructor
    92 
    93 	/**
    94 		* Constructor for performing 1st stage construction
    95 		*/
    96 	RIpcFuzzTest();
    97 
    98 	/**
    99 		* Destructor.
   100 		*/
   101 	~RIpcFuzzTest();
   102 
   103 	/**
   104 		* Performs test steps
   105 		*/
   106 	
   107 	void RunTestL(const TDesC& aTargetSrvName, TInt aFunc, 
   108 				TInt aTestType, TInt aArgCount);
   109 	
   110 private:
   111 	TInt Fuzz(TInt aMsg, TInt aArgCount);
   112 	TInt FuzzL(TInt aMsg, TInt aArgCount);
   113 	TInt Fuzz8L(TInt aMsg, TInt aArgCount);
   114 };
   115 
   116 RIpcFuzzTest::RIpcFuzzTest()
   117 	{
   118 	// No implementation required
   119 	}
   120 
   121 
   122 RIpcFuzzTest::~RIpcFuzzTest()
   123 	{
   124 	Close();	
   125 	}
   126 
   127 TInt RIpcFuzzTest::Fuzz(TInt aMsg, TInt aArgCount)
   128 	{
   129 	TIpcArgs args;
   130 	
   131 	for(TInt i = 0; i < aArgCount;i++)
   132 		{
   133 		args.Set(i,Math::Random());
   134 		}	
   135 	
   136 	TInt ret;
   137 	
   138 	if(IsFunctionAsynchronous(aMsg))
   139 		{
   140 		ret = Send(aMsg, args);
   141 		User::After(KAsynchDelay);
   142 		}
   143 	else
   144 		{
   145 		ret = SendReceive(aMsg, args);
   146 		}
   147 	return ret;
   148 	}
   149 
   150 TInt RIpcFuzzTest::Fuzz8L(TInt aMsg, TInt aArgCount)
   151 	{
   152 	HBufC8* buf = HBufC8::NewLC(255);
   153 	TPtr8 ptr = buf->Des();
   154 	ptr.Fill(Math::Random(),255);
   155 	
   156 	TIpcArgs args;
   157 	
   158 	for(TInt i = 0; i < aArgCount;i++)
   159 		{
   160 		args.Set(i,&ptr);
   161 		}
   162 	
   163 	TInt ret;
   164 	
   165 	if(IsFunctionAsynchronous(aMsg))
   166 		{
   167 		ret = Send(aMsg, args);
   168 		User::After(KAsynchDelay);
   169 		}
   170 	else
   171 		{
   172 		ret = SendReceive(aMsg, args);
   173 		}
   174 
   175 	CleanupStack::PopAndDestroy(buf);
   176 	return ret;
   177 	}
   178 
   179 TInt RIpcFuzzTest::FuzzL(TInt aMsg, TInt aArgCount)
   180 	{
   181 	HBufC* buf = HBufC::NewLC(255);
   182 	TPtr ptr = buf->Des();
   183 	ptr.Fill(Math::Random(),255);
   184 
   185 	TIpcArgs args;
   186 	
   187 	for(TInt i = 0; i < aArgCount;i++)
   188 		{
   189 		args.Set(i,&ptr);
   190 		}
   191 	
   192 	TInt ret;
   193 	
   194 	if(IsFunctionAsynchronous(aMsg))
   195 		{
   196 		ret = Send(aMsg, args);
   197 		User::After(KAsynchDelay);
   198 		}
   199 	else
   200 		{
   201 		ret = SendReceive(aMsg, args);
   202 		}
   203 
   204 	CleanupStack::PopAndDestroy(buf);
   205 	return ret;
   206 	}
   207 
   208 void RIpcFuzzTest::RunTestL(const TDesC& aTargetSrvName, 
   209 							TInt aFunc, TInt aTestType, TInt aArgCount)
   210 	{
   211 		TVersion version(0,0,0);
   212 	
   213 		TInt err = CreateSession(aTargetSrvName, version);
   214 		
   215 		LEAVE_IF_ERROR(err);
   216 	
   217 		switch(aTestType)
   218 			{
   219 			case 0:
   220 				Fuzz(aFunc,aArgCount);
   221 				break;
   222 				
   223 			case 1:
   224 				Fuzz8L(aFunc,aArgCount);
   225 				break;
   226 				
   227 			case 2:
   228 				FuzzL(aFunc,aArgCount);
   229 				break;			
   230 			}
   231 	}
   232 
   233 TInt FuzzServerL(TAny* aTestInfo)
   234 	{
   235    	CTrapCleanup* cleanup=CTrapCleanup::New();
   236    	TInt err=KErrNoMemory;
   237    	if (cleanup)
   238    		{
   239    		
   240 		TTestInfo* info = (TTestInfo*)aTestInfo;
   241 		RIpcFuzzTest fuzzer;
   242 		
   243 		TRAP(err,fuzzer.RunTestL(KServerName,info->iFunction
   244 				,info->iType, info->iArgCount));
   245 		
   246 		fuzzer.Close();
   247 
   248    		delete cleanup;
   249    		}
   250    	return err;
   251 	}
   252 
   253 
   254 void TestServerApi(TInt aFunctionNumber,
   255 			TInt aTestType,TInt aArgCount, TExitDetails& aExitDetails)
   256 	{
   257     
   258     TTestInfo testInfo;
   259 	testInfo.iFunction = aFunctionNumber;
   260 	testInfo.iType = aTestType;
   261 	testInfo.iArgCount = aArgCount;
   262     
   263     RThread thread;	
   264     _LIT(KThreadName,"FuzzerThread" );
   265 	TInt err = thread.Create(KThreadName,&FuzzServerL, KDefaultStackSize, NULL,&testInfo);
   266 	TEST2(err, KErrNone);
   267 	
   268 	TRequestStatus threadStat;
   269 	thread.Logon(threadStat);
   270 	
   271 	TBool jit = User::JustInTime();
   272 	User::SetJustInTime(EFalse);
   273 	
   274 	thread.Resume();
   275 	
   276 	User::WaitForRequest(threadStat);
   277 	
   278 	User::SetJustInTime(jit);
   279 
   280 	aExitDetails.iCategory = thread.ExitCategory();
   281 	aExitDetails.iReason = thread.ExitReason();
   282 	aExitDetails.iExitType = thread.ExitType();
   283 	
   284 	thread.Close();
   285 
   286 	}
   287 
   288 
   289 TInt LaunchServer(RProcess& aServer)
   290 	{
   291 	
   292 	TheTest.Printf(_L("Launching LogServer...\n"));
   293 	
   294 	const TUid KServerUid3 = {0x0101f401d};	
   295 	const TUidType serverUid(KNullUid,KNullUid,KServerUid3);
   296 	
   297 	TInt err = aServer.Create(KServerProcess, _L(""),serverUid);
   298 	 
   299 	if(err == KErrNone)
   300 		{   
   301 		aServer.SetPriority(EPriorityForeground);  
   302 		 
   303 		//Start server and wait until it is running
   304 		TRequestStatus serverStat;
   305 		aServer.SetJustInTime(false);   
   306 		aServer.Resume(); 
   307 		    
   308 		aServer.Rendezvous(serverStat);
   309 		User::WaitForRequest(serverStat);
   310 		}
   311 	 
   312 	 return err;
   313 	    
   314 	}
   315 
   316 void PrintTestMessage(TInt iFunc, TInt iType, TInt iArgCount)
   317 	{
   318 	switch(iType)
   319 		{
   320 		case 0:
   321 			TheTest.Printf(_L("\nFuzz Test on function number %d using random Int data. Number of Args = %d"), iFunc, iArgCount);
   322 			break;
   323 			
   324 		case 1:
   325 			TheTest.Printf(_L("\nFuzz Test on function number %d using random Des8 data. Number of Args = %d"), iFunc, iArgCount);
   326 			break;
   327 			
   328 		case 2:
   329 			TheTest.Printf(_L("\nFuzz Test on function number %d using random Des data. Number of Args = %d"), iFunc, iArgCount);
   330 			break;
   331 			
   332 		}
   333 	
   334 	}
   335 
   336 /**
   337 Invoke the tests
   338 */
   339 /**
   340 @SYMTestCaseID          SYSLIB-LOGENG-CT-4002
   341 @SYMTestCaseDesc	    Tests LogEng APIs for IPC Robustness
   342 @SYMTestPriority 	    High
   343 @SYMTestActions  	    The function calls each of the Logeng APIs through a custom session object
   344 						passing random TInt, Des8 and Des16 data .
   345 @SYMTestExpectedResults The server should be robust to all malformed messages and should not
   346 						hang or panic.
   347 @SYMDEF                	INC114113
   348 */
   349 LOCAL_C void DoFuzzTestsL ()
   350     {  
   351     TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-4002 "));
   352     RProcess server;
   353     
   354     LEAVE_IF_ERROR(LaunchServer(server));
   355 
   356     TExitDetails exitDetails;
   357       
   358     for(TInt i = 0;i< KNumFunctions;i++)
   359     	{
   360     	
   361     	//Carry out each type of test
   362     	for(TInt testType = 0; testType < 3;testType++)
   363     		{
   364        		//Carry out each test with number of arguments 1 - 4
   365     		for(TInt argCount = 1;argCount <= 4;argCount++)
   366     			{
   367     			PrintTestMessage(KFunctionNumbers[i], testType, argCount);
   368 
   369     			TestServerApi(KFunctionNumbers[i], testType, argCount, exitDetails);
   370 		    	//Kill the server process and verify that it was still running
   371 		    	//If the server was already dead it would return the reason it exited
   372 	    		if(server.ExitType() != EExitPending)
   373 	    			{
   374 	    			server.Kill(0);
   375 	    			TInt exitReason = server.ExitReason();
   376 	    			server.Close();
   377 	    			TEST2(exitReason, 0);    	
   378 	    			LEAVE_IF_ERROR(LaunchServer(server));
   379 	    			}
   380     			}
   381 	    	
   382     		TheTest.Printf(_L("\nFuzz Test Successful\n"));
   383     		}
   384     	}
   385     }
   386 
   387 
   388 /*
   389  * SERVER API TESTING
   390  */
   391 
   392 typedef void (*TestFunction)();
   393 
   394 class RClientMessageTestSession : public RSessionBase
   395 	{
   396 public:
   397 	TInt Connect();
   398 	
   399 	TInt TestMakeTransient(TInt aArg0);
   400 	TInt TestMakeTransient(const TDesC8& aArg0);
   401 	
   402 	TInt TestCliServDataParam(TInt aFunc, TDes8& aArg0);
   403 	TInt TestCliServDataParam(TInt aFunc, TDes8& aArg0, TUint32 aArg1);
   404 	TInt TestCliServDataParam(TInt aFunc, TDes8& aArg0, TDes8& aArg1, TInt aArg2);
   405 	TInt TestCliServDataParam(TInt aFunc, TDes& aArg0, TDes8& aArg1, TInt aArg2);
   406 	
   407 	TInt TestLogNotify(TInt aArg0);
   408 	TInt TestLogNotifyCancel();
   409 	
   410 	TInt TestLogViewCreate(TInt aArg0, TInt aArg1);	
   411 	
   412 	TInt TestLogViewIdParam(TInt aFunc, TInt aArg0);
   413 	TInt TestLogViewIdParam(TInt aFunc, TDes8& aArg1);
   414 	
   415 	TInt TestLogViewFetchChanges(TInt aArg0, TInt aArg1, TDes8& aArg2);
   416 	TInt TestLogViewFetchChanges(TInt aArg0, TInt aArg1, const TDesC8& aArg2);
   417 	
   418 	TInt TestLogNotifyExtended(TDes8& aArg0, TDes8& aArg1, TDes8& aArg2,TDes8& aArg3);
   419 	TInt TestLogNotifyExtended(TDes& aArg0, TDes& aArg1, TDes& aArg2,TDes& aArg3);
   420 	TInt TestLogNotifyExtended(TDes8& aArg0, TInt aArg1, TInt aArg2,const TDesC8& aArg3);
   421 	
   422 	TInt TestFunction45(TAny* aData);
   423 	
   424 
   425 	};
   426 
   427 static TInt LaunchLogServer()
   428 	{
   429 
   430 	RProcess process;
   431 
   432 	TInt err = process.Create(KServerProcess,_L(""));
   433 	 
   434 	if(err == KErrNone)
   435 		{
   436 		 TRequestStatus serverStat;		
   437 		 
   438 		 process.SetJustInTime(EFalse);
   439 		 process.Resume();
   440 		 process.Rendezvous(serverStat);
   441 		 User::WaitForRequest(serverStat);
   442 		}
   443 	
   444 	return err;
   445 	}
   446 
   447 
   448 TInt RClientMessageTestSession::Connect()
   449 	{
   450 	TInt retry = 2;
   451 	for(;;)
   452 		{
   453 		TInt r = CreateSession(KServerName,TVersion(1,0,0));
   454 		
   455 		if((r != KErrNotFound)&&(r != KErrServerTerminated))
   456 			{
   457 			return r;
   458 			}
   459 		
   460 		if(--retry == 0)
   461 			{
   462 			return r;
   463 			}
   464 		
   465 		r = LaunchLogServer();
   466 		if((r != KErrNone)&&(r != KErrAlreadyExists))
   467 			{
   468 			return r;
   469 			}	
   470 		}
   471 	}
   472 
   473 TInt RClientMessageTestSession::TestMakeTransient(TInt aArg0)
   474 	{
   475 	return SendReceive(ELogMakeTransient,TIpcArgs(aArg0));
   476 	}
   477 
   478 TInt RClientMessageTestSession::TestMakeTransient(const TDesC8& aArg0)
   479 	{
   480 	return SendReceive(ELogMakeTransient,TIpcArgs(&aArg0));
   481 	}
   482 
   483 TInt RClientMessageTestSession::TestCliServDataParam(TInt aFunc, TDes8& aArg0)
   484 	{
   485 	return SendReceive(aFunc,TIpcArgs(&aArg0));
   486 	}
   487 
   488 TInt RClientMessageTestSession::TestCliServDataParam(TInt aFunc, TDes8& aArg0, TUint32 aArg1)
   489 	{
   490 	return SendReceive(aFunc,TIpcArgs(&aArg0, aArg1));
   491 	}
   492 
   493 TInt RClientMessageTestSession::TestCliServDataParam(TInt aFunc, TDes8& aArg0, TDes8& aArg1, TInt aArg2)
   494 	{
   495 	return SendReceive(aFunc,TIpcArgs(&aArg0, &aArg1, aArg2));
   496 	}
   497 
   498 TInt RClientMessageTestSession::TestLogNotify(TInt aArg0)
   499 	{
   500 	return Send(ELogNotify,TIpcArgs(aArg0));
   501 	}
   502 
   503 TInt RClientMessageTestSession::TestLogNotifyCancel()
   504 	{
   505 	return Send(ELogNotifyCancel);
   506 	}
   507 	
   508 TInt RClientMessageTestSession::TestLogViewCreate(TInt aArg0, TInt aArg1)
   509 	{
   510 	return SendReceive(ELogViewCreate,TIpcArgs(aArg0,aArg1));
   511 	}
   512 
   513 
   514 TInt RClientMessageTestSession::TestLogViewIdParam(TInt aFunc, TInt aArg0)
   515 	{
   516 	return SendReceive(aFunc,TIpcArgs(aArg0));
   517 	}
   518 
   519 TInt RClientMessageTestSession::TestLogViewIdParam(TInt aFunc, TDes8& aArg0)
   520 	{
   521 	return SendReceive(aFunc,TIpcArgs(&aArg0));
   522 	}
   523 
   524 TInt RClientMessageTestSession::TestLogViewFetchChanges(TInt aArg0, TInt aArg1, TDes8& aArg2)
   525 	{
   526 	return SendReceive(ELogViewFetchChanges,TIpcArgs(aArg0,aArg1, &aArg2));
   527 	}
   528 
   529 TInt RClientMessageTestSession::TestLogViewFetchChanges(TInt aArg0, TInt aArg1, const TDesC8& aArg2)
   530 	{
   531 	return SendReceive(ELogViewFetchChanges,TIpcArgs(aArg0,aArg1, &aArg2));
   532 	}
   533 
   534 TInt RClientMessageTestSession::TestLogNotifyExtended(TDes8& aArg0, 
   535 								TDes8& aArg1, TDes8& aArg2,TDes8& aArg3)
   536 	{
   537 	return Send(ELogNotifyExtended,TIpcArgs(&aArg0,&aArg1,&aArg2,&aArg3));
   538 	}
   539 
   540 TInt RClientMessageTestSession::TestLogNotifyExtended(TDes& aArg0, 
   541 								TDes& aArg1, TDes& aArg2,TDes& aArg3)
   542 	{
   543 	return Send(ELogNotifyExtended,TIpcArgs(&aArg0,&aArg1,&aArg2,&aArg3));
   544 	}
   545 
   546 TInt RClientMessageTestSession::TestLogNotifyExtended(TDes8& aArg0, 
   547 								TInt aArg1, TInt aArg2,const TDesC8& aArg3)
   548 	{
   549 	return Send(ELogNotifyExtended,TIpcArgs(&aArg0,&aArg1,&aArg2,&aArg3));
   550 	}
   551 
   552 TInt RClientMessageTestSession::TestFunction45(TAny* aData)
   553 	{
   554 	return SendReceive(45,TIpcArgs(aData));
   555 	}
   556 
   557 
   558 TInt TestFunctionLauncherL(TAny* aTestFunction)
   559 	{
   560    	CTrapCleanup* cleanup=CTrapCleanup::New();
   561    	TInt r=KErrNoMemory;
   562    	if (cleanup)
   563    		{
   564    		TestFunction function = (TestFunction)aTestFunction;
   565 
   566 __UHEAP_MARK;  		
   567  		TRAP(r,function());
   568 __UHEAP_MARKEND;
   569  		
   570    		delete cleanup;
   571    		}
   572    	return r;
   573 	}
   574 
   575 
   576 TExitDetails LaunchTestThreadL(const TDesC& aThreadName, TestFunction aFunction)
   577 	{
   578 	RThread thread;	
   579 	TInt err = thread.Create(aThreadName, &TestFunctionLauncherL, KDefaultStackSize, NULL, (TAny*)aFunction);
   580 	TEST2(err, KErrNone);
   581 	
   582 	TRequestStatus threadStat;
   583 	thread.Logon(threadStat);
   584 	
   585 	TBool jit = User::JustInTime();
   586 	User::SetJustInTime(EFalse);
   587 	
   588 	thread.Resume();
   589 	User::WaitForRequest(threadStat);
   590 	
   591 	User::SetJustInTime(jit);
   592 	 
   593 	TExitDetails exitDetails;
   594 	exitDetails.iCategory = thread.ExitCategory();
   595 	exitDetails.iReason = thread.ExitReason();
   596 	exitDetails.iExitType = thread.ExitType();
   597 	
   598 	return exitDetails;
   599 	}
   600 
   601 /**
   602 @SYMTestCaseID          SYSLIB-LOGENG-CT-4003
   603 @SYMTestCaseDesc	    Tests Message schema validation for the ELogMakeTransient message.
   604 @SYMTestPriority 	    High
   605 @SYMTestActions  	    Sends messages to the test server to test the validation of messages
   606                         against the message schema.
   607 @SYMTestExpectedResults The server should validate the message and handle bad messages appropriately
   608 @SYMDEF                	INC114113
   609 */
   610 void TestMakeTransientL()
   611 	{
   612 	
   613 	RClientMessageTestSession session;
   614 	
   615 	TInt err = session.Connect();
   616 	TEST2(err, KErrNone);
   617 	
   618 	CleanupClosePushL(session);
   619 	
   620 	err = session.TestMakeTransient(0);	
   621 	TEST2(err, KErrNone);
   622 	
   623 	//anything different from 0 should be considered as ETrue
   624 	err = session.TestMakeTransient(1);	
   625 	TEST2(err, KErrNone);
   626 	
   627 	err = session.TestMakeTransient(-5);	
   628 	TEST2(err, KErrNone);
   629 	
   630 	err = session.TestMakeTransient(3);	
   631 	TEST2(err, KErrNone);
   632 	
   633 	err = session.TestMakeTransient( _L8("Des8"));	
   634 	TEST2(err, KErrNone);
   635 	
   636 	CleanupStack::PopAndDestroy(&session);
   637 	}
   638 
   639 /**
   640 @SYMTestCaseID          SYSLIB-LOGENG-CT-4004
   641 @SYMTestCaseDesc	    Tests Message schema validation for the messages accepting
   642  						TLogClientServerData parameters.
   643 @SYMTestPriority 	    High
   644 @SYMTestActions  	    Sends messages to the test server to test the validation of messages
   645 						against the message schema.  The messages contain either valid or invalid 
   646 						parameters. 
   647 @SYMTestExpectedResults The server should validate the message and handle bad messages appropriately
   648 @SYMDEF                	INC114113
   649 */
   650 void TestCliServDataParamL()
   651 	{
   652 	
   653 	RClientMessageTestSession session;
   654 	
   655 	TInt err = session.Connect();
   656     TEST2(err, KErrNone);
   657 	
   658 	CleanupClosePushL(session);
   659 	
   660 	TLogClientServerData data;
   661 	TPckg<TLogClientServerData> pData(data);
   662 	
   663 	TBuf8<sizeof(TLogClientServerData)> buf;
   664 	
   665 	buf.SetLength(sizeof(TLogClientServerData));
   666 	
   667 	buf.Fill(0xFF);
   668 	
   669 	data.iOperationType = 	ELogOperationEventAdd; 
   670 	data.iOperationId = 1;
   671 	err = session.TestCliServDataParam(ELogOperationInitiate,pData);	
   672 	TEST2(err, KErrBadDescriptor);
   673 	
   674 	data.iOperationType = 	ELogOperationViewWindowFetch; 
   675 	data.iOperationId = 5;
   676 	err = session.TestCliServDataParam(ELogOperationInitiate,pData);	
   677 	TEST2(err, KErrArgument);
   678 	
   679 	data.iOperationType = 	ELogOperationEventAdd; 
   680 	data.iOperationId = 0x8FFFFFFF;
   681 	err = session.TestCliServDataParam(ELogOperationInitiate,pData);	
   682 	TEST2(err, KErrBadDescriptor);
   683 
   684 	data.iOperationType = 	ELogOperationEventAdd; 
   685 	data.iOperationId = 0x8FFFFFFF;
   686 	err = session.TestCliServDataParam(ELogOperationInitiate,buf);	
   687 	TEST2(err, KErrArgument);
   688 	
   689 	data.iOperationType = 	ELogOperationEventAdd; 
   690 	data.iOperationId = 1;
   691 	err = session.TestCliServDataParam(ELogOperationCancel,pData);	
   692 	TEST2(err, KErrCancel);
   693 	
   694 	data.iOperationType = 	ELogOperationEventAdd; 
   695 	data.iOperationId = 1;
   696 	err = session.TestCliServDataParam(ELogOperationCancel,buf);	
   697 	TEST2(err, KErrArgument);
   698 	
   699 	CLogPackage* package = CLogPackage::NewL();
   700 	TPtr8 ptr(package->Ptr());
   701 	
   702 	data.iOperationType = 	ELogOperationEventAdd; 
   703 	data.iOperationId = 1;
   704 	err = session.TestCliServDataParam(ELogOperationGetResult,buf, ptr, 0);	
   705 	TEST2(err, KErrArgument);
   706 	
   707 	data.iOperationType = 	ELogOperationEventAdd; 
   708 	data.iOperationId = 1;
   709 	err = session.TestCliServDataParam(ELogOperationGetResult,pData, ptr, -1 );	
   710 	TEST2(err, KErrNone);
   711 	
   712 	delete package;
   713 	
   714 	TBuf8<8> smallBuf;
   715 	data.iOperationType = 	ELogOperationEventAdd; 
   716 	data.iOperationId = 1;
   717 	err = session.TestCliServDataParam(ELogOperationGetResult,buf, smallBuf, 0);	
   718 	TEST2(err, KErrArgument);
   719 	
   720 	CleanupStack::PopAndDestroy(&session);
   721 	}
   722 
   723 /**
   724 @SYMTestCaseID          SYSLIB-LOGENG-LEGACY-T_LOGSERVIPC-0001
   725 @SYMTestCaseDesc	    Tests Message schema validation for the messages accepting
   726  						TLogClientServerData parameters.
   727 @SYMTestPriority 	    High
   728 @SYMTestActions  	    Sends messages to the test server to test the validation of messages
   729 						against the message schema.  The messages contain either valid or invalid 
   730 						parameters. 
   731 @SYMTestExpectedResults The server should validate the message and handle bad messages appropriately
   732 @SYMDEF                	INC114113
   733 */
   734 void TestCliServDataParam2L()
   735 	{
   736 	RClientMessageTestSession session;
   737 	
   738 	TInt err = session.Connect();
   739     TEST2(err, KErrNone);
   740 	
   741 	CleanupClosePushL(session);
   742 	
   743 	TBuf8<sizeof(TLogClientServerData) - 1> buf;
   744 	
   745 	buf.FillZ();
   746 	
   747 	//This should panic with Logserv 63
   748 	err = session.TestCliServDataParam(ELogOperationInitiate,buf);	
   749     TEST2(err, KErrNone);
   750 	
   751 	CleanupStack::PopAndDestroy(&session);
   752 	}
   753 
   754 /**
   755 @SYMTestCaseID          SYSLIB-LOGENG-LEGACY-T_LOGSERVIPC-0002
   756 @SYMTestCaseDesc	    Tests Message schema validation for the messages accepting
   757  						TLogClientServerData parameters.
   758 @SYMTestPriority 	    High
   759 @SYMTestActions  	    Sends messages to the test server to test the validation of messages
   760 						against the message schema.  The messages contain either valid or invalid 
   761 						parameters. 
   762 @SYMTestExpectedResults The server should validate the message and handle bad messages appropriately
   763 @SYMDEF                	INC114113
   764 */
   765 void TestCliServDataParam3L()
   766 	{
   767 	RClientMessageTestSession session;
   768 	
   769 	TInt err = session.Connect();
   770     TEST2(err, KErrNone);
   771 	
   772 	CleanupClosePushL(session);
   773 	
   774 	TBuf8<sizeof(TLogClientServerData) + 1> buf;
   775 	
   776 	buf.FillZ();
   777 	
   778 	err = session.TestCliServDataParam(ELogOperationInitiate,buf);	
   779 	TEST2(err, KErrArgument);
   780 	
   781 	CleanupStack::PopAndDestroy(&session);
   782 	}
   783 
   784 
   785 /**
   786 @SYMTestCaseID          SYSLIB-LOGENG-CT-4005
   787 @SYMTestCaseDesc	    Tests Message schema validation for the ELogNotify message.
   788 @SYMTestPriority 	    High
   789 @SYMTestActions  	    Sends messages to the test server to test the validation of messages
   790 						against the message schema.  The messages contain either valid or invalid 
   791 						parameters. 
   792 @SYMTestExpectedResults The server should validate the message and handle bad messages appropriately
   793 @SYMDEF                	INC114113
   794 */
   795 void TestLogNotifyL()
   796 	{
   797 	
   798 	RClientMessageTestSession session;
   799 	
   800 	TInt err = session.Connect();
   801     TEST2(err, KErrNone);
   802 
   803     CleanupClosePushL(session);
   804 	
   805 	err = session.TestLogNotify(0);
   806 	TEST2(err, KErrNone);	
   807 	
   808 	//Cancel the pending notification
   809 	err = session.TestLogNotifyCancel();
   810 	TEST2(err, KErrNone);
   811 	
   812 	err = session.TestLogNotify(1000000);
   813 	TEST2(err, KErrNone);
   814 	
   815 	//Cancel the pending notification
   816 	err = session.TestLogNotifyCancel();
   817 	TEST2(err, KErrNone);
   818 	
   819 	err = session.TestLogNotify(-1);
   820 	TEST2(err, KErrNone);
   821 	
   822 	CleanupStack::PopAndDestroy(&session);
   823 	}
   824 
   825 /**
   826 @SYMTestCaseID          SYSLIB-LOGENG-CT-4006
   827 @SYMTestCaseDesc	    Tests Message schema validation for the ELogViewCreate message.
   828 @SYMTestPriority 	    High
   829 @SYMTestActions  	    Sends messages to the test server to test the validation of messages
   830 						against the message schema.  The messages contain either valid or invalid 
   831 						parameters. 
   832 @SYMTestExpectedResults The server should validate the message and handle bad messages appropriately
   833 @SYMDEF                	INC114113
   834 */
   835 void TestLogViewCreateL()
   836 	{
   837 	
   838 	RClientMessageTestSession session;
   839 	
   840 	TInt err = session.Connect();
   841     TEST2(err, KErrNone);
   842 	
   843 	CleanupClosePushL(session);
   844 	
   845 	err = session.TestLogViewCreate(0,ELogViewTypeEvent);	
   846 	TEST2(err, KErrNone);
   847 	
   848 	err = session.TestLogViewCreate(100000,ELogViewTypeDuplicate);	
   849 	TEST2(err, KErrNone);
   850 	
   851 	err = session.TestLogViewCreate(0,ELogViewTypeDuplicate + 1);	
   852 	TEST2(err, KErrArgument);
   853 	
   854 	err = session.TestLogViewCreate(-1,ELogViewTypeRecent);	
   855 	TEST2(err, KErrNone);
   856 	
   857 	err = session.TestLogViewCreate(20,-1);	
   858 	TEST2(err, KErrArgument);
   859 
   860 	CleanupStack::PopAndDestroy(&session);
   861 	}
   862 
   863 
   864 /**
   865 @SYMTestCaseID          SYSLIB-LOGENG-CT-4012
   866 @SYMTestCaseDesc	    Tests Message schema validation for the ELogNotifyExtended message.
   867 @SYMTestPriority 	    High
   868 @SYMTestActions  	    Sends a message to the test server to test the validation of messages
   869 						against the message schema.  The message contains an invalid descriptor. 
   870 @SYMTestExpectedResults The server should panic the client with KErrBadDescriptor
   871 @SYMDEF                	INC114113
   872 */
   873 void TestLogNotifyExtended2L()
   874 	{
   875 	
   876 	RClientMessageTestSession session;
   877 
   878 	TInt err = session.Connect();
   879     TEST2(err, KErrNone);
   880 	
   881 	CleanupClosePushL(session);
   882 
   883 	_LIT8(KDes8,"Des8");
   884 	TPckgBuf<TInt> int0(0);
   885 	
   886 	err = session.TestLogNotifyExtended(int0, 0, -1, KDes8);	
   887 	TEST2(err, KErrNone);
   888 
   889 	CleanupStack::PopAndDestroy(&session);
   890 	}
   891 
   892 /**
   893 @SYMTestCaseID          SYSLIB-LOGENG-CT-4013
   894 @SYMTestCaseDesc	    Tests Message schema validation for an invalid message
   895 @SYMTestPriority 	    High
   896 @SYMTestActions  	    Sends a message to the test server with a message number not 
   897 						defined in the schema.
   898 @SYMTestExpectedResults The server should return KErrInvalidFunction
   899 @SYMDEF                	INC114113
   900 */
   901 void InvalidMessageTestL()
   902 	{
   903 	
   904 	RClientMessageTestSession session;
   905 	
   906 	TInt err = session.Connect();
   907     TEST2(err, KErrNone);
   908 	
   909 	CleanupClosePushL(session);
   910 	
   911 	//This should cause the server to panic the client
   912 	err = session.TestFunction45(0);	
   913 	
   914 	CleanupStack::PopAndDestroy(&session);
   915 	}
   916 
   917 
   918 
   919 static void DoAPITestsL()
   920 	{
   921 	
   922 	TExitDetails exitDetails;
   923 	
   924 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-4004 "));
   925 	exitDetails = LaunchTestThreadL(_L("TestCliServDataParamL"), &TestCliServDataParamL);
   926 	TEST2(exitDetails.iExitType, EExitKill);
   927 	
   928 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-LEGACY-T_LOGSERVIPC-0001 "));
   929 	exitDetails = LaunchTestThreadL(_L("TestCliServDataParam2L"), &TestCliServDataParam2L);
   930 	TEST2(exitDetails.iExitType, EExitPanic);
   931 	TEST2(exitDetails.iReason, ELogBadDescriptor);
   932 	
   933 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-LEGACY-T_LOGSERVIPC-0002 "));
   934 	exitDetails = LaunchTestThreadL(_L("TestCliServDataParam3L"), &TestCliServDataParam3L);
   935 	TEST2(exitDetails.iExitType, EExitPanic);
   936 	TEST2(exitDetails.iReason, ELogBadDescriptor);
   937 	
   938 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-4005 "));
   939 	exitDetails = LaunchTestThreadL(_L("TestLogNotifyL"), &TestLogNotifyL);
   940 	TEST2(exitDetails.iExitType, EExitKill);
   941 	
   942 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-4006 "));
   943 	exitDetails = LaunchTestThreadL(_L("TestLogViewCreateL"), &TestLogViewCreateL);
   944 	TEST2(exitDetails.iExitType, EExitKill);
   945 	
   946 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-4012 "));
   947 	exitDetails = LaunchTestThreadL(_L("TestLogNotifyExtended2L"), &TestLogNotifyExtended2L);
   948 	TEST2(exitDetails.iExitType, EExitKill);
   949 	
   950 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-4013 "));
   951 	exitDetails = LaunchTestThreadL(_L("InvalidMessageTestL"), &InvalidMessageTestL);
   952 	TEST2(exitDetails.iExitType, EExitPanic);
   953 	TEST2(exitDetails.iReason, ELogIllegalFunction);
   954 
   955  	//test for debug-only API
   956 #ifdef _DEBUG
   957 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-4003 "));
   958  	exitDetails = LaunchTestThreadL(_L("TestMakeTransientL"), &TestMakeTransientL);
   959  	TEST2(exitDetails.iExitType, EExitKill);
   960 #endif//_DEBUG	
   961 	}
   962 
   963 
   964 
   965 
   966 GLDEF_C TInt E32Main ()
   967 	{
   968 
   969 	TheTest.Printf (_L ("\n"));
   970 	TheTest.Title ();
   971 	TheTest.Start (_L("IPC Fuzz Tests"));
   972 
   973    	CTrapCleanup* cleanup=CTrapCleanup::New();
   974    	TEST(cleanup != NULL);
   975 	
   976    	TInt err=KErrNoMemory;
   977    	if (cleanup)
   978    		{
   979    		
   980    		// Construct and install the active scheduler
   981    		CActiveScheduler* scheduler = new CActiveScheduler;
   982    	    TEST(scheduler != NULL);
   983    		CActiveScheduler::Install (scheduler);
   984    		
   985    		KillProcess(KServerProcess);
   986    		User::After(1000000);
   987    				
   988    		TRAP (err, DoFuzzTestsL ());
   989    		TEST2(err, KErrNone);
   990    		
   991    		TheTest.Next(_L("LogServ API Robustness Tests"));
   992    		TRAP (err, DoAPITestsL ());
   993    		TEST2(err, KErrNone);
   994    		
   995    		TheTest.End ();
   996    		TheTest.Close ();
   997    		
   998    		delete scheduler;
   999    		delete cleanup;
  1000    		
  1001    		}
  1002 	return err;
  1003 	}