1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/secure/t_rendezvous.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,320 @@
1.4 +// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\secure\t_rendezvous.cpp
1.18 +// Overview:
1.19 +// Test RThread and RProcess rendezvous
1.20 +// API Information:
1.21 +// RThread, RProcess
1.22 +// Details:
1.23 +// - Create a thread, request rendezvous, cancel rendezvous, request rendezvous
1.24 +// again, resume thread and wait for rendezvous, verify results as expected.
1.25 +// - Create a thread, request rendezvous, allow thread to die, verify results.
1.26 +// - Create a thread, request rendezvous, allow thread to finish, verify results.
1.27 +// - Create a process, request rendezvous, cancel rendezvous, request rendezvous
1.28 +// again, resume process and wait for rendezvous, verify results as expected.
1.29 +// - Create a process, request rendezvous, allow process to die, verify results.
1.30 +// - Create a process, request rendezvous, allow process to finish, verify results.
1.31 +// Platforms/Drives/Compatibility:
1.32 +// All.
1.33 +// Assumptions/Requirement/Pre-requisites:
1.34 +// Failures and causes:
1.35 +// Base Port information:
1.36 +//
1.37 +//
1.38 +
1.39 +#include <e32test.h>
1.40 +
1.41 +LOCAL_D RTest test(_L("T_RENDEZVOUS"));
1.42 +
1.43 +_LIT(KSyncMutext,"T_RENDEZVOUS-sync-mutex");
1.44 +RMutex SyncMutex;
1.45 +
1.46 +void Wait()
1.47 + {
1.48 + RMutex syncMutex;
1.49 + if(syncMutex.OpenGlobal(KSyncMutext)!=KErrNone)
1.50 + User::Invariant();
1.51 + syncMutex.Wait();
1.52 + syncMutex.Signal();
1.53 + syncMutex.Close();
1.54 + }
1.55 +
1.56 +const TInt KRendezvousOk = 1;
1.57 +
1.58 +TInt ThreadRendezvous(TAny *)
1.59 + {
1.60 + RThread::Rendezvous(KRendezvousOk);
1.61 + Wait();
1.62 + return KErrNone;
1.63 + }
1.64 +
1.65 +TInt ThreadDie(TAny *)
1.66 + {
1.67 + User::Panic(_L("ThreadDie"),KErrDied);
1.68 + return KErrNone;
1.69 + }
1.70 +
1.71 +TInt ThreadFinish(TAny *)
1.72 + {
1.73 + return KErrNone;
1.74 + }
1.75 +
1.76 +void TestThreadRendezvous()
1.77 + {
1.78 + TRequestStatus rendezvousStatus;
1.79 + TRequestStatus rendezvousStatusCancel;
1.80 + TRequestStatus logonStatus;
1.81 + TInt r;
1.82 + RThread thread;
1.83 +
1.84 + //
1.85 +
1.86 + test.Start(_L("Create thread 'ThreadRendezvous'"));
1.87 + r=thread.Create(_L("ThreadRendezvous"),ThreadRendezvous,KDefaultStackSize,KDefaultStackSize,KDefaultStackSize,NULL);
1.88 + test(r==KErrNone);
1.89 +
1.90 + test.Next(_L("Request rendezvous"));
1.91 + thread.Rendezvous(rendezvousStatusCancel);
1.92 + test(rendezvousStatusCancel==KRequestPending);
1.93 +
1.94 + test.Next(_L("Cancel rendezvous request"));
1.95 + r = thread.RendezvousCancel(rendezvousStatusCancel);
1.96 + test(r==KErrNone);
1.97 + test(rendezvousStatusCancel==KErrNone);
1.98 +
1.99 + test.Next(_L("Request rendezvous again"));
1.100 + thread.Rendezvous(rendezvousStatus);
1.101 + test(rendezvousStatus==KRequestPending);
1.102 +
1.103 + test.Next(_L("Also logon to thread"));
1.104 + thread.Logon(logonStatus);
1.105 + test(logonStatus==KRequestPending);
1.106 +
1.107 + test.Next(_L("Resume thread and wait for rendezvous..."));
1.108 + SyncMutex.Wait();
1.109 + thread.Resume();
1.110 + User::WaitForRequest(rendezvousStatus,logonStatus);
1.111 + test(rendezvousStatus==KRendezvousOk);
1.112 + test(logonStatus==KRequestPending);
1.113 + test(rendezvousStatusCancel==KErrNone);
1.114 +
1.115 + test.Next(_L("Rendezvous OK, now wait for thread to end..."));
1.116 + SyncMutex.Signal();
1.117 + User::WaitForRequest(logonStatus);
1.118 + test(logonStatus==KErrNone);
1.119 + test(rendezvousStatusCancel==KErrNone);
1.120 +
1.121 + CLOSE_AND_WAIT(thread);
1.122 +
1.123 + //
1.124 +
1.125 + test.Next(_L("Create thread 'ThreadDie'"));
1.126 + r=thread.Create(_L("ThreadDie"),ThreadDie,KDefaultStackSize,KDefaultStackSize,KDefaultStackSize,NULL);
1.127 + test(r==KErrNone);
1.128 +
1.129 + test.Next(_L("Request rendezvous"));
1.130 + thread.Rendezvous(rendezvousStatus);
1.131 + test(rendezvousStatus==KRequestPending);
1.132 +
1.133 + test.Next(_L("Resume thread and wait for thread to die..."));
1.134 + TBool jit = User::JustInTime();
1.135 + User::SetJustInTime(EFalse);
1.136 + thread.Resume();
1.137 + User::WaitForRequest(rendezvousStatus);
1.138 + User::SetJustInTime(jit);
1.139 + test(rendezvousStatus==KErrDied);
1.140 + test(thread.ExitReason()==KErrDied);
1.141 + test(thread.ExitType()==EExitPanic);
1.142 +
1.143 + CLOSE_AND_WAIT(thread);
1.144 +
1.145 + //
1.146 +
1.147 + test.Next(_L("Create thread 'ThreadFinish'"));
1.148 + r=thread.Create(_L("ThreadFinish"),ThreadFinish,KDefaultStackSize,KDefaultStackSize,KDefaultStackSize,NULL);
1.149 + test(r==KErrNone);
1.150 +
1.151 + test.Next(_L("Request rendezvous"));
1.152 + thread.Rendezvous(rendezvousStatus);
1.153 + test(rendezvousStatus==KRequestPending);
1.154 +
1.155 + test.Next(_L("Resume thread and wait for thread to finish..."));
1.156 + thread.Resume();
1.157 + User::WaitForRequest(rendezvousStatus);
1.158 + test(rendezvousStatus==KErrNone);
1.159 + test(thread.ExitReason()==KErrNone);
1.160 + test(thread.ExitType()==EExitKill);
1.161 +
1.162 + CLOSE_AND_WAIT(thread);
1.163 +
1.164 + //
1.165 +
1.166 + test.End();
1.167 + }
1.168 +
1.169 +
1.170 +enum TTestProcessFunctions
1.171 + {
1.172 + ETestProcessRendezvous,
1.173 + ETestProcessDie,
1.174 + ETestProcessFinish,
1.175 + };
1.176 +
1.177 +#include "testprocess.h"
1.178 +
1.179 +TInt DoTestProcess(TInt aTestNum,TInt aArg1,TInt aArg2)
1.180 + {
1.181 + (void)aArg1; // Keep compiler quiet about unused parameters
1.182 + (void)aArg2;
1.183 +
1.184 + switch(aTestNum)
1.185 + {
1.186 + case ETestProcessRendezvous:
1.187 + RProcess::Rendezvous(KRendezvousOk);
1.188 + Wait();
1.189 + return KErrNone;
1.190 +
1.191 + case ETestProcessDie:
1.192 + User::Panic(_L("ProcessDie"),KErrDied);
1.193 + return KErrNone;
1.194 +
1.195 + case ETestProcessFinish:
1.196 + return KErrNone;
1.197 +
1.198 + default:
1.199 + User::Panic(_L("T_RENDEZVOUS"),1);
1.200 + }
1.201 + return KErrNone;
1.202 + }
1.203 +
1.204 +void TestProcessRendezvous()
1.205 + {
1.206 + TRequestStatus rendezvousStatus;
1.207 + TRequestStatus rendezvousStatusCancel;
1.208 + TRequestStatus logonStatus;
1.209 + TInt r;
1.210 + RTestProcess process;
1.211 +
1.212 + test.Start(_L("Create new process"));
1.213 + process.Create(ETestProcessRendezvous);
1.214 +
1.215 + test.Next(_L("Request rendezvous"));
1.216 + process.Rendezvous(rendezvousStatusCancel);
1.217 + test(rendezvousStatusCancel==KRequestPending);
1.218 +
1.219 + test.Next(_L("Cancel rendezvous request"));
1.220 + r = process.RendezvousCancel(rendezvousStatusCancel);
1.221 + test(r==KErrNone);
1.222 + test(rendezvousStatusCancel==KErrNone);
1.223 +
1.224 + test.Next(_L("Request rendezvous again"));
1.225 + process.Rendezvous(rendezvousStatus);
1.226 + test(rendezvousStatus==KRequestPending);
1.227 +
1.228 + test.Next(_L("Also logon to process"));
1.229 + process.Logon(logonStatus);
1.230 + test(logonStatus==KRequestPending);
1.231 +
1.232 + test.Next(_L("Resume process and wait for rendezvous..."));
1.233 + SyncMutex.Wait();
1.234 + process.Resume();
1.235 + User::WaitForRequest(rendezvousStatus,logonStatus);
1.236 + test(rendezvousStatus==KRendezvousOk);
1.237 + test(logonStatus==KRequestPending);
1.238 + test(rendezvousStatusCancel==KErrNone);
1.239 +
1.240 + test.Next(_L("Rendezvous OK, now wait for process to end..."));
1.241 + SyncMutex.Signal();
1.242 + User::WaitForRequest(logonStatus);
1.243 + test(logonStatus==KErrNone);
1.244 + test(rendezvousStatusCancel==KErrNone);
1.245 +
1.246 + CLOSE_AND_WAIT(process);
1.247 +
1.248 + //
1.249 +
1.250 + test.Next(_L("Create new process"));
1.251 + process.Create(ETestProcessDie);
1.252 +
1.253 + test.Next(_L("Request rendezvous"));
1.254 + process.Rendezvous(rendezvousStatus);
1.255 + test(rendezvousStatus==KRequestPending);
1.256 +
1.257 + test.Next(_L("Resume process and wait for process to die..."));
1.258 + process.Resume();
1.259 + User::WaitForRequest(rendezvousStatus);
1.260 + test(rendezvousStatus==KErrDied);
1.261 + test(process.ExitReason()==KErrDied);
1.262 + test(process.ExitType()==EExitPanic);
1.263 +
1.264 + CLOSE_AND_WAIT(process);
1.265 +
1.266 + //
1.267 +
1.268 + test.Next(_L("Create new process"));
1.269 + process.Create(ETestProcessFinish);
1.270 +
1.271 + test.Next(_L("Request rendezvous"));
1.272 + process.Rendezvous(rendezvousStatus);
1.273 + test(rendezvousStatus==KRequestPending);
1.274 +
1.275 + test.Next(_L("Resume process and wait for process to finish..."));
1.276 + process.Resume();
1.277 + User::WaitForRequest(rendezvousStatus);
1.278 + test(rendezvousStatus==KErrNone);
1.279 + test(process.ExitReason()==KErrNone);
1.280 + test(process.ExitType()==EExitKill);
1.281 +
1.282 + CLOSE_AND_WAIT(process);
1.283 +
1.284 + //
1.285 +
1.286 + test.End();
1.287 + }
1.288 +
1.289 +
1.290 +
1.291 +GLDEF_C TInt E32Main()
1.292 + {
1.293 + TBuf16<512> cmd;
1.294 + User::CommandLine(cmd);
1.295 + if(cmd.Length() && TChar(cmd[0]).IsDigit())
1.296 + {
1.297 + TInt function = -1;
1.298 + TInt arg1 = -1;
1.299 + TInt arg2 = -1;
1.300 + TLex lex(cmd);
1.301 + lex.Val(function);
1.302 + lex.SkipSpace();
1.303 + lex.Val(arg1);
1.304 + lex.SkipSpace();
1.305 + lex.Val(arg2);
1.306 + return DoTestProcess(function,arg1,arg2);
1.307 + }
1.308 +
1.309 + test.Title();
1.310 + test(SyncMutex.CreateGlobal(KSyncMutext)==KErrNone);
1.311 +
1.312 + test.Start(_L("Test Thread rendezvous"));
1.313 + TestThreadRendezvous();
1.314 +
1.315 + test.Next(_L("Test Process rendezvous"));
1.316 + TestProcessRendezvous();
1.317 +
1.318 + SyncMutex.Close();
1.319 + test.End();
1.320 +
1.321 + return(0);
1.322 + }
1.323 +