|
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 - Graphics Resource API Conformance Test Suite |
|
20 */ |
|
21 |
|
22 #include <e32debug.h> |
|
23 #include "tgraphicsresourcemultiprocessthread.h" |
|
24 #include "tgraphicsresourceteststepbase.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.iPixelFormat == aInfo2.iPixelFormat |
|
38 && aInfo1.iSizeInPixels == aInfo2.iSizeInPixels |
|
39 && aInfo1.iUsage | aInfo2.iUsage) |
|
40 { |
|
41 result = ETrue; |
|
42 } |
|
43 return result; |
|
44 } |
|
45 |
|
46 /** |
|
47 Opens an image in a different process. |
|
48 @param aInfo The test information passed from outside the current thread |
|
49 @return The test result indicating which tests passed |
|
50 */ |
|
51 TInt TestOpenImageL(TSgProcessTestInfo& aInfo) |
|
52 { |
|
53 TSgDrawableId id = aInfo.iDrawableId; |
|
54 TSgImageInfo imageInfo1 = aInfo.iImageInfo; |
|
55 |
|
56 RSgImage image; |
|
57 TInt result = 0; |
|
58 |
|
59 if(KErrNone == image.Open(id)) |
|
60 { |
|
61 result |= EFirstTestPassed; |
|
62 } |
|
63 |
|
64 TSgImageInfo imageInfo2; |
|
65 TInt attribVal = KMaxTInt; |
|
66 if(KErrNone == image.GetInfo(imageInfo2)) |
|
67 { |
|
68 result |= ESecondTestPassed; |
|
69 } |
|
70 if(CompareInfos(imageInfo1, imageInfo2)) |
|
71 { |
|
72 result |= EThirdTestPassed; |
|
73 } |
|
74 if (image.Id() != KSgNullDrawableId) |
|
75 { |
|
76 result |= EFourthTestPassed; |
|
77 } |
|
78 if(image.Id() == id) |
|
79 { |
|
80 result |= EFifthTestPassed; |
|
81 } |
|
82 if (id == aInfo.iDrawableId) |
|
83 { |
|
84 result |= ESixthTestPassed; |
|
85 } |
|
86 TUid uid = { 0x12345678 }; |
|
87 if (KErrNotSupported == image.GetAttribute(uid, attribVal)) |
|
88 { |
|
89 result |= ESeventhTestPassed; |
|
90 } |
|
91 if (KErrArgument == image.GetAttribute(KNullUid, attribVal)) |
|
92 { |
|
93 result |= EEighthTestPassed; |
|
94 } |
|
95 image.Close(); |
|
96 |
|
97 return result; |
|
98 } |
|
99 |
|
100 /** |
|
101 Opens an image in a different process into a RSgDrawable object. |
|
102 @param aInfo The test information passed from outside the current thread |
|
103 @return The test result indicating which tests passed |
|
104 */ |
|
105 TInt TestOpenDrawableL(TSgProcessTestInfo& aInfo) |
|
106 { |
|
107 TSgDrawableId id = aInfo.iDrawableId; |
|
108 |
|
109 RSgDrawable drawable; |
|
110 TInt result = 0; |
|
111 |
|
112 if(KErrNone == drawable.Open(id)) |
|
113 { |
|
114 result |= EFirstTestPassed; |
|
115 } |
|
116 TSgDrawableId id2 = drawable.Id(); |
|
117 if(id2 != KSgNullDrawableId) |
|
118 { |
|
119 result |= ESecondTestPassed; |
|
120 } |
|
121 if(id2 == id) |
|
122 { |
|
123 result |= EThirdTestPassed; |
|
124 } |
|
125 |
|
126 drawable.Close(); |
|
127 return result; |
|
128 } |
|
129 |
|
130 /** |
|
131 Opens an image in a different process with different invalid operations. |
|
132 @param aInfo The test information passed from outside the current thread |
|
133 @return The test result indicating which tests passed |
|
134 */ |
|
135 TInt TestOpenImageInvalidL(TSgProcessTestInfo& aInfo) |
|
136 { |
|
137 TSgDrawableId id = aInfo.iDrawableId; |
|
138 TSgImageInfo imageInfo = aInfo.iImageInfo; |
|
139 |
|
140 RSgImage image; |
|
141 TInt result = 0; |
|
142 |
|
143 //create image |
|
144 if(KErrNone == image.Create(imageInfo, NULL, 0)) |
|
145 { |
|
146 result |= EFirstTestPassed; |
|
147 } |
|
148 // non-empty handle |
|
149 if(KErrInUse == image.Open(id)) |
|
150 { |
|
151 result |= ESecondTestPassed; |
|
152 } |
|
153 image.Close(); |
|
154 |
|
155 // null drawable id |
|
156 if(KErrArgument == image.Open(KSgNullDrawableId)) |
|
157 { |
|
158 result |= EThirdTestPassed; |
|
159 } |
|
160 image.Close(); |
|
161 |
|
162 // non-existing drawable id |
|
163 TSgDrawableId fakeid = {0xFFFFFFFFFFFFFFFFU}; |
|
164 if(KErrNotFound == image.Open(fakeid)) |
|
165 { |
|
166 result |= EFourthTestPassed; |
|
167 } |
|
168 image.Close(); |
|
169 |
|
170 //Valid Drawable Id |
|
171 if (KErrNone == image.Open(id)) |
|
172 { |
|
173 result |= EFifthTestPassed; |
|
174 } |
|
175 image.Close(); |
|
176 return result; |
|
177 } |
|
178 |
|
179 /** |
|
180 Opens a drawable in a different process with different invalid operations. |
|
181 @param aInfo The test information passed from outside the current thread |
|
182 @return The test result indicating which tests passed |
|
183 */ |
|
184 TInt TestOpenDrawableInvalidL() |
|
185 { |
|
186 RSgDrawable drawable; |
|
187 TInt result = 0; |
|
188 |
|
189 //null drawable id |
|
190 if(KErrArgument == drawable.Open(KSgNullDrawableId)) |
|
191 { |
|
192 result |= EFirstTestPassed; |
|
193 } |
|
194 drawable.Close(); |
|
195 |
|
196 //non-existing drawable id |
|
197 TSgDrawableId fakeid = {0xFFFFFFFFFFFFFFFFU}; |
|
198 if(KErrNotFound == drawable.Open(fakeid)) |
|
199 { |
|
200 result |= ESecondTestPassed; |
|
201 } |
|
202 drawable.Close(); |
|
203 |
|
204 //non-empty handle |
|
205 //create an image |
|
206 TSgImageInfo info1; |
|
207 info1.iSizeInPixels = TSize(8, 8); |
|
208 info1.iUsage = ESgUsageBitOpenVgImage; |
|
209 info1.iPixelFormat = EUidPixelFormatRGB_565; |
|
210 |
|
211 |
|
212 RSgImage image; |
|
213 TInt err = image.Create(info1, NULL, 0); |
|
214 if(KErrNoMemory == err) |
|
215 { |
|
216 result = KErrNoMemory; |
|
217 } |
|
218 else if(KErrNone != err) |
|
219 { |
|
220 result = err; |
|
221 } |
|
222 else |
|
223 { |
|
224 if(KErrNone == drawable.Open(image.Id())) |
|
225 { |
|
226 result |= EThirdTestPassed; |
|
227 |
|
228 if (KErrInUse == drawable.Open(image.Id())) |
|
229 { |
|
230 result |= EFourthTestPassed; |
|
231 } |
|
232 } |
|
233 drawable.Close(); |
|
234 } |
|
235 image.Close(); |
|
236 return result; |
|
237 } |
|
238 |
|
239 TInt TestCloseDriverOpenResources(RSgDriver& aDriver) |
|
240 { |
|
241 RSgImage image; |
|
242 TSgImageInfo info1; |
|
243 info1.iSizeInPixels = TSize(8, 8); |
|
244 info1.iUsage = ESgUsageBitOpenVgImage; |
|
245 info1.iPixelFormat = EUidPixelFormatRGB_565; |
|
246 |
|
247 TInt result = image.Create(info1, KCrossImageData, KCrossImageDataStride); |
|
248 |
|
249 if (result == KErrNone) |
|
250 { |
|
251 //Close the driver without closing the image. |
|
252 aDriver.Close(); //Should panic with SGRES2 |
|
253 } |
|
254 |
|
255 return result; |
|
256 } |
|
257 |
|
258 /** |
|
259 Method executed by secondary thread for test TestOpenImageMulththreadedL |
|
260 */ |
|
261 _LIT(KTestOpenImageMultithreadedSem1, "TestOpenImageMulththreadedSem1"); |
|
262 _LIT(KTestOpenImageMultithreadedSem2, "TestOpenImageMulththreadedSem2"); |
|
263 |
|
264 TInt OpenImageMultiSecondThread(TAny* aAny) |
|
265 { |
|
266 TInt err = KErrNone; |
|
267 TSgProcessTestInfo* info = static_cast<TSgProcessTestInfo*>(aAny); |
|
268 |
|
269 RSemaphore sem[2]; |
|
270 err = sem[0].OpenGlobal(KTestOpenImageMultithreadedSem1, EOwnerThread); |
|
271 if (err != KErrNone) |
|
272 { |
|
273 return err; |
|
274 } |
|
275 err = sem[1].OpenGlobal(KTestOpenImageMultithreadedSem2, EOwnerThread); |
|
276 if (err != KErrNone) |
|
277 { |
|
278 sem[0].Close(); |
|
279 return err; |
|
280 } |
|
281 |
|
282 RSgImage sgImage; |
|
283 err = sgImage.Open(info->iDrawableId); |
|
284 |
|
285 sem[0].Signal(); |
|
286 sem[1].Wait(); |
|
287 |
|
288 sgImage.Close(); |
|
289 sem[0].Signal(); |
|
290 return err; |
|
291 } |
|
292 |
|
293 /** |
|
294 Creates a second thread which will initially open a handle to the passed TSgDrawableId. |
|
295 The main thread then opens a new handle to the image. |
|
296 The second thread will then close its handle to the image. |
|
297 The main thread will then attempt to access the data of the image. |
|
298 */ |
|
299 TInt TestOpenImageMulththreadedL(TSgProcessTestInfo& aInfo) |
|
300 { |
|
301 TInt result = 0; |
|
302 |
|
303 //create a semaphore |
|
304 RSemaphore sem[2]; |
|
305 User::LeaveIfError(sem[0].CreateGlobal(KTestOpenImageMultithreadedSem1, 0, EOwnerThread)); |
|
306 CleanupClosePushL(sem[0]); |
|
307 User::LeaveIfError(sem[1].CreateGlobal(KTestOpenImageMultithreadedSem2, 0, EOwnerThread)); |
|
308 CleanupClosePushL(sem[1]); |
|
309 |
|
310 //create secondary thread |
|
311 _LIT(KMultipleThreadName, "TestOpenImageMulththreadedL"); |
|
312 RThread thread; |
|
313 TBuf<50> threadName(KMultipleThreadName); |
|
314 User::LeaveIfError(thread.Create(threadName, OpenImageMultiSecondThread, KDefaultStackSize, KSecondThreadMinHeapSize, KSecondThreadMaxHeapSize, &aInfo)); |
|
315 thread.Resume(); |
|
316 |
|
317 // Make the second thread open the image before this thread. |
|
318 sem[0].Wait(); |
|
319 |
|
320 // Second thread has opened image, now primary thread opens image |
|
321 RSgImage sgImage; |
|
322 TInt err = sgImage.Open(aInfo.iDrawableId); |
|
323 CleanupClosePushL(sgImage); |
|
324 sem[1].Signal(); |
|
325 sem[0].Wait(); |
|
326 |
|
327 // Second thread has closed image and terminated, now wait for thread to clean-up |
|
328 User::After(100000); |
|
329 |
|
330 if (err == KErrNone) |
|
331 { |
|
332 // Do something that requires data access of sgImage, in this case, creating a copy. |
|
333 result |= EFirstTestPassed; |
|
334 RSgImage sgImageCopy; |
|
335 err = sgImageCopy.Create(aInfo.iImageInfo, sgImage); |
|
336 sgImageCopy.Close(); |
|
337 if (err == KErrNone) |
|
338 { |
|
339 result |= ESecondTestPassed; |
|
340 } |
|
341 } |
|
342 |
|
343 CleanupStack::PopAndDestroy(3); // sgImage, sem[0], sem[1] |
|
344 return result; |
|
345 } |
|
346 |
|
347 TInt MainL() |
|
348 { |
|
349 TPckgBuf<TSgProcessTestInfo> infoPkg; |
|
350 User::LeaveIfError(User::GetDesParameter(KSecondProcessParametersSlot, infoPkg)); |
|
351 TSgProcessTestInfo& info = infoPkg(); |
|
352 TSgresTestCase testCase = info.iTestCase; |
|
353 TInt result = 0; |
|
354 |
|
355 RSgDriver sgDriver; |
|
356 CleanupClosePushL(sgDriver); |
|
357 |
|
358 if(KErrNone == sgDriver.Open()) |
|
359 { |
|
360 switch(testCase) |
|
361 { |
|
362 case ESgresSecondProcessOpenImage: |
|
363 result = TestOpenImageL(info); |
|
364 break; |
|
365 case ESgresSecondProcessOpenDrawable: |
|
366 result = TestOpenDrawableL(info); |
|
367 break; |
|
368 case ESgresSecondProcessOpenImageInvalid: |
|
369 result = TestOpenImageInvalidL(info); |
|
370 break; |
|
371 case ESgresSecondProcessOpenDrawableInvalid: |
|
372 result = TestOpenDrawableInvalidL(); |
|
373 break; |
|
374 case ESgresSecondProcessPanicDriverCloseOpenResources: |
|
375 result = TestCloseDriverOpenResources(sgDriver); |
|
376 break; |
|
377 case ESgresSecondProcessOpenImageMultithreaded: |
|
378 result = TestOpenImageMulththreadedL(info); |
|
379 break; |
|
380 } |
|
381 } |
|
382 |
|
383 CleanupStack::PopAndDestroy(&sgDriver); |
|
384 |
|
385 return result; |
|
386 } |
|
387 |
|
388 GLDEF_C TInt E32Main() |
|
389 { |
|
390 __UHEAP_MARK; |
|
391 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
392 if(cleanupStack == NULL) |
|
393 { |
|
394 return KErrNoMemory; |
|
395 } |
|
396 TInt ret = 0; |
|
397 TRAP_IGNORE(ret=MainL()); |
|
398 delete cleanupStack; |
|
399 __UHEAP_MARKEND; |
|
400 return ret; |
|
401 } |