21 // results. |
21 // results. |
22 // - Test and verify results of creating shared chunks under OOM conditions. Also verify |
22 // - Test and verify results of creating shared chunks under OOM conditions. Also verify |
23 // creating a chunk with a bad type, bad size and too large all fail as |
23 // creating a chunk with a bad type, bad size and too large all fail as |
24 // expected. |
24 // expected. |
25 // - Test and verify opening and closing chunk user handles work as expected. |
25 // - Test and verify opening and closing chunk user handles work as expected. |
|
26 // - Test and verify thread local and process local handles work as expected |
26 // - Test and verify setting restrictions on RChunk if created as shared chunk are as expected. |
27 // - Test and verify setting restrictions on RChunk if created as shared chunk are as expected. |
27 // - Test and verify memory access for multiply and singly shared chunks, |
28 // - Test and verify memory access for multiply and singly shared chunks, |
28 // is as expected. Including IPC, kernel, DFC and ISR reads & writes. |
29 // is as expected. Including IPC, kernel, DFC and ISR reads & writes. |
29 // - Test and verify discontinuous memory commits for multiply and singly |
30 // - Test and verify discontinuous memory commits for multiply and singly |
30 // shared chunks are as expected. |
31 // shared chunks are as expected. |
363 CHECK(1,==,Ldd.IsDestroyed()); |
364 CHECK(1,==,Ldd.IsDestroyed()); |
364 |
365 |
365 test.End(); |
366 test.End(); |
366 } |
367 } |
367 |
368 |
|
369 TInt HandleOwnershipThread(TAny* aArg) |
|
370 { |
|
371 // Use existing handle and attempt to read from chunk |
|
372 TInt handle = (TInt) aArg; |
|
373 RChunk chunk; |
|
374 chunk.SetHandle(handle); |
|
375 TInt r = *(volatile TUint8*)chunk.Base(); |
|
376 (void)r; |
|
377 CLOSE_AND_WAIT(chunk); |
|
378 return KErrNone; |
|
379 } |
|
380 |
|
381 void TestHandleOwnership() |
|
382 { |
|
383 TUint ChunkAttribs = ChunkSize|ESingle|EOwnsMemory; |
|
384 RThread thread; |
|
385 TRequestStatus rs; |
|
386 |
|
387 test.Start(_L("Create chunk")); |
|
388 CHECK(KErrNone,==,Ldd.CreateChunk(ChunkAttribs)); |
|
389 |
|
390 test.Next(_L("Commit page to chunk")); |
|
391 CHECK(KErrNone,==,Ldd.CommitMemory(EDiscontiguous,PageSize)); |
|
392 |
|
393 test.Next(_L("Check can access memory kernel side")); |
|
394 KCHECK_MEMORY(ETrue, 0); |
|
395 |
|
396 // Handle is thread-owned |
|
397 test.Next(_L("Open user handle (thread-owned)")); |
|
398 CHECK(0,<=,Ldd.GetChunkHandle(TheChunk, ETrue)); |
|
399 |
|
400 test.Next(_L("Get memory size info")); |
|
401 if((MemModelAttributes&EMemModelTypeMask)!=EMemModelTypeDirect) |
|
402 { |
|
403 CHECK(PageSize,==,TheChunk.Size()); |
|
404 } |
|
405 CHECK(ChunkSize,==,TheChunk.MaxSize()); |
|
406 TUint8* Base = TheChunk.Base(); |
|
407 CHECK(Base,!=,0); |
|
408 |
|
409 test.Next(_L("Check can access memory user side")); |
|
410 UCHECK_MEMORY(ETrue, 0); |
|
411 |
|
412 test.Next(_L("Use handle in a new thread")); |
|
413 CHECK(KErrNone,==,thread.Create(_L("thread1"), HandleOwnershipThread, KDefaultStackSize, KMinHeapSize, KMinHeapSize, (TAny*)TheChunk.Handle())); |
|
414 thread.Logon(rs); |
|
415 thread.Resume(); |
|
416 User::WaitForRequest(rs); |
|
417 CHECK(EExitPanic,==,thread.ExitType()); |
|
418 CHECK(0,==,thread.ExitReason()); // KERN-EXEC 0 |
|
419 CLOSE_AND_WAIT(thread); |
|
420 |
|
421 test.Next(_L("Close user handle")); |
|
422 TheChunk.Close(); |
|
423 |
|
424 // Handle is process-owned |
|
425 test.Next(_L("Open user handle (process-owned")); |
|
426 CHECK(0,<=,Ldd.GetChunkHandle(TheChunk, EFalse)); |
|
427 |
|
428 test.Next(_L("Check can access memory user side")); |
|
429 UCHECK_MEMORY(ETrue, 0); |
|
430 |
|
431 test.Next(_L("Close kernel handle")); |
|
432 CHECK(KErrNone,==,Ldd.CloseChunk()); |
|
433 |
|
434 test.Next(_L("Check chunk destroyed")); |
|
435 CHECK(0,==,Ldd.IsDestroyed()); |
|
436 |
|
437 test.Next(_L("Use handle in a new thread")); |
|
438 CHECK(KErrNone,==,thread.Create(_L("thread2"), HandleOwnershipThread, KDefaultStackSize, KMinHeapSize, KMinHeapSize, (TAny*)TheChunk.Handle())); |
|
439 thread.Logon(rs); |
|
440 thread.Resume(); |
|
441 User::WaitForRequest(rs); |
|
442 CHECK(EExitKill,==,thread.ExitType()); |
|
443 CHECK(KErrNone,==,thread.ExitReason()); |
|
444 CLOSE_AND_WAIT(thread); |
|
445 |
|
446 test.Next(_L("Check chunk destroyed")); |
|
447 CHECK(1,==,Ldd.IsDestroyed()); // Object was deleted |
|
448 |
|
449 test.End(); |
|
450 } |
368 |
451 |
369 void SetCreateFlags(TUint& aCreateFlags,TCommitType aCommitType) |
452 void SetCreateFlags(TUint& aCreateFlags,TCommitType aCommitType) |
370 { |
453 { |
371 if(!((TInt)aCommitType&EPhysicalMask)) |
454 if(!((TInt)aCommitType&EPhysicalMask)) |
372 aCreateFlags |= EOwnsMemory; |
455 aCreateFlags |= EOwnsMemory; |