loggingservices/eventlogger/test/src/t_logbadclient.cpp
changeset 40 b8bdbc8f59c7
parent 17 55f2396f6d25
child 45 cc28652e0254
child 51 7d4490026038
equal deleted inserted replaced
33:5e4beccba4e9 40:b8bdbc8f59c7
   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 
   216 /**
   260 /**
   217 @SYMTestCaseID			PDS-LOGENG-UT-4045
   261 @SYMTestCaseID			PDS-LOGENG-UT-4045
   218 @SYMTestCaseDesc		In a loop, where the loop iterations are less than KTestIterCount (5000 at the moment), 
   262 @SYMTestCaseDesc		In a loop, where the loop iterations are less than KTestIterCount (5000 at the moment), 
   219 						the test creates a worker thread, which will behave as a malicious client. 
   263 						the test creates a worker thread, which will behave as a malicious client. 
   220 						If the worker thread crashes the LogEng server, then the worker thread
   264 						If the worker thread crashes the LogEng server, then the worker thread
   225 @SYMTestExpectedResults Test must not fail
   269 @SYMTestExpectedResults Test must not fail
   226 @SYMREQ					REQ12746
   270 @SYMREQ					REQ12746
   227 */	
   271 */	
   228 void BadClientTest()
   272 void BadClientTest()
   229 	{
   273 	{
       
   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 
   230 	TThreadData* p = new TThreadData;
   281 	TThreadData* p = new TThreadData;
   231 	TEST(p != NULL);
   282 	TEST(p != NULL);
   232 	TThreadData& data = *p;
   283 	TThreadData& data = *p;
   233 	data.iFunction = 0;
   284 	data.iFunction = 0;
   234 	TTime now;
   285 	TTime now;
   241 		
   292 		
   242 		//Run the malicious client (one test thread which will try to crash the LogEng server)
   293 		//Run the malicious client (one test thread which will try to crash the LogEng server)
   243 		User::After(200000);
   294 		User::After(200000);
   244 		_LIT(KTestThreadName, "TLBCThr");
   295 		_LIT(KTestThreadName, "TLBCThr");
   245 		RThread thread;
   296 		RThread thread;
   246 		TInt err = thread.Create(KTestThreadName, &ThreadFunc1, 0x2000, 0x1000, 0x10000, &data, EOwnerProcess);
   297 		err = thread.Create(KTestThreadName, &ThreadFunc1, 0x2000, 0x1000, 0x10000, &data, EOwnerProcess);
   247 		if(err == KErrAlreadyExists)
   298 		if(err == KErrAlreadyExists)
   248 			{
   299 			{
   249 			TheTest.Printf(_L("##Iteration %d. Function %d. Thread \"%S\" already exists!\r\n"), data.iIteration, data.iFunction, &KTestThreadName);
   300 			TheTest.Printf(_L("##Iteration %d. Function %d. Thread \"%S\" already exists!\r\n"), data.iIteration, data.iFunction, &KTestThreadName);
   250 			for(TInt i=0;i<KMaxMessageArguments;++i)
   301 			for(TInt i=0;i<KMaxMessageArguments;++i)
   251 				{
   302 				{
   272 		User::SetJustInTime(EFalse);		
   323 		User::SetJustInTime(EFalse);		
   273 		TRequestStatus status;
   324 		TRequestStatus status;
   274 		thread.Logon(status);
   325 		thread.Logon(status);
   275 		TEST2(status.Int(), KRequestPending);
   326 		TEST2(status.Int(), KRequestPending);
   276 		thread.Resume();
   327 		thread.Resume();
   277 		User::WaitForRequest(status);
   328 		User::WaitForRequest(status, serverStatus);
       
   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 
   278 		TExitType exitType = thread.ExitType();
   337 		TExitType exitType = thread.ExitType();
   279 		TInt exitReason = thread.ExitReason();
   338 		TInt exitReason = thread.ExitReason();
   280 		thread.Close();
   339 		thread.Close();
   281 		User::SetJustInTime(ETrue);
   340 		User::SetJustInTime(ETrue);
   282 		
   341 		
   308 				TEST(0);
   367 				TEST(0);
   309 				}
   368 				}
   310 			}
   369 			}
   311 		}//for
   370 		}//for
   312 	delete p;
   371 	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 		
   313 	}
   379 	}
   314 
   380 
   315 /**
   381 /**
   316 @SYMTestCaseID			PDS-LOGENG-UT-4044
   382 @SYMTestCaseID			PDS-LOGENG-UT-4044
   317 @SYMTestCaseDesc		LogEng server startup - file I/O error simulation test.
   383 @SYMTestCaseDesc		LogEng server startup - file I/O error simulation test.