|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include "tgraphicsresourcemultiprocessthread.h" |
|
23 #include <e32debug.h> |
|
24 #include <graphics/sgimage_sw.h> |
|
25 |
|
26 /** |
|
27 Helper function to test the equivalence of two TSgImageInfo structures. |
|
28 |
|
29 @param aInfo1 A TSgImageInfo structure to compare. |
|
30 @param aInfo2 A TSgImageInfo structure to compare. |
|
31 |
|
32 @return ETrue if the two are identical, EFalse otherwise. |
|
33 */ |
|
34 TBool CompareInfos(TSgImageInfo& aInfo1, TSgImageInfo& aInfo2) |
|
35 { |
|
36 TBool result = EFalse; |
|
37 if(aInfo1.iCpuAccess == aInfo2.iCpuAccess |
|
38 && aInfo1.iPixelFormat == aInfo2.iPixelFormat |
|
39 && aInfo1.iScreenId == aInfo2.iScreenId |
|
40 && aInfo1.iShareable == aInfo2.iShareable |
|
41 && aInfo1.iSizeInPixels == aInfo2.iSizeInPixels |
|
42 && aInfo1.iUsage | aInfo2.iUsage |
|
43 && aInfo1.iUserAttributeCount == aInfo2.iUserAttributeCount) |
|
44 { |
|
45 for(TInt i=0; i<aInfo1.iUserAttributeCount; ++i) |
|
46 { |
|
47 if(aInfo1.iUserAttributes[i].iUid != aInfo2.iUserAttributes[i].iUid) |
|
48 { |
|
49 break; |
|
50 } |
|
51 } |
|
52 result = ETrue; |
|
53 } |
|
54 return result; |
|
55 } |
|
56 |
|
57 /** |
|
58 Opens an image in a different process. |
|
59 @param aInfo The test information passed from outside the current thread |
|
60 @return The test result indicating which tests passed |
|
61 */ |
|
62 TInt TestOpenImageL(TSgresTestInfo& aInfo) |
|
63 { |
|
64 TSgDrawableId id = aInfo.iDrawableId; |
|
65 TSgImageInfo imageInfo1 = aInfo.iImageInfo; |
|
66 |
|
67 RSgImage image; |
|
68 TInt result = 0; |
|
69 |
|
70 if(KErrNone == image.Open(id)) |
|
71 { |
|
72 result |= EFirstTestPassed; |
|
73 } |
|
74 |
|
75 TSgImageInfo imageInfo2; |
|
76 if(KErrNone == image.GetInfo(imageInfo2)) |
|
77 { |
|
78 result |= ESecondTestPassed; |
|
79 } |
|
80 if(CompareInfos(imageInfo1, imageInfo2)) |
|
81 { |
|
82 result |= EThirdTestPassed; |
|
83 } |
|
84 if(image.Id() == id) |
|
85 { |
|
86 result |= EFourthTestPassed; |
|
87 } |
|
88 |
|
89 image.Close(); |
|
90 |
|
91 return result; |
|
92 } |
|
93 |
|
94 /** |
|
95 Opens an image in a different process into a RSgDrawable object. |
|
96 @param aInfo The test information passed from outside the current thread |
|
97 @return The test result indicating which tests passed |
|
98 */ |
|
99 TInt TestOpenDrawableL(TSgresTestInfo& aInfo) |
|
100 { |
|
101 TSgDrawableId id = aInfo.iDrawableId; |
|
102 |
|
103 RSgDrawable drawable; |
|
104 TInt result = 0; |
|
105 |
|
106 if(KErrNone == drawable.Open(id)) |
|
107 { |
|
108 result |= EFirstTestPassed; |
|
109 } |
|
110 TSgDrawableId id2 = drawable.Id(); |
|
111 if(id2 != KSgNullDrawableId) |
|
112 { |
|
113 result |= ESecondTestPassed; |
|
114 } |
|
115 if(id2 == id) |
|
116 { |
|
117 result |= EThirdTestPassed; |
|
118 } |
|
119 |
|
120 drawable.Close(); |
|
121 return result; |
|
122 } |
|
123 |
|
124 /** |
|
125 Opens an image in a different process with different invalid operations. |
|
126 @param aInfo The test information passed from outside the current thread |
|
127 @return The test result indicating which tests passed |
|
128 */ |
|
129 TInt TestOpenImageInvalidL(TSgresTestInfo& aInfo) |
|
130 { |
|
131 TSgDrawableId id = aInfo.iDrawableId; |
|
132 TSgImageInfo imageInfo = aInfo.iImageInfo; |
|
133 |
|
134 RSgImage image; |
|
135 TInt result = 0; |
|
136 |
|
137 //create image |
|
138 if(KErrNone == image.Create(imageInfo, NULL, 0)) |
|
139 { |
|
140 result |= EFirstTestPassed; |
|
141 } |
|
142 // non-empty handle |
|
143 if(KErrInUse == image.Open(id)) |
|
144 { |
|
145 result |= ESecondTestPassed; |
|
146 } |
|
147 image.Close(); |
|
148 |
|
149 // null drawable id |
|
150 if(KErrArgument == image.Open(KSgNullDrawableId)) |
|
151 { |
|
152 result |= EThirdTestPassed; |
|
153 } |
|
154 image.Close(); |
|
155 |
|
156 // non-existing drawable id |
|
157 TSgDrawableId fakeid = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF}; |
|
158 if(KErrNotFound == image.Open(fakeid)) |
|
159 { |
|
160 result |= EFourthTestPassed; |
|
161 } |
|
162 image.Close(); |
|
163 |
|
164 // open a non-sharable image |
|
165 TInt openResult = image.Open(id); |
|
166 if(KErrPermissionDenied == openResult || KErrNotFound == openResult) |
|
167 { |
|
168 result |= EFifthTestPassed; |
|
169 } |
|
170 image.Close(); |
|
171 |
|
172 return result; |
|
173 } |
|
174 |
|
175 /** |
|
176 Calls SgDriver::AllocMarkEnd() without closing all the resources. |
|
177 @param aInfo The test information passed from outside the current thread |
|
178 @panic SGRES-ADAPTER 0 |
|
179 @return The test result indicating which tests passed |
|
180 */ |
|
181 TInt TestDriverMemoryLeakL(TSgresTestInfo& /*aInfo*/) |
|
182 { |
|
183 SgDriver::AllocMarkStart(); |
|
184 TSgImageInfo info; |
|
185 info.iSizeInPixels = TSize(8, 8); |
|
186 info.iUsage = ESgUsageDirectGdiSource; |
|
187 info.iPixelFormat = EUidPixelFormatRGB_565; |
|
188 info.iCpuAccess = ESgCpuAccessReadWrite; |
|
189 info.iShareable = EFalse; |
|
190 info.iScreenId = 0; |
|
191 |
|
192 RSgImage image; |
|
193 image.Create(info, NULL, 0); |
|
194 SgDriver::AllocMarkEnd(0); //should panic here |
|
195 image.Close(); |
|
196 return KErrNone; |
|
197 } |
|
198 |
|
199 /** |
|
200 Shuts down the driver when there are still resources open. |
|
201 @param aInfo The test information passed from outside the current thread |
|
202 @panic SGRES 1 |
|
203 @return The test result indicating which tests passed |
|
204 */ |
|
205 TInt TestShutdownMemoryLeakL(TSgresTestInfo& /*aInfo*/) |
|
206 { |
|
207 TSgImageInfo info; |
|
208 info.iSizeInPixels = TSize(8, 8); |
|
209 info.iUsage = ESgUsageDirectGdiSource; |
|
210 info.iPixelFormat = EUidPixelFormatRGB_565; |
|
211 info.iCpuAccess = ESgCpuAccessReadWrite; |
|
212 info.iShareable = EFalse; |
|
213 info.iScreenId = 0; |
|
214 |
|
215 RSgImage image; |
|
216 TInt ret = image.Create(info, NULL, 0); |
|
217 if(KErrNone != ret) |
|
218 { |
|
219 return ret; |
|
220 } |
|
221 SgDriver::Close(); //should panic here |
|
222 return KErrNone; |
|
223 } |
|
224 |
|
225 /** |
|
226 Opens a drawable in a different process with different invalid operations. |
|
227 @param aInfo The test information passed from outside the current thread |
|
228 @return The test result indicating which tests passed |
|
229 */ |
|
230 TInt TestOpenDrawableInvalidL(TSgresTestInfo& aInfo) |
|
231 { |
|
232 TSgDrawableId id = aInfo.iDrawableId; |
|
233 |
|
234 RSgDrawable drawable; |
|
235 TInt result = 0; |
|
236 |
|
237 //null drawable id |
|
238 if(KErrArgument == drawable.Open(KSgNullDrawableId)) |
|
239 { |
|
240 result |= EFirstTestPassed; |
|
241 } |
|
242 drawable.Close(); |
|
243 |
|
244 //non-existing drawable id |
|
245 TSgDrawableId fakeid = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF}; |
|
246 if(KErrNotFound == drawable.Open(fakeid)) |
|
247 { |
|
248 result |= ESecondTestPassed; |
|
249 } |
|
250 drawable.Close(); |
|
251 |
|
252 //open a non-sharable image - should fail |
|
253 TInt openResult = drawable.Open(id); |
|
254 if(KErrPermissionDenied == openResult || KErrNotFound == openResult) |
|
255 { |
|
256 result |= EThirdTestPassed; |
|
257 } |
|
258 drawable.Close(); |
|
259 |
|
260 //non-empty handle |
|
261 //create an image |
|
262 TSgImageInfo info1; |
|
263 info1.iSizeInPixels = TSize(8, 8); |
|
264 info1.iUsage = ESgUsageDirectGdiTarget; |
|
265 info1.iPixelFormat = EUidPixelFormatRGB_565; |
|
266 info1.iCpuAccess = ESgCpuAccessNone; |
|
267 info1.iShareable = ETrue; |
|
268 |
|
269 RSgImage image; |
|
270 TInt err = image.Create(info1, NULL, 0); |
|
271 if(KErrNoMemory == err) |
|
272 { |
|
273 result = KErrNoMemory; |
|
274 } |
|
275 else if(KErrNone != err) |
|
276 { |
|
277 result = err; |
|
278 } |
|
279 else |
|
280 { |
|
281 if(KErrNone == drawable.Open(image.Id())) |
|
282 { |
|
283 result |= EFourthTestPassed; |
|
284 } |
|
285 |
|
286 //handle is non-null now |
|
287 if(KErrInUse == drawable.Open(id)) |
|
288 { |
|
289 result |= EFifthTestPassed; |
|
290 } |
|
291 drawable.Close(); |
|
292 } |
|
293 image.Close(); |
|
294 return result; |
|
295 } |
|
296 |
|
297 /** |
|
298 Maps an image in a different process. |
|
299 The operation should fail. |
|
300 @param aInfo The test information passed from outside the current thread |
|
301 @return The test result indicating which tests passed |
|
302 */ |
|
303 TInt TestMapImageNonOwnerL(TSgresTestInfo& aInfo) |
|
304 { |
|
305 TSgDrawableId id = aInfo.iDrawableId; |
|
306 |
|
307 RSgImage image; |
|
308 const TAny* dataAddressRead; |
|
309 TAny* dataAddressWrite; |
|
310 TInt dataStride; |
|
311 TInt result = 0; |
|
312 |
|
313 if(KErrNone == image.Open(id)) |
|
314 { |
|
315 result |= EFirstTestPassed; |
|
316 } |
|
317 if(KErrPermissionDenied == image.MapReadOnly(dataAddressRead, dataStride)) |
|
318 { |
|
319 result |= ESecondTestPassed; |
|
320 } |
|
321 if(KErrPermissionDenied == image.MapWriteOnly(dataAddressWrite, dataStride)) |
|
322 { |
|
323 result |= EThirdTestPassed; |
|
324 } |
|
325 if(KErrPermissionDenied == image.MapReadWrite(dataAddressWrite, dataStride)) |
|
326 { |
|
327 result |= EFourthTestPassed; |
|
328 } |
|
329 |
|
330 TInt unmapResult = image.Unmap(); |
|
331 if(KErrGeneral == unmapResult || KErrPermissionDenied == unmapResult) |
|
332 { |
|
333 result |= EFifthTestPassed; |
|
334 } |
|
335 |
|
336 image.Close(); |
|
337 return result; |
|
338 } |
|
339 |
|
340 /** |
|
341 Unmaps an image in another process. |
|
342 @param aInfo The test information passed from outside the current thread |
|
343 @return The test result indicating which tests passed |
|
344 */ |
|
345 TInt TestUnmapImageL(TSgresTestInfo& aInfo) |
|
346 { |
|
347 TSgDrawableId id = aInfo.iDrawableId; |
|
348 |
|
349 RSgImage image; |
|
350 TInt result = 0; |
|
351 |
|
352 if(KErrNone == image.Open(id)) |
|
353 { |
|
354 result |= EFirstTestPassed; |
|
355 } |
|
356 if(KErrGeneral == image.Unmap()) |
|
357 { |
|
358 result |= ESecondTestPassed; |
|
359 } |
|
360 image.Close(); |
|
361 return result; |
|
362 } |
|
363 |
|
364 // Real main function |
|
365 TInt MainL() |
|
366 { |
|
367 TInt procHandles1 =0; |
|
368 TInt threadHandles1=0; |
|
369 RThread().HandleCount(procHandles1, threadHandles1); |
|
370 |
|
371 TPckgBuf<TSgresTestInfo> infoPkg; |
|
372 User::LeaveIfError(User::GetDesParameter(KSecondProcessParametersSlot, infoPkg)); |
|
373 TSgresTestInfo& info = infoPkg(); |
|
374 TSgresTestCase testCase = info.iTestCase; |
|
375 TInt result = 0; |
|
376 |
|
377 if(KErrNone == SgDriver::Open()) |
|
378 { |
|
379 switch(testCase) |
|
380 { |
|
381 case ESgresSecondProcessOpenImage: |
|
382 result = TestOpenImageL(info); |
|
383 break; |
|
384 case ESgresSecondProcessOpenDrawable: |
|
385 result = TestOpenDrawableL(info); |
|
386 break; |
|
387 case ESgresSecondProcessOpenImageInvalid: |
|
388 result = TestOpenImageInvalidL(info); |
|
389 break; |
|
390 case ESgresSecondProcessOpenDrawableInvalid: |
|
391 result = TestOpenDrawableInvalidL(info); |
|
392 break; |
|
393 case ESgresSecondProcessMapImage: |
|
394 result = TestMapImageNonOwnerL(info); |
|
395 break; |
|
396 case ESgresSecondProcessUnmapImage: |
|
397 result = TestUnmapImageL(info); |
|
398 break; |
|
399 case ESgresSecondProcessPanicDriverUnclosedResources: |
|
400 result = TestShutdownMemoryLeakL(info); |
|
401 break; |
|
402 case ESgresSecondProcessPanicMemoryLeak: |
|
403 result = TestDriverMemoryLeakL(info); |
|
404 break; |
|
405 } |
|
406 } |
|
407 |
|
408 SgDriver::Close(); |
|
409 |
|
410 // Handle check |
|
411 TInt procHandles2 =0; |
|
412 TInt threadHandles2=0; |
|
413 RThread().HandleCount(procHandles2,threadHandles2); |
|
414 if (threadHandles1 != threadHandles2) |
|
415 { |
|
416 result = KErrBadHandle; // Thread-owned handles not closed |
|
417 } |
|
418 |
|
419 return result; |
|
420 } |
|
421 |
|
422 GLDEF_C TInt E32Main() |
|
423 { |
|
424 __UHEAP_MARK; |
|
425 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
426 if(cleanupStack == NULL) |
|
427 { |
|
428 return KErrNoMemory; |
|
429 } |
|
430 TInt ret = 0; |
|
431 TRAP_IGNORE(ret=MainL()); |
|
432 delete cleanupStack; |
|
433 __UHEAP_MARKEND; |
|
434 return ret; |
|
435 } |