sl@0
|
1 |
// Copyright (c) 2004-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 |
//
|
sl@0
|
28 |
// Literal constants
|
sl@0
|
29 |
//
|
sl@0
|
30 |
_LIT(KTestName, "TC_TSCH_SCHSVR_OOM");
|
sl@0
|
31 |
|
sl@0
|
32 |
|
sl@0
|
33 |
//
|
sl@0
|
34 |
// Type definitions
|
sl@0
|
35 |
//
|
sl@0
|
36 |
typedef CArrayFixFlat<TScheduleEntryInfo> CSchEntryInfoArray;
|
sl@0
|
37 |
typedef CArrayFixFlat<TTaskInfo> CTaskInfoArray;
|
sl@0
|
38 |
typedef CArrayFixFlat<TSchedulerItemRef> CSchItemRefArray;
|
sl@0
|
39 |
typedef CArrayFixFlat<TTaskSchedulerCondition> CSchConditionArray;
|
sl@0
|
40 |
|
sl@0
|
41 |
//
|
sl@0
|
42 |
// Global data
|
sl@0
|
43 |
//
|
sl@0
|
44 |
RTest TheTest(KTestName);
|
sl@0
|
45 |
static RScheduler TheScheduler;
|
sl@0
|
46 |
static CTrapCleanup* TheCleanup;
|
sl@0
|
47 |
static RFs TheFsSession;
|
sl@0
|
48 |
|
sl@0
|
49 |
const TUid KTestUid = TUid::Uid(0x12345678);
|
sl@0
|
50 |
const TInt KTestKey1 = 1;
|
sl@0
|
51 |
|
sl@0
|
52 |
|
sl@0
|
53 |
//***********************************************************************************
|
sl@0
|
54 |
static void GetTaskInfoL(CTaskInfoArray& aTaskInfoArray,
|
sl@0
|
55 |
TInt aScheduleId)
|
sl@0
|
56 |
// Extract schedule references from the schedule server based on a filter. If
|
sl@0
|
57 |
{
|
sl@0
|
58 |
aTaskInfoArray.Reset();
|
sl@0
|
59 |
TTime nextTimeScheduleIsDue;
|
sl@0
|
60 |
TScheduleState state;
|
sl@0
|
61 |
CSchEntryInfoArray* entries
|
sl@0
|
62 |
= new (ELeave) CSchEntryInfoArray(3);
|
sl@0
|
63 |
CleanupStack::PushL(entries);
|
sl@0
|
64 |
TInt res = TheScheduler.GetScheduleL(aScheduleId,
|
sl@0
|
65 |
state,
|
sl@0
|
66 |
*entries,
|
sl@0
|
67 |
aTaskInfoArray,
|
sl@0
|
68 |
nextTimeScheduleIsDue);
|
sl@0
|
69 |
TEST2(res, KErrNone);
|
sl@0
|
70 |
CleanupStack::PopAndDestroy(entries);
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
//***********************************************************************************
|
sl@0
|
74 |
static TInt CountTasksL(TInt aScheduleId)
|
sl@0
|
75 |
{
|
sl@0
|
76 |
CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
|
sl@0
|
77 |
CleanupStack::PushL(tasks);
|
sl@0
|
78 |
GetTaskInfoL(*tasks, aScheduleId);
|
sl@0
|
79 |
TInt ret = tasks->Count();
|
sl@0
|
80 |
CleanupStack::PopAndDestroy(tasks);
|
sl@0
|
81 |
return ret;
|
sl@0
|
82 |
}
|
sl@0
|
83 |
|
sl@0
|
84 |
//***********************************************************************************
|
sl@0
|
85 |
static TInt CountScheduledItemsL(TScheduleFilter aFilter,
|
sl@0
|
86 |
RScheduler& aScheduler)
|
sl@0
|
87 |
// Extract schedule references from the schedule server based on a filter. If
|
sl@0
|
88 |
{
|
sl@0
|
89 |
CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3);
|
sl@0
|
90 |
CleanupStack::PushL(refs);
|
sl@0
|
91 |
|
sl@0
|
92 |
TInt res = aScheduler.GetScheduleRefsL(*refs, aFilter);
|
sl@0
|
93 |
TEST2(res, KErrNone);
|
sl@0
|
94 |
|
sl@0
|
95 |
TInt count = refs->Count();
|
sl@0
|
96 |
CleanupStack::PopAndDestroy(); // refs
|
sl@0
|
97 |
return count;
|
sl@0
|
98 |
}
|
sl@0
|
99 |
|
sl@0
|
100 |
|
sl@0
|
101 |
//***********************************************************************************
|
sl@0
|
102 |
static CSchEntryInfoArray* CreateScheduleArrayLC()
|
sl@0
|
103 |
{
|
sl@0
|
104 |
CSchEntryInfoArray* entryList = new (ELeave) CSchEntryInfoArray(3);
|
sl@0
|
105 |
CleanupStack::PushL(entryList);
|
sl@0
|
106 |
|
sl@0
|
107 |
TScheduleEntryInfo entry1;
|
sl@0
|
108 |
entry1.iStartTime = SchSvrHelpers::TimeBasedOnOffset(0, 20); // 20m from "now"
|
sl@0
|
109 |
entry1.iInterval = 1;
|
sl@0
|
110 |
entry1.iIntervalType = EDaily;
|
sl@0
|
111 |
entry1.iValidityPeriod = 20;
|
sl@0
|
112 |
entryList->AppendL(entry1);
|
sl@0
|
113 |
|
sl@0
|
114 |
return entryList;
|
sl@0
|
115 |
}
|
sl@0
|
116 |
|
sl@0
|
117 |
//***********************************************************************************
|
sl@0
|
118 |
static CSchConditionArray* CreateConditionArrayLC()
|
sl@0
|
119 |
{
|
sl@0
|
120 |
CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3);
|
sl@0
|
121 |
CleanupStack::PushL(conditionList);
|
sl@0
|
122 |
|
sl@0
|
123 |
TTaskSchedulerCondition condition1;
|
sl@0
|
124 |
condition1.iCategory = KTestUid;
|
sl@0
|
125 |
condition1.iKey = KTestKey1;
|
sl@0
|
126 |
condition1.iState = 10;
|
sl@0
|
127 |
condition1.iType = TTaskSchedulerCondition::EEquals;
|
sl@0
|
128 |
conditionList->AppendL(condition1);
|
sl@0
|
129 |
|
sl@0
|
130 |
return conditionList;
|
sl@0
|
131 |
}
|
sl@0
|
132 |
|
sl@0
|
133 |
/**
|
sl@0
|
134 |
@SYMTestCaseID SYSLIB-SCHSVR-CT-1027
|
sl@0
|
135 |
@SYMTestCaseDesc Tests out of memory errors for time based API's
|
sl@0
|
136 |
@SYMTestPriority High
|
sl@0
|
137 |
@SYMTestActions Test for memory errors,while creating,enabling,disabling,editing and other operations on schedule task
|
sl@0
|
138 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
139 |
@SYMREQ REQ0000
|
sl@0
|
140 |
*/
|
sl@0
|
141 |
static void DoTest1L()
|
sl@0
|
142 |
// Time based API's
|
sl@0
|
143 |
{
|
sl@0
|
144 |
TInt err = KErrNone;
|
sl@0
|
145 |
TInt tryCount = 0;
|
sl@0
|
146 |
|
sl@0
|
147 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1027 ===== Starting OOM test ===== "));
|
sl@0
|
148 |
|
sl@0
|
149 |
CSchEntryInfoArray* scheduleArray = CreateScheduleArrayLC();
|
sl@0
|
150 |
TSchedulerItemRef ref1;
|
sl@0
|
151 |
|
sl@0
|
152 |
TheTest.Next(_L("===== Testing create persistent schedule ====="));
|
sl@0
|
153 |
for (tryCount = 0; ;++tryCount)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
// These allocations are ignored because they cause corruptness
|
sl@0
|
156 |
// of the persistent store. Its a bit rubbish.
|
sl@0
|
157 |
if(tryCount < 7 || tryCount >8 )
|
sl@0
|
158 |
{
|
sl@0
|
159 |
TheScheduler.__DbgFailNext(tryCount);
|
sl@0
|
160 |
TheScheduler.__DbgMarkHeap();
|
sl@0
|
161 |
err = TheScheduler.CreatePersistentSchedule(ref1, *scheduleArray);
|
sl@0
|
162 |
if (err==KErrNone)
|
sl@0
|
163 |
{
|
sl@0
|
164 |
TheScheduler.__DbgResetHeap();
|
sl@0
|
165 |
break;
|
sl@0
|
166 |
}
|
sl@0
|
167 |
TEST2(err, KErrNoMemory);
|
sl@0
|
168 |
// reset server side heap for next iteration.
|
sl@0
|
169 |
TheScheduler.__DbgMarkEnd(0);
|
sl@0
|
170 |
}
|
sl@0
|
171 |
}
|
sl@0
|
172 |
// Check schedule count
|
sl@0
|
173 |
TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
174 |
TEST(scheduleCount == 1);
|
sl@0
|
175 |
|
sl@0
|
176 |
// OK, now we have a persistent schedule
|
sl@0
|
177 |
TheTest.Next(_L("===== Testing disable schedule ====="));
|
sl@0
|
178 |
for (tryCount = 0; ;++tryCount)
|
sl@0
|
179 |
{
|
sl@0
|
180 |
TheScheduler.__DbgFailNext(tryCount);
|
sl@0
|
181 |
TheScheduler.__DbgMarkHeap();
|
sl@0
|
182 |
err = TheScheduler.DisableSchedule(ref1.iHandle);
|
sl@0
|
183 |
if (err==KErrNone)
|
sl@0
|
184 |
{
|
sl@0
|
185 |
TheScheduler.__DbgResetHeap();
|
sl@0
|
186 |
break;
|
sl@0
|
187 |
}
|
sl@0
|
188 |
TEST2(err, KErrNoMemory);
|
sl@0
|
189 |
// reset server side heap for next iteration.
|
sl@0
|
190 |
TheScheduler.__DbgMarkEnd(0);
|
sl@0
|
191 |
}
|
sl@0
|
192 |
// Check schedule count
|
sl@0
|
193 |
scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
194 |
TEST(scheduleCount == 1);
|
sl@0
|
195 |
|
sl@0
|
196 |
TheTest.Next(_L("===== Testing enable schedule ====="));
|
sl@0
|
197 |
for (tryCount = 0; ;++tryCount)
|
sl@0
|
198 |
{
|
sl@0
|
199 |
TheScheduler.__DbgFailNext(tryCount);
|
sl@0
|
200 |
TheScheduler.__DbgMarkHeap();
|
sl@0
|
201 |
err = TheScheduler.EnableSchedule(ref1.iHandle);
|
sl@0
|
202 |
if (err==KErrNone)
|
sl@0
|
203 |
{
|
sl@0
|
204 |
TheScheduler.__DbgResetHeap();
|
sl@0
|
205 |
break;
|
sl@0
|
206 |
}
|
sl@0
|
207 |
TEST2(err, KErrNoMemory);
|
sl@0
|
208 |
// reset server side heap for next iteration.
|
sl@0
|
209 |
TheScheduler.__DbgMarkEnd(0);
|
sl@0
|
210 |
}
|
sl@0
|
211 |
// Check schedule count
|
sl@0
|
212 |
scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
213 |
TEST(scheduleCount == 1);
|
sl@0
|
214 |
|
sl@0
|
215 |
TheTest.Next(_L("===== Testing edit schedule ====="));
|
sl@0
|
216 |
for (tryCount = 0; ;++tryCount)
|
sl@0
|
217 |
{
|
sl@0
|
218 |
TheScheduler.__DbgFailNext(tryCount);
|
sl@0
|
219 |
TheScheduler.__DbgMarkHeap();
|
sl@0
|
220 |
// Even though we use the same array as before, the task scheduler
|
sl@0
|
221 |
// code is not smart enough to just return but actually replaces
|
sl@0
|
222 |
// the existing one, hence we are actually testing this method fully.
|
sl@0
|
223 |
err = TheScheduler.EditSchedule(ref1.iHandle, *scheduleArray);
|
sl@0
|
224 |
if (err==KErrNone)
|
sl@0
|
225 |
{
|
sl@0
|
226 |
TheScheduler.__DbgResetHeap();
|
sl@0
|
227 |
break;
|
sl@0
|
228 |
}
|
sl@0
|
229 |
TEST2(err, KErrNoMemory);
|
sl@0
|
230 |
// reset server side heap for next iteration.
|
sl@0
|
231 |
TheScheduler.__DbgMarkEnd(0);
|
sl@0
|
232 |
}
|
sl@0
|
233 |
// Check schedule count
|
sl@0
|
234 |
scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
235 |
TEST(scheduleCount == 1);
|
sl@0
|
236 |
|
sl@0
|
237 |
TheTest.Next(_L("===== Testing delete schedule ====="));
|
sl@0
|
238 |
for (tryCount = 0; ;++tryCount)
|
sl@0
|
239 |
{
|
sl@0
|
240 |
TheScheduler.__DbgFailNext(tryCount);
|
sl@0
|
241 |
TheScheduler.__DbgMarkHeap();
|
sl@0
|
242 |
err = TheScheduler.DeleteSchedule(ref1.iHandle);
|
sl@0
|
243 |
if (err==KErrNone)
|
sl@0
|
244 |
{
|
sl@0
|
245 |
TheScheduler.__DbgResetHeap();
|
sl@0
|
246 |
break;
|
sl@0
|
247 |
}
|
sl@0
|
248 |
TEST2(err, KErrNoMemory);
|
sl@0
|
249 |
// reset server side heap for next iteration.
|
sl@0
|
250 |
TheScheduler.__DbgMarkEnd(0);
|
sl@0
|
251 |
}
|
sl@0
|
252 |
// Check schedule count
|
sl@0
|
253 |
scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
254 |
TEST(scheduleCount == 0);
|
sl@0
|
255 |
|
sl@0
|
256 |
// delete old files.
|
sl@0
|
257 |
// We need to do this because we have actually corrupted the store,
|
sl@0
|
258 |
// even though its empty. Without deleting it we get problems below.
|
sl@0
|
259 |
// This is a bit rubbish having to do this but what else can be done??
|
sl@0
|
260 |
TheTest.Next(_L("Delete old files"));
|
sl@0
|
261 |
SchSvrHelpers::DeleteScheduleFilesL();
|
sl@0
|
262 |
|
sl@0
|
263 |
// OK now add back schedule in preparation for adding tasks.
|
sl@0
|
264 |
err = TheScheduler.CreatePersistentSchedule(ref1, *scheduleArray);
|
sl@0
|
265 |
TEST2(err, KErrNone);
|
sl@0
|
266 |
|
sl@0
|
267 |
TheTest.Next(_L("===== Testing ScheduleTask ====="));
|
sl@0
|
268 |
|
sl@0
|
269 |
_LIT(KTaskName, "TheTaskName");
|
sl@0
|
270 |
TName name = KTaskName();
|
sl@0
|
271 |
TTaskInfo taskInfo(0, name, 2, 0);
|
sl@0
|
272 |
|
sl@0
|
273 |
HBufC* data = _L("the data").AllocLC();
|
sl@0
|
274 |
// cant test ScheduleTask API using OOM loop as it does dodgy things to
|
sl@0
|
275 |
// the store which cause allocation problems. Need to investigate this
|
sl@0
|
276 |
// later at some stage.
|
sl@0
|
277 |
TEST2(TheScheduler.ScheduleTask(taskInfo, *data, ref1.iHandle), KErrNone);
|
sl@0
|
278 |
|
sl@0
|
279 |
// Check schedule and task count
|
sl@0
|
280 |
scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
281 |
TEST(scheduleCount == 1);
|
sl@0
|
282 |
TInt taskCount = CountTasksL(ref1.iHandle);
|
sl@0
|
283 |
TEST(taskCount = 1);
|
sl@0
|
284 |
|
sl@0
|
285 |
TheTest.Next(_L("===== Testing GetScheduleRefsL ====="));
|
sl@0
|
286 |
|
sl@0
|
287 |
CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3);
|
sl@0
|
288 |
CleanupStack::PushL(refs);
|
sl@0
|
289 |
for (tryCount = 0; ;++tryCount)
|
sl@0
|
290 |
{
|
sl@0
|
291 |
TheScheduler.__DbgFailNext(tryCount);
|
sl@0
|
292 |
TheScheduler.__DbgMarkHeap();
|
sl@0
|
293 |
err = TheScheduler.GetScheduleRefsL(*refs, EPendingSchedules);
|
sl@0
|
294 |
if (err==KErrNone)
|
sl@0
|
295 |
{
|
sl@0
|
296 |
TheScheduler.__DbgResetHeap();
|
sl@0
|
297 |
break;
|
sl@0
|
298 |
}
|
sl@0
|
299 |
TEST2(err, KErrNoMemory);
|
sl@0
|
300 |
// reset server side heap for next iteration.
|
sl@0
|
301 |
TheScheduler.__DbgMarkEnd(0);
|
sl@0
|
302 |
}
|
sl@0
|
303 |
// Check schedule and task count
|
sl@0
|
304 |
scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
305 |
TEST(scheduleCount == 1);
|
sl@0
|
306 |
taskCount = CountTasksL(ref1.iHandle);
|
sl@0
|
307 |
TEST(taskCount = 1);
|
sl@0
|
308 |
|
sl@0
|
309 |
TheTest.Next(_L("===== Testing GetScheduleL ====="));
|
sl@0
|
310 |
|
sl@0
|
311 |
CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
|
sl@0
|
312 |
CleanupStack::PushL(tasks);
|
sl@0
|
313 |
TScheduleState state;
|
sl@0
|
314 |
TTime time;
|
sl@0
|
315 |
CSchEntryInfoArray* entryList = new (ELeave) CSchEntryInfoArray(3);
|
sl@0
|
316 |
CleanupStack::PushL(entryList);
|
sl@0
|
317 |
for (tryCount = 0; ;++tryCount)
|
sl@0
|
318 |
{
|
sl@0
|
319 |
TheScheduler.__DbgFailNext(tryCount);
|
sl@0
|
320 |
TheScheduler.__DbgMarkHeap();
|
sl@0
|
321 |
err = TheScheduler.GetScheduleL(ref1.iHandle,
|
sl@0
|
322 |
state,
|
sl@0
|
323 |
*entryList,
|
sl@0
|
324 |
*tasks, time);
|
sl@0
|
325 |
if (err==KErrNone)
|
sl@0
|
326 |
{
|
sl@0
|
327 |
TheScheduler.__DbgResetHeap();
|
sl@0
|
328 |
break;
|
sl@0
|
329 |
}
|
sl@0
|
330 |
TEST2(err, KErrNoMemory);
|
sl@0
|
331 |
// reset server side heap for next iteration.
|
sl@0
|
332 |
TheScheduler.__DbgMarkEnd(0);
|
sl@0
|
333 |
}
|
sl@0
|
334 |
// Check schedule and task count
|
sl@0
|
335 |
TEST(entryList->Count() == 1);
|
sl@0
|
336 |
TEST(tasks->Count() == 1);
|
sl@0
|
337 |
scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
338 |
TEST(scheduleCount == 1);
|
sl@0
|
339 |
taskCount = CountTasksL(ref1.iHandle);
|
sl@0
|
340 |
TEST(taskCount = 1);
|
sl@0
|
341 |
|
sl@0
|
342 |
CleanupStack::PopAndDestroy(entryList);
|
sl@0
|
343 |
CleanupStack::PopAndDestroy(tasks);
|
sl@0
|
344 |
|
sl@0
|
345 |
TheTest.Next(_L("===== Testing GetTaskRefsL ====="));
|
sl@0
|
346 |
|
sl@0
|
347 |
for (tryCount = 0; ;++tryCount)
|
sl@0
|
348 |
{
|
sl@0
|
349 |
TheScheduler.__DbgFailNext(tryCount);
|
sl@0
|
350 |
TheScheduler.__DbgMarkHeap();
|
sl@0
|
351 |
err = TheScheduler.GetTaskRefsL(*refs,
|
sl@0
|
352 |
EAllSchedules,
|
sl@0
|
353 |
EAllTasks);
|
sl@0
|
354 |
if (err==KErrNone)
|
sl@0
|
355 |
{
|
sl@0
|
356 |
TheScheduler.__DbgResetHeap();
|
sl@0
|
357 |
break;
|
sl@0
|
358 |
}
|
sl@0
|
359 |
TEST2(err, KErrNoMemory);
|
sl@0
|
360 |
// reset server side heap for next iteration.
|
sl@0
|
361 |
TheScheduler.__DbgMarkEnd(0);
|
sl@0
|
362 |
}
|
sl@0
|
363 |
CleanupStack::PopAndDestroy(refs);
|
sl@0
|
364 |
|
sl@0
|
365 |
TheTest.Next(_L("===== Testing GetTaskDataSize ====="));
|
sl@0
|
366 |
|
sl@0
|
367 |
TInt size;
|
sl@0
|
368 |
for (tryCount = 0; ;++tryCount)
|
sl@0
|
369 |
{
|
sl@0
|
370 |
TheScheduler.__DbgFailNext(tryCount);
|
sl@0
|
371 |
TheScheduler.__DbgMarkHeap();
|
sl@0
|
372 |
err = TheScheduler.GetTaskDataSize(ref1.iHandle,
|
sl@0
|
373 |
size);
|
sl@0
|
374 |
if (err==KErrNone)
|
sl@0
|
375 |
{
|
sl@0
|
376 |
TheScheduler.__DbgResetHeap();
|
sl@0
|
377 |
break;
|
sl@0
|
378 |
}
|
sl@0
|
379 |
TEST2(err, KErrNoMemory);
|
sl@0
|
380 |
// reset server side heap for next iteration.
|
sl@0
|
381 |
TheScheduler.__DbgMarkEnd(0);
|
sl@0
|
382 |
}
|
sl@0
|
383 |
|
sl@0
|
384 |
TheTest.Next(_L("===== Testing GetTaskInfoL ====="));
|
sl@0
|
385 |
|
sl@0
|
386 |
HBufC* newData = HBufC::NewLC(size);
|
sl@0
|
387 |
TPtr pTaskData = newData->Des();
|
sl@0
|
388 |
|
sl@0
|
389 |
TTaskInfo newTaskInfo;
|
sl@0
|
390 |
for (tryCount = 0; ;++tryCount)
|
sl@0
|
391 |
{
|
sl@0
|
392 |
TheScheduler.__DbgFailNext(tryCount);
|
sl@0
|
393 |
TheScheduler.__DbgMarkHeap();
|
sl@0
|
394 |
err = TheScheduler.GetTaskInfoL(taskInfo.iTaskId,
|
sl@0
|
395 |
newTaskInfo,
|
sl@0
|
396 |
pTaskData,
|
sl@0
|
397 |
ref1,
|
sl@0
|
398 |
time);
|
sl@0
|
399 |
if (err==KErrNone)
|
sl@0
|
400 |
{
|
sl@0
|
401 |
TheScheduler.__DbgResetHeap();
|
sl@0
|
402 |
break;
|
sl@0
|
403 |
}
|
sl@0
|
404 |
TEST2(err, KErrNoMemory);
|
sl@0
|
405 |
// reset server side heap for next iteration.
|
sl@0
|
406 |
TheScheduler.__DbgMarkEnd(0);
|
sl@0
|
407 |
}
|
sl@0
|
408 |
TEST(newData->MatchF(*data) == 0);
|
sl@0
|
409 |
|
sl@0
|
410 |
scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
411 |
TEST(scheduleCount == 1);
|
sl@0
|
412 |
taskCount = CountTasksL(ref1.iHandle);
|
sl@0
|
413 |
TEST(taskCount = 1);
|
sl@0
|
414 |
|
sl@0
|
415 |
CleanupStack::PopAndDestroy(newData);
|
sl@0
|
416 |
CleanupStack::PopAndDestroy(data);
|
sl@0
|
417 |
|
sl@0
|
418 |
TheTest.Next(_L("===== Testing GetScheduleTypeL ====="));
|
sl@0
|
419 |
|
sl@0
|
420 |
TScheduleType type;
|
sl@0
|
421 |
for (tryCount = 0; ;++tryCount)
|
sl@0
|
422 |
{
|
sl@0
|
423 |
TheScheduler.__DbgFailNext(tryCount);
|
sl@0
|
424 |
TheScheduler.__DbgMarkHeap();
|
sl@0
|
425 |
err = TheScheduler.GetScheduleTypeL(ref1.iHandle, type);
|
sl@0
|
426 |
if (err==KErrNone)
|
sl@0
|
427 |
{
|
sl@0
|
428 |
TheScheduler.__DbgResetHeap();
|
sl@0
|
429 |
break;
|
sl@0
|
430 |
}
|
sl@0
|
431 |
TEST2(err, KErrNoMemory);
|
sl@0
|
432 |
// reset server side heap for next iteration.
|
sl@0
|
433 |
TheScheduler.__DbgMarkEnd(0);
|
sl@0
|
434 |
}
|
sl@0
|
435 |
TEST(type == ETimeSchedule);
|
sl@0
|
436 |
|
sl@0
|
437 |
CleanupStack::PopAndDestroy(scheduleArray);
|
sl@0
|
438 |
|
sl@0
|
439 |
TheTest.Next(_L("===== Testing DeleteTask ====="));
|
sl@0
|
440 |
|
sl@0
|
441 |
for (tryCount = 0; ;++tryCount)
|
sl@0
|
442 |
{
|
sl@0
|
443 |
TheScheduler.__DbgFailNext(tryCount);
|
sl@0
|
444 |
TheScheduler.__DbgMarkHeap();
|
sl@0
|
445 |
err = TheScheduler.DeleteTask(taskInfo.iTaskId);
|
sl@0
|
446 |
//include test for KErrNotFound here as task is actually deleted and
|
sl@0
|
447 |
// then store is updated (which causes mem failure). Problems
|
sl@0
|
448 |
// will still occur if you add a new task again and try and access store
|
sl@0
|
449 |
// as store is likely to still be corrupt. Investigate this??
|
sl@0
|
450 |
if (err==KErrNone || err==KErrNotFound)
|
sl@0
|
451 |
{
|
sl@0
|
452 |
TheScheduler.__DbgResetHeap();
|
sl@0
|
453 |
break;
|
sl@0
|
454 |
}
|
sl@0
|
455 |
TEST2(err, KErrNoMemory);
|
sl@0
|
456 |
// reset server side heap for next iteration.
|
sl@0
|
457 |
TheScheduler.__DbgMarkEnd(0);
|
sl@0
|
458 |
}
|
sl@0
|
459 |
scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
460 |
TEST(scheduleCount == 1);
|
sl@0
|
461 |
taskCount = CountTasksL(ref1.iHandle);
|
sl@0
|
462 |
TEST(taskCount == 0);
|
sl@0
|
463 |
|
sl@0
|
464 |
//Now delete schedule to setup for next test
|
sl@0
|
465 |
TEST2(TheScheduler.DeleteSchedule(ref1.iHandle), KErrNone);
|
sl@0
|
466 |
scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
467 |
TEST(scheduleCount == 0);
|
sl@0
|
468 |
|
sl@0
|
469 |
SchSvrHelpers::Pause(TheTest);
|
sl@0
|
470 |
}
|
sl@0
|
471 |
|
sl@0
|
472 |
/**
|
sl@0
|
473 |
@SYMTestCaseID SYSLIB-SCHSVR-CT-1028
|
sl@0
|
474 |
@SYMTestCaseDesc Tests out of memory errors for Condition based API's
|
sl@0
|
475 |
@SYMTestPriority High
|
sl@0
|
476 |
@SYMTestActions Create a persistent schedule,get and delete schedule.
|
sl@0
|
477 |
Check for memory and no errors.
|
sl@0
|
478 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
479 |
@SYMREQ REQ0000
|
sl@0
|
480 |
*/
|
sl@0
|
481 |
static void DoTest2L()
|
sl@0
|
482 |
// Condition based API's
|
sl@0
|
483 |
{
|
sl@0
|
484 |
TInt err = KErrNone;
|
sl@0
|
485 |
TInt tryCount = 0;
|
sl@0
|
486 |
|
sl@0
|
487 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1028 ===== Starting Condition OOM test ===== "));
|
sl@0
|
488 |
|
sl@0
|
489 |
// delete old files.
|
sl@0
|
490 |
// We need to do this because we have actually corrupted the store,
|
sl@0
|
491 |
// with the DeleteTask call. Without deleting it we get problems below.
|
sl@0
|
492 |
// This is a bit rubbish having to do this but what else can be done??
|
sl@0
|
493 |
TheTest.Next(_L("Delete old files"));
|
sl@0
|
494 |
SchSvrHelpers::DeleteScheduleFilesL();
|
sl@0
|
495 |
|
sl@0
|
496 |
//Ensure P&S variables are defined.
|
sl@0
|
497 |
err = RProperty::Define(KTestUid, KTestKey1, RProperty::EInt);
|
sl@0
|
498 |
TEST(err == KErrNone || err == KErrAlreadyExists);
|
sl@0
|
499 |
TEST2(RProperty::Set(KTestUid, KTestKey1,1), KErrNone);
|
sl@0
|
500 |
|
sl@0
|
501 |
CSchConditionArray* conditionArray = CreateConditionArrayLC();
|
sl@0
|
502 |
TSchedulerItemRef ref1;
|
sl@0
|
503 |
|
sl@0
|
504 |
TheTest.Next(_L("===== Testing create persistent schedule ====="));
|
sl@0
|
505 |
for (tryCount = 0; ;++tryCount)
|
sl@0
|
506 |
{
|
sl@0
|
507 |
TheScheduler.__DbgFailNext(tryCount);
|
sl@0
|
508 |
TheScheduler.__DbgMarkHeap();
|
sl@0
|
509 |
err = TheScheduler.CreatePersistentSchedule(ref1, *conditionArray, Time::MaxTTime());
|
sl@0
|
510 |
if (err==KErrNone)
|
sl@0
|
511 |
{
|
sl@0
|
512 |
TheScheduler.__DbgResetHeap();
|
sl@0
|
513 |
break;
|
sl@0
|
514 |
}
|
sl@0
|
515 |
TEST2(err, KErrNoMemory);
|
sl@0
|
516 |
// reset server side heap for next iteration.
|
sl@0
|
517 |
TheScheduler.__DbgMarkEnd(0);
|
sl@0
|
518 |
}
|
sl@0
|
519 |
// Check schedule count
|
sl@0
|
520 |
TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
521 |
TEST(scheduleCount == 1);
|
sl@0
|
522 |
|
sl@0
|
523 |
// This test code causes problems when EditSchedule fails, it deletes the entries
|
sl@0
|
524 |
// but doenst delete the actual CSchedule object. We can't do this really as the
|
sl@0
|
525 |
// schedule may have oustanding tasks. Need to clean up data in a consistent manner.
|
sl@0
|
526 |
// Fix this! Same applied for time based EditSchedule
|
sl@0
|
527 |
/* TheTest.Next(_L("===== Testing edit schedule ====="));
|
sl@0
|
528 |
for (tryCount = 0; ;++tryCount)
|
sl@0
|
529 |
{
|
sl@0
|
530 |
TheScheduler.__DbgFailNext(tryCount);
|
sl@0
|
531 |
TheScheduler.__DbgMarkHeap();
|
sl@0
|
532 |
// Even though we use the same array as before, the task scheduler
|
sl@0
|
533 |
// code is not smart enough to just return but actually replaces
|
sl@0
|
534 |
// the existing one, hence we are actually testing this method fully.
|
sl@0
|
535 |
err = TheScheduler.EditSchedule(ref1.iHandle, *conditionArray,
|
sl@0
|
536 |
SchSvrHelpers::TimeBasedOnOffset(0, 20));
|
sl@0
|
537 |
if (err==KErrNone)
|
sl@0
|
538 |
{
|
sl@0
|
539 |
TheScheduler.__DbgResetHeap();
|
sl@0
|
540 |
break;
|
sl@0
|
541 |
}
|
sl@0
|
542 |
TEST2(err, KErrNoMemory);
|
sl@0
|
543 |
// reset server side heap for next iteration.
|
sl@0
|
544 |
TheScheduler.__DbgMarkEnd(0);
|
sl@0
|
545 |
}
|
sl@0
|
546 |
// Check schedule count
|
sl@0
|
547 |
scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
548 |
TEST(scheduleCount == 1);
|
sl@0
|
549 |
*/
|
sl@0
|
550 |
TheTest.Next(_L("===== Testing GetScheduleL ====="));
|
sl@0
|
551 |
|
sl@0
|
552 |
CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
|
sl@0
|
553 |
CleanupStack::PushL(tasks);
|
sl@0
|
554 |
TScheduleState state;
|
sl@0
|
555 |
TTime time;
|
sl@0
|
556 |
CSchConditionArray* entryList = new (ELeave) CSchConditionArray(3);
|
sl@0
|
557 |
CleanupStack::PushL(entryList);
|
sl@0
|
558 |
for (tryCount = 0; ;++tryCount)
|
sl@0
|
559 |
{
|
sl@0
|
560 |
TheScheduler.__DbgFailNext(tryCount);
|
sl@0
|
561 |
TheScheduler.__DbgMarkHeap();
|
sl@0
|
562 |
err = TheScheduler.GetScheduleL(ref1.iHandle,
|
sl@0
|
563 |
state,
|
sl@0
|
564 |
*entryList,
|
sl@0
|
565 |
time, *tasks);
|
sl@0
|
566 |
if (err==KErrNone)
|
sl@0
|
567 |
{
|
sl@0
|
568 |
TheScheduler.__DbgResetHeap();
|
sl@0
|
569 |
break;
|
sl@0
|
570 |
}
|
sl@0
|
571 |
TEST2(err, KErrNoMemory);
|
sl@0
|
572 |
// reset server side heap for next iteration.
|
sl@0
|
573 |
TheScheduler.__DbgMarkEnd(0);
|
sl@0
|
574 |
}
|
sl@0
|
575 |
CleanupStack::PopAndDestroy(entryList);
|
sl@0
|
576 |
CleanupStack::PopAndDestroy(tasks);
|
sl@0
|
577 |
|
sl@0
|
578 |
TheTest.Next(_L("===== Testing delete schedule ====="));
|
sl@0
|
579 |
for (tryCount = 0; ;++tryCount)
|
sl@0
|
580 |
{
|
sl@0
|
581 |
TheScheduler.__DbgFailNext(tryCount);
|
sl@0
|
582 |
TheScheduler.__DbgMarkHeap();
|
sl@0
|
583 |
err = TheScheduler.DeleteSchedule(ref1.iHandle);
|
sl@0
|
584 |
if (err==KErrNone)
|
sl@0
|
585 |
{
|
sl@0
|
586 |
TheScheduler.__DbgResetHeap();
|
sl@0
|
587 |
break;
|
sl@0
|
588 |
}
|
sl@0
|
589 |
TEST2(err, KErrNoMemory);
|
sl@0
|
590 |
// reset server side heap for next iteration.
|
sl@0
|
591 |
TheScheduler.__DbgMarkEnd(0);
|
sl@0
|
592 |
}
|
sl@0
|
593 |
// Check schedule count
|
sl@0
|
594 |
scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
|
sl@0
|
595 |
TEST(scheduleCount == 0);
|
sl@0
|
596 |
|
sl@0
|
597 |
CleanupStack::PopAndDestroy(conditionArray);
|
sl@0
|
598 |
|
sl@0
|
599 |
SchSvrHelpers::Pause(TheTest);
|
sl@0
|
600 |
}
|
sl@0
|
601 |
|
sl@0
|
602 |
//***********************************************************************************
|
sl@0
|
603 |
static TInt RunTestsL()
|
sl@0
|
604 |
{
|
sl@0
|
605 |
TheTest.Next(_L("Delete old files"));
|
sl@0
|
606 |
SchSvrHelpers::DeleteScheduleFilesL();
|
sl@0
|
607 |
|
sl@0
|
608 |
TheTest.Next(_L("Create Task notification semaphore"));
|
sl@0
|
609 |
//initialise task notification semaphore
|
sl@0
|
610 |
STaskSemaphore sem;
|
sl@0
|
611 |
sem.CreateL();
|
sl@0
|
612 |
|
sl@0
|
613 |
// Connect to the server
|
sl@0
|
614 |
TheTest.Next(_L("===== Connect to Scheduler ====="));
|
sl@0
|
615 |
TInt res = TheScheduler.Connect();
|
sl@0
|
616 |
TEST2(res, KErrNone);
|
sl@0
|
617 |
// Register a client with the server
|
sl@0
|
618 |
TheTest.Next(_L("===== Registering Client ====="));
|
sl@0
|
619 |
res = SchSvrHelpers::RegisterClientL(TheScheduler);
|
sl@0
|
620 |
TEST2(res, KErrNone);
|
sl@0
|
621 |
|
sl@0
|
622 |
TheTest.Next(_L("Start tests"));
|
sl@0
|
623 |
DoTest1L();
|
sl@0
|
624 |
DoTest2L();
|
sl@0
|
625 |
|
sl@0
|
626 |
// Need to add OOM tests for when a task is executed
|
sl@0
|
627 |
// to clarify behaviour. This will be tricky!!!
|
sl@0
|
628 |
|
sl@0
|
629 |
TheTest.Next(_L("Tidying up"));
|
sl@0
|
630 |
//Tidying up so next test will be clear.
|
sl@0
|
631 |
TheTest.Next(_L("Delete all schedules"));
|
sl@0
|
632 |
SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
|
sl@0
|
633 |
SchSvrHelpers::Pause(TheTest, 2);
|
sl@0
|
634 |
TheTest.Next(_L("Delete old files\n"));
|
sl@0
|
635 |
SchSvrHelpers::DeleteScheduleFilesL();
|
sl@0
|
636 |
|
sl@0
|
637 |
TheScheduler.Close();
|
sl@0
|
638 |
|
sl@0
|
639 |
//close handle to semaphore
|
sl@0
|
640 |
sem.Close();
|
sl@0
|
641 |
|
sl@0
|
642 |
return KErrNone;
|
sl@0
|
643 |
}
|
sl@0
|
644 |
|
sl@0
|
645 |
//***********************************************************************************
|
sl@0
|
646 |
GLDEF_C TInt E32Main()
|
sl@0
|
647 |
//
|
sl@0
|
648 |
// TheTest the scheduler
|
sl@0
|
649 |
//
|
sl@0
|
650 |
{
|
sl@0
|
651 |
__UHEAP_MARK;
|
sl@0
|
652 |
TheTest.Start(_L("OOM testing"));
|
sl@0
|
653 |
TheTest.Title();
|
sl@0
|
654 |
TheCleanup = CTrapCleanup::New();
|
sl@0
|
655 |
|
sl@0
|
656 |
//If the previous test fails, SCHSVR.exe may stay in memory.
|
sl@0
|
657 |
TRAPD(error,CleanupHelpers::TestCleanupL());
|
sl@0
|
658 |
TEST2(error, KErrNone);
|
sl@0
|
659 |
|
sl@0
|
660 |
TheTest(TheFsSession.Connect() == KErrNone);;
|
sl@0
|
661 |
TRAP(error, RunTestsL());
|
sl@0
|
662 |
TEST2(error,KErrNone);
|
sl@0
|
663 |
TRAP(error,CleanupHelpers::TestCleanupL());
|
sl@0
|
664 |
TEST2(error, KErrNone);
|
sl@0
|
665 |
delete TheCleanup;
|
sl@0
|
666 |
|
sl@0
|
667 |
TheFsSession.Close();
|
sl@0
|
668 |
TheTest.End();
|
sl@0
|
669 |
TheTest.Close();
|
sl@0
|
670 |
__UHEAP_MARKEND;
|
sl@0
|
671 |
return KErrNone;
|
sl@0
|
672 |
}
|