Update contrib.
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 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\secure\t_rendezvous.cpp
16 // Test RThread and RProcess rendezvous
20 // - Create a thread, request rendezvous, cancel rendezvous, request rendezvous
21 // again, resume thread and wait for rendezvous, verify results as expected.
22 // - Create a thread, request rendezvous, allow thread to die, verify results.
23 // - Create a thread, request rendezvous, allow thread to finish, verify results.
24 // - Create a process, request rendezvous, cancel rendezvous, request rendezvous
25 // again, resume process and wait for rendezvous, verify results as expected.
26 // - Create a process, request rendezvous, allow process to die, verify results.
27 // - Create a process, request rendezvous, allow process to finish, verify results.
28 // Platforms/Drives/Compatibility:
30 // Assumptions/Requirement/Pre-requisites:
31 // Failures and causes:
32 // Base Port information:
38 LOCAL_D RTest test(_L("T_RENDEZVOUS"));
40 _LIT(KSyncMutext,"T_RENDEZVOUS-sync-mutex");
46 if(syncMutex.OpenGlobal(KSyncMutext)!=KErrNone)
53 const TInt KRendezvousOk = 1;
55 TInt ThreadRendezvous(TAny *)
57 RThread::Rendezvous(KRendezvousOk);
62 TInt ThreadDie(TAny *)
64 User::Panic(_L("ThreadDie"),KErrDied);
68 TInt ThreadFinish(TAny *)
73 void TestThreadRendezvous()
75 TRequestStatus rendezvousStatus;
76 TRequestStatus rendezvousStatusCancel;
77 TRequestStatus logonStatus;
83 test.Start(_L("Create thread 'ThreadRendezvous'"));
84 r=thread.Create(_L("ThreadRendezvous"),ThreadRendezvous,KDefaultStackSize,KDefaultStackSize,KDefaultStackSize,NULL);
87 test.Next(_L("Request rendezvous"));
88 thread.Rendezvous(rendezvousStatusCancel);
89 test(rendezvousStatusCancel==KRequestPending);
91 test.Next(_L("Cancel rendezvous request"));
92 r = thread.RendezvousCancel(rendezvousStatusCancel);
94 test(rendezvousStatusCancel==KErrNone);
96 test.Next(_L("Request rendezvous again"));
97 thread.Rendezvous(rendezvousStatus);
98 test(rendezvousStatus==KRequestPending);
100 test.Next(_L("Also logon to thread"));
101 thread.Logon(logonStatus);
102 test(logonStatus==KRequestPending);
104 test.Next(_L("Resume thread and wait for rendezvous..."));
107 User::WaitForRequest(rendezvousStatus,logonStatus);
108 test(rendezvousStatus==KRendezvousOk);
109 test(logonStatus==KRequestPending);
110 test(rendezvousStatusCancel==KErrNone);
112 test.Next(_L("Rendezvous OK, now wait for thread to end..."));
114 User::WaitForRequest(logonStatus);
115 test(logonStatus==KErrNone);
116 test(rendezvousStatusCancel==KErrNone);
118 CLOSE_AND_WAIT(thread);
122 test.Next(_L("Create thread 'ThreadDie'"));
123 r=thread.Create(_L("ThreadDie"),ThreadDie,KDefaultStackSize,KDefaultStackSize,KDefaultStackSize,NULL);
126 test.Next(_L("Request rendezvous"));
127 thread.Rendezvous(rendezvousStatus);
128 test(rendezvousStatus==KRequestPending);
130 test.Next(_L("Resume thread and wait for thread to die..."));
131 TBool jit = User::JustInTime();
132 User::SetJustInTime(EFalse);
134 User::WaitForRequest(rendezvousStatus);
135 User::SetJustInTime(jit);
136 test(rendezvousStatus==KErrDied);
137 test(thread.ExitReason()==KErrDied);
138 test(thread.ExitType()==EExitPanic);
140 CLOSE_AND_WAIT(thread);
144 test.Next(_L("Create thread 'ThreadFinish'"));
145 r=thread.Create(_L("ThreadFinish"),ThreadFinish,KDefaultStackSize,KDefaultStackSize,KDefaultStackSize,NULL);
148 test.Next(_L("Request rendezvous"));
149 thread.Rendezvous(rendezvousStatus);
150 test(rendezvousStatus==KRequestPending);
152 test.Next(_L("Resume thread and wait for thread to finish..."));
154 User::WaitForRequest(rendezvousStatus);
155 test(rendezvousStatus==KErrNone);
156 test(thread.ExitReason()==KErrNone);
157 test(thread.ExitType()==EExitKill);
159 CLOSE_AND_WAIT(thread);
167 enum TTestProcessFunctions
169 ETestProcessRendezvous,
174 #include "testprocess.h"
176 TInt DoTestProcess(TInt aTestNum,TInt aArg1,TInt aArg2)
178 (void)aArg1; // Keep compiler quiet about unused parameters
183 case ETestProcessRendezvous:
184 RProcess::Rendezvous(KRendezvousOk);
188 case ETestProcessDie:
189 User::Panic(_L("ProcessDie"),KErrDied);
192 case ETestProcessFinish:
196 User::Panic(_L("T_RENDEZVOUS"),1);
201 void TestProcessRendezvous()
203 TRequestStatus rendezvousStatus;
204 TRequestStatus rendezvousStatusCancel;
205 TRequestStatus logonStatus;
207 RTestProcess process;
209 test.Start(_L("Create new process"));
210 process.Create(ETestProcessRendezvous);
212 test.Next(_L("Request rendezvous"));
213 process.Rendezvous(rendezvousStatusCancel);
214 test(rendezvousStatusCancel==KRequestPending);
216 test.Next(_L("Cancel rendezvous request"));
217 r = process.RendezvousCancel(rendezvousStatusCancel);
219 test(rendezvousStatusCancel==KErrNone);
221 test.Next(_L("Request rendezvous again"));
222 process.Rendezvous(rendezvousStatus);
223 test(rendezvousStatus==KRequestPending);
225 test.Next(_L("Also logon to process"));
226 process.Logon(logonStatus);
227 test(logonStatus==KRequestPending);
229 test.Next(_L("Resume process and wait for rendezvous..."));
232 User::WaitForRequest(rendezvousStatus,logonStatus);
233 test(rendezvousStatus==KRendezvousOk);
234 test(logonStatus==KRequestPending);
235 test(rendezvousStatusCancel==KErrNone);
237 test.Next(_L("Rendezvous OK, now wait for process to end..."));
239 User::WaitForRequest(logonStatus);
240 test(logonStatus==KErrNone);
241 test(rendezvousStatusCancel==KErrNone);
243 CLOSE_AND_WAIT(process);
247 test.Next(_L("Create new process"));
248 process.Create(ETestProcessDie);
250 test.Next(_L("Request rendezvous"));
251 process.Rendezvous(rendezvousStatus);
252 test(rendezvousStatus==KRequestPending);
254 test.Next(_L("Resume process and wait for process to die..."));
256 User::WaitForRequest(rendezvousStatus);
257 test(rendezvousStatus==KErrDied);
258 test(process.ExitReason()==KErrDied);
259 test(process.ExitType()==EExitPanic);
261 CLOSE_AND_WAIT(process);
265 test.Next(_L("Create new process"));
266 process.Create(ETestProcessFinish);
268 test.Next(_L("Request rendezvous"));
269 process.Rendezvous(rendezvousStatus);
270 test(rendezvousStatus==KRequestPending);
272 test.Next(_L("Resume process and wait for process to finish..."));
274 User::WaitForRequest(rendezvousStatus);
275 test(rendezvousStatus==KErrNone);
276 test(process.ExitReason()==KErrNone);
277 test(process.ExitType()==EExitKill);
279 CLOSE_AND_WAIT(process);
288 GLDEF_C TInt E32Main()
291 User::CommandLine(cmd);
292 if(cmd.Length() && TChar(cmd[0]).IsDigit())
303 return DoTestProcess(function,arg1,arg2);
307 test(SyncMutex.CreateGlobal(KSyncMutext)==KErrNone);
309 test.Start(_L("Test Thread rendezvous"));
310 TestThreadRendezvous();
312 test.Next(_L("Test Process rendezvous"));
313 TestProcessRendezvous();