|
1 // Copyright (c) 2001-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 definition of CTestStepCTMbufmgr which is the base class |
|
15 // for all the Mbufmgr Test Step classes |
|
16 // |
|
17 |
|
18 #include <e32base.h> |
|
19 |
|
20 // Test system includes |
|
21 #include <networking/log.h> |
|
22 #include <networking/teststep.h> |
|
23 #include "TestStepCTMbufmgr.h" |
|
24 #include "TestSuiteCTMbufmgr.h" |
|
25 |
|
26 #include "Test20Alloc.h" |
|
27 |
|
28 // constructor |
|
29 CTest20Alloc::CTest20Alloc() |
|
30 { |
|
31 iTestStepName = _L("MBufMgrTest20");// Store the name of this test case |
|
32 } |
|
33 |
|
34 // destructor |
|
35 CTest20Alloc::~CTest20Alloc() |
|
36 { |
|
37 } |
|
38 |
|
39 struct AllocTestStruct |
|
40 { |
|
41 TInt min; |
|
42 TInt max; |
|
43 TInt allocSize; |
|
44 TInt expectedSize; |
|
45 TInt expectedBufCount; |
|
46 TInt expectedBufSizes[4]; |
|
47 }; |
|
48 |
|
49 const AllocTestStruct allocTests[] = |
|
50 { |
|
51 { 64, 96, 96, 0, 0, {} }, // lower min nax range than pool range |
|
52 { 1800, 2000, 96, 0, 0, {} }, // higher min nax range than pool range |
|
53 { 1400, 1400, 96, 0, 0, {} }, // mid max range that doesn't match contain any pools |
|
54 { 1600, 1600, 96, 96, 1, {1600} }, // highest size, allocate smaller |
|
55 { 128, 128, 96, 96, 1, {128} }, // lowest size, allocate smaller |
|
56 { 400, 400, 96, 96, 1, {400} }, // mid size, allocate smaller |
|
57 { 1600, 1600, 3200, 3200, 2, {1600,1600} }, // highest size, allocate slightly higher |
|
58 { 1600, 1600, 1604, 1604, 2, {1600,1600} }, // highest size, allocate slightly higher |
|
59 { 128, 128, 132, 132, 2, {128,128} }, // lowest size, allocate slightly higher |
|
60 { 400, 400, 260, 260, 1, {400} }, // mid size, allocate slightly higher |
|
61 { 128, 1600, 1604, 1604, 2, {1600,128} }, // |
|
62 { 128, 1600, 1728, 1728, 2, {1600,128} }, // |
|
63 { 128, 1600, 1856, 1856, 2, {1600,400} }, // |
|
64 { 128, 1600, 2000, 2000, 2, {1600,400} }, // |
|
65 { 128, 1600, 2128, 2128, 2, {1600,1600} }, // |
|
66 { 128, 1600, 2130, 2130, 2, {1600,1600} }, // |
|
67 { 128, 1600, 2398, 2398, 2, {1600,1600}, }, // |
|
68 { 128, 128, 300, 300, 3, {128,128,128} }, // |
|
69 { 128, 1600, 3208, 3208, 3, {1600,1600,128} }, // Edge case spotted in old algorithm by SMP work |
|
70 { 1600, 1600, 3208, 3208, 3, {1600,1600,1600} }, // Edge case spotted in old algorithm by SMP work |
|
71 |
|
72 { 0, 0, 0, 0,-1, {} } // -1 indicates end of list |
|
73 }; |
|
74 |
|
75 // |
|
76 enum TVerdict CTest20Alloc::doTestStepL(void) |
|
77 { |
|
78 __UHEAP_MARK; |
|
79 |
|
80 #ifdef __CFLOG_ACTIVE |
|
81 __CFLOG_CREATEL; |
|
82 __CFLOG_OPEN; |
|
83 #endif |
|
84 |
|
85 //-------------- substep 1 -------------------- |
|
86 Log(_L(" 01 Create CMBufManager and install active scheduler:")); |
|
87 CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler ); |
|
88 CActiveScheduler::Install(iActSch); |
|
89 |
|
90 MMBufSizeAllocator* MBufSizeAllocator; |
|
91 CleanupStack::PushL(CreateInstanceMBufMgrL(KMBufDefaultHeapSize / 2, MBufSizeAllocator)); |
|
92 |
|
93 // Create some initial pools |
|
94 MBufSizeAllocator->AddL(128, 128, 64, 48); |
|
95 MBufSizeAllocator->AddL(400, 32, 16, 12); |
|
96 MBufSizeAllocator->AddL(1600, 32, 16, 12); |
|
97 |
|
98 TBool accumulatedFail = EFalse; |
|
99 |
|
100 //-------------- substep 2 -------------------- |
|
101 Log(_L(" 02 Alloc Tests")); |
|
102 const AllocTestStruct* test = allocTests; |
|
103 while(test->expectedBufCount != -1) |
|
104 { |
|
105 TBool fail = EFalse; |
|
106 RMBufChain chain; |
|
107 |
|
108 //-------------- substep 2 -------------------- |
|
109 _LIT(aLog1, " Min %d Max %d Alloc %d"); |
|
110 Log(aLog1,test->min,test->max,test->allocSize); |
|
111 chain.Alloc(test->allocSize,test->min,test->max); |
|
112 |
|
113 if(chain.Length() != test->expectedSize) |
|
114 { |
|
115 _LIT(aLog2, "Error: Wrong number of bytes allocated: received %d expected %d"); |
|
116 Log(aLog2,chain.Length(),test->expectedSize); |
|
117 fail = ETrue; |
|
118 } |
|
119 if( (!chain.IsEmpty() && chain.NumBufs() != test->expectedBufCount) |
|
120 || ( chain.IsEmpty() && 0 != test->expectedBufCount) |
|
121 ) |
|
122 { |
|
123 _LIT(aLog3, "Error: Wrong number of buffers allocated: received %d expected %d"); |
|
124 Log(aLog3,chain.IsEmpty()?0:chain.NumBufs(),test->expectedBufCount); |
|
125 fail = ETrue; |
|
126 } |
|
127 |
|
128 if(!chain.IsEmpty()) |
|
129 { |
|
130 RMBuf* buf = chain.First(); |
|
131 int count=0; |
|
132 while(count<chain.NumBufs() && buf) |
|
133 { |
|
134 if(buf->Size() != test->expectedBufSizes[count]) |
|
135 { |
|
136 _LIT(aLog4, "Error: Expected buffer %d in the chain to be %d rather than %d"); |
|
137 Log(aLog4,count,test->expectedBufSizes[count],buf->Size()); |
|
138 fail = ETrue; |
|
139 } |
|
140 |
|
141 buf = buf->Next(); |
|
142 count++; |
|
143 } |
|
144 } |
|
145 |
|
146 accumulatedFail |= fail; |
|
147 chain.Free(); |
|
148 |
|
149 ++test; |
|
150 } |
|
151 |
|
152 //-------------- substep 7 -------------------- |
|
153 Log(_L(" 03 Clean up stack:")); |
|
154 CleanupStack::PopAndDestroy(iMBMngr); |
|
155 CActiveScheduler::Install(NULL); |
|
156 CleanupStack::PopAndDestroy(iActSch); |
|
157 |
|
158 #ifdef __CFLOG_ACTIVE |
|
159 __CFLOG_CLOSE; |
|
160 __CFLOG_DELETE; |
|
161 #endif |
|
162 __UHEAP_MARKEND; |
|
163 |
|
164 if (accumulatedFail) |
|
165 { |
|
166 return EFail; |
|
167 } |
|
168 |
|
169 return EPass; |
|
170 } |