sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: // TESTFIXES.CPP
sl@0: // 
sl@0: //
sl@0: 
sl@0: #include <e32base.h>
sl@0: #include <e32test.h>
sl@0: #include <csch_cli.h>
sl@0: #include <f32file.h>
sl@0: #include "Thelpers.h"
sl@0: #include "TestUtils.h"
sl@0: 
sl@0: // Globals
sl@0: static RTest			TheTest(_L("TestFixes"));
sl@0: static RScheduler		TheScheduler;
sl@0: static RFs				TheFsSession;
sl@0: 
sl@0: // Type definitions
sl@0: typedef CArrayFixFlat<TScheduleEntryInfo>	CScheduleEntryInfoArray;
sl@0: typedef CArrayFixFlat<TTaskInfo>			CTaskInfoArray;
sl@0: 
sl@0: //***********************************************************************************
sl@0: static TInt RegisterClient(RScheduler& aScheduler)
sl@0: //
sl@0: //	Utility function to simplify registering a client with the task scheduler
sl@0: //
sl@0: 	{
sl@0: 	TFileName filename = _L("Z:\\System\\Bin\\MinimalTaskHandler.exe");
sl@0: 	return aScheduler.Register(filename, 27);
sl@0: 	}
sl@0: 
sl@0: //***********************************************************************************
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID          SYSLIB-SCHSVR-CT-1023
sl@0: @SYMTestCaseDesc	    Tests for defect EDNHLJT-4WDEJV
sl@0: 						A Kern Exec3 panic occurs 30 minutes after scheduling 300 tasks to complete at once.
sl@0: @SYMTestPriority 	    High
sl@0: @SYMTestActions  	    Create the schedule for the task.Create 300 tasks and enable the schedule and wait for 30 seconds.Check if any panic occurs
sl@0: @SYMTestExpectedResults Check if any panic occurs
sl@0: @SYMREQ                 REQ0000
sl@0: */
sl@0: static void Test1L()
sl@0: 	{	
sl@0: 	// Test title
sl@0: 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1023 \nTest for defect EDNHLJT-4WDEJV "));
sl@0: 	// A Kern Exec3 panic occurs after 30ish minutes after scheduling 300 tasks to complete at once.
sl@0: 	
sl@0: 	// Constants / vars used in this function
sl@0: 	TSchedulerItemRef itemRef;
sl@0: 
sl@0: 	TheTest.Next(_L("Connect to Scheduler"));
sl@0: 	TInt res = TheScheduler.Connect();
sl@0: 	TheTest (res==KErrNone);
sl@0: 
sl@0: 	TheTest.Next(_L("Registering Client"));
sl@0: 	TheTest (RegisterClient(TheScheduler) == KErrNone);
sl@0: 	
sl@0: 	// Create some scheduling entries
sl@0: 	CArrayFixFlat<TScheduleEntryInfo>* entries = new(ELeave) CArrayFixFlat<TScheduleEntryInfo>(10);
sl@0: 	CleanupStack::PushL(entries);
sl@0: 
sl@0: 	TScheduleEntryInfo entry1;
sl@0: 	entry1.iIntervalType	= EHourly;
sl@0: 	entry1.iStartTime		= SchSvrHelpers::TimeBasedOnOffset(1);
sl@0: 	entry1.iInterval		= 1;
sl@0: 	entry1.iValidityPeriod	= 20;
sl@0: 	entries->AppendL(entry1);
sl@0: 
sl@0: 	// Create the schedule for the task...
sl@0: 	res = TheScheduler.CreatePersistentSchedule(itemRef, *entries);
sl@0: 	TheTest(res == KErrNone);
sl@0: 
sl@0: 	// Disable the schedule straight away
sl@0: 	res = TheScheduler.DisableSchedule(itemRef.iHandle);
sl@0: 	TheTest(res == KErrNone);
sl@0: 	
sl@0: 	if	(res == KErrNone)
sl@0: 		{
sl@0: 		for(TInt i=0; i<300; i++)
sl@0: 			{
sl@0: 			// Create the tasks themselves..
sl@0: 			TTaskInfo task;
sl@0: 			task.iRepeat	= 1; // repeat once
sl@0: 			task.iName		= _L("Test Task For Defect Verification");
sl@0: 			task.iPriority	= 100;
sl@0: 			//
sl@0: 			HBufC* taskData = HBufC::NewMaxLC(100);
sl@0: 			taskData->Des().Repeat(_L(" "));
sl@0: 			//
sl@0: 			res = TheScheduler.ScheduleTask(task, *taskData, itemRef.iHandle);
sl@0: 			TheTest(res == KErrNone);
sl@0: 
sl@0: 			CleanupStack::PopAndDestroy(taskData);
sl@0: 			}
sl@0: 		}
sl@0: 
sl@0: 	res = TheScheduler.EnableSchedule(itemRef.iHandle);
sl@0: 	TheTest(res == KErrNone);
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy(entries);
sl@0: 
sl@0: 	TheTest.Printf(_L("Waiting for 30 minutes\n"));
sl@0: 	// Wait for thirty minutes to see if a Kern Exec3 panic  occurs 
sl@0: 	User::After(1000000 * 60 * 30); // thirty mins
sl@0: 
sl@0: 	}
sl@0: 
sl@0: //***********************************************************************************
sl@0: 
sl@0: GLDEF_C TInt DoTheTestsL()
sl@0: //
sl@0: //	Kickoff method
sl@0: //
sl@0: 	{
sl@0: 	// Add tests here:-
sl@0: 	Test1L();
sl@0: 
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 
sl@0: //***********************************************************************************
sl@0: GLDEF_C TInt E32Main()
sl@0: //	
sl@0: // Entry point
sl@0: //
sl@0:     {
sl@0: 	__UHEAP_MARK;
sl@0: 	TheTest.Title();
sl@0: 	TheTest.Start(_L("TheTest Task Scheduler Fixes"));
sl@0: 
sl@0: 	TInt error = KErrNone;
sl@0: 	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0: 	if	(!cleanup)
sl@0: 		return KErrNoMemory;
sl@0: 
sl@0: 	TheFsSession.Connect();
sl@0: 	TRAP(error, DoTheTestsL());
sl@0: 	TEST(error == KErrNone);
sl@0: 	TheFsSession.Close();
sl@0: 	TheTest(error == KErrNone);
sl@0: 	delete cleanup;	
sl@0: 
sl@0: 	TheTest.End();
sl@0: 	TheTest.Close();
sl@0: 	__UHEAP_MARKEND;
sl@0: 	return(KErrNone);
sl@0: 	}