First public contribution.
1 // Copyright (c) 1994-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\system\t_env.cpp
16 // Test RProcess parameters
20 // - Create a thread that causes a variety of panics. Verify that the exit
21 // reason is as expected.
22 // - Create a process that causes a variety of panics. Verify that the results
24 // - Test passing 16 bit and 8 bit descriptors to another process. Verify the
25 // text and other results are as expected.
26 // - Verify that an invalid read of a descriptor by a process causes a panic.
27 // - Test passing zero length data to a separate process works as expected.
28 // - Test that passing each of a mutex, semaphore, file handle and chunk to a
29 // separate process works as expected.
30 // Platforms/Drives/Compatibility:
32 // Assumptions/Requirement/Pre-requisites:
33 // Failures and causes:
34 // Base Port information:
39 #include <e32std_private.h>
42 #include <e32msgqueue.h>
46 #if defined (__WINS__)
47 #define PDD_NAME _L("ECDRV.PDD")
48 #define LDD_NAME _L("ECOMM.LDD")
50 #define PDD_NAME _L("EUART")
51 #define LDD_NAME _L("ECOMM")
55 LOCAL_D RTest test(_L("T_ENV"));
58 _LIT(KProcName, "t_env_child.exe");
59 _LIT(KThreadName, "t_env_panic_thread");
60 _LIT(KQueueName, "testqueue");
61 _LIT(KMutexName, "testmutex");
62 _LIT(KSemName, "testsemaphore");
63 _LIT(KChunkName, "testchunk");
64 _LIT(KFileName, "c:\\testfile");
66 const TInt KHeapSize=0x2000;
73 TData(TInt aTest, RProcess& aProcess);
78 TData::TData(TInt aTest, RProcess& aProcess) : iTest(aTest), iProcess(aProcess)
87 void SetupParameters(RProcess& aNewProcess);
90 void Command(TInt aCommand);
93 RMsgQueue<TInt> iCommandQueue;
94 RMsgQueue<TInt> iIntQueue;
102 void Handles::Command(TInt aC)
104 iCommandQueue.SendBlocking(aC);
107 void Handles::SetupParameters(RProcess& aNewProcess)
109 aNewProcess.SetParameter(1, iCommandQueue);
110 aNewProcess.SetParameter(2, iIntQueue);
111 aNewProcess.SetParameter(3, iMutex);
112 aNewProcess.SetParameter(4, iSem);
113 aNewProcess.SetParameter(5, iChunk);
114 aNewProcess.SetParameter(7, iSession);
115 aNewProcess.SetParameter(8, iFile);
120 _LIT8(KTestData,"test data");
124 TInt ret = iCommandQueue.CreateGlobal(KNullDesC, 10, EOwnerProcess);
125 test(ret == KErrNone);
127 ret = iIntQueue.CreateGlobal(KQueueName,1);
128 test(ret == KErrNone);
130 ret = iMutex.CreateGlobal(KMutexName);
131 test(ret == KErrNone);
133 ret = iSem.CreateGlobal(KSemName,0);
134 test(ret == KErrNone);
136 ret = iChunk.CreateGlobal(KChunkName, 1024, 2048);
137 test(ret == KErrNone);
139 ret = iSession.Connect();
140 test(ret == KErrNone);
142 ret = iSession.ShareProtected();
143 test(ret == KErrNone);
145 ret = iFile.Open(iSession, KFileName, EFileStreamText|EFileWrite|EFileShareAny);
146 if (ret == KErrNotFound) // file does not exist - create it
147 ret = iFile.Create(iSession, KFileName, EFileStreamText|EFileWrite|EFileShareAny);
148 test(ret == KErrNone);
149 ret = iFile.Write(0, KTestData);
150 test(ret == KErrNone);
155 iCommandQueue.Close();
164 LOCAL_C TInt testSetParameterPanics(TAny* aData)
166 const TData* data = (const TData*)aData;
169 case 0: //try and pass a non local handle
171 RMsgQueue<TInt> localMsgQueue;
172 localMsgQueue.CreateLocal(1);
173 data->iProcess.SetParameter(1, localMsgQueue); //should panic with plat security panic
177 case 1: //out of range slot
179 RMsgQueue<TInt> globalMsgQueue;
180 globalMsgQueue.CreateGlobal(KNullDesC, 1);
181 data->iProcess.SetParameter(-1, globalMsgQueue); //should panic with range error
187 RMsgQueue<TInt> globalMsgQueue;
188 globalMsgQueue.CreateGlobal(KNullDesC, 1);
189 data->iProcess.SetParameter(1234, globalMsgQueue); //should panic with range error
195 RMsgQueue<TInt> globalMsgQueue;
196 globalMsgQueue.CreateGlobal(KNullDesC, 1);
197 data->iProcess.SetParameter(1, globalMsgQueue);
198 data->iProcess.SetParameter(1, globalMsgQueue); //panic, in use
204 TPtrC8 bad((const TUint8*)0xfeed,4);
205 data->iProcess.SetParameter(1, bad);
209 case 5: //slot 0 is for the command line
211 RMsgQueue<TInt> globalMsgQueue;
212 globalMsgQueue.CreateGlobal(KNullDesC, 1);
213 data->iProcess.SetParameter(0, globalMsgQueue); //panic, in use
224 GLDEF_C TInt E32Main()
228 test.Start(_L("Process Parameters"));
230 test.Next(_L("Test Panics on a set"));
232 TBool jit = User::JustInTime();
233 User::SetJustInTime(EFalse);
236 TInt ret = p.Create(KProcName, KProcName);
237 test(ret == KErrNone);
238 for (i = 0; i < 6; i++)
240 test.Printf(_L("panic test number %d\n"), i);
243 ret = thread.Create(KThreadName, testSetParameterPanics, KDefaultStackSize, KHeapSize, KHeapSize, &data);
244 test(KErrNone == ret);
248 User::WaitForRequest(stat);
249 test.Printf(_L("exit type is %d, stat is %d"), thread.ExitType(), stat.Int());
250 test (thread.ExitType() == EExitPanic);
254 test (thread.ExitReason() == EPlatformSecurityTrap);
259 test (thread.ExitReason() == EParameterSlotRange);
264 test (thread.ExitReason() == EParameterSlotInUse);
268 test (thread.ExitReason() == ECausedException);
271 CLOSE_AND_WAIT(thread);
276 test.Next(_L("launch panicing process"));
282 for (i = 0; i < 1; i++)
285 ret = p.Create(KProcName, KNullDesC);
286 test(ret == KErrNone);
288 h.SetupParameters(p);
290 User::WaitForRequest(stat);
291 test(p.ExitType()==EExitPanic);
292 test(p.ExitReason()==EParameterSlotRange);
295 User::SetJustInTime(jit);
297 test.Next(_L("test 16 bit descriptor"));
299 ret = p.Create(KProcName, KNullDesC);
300 test(ret == KErrNone);
302 h.SetupParameters(p);
303 p.SetParameter(15, _L("16 bit text"));
305 User::WaitForRequest(stat);
306 test(p.ExitType()==EExitKill);
307 test(p.ExitReason()==KErrNone);
310 test.Next(_L("test 8 bit descriptor"));
312 ret = p.Create(KProcName, KNullDesC);
313 test(ret == KErrNone);
315 h.SetupParameters(p);
316 p.SetParameter(15, _L8("8 bit text"));
318 User::WaitForRequest(stat);
319 test(p.ExitType()==EExitKill);
320 test(p.ExitReason()==KErrNone);
324 test.Next(_L("test bad read of descriptor"));
326 ret = p.Create(KProcName, KNullDesC);
327 test(ret == KErrNone);
329 h.SetupParameters(p);
330 p.SetParameter(15, _L8("aa"));
332 User::WaitForRequest(stat);
333 test(p.ExitType()==EExitPanic);
334 test(p.ExitReason()==ECausedException);
337 test.Next(_L("test zero length data"));
339 ret = p.Create(KProcName, KNullDesC);
340 test(ret == KErrNone);
342 h.SetupParameters(p);
343 p.SetParameter(15, KNullDesC);
345 User::WaitForRequest(stat);
346 test(p.ExitType()==EExitKill);
347 test(p.ExitReason()==KErrNone);
350 test.Next(_L("test reserved command line"));
352 ret = p.Create(KProcName, KNullDesC);
353 test(ret == KErrNone);
355 h.SetupParameters(p);
357 User::WaitForRequest(stat);
358 test(p.ExitType()==EExitKill);
359 test(p.ExitReason()==KErrNone);
363 test.Next(_L("test mutex"));
365 ret = p.Create(KProcName, KNullDesC);
366 test(ret == KErrNone);
368 h.SetupParameters(p);
370 User::WaitForRequest(stat);
371 test(p.ExitType()==EExitKill);
372 test(p.ExitReason()==KErrNone);
376 test.Next(_L("test semaphore"));
378 ret = p.Create(KProcName, KNullDesC);
379 test(ret == KErrNone);
381 h.SetupParameters(p);
383 User::WaitForRequest(stat);
384 test(p.ExitType()==EExitKill);
385 test(p.ExitReason()==KErrNone);
388 test.Next(_L("test file handle"));
390 ret = p.Create(KProcName, KNullDesC);
391 test(ret == KErrNone);
393 h.SetupParameters(p);
395 User::WaitForRequest(stat);
396 test(p.ExitType()==EExitKill);
397 test(p.ExitReason()==KErrNone);
400 test.Next(_L("test chunk"));
402 ret = p.Create(KProcName, KNullDesC);
403 test(ret == KErrNone);
405 h.SetupParameters(p);
407 User::WaitForRequest(stat);
408 test(p.ExitType()==EExitKill);
409 test(p.ExitReason()==KErrNone);