loggingservices/eventlogger/test/src/t_logbadclient.cpp
branchRCL_3
changeset 24 cc28652e0254
parent 23 26645d81f48d
equal deleted inserted replaced
23:26645d81f48d 24:cc28652e0254
   211 	__UHEAP_MARKEND;
   211 	__UHEAP_MARKEND;
   212 	
   212 	
   213 	return KErrNone;		
   213 	return KErrNone;		
   214 	}
   214 	}
   215 
   215 
   216 //////////////////////////////////////////////////////////////////////////////////////////////////
       
   217 //////////////////////////////////////////////////////////////////////////////////////////////////
       
   218 
       
   219 //Thread function to detect a crash in the server.
       
   220 //The server should run for the duration of the test.
       
   221 // return KErrAbort: If failure to start server
       
   222 // return KErrServerTerminated: If server process is terminated 
       
   223 
       
   224 TInt ServerWatcherFunc(TAny* /*aData*/)
       
   225 	{
       
   226 	__UHEAP_MARK;
       
   227 
       
   228 	_LIT(KLogEngServerName,"LogServ*");
       
   229 
       
   230 	TInt err;
       
   231 
       
   232 	// Start the server if not already running
       
   233 	RLogSession sess;
       
   234 	err = sess.Connect();
       
   235 	if (err != KErrNone)
       
   236 		return KErrAbort;
       
   237 	sess.Close();
       
   238 
       
   239 	TFindProcess findProcess(KLogEngServerName);
       
   240 	TFullName result;
       
   241 	if ( findProcess.Next(result) != KErrNone )
       
   242 		return KErrAbort;
       
   243 	
       
   244 	RProcess server;
       
   245 	if( server.Open(findProcess, EOwnerProcess) != KErrNone)
       
   246 		return KErrAbort;
       
   247 
       
   248 	TRequestStatus status;
       
   249 	server.Logon(status);	
       
   250  	User::WaitForRequest(status);
       
   251 	
       
   252 	server.Close();
       
   253 	
       
   254 	__UHEAP_MARKEND;
       
   255 
       
   256 	return KErrServerTerminated;
       
   257 	}
       
   258 
       
   259 
       
   260 /**
   216 /**
   261 @SYMTestCaseID			PDS-LOGENG-UT-4045
   217 @SYMTestCaseID			PDS-LOGENG-UT-4045
   262 @SYMTestCaseDesc		In a loop, where the loop iterations are less than KTestIterCount (5000 at the moment), 
   218 @SYMTestCaseDesc		In a loop, where the loop iterations are less than KTestIterCount (5000 at the moment), 
   263 						the test creates a worker thread, which will behave as a malicious client. 
   219 						the test creates a worker thread, which will behave as a malicious client. 
   264 						If the worker thread crashes the LogEng server, then the worker thread
   220 						If the worker thread crashes the LogEng server, then the worker thread
   269 @SYMTestExpectedResults Test must not fail
   225 @SYMTestExpectedResults Test must not fail
   270 @SYMREQ					REQ12746
   226 @SYMREQ					REQ12746
   271 */	
   227 */	
   272 void BadClientTest()
   228 void BadClientTest()
   273 	{
   229 	{
   274 	// Start a thread to watch the server process
       
   275 	RThread serverWatcher;
       
   276 	TInt err = serverWatcher.Create(_L("ServerWatcher"), &ServerWatcherFunc, 0x2000, 0x1000, 0x10000, NULL, EOwnerProcess);
       
   277 	TRequestStatus serverStatus;
       
   278 	serverWatcher.Logon(serverStatus);
       
   279 	serverWatcher.Resume();
       
   280 
       
   281 	TThreadData* p = new TThreadData;
   230 	TThreadData* p = new TThreadData;
   282 	TEST(p != NULL);
   231 	TEST(p != NULL);
   283 	TThreadData& data = *p;
   232 	TThreadData& data = *p;
   284 	data.iFunction = 0;
   233 	data.iFunction = 0;
   285 	TTime now;
   234 	TTime now;
   292 		
   241 		
   293 		//Run the malicious client (one test thread which will try to crash the LogEng server)
   242 		//Run the malicious client (one test thread which will try to crash the LogEng server)
   294 		User::After(200000);
   243 		User::After(200000);
   295 		_LIT(KTestThreadName, "TLBCThr");
   244 		_LIT(KTestThreadName, "TLBCThr");
   296 		RThread thread;
   245 		RThread thread;
   297 		err = thread.Create(KTestThreadName, &ThreadFunc1, 0x2000, 0x1000, 0x10000, &data, EOwnerProcess);
   246 		TInt err = thread.Create(KTestThreadName, &ThreadFunc1, 0x2000, 0x1000, 0x10000, &data, EOwnerProcess);
   298 		if(err == KErrAlreadyExists)
   247 		if(err == KErrAlreadyExists)
   299 			{
   248 			{
   300 			TheTest.Printf(_L("##Iteration %d. Function %d. Thread \"%S\" already exists!\r\n"), data.iIteration, data.iFunction, &KTestThreadName);
   249 			TheTest.Printf(_L("##Iteration %d. Function %d. Thread \"%S\" already exists!\r\n"), data.iIteration, data.iFunction, &KTestThreadName);
   301 			for(TInt i=0;i<KMaxMessageArguments;++i)
   250 			for(TInt i=0;i<KMaxMessageArguments;++i)
   302 				{
   251 				{
   323 		User::SetJustInTime(EFalse);		
   272 		User::SetJustInTime(EFalse);		
   324 		TRequestStatus status;
   273 		TRequestStatus status;
   325 		thread.Logon(status);
   274 		thread.Logon(status);
   326 		TEST2(status.Int(), KRequestPending);
   275 		TEST2(status.Int(), KRequestPending);
   327 		thread.Resume();
   276 		thread.Resume();
   328 		User::WaitForRequest(status, serverStatus);
   277 		User::WaitForRequest(status);
   329 
       
   330 		// If the Server has crashed then we must fail		
       
   331 		if (serverStatus != KRequestPending) 
       
   332 			{
       
   333 			TheTest.Printf(_L("##Iteration=%d, Function=%d, Status1=%d, Status2=%d\r\n"), data.iIteration, data.iFunction, status.Int(), serverStatus.Int());
       
   334 			break;
       
   335 			}
       
   336 
       
   337 		TExitType exitType = thread.ExitType();
   278 		TExitType exitType = thread.ExitType();
   338 		TInt exitReason = thread.ExitReason();
   279 		TInt exitReason = thread.ExitReason();
   339 		thread.Close();
   280 		thread.Close();
   340 		User::SetJustInTime(ETrue);
   281 		User::SetJustInTime(ETrue);
   341 		
   282 		
   367 				TEST(0);
   308 				TEST(0);
   368 				}
   309 				}
   369 			}
   310 			}
   370 		}//for
   311 		}//for
   371 	delete p;
   312 	delete p;
   372 
       
   373 
       
   374 	// Check to see if the server crashed and not detected by client
       
   375 	TEST(serverStatus.Int() == KRequestPending);
       
   376 	serverWatcher.Kill(KErrCancel);
       
   377 	serverWatcher.Close();
       
   378 		
       
   379 	}
   313 	}
   380 
   314 
   381 /**
   315 /**
   382 @SYMTestCaseID			PDS-LOGENG-UT-4044
   316 @SYMTestCaseID			PDS-LOGENG-UT-4044
   383 @SYMTestCaseDesc		LogEng server startup - file I/O error simulation test.
   317 @SYMTestCaseDesc		LogEng server startup - file I/O error simulation test.