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: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "Thelpers.h" sl@0: sl@0: #include "TestUtils.h" sl@0: sl@0: // Globals sl@0: RTest TheTest(_L("TC_TSCH_SCHEDULING1")); sl@0: static RScheduler TheScheduler; sl@0: static RFs TheFsSession; sl@0: sl@0: typedef CArrayFixFlat CScheduleEntryInfoArray; sl@0: typedef CArrayFixFlat CTaskInfoArray; sl@0: typedef CArrayFixFlat CSchItemRefArray; sl@0: sl@0: _LIT(KMinimalTaskHandler, "MinimalTaskHandler"); sl@0: sl@0: _LIT(KTimeFormatString, "%-B%:0%J%:1%T%:2%S%.%*C4%:3%+B"); sl@0: _LIT(KCurrentDateTimeChanged, "Date & Time changed to: [%S]\n"); sl@0: sl@0: const TInt KTimeToWait = 4*1000*1000; sl@0: sl@0: sl@0: //*********************************************************************************** sl@0: sl@0: // Sets time to before specified time by aTimeBeforeInSeconds sl@0: static void SetTimeBeforeL(RTest& aTest, TTime& aTime, TInt aTimeBeforeInSeconds) sl@0: { sl@0: TTimeIntervalSeconds secs(aTimeBeforeInSeconds); sl@0: TTime time = aTime-secs; sl@0: SchSvrHelpers::SetHomeTimeL(time); sl@0: TBuf<30> dateString; sl@0: time.FormatL(dateString, KTimeFormatString); sl@0: aTest.Printf(KCurrentDateTimeChanged, &dateString); sl@0: } sl@0: sl@0: // gets the due time for this schedule sl@0: static TTime GetDueTimeL(TInt aScheduleId) sl@0: { sl@0: TTime nextTimeScheduleIsDue; sl@0: TScheduleState state; sl@0: CScheduleEntryInfoArray* entries sl@0: = new (ELeave) CScheduleEntryInfoArray(3); sl@0: CleanupStack::PushL(entries); sl@0: CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3); sl@0: CleanupStack::PushL(tasks); sl@0: sl@0: TInt res = TheScheduler.GetScheduleL(aScheduleId, state, *entries, *tasks, nextTimeScheduleIsDue); sl@0: TEST2(res, KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(2); // entries, tasks sl@0: return state.iDueTime; sl@0: } sl@0: sl@0: // Forces the task to be exectued aCount times. sl@0: static void ForceTaskExecutionForSpecifiedIdL(TInt aId, TInt aCount) sl@0: { sl@0: TheTest.Printf(_L("Executing %d times\n"), aCount); sl@0: TTime time; sl@0: for (TInt i=0; iAppendL(entry1); sl@0: TInt res = aScheduler.CreatePersistentSchedule(aRef, *entryList); sl@0: CleanupStack::PopAndDestroy(); // entryList sl@0: return res; sl@0: } sl@0: sl@0: // counts the number of scheduled items based on the supplied filter. sl@0: static TInt CountScheduledItemsL(TScheduleFilter aFilter, sl@0: RScheduler& aScheduler) sl@0: // Extract schedule references from the schedule server based on a filter. If sl@0: { sl@0: CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3); sl@0: CleanupStack::PushL(refs); sl@0: sl@0: TInt res = aScheduler.GetScheduleRefsL(*refs, aFilter); sl@0: TEST2(res, KErrNone); sl@0: sl@0: TInt count = refs->Count(); sl@0: CleanupStack::PopAndDestroy(); // refs sl@0: return count; sl@0: } sl@0: sl@0: // Extract task references from the schedule server based on a ID sl@0: static void GetTaskInfoL(CTaskInfoArray& aTaskInfoArray, sl@0: TInt aScheduleId) sl@0: { sl@0: aTaskInfoArray.Reset(); sl@0: TTime nextTimeScheduleIsDue; sl@0: TScheduleState state; sl@0: CScheduleEntryInfoArray* entries sl@0: = new (ELeave) CScheduleEntryInfoArray(3); sl@0: CleanupStack::PushL(entries); sl@0: TInt res = TheScheduler.GetScheduleL(aScheduleId, sl@0: state, sl@0: *entries, sl@0: aTaskInfoArray, sl@0: nextTimeScheduleIsDue); sl@0: TEST2(res, KErrNone); sl@0: CleanupStack::PopAndDestroy(entries); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: // schedules a transient task sl@0: static TInt ScheduleTransientTaskL(TInt& aTaskId, sl@0: TSchedulerItemRef& aRef, sl@0: TInt aRepeat, sl@0: RScheduler& aScheduler) sl@0: { sl@0: CScheduleEntryInfoArray* entryList = new(ELeave) CScheduleEntryInfoArray(3); sl@0: CleanupStack::PushL(entryList); sl@0: sl@0: aRef.iName = _L("transient one"); sl@0: sl@0: // SCEHDULES sl@0: TScheduleEntryInfo entry1; sl@0: entry1.iStartTime = SchSvrHelpers::TimeBasedOnOffset(0, 1); // 1 min in the future sl@0: entry1.iInterval = 1; sl@0: entry1.iIntervalType = EDaily; sl@0: entry1.iValidityPeriod = 20; sl@0: entryList->AppendL(entry1); sl@0: sl@0: TScheduleEntryInfo entry2; sl@0: entry2.iStartTime = SchSvrHelpers::TimeBasedOnOffset(0, 2); // 2 mins in the future sl@0: entry2.iInterval = 1; sl@0: entry2.iIntervalType = EDaily; sl@0: entry2.iValidityPeriod = 500; sl@0: entryList->AppendL(entry2); sl@0: sl@0: TScheduleEntryInfo entry3; sl@0: entry3.iStartTime = SchSvrHelpers::TimeBasedOnOffset(0, 3); // 3 mins in the future sl@0: entry3.iInterval = 1; sl@0: entry3.iIntervalType = EDaily; sl@0: entry3.iValidityPeriod = 5; sl@0: entryList->AppendL(entry3); sl@0: sl@0: // TASK sl@0: TTaskInfo taskInfo; sl@0: taskInfo.iName = _L("mail"); sl@0: taskInfo.iTaskId = aTaskId; sl@0: taskInfo.iRepeat = aRepeat; sl@0: taskInfo.iPriority = 2; sl@0: HBufC* data = _L("the data, some strange new name ").AllocLC(); sl@0: sl@0: // Schedule the item sl@0: TInt res = aScheduler.ScheduleTask(taskInfo, *data, aRef, *entryList); sl@0: CleanupStack::PopAndDestroy(2); // data, entryList sl@0: sl@0: aTaskId = taskInfo.iTaskId; sl@0: return res; sl@0: } sl@0: sl@0: /* sl@0: * Add Persistent and long term schedules to SchedulessBackup.dat files. this function sl@0: * is part of the DEF108026 defect testing called by DEF108026() sl@0: * It is part of the manual test SYSLIB-SCHSVR-CT-4003 sl@0: * should be commented and will run as manual test only. sl@0: * sl@0: * sl@0: sl@0: static void DEF108026_AddPersistentSchedulesL( TBool aImmediate ) sl@0: { sl@0: sl@0: _LIT(KTaskData1, "This is some really exciting task data (number 1)"); sl@0: _LIT(KTaskData2, "This is some really exciting task data (number 2)"); sl@0: _LIT(KTestName, "Def108026_test"); sl@0: sl@0: TheTest.Next(_L("Def108026_test: Adding schedules")); sl@0: sl@0: RDebug::Print(_L("DEF108026_AddPersistentSchedulesL")); sl@0: sl@0: TheTest.Next(_L("Connect to Scheduler")); sl@0: TInt res = TheScheduler.Connect(); sl@0: TEST2(res, KErrNone); sl@0: sl@0: TheTest.Next(_L("Registering Client")); sl@0: TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone); sl@0: sl@0: sl@0: sl@0: TTime startTimeForSchedule; sl@0: if ( aImmediate ) sl@0: { sl@0: // This is the time when we want the schedule to fire sl@0: startTimeForSchedule = TTime( (TDateTime(2007, EJune, 20, 10, 00, 0, 0)) ); sl@0: RDebug::Print( _L("Added immediate schedule")); sl@0: } sl@0: else sl@0: { sl@0: startTimeForSchedule = TTime( (TDateTime(2037, EJune, 20, 10, 00, 0, 0)) ); // These schedules are due in the future. sl@0: RDebug::Print( _L("Added long-term schedule")); sl@0: } sl@0: sl@0: sl@0: // Prepare a schedule describing when we want the tasks to run (10:00 am) sl@0: TSchedulerItemRef ref; sl@0: User::LeaveIfError(CreateScheduleL(ref, TheScheduler, startTimeForSchedule)); sl@0: sl@0: // Disable the schedule whilst we set it up sl@0: User::LeaveIfError(TheScheduler.DisableSchedule(ref.iHandle)); sl@0: sl@0: // Associate a task with the schedule sl@0: TTaskInfo taskInfo1; sl@0: taskInfo1.iRepeat = 0; sl@0: taskInfo1.iName = KTestName; sl@0: taskInfo1.iPriority = 2; sl@0: sl@0: // Create some data associated with this task sl@0: HBufC* taskData1 = KTaskData1().AllocLC(); sl@0: User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref.iHandle)); sl@0: CleanupStack::PopAndDestroy(); // taskData1 sl@0: sl@0: // Associate a task (2) with the schedule sl@0: TTaskInfo taskInfo2; sl@0: taskInfo2.iRepeat = 0; sl@0: taskInfo2.iName = KTestName; sl@0: taskInfo2.iPriority = 2; sl@0: sl@0: // Create some data associated with this task sl@0: HBufC* taskData2 = KTaskData2().AllocLC(); sl@0: User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref.iHandle)); sl@0: CleanupStack::PopAndDestroy(); // taskData2 sl@0: sl@0: // We should now have two tasks scheduled at exactly the same time... sl@0: User::LeaveIfError(TheScheduler.EnableSchedule(ref.iHandle)); sl@0: sl@0: CleanupHelpers::KillProcess(KMinimalTaskHandler); sl@0: } sl@0: sl@0: * sl@0: ** end of DEF108026_AddPersistentSchedulesL() **/ sl@0: sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-1031 sl@0: @SYMTestCaseDesc Test code for defect "Sending SMS to multiple recipients sl@0: sends message to only one recipient" (EDNEMHE-4Q69BG) sl@0: @SYMTestPriority High sl@0: @SYMTestActions Schedule two tasks to run at same time sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: static void Test1L() sl@0: { sl@0: _LIT(KTaskData1, "This is some really exciting task data (number 1)"); sl@0: _LIT(KTaskData2, "This is some really exciting task data (number 2)"); sl@0: _LIT(KTestName, "SmsTest"); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1031 TheTest3: SMS:Sending to multiple recipients")); sl@0: sl@0: TheTest.Next(_L("Connect to Scheduler")); sl@0: TInt res = TheScheduler.Connect(); sl@0: TEST2(res, KErrNone); sl@0: sl@0: TheTest.Next(_L("Registering Client")); sl@0: TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone); sl@0: sl@0: // Set the time to a known value, since this makes testing much easier (and more sl@0: // repeatable). sl@0: SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 55, 0, 0))); // 9:55 am sl@0: sl@0: // This is the time when we want the schedule to fire sl@0: TTime startTimeForSchedule(TDateTime(2000, EJanuary, 1, 10, 0, 0, 0)); // 10:00 am sl@0: sl@0: // Prepare a schedule describing when we want the tasks to run (10:00 am) sl@0: TSchedulerItemRef ref; sl@0: User::LeaveIfError(CreateScheduleL(ref, TheScheduler, startTimeForSchedule)); sl@0: sl@0: // Disable the schedule whilst we set it up sl@0: User::LeaveIfError(TheScheduler.DisableSchedule(ref.iHandle)); sl@0: sl@0: // Associate a task with the schedule sl@0: TTaskInfo taskInfo1; sl@0: taskInfo1.iRepeat = 0; sl@0: taskInfo1.iName = KTestName; sl@0: taskInfo1.iPriority = 2; sl@0: sl@0: // Create some data associated with this task sl@0: HBufC* taskData1 = KTaskData1().AllocLC(); sl@0: User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref.iHandle)); sl@0: CleanupStack::PopAndDestroy(); // taskData1 sl@0: sl@0: // Associate a task (2) with the schedule sl@0: TTaskInfo taskInfo2; sl@0: taskInfo2.iRepeat = 0; sl@0: taskInfo2.iName = KTestName; sl@0: taskInfo2.iPriority = 2; sl@0: sl@0: // Create some data associated with this task sl@0: HBufC* taskData2 = KTaskData2().AllocLC(); sl@0: User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref.iHandle)); sl@0: CleanupStack::PopAndDestroy(); // taskData2 sl@0: sl@0: // We should now have two tasks scheduled at exactly the same time... sl@0: User::LeaveIfError(TheScheduler.EnableSchedule(ref.iHandle)); sl@0: sl@0: // Set the time to 5 minutes *AFTER* the schedule was due to run (10:05am). In this instance, sl@0: // based on the new fixed Schedule Server, the schedule should still execute since sl@0: // it falls within the validity period (30 mins), however, in the old scheme of things, sl@0: // the schedule would not be valid again until tomorrow (2/1/2000) at 10:00am and hence sl@0: // would not execute until then. sl@0: SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 10, 5, 0, 0))); // 10:05 am sl@0: sl@0: // Now wait for something to happen... sl@0: TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone); sl@0: CleanupHelpers::KillProcess(KMinimalTaskHandler); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-1032 sl@0: @SYMTestCaseDesc Tests for creation of transient schedule with task repeating 5 times sl@0: @SYMTestPriority High sl@0: @SYMTestActions There should be no schedules as its a transient one and last schedule sl@0: should have deleted by itself. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: static void Test2L() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1032 Testing creation of transient schedule with task repeating 5 times ")); sl@0: sl@0: TInt tTask = 0; sl@0: TSchedulerItemRef ref; sl@0: // schedule has 3 entries - +1min, +2min and +3min sl@0: TInt res = ScheduleTransientTaskL(tTask, ref, 5, TheScheduler);//5 repeats sl@0: TEST2(res, KErrNone); sl@0: sl@0: TheTest.Printf(_L("Get Task count and repeat count\n")); sl@0: sl@0: CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3); sl@0: CleanupStack::PushL(tasks); sl@0: GetTaskInfoL(*tasks, ref.iHandle); sl@0: TEST(tasks->Count() == 1); sl@0: TTaskInfo info = tasks->At(0); sl@0: TEST(info.iRepeat == 5); sl@0: ForceTaskExecutionForSpecifiedIdL(ref.iHandle, 3); sl@0: GetTaskInfoL(*tasks, ref.iHandle); sl@0: TEST(tasks->Count() == 1); sl@0: info = tasks->At(0); sl@0: TEST(info.iRepeat == 2); // still 2 repeats to go. sl@0: ForceTaskExecutionForSpecifiedIdL(ref.iHandle, 2); sl@0: sl@0: CleanupStack::PopAndDestroy(tasks); sl@0: sl@0: TInt scheduleCount = CountScheduledItemsL(EPendingSchedules, TheScheduler); sl@0: // There should be no schedules as its a transient one and last schedule sl@0: // should have deleted itself. sl@0: TEST(scheduleCount == 0); sl@0: SchSvrHelpers::Pause(TheTest); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-1341 sl@0: @SYMTestCaseDesc Tests for defect number DEF055586L sl@0: @SYMTestPriority High sl@0: @SYMTestActions Check to ensure that last element in schedule entries sl@0: array not skipped by schedule checking functions sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: static void DEF055586L() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1041 DEF055586 - Last element in array missed by loop")); sl@0: sl@0: TheTest.Next(_L("Connect to Scheduler")); sl@0: TInt res = TheScheduler.Connect(); sl@0: TEST2(res, KErrNone); sl@0: sl@0: TheTest.Next(_L("Registering Client")); sl@0: TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone); sl@0: sl@0: // Set the time to a known value, since this makes testing much easier (and more sl@0: // repeatable). sl@0: SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 55, 0, 0))); // 9:55 am sl@0: sl@0: // This is the time when we want the schedule to fire sl@0: TTime startTimeForSchedule(TDateTime(2000, EJanuary, 1, 10, 0, 0, 0)); // 10:00 am sl@0: sl@0: // Prepare a schedule describing when we want the tasks to run (10:00 am) sl@0: TSchedulerItemRef ref; sl@0: sl@0: CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1); sl@0: CleanupStack::PushL(entryList); sl@0: sl@0: TScheduleEntryInfo entry1; sl@0: entry1.iStartTime = startTimeForSchedule; sl@0: entry1.iInterval = 0; // TTimeIntervalDays: set to 0 to induce an error sl@0: entry1.iIntervalType = EDaily; sl@0: entry1.iValidityPeriod = 30; // minutes sl@0: entryList->AppendL(entry1); sl@0: TInt err = TheScheduler.CreatePersistentSchedule(ref, *entryList); sl@0: sl@0: TEST2(err, KErrArgument); sl@0: sl@0: TheTest.Next(_L("DEF055586 - Now checking 0 entries in schedule")); sl@0: entryList->Reset(); sl@0: sl@0: err = TheScheduler.CreatePersistentSchedule(ref, *entryList); sl@0: sl@0: TEST2(err, KErrArgument); sl@0: sl@0: CleanupStack::PopAndDestroy(); // entryList sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-3159 sl@0: @SYMTestCaseDesc Tests for defect number DEF094149 sl@0: @SYMTestPriority Normal sl@0: @SYMTestActions Create one Schedule and two task in it, then delete one task sl@0: check whether Task Scheduler execute disabled Schedule sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void DEF094149L() sl@0: { sl@0: // Create scheduling entries sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3159 DEF094149: RF Task Scheduler execute deleted tasks (in stress conditions) ")); sl@0: TTime time; sl@0: time.HomeTime(); sl@0: time += TTimeIntervalSeconds(2); // Scheduler will run task in 2 seconds sl@0: sl@0: TScheduleEntryInfo entry; sl@0: entry.iIntervalType = EHourly; sl@0: entry.iStartTime = time; sl@0: entry.iInterval = 1; sl@0: entry.iValidityPeriod = 20; sl@0: sl@0: CArrayFixFlat* entries = new(ELeave) CArrayFixFlat(10); sl@0: CleanupStack::PushL(entries); sl@0: sl@0: entries->AppendL(entry); sl@0: TSchedulerItemRef ref; sl@0: // Create the schedule for the task... and disable it sl@0: TheScheduler.Connect(); sl@0: TheScheduler.CreatePersistentSchedule(ref, *entries); sl@0: TheScheduler.DisableSchedule(ref.iHandle); sl@0: sl@0: // CreateNewTask 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: sl@0: TBuf<255>fileName = _L("Some task"); sl@0: TheScheduler.Register( fileName, 1 ); sl@0: HBufC* taskData = HBufC::NewLC(1); sl@0: sl@0: //first task sl@0: TheScheduler.ScheduleTask(task, *taskData,ref.iHandle); sl@0: TInt taskid1; sl@0: taskid1 = task.iTaskId; sl@0: sl@0: //Second task sl@0: TheScheduler.ScheduleTask(task, *taskData,ref.iHandle); sl@0: TInt taskid2; sl@0: taskid2 = task.iTaskId; sl@0: sl@0: TInt err = TheScheduler.DeleteTask(taskid1); sl@0: sl@0: User::After(KTimeToWait); sl@0: err = TheScheduler.DeleteTask(taskid2); sl@0: sl@0: //check whether Task Scheduler execute the second task after deleting first tasks sl@0: //If the Schedule executed then err == KErrNotFound sl@0: TEST2(err, KErrNone); sl@0: CleanupStack::PopAndDestroy(taskData); sl@0: CleanupStack::PopAndDestroy(entries); sl@0: sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-3358 sl@0: @SYMTestCaseDesc Tests for defect number INC098909 sl@0: @SYMTestPriority High sl@0: @SYMTestActions Mark heap of Scheduler then create a schedule & task wait for its sl@0: execution then check heap again for memory leaks sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF INC098909: Process !TaskScheluder leaks memory in mail polls. sl@0: */ sl@0: static void INC098909() sl@0: { sl@0: const TInt KTimeToWait = 5*1000*1000; sl@0: //SchSvrHelpers::DeleteScheduleFilesL(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3358 INC098909: Process !TaskScheluder leaks memory in mail polls ")); sl@0: TheTest.Next(_L("Connect to Scheduler")); sl@0: TEST2(TheScheduler.Connect(),KErrNone); sl@0: sl@0: TheTest.Next(_L("Registering Client")); sl@0: TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone); sl@0: sl@0: User::LeaveIfError(TheScheduler.__DbgMarkHeap()); sl@0: sl@0: //Create Schedule sl@0: CArrayFixFlat* entryList = new(ELeave) CArrayFixFlat(1); sl@0: CleanupStack::PushL(entryList); sl@0: TSchedulerItemRef ref; sl@0: sl@0: TTime time; sl@0: time.HomeTime(); sl@0: time += TTimeIntervalSeconds(0); // Scheduler will run task in 5 sec sl@0: sl@0: TScheduleEntryInfo entry1; sl@0: entry1.iIntervalType = EHourly; sl@0: entry1.iStartTime = time; sl@0: entry1.iInterval = 1; sl@0: entry1.iValidityPeriod = 20; sl@0: entryList->AppendL(entry1); sl@0: sl@0: // Create the schedule for the task... sl@0: TEST2(TheScheduler.CreatePersistentSchedule(ref, *entryList),KErrNone); sl@0: sl@0: //Create Task sl@0: TTaskInfo task; sl@0: task.iRepeat = 1; // repeat once sl@0: task.iName = _L("Test "); sl@0: task.iPriority = 100; sl@0: sl@0: HBufC* taskData = HBufC::NewLC(1); sl@0: TEST2(TheScheduler.ScheduleTask(task, *taskData,ref.iHandle), KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(taskData); sl@0: CleanupStack::PopAndDestroy(entryList); sl@0: sl@0: //Wait schedule to complete sl@0: User::After(KTimeToWait); sl@0: sl@0: User::LeaveIfError(TheScheduler.__DbgMarkEnd(0)); sl@0: sl@0: SchSvrHelpers::DeleteAllSchedulesL(TheScheduler); sl@0: sl@0: // really clean out the scheduler (get rid of all the files and process) sl@0: TheScheduler.Close(); sl@0: SchSvrHelpers::DeleteScheduleFilesL(); sl@0: CleanupHelpers::KillProcess(KMinimalTaskHandler); sl@0: // Now wait for something to happen... sl@0: TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone); sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-4003 sl@0: @SYMTestCaseDesc Test for DEF108026: sl@0: The aim of this test is to create enough persistent schedules. This reproduce the defect, when sl@0: SysStart startup. task scheduler will see that these schedules are due. It will then add them sl@0: immediately to the timer during SSA phase. As this operation consumes a long time and CSchStartupStateMgr::RunL() sl@0: is blocking, the domain manager fails to be ackowleged about the state transition, therefore certain processes like sl@0: Esock workers does not complete. These schedules are due immediately (at the time we run this test), we need then to sl@0: set the time of the device at the time where the schedules are due. We set the home time of the device in CSchServer::ConstructL(). sl@0: I add in comment the modified CSchServer::ConstructL(). sl@0: ssch_svr.dll must be rebuilt. sl@0: I could reproduces this defect only on Uiq. I could not reproduce it on techview! sl@0: @SYMTestPriority Normal sl@0: @SYMTestActions Create persistent and long-term schedules. sl@0: @SYMTestExpectedResults Test must create a sl@0: @SYMDEF DEF108026:SCHSVR performs SSA-driven actions before acknowledging transition. sl@0: */ sl@0: /*********************** constructL() modified.Needed to explain the manual test DEF108026() ******************************** sl@0: ** sl@0: ** sl@0: void CSchServer::ConstructL() sl@0: { sl@0: #ifdef __SCHLOGGING__ sl@0: iTheLog = CSheduleServerLog::NewL(_L("SchSvr")); sl@0: Dll::SetTls(iTheLog); sl@0: #endif sl@0: sl@0: // Create server storage path sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: sl@0: #ifdef __SECURE_DATA__ sl@0: TInt err = fs.CreatePrivatePath(EDriveC); sl@0: #else sl@0: _LIT(KDirPath, "C:\\System\\Schedules\\"); sl@0: TInt err = fs.MkDirAll(KDirPath); sl@0: #endif sl@0: sl@0: if(err != KErrNone && err != KErrAlreadyExists) sl@0: User::Leave(err); sl@0: sl@0: fs.Close(); sl@0: sl@0: sl@0: sl@0: sl@0: // The process that we need to add to set the time of the device. sl@0: // We need to set it to the same time that the schedules added are due. sl@0: TTime newTime ( (TDateTime(2007, EJune, 20, 10, 00, 00, 00)) ); // 10:00 am sl@0: { sl@0: sl@0: _LIT(KSetHomeTime, "TSetHomeTime"); sl@0: _LIT(KTimeFormat, "%F%Y%M%D:%H%T%S.%*C6"); sl@0: sl@0: RProcess p; sl@0: TRequestStatus stat; sl@0: TBuf<128> bufLocalTime; sl@0: sl@0: newTime.FormatL(bufLocalTime, KTimeFormat); sl@0: sl@0: User::LeaveIfError(p.Create(KSetHomeTime, bufLocalTime)); sl@0: sl@0: // Asynchronous logon: completes when process terminates with process exit code sl@0: p.Logon(stat); sl@0: p.Resume(); sl@0: sl@0: User::WaitForRequest(stat); sl@0: TInt exitReason = p.ExitReason(); sl@0: p.Close(); sl@0: //return (exitReason); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: iTaskScheduler = CTaskScheduler::NewL(); sl@0: sl@0: iSSAMgr = new(ELeave) CSchStartupStateMgr(KDmHierarchyIdStartup, KBaseServicesDomain3); sl@0: iSSAMgr->RegisterObserverL(iTaskScheduler); sl@0: iSSAMgr->InitialiseL(); sl@0: sl@0: StartL(KSchSvrName); sl@0: } sl@0: ** sl@0: ** end of the changes we need to do in ssch_svr.cpp **/ sl@0: sl@0: /* sl@0: * This should be called by DoTheTestsL () . It is part of the manual test SYSLIB-SCHSVR-CT-4003 sl@0: * should be commented and will run as manual test only. sl@0: * sl@0: * sl@0: static void DEF108026() sl@0: { sl@0: TheTest.Next(_L("DEF108026: Creating enough persistent and long-term schedules to make task scheduler slower while adding them to the timer")); sl@0: sl@0: for ( TInt i = 0; i < 500; i++ ) sl@0: { sl@0: DEF108026_AddPersistentSchedulesL( ETrue ); sl@0: HBufC* debugTxt = HBufC::NewLC( 256 ); sl@0: debugTxt->Des().Append( _L( "Added Test... " ) ); sl@0: debugTxt->Des().AppendNum( i++ ); sl@0: RDebug::Print( *debugTxt ); sl@0: CleanupStack::PopAndDestroy( debugTxt ); sl@0: } sl@0: sl@0: sl@0: for ( TInt i = 0; i < 1000; i++ ) sl@0: { sl@0: DEF108026_AddPersistentSchedulesL( EFalse ); sl@0: HBufC* debugTxt = HBufC::NewLC( 256 ); sl@0: debugTxt->Des().Append( _L( "Added Test... " ) ); sl@0: debugTxt->Des().AppendNum( i++ ); sl@0: RDebug::Print( *debugTxt ); sl@0: CleanupStack::PopAndDestroy( debugTxt ); sl@0: } sl@0: sl@0: } sl@0: ** end of DEF108026 () **/ sl@0: sl@0: GLDEF_C TInt DoTheTestsL() sl@0: { sl@0: sl@0: //Delete old files. sl@0: SchSvrHelpers::DeleteScheduleFilesL(); sl@0: sl@0: STaskSemaphore sem; sl@0: sem.CreateL(); sl@0: sl@0: TheTest.Next(_L("Start tests")); sl@0: // Add tests here:- sl@0: sl@0: //DEF108026(); //This is a manual test. This test runs only under certain condition, sl@0: //Read the condition required to run this test in the implementation of the DEF108026() comments. sl@0: sl@0: INC098909(); // Should be commented while running def108026 sl@0: DEF094149L(); // Should be commented while running def108026 sl@0: Test1L(); //Should be commented while running def108026 sl@0: Test2L(); //Should be commented while running def108026 sl@0: DEF055586L(); //Should be commented while running def108026 sl@0: sl@0: sem.Close(); sl@0: sl@0: //Tidying up so next test will be clear. sl@0: TheTest.Next(_L("Delete all schedules")); sl@0: SchSvrHelpers::DeleteAllSchedulesL(TheScheduler); // While running def108026() manual test, this should be commented. We sl@0: // want keep the persistent schedules. sl@0: SchSvrHelpers::Pause(TheTest, 2); sl@0: TheTest.Next(_L("Delete old files\n")); sl@0: SchSvrHelpers::DeleteScheduleFilesL(); // While running def108026() manual test, this should be commented. We sl@0: // want keep the persistent schedules. sl@0: TheScheduler.Close(); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: //*********************************************************************************** sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: __UHEAP_MARK; sl@0: TheTest.Title(); sl@0: TheTest.Start(_L("TC_TSCH_SCHEDULING1")); sl@0: sl@0: TInt error = KErrNone; sl@0: CTrapCleanup* cleanup = CTrapCleanup::New(); sl@0: if (!cleanup) sl@0: return KErrNoMemory; sl@0: //If the previous test fails, SCHSVR.exe may stay in memory. sl@0: TRAP(error,CleanupHelpers::TestCleanupL()); sl@0: TEST2(error, KErrNone); sl@0: sl@0: TEST2(TheFsSession.Connect(), KErrNone); sl@0: TheTest.Next(_L("Do the tests")); sl@0: TRAP(error, DoTheTestsL()); sl@0: TEST2(error,KErrNone); // While running DEF108026 this line should be commented. If not, error = -4 (no memory) and this leaves. sl@0: //The reason is that our generated schedules take a lot of space. But this is the aim of this manual test: sl@0: // The SchedulesBackup.dat must be bigger as possible to reproduce the defect sl@0: TheFsSession.Close(); sl@0: TRAP(error,CleanupHelpers::TestCleanupL()); sl@0: TEST2(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: }