|
1 // Copyright (c) 2002-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 // Contains MBufMgr Test Step 03 |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 |
|
21 // Test system includes |
|
22 #include <networking/log.h> |
|
23 #include <networking/teststep.h> |
|
24 #include "TestStepCTMbufmgr.h" |
|
25 #include "TestSuiteCTMbufmgr.h" |
|
26 |
|
27 #include "Test03AllocLeave.h" |
|
28 |
|
29 |
|
30 // constructor |
|
31 CTest03AllocLeave::CTest03AllocLeave() |
|
32 { |
|
33 iTestStepName = _L("MBufMgrTest03");// Store the name of this test case |
|
34 } |
|
35 |
|
36 // destructor |
|
37 CTest03AllocLeave::~CTest03AllocLeave() |
|
38 { |
|
39 } |
|
40 |
|
41 // |
|
42 enum TVerdict CTest03AllocLeave::doTestStepL(void) |
|
43 { |
|
44 __UHEAP_MARK; |
|
45 |
|
46 #ifdef __CFLOG_ACTIVE |
|
47 __CFLOG_CREATEL; |
|
48 __CFLOG_OPEN; |
|
49 #endif |
|
50 |
|
51 TVerdict verdict(EFail); |
|
52 //-------------- substep 1 -------------------- |
|
53 Log(_L(" 01 Create CMBufManager (with 15K alloc memory) and install active scheduler:")); |
|
54 CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler ); |
|
55 CActiveScheduler::Install(iActSch); |
|
56 |
|
57 CleanupStack::PushL(CreateInstanceMBufMgrL(65536)); |
|
58 if (!iMBMngr) |
|
59 { |
|
60 Log(_L("Error:Could not create MBuf manager")); |
|
61 |
|
62 #ifdef __CFLOG_ACTIVE |
|
63 __CFLOG_CLOSE; |
|
64 __CFLOG_DELETE; |
|
65 #endif |
|
66 User::Leave(EFail); |
|
67 } |
|
68 |
|
69 //-------------- substep 2 -------------------- |
|
70 RMBuf* mbufs[14]; |
|
71 TInt i; |
|
72 TInt ret; |
|
73 Log(_L(" 02 Allocate 42000-bytes long worth of mbufs")); |
|
74 for (i = 0; i < sizeof(mbufs)/sizeof(mbufs[0]); ++i) |
|
75 { |
|
76 TRAP(ret,mbufs[i] = iMBMngr->AllocL(3000)); |
|
77 Log(_L(" Heap Size after %d allocs : %d"),i,iMBMngr->__DbgGetHeapSize()); |
|
78 if (ret != KErrNone) |
|
79 { |
|
80 Log(_L("Error: Couldn't allocate RMBuf:")); |
|
81 |
|
82 #ifdef __CFLOG_ACTIVE |
|
83 __CFLOG_CLOSE; |
|
84 __CFLOG_DELETE; |
|
85 #endif |
|
86 User::Leave(EFail); |
|
87 } |
|
88 } |
|
89 |
|
90 |
|
91 //-------------- substep 3 -------------------- |
|
92 Log(_L(" 03 Allocate 8192-bytes long RMBuf2:")); |
|
93 RMBuf* aMBuf2=0; |
|
94 TRAP(ret,aMBuf2 = iMBMngr->AllocL(16384);) |
|
95 if (ret != KErrNone) |
|
96 { |
|
97 Log(_L("Info: Couldn't allocate RMBuf as it should be so.")); |
|
98 if (ret == KErrNoMBufs) |
|
99 verdict = EPass; |
|
100 else |
|
101 { |
|
102 Log(_L("Error: The reason AllocL has failed is %d instead of %d"),ret,KErrNoMBufs); |
|
103 verdict = EFail; |
|
104 } |
|
105 } |
|
106 Log(_L(" Heap Size after failed alloc %d"),iMBMngr->__DbgGetHeapSize()); |
|
107 // Cleanup . |
|
108 //-------------- substep 4 -------------------- |
|
109 Log(_L(" 04 Deallocate RMBufs (1, 2 & 3):")); |
|
110 for (i = 0; i < sizeof(mbufs)/sizeof(mbufs[0]); ++i) |
|
111 { |
|
112 iMBMngr->Free(mbufs[i]); |
|
113 } |
|
114 |
|
115 if (aMBuf2 != NULL) |
|
116 iMBMngr->Free(aMBuf2); |
|
117 |
|
118 //-------------- substep 5 -------------------- |
|
119 Log(_L(" 05 Clean up stack:")); |
|
120 CleanupStack::PopAndDestroy(iMBMngr); |
|
121 CActiveScheduler::Install(NULL); |
|
122 CleanupStack::PopAndDestroy(iActSch); |
|
123 |
|
124 #ifdef __CFLOG_ACTIVE |
|
125 __CFLOG_CLOSE; |
|
126 __CFLOG_DELETE; |
|
127 #endif |
|
128 __UHEAP_MARKEND; |
|
129 return verdict; |
|
130 } |