os/ossrv/genericservices/taskscheduler/Test/Robustness/TC_TSCH_ROBUSTNESS.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericservices/taskscheduler/Test/Robustness/TC_TSCH_ROBUSTNESS.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,583 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <csch_cli.h>
    1.20 +#include "Thelpers.h"
    1.21 +
    1.22 +#include <e32base.h>
    1.23 +#include <e32test.h>
    1.24 +#include <f32file.h>
    1.25 +#include <s32file.h>
    1.26 +#include <e32property.h>
    1.27 +#include <schinfointernal.h>
    1.28 +#include "TestUtils.h"
    1.29 +
    1.30 +_LIT(KTestName,	"Task Scheduler Robustness Test");
    1.31 +_LIT(KTaskScheduler, "schexe");
    1.32 +
    1.33 +RTest	TheTest(KTestName);
    1.34 +
    1.35 +typedef CArrayFixFlat<TTaskInfo>			CTaskInfoArray;
    1.36 +typedef CArrayFixFlat<TSchedulerItemRef>    CSchItemRefArray;
    1.37 +typedef CArrayFixFlat<TTaskSchedulerCondition>	CSchConditionArray;
    1.38 +
    1.39 +static RScheduler	TheScheduler;
    1.40 +static CTrapCleanup*	TheCleanup;
    1.41 +static RFs			TheFsSession;
    1.42 +
    1.43 +const TInt KTestKey1 = 1;
    1.44 +
    1.45 +_LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames
    1.46 +
    1.47 +// This function launches the TPropertyDefine process which
    1.48 +//	has WriteDeviceData Capabilities enabling it to create the P&S 
    1.49 +//	variables used by this test.
    1.50 +static void LaunchHelperL(TUid aCategory, TInt aKey, TInt aAttr)
    1.51 +	{
    1.52 +	_LIT(KConditionHelper, "TPropertyDefine");
    1.53 +	TRequestStatus stat;
    1.54 +	RProcess p;
    1.55 +	
    1.56 +	TBuf<32> args;
    1.57 +	args.AppendNum(aCategory.iUid);
    1.58 +	args.Append(KSeparator);
    1.59 +	args.AppendNum(aKey);
    1.60 +	args.Append(KSeparator);
    1.61 +	args.AppendNum(aAttr);
    1.62 +	
    1.63 +	User::LeaveIfError(p.Create(KConditionHelper, args,EOwnerProcess));
    1.64 +	
    1.65 +	// Asynchronous logon: completes when process terminates with process exit code
    1.66 +	p.Logon(stat);
    1.67 +	p.Resume();
    1.68 +
    1.69 +	User::WaitForRequest(stat);
    1.70 +	TInt exitReason = p.ExitReason();
    1.71 +	p.Close();
    1.72 +	User::LeaveIfError(exitReason);
    1.73 +	}
    1.74 +	
    1.75 +	
    1.76 +static void CreateTestVariables()
    1.77 +	{
    1.78 +	LaunchHelperL(KUidSystemCategory, KTestKey1,RProperty::EInt);
    1.79 +	}	
    1.80 +
    1.81 +static void ResetVariablesL(TInt aKey1Val)
    1.82 +	{
    1.83 +	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey1,aKey1Val));		
    1.84 +	}
    1.85 +	
    1.86 +	
    1.87 +// single condition with default time set to 1 year in the future
    1.88 +static TInt CreateScheduleL(TSchedulerItemRef& aRef, 
    1.89 +									RScheduler& aScheduler,
    1.90 +									const TUid& aConditionUID,
    1.91 +									TUint aConditionUInt)
    1.92 +	{
    1.93 +	aRef.iName = _L("Schedule created using CreateScheduleSingle");
    1.94 +
    1.95 +	CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(1);
    1.96 +	CleanupStack::PushL(conditionList);
    1.97 +	
    1.98 +	//create a single condition
    1.99 +	TTaskSchedulerCondition condition1;
   1.100 +	condition1.iCategory = aConditionUID;
   1.101 +	condition1.iKey		= aConditionUInt;
   1.102 +	condition1.iState	= 10;
   1.103 +	condition1.iType	= TTaskSchedulerCondition::EEquals;
   1.104 +	
   1.105 +	conditionList->AppendL(condition1);
   1.106 +		
   1.107 +	//create a persistent schedule
   1.108 +	TTime time = SchSvrHelpers::TimeBasedOnOffset(0, 0, 0, 0, 0, 1); //1 year in the future
   1.109 +	TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
   1.110 +	CleanupStack::PopAndDestroy(); // conditionList
   1.111 +	return res;
   1.112 +	}
   1.113 +
   1.114 +//Add a single task to a schedule	
   1.115 +static TInt AddTaskToScheduleL(const TDesC& aName, 
   1.116 +									TInt& aNewId, 
   1.117 +									TInt aScheduleId, 
   1.118 +									RScheduler& aScheduler)
   1.119 +	{
   1.120 +	TTaskInfo taskInfo;
   1.121 +	taskInfo.iTaskId = aNewId;
   1.122 +	taskInfo.iName = aName;
   1.123 +	taskInfo.iPriority = 2;
   1.124 +	taskInfo.iRepeat = 0;
   1.125 +	HBufC* data = _L("the data").AllocLC();
   1.126 +	TInt res = aScheduler.ScheduleTask(taskInfo, *data, aScheduleId);
   1.127 +	aNewId = taskInfo.iTaskId;
   1.128 +
   1.129 +	CleanupStack::PopAndDestroy(); // data
   1.130 +	return res;
   1.131 +	}
   1.132 +	
   1.133 +	
   1.134 +static TInt ScheduleTaskL()
   1.135 +	{
   1.136 +	//reset the p&s variables before creating the schedule
   1.137 +	ResetVariablesL(0);
   1.138 +	
   1.139 +	//Create a schedule
   1.140 +	TSchedulerItemRef ref1;
   1.141 +	TheTest.Printf(_L("Create a schedule\n"));
   1.142 +	TInt res = CreateScheduleL(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
   1.143 +	TEST2(res, KErrNone);
   1.144 +	
   1.145 +	//Add task to the schedule
   1.146 +	TInt task1 = 0;
   1.147 +	_LIT(KName1, "Test Task");
   1.148 +	TheTest.Printf(_L("Schedule a task\n"));
   1.149 +
   1.150 +	res = AddTaskToScheduleL(KName1, task1, ref1.iHandle, TheScheduler);
   1.151 +	TEST2(res, KErrNone);
   1.152 +	 
   1.153 +	return res;	
   1.154 +	}
   1.155 +	
   1.156 +static void ExecuteTaskL()
   1.157 +	{
   1.158 +	TheTest.Printf(_L("Execute Task\n"));
   1.159 +	//Set property causing schedule to be run
   1.160 +	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey1,10));
   1.161 +	
   1.162 +	//Pause to wait for the task to be executed
   1.163 +	SchSvrHelpers::Pause(TheTest, 2);
   1.164 +	
   1.165 +	}
   1.166 +
   1.167 +static TInt ScheduleAndExecuteTaskL()
   1.168 +	{
   1.169 +	TInt res = ScheduleTaskL();
   1.170 +
   1.171 +	ExecuteTaskL();
   1.172 +	 
   1.173 +	return res;	
   1.174 +	}
   1.175 +
   1.176 +LOCAL_C void AddTaskFunctionL()
   1.177 +	{
   1.178 +	RScheduler	localScheduler;
   1.179 +	// Connect to the server
   1.180 +	TInt res = localScheduler.Connect();
   1.181 +	TEST2(res, KErrNone);
   1.182 +	//Schedule a task and execute it
   1.183 +	//reset the p&s variables before creating the schedule
   1.184 +	ResetVariablesL(0);
   1.185 +		
   1.186 +	//Create a schedule
   1.187 +	TSchedulerItemRef ref1;
   1.188 +	ref1.iName = _L("Schedule created using CreateScheduleSingle");
   1.189 +	CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(1);
   1.190 +	CleanupStack::PushL(conditionList);
   1.191 +		
   1.192 +	//create a single condition
   1.193 +	TTaskSchedulerCondition condition1;
   1.194 +	condition1.iCategory = KUidSystemCategory;
   1.195 +	condition1.iKey		= KTestKey1;
   1.196 +	condition1.iState	= 10;
   1.197 +	condition1.iType	= TTaskSchedulerCondition::EEquals;
   1.198 +			
   1.199 +	conditionList->AppendL(condition1);
   1.200 +				
   1.201 +	//create a persistent schedule
   1.202 +	TTime time = SchSvrHelpers::TimeBasedOnOffset(0, 0, 0, 0, 0, 1); //1 year in the future
   1.203 +	res = localScheduler.CreatePersistentSchedule(ref1, *conditionList, time);
   1.204 +	CleanupStack::PopAndDestroy(); // conditionList
   1.205 +			
   1.206 +	//Add task to the schedule
   1.207 +	TInt task1 = 0;
   1.208 +	_LIT(KName1, "Test Task");
   1.209 +		
   1.210 +	TTaskInfo taskInfo;
   1.211 +	taskInfo.iTaskId = task1;
   1.212 +	taskInfo.iName = KName1;
   1.213 +	taskInfo.iPriority = 2;
   1.214 +	taskInfo.iRepeat = 0;
   1.215 +	HBufC* data = _L("the data").AllocLC();
   1.216 +
   1.217 +	TInt ret = localScheduler.ScheduleTask(taskInfo, *data, ref1.iHandle);
   1.218 +	TEST2(ret, 0);//EPanicNotRegistered == 0
   1.219 +		
   1.220 +	task1 = taskInfo.iTaskId;
   1.221 +
   1.222 +	CleanupStack::PopAndDestroy(); // data
   1.223 +		
   1.224 +	//Tidying up so next test will be clear.
   1.225 +	SchSvrHelpers::DeleteAllSchedulesL(localScheduler);
   1.226 +
   1.227 +	localScheduler.Close();
   1.228 +	}
   1.229 +
   1.230 +// Helper function for DEF124488 
   1.231 +LOCAL_C TInt TestPanicThread(TAny*)
   1.232 +	{
   1.233 +	CTrapCleanup* cleanup = CTrapCleanup::New();
   1.234 +	if(!cleanup)
   1.235 +		return KErrNoMemory;
   1.236 +	
   1.237 +
   1.238 +	TRAPD(err,AddTaskFunctionL())
   1.239 +	TEST2(err,KErrNone);
   1.240 +	
   1.241 +	delete cleanup;
   1.242 +	return KErrNone;
   1.243 +	}
   1.244 +
   1.245 +/**	
   1.246 +@SYMTestCaseID 	SYSLIB-SCHSVR-CT-3369
   1.247 +@SYMTestCaseDesc	Test deletion of temporary files with non existent client
   1.248 +@SYMTestPriority	High
   1.249 +@SYMTestActions 	Schedule a task with a client that does not exist.  
   1.250 +					Ensure that all temporary files are deleted after 
   1.251 +					schedule excecutes
   1.252 +@SYMTestExpectedResults All temporary files should be deleted by task scheduler
   1.253 +@SYMDEF 		 PDEF101876
   1.254 +*/
   1.255 +static void DoTest1L()
   1.256 +	{	
   1.257 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3369 Test handling of non existent client "));	
   1.258 +	// Connect to the server
   1.259 +	TheTest.Next(_L("===== Connect to Scheduler ====="));
   1.260 +	TInt res = TheScheduler.Connect();
   1.261 +	TEST2(res, KErrNone);
   1.262 +	
   1.263 +	// Register a client with the server - this client does not exist
   1.264 +	TheTest.Next(_L("===== Registering Client ====="));
   1.265 +	res = SchSvrHelpers::RegisterNonExistentClient(TheScheduler);
   1.266 +	TEST2(res, KErrNone);
   1.267 +
   1.268 +	//Schedule a task and execute it
   1.269 +	ScheduleAndExecuteTaskL();
   1.270 +	
   1.271 +	// Check for left task files after scheduled tasks completed
   1.272 +	// To access private data cage, uses SchSvrHelplers::CheckTaskFilesL()
   1.273 +	TheTest.Next(_L("Now checking no files left when tasks completed"));
   1.274 +	TInt err = SchSvrHelpers::CheckTaskFilesL();
   1.275 +	
   1.276 +	// If there's any task files left, test fails with error code KErrGeneral
   1.277 +	TEST(err == KErrNone);
   1.278 +	TheTest.Next(_L("All files deleted as expected..."));
   1.279 +
   1.280 +	//Tidying up so next test will be clear.
   1.281 +	TheTest.Next(_L("Delete all schedules"));
   1.282 +	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
   1.283 +
   1.284 +	TheScheduler.Close();
   1.285 +
   1.286 +	}
   1.287 +	
   1.288 +/**
   1.289 +@SYMTestCaseID 	SYSLIB-SCHSVR-CT-3370
   1.290 +@SYMTestCaseDesc	Test deletion of temporary files with faulty client
   1.291 +@SYMTestPriority	High
   1.292 +@SYMTestActions 	Schedule a task with a client that panics and does not 
   1.293 +					release the temporary file handle. 
   1.294 +					Ensure that all temporary files are deleted after schedule excecutes
   1.295 +@SYMTestExpectedResults All temporary files should be deleted by task scheduler
   1.296 +@SYMDEF 		 PDEF101876
   1.297 +*/	
   1.298 +static void DoTest2L()
   1.299 +	{
   1.300 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3370 Test handling of panicing client "));
   1.301 +	
   1.302 +	// Connect to the server
   1.303 +	TheTest.Next(_L("===== Connect to Scheduler ====="));
   1.304 +	TInt res = TheScheduler.Connect();
   1.305 +	TEST2(res, KErrNone);
   1.306 +	
   1.307 +	// Register a client with the server - this client panics
   1.308 +	//after calling RFile::AdoptFromClient
   1.309 +	TheTest.Next(_L("===== Registering Client ====="));
   1.310 +	res = SchSvrHelpers::RegisterPanicingClient(TheScheduler);
   1.311 +	TEST2(res, KErrNone);
   1.312 +		
   1.313 +	//Schedule a task and execute it - we expect the client to panic
   1.314 +	ScheduleAndExecuteTaskL();
   1.315 +	
   1.316 +	// Check for left task files after scheduled tasks completed
   1.317 +	// To access private data cage, uses SchSvrHelplers::CheckTaskFilesL()
   1.318 +	TheTest.Next(_L("Now checking no files left when tasks completed"));
   1.319 +	TInt err = SchSvrHelpers::CheckTaskFilesL();
   1.320 +
   1.321 +	// If there's any task files left, test fails with error code KErrGeneral
   1.322 +	TEST(err == KErrNone);	
   1.323 +	
   1.324 +	TheTest.Next(_L("All files deleted as expected..."));
   1.325 +
   1.326 +	//Tidying up so next test will be clear.
   1.327 +	TheTest.Next(_L("Delete all schedules"));
   1.328 +	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
   1.329 +
   1.330 +	TheScheduler.Close();
   1.331 +	}
   1.332 +
   1.333 +/**
   1.334 +@SYMTestCaseID 	SYSLIB-SCHSVR-CT-3371
   1.335 +@SYMTestCaseDesc	Test deletion of temporary files on task scheduler startup
   1.336 +@SYMTestPriority	High
   1.337 +@SYMTestActions 	Create temporary files in the task schedulers private data cage.
   1.338 +					Start the task scheduler and verify that these files are deleted.
   1.339 +@SYMTestExpectedResults All temporary files should be deleted by task scheduler on startup
   1.340 +@SYMDEF 		 PDEF101876
   1.341 +*/	
   1.342 +static void DoTest3L()
   1.343 +	{	
   1.344 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3371 Test deletion of temporary files on startup "));
   1.345 +	
   1.346 +	//Connect to the scheduler
   1.347 +	TInt res = TheScheduler.Connect();
   1.348 +	TEST2(res, KErrNone);
   1.349 +
   1.350 + 	// Kill the server to ensure we restart it when we connect
   1.351 +	res = CleanupHelpers::KillProcess(KTaskScheduler);
   1.352 +	TEST2(res, KErrNone);
   1.353 + 	TheScheduler.Close();
   1.354 + 	
   1.355 +	// Create task files to test cleanup
   1.356 +	// To access private data cage, uses SchSvrHelplers::CreateTaskFilesL()
   1.357 +	TheTest.Next(_L("Creating dummy task files"));
   1.358 +	res = SchSvrHelpers::CreateTaskFilesL();
   1.359 +
   1.360 +	//Restart the scheduler which should clean up temp files on startup
   1.361 +	TheTest.Next(_L("===== Connect to Scheduler ====="));
   1.362 +	res = TheScheduler.Connect();
   1.363 +	TEST2(res, KErrNone);
   1.364 +	
   1.365 +	//wait for the server to start up
   1.366 +	SchSvrHelpers::Pause(TheTest, 2);
   1.367 +		
   1.368 +	TheScheduler.Close();
   1.369 +	
   1.370 +	// Check for left task files after scheduled tasks completed
   1.371 +	// To access private data cage, uses SchSvrHelplers::CheckTaskFilesL()
   1.372 +	TheTest.Next(_L("Now checking no files left after task scheduler starts"));
   1.373 +	res = SchSvrHelpers::CheckTaskFilesL();
   1.374 +	
   1.375 +	TEST2(res, KErrNone);
   1.376 +	
   1.377 +	TheTest.Next(_L("All files deleted as expected..."));
   1.378 +	}
   1.379 +
   1.380 +/**
   1.381 +@SYMTestCaseID 		SYSLIB-SCHSVR-CT-3402
   1.382 +@SYMTestCaseDesc	Test memory cleanup on Task Scheduler exit
   1.383 +@SYMTestPriority	High
   1.384 +@SYMTestActions 	Start the scheduler and register a client.
   1.385 +					Execute a schedule and then terminate the scheduler.
   1.386 +					When the scheduler is restarted it should exit as there are no
   1.387 +					pending schedules. On exit all allocated memory should be freed	
   1.388 +@SYMTestExpectedResults All allocated memory should be freed when the scheduler exits
   1.389 +@SYMDEF 		 DEF102414
   1.390 +*/	
   1.391 +static void DoTest4L()
   1.392 +	{	
   1.393 +	__UHEAP_MARK;
   1.394 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3402 Test memory cleanup on Task Scheduler exit "));
   1.395 +	
   1.396 +	// Connect to the server
   1.397 +	TheTest.Next(_L("===== Connect to Scheduler ====="));
   1.398 +	TInt res = TheScheduler.Connect();
   1.399 +	TEST2(res, KErrNone);
   1.400 +	
   1.401 +	// Register a client with the server
   1.402 +	TheTest.Next(_L("===== Registering Client ====="));
   1.403 +	res = SchSvrHelpers::RegisterClientL(TheScheduler);
   1.404 +	TEST2(res, KErrNone);
   1.405 +	
   1.406 +	//Schedule a task and execute it
   1.407 +	ScheduleAndExecuteTaskL();
   1.408 +	
   1.409 + 	// Kill the server
   1.410 +	res = CleanupHelpers::KillProcess(KTaskScheduler);
   1.411 +	TEST2(res, KErrNone);
   1.412 +	
   1.413 + 	TheScheduler.Close();
   1.414 +	
   1.415 +	//Restarting with a registered client and no schedule should
   1.416 +	//cause the server to exit.  Ther server should free all allocated
   1.417 +	//memory.  If all memory is not freed, heap check macros within
   1.418 +	// the task scheduler code will cause a panic 
   1.419 +	SchSvrHelpers::LaunchTaskSchedulerL();
   1.420 +	
   1.421 +	//wait for the server to exit
   1.422 +	SchSvrHelpers::Pause(TheTest, 2);
   1.423 +	
   1.424 +	//Verify that the server has already exited - there are two valid 
   1.425 +	//error codes depending on how quickly the process is cleaned up
   1.426 +	//KErrDied - Process is dead but hasn't been cleaned up yet by the kernel
   1.427 +	//KErrNotFound - Process has been cleaned up
   1.428 +	res = CleanupHelpers::KillProcess(KTaskScheduler);
   1.429 +	
   1.430 +	TEST((res == KErrDied)||(res == KErrNotFound));
   1.431 +	
   1.432 +	__UHEAP_MARKEND;
   1.433 +
   1.434 +	TheTest.Next(_L("All memory freed..."));
   1.435 +	}
   1.436 +	
   1.437 +	
   1.438 +/**
   1.439 +@SYMTestCaseID 		SYSLIB-SCHSVR-CT-3412
   1.440 +@SYMTestCaseDesc	Test Task Scheduler startup with pending schedule
   1.441 +@SYMTestPriority	High
   1.442 +@SYMTestActions 	Start the scheduler and register a client.
   1.443 +					Create a scheduled task and then terminate the scheduler without executing the task.
   1.444 +					When the scheduler is restarted it should not exit as there is a 
   1.445 +					pending schedule. Verify that the scheduler is still active by executing
   1.446 +					the schedule
   1.447 +@SYMTestExpectedResults	The task scheduler should not exit and the schedule should execute
   1.448 +@SYMDEF 		 DEF102414
   1.449 +*/	
   1.450 +static void DoTest5L()
   1.451 +	{
   1.452 +	__UHEAP_MARK;
   1.453 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3412 Test Task Scheduler startup with pending schedule "));
   1.454 +	
   1.455 +	// Connect to the server
   1.456 +	TheTest.Next(_L("===== Connect to Scheduler ====="));
   1.457 +	TInt res = TheScheduler.Connect();
   1.458 +	TEST2(res, KErrNone);
   1.459 +	
   1.460 +	// Register a client with the server
   1.461 +	TheTest.Next(_L("===== Registering Client ====="));
   1.462 +	res = SchSvrHelpers::RegisterClientL(TheScheduler);
   1.463 +	TEST2(res, KErrNone);
   1.464 +	
   1.465 +	//Schedule a task
   1.466 +	ScheduleTaskL();
   1.467 +	
   1.468 + 	// Kill the server
   1.469 +	res = CleanupHelpers::KillProcess(KTaskScheduler);
   1.470 +	TEST2(res, KErrNone);
   1.471 + 	TheScheduler.Close();
   1.472 + 	
   1.473 + 	TheTest.Next(_L("Create Task notification semaphore"));
   1.474 +	//initialise task notification semaphore
   1.475 +	STaskSemaphore sem;
   1.476 +	sem.CreateL();
   1.477 +	
   1.478 +	//Restart the scheduler - task scheduler should not exit as there is a 
   1.479 +	//pending schedule
   1.480 +	res = SchSvrHelpers::LaunchTaskSchedulerL();
   1.481 +	TEST2(res, KErrNone);
   1.482 +	
   1.483 +	//Execute task and wait for it to run - this would not succeed
   1.484 +	//if task scheduler had exited above
   1.485 +	ExecuteTaskL();
   1.486 +	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone); 
   1.487 +	
   1.488 +	//Kill the process and verify that the scheduler was active
   1.489 +	//If the task scheduler isnt active when we try to kill it
   1.490 +	//KillProcess would return KErrDied
   1.491 +	res = CleanupHelpers::KillProcess(KTaskScheduler);
   1.492 +	TEST2(res, KErrNone);
   1.493 +	
   1.494 +	//close handle to semaphore
   1.495 +	sem.Close();
   1.496 +
   1.497 +	__UHEAP_MARKEND;	
   1.498 +	
   1.499 +	}
   1.500 +
   1.501 +/**	
   1.502 +@SYMTestCaseID 	SYSLIB-SCHSVR-CT-4010
   1.503 +@SYMTestCaseDesc	Test that adding a task using an unregistered client panics the client and does not crash the server.
   1.504 +@SYMTestPriority	High
   1.505 +@SYMTestActions 	Schedule a task with a client that has not been registered.  
   1.506 +@SYMTestExpectedResults Client should be panicked.
   1.507 +@SYMDEF 		DEF124488 
   1.508 +*/
   1.509 +static void DoTest6L()
   1.510 +	{	
   1.511 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-4010 Test handling of unregistered client Should Panic Client thread "));	
   1.512 +	
   1.513 +	RThread testThread;
   1.514 +	_LIT(KThreadName, "PanicClientThread");
   1.515 +
   1.516 +	testThread.Create(KThreadName, TestPanicThread, KDefaultStackSize, 0x1000, 0x100000, NULL);
   1.517 +
   1.518 +	TRequestStatus requestStatus;
   1.519 +	// Request notification when the thread terminates
   1.520 +	testThread.Logon(requestStatus);
   1.521 +	
   1.522 +	TBool justInTime=User::JustInTime(); 
   1.523 +	User::SetJustInTime(EFalse); 
   1.524 +	// Let the thread execute
   1.525 +	testThread.Resume();
   1.526 +
   1.527 +	// Wait for termination
   1.528 +	User::WaitForRequest(requestStatus);
   1.529 +	User::SetJustInTime(justInTime); 
   1.530 +
   1.531 +	TEST2(testThread.ExitReason(), 0);
   1.532 +	testThread.Close();
   1.533 +
   1.534 +	}
   1.535 +
   1.536 +static TInt RunTestsL()
   1.537 +	{
   1.538 +	TheTest.Next(_L("Delete old files"));
   1.539 +	SchSvrHelpers::DeleteScheduleFilesL();
   1.540 +	
   1.541 +	//create P&S variables for the test
   1.542 +	CreateTestVariables();
   1.543 +	
   1.544 +	TheTest.Next(_L("Start tests"));
   1.545 +
   1.546 +	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
   1.547 +	CleanupStack::PushL(scheduler);
   1.548 +	CActiveScheduler::Install(scheduler);
   1.549 +	
   1.550 +	DoTest1L();
   1.551 +	DoTest2L();
   1.552 +	DoTest3L();
   1.553 +	DoTest4L();
   1.554 +	DoTest5L();	
   1.555 +	DoTest6L();
   1.556 +	
   1.557 +	TheTest.Next(_L("Tidying up"));
   1.558 +	CleanupStack::PopAndDestroy(scheduler);
   1.559 +
   1.560 +	return KErrNone;
   1.561 +	}
   1.562 +
   1.563 +GLDEF_C TInt E32Main()
   1.564 +    {
   1.565 +	__UHEAP_MARK;
   1.566 +	TheTest.Start(_L("TC_TSCH_ROBUSTNESS"));
   1.567 +	TheTest.Title();
   1.568 +	TheCleanup = CTrapCleanup::New();
   1.569 +
   1.570 +	//If the previous test fails, SCHSVR.exe may stay in memory.
   1.571 +	TRAPD(error,CleanupHelpers::TestCleanupL());
   1.572 +	TEST2(error, KErrNone);
   1.573 +	TheTest(TheFsSession.Connect() == KErrNone);;
   1.574 +	TRAP(error, RunTestsL());
   1.575 +	TEST2(error, KErrNone);	
   1.576 +	TRAP(error,CleanupHelpers::TestCleanupL());
   1.577 +	TEST2(error, KErrNone);
   1.578 +	delete TheCleanup;	
   1.579 +	
   1.580 +	TheFsSession.Close();
   1.581 +	TheTest.End();
   1.582 +	TheTest.Close();
   1.583 +	__UHEAP_MARKEND;
   1.584 +
   1.585 +	return KErrNone;
   1.586 +	}