sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <csch_cli.h>
|
sl@0
|
17 |
#include "Thelpers.h"
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <e32base.h>
|
sl@0
|
20 |
#include <e32test.h>
|
sl@0
|
21 |
#include <f32file.h>
|
sl@0
|
22 |
#include <s32file.h>
|
sl@0
|
23 |
#include <e32property.h>
|
sl@0
|
24 |
#include <schinfointernal.h>
|
sl@0
|
25 |
#include "TestUtils.h"
|
sl@0
|
26 |
|
sl@0
|
27 |
_LIT(KTestName, "Task Scheduler Robustness Test");
|
sl@0
|
28 |
_LIT(KTaskScheduler, "schexe");
|
sl@0
|
29 |
|
sl@0
|
30 |
RTest TheTest(KTestName);
|
sl@0
|
31 |
|
sl@0
|
32 |
typedef CArrayFixFlat<TTaskInfo> CTaskInfoArray;
|
sl@0
|
33 |
typedef CArrayFixFlat<TSchedulerItemRef> CSchItemRefArray;
|
sl@0
|
34 |
typedef CArrayFixFlat<TTaskSchedulerCondition> CSchConditionArray;
|
sl@0
|
35 |
|
sl@0
|
36 |
static RScheduler TheScheduler;
|
sl@0
|
37 |
static CTrapCleanup* TheCleanup;
|
sl@0
|
38 |
static RFs TheFsSession;
|
sl@0
|
39 |
|
sl@0
|
40 |
const TInt KTestKey1 = 1;
|
sl@0
|
41 |
|
sl@0
|
42 |
_LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames
|
sl@0
|
43 |
|
sl@0
|
44 |
// This function launches the TPropertyDefine process which
|
sl@0
|
45 |
// has WriteDeviceData Capabilities enabling it to create the P&S
|
sl@0
|
46 |
// variables used by this test.
|
sl@0
|
47 |
static void LaunchHelperL(TUid aCategory, TInt aKey, TInt aAttr)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
_LIT(KConditionHelper, "TPropertyDefine");
|
sl@0
|
50 |
TRequestStatus stat;
|
sl@0
|
51 |
RProcess p;
|
sl@0
|
52 |
|
sl@0
|
53 |
TBuf<32> args;
|
sl@0
|
54 |
args.AppendNum(aCategory.iUid);
|
sl@0
|
55 |
args.Append(KSeparator);
|
sl@0
|
56 |
args.AppendNum(aKey);
|
sl@0
|
57 |
args.Append(KSeparator);
|
sl@0
|
58 |
args.AppendNum(aAttr);
|
sl@0
|
59 |
|
sl@0
|
60 |
User::LeaveIfError(p.Create(KConditionHelper, args,EOwnerProcess));
|
sl@0
|
61 |
|
sl@0
|
62 |
// Asynchronous logon: completes when process terminates with process exit code
|
sl@0
|
63 |
p.Logon(stat);
|
sl@0
|
64 |
p.Resume();
|
sl@0
|
65 |
|
sl@0
|
66 |
User::WaitForRequest(stat);
|
sl@0
|
67 |
TInt exitReason = p.ExitReason();
|
sl@0
|
68 |
p.Close();
|
sl@0
|
69 |
User::LeaveIfError(exitReason);
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
|
sl@0
|
73 |
static void CreateTestVariables()
|
sl@0
|
74 |
{
|
sl@0
|
75 |
LaunchHelperL(KUidSystemCategory, KTestKey1,RProperty::EInt);
|
sl@0
|
76 |
}
|
sl@0
|
77 |
|
sl@0
|
78 |
static void ResetVariablesL(TInt aKey1Val)
|
sl@0
|
79 |
{
|
sl@0
|
80 |
User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey1,aKey1Val));
|
sl@0
|
81 |
}
|
sl@0
|
82 |
|
sl@0
|
83 |
|
sl@0
|
84 |
// single condition with default time set to 1 year in the future
|
sl@0
|
85 |
static TInt CreateScheduleL(TSchedulerItemRef& aRef,
|
sl@0
|
86 |
RScheduler& aScheduler,
|
sl@0
|
87 |
const TUid& aConditionUID,
|
sl@0
|
88 |
TUint aConditionUInt)
|
sl@0
|
89 |
{
|
sl@0
|
90 |
aRef.iName = _L("Schedule created using CreateScheduleSingle");
|
sl@0
|
91 |
|
sl@0
|
92 |
CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(1);
|
sl@0
|
93 |
CleanupStack::PushL(conditionList);
|
sl@0
|
94 |
|
sl@0
|
95 |
//create a single condition
|
sl@0
|
96 |
TTaskSchedulerCondition condition1;
|
sl@0
|
97 |
condition1.iCategory = aConditionUID;
|
sl@0
|
98 |
condition1.iKey = aConditionUInt;
|
sl@0
|
99 |
condition1.iState = 10;
|
sl@0
|
100 |
condition1.iType = TTaskSchedulerCondition::EEquals;
|
sl@0
|
101 |
|
sl@0
|
102 |
conditionList->AppendL(condition1);
|
sl@0
|
103 |
|
sl@0
|
104 |
//create a persistent schedule
|
sl@0
|
105 |
TTime time = SchSvrHelpers::TimeBasedOnOffset(0, 0, 0, 0, 0, 1); //1 year in the future
|
sl@0
|
106 |
TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
|
sl@0
|
107 |
CleanupStack::PopAndDestroy(); // conditionList
|
sl@0
|
108 |
return res;
|
sl@0
|
109 |
}
|
sl@0
|
110 |
|
sl@0
|
111 |
//Add a single task to a schedule
|
sl@0
|
112 |
static TInt AddTaskToScheduleL(const TDesC& aName,
|
sl@0
|
113 |
TInt& aNewId,
|
sl@0
|
114 |
TInt aScheduleId,
|
sl@0
|
115 |
RScheduler& aScheduler)
|
sl@0
|
116 |
{
|
sl@0
|
117 |
TTaskInfo taskInfo;
|
sl@0
|
118 |
taskInfo.iTaskId = aNewId;
|
sl@0
|
119 |
taskInfo.iName = aName;
|
sl@0
|
120 |
taskInfo.iPriority = 2;
|
sl@0
|
121 |
taskInfo.iRepeat = 0;
|
sl@0
|
122 |
HBufC* data = _L("the data").AllocLC();
|
sl@0
|
123 |
TInt res = aScheduler.ScheduleTask(taskInfo, *data, aScheduleId);
|
sl@0
|
124 |
aNewId = taskInfo.iTaskId;
|
sl@0
|
125 |
|
sl@0
|
126 |
CleanupStack::PopAndDestroy(); // data
|
sl@0
|
127 |
return res;
|
sl@0
|
128 |
}
|
sl@0
|
129 |
|
sl@0
|
130 |
|
sl@0
|
131 |
static TInt ScheduleTaskL()
|
sl@0
|
132 |
{
|
sl@0
|
133 |
//reset the p&s variables before creating the schedule
|
sl@0
|
134 |
ResetVariablesL(0);
|
sl@0
|
135 |
|
sl@0
|
136 |
//Create a schedule
|
sl@0
|
137 |
TSchedulerItemRef ref1;
|
sl@0
|
138 |
TheTest.Printf(_L("Create a schedule\n"));
|
sl@0
|
139 |
TInt res = CreateScheduleL(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
|
sl@0
|
140 |
TEST2(res, KErrNone);
|
sl@0
|
141 |
|
sl@0
|
142 |
//Add task to the schedule
|
sl@0
|
143 |
TInt task1 = 0;
|
sl@0
|
144 |
_LIT(KName1, "Test Task");
|
sl@0
|
145 |
TheTest.Printf(_L("Schedule a task\n"));
|
sl@0
|
146 |
|
sl@0
|
147 |
res = AddTaskToScheduleL(KName1, task1, ref1.iHandle, TheScheduler);
|
sl@0
|
148 |
TEST2(res, KErrNone);
|
sl@0
|
149 |
|
sl@0
|
150 |
return res;
|
sl@0
|
151 |
}
|
sl@0
|
152 |
|
sl@0
|
153 |
static void ExecuteTaskL()
|
sl@0
|
154 |
{
|
sl@0
|
155 |
TheTest.Printf(_L("Execute Task\n"));
|
sl@0
|
156 |
//Set property causing schedule to be run
|
sl@0
|
157 |
User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey1,10));
|
sl@0
|
158 |
|
sl@0
|
159 |
//Pause to wait for the task to be executed
|
sl@0
|
160 |
SchSvrHelpers::Pause(TheTest, 2);
|
sl@0
|
161 |
|
sl@0
|
162 |
}
|
sl@0
|
163 |
|
sl@0
|
164 |
static TInt ScheduleAndExecuteTaskL()
|
sl@0
|
165 |
{
|
sl@0
|
166 |
TInt res = ScheduleTaskL();
|
sl@0
|
167 |
|
sl@0
|
168 |
ExecuteTaskL();
|
sl@0
|
169 |
|
sl@0
|
170 |
return res;
|
sl@0
|
171 |
}
|
sl@0
|
172 |
|
sl@0
|
173 |
LOCAL_C void AddTaskFunctionL()
|
sl@0
|
174 |
{
|
sl@0
|
175 |
RScheduler localScheduler;
|
sl@0
|
176 |
// Connect to the server
|
sl@0
|
177 |
TInt res = localScheduler.Connect();
|
sl@0
|
178 |
TEST2(res, KErrNone);
|
sl@0
|
179 |
//Schedule a task and execute it
|
sl@0
|
180 |
//reset the p&s variables before creating the schedule
|
sl@0
|
181 |
ResetVariablesL(0);
|
sl@0
|
182 |
|
sl@0
|
183 |
//Create a schedule
|
sl@0
|
184 |
TSchedulerItemRef ref1;
|
sl@0
|
185 |
ref1.iName = _L("Schedule created using CreateScheduleSingle");
|
sl@0
|
186 |
CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(1);
|
sl@0
|
187 |
CleanupStack::PushL(conditionList);
|
sl@0
|
188 |
|
sl@0
|
189 |
//create a single condition
|
sl@0
|
190 |
TTaskSchedulerCondition condition1;
|
sl@0
|
191 |
condition1.iCategory = KUidSystemCategory;
|
sl@0
|
192 |
condition1.iKey = KTestKey1;
|
sl@0
|
193 |
condition1.iState = 10;
|
sl@0
|
194 |
condition1.iType = TTaskSchedulerCondition::EEquals;
|
sl@0
|
195 |
|
sl@0
|
196 |
conditionList->AppendL(condition1);
|
sl@0
|
197 |
|
sl@0
|
198 |
//create a persistent schedule
|
sl@0
|
199 |
TTime time = SchSvrHelpers::TimeBasedOnOffset(0, 0, 0, 0, 0, 1); //1 year in the future
|
sl@0
|
200 |
res = localScheduler.CreatePersistentSchedule(ref1, *conditionList, time);
|
sl@0
|
201 |
CleanupStack::PopAndDestroy(); // conditionList
|
sl@0
|
202 |
|
sl@0
|
203 |
//Add task to the schedule
|
sl@0
|
204 |
TInt task1 = 0;
|
sl@0
|
205 |
_LIT(KName1, "Test Task");
|
sl@0
|
206 |
|
sl@0
|
207 |
TTaskInfo taskInfo;
|
sl@0
|
208 |
taskInfo.iTaskId = task1;
|
sl@0
|
209 |
taskInfo.iName = KName1;
|
sl@0
|
210 |
taskInfo.iPriority = 2;
|
sl@0
|
211 |
taskInfo.iRepeat = 0;
|
sl@0
|
212 |
HBufC* data = _L("the data").AllocLC();
|
sl@0
|
213 |
|
sl@0
|
214 |
TInt ret = localScheduler.ScheduleTask(taskInfo, *data, ref1.iHandle);
|
sl@0
|
215 |
TEST2(ret, 0);//EPanicNotRegistered == 0
|
sl@0
|
216 |
|
sl@0
|
217 |
task1 = taskInfo.iTaskId;
|
sl@0
|
218 |
|
sl@0
|
219 |
CleanupStack::PopAndDestroy(); // data
|
sl@0
|
220 |
|
sl@0
|
221 |
//Tidying up so next test will be clear.
|
sl@0
|
222 |
SchSvrHelpers::DeleteAllSchedulesL(localScheduler);
|
sl@0
|
223 |
|
sl@0
|
224 |
localScheduler.Close();
|
sl@0
|
225 |
}
|
sl@0
|
226 |
|
sl@0
|
227 |
// Helper function for DEF124488
|
sl@0
|
228 |
LOCAL_C TInt TestPanicThread(TAny*)
|
sl@0
|
229 |
{
|
sl@0
|
230 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
sl@0
|
231 |
if(!cleanup)
|
sl@0
|
232 |
return KErrNoMemory;
|
sl@0
|
233 |
|
sl@0
|
234 |
|
sl@0
|
235 |
TRAPD(err,AddTaskFunctionL())
|
sl@0
|
236 |
TEST2(err,KErrNone);
|
sl@0
|
237 |
|
sl@0
|
238 |
delete cleanup;
|
sl@0
|
239 |
return KErrNone;
|
sl@0
|
240 |
}
|
sl@0
|
241 |
|
sl@0
|
242 |
/**
|
sl@0
|
243 |
@SYMTestCaseID SYSLIB-SCHSVR-CT-3369
|
sl@0
|
244 |
@SYMTestCaseDesc Test deletion of temporary files with non existent client
|
sl@0
|
245 |
@SYMTestPriority High
|
sl@0
|
246 |
@SYMTestActions Schedule a task with a client that does not exist.
|
sl@0
|
247 |
Ensure that all temporary files are deleted after
|
sl@0
|
248 |
schedule excecutes
|
sl@0
|
249 |
@SYMTestExpectedResults All temporary files should be deleted by task scheduler
|
sl@0
|
250 |
@SYMDEF PDEF101876
|
sl@0
|
251 |
*/
|
sl@0
|
252 |
static void DoTest1L()
|
sl@0
|
253 |
{
|
sl@0
|
254 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3369 Test handling of non existent client "));
|
sl@0
|
255 |
// Connect to the server
|
sl@0
|
256 |
TheTest.Next(_L("===== Connect to Scheduler ====="));
|
sl@0
|
257 |
TInt res = TheScheduler.Connect();
|
sl@0
|
258 |
TEST2(res, KErrNone);
|
sl@0
|
259 |
|
sl@0
|
260 |
// Register a client with the server - this client does not exist
|
sl@0
|
261 |
TheTest.Next(_L("===== Registering Client ====="));
|
sl@0
|
262 |
res = SchSvrHelpers::RegisterNonExistentClient(TheScheduler);
|
sl@0
|
263 |
TEST2(res, KErrNone);
|
sl@0
|
264 |
|
sl@0
|
265 |
//Schedule a task and execute it
|
sl@0
|
266 |
ScheduleAndExecuteTaskL();
|
sl@0
|
267 |
|
sl@0
|
268 |
// Check for left task files after scheduled tasks completed
|
sl@0
|
269 |
// To access private data cage, uses SchSvrHelplers::CheckTaskFilesL()
|
sl@0
|
270 |
TheTest.Next(_L("Now checking no files left when tasks completed"));
|
sl@0
|
271 |
TInt err = SchSvrHelpers::CheckTaskFilesL();
|
sl@0
|
272 |
|
sl@0
|
273 |
// If there's any task files left, test fails with error code KErrGeneral
|
sl@0
|
274 |
TEST(err == KErrNone);
|
sl@0
|
275 |
TheTest.Next(_L("All files deleted as expected..."));
|
sl@0
|
276 |
|
sl@0
|
277 |
//Tidying up so next test will be clear.
|
sl@0
|
278 |
TheTest.Next(_L("Delete all schedules"));
|
sl@0
|
279 |
SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
|
sl@0
|
280 |
|
sl@0
|
281 |
TheScheduler.Close();
|
sl@0
|
282 |
|
sl@0
|
283 |
}
|
sl@0
|
284 |
|
sl@0
|
285 |
/**
|
sl@0
|
286 |
@SYMTestCaseID SYSLIB-SCHSVR-CT-3370
|
sl@0
|
287 |
@SYMTestCaseDesc Test deletion of temporary files with faulty client
|
sl@0
|
288 |
@SYMTestPriority High
|
sl@0
|
289 |
@SYMTestActions Schedule a task with a client that panics and does not
|
sl@0
|
290 |
release the temporary file handle.
|
sl@0
|
291 |
Ensure that all temporary files are deleted after schedule excecutes
|
sl@0
|
292 |
@SYMTestExpectedResults All temporary files should be deleted by task scheduler
|
sl@0
|
293 |
@SYMDEF PDEF101876
|
sl@0
|
294 |
*/
|
sl@0
|
295 |
static void DoTest2L()
|
sl@0
|
296 |
{
|
sl@0
|
297 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3370 Test handling of panicing client "));
|
sl@0
|
298 |
|
sl@0
|
299 |
// Connect to the server
|
sl@0
|
300 |
TheTest.Next(_L("===== Connect to Scheduler ====="));
|
sl@0
|
301 |
TInt res = TheScheduler.Connect();
|
sl@0
|
302 |
TEST2(res, KErrNone);
|
sl@0
|
303 |
|
sl@0
|
304 |
// Register a client with the server - this client panics
|
sl@0
|
305 |
//after calling RFile::AdoptFromClient
|
sl@0
|
306 |
TheTest.Next(_L("===== Registering Client ====="));
|
sl@0
|
307 |
res = SchSvrHelpers::RegisterPanicingClient(TheScheduler);
|
sl@0
|
308 |
TEST2(res, KErrNone);
|
sl@0
|
309 |
|
sl@0
|
310 |
//Schedule a task and execute it - we expect the client to panic
|
sl@0
|
311 |
ScheduleAndExecuteTaskL();
|
sl@0
|
312 |
|
sl@0
|
313 |
// Check for left task files after scheduled tasks completed
|
sl@0
|
314 |
// To access private data cage, uses SchSvrHelplers::CheckTaskFilesL()
|
sl@0
|
315 |
TheTest.Next(_L("Now checking no files left when tasks completed"));
|
sl@0
|
316 |
TInt err = SchSvrHelpers::CheckTaskFilesL();
|
sl@0
|
317 |
|
sl@0
|
318 |
// If there's any task files left, test fails with error code KErrGeneral
|
sl@0
|
319 |
TEST(err == KErrNone);
|
sl@0
|
320 |
|
sl@0
|
321 |
TheTest.Next(_L("All files deleted as expected..."));
|
sl@0
|
322 |
|
sl@0
|
323 |
//Tidying up so next test will be clear.
|
sl@0
|
324 |
TheTest.Next(_L("Delete all schedules"));
|
sl@0
|
325 |
SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
|
sl@0
|
326 |
|
sl@0
|
327 |
TheScheduler.Close();
|
sl@0
|
328 |
}
|
sl@0
|
329 |
|
sl@0
|
330 |
/**
|
sl@0
|
331 |
@SYMTestCaseID SYSLIB-SCHSVR-CT-3371
|
sl@0
|
332 |
@SYMTestCaseDesc Test deletion of temporary files on task scheduler startup
|
sl@0
|
333 |
@SYMTestPriority High
|
sl@0
|
334 |
@SYMTestActions Create temporary files in the task schedulers private data cage.
|
sl@0
|
335 |
Start the task scheduler and verify that these files are deleted.
|
sl@0
|
336 |
@SYMTestExpectedResults All temporary files should be deleted by task scheduler on startup
|
sl@0
|
337 |
@SYMDEF PDEF101876
|
sl@0
|
338 |
*/
|
sl@0
|
339 |
static void DoTest3L()
|
sl@0
|
340 |
{
|
sl@0
|
341 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3371 Test deletion of temporary files on startup "));
|
sl@0
|
342 |
|
sl@0
|
343 |
//Connect to the scheduler
|
sl@0
|
344 |
TInt res = TheScheduler.Connect();
|
sl@0
|
345 |
TEST2(res, KErrNone);
|
sl@0
|
346 |
|
sl@0
|
347 |
// Kill the server to ensure we restart it when we connect
|
sl@0
|
348 |
res = CleanupHelpers::KillProcess(KTaskScheduler);
|
sl@0
|
349 |
TEST2(res, KErrNone);
|
sl@0
|
350 |
TheScheduler.Close();
|
sl@0
|
351 |
|
sl@0
|
352 |
// Create task files to test cleanup
|
sl@0
|
353 |
// To access private data cage, uses SchSvrHelplers::CreateTaskFilesL()
|
sl@0
|
354 |
TheTest.Next(_L("Creating dummy task files"));
|
sl@0
|
355 |
res = SchSvrHelpers::CreateTaskFilesL();
|
sl@0
|
356 |
|
sl@0
|
357 |
//Restart the scheduler which should clean up temp files on startup
|
sl@0
|
358 |
TheTest.Next(_L("===== Connect to Scheduler ====="));
|
sl@0
|
359 |
res = TheScheduler.Connect();
|
sl@0
|
360 |
TEST2(res, KErrNone);
|
sl@0
|
361 |
|
sl@0
|
362 |
//wait for the server to start up
|
sl@0
|
363 |
SchSvrHelpers::Pause(TheTest, 2);
|
sl@0
|
364 |
|
sl@0
|
365 |
TheScheduler.Close();
|
sl@0
|
366 |
|
sl@0
|
367 |
// Check for left task files after scheduled tasks completed
|
sl@0
|
368 |
// To access private data cage, uses SchSvrHelplers::CheckTaskFilesL()
|
sl@0
|
369 |
TheTest.Next(_L("Now checking no files left after task scheduler starts"));
|
sl@0
|
370 |
res = SchSvrHelpers::CheckTaskFilesL();
|
sl@0
|
371 |
|
sl@0
|
372 |
TEST2(res, KErrNone);
|
sl@0
|
373 |
|
sl@0
|
374 |
TheTest.Next(_L("All files deleted as expected..."));
|
sl@0
|
375 |
}
|
sl@0
|
376 |
|
sl@0
|
377 |
/**
|
sl@0
|
378 |
@SYMTestCaseID SYSLIB-SCHSVR-CT-3402
|
sl@0
|
379 |
@SYMTestCaseDesc Test memory cleanup on Task Scheduler exit
|
sl@0
|
380 |
@SYMTestPriority High
|
sl@0
|
381 |
@SYMTestActions Start the scheduler and register a client.
|
sl@0
|
382 |
Execute a schedule and then terminate the scheduler.
|
sl@0
|
383 |
When the scheduler is restarted it should exit as there are no
|
sl@0
|
384 |
pending schedules. On exit all allocated memory should be freed
|
sl@0
|
385 |
@SYMTestExpectedResults All allocated memory should be freed when the scheduler exits
|
sl@0
|
386 |
@SYMDEF DEF102414
|
sl@0
|
387 |
*/
|
sl@0
|
388 |
static void DoTest4L()
|
sl@0
|
389 |
{
|
sl@0
|
390 |
__UHEAP_MARK;
|
sl@0
|
391 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3402 Test memory cleanup on Task Scheduler exit "));
|
sl@0
|
392 |
|
sl@0
|
393 |
// Connect to the server
|
sl@0
|
394 |
TheTest.Next(_L("===== Connect to Scheduler ====="));
|
sl@0
|
395 |
TInt res = TheScheduler.Connect();
|
sl@0
|
396 |
TEST2(res, KErrNone);
|
sl@0
|
397 |
|
sl@0
|
398 |
// Register a client with the server
|
sl@0
|
399 |
TheTest.Next(_L("===== Registering Client ====="));
|
sl@0
|
400 |
res = SchSvrHelpers::RegisterClientL(TheScheduler);
|
sl@0
|
401 |
TEST2(res, KErrNone);
|
sl@0
|
402 |
|
sl@0
|
403 |
//Schedule a task and execute it
|
sl@0
|
404 |
ScheduleAndExecuteTaskL();
|
sl@0
|
405 |
|
sl@0
|
406 |
// Kill the server
|
sl@0
|
407 |
res = CleanupHelpers::KillProcess(KTaskScheduler);
|
sl@0
|
408 |
TEST2(res, KErrNone);
|
sl@0
|
409 |
|
sl@0
|
410 |
TheScheduler.Close();
|
sl@0
|
411 |
|
sl@0
|
412 |
//Restarting with a registered client and no schedule should
|
sl@0
|
413 |
//cause the server to exit. Ther server should free all allocated
|
sl@0
|
414 |
//memory. If all memory is not freed, heap check macros within
|
sl@0
|
415 |
// the task scheduler code will cause a panic
|
sl@0
|
416 |
SchSvrHelpers::LaunchTaskSchedulerL();
|
sl@0
|
417 |
|
sl@0
|
418 |
//wait for the server to exit
|
sl@0
|
419 |
SchSvrHelpers::Pause(TheTest, 2);
|
sl@0
|
420 |
|
sl@0
|
421 |
//Verify that the server has already exited - there are two valid
|
sl@0
|
422 |
//error codes depending on how quickly the process is cleaned up
|
sl@0
|
423 |
//KErrDied - Process is dead but hasn't been cleaned up yet by the kernel
|
sl@0
|
424 |
//KErrNotFound - Process has been cleaned up
|
sl@0
|
425 |
res = CleanupHelpers::KillProcess(KTaskScheduler);
|
sl@0
|
426 |
|
sl@0
|
427 |
TEST((res == KErrDied)||(res == KErrNotFound));
|
sl@0
|
428 |
|
sl@0
|
429 |
__UHEAP_MARKEND;
|
sl@0
|
430 |
|
sl@0
|
431 |
TheTest.Next(_L("All memory freed..."));
|
sl@0
|
432 |
}
|
sl@0
|
433 |
|
sl@0
|
434 |
|
sl@0
|
435 |
/**
|
sl@0
|
436 |
@SYMTestCaseID SYSLIB-SCHSVR-CT-3412
|
sl@0
|
437 |
@SYMTestCaseDesc Test Task Scheduler startup with pending schedule
|
sl@0
|
438 |
@SYMTestPriority High
|
sl@0
|
439 |
@SYMTestActions Start the scheduler and register a client.
|
sl@0
|
440 |
Create a scheduled task and then terminate the scheduler without executing the task.
|
sl@0
|
441 |
When the scheduler is restarted it should not exit as there is a
|
sl@0
|
442 |
pending schedule. Verify that the scheduler is still active by executing
|
sl@0
|
443 |
the schedule
|
sl@0
|
444 |
@SYMTestExpectedResults The task scheduler should not exit and the schedule should execute
|
sl@0
|
445 |
@SYMDEF DEF102414
|
sl@0
|
446 |
*/
|
sl@0
|
447 |
static void DoTest5L()
|
sl@0
|
448 |
{
|
sl@0
|
449 |
__UHEAP_MARK;
|
sl@0
|
450 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3412 Test Task Scheduler startup with pending schedule "));
|
sl@0
|
451 |
|
sl@0
|
452 |
// Connect to the server
|
sl@0
|
453 |
TheTest.Next(_L("===== Connect to Scheduler ====="));
|
sl@0
|
454 |
TInt res = TheScheduler.Connect();
|
sl@0
|
455 |
TEST2(res, KErrNone);
|
sl@0
|
456 |
|
sl@0
|
457 |
// Register a client with the server
|
sl@0
|
458 |
TheTest.Next(_L("===== Registering Client ====="));
|
sl@0
|
459 |
res = SchSvrHelpers::RegisterClientL(TheScheduler);
|
sl@0
|
460 |
TEST2(res, KErrNone);
|
sl@0
|
461 |
|
sl@0
|
462 |
//Schedule a task
|
sl@0
|
463 |
ScheduleTaskL();
|
sl@0
|
464 |
|
sl@0
|
465 |
// Kill the server
|
sl@0
|
466 |
res = CleanupHelpers::KillProcess(KTaskScheduler);
|
sl@0
|
467 |
TEST2(res, KErrNone);
|
sl@0
|
468 |
TheScheduler.Close();
|
sl@0
|
469 |
|
sl@0
|
470 |
TheTest.Next(_L("Create Task notification semaphore"));
|
sl@0
|
471 |
//initialise task notification semaphore
|
sl@0
|
472 |
STaskSemaphore sem;
|
sl@0
|
473 |
sem.CreateL();
|
sl@0
|
474 |
|
sl@0
|
475 |
//Restart the scheduler - task scheduler should not exit as there is a
|
sl@0
|
476 |
//pending schedule
|
sl@0
|
477 |
res = SchSvrHelpers::LaunchTaskSchedulerL();
|
sl@0
|
478 |
TEST2(res, KErrNone);
|
sl@0
|
479 |
|
sl@0
|
480 |
//Execute task and wait for it to run - this would not succeed
|
sl@0
|
481 |
//if task scheduler had exited above
|
sl@0
|
482 |
ExecuteTaskL();
|
sl@0
|
483 |
TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
|
sl@0
|
484 |
|
sl@0
|
485 |
//Kill the process and verify that the scheduler was active
|
sl@0
|
486 |
//If the task scheduler isnt active when we try to kill it
|
sl@0
|
487 |
//KillProcess would return KErrDied
|
sl@0
|
488 |
res = CleanupHelpers::KillProcess(KTaskScheduler);
|
sl@0
|
489 |
TEST2(res, KErrNone);
|
sl@0
|
490 |
|
sl@0
|
491 |
//close handle to semaphore
|
sl@0
|
492 |
sem.Close();
|
sl@0
|
493 |
|
sl@0
|
494 |
__UHEAP_MARKEND;
|
sl@0
|
495 |
|
sl@0
|
496 |
}
|
sl@0
|
497 |
|
sl@0
|
498 |
/**
|
sl@0
|
499 |
@SYMTestCaseID SYSLIB-SCHSVR-CT-4010
|
sl@0
|
500 |
@SYMTestCaseDesc Test that adding a task using an unregistered client panics the client and does not crash the server.
|
sl@0
|
501 |
@SYMTestPriority High
|
sl@0
|
502 |
@SYMTestActions Schedule a task with a client that has not been registered.
|
sl@0
|
503 |
@SYMTestExpectedResults Client should be panicked.
|
sl@0
|
504 |
@SYMDEF DEF124488
|
sl@0
|
505 |
*/
|
sl@0
|
506 |
static void DoTest6L()
|
sl@0
|
507 |
{
|
sl@0
|
508 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-4010 Test handling of unregistered client Should Panic Client thread "));
|
sl@0
|
509 |
|
sl@0
|
510 |
RThread testThread;
|
sl@0
|
511 |
_LIT(KThreadName, "PanicClientThread");
|
sl@0
|
512 |
|
sl@0
|
513 |
testThread.Create(KThreadName, TestPanicThread, KDefaultStackSize, 0x1000, 0x100000, NULL);
|
sl@0
|
514 |
|
sl@0
|
515 |
TRequestStatus requestStatus;
|
sl@0
|
516 |
// Request notification when the thread terminates
|
sl@0
|
517 |
testThread.Logon(requestStatus);
|
sl@0
|
518 |
|
sl@0
|
519 |
TBool justInTime=User::JustInTime();
|
sl@0
|
520 |
User::SetJustInTime(EFalse);
|
sl@0
|
521 |
// Let the thread execute
|
sl@0
|
522 |
testThread.Resume();
|
sl@0
|
523 |
|
sl@0
|
524 |
// Wait for termination
|
sl@0
|
525 |
User::WaitForRequest(requestStatus);
|
sl@0
|
526 |
User::SetJustInTime(justInTime);
|
sl@0
|
527 |
|
sl@0
|
528 |
TEST2(testThread.ExitReason(), 0);
|
sl@0
|
529 |
testThread.Close();
|
sl@0
|
530 |
|
sl@0
|
531 |
}
|
sl@0
|
532 |
|
sl@0
|
533 |
static TInt RunTestsL()
|
sl@0
|
534 |
{
|
sl@0
|
535 |
TheTest.Next(_L("Delete old files"));
|
sl@0
|
536 |
SchSvrHelpers::DeleteScheduleFilesL();
|
sl@0
|
537 |
|
sl@0
|
538 |
//create P&S variables for the test
|
sl@0
|
539 |
CreateTestVariables();
|
sl@0
|
540 |
|
sl@0
|
541 |
TheTest.Next(_L("Start tests"));
|
sl@0
|
542 |
|
sl@0
|
543 |
CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
|
sl@0
|
544 |
CleanupStack::PushL(scheduler);
|
sl@0
|
545 |
CActiveScheduler::Install(scheduler);
|
sl@0
|
546 |
|
sl@0
|
547 |
DoTest1L();
|
sl@0
|
548 |
DoTest2L();
|
sl@0
|
549 |
DoTest3L();
|
sl@0
|
550 |
DoTest4L();
|
sl@0
|
551 |
DoTest5L();
|
sl@0
|
552 |
DoTest6L();
|
sl@0
|
553 |
|
sl@0
|
554 |
TheTest.Next(_L("Tidying up"));
|
sl@0
|
555 |
CleanupStack::PopAndDestroy(scheduler);
|
sl@0
|
556 |
|
sl@0
|
557 |
return KErrNone;
|
sl@0
|
558 |
}
|
sl@0
|
559 |
|
sl@0
|
560 |
GLDEF_C TInt E32Main()
|
sl@0
|
561 |
{
|
sl@0
|
562 |
__UHEAP_MARK;
|
sl@0
|
563 |
TheTest.Start(_L("TC_TSCH_ROBUSTNESS"));
|
sl@0
|
564 |
TheTest.Title();
|
sl@0
|
565 |
TheCleanup = CTrapCleanup::New();
|
sl@0
|
566 |
|
sl@0
|
567 |
//If the previous test fails, SCHSVR.exe may stay in memory.
|
sl@0
|
568 |
TRAPD(error,CleanupHelpers::TestCleanupL());
|
sl@0
|
569 |
TEST2(error, KErrNone);
|
sl@0
|
570 |
TheTest(TheFsSession.Connect() == KErrNone);;
|
sl@0
|
571 |
TRAP(error, RunTestsL());
|
sl@0
|
572 |
TEST2(error, KErrNone);
|
sl@0
|
573 |
TRAP(error,CleanupHelpers::TestCleanupL());
|
sl@0
|
574 |
TEST2(error, KErrNone);
|
sl@0
|
575 |
delete TheCleanup;
|
sl@0
|
576 |
|
sl@0
|
577 |
TheFsSession.Close();
|
sl@0
|
578 |
TheTest.End();
|
sl@0
|
579 |
TheTest.Close();
|
sl@0
|
580 |
__UHEAP_MARKEND;
|
sl@0
|
581 |
|
sl@0
|
582 |
return KErrNone;
|
sl@0
|
583 |
}
|