1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/bench/t_proc1.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,816 @@
1.4 +// Copyright (c) 1996-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\bench\t_proc1.cpp
1.18 +// One half of the process relative type test stuff
1.19 +// Overview:
1.20 +// Tests the RProcess class, including tests on the heap, process naming,
1.21 +// process resumption, process creation and shared chunks.
1.22 +// API Information:
1.23 +// RProcess
1.24 +// Details:
1.25 +// - Open a nonexistent process by a process Id and checks for the failure
1.26 +// of finding this process.
1.27 +// - Open a process with invalid name and verify failure results are as expected.
1.28 +// - Test the closing of processes by calling Kill, Terminate, and Panic methods.
1.29 +// Verify results are as expected.
1.30 +// - Create a process and verify the full path name of the loaded executable on
1.31 +// which this process is based.
1.32 +// - Open a process by name, rename the process in a variety of ways and verify
1.33 +// the results are as expected.
1.34 +// - Open a process, assign high, low, and bad priorities, verify the results
1.35 +// are as expected.
1.36 +// - Open a process, kill it and verify the results are as expected.
1.37 +// - Open a process by name based on the file name, verify the results are as
1.38 +// expected.
1.39 +// - Retrieve the process Id and open a handle on it. Create a duplicate process.
1.40 +// Verify the results are as expected.
1.41 +// - Find a process using TFindProcess() and open a handle on it. Verify the
1.42 +// results are as expected.
1.43 +// - Check chunk sharing between threads and verify results are as expected.
1.44 +// - Perform a "speed" test where a new thread is created and the thread increments
1.45 +// a count until stopped. Calculate and display counts per second. Verify results
1.46 +// are as expected.
1.47 +// - Verify the ExitReason, ExitType and ExitCatagory when the thread dies.
1.48 +// - Verify that stopping the process completes existing pending requests with
1.49 +// KErrServerTerminated.
1.50 +// - Verify that the heap was not corrupted by the tests.
1.51 +// Platforms/Drives/Compatibility:
1.52 +// All.
1.53 +// Assumptions/Requirement/Pre-requisites:
1.54 +// Failures and causes:
1.55 +// Base Port information:
1.56 +//
1.57 +//
1.58 +
1.59 +#include <e32test.h>
1.60 +#include "../mmu/mmudetect.h"
1.61 +#include "t_proc.h"
1.62 +
1.63 +LOCAL_D RTest test(_L("T_PROC1"));
1.64 +
1.65 +const TBufC<67> tooLong=_L("This should return KErrBadName and not crash.......0123456789ABCDEF");
1.66 +const TBufC<66> notQuiteTooLong=_L("This should return KErrNone and be completely OK..0123456789ABCDEF");
1.67 +const TBufC<26> bond=_L("Bond, James Bond[00000000]");
1.68 +const TBufC<16> jamesBond=_L("Bond, James Bond");
1.69 +
1.70 +RProcess proc;
1.71 +RProcess proc2;
1.72 +RProcess proc3;
1.73 +RProcess proc4;
1.74 +
1.75 +TName command;
1.76 +TRequestStatus stat,notStat;
1.77 +
1.78 +const TInt KKillReason=2563453;
1.79 +const TInt KTerminateReason=8034255;
1.80 +const TInt KPanicReason=39365235;
1.81 +
1.82 +LOCAL_D RSemaphore client;
1.83 +LOCAL_D TInt speedCount;
1.84 +
1.85 +class RDisplay : public RSessionBase
1.86 + {
1.87 +public:
1.88 + TInt Open();
1.89 + TInt Display(const TDesC& aMessage);
1.90 + TInt Read();
1.91 + TInt Write();
1.92 + TInt Stop();
1.93 + TInt Test();
1.94 + TVersion Version();
1.95 + };
1.96 +
1.97 +TInt RDisplay::Open()
1.98 +//
1.99 +// Open the server.
1.100 +//
1.101 + {
1.102 +
1.103 + return(CreateSession(_L("Display"),Version(),1));
1.104 + }
1.105 +
1.106 +TInt RDisplay::Display(const TDesC& aMessage)
1.107 +//
1.108 +// Display a message.
1.109 +//
1.110 + {
1.111 +
1.112 + TBuf<0x10> b(aMessage);
1.113 + return(SendReceive(CMyServer::EDisplay,TIpcArgs(&b)));
1.114 + }
1.115 +
1.116 +TInt RDisplay::Read()
1.117 +//
1.118 +// Get session to test CSession2::ReadL.
1.119 +//
1.120 + {
1.121 +
1.122 + TBuf<0x10> b(_L("Testing read"));
1.123 + return(SendReceive(CMyServer::ERead,TIpcArgs(&b)));
1.124 + }
1.125 +
1.126 +TInt RDisplay::Write()
1.127 +//
1.128 +// Get session to test CSession2::WriteL.
1.129 +//
1.130 + {
1.131 +
1.132 + TBuf<0x10> b;
1.133 + TBufC<0x10> c; // Bad descriptor - read only
1.134 + TInt r=SendReceive(CMyServer::EWrite,TIpcArgs(&b,&c));
1.135 + if (r==KErrNone && b!=_L("It worked!"))
1.136 + r=KErrGeneral;
1.137 + return r;
1.138 + }
1.139 +
1.140 +TInt RDisplay::Test()
1.141 +//
1.142 +// Send a message and wait for completion.
1.143 +//
1.144 + {
1.145 +
1.146 + TInt i[4];
1.147 + return(SendReceive(CMyServer::ETest,TIpcArgs(&i[0])));
1.148 + }
1.149 +
1.150 +TInt RDisplay::Stop()
1.151 +//
1.152 +// Stop the server.
1.153 +//
1.154 + {
1.155 +
1.156 + TInt i[4];
1.157 + return(SendReceive(CMyServer::EStop,TIpcArgs(&i[0])));
1.158 + }
1.159 +
1.160 +TVersion RDisplay::Version()
1.161 +//
1.162 +// Return the current version.
1.163 +//
1.164 + {
1.165 +
1.166 + TVersion v(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
1.167 + return(v);
1.168 + }
1.169 +
1.170 +LOCAL_C TInt RunPanicThread(RThread& aThread)
1.171 + {
1.172 + TRequestStatus s;
1.173 + aThread.Logon(s);
1.174 + TBool jit = User::JustInTime();
1.175 + User::SetJustInTime(EFalse);
1.176 + aThread.Resume();
1.177 + User::WaitForRequest(s);
1.178 + User::SetJustInTime(jit);
1.179 + return s.Int();
1.180 + }
1.181 +
1.182 +TInt KillProtectedEntry(TAny*)
1.183 + {
1.184 + proc.Kill(KErrGeneral);
1.185 + return KErrGeneral;
1.186 + }
1.187 +
1.188 +TInt createProc2(RProcess& aProcess)
1.189 + {
1.190 + TFileName filename(RProcess().FileName());
1.191 + TInt pos=filename.LocateReverse(TChar('\\'));
1.192 + filename.SetLength(pos+1);
1.193 + filename+=_L("T_PROC2.EXE");
1.194 + TInt r=aProcess.Create(filename, command);
1.195 + if (r==KErrNone)
1.196 + {
1.197 + TFullName fn(aProcess.FullName());
1.198 + test.Printf(_L("Created %S\n"),&fn);
1.199 + }
1.200 + return r;
1.201 + }
1.202 +
1.203 +void simpleTests1()
1.204 + {
1.205 + test.Next(_L("Open by name"));
1.206 + RProcess me;
1.207 + TInt r=proc2.Open(me.Name());
1.208 + test(r==KErrNone);
1.209 + test.Next(_L("Rename"));
1.210 + TName initName(me.Name());
1.211 + r=User::RenameProcess(jamesBond);
1.212 + test(r==KErrNone);
1.213 + test(me.Name().Left(26)==bond);
1.214 + test(proc2.Name().Left(26)==bond);
1.215 + r=User::RenameProcess(tooLong);
1.216 + test(r==KErrBadName);
1.217 + test(me.Name().Left(26)==bond);
1.218 + test(proc2.Name().Left(26)==bond);
1.219 + TName* work=new TName(notQuiteTooLong);
1.220 + r=User::RenameProcess(*work);
1.221 + test(r==KErrNone);
1.222 + work->Append(_L("[00000000]"));
1.223 + test(me.Name().Length()==KMaxKernelName);
1.224 + test(me.Name().Left(KMaxKernelName-4)==*work);
1.225 + test(proc2.Name().Length()==KMaxKernelName);
1.226 + test(proc2.Name().Left(KMaxKernelName-4)==*work);
1.227 + delete work;
1.228 + r=User::RenameProcess(_L("T_PROC1"));
1.229 + test(r==KErrNone);
1.230 + TFullName fn(_L("T_PROC1["));
1.231 + TUidType uidType(me.Type());
1.232 + TUint32 uid3 = uidType[2].iUid;
1.233 + fn.AppendNumFixedWidth(uid3,EHex,8);
1.234 + fn.Append(']');
1.235 + test(proc2.Name().Left(17)==fn);
1.236 + test(me.Name().Left(17)==fn);
1.237 + TInt l = initName.Locate('[');
1.238 + r=User::RenameProcess(initName.Left(l));
1.239 + test(r==KErrNone);
1.240 + test(proc2.Name()==initName);
1.241 + proc2.Close();
1.242 + }
1.243 +
1.244 +TInt BadPriority(TAny* proc2)
1.245 + {
1.246 + ((RProcess*)proc2)->SetPriority(EPriorityWindowServer);
1.247 + return KErrNone;
1.248 + }
1.249 +
1.250 +void simpleTests2()
1.251 + {
1.252 + TInt r=proc2.Open(proc.Name());
1.253 + test.Next(_L("Mess with Priority"));
1.254 + proc.SetPriority(EPriorityHigh);
1.255 + test.Printf(_L("%d %d\n"),proc.Priority(),proc2.Priority());
1.256 + test(proc.Priority()==EPriorityHigh);
1.257 + test(proc2.Priority()==EPriorityHigh);
1.258 + proc2.SetPriority(EPriorityLow);
1.259 + test(proc.Priority()==EPriorityLow);
1.260 + test(proc2.Priority()==EPriorityLow);
1.261 +
1.262 + RThread thread;
1.263 + r=thread.Create(_L("Bad Priority"),BadPriority,KDefaultStackSize,NULL,&proc2);
1.264 + test(r==KErrNone);
1.265 + r=RunPanicThread(thread);
1.266 + test(r==EBadPriority);
1.267 + test(thread.ExitType()==EExitPanic);
1.268 + test(thread.ExitReason()==EBadPriority);
1.269 + test(thread.ExitCategory()==_L("KERN-EXEC"));
1.270 + CLOSE_AND_WAIT(thread);
1.271 + test(proc.Priority()==EPriorityLow);
1.272 + test(proc2.Priority()==EPriorityLow);
1.273 + proc2.Close();
1.274 + }
1.275 +
1.276 +void procTests1()
1.277 + {
1.278 + test.Next(_L("Test functions"));
1.279 + TFileName fileName(proc.FileName());
1.280 + test.Printf(fileName);
1.281 +#ifndef __WINS__
1.282 + if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
1.283 + test(fileName.Mid(1).CompareF(_L(":\\Sys\\Bin\\T_PROC2.EXE"))==0);
1.284 + else
1.285 + test(fileName.Mid(1).CompareF(_L(":\\System\\Bin\\T_PROC2.EXE"))==0);
1.286 +#else
1.287 + if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
1.288 + test(fileName.CompareF(_L("Z:\\Sys\\Bin\\T_PROC2.EXE"))==0);
1.289 + else
1.290 + test(fileName.CompareF(_L("Z:\\System\\Bin\\T_PROC2.EXE"))==0);
1.291 +#endif
1.292 + test(proc.Name().Left(21).CompareF(_L("T_PROC2.EXE[00000000]"))==0);
1.293 + test(proc.Priority()==EPriorityForeground);
1.294 + test(proc.ExitType()==EExitPending);
1.295 + test(proc.ExitReason()==0);
1.296 + test(proc.ExitCategory()==KNullDesC);
1.297 + }
1.298 +
1.299 +void procTests2()
1.300 + {
1.301 + test.Next(_L("Kill and recreate"));
1.302 + RProcess proc2;
1.303 + TInt r=proc2.Open(proc.Id());
1.304 + test(r==KErrNone);
1.305 + test(proc2.Handle()!=0);
1.306 + proc.Logon(stat);
1.307 + proc.Logon(notStat);
1.308 + r=proc.LogonCancel(notStat);
1.309 + test(r==KErrNone);
1.310 + test(notStat==KErrNone);
1.311 + proc.Kill(KKillReason);
1.312 + User::WaitForRequest(stat);
1.313 + test(stat==KKillReason);
1.314 + test(proc.ExitType()==EExitKill);
1.315 + test(proc.ExitReason()==KKillReason);
1.316 + test(proc.ExitCategory()==_L("Kill"));
1.317 + proc.Close();
1.318 + test(proc.Handle()==0);
1.319 + test(proc2.ExitType()==EExitKill);
1.320 + test(proc2.ExitReason()==KKillReason);
1.321 + test(proc2.ExitCategory()==_L("Kill"));
1.322 + CLOSE_AND_WAIT(proc2);
1.323 + test(proc2.Handle()==0);
1.324 + }
1.325 +
1.326 +void procTests3()
1.327 + {
1.328 + TFileName filename(RProcess().FileName());
1.329 + TInt pos=filename.LocateReverse(TChar('\\'));
1.330 + filename.SetLength(pos+1);
1.331 + filename+=_L("T_PROC2.EXE");
1.332 + TInt r=proc.Create(filename, command);
1.333 + test(r==KErrNone);
1.334 + TFullName fn(proc.FullName());
1.335 + test.Printf(_L("Created %S\n"),&fn);
1.336 + test(proc.FileName().CompareF(filename)==0);
1.337 + test(proc.Name().Left(21).CompareF(_L("T_PROC2.EXE[00000000]"))==0);
1.338 + test(proc.Priority()==EPriorityForeground);
1.339 + test(proc.ExitType()==EExitPending);
1.340 + test(proc.ExitReason()==0);
1.341 + test(proc.ExitCategory()==KNullDesC);
1.342 + }
1.343 +
1.344 +void procTests4()
1.345 + {
1.346 + test.Next(_L("Get and open by Id"));
1.347 + TProcessId id=proc.Id();
1.348 + TProcessId id2=proc.Id();
1.349 + test(id==id2);
1.350 + TInt r=proc2.Open(proc.Name());
1.351 + test(r==KErrNone);
1.352 + id2=proc2.Id();
1.353 + test(id==id2);
1.354 + r=proc3.Open(id);
1.355 + test(r==KErrNone);
1.356 + id2=proc3.Id();
1.357 + test(id==id2);
1.358 + proc3.Close();
1.359 + if (HaveVirtMem())
1.360 + {
1.361 + test.Next(_L("Create duplicate"));
1.362 + r=createProc2(proc3);
1.363 + test(r==KErrNone);
1.364 + id2=proc3.Id();
1.365 + test(id!=id2);
1.366 + test(*(TUint*)&id<*(TUint*)&id2);
1.367 + }
1.368 + }
1.369 +
1.370 +void procTests5()
1.371 + {
1.372 + test.Next(_L("Try to find processes"));
1.373 + TFindProcess* findProc=new TFindProcess(_L("T_PROC2*"));
1.374 + test(findProc!=NULL);
1.375 + TFullName* result=new TFullName;
1.376 + test(result!=NULL);
1.377 + TInt r=findProc->Next(*result);
1.378 + test(r==KErrNone);
1.379 + TFullName temp = proc.FullName();
1.380 + test(result->CompareF(temp)==0);
1.381 + r=findProc->Next(*result);
1.382 + test(r==KErrNone);
1.383 + test(result->CompareF(proc3.FullName())==0);
1.384 + r=findProc->Next(*result);
1.385 + test(r==KErrNotFound);
1.386 + findProc->Find(_L("T?PROC2*]*"));
1.387 + r=findProc->Next(*result);
1.388 + test(r==KErrNone);
1.389 + test(result->CompareF(temp)==0);
1.390 + r=findProc->Next(*result);
1.391 + test(r==KErrNone);
1.392 + test(result->CompareF(proc3.FullName())==0);
1.393 + delete result;
1.394 + test.Next(_L("Open by find handle"));
1.395 + r=proc4.Open(*findProc);
1.396 + test(r==KErrNone);
1.397 + TProcessId id=proc3.Id();
1.398 + TProcessId id2=proc4.Id();
1.399 + test(id==id2);
1.400 + delete findProc;
1.401 + }
1.402 +
1.403 +void procTests6()
1.404 + {
1.405 + test.Next(_L("Kill duplicate"));
1.406 + proc3.Logon(stat);
1.407 + test(stat==KRequestPending);
1.408 + proc4.Kill(12345);
1.409 + User::WaitForRequest(stat);
1.410 + test(stat==12345);
1.411 + }
1.412 +
1.413 +void createProcess()
1.414 +//
1.415 +// Create T_PROC2 and, on the way, do lots of basic tests
1.416 +//
1.417 + {
1.418 + test.Start(_L("Create"));
1.419 + TInt r=globSem1.CreateGlobal(_L("GlobSem1"), 0);
1.420 + test(r==KErrNone);
1.421 + r=globSem2.CreateGlobal(_L("GlobSem2"), 0);
1.422 + test(r==KErrNone);
1.423 +
1.424 + r=createProc2(proc);
1.425 + test(r==KErrNone);
1.426 +
1.427 + procTests1();
1.428 +
1.429 + simpleTests1();
1.430 + simpleTests2();
1.431 +
1.432 + procTests2();
1.433 + procTests3();
1.434 + procTests4();
1.435 + if (HaveVirtMem())
1.436 + {
1.437 + procTests5();
1.438 + procTests6();
1.439 + }
1.440 +
1.441 + proc2.Close();
1.442 + proc3.Close();
1.443 + if (proc4.Handle())
1.444 + CLOSE_AND_WAIT(proc4);
1.445 +
1.446 + test.Next(_L("Resume"));
1.447 + proc.Logon(stat); // logon to process
1.448 + proc.Logon(notStat);
1.449 + r=proc.LogonCancel(notStat);
1.450 + test(r==KErrNone);
1.451 + test(notStat==KErrNone);
1.452 + test(proc.ExitType()==EExitPending);
1.453 + proc.Resume();
1.454 + globSem1.Wait(); // wait for T_PROC2 to get started
1.455 + test.End();
1.456 + }
1.457 +
1.458 +void murderProcess()
1.459 + {
1.460 + test.Start(_L("Kill"));
1.461 + RProcess process;
1.462 + TInt r=createProc2(process);
1.463 + test(r==KErrNone);
1.464 + TProcessId id=process.Id();
1.465 + TProcessId id2=process.Id();
1.466 + test(id==id2);
1.467 + TRequestStatus stat;
1.468 + process.Logon(stat);
1.469 + test(process.ExitType()==EExitPending);
1.470 + process.Kill(KKillReason);
1.471 + User::WaitForRequest(stat);
1.472 + test(stat==KKillReason);
1.473 + test(process.ExitType()==EExitKill);
1.474 + test(process.ExitReason()==KKillReason);
1.475 + test(process.ExitCategory()==_L("Kill"));
1.476 + CLOSE_AND_WAIT(process);
1.477 +
1.478 + test.Next(_L("Terminate"));
1.479 + r=createProc2(process);
1.480 + test(r==KErrNone);
1.481 + id2=process.Id();
1.482 + test(*(TUint*)&id+2==*(TUint*)&id2); // use 2 ID's each time, one for process, one for thread
1.483 + process.Logon(stat);
1.484 + test(process.ExitType()==EExitPending);
1.485 + process.Terminate(KTerminateReason);
1.486 + User::WaitForRequest(stat);
1.487 + test(stat==KTerminateReason);
1.488 + test(process.ExitType()==EExitTerminate);
1.489 + test(process.ExitReason()==KTerminateReason);
1.490 + test(process.ExitCategory()==_L("Terminate"));
1.491 + CLOSE_AND_WAIT(process);
1.492 +
1.493 + test.Next(_L("Panic"));
1.494 + r=createProc2(process);
1.495 + test(r==KErrNone);
1.496 + id2=process.Id();
1.497 + test(*(TUint*)&id+4==*(TUint*)&id2);
1.498 + test(process.ExitType()==EExitPending);
1.499 + process.Logon(stat);
1.500 + process.SetJustInTime(EFalse); // prevent the process panic from starting the debugger
1.501 + process.Panic(_L("BOO!"),KPanicReason);
1.502 + User::WaitForRequest(stat);
1.503 + test(stat==KPanicReason);
1.504 + test(process.ExitType()==EExitPanic);
1.505 + test(process.ExitReason()==KPanicReason);
1.506 + test(process.ExitCategory()==_L("BOO!"));
1.507 + CLOSE_AND_WAIT(process);
1.508 + test.End();
1.509 + }
1.510 +
1.511 +void sharedChunks()
1.512 + {
1.513 + test.Start(_L("Test chunk sharing between threads"));
1.514 +
1.515 + test.Next(_L("Create chunk Marmalade"));
1.516 + TInt r=0;
1.517 + RChunk chunk;
1.518 + TInt size=0x1000;
1.519 + TInt maxSize=0x5000;
1.520 + r=chunk.CreateGlobal(_L("Marmalade"),size,maxSize);
1.521 + test(r==KErrNone);
1.522 + test.Next(_L("Write 0-9 to it"));
1.523 + TUint8* base=chunk.Base();
1.524 + for (TInt8 j=0;j<10;j++)
1.525 + *base++=j; // write 0 - 9 to the chunk
1.526 + globSem2.Signal(); // T_PROC2 can check the chunk now
1.527 + globSem1.Wait();
1.528 + chunk.Close(); // now it's ok to kill the chunk
1.529 +
1.530 + test.End();
1.531 + }
1.532 +
1.533 +TInt sharedChunks2(TAny* /*aDummy*/)
1.534 + {
1.535 + RTest test(_L("Shared Chunks 2"));
1.536 +
1.537 + test.Title();
1.538 + test.Start(_L("Test chunk sharing between threads"));
1.539 +
1.540 + test.Next(_L("Create chunk Marmalade"));
1.541 + TInt r=0;
1.542 + RChunk chunk;
1.543 + TInt size=0x1000;
1.544 + TInt maxSize=0x5000;
1.545 + r=chunk.CreateGlobal(_L("Marmalade"),size,maxSize);
1.546 + test(r==KErrNone);
1.547 + test.Next(_L("Write 0-9 to it"));
1.548 + TUint8* base=chunk.Base();
1.549 + for (TInt8 j=0;j<10;j++)
1.550 + *base++=j; // write 0 - 9 to the chunk
1.551 + globSem2.Signal(); // T_PROC2 can check the chunk now
1.552 + globSem1.Wait();
1.553 + chunk.Close(); // now it's ok to kill the chunk
1.554 +
1.555 + test.End();
1.556 + return(KErrNone);
1.557 + }
1.558 +
1.559 +TInt speedyThreadEntryPoint(TAny*)
1.560 +//
1.561 +// The entry point for the speed test thread.
1.562 +//
1.563 + {
1.564 + RDisplay t;
1.565 + TInt r=t.Open();
1.566 + test(r==KErrNone);
1.567 + speedCount=0;
1.568 + client.Signal();
1.569 + while ((r=t.Test())==KErrNone)
1.570 + speedCount++;
1.571 + t.Close();
1.572 + return r;
1.573 + }
1.574 +
1.575 +TInt BadName(TAny*)
1.576 + {
1.577 + proc.Open(_L("*"));
1.578 + return KErrNone;
1.579 + }
1.580 +
1.581 +TInt sharedHeap(TAny*)
1.582 + {
1.583 + RTest test2(_L("sharedHeap"));
1.584 + test2.Title();
1.585 + test2.Start(_L("Shared heap tests"));
1.586 +
1.587 + RAllocator* allocator = &User::Allocator();
1.588 + test2.Printf(_L("sharedHeap's heap is at %08x\n"), allocator);
1.589 +
1.590 + TInt size;
1.591 + allocator->AllocSize(size);
1.592 + test2.Printf(_L("sharedHeap's heap allocsize is %08x\n"),size);
1.593 +
1.594 +// Press a key only if running the test in manual mode. We will be
1.595 +// able to ascertain this when RTest has been enhanced.
1.596 +// test.Next(_L("Press a key to continue"));
1.597 +// test2.Getch();
1.598 +
1.599 + test2.End();
1.600 + return(KErrNone);
1.601 + }
1.602 +
1.603 +_LIT(KTestProcessNewName,"T_PROC1_NEW.EXE");
1.604 +
1.605 +TInt DupRenameProcTest(TInt aCall)
1.606 + {
1.607 + test.Printf(_L("DupRenameProcTest: call %d\n"),aCall);
1.608 +
1.609 + TInt r;
1.610 +
1.611 + switch(aCall)
1.612 + {
1.613 + case 1:
1.614 + {
1.615 + r = User::RenameProcess(KTestProcessNewName);
1.616 + test(r==KErrNone);
1.617 + TFullName fn(RProcess().FullName());
1.618 + test.Printf(_L("Renamed to %S\n"),&fn);
1.619 + TInt li = fn.Locate('[');
1.620 + TInt ri = fn.Locate(']');
1.621 + test(fn.Left(li)==KTestProcessNewName);
1.622 + test(fn.Mid(ri+1)==_L("0001"));
1.623 + }
1.624 +
1.625 + case 0:
1.626 + {
1.627 + TFileName filename(RProcess().FileName());
1.628 + TInt pos=filename.LocateReverse(TChar('\\'));
1.629 + filename.SetLength(pos+1);
1.630 + filename+=_L("T_PROC1.EXE");
1.631 + RProcess pr;
1.632 + TBuf16<10> call;
1.633 + call.Num(aCall+1);
1.634 + r = pr.Create(filename, call);
1.635 + TFullName fn(pr.FullName());
1.636 + test.Printf(_L("Created %S\n"),&fn);
1.637 + TRequestStatus st;
1.638 + pr.Logon(st);
1.639 + pr.Resume();
1.640 + User::WaitForRequest(st);
1.641 + CLOSE_AND_WAIT(pr);
1.642 + }
1.643 + return KErrNone;
1.644 +
1.645 + case 2:
1.646 + {
1.647 + r = User::RenameProcess(KTestProcessNewName);
1.648 + test(r==KErrNone);
1.649 + TFullName fn(RProcess().FullName());
1.650 + test.Printf(_L("Renamed to %S\n"),&fn);
1.651 + TInt li = fn.Locate('[');
1.652 + TInt ri = fn.Locate(']');
1.653 + test(fn.Left(li)==KTestProcessNewName);
1.654 + test(fn.Mid(ri+1)==_L("0002"));
1.655 + }
1.656 + return KErrNone;
1.657 +
1.658 + default:
1.659 + return KErrArgument;
1.660 + }
1.661 + }
1.662 +
1.663 +_LIT(KTestProcessName,"TestName");
1.664 +
1.665 +void TestProcessRename()
1.666 + {
1.667 + // Rename the current process with test name
1.668 + TInt r = User::RenameProcess(KTestProcessName);
1.669 + test(r==KErrNone);
1.670 + TName name1 = RProcess().Name();
1.671 +
1.672 + // Check new name is correct
1.673 + TName name2 = name1;
1.674 + name2.SetLength(KTestProcessName().Length());
1.675 + test(name2.CompareF(KTestProcessName)==0);
1.676 +
1.677 + // Rename the process with same test name
1.678 + r = User::RenameProcess(KTestProcessName);
1.679 + test(r==KErrNone);
1.680 + name2 = RProcess().Name();
1.681 + test(name1.Compare(name2)==0); // name should be unchanged
1.682 + }
1.683 +
1.684 +TInt E32Main()
1.685 + {
1.686 + __KHEAP_MARK;
1.687 +
1.688 + // Turn off lazy dll unloading
1.689 + RLoader l;
1.690 + test(l.Connect()==KErrNone);
1.691 + test(l.CancelLazyDllUnload()==KErrNone);
1.692 + l.Close();
1.693 +
1.694 + TBuf16<512> cmd;
1.695 + User::CommandLine(cmd);
1.696 + if(cmd.Length() && TChar(cmd[0]).IsDigit())
1.697 + {
1.698 + TInt r = DupRenameProcTest(TUint(TChar(cmd[0])) - '0');
1.699 + test(r==KErrNone);
1.700 + return 0;
1.701 + }
1.702 +
1.703 + test.Title();
1.704 +
1.705 + test.Start(_L("Testing process stuff 1"));
1.706 + TInt r;
1.707 + TRequestStatus s;
1.708 + test.Next(_L("Creating semaphore"));
1.709 + r=client.CreateLocal(0);
1.710 + test(r==KErrNone);
1.711 +
1.712 + test.Next(_L("Try to open nonexistant process by ID"));
1.713 + r=proc.Open(*(TProcessId*)&KMaxTUint);
1.714 + test(r==KErrNotFound);
1.715 +
1.716 + test.Next(_L("Try to open process with invalid name"));
1.717 + RThread thread;
1.718 + r=thread.Create(_L("Bad Name"),BadName,KDefaultStackSize,NULL,NULL);
1.719 + test(r==KErrNone);
1.720 + TRequestStatus threadStat;
1.721 + thread.Logon(threadStat);
1.722 + TBool justInTime=User::JustInTime();
1.723 + User::SetJustInTime(EFalse);
1.724 + thread.Resume();
1.725 + User::WaitForRequest(threadStat);
1.726 + User::SetJustInTime(justInTime);
1.727 + test(threadStat==EBadName);
1.728 + test(thread.ExitType()==EExitPanic);
1.729 + test(thread.ExitReason()==EBadName);
1.730 + test(thread.ExitCategory()==_L("KERN-EXEC"));
1.731 + CLOSE_AND_WAIT(thread);
1.732 +
1.733 + test.Next(_L("Murder processes in different ways"));
1.734 + murderProcess();
1.735 +
1.736 + test.Next(_L("Create second process"));
1.737 + createProcess();
1.738 +
1.739 + test.Next(_L("Shared Chunks from main thread"));
1.740 + sharedChunks();
1.741 +
1.742 + test.Next(_L("Shared chunks from secondary thread"));
1.743 + RThread t;
1.744 + r=t.Create(_L("Shared chunks 2"),sharedChunks2,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
1.745 + test(r==KErrNone);
1.746 + t.Logon(s);
1.747 + t.Resume();
1.748 + User::WaitForRequest(s);
1.749 + test(s==KErrNone);
1.750 + CLOSE_AND_WAIT(t);
1.751 +
1.752 + test.Next(_L("Starting speedy client"));
1.753 + RThread speedy;
1.754 + r=speedy.Create(_L("Speedy"),speedyThreadEntryPoint,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
1.755 + test(r==KErrNone);
1.756 +
1.757 + RThread().SetPriority(EPriorityMuchMore);
1.758 + speedy.SetPriority(EPriorityNormal);
1.759 + TRequestStatus speedyStatus;
1.760 + speedy.Logon(speedyStatus);
1.761 + speedy.Resume();
1.762 +
1.763 + test.Next(_L("Wait for speedy to start"));
1.764 + client.Wait();
1.765 +
1.766 + globSem1.Wait(); // wait for proc2 to be nice & quiet
1.767 + test.Printf(_L("Starting speed test...\n"));
1.768 + User::After(300000);
1.769 + TInt b=speedCount;
1.770 + User::After(3000000);
1.771 + TInt n=speedCount;
1.772 + test.Printf(_L("Count = %d in 1 second\n"),(n-b)/3);
1.773 +
1.774 + test.Next(_L("Tell second process speed tests are done"));
1.775 + globSem2.Signal();
1.776 +
1.777 + test.Next(_L("Process Logon"));
1.778 + User::WaitForRequest(stat);
1.779 + const TDesC& cat=proc.ExitCategory();
1.780 + test.Printf(_L("Exit category = %S\n"),&cat);
1.781 + test.Printf(_L("Exit reason = %x\n"),proc.ExitReason());
1.782 + test.Printf(_L("Exit type = %x\n"),proc.ExitType());
1.783 +
1.784 + test(stat==KErrNone);
1.785 + test(proc.ExitCategory()==_L("Kill"));
1.786 + test(proc.ExitReason()==KErrNone);
1.787 + test(proc.ExitType()==EExitKill);
1.788 + test(notStat==KErrNone);
1.789 + test.Next(_L("Test LogonCancel to dead process is ok"));
1.790 + r=proc.LogonCancel(stat);
1.791 + test(r==KErrGeneral);
1.792 + globSem1.Close();
1.793 + globSem2.Close();
1.794 + client.Close();
1.795 +
1.796 + User::WaitForRequest(speedyStatus);
1.797 + test(speedyStatus==KErrServerTerminated);
1.798 + test(speedy.ExitReason()==KErrServerTerminated);
1.799 + test(speedy.ExitType()==EExitKill);
1.800 + CLOSE_AND_WAIT(speedy);
1.801 + CLOSE_AND_WAIT(proc);
1.802 +
1.803 + User::After(5000000); // wait for MMC session to disappear
1.804 +
1.805 + test.Next(_L("Test rename of the processes with duplicate names"));
1.806 + r = DupRenameProcTest(0);
1.807 + test(r==KErrNone);
1.808 +
1.809 + TestProcessRename();
1.810 +
1.811 + test.Next(_L("Check for kernel alloc heaven"));
1.812 + __KHEAP_MARKEND;
1.813 +
1.814 + test.End();
1.815 +
1.816 + return(KErrNone);
1.817 + }
1.818 +
1.819 +