|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Implements the basic test step which implements OOM tests. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include "oomteststep.h" |
|
23 #include <scs/scsclient.h> |
|
24 |
|
25 EXPORT_C COomTestStep::COomTestStep() |
|
26 // Constructor. |
|
27 : iOOMTest(EFalse) |
|
28 { |
|
29 //empty |
|
30 } |
|
31 |
|
32 EXPORT_C COomTestStep::~COomTestStep() |
|
33 // Destructor. |
|
34 { |
|
35 //empty |
|
36 } |
|
37 |
|
38 |
|
39 EXPORT_C TVerdict COomTestStep::doTestStepPreambleL() |
|
40 /** |
|
41 From CTestStep. Do some boilerplate pre-test configuration. |
|
42 */ |
|
43 { |
|
44 __UHEAP_MARK; |
|
45 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells()); |
|
46 |
|
47 ReadTestConfigurationL(); |
|
48 SetTestStepResult(EPass); |
|
49 |
|
50 ImplTestStepPreambleL(); |
|
51 |
|
52 return TestStepResult(); |
|
53 } |
|
54 |
|
55 |
|
56 EXPORT_C TVerdict COomTestStep::doTestStepL() |
|
57 /** |
|
58 From CTestStep. Default behaviour of ImplTestStepL() allows for the test case to be run both |
|
59 under 'Normal' and 'Out of Memory' Conditions. |
|
60 |
|
61 Implementation of the test case itself is called from the ImplTestStepL() of the derived test step. |
|
62 |
|
63 The state of the iOOMTest member variable determines the type of test conditons: |
|
64 - EFalse : Normal Test |
|
65 - ETrue : Out of Memory Test |
|
66 */ |
|
67 { |
|
68 |
|
69 if (iOOMTest) |
|
70 { |
|
71 ImplOomTestL(); |
|
72 } |
|
73 else if (iOOMServerTest) |
|
74 { |
|
75 ImplOomServerTestL(); |
|
76 } |
|
77 else |
|
78 { |
|
79 ImplTestStepL(); |
|
80 } |
|
81 |
|
82 return TestStepResult(); |
|
83 } |
|
84 |
|
85 |
|
86 EXPORT_C TVerdict COomTestStep::doTestStepPostambleL() |
|
87 /** |
|
88 From CTestStep. Destroys the active scheduler of the test step. |
|
89 */ |
|
90 { |
|
91 ImplTestStepPostambleL(); |
|
92 |
|
93 INFO_PRINTF2(_L("HEAP CELLS: %d"),User::CountAllocCells()); |
|
94 __UHEAP_MARKEND; |
|
95 |
|
96 return TestStepResult(); |
|
97 } |
|
98 |
|
99 |
|
100 TVerdict COomTestStep::ImplOomTestL() |
|
101 /** |
|
102 Runs the test step under OOM Conditions checking that each heap allocation is fail safe. |
|
103 |
|
104 */ |
|
105 { |
|
106 // Pre and Post test heap cell allocation counts |
|
107 TInt cellCountAfter = 0; |
|
108 TInt cellCountBefore = 0; |
|
109 |
|
110 // The loop tests each heap allocation under out of memory conditions to determine whether |
|
111 // the test framework cleans up correctly without leaking memory. |
|
112 // |
|
113 // The 'for' loop terminates as soon as any of the following events occur: |
|
114 // a) The pre and post heap cell counts mismatch signalling a memory leakage |
|
115 // b) Any leave with an error code other than 'KErrNoMemory' |
|
116 // c) All heap allocations have been tested and the test returns 'KErrNone' |
|
117 |
|
118 for (TInt testCount = 0; ; ++testCount) |
|
119 { |
|
120 __UHEAP_MARK; |
|
121 __UHEAP_SETFAIL(RHeap::EDeterministic, testCount+1); |
|
122 cellCountBefore = User::CountAllocCells(); |
|
123 TRAPD(err, ImplTestStepL()); |
|
124 cellCountAfter = User::CountAllocCells(); |
|
125 __UHEAP_MARKEND; |
|
126 |
|
127 INFO_PRINTF3(_L("OOM Test %d: Status = %d"),testCount,err); |
|
128 |
|
129 if (err == KErrNone) |
|
130 { |
|
131 INFO_PRINTF1(_L("OOM Test Finished")); |
|
132 break; |
|
133 } |
|
134 else if(err == KErrNoMemory) |
|
135 { |
|
136 if (cellCountBefore != cellCountAfter) |
|
137 { |
|
138 ERR_PRINTF2(_L("OOM Test Result: Failed - Memory leakage on iteration %d"), testCount); |
|
139 ERR_PRINTF2(_L("Pre-Test Heap Cell Count: %d"), cellCountBefore); |
|
140 ERR_PRINTF2(_L("Post-Test Heap Cell Count: %d"), cellCountAfter); |
|
141 SetTestStepResult(EFail); |
|
142 break; |
|
143 } |
|
144 } |
|
145 else |
|
146 { |
|
147 User::Leave(err); |
|
148 break; |
|
149 } |
|
150 } |
|
151 |
|
152 return TestStepResult(); |
|
153 } |
|
154 |
|
155 |
|
156 TVerdict COomTestStep::ImplOomServerTestL() |
|
157 { |
|
158 RScsClientBase *client = ClientHandle(); |
|
159 if(!client) |
|
160 { |
|
161 ERR_PRINTF1(_L("ClientHandle has returned NULL. The server cannot be tested without the client handle!")); |
|
162 User::Leave(KErrArgument); |
|
163 } |
|
164 TInt err(0); |
|
165 for (TInt testCount=0; ; ++testCount) |
|
166 { |
|
167 INFO_PRINTF2(_L("OOM Server Test %d"), testCount); |
|
168 err = client->SetServerHeapFail(testCount+1); |
|
169 if(KErrNone != err) |
|
170 { |
|
171 ERR_PRINTF3(_L("OOM Server Test Result: Failed to set heap fail on iteration %d. Error:%d"), testCount, err); |
|
172 SetTestStepResult(EFail); |
|
173 break; |
|
174 } |
|
175 TRAPD(retStepVal, ImplTestStepL()); |
|
176 err = client->ResetServerHeapFail(); |
|
177 |
|
178 if(KErrNone != err) |
|
179 { |
|
180 ERR_PRINTF3(_L("ResetServerHeapFail failed on iteration %d with error %d"), testCount, err); |
|
181 SetTestStepResult(EFail); |
|
182 break; |
|
183 } |
|
184 |
|
185 if(KErrNoMemory == retStepVal) |
|
186 { |
|
187 INFO_PRINTF2(_L("Received correct out of memory error on iteration %d"), testCount); |
|
188 } |
|
189 else if (KErrNone == retStepVal) |
|
190 { |
|
191 INFO_PRINTF1(_L("Server OOM Test Finished")); |
|
192 break; |
|
193 } |
|
194 else |
|
195 { |
|
196 // Propagate all errors apart from KErrNoMemory |
|
197 User::Leave(retStepVal); |
|
198 } |
|
199 }// for |
|
200 |
|
201 return TestStepResult(); |
|
202 } |
|
203 |
|
204 |
|
205 void COomTestStep::ReadTestConfigurationL() |
|
206 { |
|
207 // Read OOM Test Flag |
|
208 GetBoolFromConfig(ConfigSection(), KConfigOOMTest, iOOMTest); |
|
209 // Read OOM Server Test Flag |
|
210 GetBoolFromConfig(ConfigSection(), KConfigOOMServerTest, iOOMServerTest); |
|
211 } |
|
212 |
|
213 EXPORT_C RScsClientBase* COomTestStep::ClientHandle() |
|
214 /** |
|
215 Returns a pointer to RScsClientBase class. This default implementation returns NULL. |
|
216 If a server is tested with OOM conditions, the derived class must return a pointer to |
|
217 the RScsClientBase-derived object. |
|
218 */ |
|
219 { |
|
220 return NULL; |
|
221 } |