0
|
1 |
// Copyright (c) 2008-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 the License "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 |
//
|
|
15 |
|
|
16 |
#include <kernel/kern_priv.h>
|
|
17 |
#include "d_newldd.h"
|
|
18 |
#include "t_newldd.h"
|
|
19 |
|
|
20 |
TInt DOperatorNewTest::Request(TInt aReqNo, TAny* /*a1*/, TAny* /*a2*/)
|
|
21 |
{
|
|
22 |
switch(aReqNo)
|
|
23 |
{
|
|
24 |
//new
|
|
25 |
case RNewLddTest::ENew:
|
|
26 |
{
|
|
27 |
return TestNew();
|
|
28 |
}
|
|
29 |
//placement new
|
|
30 |
case RNewLddTest::EPlacementVectorNew:
|
|
31 |
{
|
|
32 |
return TestPlacementVectorNew();
|
|
33 |
}
|
|
34 |
//vector new
|
|
35 |
case RNewLddTest::EVectorNew:
|
|
36 |
{
|
|
37 |
return TestVectorNew();
|
|
38 |
}
|
|
39 |
case RNewLddTest::EPlacementNew:
|
|
40 |
{
|
|
41 |
return TestPlacementNew();
|
|
42 |
}
|
|
43 |
default:
|
|
44 |
break;
|
|
45 |
}
|
|
46 |
return KErrNone;
|
|
47 |
}
|
|
48 |
|
|
49 |
TInt DOperatorNewTest::TestNew()
|
|
50 |
{
|
|
51 |
Kern::Printf("::TestNew()");
|
|
52 |
NKern::ThreadEnterCS();
|
|
53 |
|
|
54 |
#define TEST_KERN_NEW_OOM(CLASS)\
|
|
55 |
{\
|
|
56 |
Kern::Printf("new " #CLASS);\
|
|
57 |
CLASS* p##CLASS=NULL;\
|
|
58 |
XTRAPD(r,XT_DEFAULT, p##CLASS = new CLASS);\
|
|
59 |
if(r!=KErrNone)\
|
|
60 |
{\
|
|
61 |
NKern::ThreadLeaveCS();\
|
|
62 |
return r;\
|
|
63 |
}\
|
|
64 |
if(p##CLASS)\
|
|
65 |
{\
|
|
66 |
delete p##CLASS;\
|
|
67 |
NKern::ThreadLeaveCS();\
|
|
68 |
return KErrGeneral;\
|
|
69 |
}\
|
|
70 |
}
|
|
71 |
|
|
72 |
//OOM tests: should(must) not throw
|
|
73 |
Kern::Printf("OOM Tests;");
|
|
74 |
|
|
75 |
TEST_KERN_NEW_OOM(XVeryLargeClassCtorAndDtor);
|
|
76 |
TEST_KERN_NEW_OOM(XVeryLargeClassCtorOnly);
|
|
77 |
TEST_KERN_NEW_OOM(XVeryLargeClassDtorOnly);
|
|
78 |
TEST_KERN_NEW_OOM(XVeryLargeClassNoTors);
|
|
79 |
|
|
80 |
Kern::Printf("non-OOM Tests;");
|
|
81 |
//Non-OOM:
|
|
82 |
|
|
83 |
#define TEST_KERN_NEW(CLASS, TEST_CTOR)\
|
|
84 |
{\
|
|
85 |
Kern::Printf("new " #CLASS);\
|
|
86 |
CLASS* p##CLASS=NULL;\
|
|
87 |
XTRAPD(r,XT_DEFAULT, p##CLASS = new CLASS);\
|
|
88 |
if(r!=KErrNone)\
|
|
89 |
{\
|
|
90 |
NKern::ThreadLeaveCS();\
|
|
91 |
return r;\
|
|
92 |
}\
|
|
93 |
if(p##CLASS==NULL)\
|
|
94 |
{\
|
|
95 |
NKern::ThreadLeaveCS();\
|
|
96 |
return KErrGeneral;\
|
|
97 |
}\
|
|
98 |
volatile TBool testCtor=(TEST_CTOR);\
|
|
99 |
if(testCtor && (p##CLASS->iState!=EConstructed) )\
|
|
100 |
{\
|
|
101 |
r=KErrGeneral;\
|
|
102 |
}\
|
|
103 |
delete p##CLASS;\
|
|
104 |
p##CLASS=NULL;\
|
|
105 |
if(r!=KErrNone)\
|
|
106 |
return r;\
|
|
107 |
}
|
|
108 |
|
|
109 |
TEST_KERN_NEW(XCtorAndDtor, ETrue);
|
|
110 |
TEST_KERN_NEW(XCtorOnly, ETrue);
|
|
111 |
TEST_KERN_NEW(XDtorOnly, EFalse);
|
|
112 |
TEST_KERN_NEW(XNoTors, EFalse);
|
|
113 |
|
|
114 |
NKern::ThreadLeaveCS();
|
|
115 |
return KErrNone;
|
|
116 |
}
|
|
117 |
|
|
118 |
TInt DOperatorNewTest::TestPlacementNew()
|
|
119 |
{
|
|
120 |
Kern::Printf("::TestPlacementNew");
|
|
121 |
|
|
122 |
#define TEST_KERN_PLACEMENT_NEW(CLASS, POST_CTOR, POST_DTOR) \
|
|
123 |
{\
|
|
124 |
Kern::Printf("new(someram) " #CLASS);\
|
|
125 |
NKern::ThreadEnterCS();\
|
|
126 |
void* someram = Kern::AllocZ(sizeof(CLASS));\
|
|
127 |
NKern::ThreadLeaveCS();\
|
|
128 |
if(!someram)\
|
|
129 |
return KErrNoMemory;\
|
|
130 |
\
|
|
131 |
CLASS* p##CLASS = new (someram) CLASS;\
|
|
132 |
TInt r=KErrNone;\
|
|
133 |
if(p##CLASS->iState != POST_CTOR)\
|
|
134 |
{\
|
|
135 |
r=KErrGeneral;\
|
|
136 |
}\
|
|
137 |
if(r==KErrNone)\
|
|
138 |
{\
|
|
139 |
p##CLASS->~CLASS();\
|
|
140 |
if(p##CLASS->iState != POST_DTOR)\
|
|
141 |
{\
|
|
142 |
r=KErrGeneral;\
|
|
143 |
}\
|
|
144 |
}\
|
|
145 |
NKern::ThreadEnterCS();\
|
|
146 |
Kern::Free(someram);\
|
|
147 |
NKern::ThreadLeaveCS();\
|
|
148 |
if(r != KErrNone)\
|
|
149 |
return r;\
|
|
150 |
}
|
|
151 |
|
|
152 |
TEST_KERN_PLACEMENT_NEW(XCtorAndDtor, EConstructed, EDeconstructed);
|
|
153 |
TEST_KERN_PLACEMENT_NEW(XCtorOnly, EConstructed, EConstructed);
|
|
154 |
TEST_KERN_PLACEMENT_NEW(XDtorOnly, ENull, EDeconstructed);
|
|
155 |
TEST_KERN_PLACEMENT_NEW(XNoTors, ENull, ENull);
|
|
156 |
|
|
157 |
return KErrNone;
|
|
158 |
}
|
|
159 |
|
|
160 |
TInt DOperatorNewTest::TestPlacementVectorNew()
|
|
161 |
{
|
|
162 |
|
|
163 |
Kern::Printf("::TestPlacementVectorNew");
|
|
164 |
|
|
165 |
//for vector placement new, emulator compilers
|
|
166 |
//allocate a cookie at start of buffer.
|
|
167 |
//this seems wrong since the cookie is an internal compiller
|
|
168 |
//detail which the user should not need to know about
|
|
169 |
#if defined(__WINSCW__) || defined(__VC32__)
|
|
170 |
Kern::Printf("Not running on emulator. WINSCW and Visual studio\n insert a cookie for placement vector new");
|
|
171 |
|
|
172 |
#else
|
|
173 |
|
|
174 |
#define TEST_KERN_PLACEMENT_VECTOR_NEW(CLASS, ARRAY_LENGTH, POST_CTOR, POST_DTOR) \
|
|
175 |
{\
|
|
176 |
NKern::ThreadEnterCS();\
|
|
177 |
void* someram = Kern::AllocZ(sizeof(CLASS) * (ARRAY_LENGTH));\
|
|
178 |
NKern::ThreadLeaveCS();\
|
|
179 |
if(someram==NULL)\
|
|
180 |
return KErrNoMemory;\
|
|
181 |
\
|
|
182 |
TInt r = KErrNone;\
|
|
183 |
Kern::Printf("new (someram) " #CLASS "[%d]", ARRAY_LENGTH);\
|
|
184 |
\
|
|
185 |
CLASS* p##CLASS = new (someram) CLASS[ARRAY_LENGTH];\
|
|
186 |
for(TInt i=0; i<(ARRAY_LENGTH); ++i)\
|
|
187 |
{\
|
|
188 |
if(p##CLASS[i].iState != POST_CTOR)\
|
|
189 |
{\
|
|
190 |
r=KErrGeneral;\
|
|
191 |
break;\
|
|
192 |
}\
|
|
193 |
p##CLASS[i].~CLASS();\
|
|
194 |
if(p##CLASS[i].iState != POST_DTOR)\
|
|
195 |
{\
|
|
196 |
r=KErrGeneral;\
|
|
197 |
break;\
|
|
198 |
}\
|
|
199 |
}\
|
|
200 |
NKern::ThreadEnterCS();\
|
|
201 |
Kern::Free(someram);\
|
|
202 |
NKern::ThreadLeaveCS();\
|
|
203 |
if(r!=KErrNone)\
|
|
204 |
return r;\
|
|
205 |
}\
|
|
206 |
|
|
207 |
TEST_KERN_PLACEMENT_VECTOR_NEW(XCtorAndDtor, KTestArrayLength, EConstructed, EDeconstructed);
|
|
208 |
TEST_KERN_PLACEMENT_VECTOR_NEW(XCtorOnly, KTestArrayLength, EConstructed, EConstructed);
|
|
209 |
TEST_KERN_PLACEMENT_VECTOR_NEW(XDtorOnly, KTestArrayLength, ENull, EDeconstructed);
|
|
210 |
TEST_KERN_PLACEMENT_VECTOR_NEW(XNoTors, KTestArrayLength, ENull, ENull);
|
|
211 |
|
|
212 |
#endif
|
|
213 |
|
|
214 |
return KErrNone;
|
|
215 |
}
|
|
216 |
TInt DOperatorNewTest::TestVectorNew()
|
|
217 |
{
|
|
218 |
//OOM testing
|
|
219 |
Kern::Printf("::TestVectorNew()");
|
|
220 |
Kern::Printf("OOM test");
|
|
221 |
|
|
222 |
TInt r=KErrNone;
|
|
223 |
|
|
224 |
#define TEST_KERN_VECTOR_NEW_OOM(CLASS, ARRAY_LENGTH)\
|
|
225 |
{\
|
|
226 |
Kern::Printf("new " #CLASS "[%d]", ARRAY_LENGTH);\
|
|
227 |
CLASS* p##CLASS = NULL;\
|
|
228 |
NKern::ThreadEnterCS();\
|
|
229 |
XTRAP(r,XT_DEFAULT,p##CLASS = new CLASS[ARRAY_LENGTH]; );\
|
|
230 |
if(p##CLASS)\
|
|
231 |
{\
|
|
232 |
r=KErrGeneral;\
|
|
233 |
delete p##CLASS;\
|
|
234 |
}\
|
|
235 |
NKern::ThreadLeaveCS();\
|
|
236 |
if(r!=KErrNone)\
|
|
237 |
{\
|
|
238 |
return r;\
|
|
239 |
}\
|
|
240 |
}\
|
|
241 |
|
|
242 |
TEST_KERN_VECTOR_NEW_OOM(XCtorAndDtor, KOOMArraySize);
|
|
243 |
TEST_KERN_VECTOR_NEW_OOM(XCtorOnly, KOOMArraySize);
|
|
244 |
TEST_KERN_VECTOR_NEW_OOM(XDtorOnly, KOOMArraySize);
|
|
245 |
TEST_KERN_VECTOR_NEW_OOM(XNoTors, KOOMArraySize);
|
|
246 |
|
|
247 |
|
|
248 |
//non-OOM:
|
|
249 |
Kern::Printf("non-OOM test");
|
|
250 |
|
|
251 |
#define TEST_KERN_VECTOR_NEW(CLASS, ARRAY_LENGTH, TEST_CTOR)\
|
|
252 |
{\
|
|
253 |
Kern::Printf("new " #CLASS "[%d]", ARRAY_LENGTH);\
|
|
254 |
CLASS* p##CLASS = NULL;\
|
|
255 |
NKern::ThreadEnterCS();\
|
|
256 |
XTRAP(r,XT_DEFAULT,p##CLASS = new CLASS[ARRAY_LENGTH]; );\
|
|
257 |
NKern::ThreadLeaveCS();\
|
|
258 |
if(p##CLASS == NULL)\
|
|
259 |
{\
|
|
260 |
return KErrNoMemory;\
|
|
261 |
}\
|
|
262 |
\
|
|
263 |
TBool testCtor=(TEST_CTOR);\
|
|
264 |
if(testCtor)\
|
|
265 |
{\
|
|
266 |
for(TInt i=0; i<(ARRAY_LENGTH); ++i)\
|
|
267 |
{\
|
|
268 |
if(p##CLASS[i].iState!= EConstructed)\
|
|
269 |
{\
|
|
270 |
r=KErrGeneral;\
|
|
271 |
break;\
|
|
272 |
}\
|
|
273 |
}\
|
|
274 |
}\
|
|
275 |
\
|
|
276 |
NKern::ThreadEnterCS();\
|
|
277 |
delete[] p##CLASS;\
|
|
278 |
NKern::ThreadLeaveCS();\
|
|
279 |
p##CLASS=NULL;\
|
|
280 |
if(r!=KErrNone)\
|
|
281 |
{\
|
|
282 |
return r;\
|
|
283 |
}\
|
|
284 |
}\
|
|
285 |
|
|
286 |
TEST_KERN_VECTOR_NEW(XCtorAndDtor, KTestArrayLength, ETrue);
|
|
287 |
TEST_KERN_VECTOR_NEW(XCtorOnly, KTestArrayLength, ETrue);
|
|
288 |
TEST_KERN_VECTOR_NEW(XDtorOnly, KTestArrayLength, EFalse);
|
|
289 |
TEST_KERN_VECTOR_NEW(XNoTors, KTestArrayLength, EFalse);
|
|
290 |
|
|
291 |
return KErrNone;
|
|
292 |
}
|
|
293 |
|
|
294 |
TInt DOperatorNewTestFactory::Create(DLogicalChannelBase*& aChannel)
|
|
295 |
//
|
|
296 |
// Create a new DTest on this logical device
|
|
297 |
//
|
|
298 |
{
|
|
299 |
aChannel=new DOperatorNewTest();
|
|
300 |
return aChannel?KErrNone:KErrNoMemory;
|
|
301 |
}
|
|
302 |
|
|
303 |
TInt DOperatorNewTestFactory::Install()
|
|
304 |
//
|
|
305 |
// Install the LDD - overriding pure virtual
|
|
306 |
//
|
|
307 |
{
|
|
308 |
iVersion = TVersion(0,1,1);
|
|
309 |
return SetName(&KLddName);
|
|
310 |
}
|
|
311 |
|
|
312 |
void DOperatorNewTestFactory::GetCaps(TDes8& /*aDes*/) const
|
|
313 |
//
|
|
314 |
// Get capabilities - overriding pure virtual
|
|
315 |
//
|
|
316 |
{
|
|
317 |
//not supported
|
|
318 |
}
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
DECLARE_STANDARD_LDD()
|
|
323 |
{
|
|
324 |
//create factory here.
|
|
325 |
return new DOperatorNewTestFactory;
|
|
326 |
}
|
|
327 |
|
|
328 |
|