|
1 // Copyright (c) 2003-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 // e32test\stack\t_stacksize.cpp |
|
15 // Overview: |
|
16 // Verifies the correct implementation of CreateStackOverride method of RProcess. |
|
17 // Meanings of constants: |
|
18 // KDefaultStackSize: |
|
19 // - System wide default stack size in actual version; |
|
20 // KNumberOfFitIteration: |
|
21 // - Number of DummyRecursion which can fit in KDefaultStackSize. |
|
22 // Value = KDefaultStackSize / 2KB - 1 |
|
23 // KNumberOfUnfitIteration: |
|
24 // - Number of DummyRecursion which is raised a Panic based on stack overflow. |
|
25 // Value = KDefaultStackSize / 2KB rounded up to nearest integer |
|
26 // Details: |
|
27 // ETestProcess1: Create a process with original RProcess::Create() and start it |
|
28 // - it passes with KNumberOfFitIteration DummyRecursion . |
|
29 // ETestProcess2: Create a process with RProcess::CreateWithStackOverride(), default |
|
30 // stack size and start it |
|
31 // - it passes with KNumberOfFitIteration DummyRecursion. |
|
32 // ETestProcess3: Create a process with original RProcess::Create() and start it |
|
33 // - it raised Panic on Stack overflow with KNumberOfUnfitIteration DummyRecursion. |
|
34 // ETestProcess4: Create a process with RProcess::CreateWithStackOverride(), default |
|
35 // stack size and start it |
|
36 // - it raised Panic on Stack overflow with KNumberOfUnfitIteration DummyRecursion. |
|
37 // ETestProcess5: Create a process with RProcess::CreateWithStackOverride(), 2*KDefaultStackSize |
|
38 // stack and start it |
|
39 // - it passes with KNumberOfUnfitIteration DummyRecursion. |
|
40 // ETestProcess6: Create a process with RProcess::CreateWithStackOverride(), -2*KDefaultStackSize |
|
41 // stack. |
|
42 // - the process creation interrupted with KErrArgument error code |
|
43 // ETestProcess7: Create a process with RProcess::CreateWithStackOverride(), KDefaultStackSize/2 |
|
44 // stack and start it |
|
45 // - it passes with KNumberOfFitIteration DummyRecursion, because the process will be |
|
46 // create with (App. image) default stack size. |
|
47 // Platforms/Drives/Compatibility: |
|
48 // It is won't work on emulator, because the unlimited stack size. |
|
49 // Assumptions/Requirement/Pre-requisites: |
|
50 // No |
|
51 // Failures and causes: |
|
52 // Failures of this test will indicate defects in the implementation of CreateWithStackOverride(). |
|
53 // Base Port information: |
|
54 // No? |
|
55 // |
|
56 // |
|
57 |
|
58 #include <e32test.h> |
|
59 #include "u32std.h" |
|
60 #include <u32hal.h> |
|
61 #include <e32svr.h> |
|
62 |
|
63 LOCAL_D RTest test(_L("T_STACKSIZE")); |
|
64 LOCAL_D RTest test2(_L("*** T_STACKSIZE SLAVE ***")); |
|
65 |
|
66 const TInt KNumberOfFitIteration = KDefaultStackSize / 2048 - 1; |
|
67 const TInt KNumberOfUnfitIteration = (KDefaultStackSize + 2047) / 2048; |
|
68 |
|
69 enum TTestProcessFunctions |
|
70 { |
|
71 ETestProcess1, |
|
72 ETestProcess2, |
|
73 ETestProcess3, |
|
74 ETestProcess4, |
|
75 ETestProcess5, |
|
76 ETestProcess6, |
|
77 ETestProcess7, |
|
78 }; |
|
79 |
|
80 class RTestProcess : public RProcess |
|
81 { |
|
82 public: |
|
83 TInt Create(TTestProcessFunctions aFunction, TInt aStackSize=0, TInt aArg1=-1,TInt aArg2=-1); |
|
84 }; |
|
85 |
|
86 TInt RTestProcess::Create(TTestProcessFunctions aFunction, TInt aStackSize, TInt aArg1,TInt aArg2) |
|
87 { |
|
88 |
|
89 test.Printf(_L("RTestProcess::Create started with stack size:%d bytes\n") |
|
90 , (0 == aStackSize ? KDefaultStackSize : aStackSize ) |
|
91 ); |
|
92 if(aArg1==-1) |
|
93 aArg1 = RProcess().Id(); |
|
94 TBuf<512> commandLine; |
|
95 commandLine.Num((TInt)aFunction); |
|
96 commandLine.Append(_L(" ")); |
|
97 commandLine.AppendNum(aArg1); |
|
98 commandLine.Append(_L(" ")); |
|
99 commandLine.AppendNum(aArg2); |
|
100 |
|
101 TFileName filename(RProcess().FileName()); |
|
102 TInt pos=filename.LocateReverse(TChar('\\')); |
|
103 filename.SetLength(pos+1); |
|
104 filename+=_L("T_STACKSIZE.EXE"); |
|
105 |
|
106 TInt r=KErrNone; |
|
107 switch (aFunction) |
|
108 { |
|
109 case ETestProcess1: |
|
110 test.Printf(_L("Call original Create.\n")); |
|
111 r = RProcess::Create(filename,commandLine); |
|
112 break; |
|
113 |
|
114 case ETestProcess2: |
|
115 test.Printf(_L("Call CreateWithStackOverride\n")); |
|
116 r = RProcess::CreateWithStackOverride(filename, commandLine, TUidType(), aStackSize, EOwnerProcess); |
|
117 break; |
|
118 |
|
119 case ETestProcess3: |
|
120 test.Printf(_L("Call original Create.\n")); |
|
121 r = RProcess::Create(filename,commandLine); |
|
122 break; |
|
123 |
|
124 case ETestProcess4: |
|
125 test.Printf(_L("Call CreateWithStackOverride\n")); |
|
126 r = RProcess::CreateWithStackOverride(filename, commandLine, TUidType(), aStackSize, EOwnerProcess); |
|
127 break; |
|
128 |
|
129 case ETestProcess5: |
|
130 test.Printf(_L("Call CreateWithStackOverride\n")); |
|
131 r = RProcess::CreateWithStackOverride(filename, commandLine, TUidType(), aStackSize, EOwnerProcess); |
|
132 break; |
|
133 |
|
134 case ETestProcess6: |
|
135 test.Printf(_L("Call CreateWithStackOverride\n")); |
|
136 r = RProcess::CreateWithStackOverride(filename, commandLine, TUidType(), aStackSize, EOwnerProcess); |
|
137 break; |
|
138 |
|
139 case ETestProcess7: |
|
140 test.Printf(_L("Call CreateWithStackOverride\n")); |
|
141 r = RProcess::CreateWithStackOverride(filename, commandLine, TUidType(), aStackSize, EOwnerProcess); |
|
142 break; |
|
143 |
|
144 default: |
|
145 User::Panic(_L("T_STACKSIZE"),1); |
|
146 |
|
147 } |
|
148 |
|
149 test.Printf(_L("RTestProcess::Create end.\n")); |
|
150 return r; |
|
151 } |
|
152 |
|
153 |
|
154 TInt DummyRecursion(TInt aA) |
|
155 { |
|
156 TBuf8<2040> gobble; // gobble 2K of stack |
|
157 gobble.Append(TChar(aA)); // stop compiler optimising out gobble buffer |
|
158 if (aA <= 1) |
|
159 return aA; |
|
160 return 1 + DummyRecursion(aA-1); |
|
161 } |
|
162 |
|
163 TInt DoTestProcess(TInt aTestNum,TInt aArg1,TInt aArg2) |
|
164 { |
|
165 (void)aArg1; |
|
166 (void)aArg2; |
|
167 |
|
168 |
|
169 switch(aTestNum) |
|
170 { |
|
171 case ETestProcess1: |
|
172 { |
|
173 test2.Printf(_L("ETestProcess1 started with %d recursion...\n"), KNumberOfFitIteration); |
|
174 test2(DummyRecursion(KNumberOfFitIteration)==KNumberOfFitIteration); |
|
175 break; |
|
176 } |
|
177 |
|
178 case ETestProcess2: |
|
179 { |
|
180 test2.Printf(_L("ETestProcess2 started with %d recursion...\n"), KNumberOfFitIteration); |
|
181 test2(DummyRecursion(KNumberOfFitIteration)==KNumberOfFitIteration); |
|
182 break; |
|
183 } |
|
184 |
|
185 case ETestProcess3: |
|
186 { |
|
187 test2.Printf(_L("ETestProcess3 started with %d recusion...\n"), KNumberOfUnfitIteration); |
|
188 test2(DummyRecursion(KNumberOfUnfitIteration)==KNumberOfUnfitIteration); |
|
189 break; |
|
190 } |
|
191 |
|
192 case ETestProcess4: |
|
193 { |
|
194 test2.Printf(_L("ETestProcess4 started with %d recursion...\n"), KNumberOfUnfitIteration); |
|
195 test2(DummyRecursion(KNumberOfUnfitIteration)==KNumberOfUnfitIteration); |
|
196 break; |
|
197 } |
|
198 |
|
199 case ETestProcess5: |
|
200 { |
|
201 test2.Printf(_L("ETestProcess5 started with %d recursion...\n"), KNumberOfUnfitIteration); |
|
202 test2(DummyRecursion(KNumberOfUnfitIteration)==KNumberOfUnfitIteration); |
|
203 break; |
|
204 } |
|
205 |
|
206 case ETestProcess6: |
|
207 { |
|
208 test2.Printf(_L("ETestProcess6 started with %d recursion...\n"), KNumberOfFitIteration); |
|
209 test2(DummyRecursion(KNumberOfFitIteration)==KNumberOfFitIteration); |
|
210 break; |
|
211 } |
|
212 |
|
213 case ETestProcess7: |
|
214 { |
|
215 |
|
216 test2.Printf(_L("ETestProcess7 started with %d recursion\n"), KNumberOfFitIteration); |
|
217 test2.Printf(_L("(it is raised a Panic with %d bytes stack)...\n"), KDefaultStackSize/2); |
|
218 test2(DummyRecursion(KNumberOfFitIteration)==KNumberOfFitIteration); |
|
219 break; |
|
220 } |
|
221 |
|
222 default: |
|
223 User::Panic(_L("T_STACKSIZE"),1); |
|
224 } |
|
225 |
|
226 test2.Printf(_L("\n\t finished.\n")); |
|
227 |
|
228 return KErrNone; |
|
229 } |
|
230 |
|
231 GLDEF_C TInt E32Main() |
|
232 { |
|
233 |
|
234 |
|
235 TBuf16<512> cmd; |
|
236 User::CommandLine(cmd); |
|
237 if(cmd.Length() && TChar(cmd[0]).IsDigit()) |
|
238 { |
|
239 test2.Title(); |
|
240 test2.Start(_L("Slave process started...")); |
|
241 TInt function = -1; |
|
242 TInt arg1 = -1; |
|
243 TInt arg2 = -1; |
|
244 TLex lex(cmd); |
|
245 lex.Val(function); |
|
246 lex.SkipSpace(); |
|
247 lex.Val(arg1); |
|
248 lex.SkipSpace(); |
|
249 lex.Val(arg2); |
|
250 int r = DoTestProcess(function,arg1,arg2); |
|
251 test2.End(); |
|
252 return r; |
|
253 } |
|
254 |
|
255 test.Title(); |
|
256 |
|
257 RTestProcess rogueP; |
|
258 TRequestStatus rendezvous; |
|
259 |
|
260 test.Start(_L("Create process with original Create and default stack size")); |
|
261 TInt r = rogueP.Create(ETestProcess1, 0 ); |
|
262 test(r==KErrNone); |
|
263 rogueP.Rendezvous(rendezvous); |
|
264 rogueP.Resume(); |
|
265 User::WaitForRequest(rendezvous); |
|
266 test.Printf(_L("ExitType:%d\n"),rogueP.ExitType() ); |
|
267 test(rogueP.ExitType()==EExitKill); |
|
268 |
|
269 test.Next(_L("Create process with CreateWithStackOverride and default stack size")); |
|
270 r = rogueP.Create(ETestProcess2, 0 ); |
|
271 test(r==KErrNone); |
|
272 rogueP.Rendezvous(rendezvous); |
|
273 rogueP.Resume(); |
|
274 User::WaitForRequest(rendezvous); |
|
275 test.Printf(_L("ExitType:%d\n"),rogueP.ExitType() ); |
|
276 test(rogueP.ExitType()==EExitKill); |
|
277 |
|
278 test.Next(_L("Create process with original Create and default stack size")); |
|
279 r = rogueP.Create(ETestProcess3, 0 ); |
|
280 test(r==KErrNone); |
|
281 rogueP.Rendezvous(rendezvous); |
|
282 rogueP.Resume(); |
|
283 User::WaitForRequest(rendezvous); |
|
284 test.Printf(_L("ExitType:%d\n"),rogueP.ExitType() ); |
|
285 #if !defined(__WINS__) |
|
286 test(rogueP.ExitType()==EExitPanic); |
|
287 #else |
|
288 test(rogueP.ExitType()==EExitKill); |
|
289 #endif |
|
290 |
|
291 test.Next(_L("Create process with CreateWithStackOverride and default stack size")); |
|
292 r = rogueP.Create(ETestProcess4, 0 ); |
|
293 test(r==KErrNone); |
|
294 rogueP.Rendezvous(rendezvous); |
|
295 rogueP.Resume(); |
|
296 User::WaitForRequest(rendezvous); |
|
297 test.Printf(_L("ExitType:%d\n"),rogueP.ExitType() ); |
|
298 |
|
299 #if !defined(__WINS__) |
|
300 test(rogueP.ExitType()==EExitPanic); |
|
301 #else |
|
302 test(rogueP.ExitType()==EExitKill); |
|
303 #endif |
|
304 |
|
305 |
|
306 test.Next(_L("Create process with CreateWithStackOverride and 2 * KDefaultStackSize stack size")); |
|
307 r = rogueP.Create(ETestProcess5, 2 * KDefaultStackSize ); |
|
308 test(r==KErrNone); |
|
309 rogueP.Rendezvous(rendezvous); |
|
310 rogueP.Resume(); |
|
311 User::WaitForRequest(rendezvous); |
|
312 test.Printf(_L("ExitType:%d\n"),rogueP.ExitType() ); |
|
313 test(rogueP.ExitType()==EExitKill); |
|
314 |
|
315 #if !defined(__WINS__) |
|
316 test.Next(_L("Create process with CreateWithStackOverride and negative stack size")); |
|
317 r = rogueP.Create(ETestProcess6, - 2 * KDefaultStackSize ); |
|
318 test(r==KErrArgument); |
|
319 #endif |
|
320 |
|
321 test.Next(_L("Create process with CreateWithStackOverride and KDefaultStackSize/2 stack size")); |
|
322 r = rogueP.Create(ETestProcess7, KDefaultStackSize / 2 ); |
|
323 test(r==KErrNone); |
|
324 rogueP.Rendezvous(rendezvous); |
|
325 rogueP.Resume(); |
|
326 User::WaitForRequest(rendezvous); |
|
327 test.Printf(_L("ExitType:%d\n"),rogueP.ExitType() ); |
|
328 test(rogueP.ExitType()==EExitKill); |
|
329 |
|
330 test.Printf(_L("Test finished.\n")); |
|
331 test.End(); |
|
332 |
|
333 return(0); |
|
334 } |
|
335 |