|
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 // Surface manager multi-processed test code |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @test |
|
21 @internalComponent - Internal Symbian test code |
|
22 */ |
|
23 |
|
24 #include <e32base.h> |
|
25 #include <e32cons.h> |
|
26 #include <e32test.h> |
|
27 #include <e32std.h> |
|
28 #include <e32debug.h> |
|
29 #include <e32def_private.h> |
|
30 #include <graphics/surface.h> |
|
31 #include <graphics/surfacemanager.h> |
|
32 #include "tsmgmultprocessshared.h" |
|
33 |
|
34 LOCAL_D RTest test(_L("TReceiveSurface")); |
|
35 |
|
36 |
|
37 class CTestDriverSecondProcess : public CTestDriver |
|
38 { |
|
39 public: |
|
40 CTestDriverSecondProcess(); |
|
41 ~CTestDriverSecondProcess(); |
|
42 void ConstructL(); |
|
43 static CTestDriverSecondProcess* NewL(); |
|
44 public: |
|
45 void TestMultipleChannelsInSecondProcess2(); |
|
46 void TestMultipleChannelsInSecondProcess1(); |
|
47 void TestCheckSyncOperation(); |
|
48 void TestCheckHandleInSecondProcess(); |
|
49 void TestSurfaceInfoUsingSurfaceId(); |
|
50 void TestOpeningSurfaceUsingSurfaceId(); |
|
51 void TestOpeningSurfaceInvalidParams(); |
|
52 void OpenWaitMap(); |
|
53 void CreateWaitKill(); |
|
54 void OpenClose(); |
|
55 void MapSurfaceInfoCantAccess(); |
|
56 void TestReadFromBufferInSecondProcess(); |
|
57 void TestGetSurfaceHint(); |
|
58 void TestSetSurfaceHint(); |
|
59 void TestAddSurfaceHint(); |
|
60 void TestOutofMemory(); |
|
61 private: |
|
62 RSurfaceManager iSurfaceManagerTwo; |
|
63 }; |
|
64 |
|
65 CTestDriverSecondProcess::CTestDriverSecondProcess():CTestDriver() |
|
66 { |
|
67 } |
|
68 |
|
69 CTestDriverSecondProcess::~CTestDriverSecondProcess() |
|
70 { |
|
71 iSurfaceManagerTwo.Close(); |
|
72 } |
|
73 |
|
74 void CTestDriverSecondProcess::ConstructL() |
|
75 { |
|
76 CTestDriver::ConstructL(); |
|
77 User::LeaveIfError( iSurfaceManagerTwo.Open()); |
|
78 } |
|
79 |
|
80 CTestDriverSecondProcess* CTestDriverSecondProcess::NewL() |
|
81 { |
|
82 CTestDriverSecondProcess * driver = new (ELeave) CTestDriverSecondProcess(); |
|
83 CleanupStack::PushL(driver); |
|
84 driver->ConstructL(); |
|
85 CleanupStack::Pop(driver); |
|
86 return driver; |
|
87 } |
|
88 |
|
89 void CTestDriverSecondProcess::TestMultipleChannelsInSecondProcess2() |
|
90 { |
|
91 // Store the attributes used to create the Surface |
|
92 RSurfaceManager::TSurfaceCreationAttributesBuf buf; |
|
93 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf(); |
|
94 attributes.iSize = TSize(280,301); |
|
95 attributes.iBuffers = 1; |
|
96 attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar; // 2bpp |
|
97 attributes.iStride = 1; |
|
98 attributes.iOffsetToFirstBuffer = 1; |
|
99 attributes.iAlignment = 1; |
|
100 |
|
101 RSurfaceManager::THintPair hints[2]; // two hint pairs specified |
|
102 attributes.iHintCount = 2; |
|
103 attributes.iSurfaceHints = hints; |
|
104 hints[0].Set(TUid::Uid(0x124578), 25, ETrue); |
|
105 hints[1].Set(TUid::Uid(0x237755), 50, ETrue); |
|
106 |
|
107 attributes.iContiguous = ETrue; |
|
108 attributes.iCacheAttrib = RSurfaceManager::ECached; |
|
109 attributes.iOffsetBetweenBuffers = 0; |
|
110 attributes.iMappable = ETrue; |
|
111 |
|
112 // Create the surface |
|
113 TSurfaceId surfaceIdOne; |
|
114 if(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceIdOne)) |
|
115 { |
|
116 iTestResult |= EFirstTestPassed; |
|
117 } |
|
118 |
|
119 // Create the surface |
|
120 TSurfaceId surfaceIdTwo; |
|
121 if(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceIdTwo)) |
|
122 { |
|
123 iTestResult |= ESecondTestPassed; |
|
124 } |
|
125 |
|
126 if(KErrNone == iSurfaceManager.OpenSurface(surfaceIdTwo)) |
|
127 { |
|
128 iTestResult |= EThirdTestPassed; |
|
129 } |
|
130 |
|
131 if(KErrNone == iSurfaceManagerTwo.OpenSurface(surfaceIdOne)) |
|
132 { |
|
133 iTestResult |= EFourthTestPassed; |
|
134 } |
|
135 |
|
136 // Set the results so they can be read and tested by the first process |
|
137 iChunkWrapper->SetSecondProcessResults(iTestResult); |
|
138 // Put the surfaceId onto the shared chunk |
|
139 iChunkWrapper->SetId(surfaceIdOne); |
|
140 |
|
141 |
|
142 // Pass control back to the first process |
|
143 RSemaphore sem; |
|
144 if(KErrNone == sem.OpenGlobal(KMultiProcessSemaphore)) |
|
145 { |
|
146 iTestResult |= EThirdTestPassed; |
|
147 } |
|
148 |
|
149 sem.Signal(); |
|
150 |
|
151 RSemaphore sem2; |
|
152 if(KErrNone == sem2.OpenGlobal(KMultiProcessSemaphore2)) |
|
153 { |
|
154 iTestResult |= EFourthTestPassed; |
|
155 } |
|
156 sem2.Wait(); |
|
157 |
|
158 // Set the results so they can be read and tested by the first process |
|
159 iChunkWrapper->SetSecondProcessResults(iTestResult); |
|
160 // // Put the surfaceId onto the shared chunk |
|
161 iChunkWrapper->SetId(surfaceIdTwo); |
|
162 |
|
163 sem.Close(); |
|
164 sem2.Close(); |
|
165 } |
|
166 |
|
167 void CTestDriverSecondProcess::TestMultipleChannelsInSecondProcess1() |
|
168 { |
|
169 // Open the chunk wrapper and get the surfaceId |
|
170 TSurfaceId surfaceIdOne = iChunkWrapper->GetId(); |
|
171 |
|
172 // Open the surface using the surfaceId - check that it returns KErrNone |
|
173 if(KErrNone == iSurfaceManager.OpenSurface(surfaceIdOne)) |
|
174 { |
|
175 iTestResult |= EFirstTestPassed; |
|
176 } |
|
177 |
|
178 // Pass control back to the first process |
|
179 RSemaphore sem; |
|
180 if(KErrNone == sem.OpenGlobal(KMultiProcessSemaphore)) |
|
181 { |
|
182 iTestResult |= ESecondTestPassed; |
|
183 } |
|
184 |
|
185 RSemaphore sem2; |
|
186 if(KErrNone == sem2.OpenGlobal(KMultiProcessSemaphore2)) |
|
187 { |
|
188 iTestResult |= EThirdTestPassed; |
|
189 } |
|
190 |
|
191 // Set the results so they can be read and tested by the first process |
|
192 iChunkWrapper->SetSecondProcessResults(iTestResult); |
|
193 |
|
194 sem.Signal(); |
|
195 sem2.Wait(); |
|
196 |
|
197 // Get the surface info |
|
198 RSurfaceManager::TInfoBuf infoBuf; |
|
199 if(KErrNone == iSurfaceManager.SurfaceInfo(surfaceIdOne, infoBuf)) |
|
200 { |
|
201 iTestResult |= EFourthTestPassed; |
|
202 } |
|
203 TSurfaceId surfaceIdTwo = iChunkWrapper->GetId(); |
|
204 |
|
205 if(KErrArgument == iSurfaceManager.SurfaceInfo(surfaceIdTwo, infoBuf)) |
|
206 { |
|
207 iTestResult |= EFifthTestPassed; |
|
208 } |
|
209 // Set the results so they can be read and tested by the first process |
|
210 iChunkWrapper->SetSecondProcessResults(iTestResult); |
|
211 |
|
212 sem.Close(); |
|
213 sem2.Close(); |
|
214 } |
|
215 |
|
216 void CTestDriverSecondProcess::TestCheckSyncOperation() |
|
217 { |
|
218 // Open the chunk wrapper and get the surfaceId |
|
219 TSurfaceId surfaceId = iChunkWrapper->GetId(); |
|
220 |
|
221 // Check it returns KErrAccessDenied when the surface is not Open |
|
222 TInt bufferNo = 1; |
|
223 |
|
224 RSurfaceManager::TSyncOperation syncOperation = RSurfaceManager::ESyncBeforeNonCPURead; |
|
225 |
|
226 if(KErrAccessDenied == iSurfaceManager.SynchronizeCache(surfaceId, bufferNo,syncOperation)) |
|
227 { |
|
228 iTestResult |= EFirstTestPassed; |
|
229 } |
|
230 |
|
231 // Open the surface using the surfaceId - check that it returns KErrNone |
|
232 if(KErrNone == iSurfaceManager.OpenSurface(surfaceId)) |
|
233 { |
|
234 iTestResult |= ESecondTestPassed; |
|
235 } |
|
236 |
|
237 // Map the surface |
|
238 RChunk handle; |
|
239 |
|
240 if(KErrNone == iSurfaceManager.MapSurface(surfaceId, handle)) |
|
241 { |
|
242 iTestResult |= EThirdTestPassed; |
|
243 } |
|
244 |
|
245 if(KErrNone == iSurfaceManager.SynchronizeCache(surfaceId, bufferNo,syncOperation)) |
|
246 { |
|
247 iTestResult |= EFourthTestPassed; |
|
248 } |
|
249 // Set the results so they can be read and tested by the first process |
|
250 iChunkWrapper->SetSecondProcessResults(iTestResult); |
|
251 // Close the chunkwrapper, handle and the surface manager |
|
252 handle.Close(); |
|
253 |
|
254 } |
|
255 void CTestDriverSecondProcess::TestCheckHandleInSecondProcess() |
|
256 { |
|
257 // Open the chunk wrapper and get the surfaceId |
|
258 TSurfaceId surfaceId = iChunkWrapper->GetId(); |
|
259 |
|
260 // Open the surface using the surfaceId - check that it returns KErrNone |
|
261 if(KErrNone == iSurfaceManager.OpenSurface(surfaceId)) |
|
262 { |
|
263 iTestResult |= EFirstTestPassed; |
|
264 } |
|
265 |
|
266 // Map the surface |
|
267 RChunk handle; |
|
268 |
|
269 if(KErrNone == iSurfaceManager.MapSurface(surfaceId, handle)) |
|
270 { |
|
271 iTestResult |= ESecondTestPassed; |
|
272 } |
|
273 |
|
274 // Get the surface info |
|
275 RSurfaceManager::TInfoBuf infoBuf; |
|
276 if(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf)) |
|
277 { |
|
278 iTestResult |= EThirdTestPassed; |
|
279 } |
|
280 RSurfaceManager::TSurfaceInfoV01& info = infoBuf(); |
|
281 // Get the adress of this chunk of memory |
|
282 TUint8* surfaceAdd = handle.Base(); |
|
283 TInt offsetToFirstBuffer; |
|
284 if(KErrNone == iSurfaceManager.GetBufferOffset(surfaceId, 0, offsetToFirstBuffer)) |
|
285 { |
|
286 iTestResult |= EFourthTestPassed; |
|
287 } |
|
288 TUint8* bufferAdd = surfaceAdd + offsetToFirstBuffer; |
|
289 |
|
290 // Write to the first buffer, and test the value is written |
|
291 *bufferAdd = 20; |
|
292 // Set the results so they can be read and tested by the first process |
|
293 iChunkWrapper->SetSecondProcessResults(iTestResult); |
|
294 |
|
295 // Close the chunkwrapper, handle and the surface manager |
|
296 handle.Close(); |
|
297 } |
|
298 |
|
299 /** |
|
300 Test 18. Receiving a surface and querying SurfaceInfo for surface properties |
|
301 |
|
302 Process 1: Create the Surface |
|
303 Process 2: Receive the Surface Id |
|
304 Process 2: Receive the attributes used to create the surface |
|
305 Process 2: Open the surface using the id |
|
306 Process 2: Map the surface |
|
307 Process 2: Call SurfaceInfo to get the attributes of the Surface |
|
308 Check if these are equal to the ones received. |
|
309 |
|
310 @see TestSurfaceInfoUsingSurfaceIdL() in tsurfacemanager.cpp |
|
311 */ |
|
312 void CTestDriverSecondProcess::TestSurfaceInfoUsingSurfaceId() |
|
313 { |
|
314 // Set attributes for the surface - these are expected attributes in the second process |
|
315 RSurfaceManager::TSurfaceCreationAttributesBuf buf; |
|
316 RSurfaceManager::TSurfaceCreationAttributes& attributes=buf(); |
|
317 attributes.iSize = TSize(200,200); |
|
318 attributes.iBuffers = 1; |
|
319 attributes.iPixelFormat = EUidPixelFormatARGB_1555; |
|
320 attributes.iStride = 415; |
|
321 attributes.iOffsetToFirstBuffer = 80; |
|
322 attributes.iAlignment = 8; |
|
323 attributes.iContiguous=ETrue; |
|
324 |
|
325 RSurfaceManager::THintPair hints[2]; // two hint pairs specified |
|
326 attributes.iHintCount = 2; |
|
327 attributes.iSurfaceHints = hints; |
|
328 hints[0].Set(TUid::Uid(0x124545), 50, EFalse); |
|
329 hints[1].Set(TUid::Uid(0x237755), 50, EFalse); |
|
330 |
|
331 attributes.iOffsetBetweenBuffers = 0; |
|
332 attributes.iCacheAttrib = RSurfaceManager::ENotCached; |
|
333 attributes.iMappable = ETrue; |
|
334 |
|
335 TSurfaceId surfaceId = iChunkWrapper->GetId(); |
|
336 |
|
337 // Open the surface using the surfaceId - check that it returns KErrNone |
|
338 if(KErrNone == iSurfaceManager.OpenSurface(surfaceId)) |
|
339 { |
|
340 iTestResult |= EFirstTestPassed; |
|
341 } |
|
342 |
|
343 // Map the surface |
|
344 RChunk handle; |
|
345 |
|
346 if(KErrNone == iSurfaceManager.MapSurface(surfaceId, handle)) |
|
347 { |
|
348 iTestResult |= ESecondTestPassed; |
|
349 } |
|
350 |
|
351 // Get the surface info |
|
352 RSurfaceManager::TInfoBuf infoBuf; |
|
353 if(KErrNone == iSurfaceManager.SurfaceInfo(surfaceId, infoBuf)) |
|
354 { |
|
355 iTestResult |= EThirdTestPassed; |
|
356 } |
|
357 RSurfaceManager::TSurfaceInfoV01& info = infoBuf(); |
|
358 TInt offsetToFirstBuffer; |
|
359 if(KErrNone == iSurfaceManager.GetBufferOffset(surfaceId, 0, offsetToFirstBuffer)) |
|
360 { |
|
361 iTestResult |= EFourthTestPassed; |
|
362 } |
|
363 |
|
364 if(info.iSize == attributes.iSize) |
|
365 { |
|
366 iTestResult |= EFifthTestPassed; |
|
367 } |
|
368 if(info.iBuffers == attributes.iBuffers) |
|
369 { |
|
370 iTestResult |= ESixthTestPassed; |
|
371 } |
|
372 if(info.iPixelFormat == attributes.iPixelFormat) |
|
373 { |
|
374 iTestResult |= ESeventhTestPassed; |
|
375 } |
|
376 if(info.iStride == attributes.iStride) |
|
377 { |
|
378 iTestResult |= EEighthTestPassed; |
|
379 } |
|
380 if(offsetToFirstBuffer >= attributes.iOffsetToFirstBuffer) |
|
381 { |
|
382 iTestResult |= ENinthTestPassed; |
|
383 } |
|
384 if(info.iContiguous == attributes.iContiguous) |
|
385 { |
|
386 iTestResult |= ETenthTestPassed; |
|
387 } |
|
388 |
|
389 // Set the results so they can be read and tested by the first process |
|
390 iChunkWrapper->SetSecondProcessResults(iTestResult); |
|
391 |
|
392 // Close handle |
|
393 handle.Close(); |
|
394 } |
|
395 |
|
396 /** |
|
397 Test 19. Opening a surface using surfaceId |
|
398 |
|
399 Priocess 1: Create the surface |
|
400 Process 2: Receive the Surface id |
|
401 Process 2: Open the Surface using the stored Surface id |
|
402 Check OpenSurface returns KErrNone |
|
403 |
|
404 @see TestOpeningSurfaceUsingSurfaceIdL() in tsurfacemanager.cpp |
|
405 */ |
|
406 void CTestDriverSecondProcess::TestOpeningSurfaceUsingSurfaceId() |
|
407 { |
|
408 // Open the chunk wrapper and get the surfaceId |
|
409 // CChunkWrapper* chunkWrapper = CChunkWrapper::OpenL(KSharedChunkName, ETrue); |
|
410 TSurfaceId surfaceId = iChunkWrapper->GetId(); |
|
411 |
|
412 // Open the surface using the surfaceId - check that it returns KErrNone |
|
413 if(KErrNone == iSurfaceManager.OpenSurface(surfaceId)) |
|
414 { |
|
415 iTestResult |= EFirstTestPassed; |
|
416 } |
|
417 |
|
418 // Set the results so they can be read and tested by the first process |
|
419 iChunkWrapper->SetSecondProcessResults(iTestResult); |
|
420 |
|
421 } |
|
422 |
|
423 /** |
|
424 Test 20. Opening a surface using invalid surfaceId |
|
425 |
|
426 Process 1:Create the surface |
|
427 Process 2: Receive a Surface Id |
|
428 Change Surface Id by |
|
429 1. adding 500 to the SurfaceId |
|
430 2. making the Surface ID negative |
|
431 3. converting the type of the Surface ID to EInvalidSurface |
|
432 Process 2: Call OpenSurface using the new SurfaceId |
|
433 Check that the return value of OpenSurface is KErrArgument |
|
434 |
|
435 @see TestOpenSurfaceInvalidParams() in tsurfacemanager.cpp |
|
436 */ |
|
437 void CTestDriverSecondProcess::TestOpeningSurfaceInvalidParams() |
|
438 { |
|
439 |
|
440 TSurfaceId surfaceId = iChunkWrapper->GetId(); |
|
441 |
|
442 // Open Surface using the right Id |
|
443 if(KErrNone == iSurfaceManager.OpenSurface(surfaceId)) |
|
444 { |
|
445 iTestResult |= EFirstTestPassed; |
|
446 } |
|
447 // Open the surface using the invalid surfaceId - check that it returns KErrArgument |
|
448 TSurfaceId invalidSurfaceId = surfaceId; |
|
449 //Add 500 to the first field of surfaceId |
|
450 invalidSurfaceId.iInternal[0] = surfaceId.iInternal[0]+500; |
|
451 if(KErrArgument == iSurfaceManager.OpenSurface(invalidSurfaceId)) |
|
452 { |
|
453 iTestResult |= ESecondTestPassed; |
|
454 } |
|
455 // Change the surfaceId type to EInvalidSurface |
|
456 invalidSurfaceId.iInternal[3] = (surfaceId.iInternal[3] & 0x00FFFFFF) | ( TSurfaceId::EInvalidSurface <<24 ) ; |
|
457 if(KErrArgument == iSurfaceManager.OpenSurface(invalidSurfaceId)) |
|
458 { |
|
459 iTestResult |= EThirdTestPassed; |
|
460 } |
|
461 |
|
462 // Set the results so they can be read and tested by the first process |
|
463 iChunkWrapper->SetSecondProcessResults(iTestResult); |
|
464 |
|
465 } |
|
466 |
|
467 /** |
|
468 Test 22: Create, Open and Close in 3 different processes, |
|
469 leaves surface accessible in first 2 processes |
|
470 |
|
471 ... |
|
472 Process 2: Open Surface |
|
473 ... |
|
474 Process 2: MapSurface - KErrNone (still accessible) |
|
475 ... |
|
476 */ |
|
477 void CTestDriverSecondProcess::OpenWaitMap() |
|
478 { |
|
479 |
|
480 // Find the surfaceId |
|
481 TSurfaceId id = iChunkWrapper->GetId(); |
|
482 |
|
483 // Open Surface |
|
484 if(KErrNone == iSurfaceManager.OpenSurface(id)) |
|
485 { |
|
486 iTestResult |= EFirstTestPassed; |
|
487 } |
|
488 |
|
489 // Pass control back to the first process |
|
490 RSemaphore sem; |
|
491 if(KErrNone == sem.OpenGlobal(KMultiProcessSemaphore)) |
|
492 { |
|
493 iTestResult |= ESecondTestPassed; |
|
494 } |
|
495 sem.Signal(); |
|
496 |
|
497 RSemaphore sem2; |
|
498 if(KErrNone == sem2.OpenGlobal(KMultiProcessSemaphore2)) |
|
499 { |
|
500 iTestResult |= EThirdTestPassed; |
|
501 } |
|
502 sem2.Wait(); |
|
503 |
|
504 // Map surface |
|
505 RChunk handle; |
|
506 if(KErrNone == iSurfaceManager.MapSurface(id, handle)) |
|
507 { |
|
508 iTestResult |= EFourthTestPassed; |
|
509 } |
|
510 |
|
511 // Set the results so they can be read and tested by the first process |
|
512 iChunkWrapper->SetSecondProcessResults(iTestResult); |
|
513 |
|
514 sem.Close(); |
|
515 sem2.Close(); |
|
516 handle.Close(); |
|
517 |
|
518 } |
|
519 |
|
520 |
|
521 /** |
|
522 Test 23/24/25/26: Test surface can be accessed when creating process dies / |
|
523 Test surface can be closed when creating process dies / |
|
524 Test surface can be closed from third process when |
|
525 creating process dies and second process closes / |
|
526 Test surface can't be accessed in a second process when open |
|
527 and closed in the first process. |
|
528 |
|
529 Process 2: Create Surface |
|
530 ... |
|
531 Process 2: Kill Process |
|
532 ... |
|
533 */ |
|
534 void CTestDriverSecondProcess::CreateWaitKill() |
|
535 { |
|
536 // Setup attributes |
|
537 RSurfaceManager::TSurfaceCreationAttributesBuf buf; |
|
538 RSurfaceManager::TSurfaceCreationAttributes& attributes = buf(); |
|
539 |
|
540 attributes.iSize = TSize(20,80); // w > 0, h > 0 |
|
541 attributes.iBuffers = 12; // > 0 |
|
542 attributes.iPixelFormat = EUidPixelFormatYUV_422SemiPlanar; // 2bpp |
|
543 attributes.iStride = 250; // > 0, < width * bpp |
|
544 attributes.iOffsetToFirstBuffer = 200; // > 0, divisible by alignment |
|
545 attributes.iAlignment = 4; // 1 || 2 || 4 || 8 |
|
546 attributes.iContiguous = ETrue; |
|
547 |
|
548 RSurfaceManager::THintPair hints[2]; // two hint pairs specified |
|
549 attributes.iHintCount = 2; |
|
550 attributes.iSurfaceHints = hints; |
|
551 hints[0].Set(TUid::Uid(0x124545), 50, EFalse); |
|
552 hints[1].Set(TUid::Uid(0x237755), 50, EFalse); |
|
553 |
|
554 attributes.iOffsetBetweenBuffers = 0; |
|
555 attributes.iMappable = ETrue; |
|
556 |
|
557 // Create the surface |
|
558 TSurfaceId surfaceId; |
|
559 if(KErrNone == iSurfaceManager.CreateSurface(buf, surfaceId)) |
|
560 { |
|
561 iTestResult |= EFirstTestPassed; |
|
562 } |
|
563 // Put the surfaceId onto the shared chunk |
|
564 iChunkWrapper->SetId(surfaceId); |
|
565 |
|
566 // Pass control back to the first process |
|
567 RSemaphore sem; |
|
568 if(KErrNone == sem.OpenGlobal(KMultiProcessSemaphore)) |
|
569 { |
|
570 iTestResult |= ESecondTestPassed; |
|
571 } |
|
572 sem.Signal(); |
|
573 |
|
574 RSemaphore sem2; |
|
575 if(KErrNone == sem2.OpenGlobal(KMultiProcessSemaphore2)) |
|
576 { |
|
577 iTestResult |= EThirdTestPassed; |
|
578 } |
|
579 sem2.Wait(); |
|
580 |
|
581 // Set the results so they can be read and tested by the first process |
|
582 iChunkWrapper->SetSecondProcessResults(iTestResult); |
|
583 |
|
584 // CleanupStack::PopAndDestroy(2,&sem); |
|
585 sem.Close(); |
|
586 sem2.Close(); |
|
587 } |
|
588 |
|
589 /** |
|
590 Test 27/28/29: Test closing doesn't prevent opening on another process |
|
591 Test closing doesn't prevent access on another process |
|
592 Test closing a surface in the creating process |
|
593 when it has already been closed in a second process returns KErrNone |
|
594 |
|
595 ... |
|
596 Process 2: Open Surface |
|
597 Process 2: Close Surface |
|
598 ... |
|
599 */ |
|
600 void CTestDriverSecondProcess::OpenClose() |
|
601 { |
|
602 |
|
603 // Find the surfaceId |
|
604 TSurfaceId id = iChunkWrapper->GetId(); |
|
605 |
|
606 // Open Surface |
|
607 if(KErrNone == iSurfaceManager.OpenSurface(id)) |
|
608 { |
|
609 iTestResult |= EFirstTestPassed; |
|
610 } |
|
611 |
|
612 // Close Surface |
|
613 if(KErrNone == iSurfaceManager.CloseSurface(id)) |
|
614 { |
|
615 iTestResult |= ESecondTestPassed; |
|
616 } |
|
617 |
|
618 // Pass control back to the first process |
|
619 RSemaphore sem; |
|
620 if(KErrNone == sem.OpenGlobal(KMultiProcessSemaphore)) |
|
621 { |
|
622 iTestResult |= EThirdTestPassed; |
|
623 } |
|
624 sem.Signal(); |
|
625 |
|
626 RSemaphore sem2; |
|
627 if(KErrNone == sem2.OpenGlobal(KMultiProcessSemaphore2)) |
|
628 { |
|
629 iTestResult |= EFourthTestPassed; |
|
630 } |
|
631 sem2.Wait(); |
|
632 |
|
633 // Set the results so they can be read and tested by the first process |
|
634 iChunkWrapper->SetSecondProcessResults(iTestResult); |
|
635 |
|
636 sem.Close(); |
|
637 sem2.Close(); |
|
638 } |
|
639 |
|
640 /** |
|
641 Test 30: Test a surface cannot be accessed in a second process if not opened |
|
642 |
|
643 ... |
|
644 Process 2: Map Surface - KErrAccessDenied |
|
645 Process 2: Surface Info - KErrAccessDenied |
|
646 */ |
|
647 void CTestDriverSecondProcess::MapSurfaceInfoCantAccess() |
|
648 { |
|
649 // Find the surfaceId |
|
650 TSurfaceId id = iChunkWrapper->GetId(); |
|
651 |
|
652 // Map surface |
|
653 RChunk handle; |
|
654 if(KErrAccessDenied == iSurfaceManager.MapSurface(id, handle)) |
|
655 { |
|
656 iTestResult |= EFirstTestPassed; |
|
657 } |
|
658 |
|
659 // Surface Info |
|
660 RSurfaceManager::TInfoBuf infoBuf; |
|
661 if(KErrAccessDenied == iSurfaceManager.SurfaceInfo(id, infoBuf)) |
|
662 { |
|
663 iTestResult |= ESecondTestPassed; |
|
664 } |
|
665 |
|
666 // Pass control back to the first process |
|
667 RSemaphore sem; |
|
668 if(KErrNone == sem.OpenGlobal(KMultiProcessSemaphore)) |
|
669 { |
|
670 iTestResult |= EThirdTestPassed; |
|
671 } |
|
672 sem.Signal(); |
|
673 |
|
674 RSemaphore sem2; |
|
675 if(KErrNone == sem2.OpenGlobal(KMultiProcessSemaphore2)) |
|
676 { |
|
677 iTestResult |= EFourthTestPassed; |
|
678 } |
|
679 sem2.Wait(); |
|
680 |
|
681 // Set the results so they can be read and tested by the first process |
|
682 iChunkWrapper->SetSecondProcessResults(iTestResult); |
|
683 |
|
684 // CleanupStack::PopAndDestroy(3,&handle); |
|
685 sem.Close(); |
|
686 sem2.Close(); |
|
687 handle.Close(); |
|
688 } |
|
689 |
|
690 /** |
|
691 Test 31: Test that a buffer written to in one surface can be read from in another |
|
692 |
|
693 Process 1: Create Surface |
|
694 Process 1: Map Surface |
|
695 Process 1: Write to buffer |
|
696 Process 2: Open the surface |
|
697 Process 2: Read from buffer |
|
698 */ |
|
699 void CTestDriverSecondProcess::TestReadFromBufferInSecondProcess() |
|
700 { |
|
701 // Find the surfaceId |
|
702 TSurfaceId id = iChunkWrapper->GetId(); |
|
703 |
|
704 // Open Surface |
|
705 if(KErrNone == iSurfaceManager.OpenSurface(id)) |
|
706 { |
|
707 iTestResult |= EFirstTestPassed; |
|
708 } |
|
709 |
|
710 // Map surface |
|
711 RChunk handle; |
|
712 if(KErrNone == iSurfaceManager.MapSurface(id, handle)) |
|
713 { |
|
714 iTestResult |= ESecondTestPassed; |
|
715 } |
|
716 |
|
717 // Read from the buffer |
|
718 RSurfaceManager::TInfoBuf infoBuf; |
|
719 if(KErrNone == iSurfaceManager.SurfaceInfo(id, infoBuf)) |
|
720 { |
|
721 iTestResult |= EThirdTestPassed; |
|
722 } |
|
723 RSurfaceManager::TSurfaceInfoV01& info = infoBuf(); |
|
724 TUint8* surfaceAdd = handle.Base(); |
|
725 TInt offsetToFirstBuffer; |
|
726 if(KErrNone == iSurfaceManager.GetBufferOffset(id, 0, offsetToFirstBuffer)) |
|
727 { |
|
728 iTestResult |= EFourthTestPassed; |
|
729 } |
|
730 TUint8* bufferAdd = surfaceAdd + offsetToFirstBuffer; |
|
731 if(*bufferAdd == 134) |
|
732 { |
|
733 iTestResult |= EFifthTestPassed; |
|
734 } |
|
735 |
|
736 // Set the results so they can be read and tested by the first process |
|
737 iChunkWrapper->SetSecondProcessResults(iTestResult); |
|
738 |
|
739 handle.Close(); |
|
740 } |
|
741 |
|
742 void CTestDriverSecondProcess::TestGetSurfaceHint() |
|
743 { |
|
744 // Open the chunk wrapper and get the surfaceId |
|
745 TSurfaceId surfaceId = iChunkWrapper->GetId(); |
|
746 |
|
747 RSurfaceManager::THintPair hintPair; |
|
748 hintPair.iKey.iUid = 0x124578; |
|
749 if (KErrAccessDenied == iSurfaceManager.GetSurfaceHint(surfaceId, hintPair)) |
|
750 { |
|
751 iTestResult |= EFirstTestPassed; |
|
752 } |
|
753 |
|
754 if(KErrNone == iSurfaceManager.OpenSurface(surfaceId)) |
|
755 { |
|
756 iTestResult |= ESecondTestPassed; |
|
757 } |
|
758 |
|
759 if (KErrNone == iSurfaceManager.GetSurfaceHint(surfaceId, hintPair)) |
|
760 { |
|
761 iTestResult |= EThirdTestPassed; |
|
762 } |
|
763 |
|
764 // Set the results so they can be read and tested by the first process |
|
765 iChunkWrapper->SetSecondProcessResults(iTestResult); |
|
766 |
|
767 } |
|
768 |
|
769 |
|
770 void CTestDriverSecondProcess::TestSetSurfaceHint() |
|
771 { |
|
772 // Open the chunk wrapper and get the surfaceId |
|
773 TSurfaceId surfaceId = iChunkWrapper->GetId(); |
|
774 |
|
775 RSurfaceManager::THintPair hintPair; |
|
776 hintPair.iKey.iUid = 0x124578; |
|
777 hintPair.iValue = 300; |
|
778 |
|
779 if (KErrAccessDenied == iSurfaceManager.SetSurfaceHint(surfaceId, hintPair)) |
|
780 { |
|
781 iTestResult |= EFirstTestPassed; |
|
782 } |
|
783 |
|
784 if(KErrNone == iSurfaceManager.OpenSurface(surfaceId)) |
|
785 { |
|
786 iTestResult |= ESecondTestPassed; |
|
787 } |
|
788 |
|
789 if (KErrNone == iSurfaceManager.SetSurfaceHint(surfaceId, hintPair)) |
|
790 { |
|
791 iTestResult |= EThirdTestPassed; |
|
792 } |
|
793 RSurfaceManager::THintPair hintPairNew; |
|
794 hintPairNew.iKey.iUid = 0x124578; |
|
795 |
|
796 iSurfaceManager.GetSurfaceHint(surfaceId,hintPairNew); |
|
797 if (hintPairNew.iValue == hintPair.iValue) |
|
798 { |
|
799 iTestResult |= EFourthTestPassed; |
|
800 } |
|
801 // Set the results so they can be read and tested by the first process |
|
802 iChunkWrapper->SetSecondProcessResults(iTestResult); |
|
803 |
|
804 } |
|
805 |
|
806 |
|
807 void CTestDriverSecondProcess::TestAddSurfaceHint() |
|
808 { |
|
809 // Open the chunk wrapper and get the surfaceId |
|
810 TSurfaceId surfaceId = iChunkWrapper->GetId(); |
|
811 |
|
812 RSurfaceManager::THintPair hintPair; |
|
813 hintPair.iKey.iUid = 0x124580; |
|
814 hintPair.iValue = 300; |
|
815 hintPair.iMutable = ETrue; |
|
816 if (KErrAccessDenied == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair)) |
|
817 { |
|
818 iTestResult |= EFirstTestPassed; |
|
819 } |
|
820 |
|
821 if(KErrNone == iSurfaceManager.OpenSurface(surfaceId)) |
|
822 { |
|
823 iTestResult |= ESecondTestPassed; |
|
824 } |
|
825 |
|
826 if (KErrNone == iSurfaceManager.AddSurfaceHint(surfaceId, hintPair)) |
|
827 { |
|
828 iTestResult |= EThirdTestPassed; |
|
829 } |
|
830 RSurfaceManager::THintPair hintPairNew; |
|
831 hintPairNew.iKey.iUid = 0x124580; |
|
832 |
|
833 iSurfaceManager.GetSurfaceHint(surfaceId,hintPairNew); |
|
834 if (hintPairNew.iValue == hintPair.iValue) |
|
835 { |
|
836 iTestResult |= EFourthTestPassed; |
|
837 } |
|
838 // Set the results so they can be read and tested by the first process |
|
839 iChunkWrapper->SetSecondProcessResults(iTestResult); |
|
840 |
|
841 } |
|
842 |
|
843 |
|
844 void CTestDriverSecondProcess::TestOutofMemory() |
|
845 { |
|
846 // Open the chunk wrapper and get the surfaceId |
|
847 TSurfaceId surfaceId = iChunkWrapper->GetId(); |
|
848 // Test OOM in OpenSurface() |
|
849 __KHEAP_SETFAIL(RHeap::EDeterministic, 1); |
|
850 if (KErrNoMemory == iSurfaceManager.OpenSurface(surfaceId)) |
|
851 { |
|
852 iTestResult |= EFirstTestPassed; |
|
853 } |
|
854 __KHEAP_RESET; |
|
855 // Test OOM in AddConnection() |
|
856 RSurfaceManager surfaceManagerTest; |
|
857 __KHEAP_SETFAIL(RHeap::EDeterministic, 1); |
|
858 if (KErrNoMemory == surfaceManagerTest.Open()) |
|
859 { |
|
860 iTestResult |= ESecondTestPassed; |
|
861 } |
|
862 __KHEAP_RESET; |
|
863 // Set the results so they can be read and tested by the first process |
|
864 iChunkWrapper->SetSecondProcessResults(iTestResult); |
|
865 } |
|
866 // Real main function |
|
867 void MainL() |
|
868 { |
|
869 |
|
870 test.Title(); |
|
871 RDebug::Print(_L("marker")); |
|
872 |
|
873 test.Start(_L("Starting 2nd Process")); |
|
874 TInt testCase; |
|
875 User::GetTIntParameter(EMultiProcessSecondSlot, testCase); |
|
876 TInt procHandles1 =0; |
|
877 TInt threadHandles1=0; |
|
878 RThread().HandleCount(procHandles1, threadHandles1); |
|
879 |
|
880 CTestDriverSecondProcess* testDriver = CTestDriverSecondProcess::NewL(); |
|
881 CleanupStack::PushL(testDriver); |
|
882 |
|
883 switch(testCase) |
|
884 { |
|
885 case ETestInfoReceivedSurface: |
|
886 testDriver->TestSurfaceInfoUsingSurfaceId(); |
|
887 break; |
|
888 case ETestOpenReceivedSurface: |
|
889 testDriver->TestOpeningSurfaceUsingSurfaceId(); |
|
890 break; |
|
891 case ETestOpenSurfaceInvalidParams: |
|
892 testDriver->TestOpeningSurfaceInvalidParams(); |
|
893 break; |
|
894 case EOpenWaitMap: |
|
895 testDriver->OpenWaitMap(); |
|
896 break; |
|
897 case ECreateWaitKill: |
|
898 testDriver->CreateWaitKill(); |
|
899 break; |
|
900 case EOpenClose: |
|
901 testDriver->OpenClose(); |
|
902 break; |
|
903 case EMapSurfaceInfoCantAccess: |
|
904 testDriver->MapSurfaceInfoCantAccess(); |
|
905 break; |
|
906 case EReadFromBuffer: |
|
907 testDriver->TestReadFromBufferInSecondProcess(); |
|
908 break; |
|
909 case ECheckHandle: |
|
910 testDriver->TestCheckHandleInSecondProcess(); |
|
911 break; |
|
912 case ESyncOperation: |
|
913 testDriver->TestCheckSyncOperation(); |
|
914 break; |
|
915 case ETestChannelMultiProcess1: |
|
916 testDriver->TestMultipleChannelsInSecondProcess1(); |
|
917 break; |
|
918 case ETestChannelMultiProcess2: |
|
919 testDriver->TestMultipleChannelsInSecondProcess2(); |
|
920 break; |
|
921 case EGetSurfaceHint: |
|
922 testDriver->TestGetSurfaceHint(); |
|
923 break; |
|
924 case ESetSurfaceHint: |
|
925 testDriver->TestSetSurfaceHint(); |
|
926 break; |
|
927 case EAddSurfaceHint: |
|
928 testDriver->TestAddSurfaceHint(); |
|
929 break; |
|
930 case ECheckOutofMemory: |
|
931 #ifdef _DEBUG |
|
932 testDriver->TestOutofMemory(); |
|
933 #endif |
|
934 break; |
|
935 default: |
|
936 User::Leave(KErrArgument); |
|
937 break; |
|
938 } |
|
939 CleanupStack::PopAndDestroy(testDriver); |
|
940 |
|
941 // Handle check |
|
942 TInt procHandles2 =0; |
|
943 TInt threadHandles2=0; |
|
944 RThread().HandleCount(procHandles2,threadHandles2); |
|
945 if (threadHandles1 != threadHandles2) |
|
946 { |
|
947 User::Leave(KErrGeneral); // Thread-owned handles not closed |
|
948 } |
|
949 |
|
950 |
|
951 test.End(); |
|
952 test.Close(); |
|
953 } |
|
954 |
|
955 // Cleanup stack harness |
|
956 GLDEF_C TInt E32Main() |
|
957 { |
|
958 __UHEAP_MARK; |
|
959 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
960 TRAPD(error, MainL()); |
|
961 _LIT(KTSecondProcessPanic,"tsecondprocessmain"); |
|
962 __ASSERT_ALWAYS(!error, User::Panic(KTSecondProcessPanic, error)); |
|
963 delete cleanupStack; |
|
964 __UHEAP_MARKEND; |
|
965 return 0; |
|
966 } |