sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\bench\t_proc1.cpp sl@0: // One half of the process relative type test stuff sl@0: // Overview: sl@0: // Tests the RProcess class, including tests on the heap, process naming, sl@0: // process resumption, process creation and shared chunks. sl@0: // API Information: sl@0: // RProcess sl@0: // Details: sl@0: // - Open a nonexistent process by a process Id and checks for the failure sl@0: // of finding this process. sl@0: // - Open a process with invalid name and verify failure results are as expected. sl@0: // - Test the closing of processes by calling Kill, Terminate, and Panic methods. sl@0: // Verify results are as expected. sl@0: // - Create a process and verify the full path name of the loaded executable on sl@0: // which this process is based. sl@0: // - Open a process by name, rename the process in a variety of ways and verify sl@0: // the results are as expected. sl@0: // - Open a process, assign high, low, and bad priorities, verify the results sl@0: // are as expected. sl@0: // - Open a process, kill it and verify the results are as expected. sl@0: // - Open a process by name based on the file name, verify the results are as sl@0: // expected. sl@0: // - Retrieve the process Id and open a handle on it. Create a duplicate process. sl@0: // Verify the results are as expected. sl@0: // - Find a process using TFindProcess() and open a handle on it. Verify the sl@0: // results are as expected. sl@0: // - Check chunk sharing between threads and verify results are as expected. sl@0: // - Perform a "speed" test where a new thread is created and the thread increments sl@0: // a count until stopped. Calculate and display counts per second. Verify results sl@0: // are as expected. sl@0: // - Verify the ExitReason, ExitType and ExitCatagory when the thread dies. sl@0: // - Verify that stopping the process completes existing pending requests with sl@0: // KErrServerTerminated. sl@0: // - Verify that the heap was not corrupted by the tests. sl@0: // Platforms/Drives/Compatibility: sl@0: // All. sl@0: // Assumptions/Requirement/Pre-requisites: sl@0: // Failures and causes: sl@0: // Base Port information: sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include "../mmu/mmudetect.h" sl@0: #include "t_proc.h" sl@0: sl@0: LOCAL_D RTest test(_L("T_PROC1")); sl@0: sl@0: const TBufC<67> tooLong=_L("This should return KErrBadName and not crash.......0123456789ABCDEF"); sl@0: const TBufC<66> notQuiteTooLong=_L("This should return KErrNone and be completely OK..0123456789ABCDEF"); sl@0: const TBufC<26> bond=_L("Bond, James Bond[00000000]"); sl@0: const TBufC<16> jamesBond=_L("Bond, James Bond"); sl@0: sl@0: RProcess proc; sl@0: RProcess proc2; sl@0: RProcess proc3; sl@0: RProcess proc4; sl@0: sl@0: TName command; sl@0: TRequestStatus stat,notStat; sl@0: sl@0: const TInt KKillReason=2563453; sl@0: const TInt KTerminateReason=8034255; sl@0: const TInt KPanicReason=39365235; sl@0: sl@0: LOCAL_D RSemaphore client; sl@0: LOCAL_D TInt speedCount; sl@0: sl@0: class RDisplay : public RSessionBase sl@0: { sl@0: public: sl@0: TInt Open(); sl@0: TInt Display(const TDesC& aMessage); sl@0: TInt Read(); sl@0: TInt Write(); sl@0: TInt Stop(); sl@0: TInt Test(); sl@0: TVersion Version(); sl@0: }; sl@0: sl@0: TInt RDisplay::Open() sl@0: // sl@0: // Open the server. sl@0: // sl@0: { sl@0: sl@0: return(CreateSession(_L("Display"),Version(),1)); sl@0: } sl@0: sl@0: TInt RDisplay::Display(const TDesC& aMessage) sl@0: // sl@0: // Display a message. sl@0: // sl@0: { sl@0: sl@0: TBuf<0x10> b(aMessage); sl@0: return(SendReceive(CMyServer::EDisplay,TIpcArgs(&b))); sl@0: } sl@0: sl@0: TInt RDisplay::Read() sl@0: // sl@0: // Get session to test CSession2::ReadL. sl@0: // sl@0: { sl@0: sl@0: TBuf<0x10> b(_L("Testing read")); sl@0: return(SendReceive(CMyServer::ERead,TIpcArgs(&b))); sl@0: } sl@0: sl@0: TInt RDisplay::Write() sl@0: // sl@0: // Get session to test CSession2::WriteL. sl@0: // sl@0: { sl@0: sl@0: TBuf<0x10> b; sl@0: TBufC<0x10> c; // Bad descriptor - read only sl@0: TInt r=SendReceive(CMyServer::EWrite,TIpcArgs(&b,&c)); sl@0: if (r==KErrNone && b!=_L("It worked!")) sl@0: r=KErrGeneral; sl@0: return r; sl@0: } sl@0: sl@0: TInt RDisplay::Test() sl@0: // sl@0: // Send a message and wait for completion. sl@0: // sl@0: { sl@0: sl@0: TInt i[4]; sl@0: return(SendReceive(CMyServer::ETest,TIpcArgs(&i[0]))); sl@0: } sl@0: sl@0: TInt RDisplay::Stop() sl@0: // sl@0: // Stop the server. sl@0: // sl@0: { sl@0: sl@0: TInt i[4]; sl@0: return(SendReceive(CMyServer::EStop,TIpcArgs(&i[0]))); sl@0: } sl@0: sl@0: TVersion RDisplay::Version() sl@0: // sl@0: // Return the current version. sl@0: // sl@0: { sl@0: sl@0: TVersion v(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber); sl@0: return(v); sl@0: } sl@0: sl@0: LOCAL_C TInt RunPanicThread(RThread& aThread) sl@0: { sl@0: TRequestStatus s; sl@0: aThread.Logon(s); sl@0: TBool jit = User::JustInTime(); sl@0: User::SetJustInTime(EFalse); sl@0: aThread.Resume(); sl@0: User::WaitForRequest(s); sl@0: User::SetJustInTime(jit); sl@0: return s.Int(); sl@0: } sl@0: sl@0: TInt KillProtectedEntry(TAny*) sl@0: { sl@0: proc.Kill(KErrGeneral); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: TInt createProc2(RProcess& aProcess) sl@0: { sl@0: TFileName filename(RProcess().FileName()); sl@0: TInt pos=filename.LocateReverse(TChar('\\')); sl@0: filename.SetLength(pos+1); sl@0: filename+=_L("T_PROC2.EXE"); sl@0: TInt r=aProcess.Create(filename, command); sl@0: if (r==KErrNone) sl@0: { sl@0: TFullName fn(aProcess.FullName()); sl@0: test.Printf(_L("Created %S\n"),&fn); sl@0: } sl@0: return r; sl@0: } sl@0: sl@0: void simpleTests1() sl@0: { sl@0: test.Next(_L("Open by name")); sl@0: RProcess me; sl@0: TInt r=proc2.Open(me.Name()); sl@0: test(r==KErrNone); sl@0: test.Next(_L("Rename")); sl@0: TName initName(me.Name()); sl@0: r=User::RenameProcess(jamesBond); sl@0: test(r==KErrNone); sl@0: test(me.Name().Left(26)==bond); sl@0: test(proc2.Name().Left(26)==bond); sl@0: r=User::RenameProcess(tooLong); sl@0: test(r==KErrBadName); sl@0: test(me.Name().Left(26)==bond); sl@0: test(proc2.Name().Left(26)==bond); sl@0: TName* work=new TName(notQuiteTooLong); sl@0: r=User::RenameProcess(*work); sl@0: test(r==KErrNone); sl@0: work->Append(_L("[00000000]")); sl@0: test(me.Name().Length()==KMaxKernelName); sl@0: test(me.Name().Left(KMaxKernelName-4)==*work); sl@0: test(proc2.Name().Length()==KMaxKernelName); sl@0: test(proc2.Name().Left(KMaxKernelName-4)==*work); sl@0: delete work; sl@0: r=User::RenameProcess(_L("T_PROC1")); sl@0: test(r==KErrNone); sl@0: TFullName fn(_L("T_PROC1[")); sl@0: TUidType uidType(me.Type()); sl@0: TUint32 uid3 = uidType[2].iUid; sl@0: fn.AppendNumFixedWidth(uid3,EHex,8); sl@0: fn.Append(']'); sl@0: test(proc2.Name().Left(17)==fn); sl@0: test(me.Name().Left(17)==fn); sl@0: TInt l = initName.Locate('['); sl@0: r=User::RenameProcess(initName.Left(l)); sl@0: test(r==KErrNone); sl@0: test(proc2.Name()==initName); sl@0: proc2.Close(); sl@0: } sl@0: sl@0: TInt BadPriority(TAny* proc2) sl@0: { sl@0: ((RProcess*)proc2)->SetPriority(EPriorityWindowServer); sl@0: return KErrNone; sl@0: } sl@0: sl@0: void simpleTests2() sl@0: { sl@0: TInt r=proc2.Open(proc.Name()); sl@0: test.Next(_L("Mess with Priority")); sl@0: proc.SetPriority(EPriorityHigh); sl@0: test.Printf(_L("%d %d\n"),proc.Priority(),proc2.Priority()); sl@0: test(proc.Priority()==EPriorityHigh); sl@0: test(proc2.Priority()==EPriorityHigh); sl@0: proc2.SetPriority(EPriorityLow); sl@0: test(proc.Priority()==EPriorityLow); sl@0: test(proc2.Priority()==EPriorityLow); sl@0: sl@0: RThread thread; sl@0: r=thread.Create(_L("Bad Priority"),BadPriority,KDefaultStackSize,NULL,&proc2); sl@0: test(r==KErrNone); sl@0: r=RunPanicThread(thread); sl@0: test(r==EBadPriority); sl@0: test(thread.ExitType()==EExitPanic); sl@0: test(thread.ExitReason()==EBadPriority); sl@0: test(thread.ExitCategory()==_L("KERN-EXEC")); sl@0: CLOSE_AND_WAIT(thread); sl@0: test(proc.Priority()==EPriorityLow); sl@0: test(proc2.Priority()==EPriorityLow); sl@0: proc2.Close(); sl@0: } sl@0: sl@0: void procTests1() sl@0: { sl@0: test.Next(_L("Test functions")); sl@0: TFileName fileName(proc.FileName()); sl@0: test.Printf(fileName); sl@0: #ifndef __WINS__ sl@0: if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)) sl@0: test(fileName.Mid(1).CompareF(_L(":\\Sys\\Bin\\T_PROC2.EXE"))==0); sl@0: else sl@0: test(fileName.Mid(1).CompareF(_L(":\\System\\Bin\\T_PROC2.EXE"))==0); sl@0: #else sl@0: if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)) sl@0: test(fileName.CompareF(_L("Z:\\Sys\\Bin\\T_PROC2.EXE"))==0); sl@0: else sl@0: test(fileName.CompareF(_L("Z:\\System\\Bin\\T_PROC2.EXE"))==0); sl@0: #endif sl@0: test(proc.Name().Left(21).CompareF(_L("T_PROC2.EXE[00000000]"))==0); sl@0: test(proc.Priority()==EPriorityForeground); sl@0: test(proc.ExitType()==EExitPending); sl@0: test(proc.ExitReason()==0); sl@0: test(proc.ExitCategory()==KNullDesC); sl@0: } sl@0: sl@0: void procTests2() sl@0: { sl@0: test.Next(_L("Kill and recreate")); sl@0: RProcess proc2; sl@0: TInt r=proc2.Open(proc.Id()); sl@0: test(r==KErrNone); sl@0: test(proc2.Handle()!=0); sl@0: proc.Logon(stat); sl@0: proc.Logon(notStat); sl@0: r=proc.LogonCancel(notStat); sl@0: test(r==KErrNone); sl@0: test(notStat==KErrNone); sl@0: proc.Kill(KKillReason); sl@0: User::WaitForRequest(stat); sl@0: test(stat==KKillReason); sl@0: test(proc.ExitType()==EExitKill); sl@0: test(proc.ExitReason()==KKillReason); sl@0: test(proc.ExitCategory()==_L("Kill")); sl@0: proc.Close(); sl@0: test(proc.Handle()==0); sl@0: test(proc2.ExitType()==EExitKill); sl@0: test(proc2.ExitReason()==KKillReason); sl@0: test(proc2.ExitCategory()==_L("Kill")); sl@0: CLOSE_AND_WAIT(proc2); sl@0: test(proc2.Handle()==0); sl@0: } sl@0: sl@0: void procTests3() sl@0: { sl@0: TFileName filename(RProcess().FileName()); sl@0: TInt pos=filename.LocateReverse(TChar('\\')); sl@0: filename.SetLength(pos+1); sl@0: filename+=_L("T_PROC2.EXE"); sl@0: TInt r=proc.Create(filename, command); sl@0: test(r==KErrNone); sl@0: TFullName fn(proc.FullName()); sl@0: test.Printf(_L("Created %S\n"),&fn); sl@0: test(proc.FileName().CompareF(filename)==0); sl@0: test(proc.Name().Left(21).CompareF(_L("T_PROC2.EXE[00000000]"))==0); sl@0: test(proc.Priority()==EPriorityForeground); sl@0: test(proc.ExitType()==EExitPending); sl@0: test(proc.ExitReason()==0); sl@0: test(proc.ExitCategory()==KNullDesC); sl@0: } sl@0: sl@0: void procTests4() sl@0: { sl@0: test.Next(_L("Get and open by Id")); sl@0: TProcessId id=proc.Id(); sl@0: TProcessId id2=proc.Id(); sl@0: test(id==id2); sl@0: TInt r=proc2.Open(proc.Name()); sl@0: test(r==KErrNone); sl@0: id2=proc2.Id(); sl@0: test(id==id2); sl@0: r=proc3.Open(id); sl@0: test(r==KErrNone); sl@0: id2=proc3.Id(); sl@0: test(id==id2); sl@0: proc3.Close(); sl@0: if (HaveVirtMem()) sl@0: { sl@0: test.Next(_L("Create duplicate")); sl@0: r=createProc2(proc3); sl@0: test(r==KErrNone); sl@0: id2=proc3.Id(); sl@0: test(id!=id2); sl@0: test(*(TUint*)&id<*(TUint*)&id2); sl@0: } sl@0: } sl@0: sl@0: void procTests5() sl@0: { sl@0: test.Next(_L("Try to find processes")); sl@0: TFindProcess* findProc=new TFindProcess(_L("T_PROC2*")); sl@0: test(findProc!=NULL); sl@0: TFullName* result=new TFullName; sl@0: test(result!=NULL); sl@0: TInt r=findProc->Next(*result); sl@0: test(r==KErrNone); sl@0: TFullName temp = proc.FullName(); sl@0: test(result->CompareF(temp)==0); sl@0: r=findProc->Next(*result); sl@0: test(r==KErrNone); sl@0: test(result->CompareF(proc3.FullName())==0); sl@0: r=findProc->Next(*result); sl@0: test(r==KErrNotFound); sl@0: findProc->Find(_L("T?PROC2*]*")); sl@0: r=findProc->Next(*result); sl@0: test(r==KErrNone); sl@0: test(result->CompareF(temp)==0); sl@0: r=findProc->Next(*result); sl@0: test(r==KErrNone); sl@0: test(result->CompareF(proc3.FullName())==0); sl@0: delete result; sl@0: test.Next(_L("Open by find handle")); sl@0: r=proc4.Open(*findProc); sl@0: test(r==KErrNone); sl@0: TProcessId id=proc3.Id(); sl@0: TProcessId id2=proc4.Id(); sl@0: test(id==id2); sl@0: delete findProc; sl@0: } sl@0: sl@0: void procTests6() sl@0: { sl@0: test.Next(_L("Kill duplicate")); sl@0: proc3.Logon(stat); sl@0: test(stat==KRequestPending); sl@0: proc4.Kill(12345); sl@0: User::WaitForRequest(stat); sl@0: test(stat==12345); sl@0: } sl@0: sl@0: void createProcess() sl@0: // sl@0: // Create T_PROC2 and, on the way, do lots of basic tests sl@0: // sl@0: { sl@0: test.Start(_L("Create")); sl@0: TInt r=globSem1.CreateGlobal(_L("GlobSem1"), 0); sl@0: test(r==KErrNone); sl@0: r=globSem2.CreateGlobal(_L("GlobSem2"), 0); sl@0: test(r==KErrNone); sl@0: sl@0: r=createProc2(proc); sl@0: test(r==KErrNone); sl@0: sl@0: procTests1(); sl@0: sl@0: simpleTests1(); sl@0: simpleTests2(); sl@0: sl@0: procTests2(); sl@0: procTests3(); sl@0: procTests4(); sl@0: if (HaveVirtMem()) sl@0: { sl@0: procTests5(); sl@0: procTests6(); sl@0: } sl@0: sl@0: proc2.Close(); sl@0: proc3.Close(); sl@0: if (proc4.Handle()) sl@0: CLOSE_AND_WAIT(proc4); sl@0: sl@0: test.Next(_L("Resume")); sl@0: proc.Logon(stat); // logon to process sl@0: proc.Logon(notStat); sl@0: r=proc.LogonCancel(notStat); sl@0: test(r==KErrNone); sl@0: test(notStat==KErrNone); sl@0: test(proc.ExitType()==EExitPending); sl@0: proc.Resume(); sl@0: globSem1.Wait(); // wait for T_PROC2 to get started sl@0: test.End(); sl@0: } sl@0: sl@0: void murderProcess() sl@0: { sl@0: test.Start(_L("Kill")); sl@0: RProcess process; sl@0: TInt r=createProc2(process); sl@0: test(r==KErrNone); sl@0: TProcessId id=process.Id(); sl@0: TProcessId id2=process.Id(); sl@0: test(id==id2); sl@0: TRequestStatus stat; sl@0: process.Logon(stat); sl@0: test(process.ExitType()==EExitPending); sl@0: process.Kill(KKillReason); sl@0: User::WaitForRequest(stat); sl@0: test(stat==KKillReason); sl@0: test(process.ExitType()==EExitKill); sl@0: test(process.ExitReason()==KKillReason); sl@0: test(process.ExitCategory()==_L("Kill")); sl@0: CLOSE_AND_WAIT(process); sl@0: sl@0: test.Next(_L("Terminate")); sl@0: r=createProc2(process); sl@0: test(r==KErrNone); sl@0: id2=process.Id(); sl@0: test(*(TUint*)&id+2==*(TUint*)&id2); // use 2 ID's each time, one for process, one for thread sl@0: process.Logon(stat); sl@0: test(process.ExitType()==EExitPending); sl@0: process.Terminate(KTerminateReason); sl@0: User::WaitForRequest(stat); sl@0: test(stat==KTerminateReason); sl@0: test(process.ExitType()==EExitTerminate); sl@0: test(process.ExitReason()==KTerminateReason); sl@0: test(process.ExitCategory()==_L("Terminate")); sl@0: CLOSE_AND_WAIT(process); sl@0: sl@0: test.Next(_L("Panic")); sl@0: r=createProc2(process); sl@0: test(r==KErrNone); sl@0: id2=process.Id(); sl@0: test(*(TUint*)&id+4==*(TUint*)&id2); sl@0: test(process.ExitType()==EExitPending); sl@0: process.Logon(stat); sl@0: process.SetJustInTime(EFalse); // prevent the process panic from starting the debugger sl@0: process.Panic(_L("BOO!"),KPanicReason); sl@0: User::WaitForRequest(stat); sl@0: test(stat==KPanicReason); sl@0: test(process.ExitType()==EExitPanic); sl@0: test(process.ExitReason()==KPanicReason); sl@0: test(process.ExitCategory()==_L("BOO!")); sl@0: CLOSE_AND_WAIT(process); sl@0: test.End(); sl@0: } sl@0: sl@0: void sharedChunks() sl@0: { sl@0: test.Start(_L("Test chunk sharing between threads")); sl@0: sl@0: test.Next(_L("Create chunk Marmalade")); sl@0: TInt r=0; sl@0: RChunk chunk; sl@0: TInt size=0x1000; sl@0: TInt maxSize=0x5000; sl@0: r=chunk.CreateGlobal(_L("Marmalade"),size,maxSize); sl@0: test(r==KErrNone); sl@0: test.Next(_L("Write 0-9 to it")); sl@0: TUint8* base=chunk.Base(); sl@0: for (TInt8 j=0;j<10;j++) sl@0: *base++=j; // write 0 - 9 to the chunk sl@0: globSem2.Signal(); // T_PROC2 can check the chunk now sl@0: globSem1.Wait(); sl@0: chunk.Close(); // now it's ok to kill the chunk sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: TInt sharedChunks2(TAny* /*aDummy*/) sl@0: { sl@0: RTest test(_L("Shared Chunks 2")); sl@0: sl@0: test.Title(); sl@0: test.Start(_L("Test chunk sharing between threads")); sl@0: sl@0: test.Next(_L("Create chunk Marmalade")); sl@0: TInt r=0; sl@0: RChunk chunk; sl@0: TInt size=0x1000; sl@0: TInt maxSize=0x5000; sl@0: r=chunk.CreateGlobal(_L("Marmalade"),size,maxSize); sl@0: test(r==KErrNone); sl@0: test.Next(_L("Write 0-9 to it")); sl@0: TUint8* base=chunk.Base(); sl@0: for (TInt8 j=0;j<10;j++) sl@0: *base++=j; // write 0 - 9 to the chunk sl@0: globSem2.Signal(); // T_PROC2 can check the chunk now sl@0: globSem1.Wait(); sl@0: chunk.Close(); // now it's ok to kill the chunk sl@0: sl@0: test.End(); sl@0: return(KErrNone); sl@0: } sl@0: sl@0: TInt speedyThreadEntryPoint(TAny*) sl@0: // sl@0: // The entry point for the speed test thread. sl@0: // sl@0: { sl@0: RDisplay t; sl@0: TInt r=t.Open(); sl@0: test(r==KErrNone); sl@0: speedCount=0; sl@0: client.Signal(); sl@0: while ((r=t.Test())==KErrNone) sl@0: speedCount++; sl@0: t.Close(); sl@0: return r; sl@0: } sl@0: sl@0: TInt BadName(TAny*) sl@0: { sl@0: proc.Open(_L("*")); sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt sharedHeap(TAny*) sl@0: { sl@0: RTest test2(_L("sharedHeap")); sl@0: test2.Title(); sl@0: test2.Start(_L("Shared heap tests")); sl@0: sl@0: RAllocator* allocator = &User::Allocator(); sl@0: test2.Printf(_L("sharedHeap's heap is at %08x\n"), allocator); sl@0: sl@0: TInt size; sl@0: allocator->AllocSize(size); sl@0: test2.Printf(_L("sharedHeap's heap allocsize is %08x\n"),size); sl@0: sl@0: // Press a key only if running the test in manual mode. We will be sl@0: // able to ascertain this when RTest has been enhanced. sl@0: // test.Next(_L("Press a key to continue")); sl@0: // test2.Getch(); sl@0: sl@0: test2.End(); sl@0: return(KErrNone); sl@0: } sl@0: sl@0: _LIT(KTestProcessNewName,"T_PROC1_NEW.EXE"); sl@0: sl@0: TInt DupRenameProcTest(TInt aCall) sl@0: { sl@0: test.Printf(_L("DupRenameProcTest: call %d\n"),aCall); sl@0: sl@0: TInt r; sl@0: sl@0: switch(aCall) sl@0: { sl@0: case 1: sl@0: { sl@0: r = User::RenameProcess(KTestProcessNewName); sl@0: test(r==KErrNone); sl@0: TFullName fn(RProcess().FullName()); sl@0: test.Printf(_L("Renamed to %S\n"),&fn); sl@0: TInt li = fn.Locate('['); sl@0: TInt ri = fn.Locate(']'); sl@0: test(fn.Left(li)==KTestProcessNewName); sl@0: test(fn.Mid(ri+1)==_L("0001")); sl@0: } sl@0: sl@0: case 0: sl@0: { sl@0: TFileName filename(RProcess().FileName()); sl@0: TInt pos=filename.LocateReverse(TChar('\\')); sl@0: filename.SetLength(pos+1); sl@0: filename+=_L("T_PROC1.EXE"); sl@0: RProcess pr; sl@0: TBuf16<10> call; sl@0: call.Num(aCall+1); sl@0: r = pr.Create(filename, call); sl@0: TFullName fn(pr.FullName()); sl@0: test.Printf(_L("Created %S\n"),&fn); sl@0: TRequestStatus st; sl@0: pr.Logon(st); sl@0: pr.Resume(); sl@0: User::WaitForRequest(st); sl@0: CLOSE_AND_WAIT(pr); sl@0: } sl@0: return KErrNone; sl@0: sl@0: case 2: sl@0: { sl@0: r = User::RenameProcess(KTestProcessNewName); sl@0: test(r==KErrNone); sl@0: TFullName fn(RProcess().FullName()); sl@0: test.Printf(_L("Renamed to %S\n"),&fn); sl@0: TInt li = fn.Locate('['); sl@0: TInt ri = fn.Locate(']'); sl@0: test(fn.Left(li)==KTestProcessNewName); sl@0: test(fn.Mid(ri+1)==_L("0002")); sl@0: } sl@0: return KErrNone; sl@0: sl@0: default: sl@0: return KErrArgument; sl@0: } sl@0: } sl@0: sl@0: _LIT(KTestProcessName,"TestName"); sl@0: sl@0: void TestProcessRename() sl@0: { sl@0: // Rename the current process with test name sl@0: TInt r = User::RenameProcess(KTestProcessName); sl@0: test(r==KErrNone); sl@0: TName name1 = RProcess().Name(); sl@0: sl@0: // Check new name is correct sl@0: TName name2 = name1; sl@0: name2.SetLength(KTestProcessName().Length()); sl@0: test(name2.CompareF(KTestProcessName)==0); sl@0: sl@0: // Rename the process with same test name sl@0: r = User::RenameProcess(KTestProcessName); sl@0: test(r==KErrNone); sl@0: name2 = RProcess().Name(); sl@0: test(name1.Compare(name2)==0); // name should be unchanged sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: __KHEAP_MARK; sl@0: sl@0: // Turn off lazy dll unloading sl@0: RLoader l; sl@0: test(l.Connect()==KErrNone); sl@0: test(l.CancelLazyDllUnload()==KErrNone); sl@0: l.Close(); sl@0: sl@0: TBuf16<512> cmd; sl@0: User::CommandLine(cmd); sl@0: if(cmd.Length() && TChar(cmd[0]).IsDigit()) sl@0: { sl@0: TInt r = DupRenameProcTest(TUint(TChar(cmd[0])) - '0'); sl@0: test(r==KErrNone); sl@0: return 0; sl@0: } sl@0: sl@0: test.Title(); sl@0: sl@0: test.Start(_L("Testing process stuff 1")); sl@0: TInt r; sl@0: TRequestStatus s; sl@0: test.Next(_L("Creating semaphore")); sl@0: r=client.CreateLocal(0); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Try to open nonexistant process by ID")); sl@0: r=proc.Open(*(TProcessId*)&KMaxTUint); sl@0: test(r==KErrNotFound); sl@0: sl@0: test.Next(_L("Try to open process with invalid name")); sl@0: RThread thread; sl@0: r=thread.Create(_L("Bad Name"),BadName,KDefaultStackSize,NULL,NULL); sl@0: test(r==KErrNone); sl@0: TRequestStatus threadStat; sl@0: thread.Logon(threadStat); sl@0: TBool justInTime=User::JustInTime(); sl@0: User::SetJustInTime(EFalse); sl@0: thread.Resume(); sl@0: User::WaitForRequest(threadStat); sl@0: User::SetJustInTime(justInTime); sl@0: test(threadStat==EBadName); sl@0: test(thread.ExitType()==EExitPanic); sl@0: test(thread.ExitReason()==EBadName); sl@0: test(thread.ExitCategory()==_L("KERN-EXEC")); sl@0: CLOSE_AND_WAIT(thread); sl@0: sl@0: test.Next(_L("Murder processes in different ways")); sl@0: murderProcess(); sl@0: sl@0: test.Next(_L("Create second process")); sl@0: createProcess(); sl@0: sl@0: test.Next(_L("Shared Chunks from main thread")); sl@0: sharedChunks(); sl@0: sl@0: test.Next(_L("Shared chunks from secondary thread")); sl@0: RThread t; sl@0: r=t.Create(_L("Shared chunks 2"),sharedChunks2,KDefaultStackSize,KHeapSize,KHeapSize,NULL); sl@0: test(r==KErrNone); sl@0: t.Logon(s); sl@0: t.Resume(); sl@0: User::WaitForRequest(s); sl@0: test(s==KErrNone); sl@0: CLOSE_AND_WAIT(t); sl@0: sl@0: test.Next(_L("Starting speedy client")); sl@0: RThread speedy; sl@0: r=speedy.Create(_L("Speedy"),speedyThreadEntryPoint,KDefaultStackSize,KHeapSize,KHeapSize,NULL); sl@0: test(r==KErrNone); sl@0: sl@0: RThread().SetPriority(EPriorityMuchMore); sl@0: speedy.SetPriority(EPriorityNormal); sl@0: TRequestStatus speedyStatus; sl@0: speedy.Logon(speedyStatus); sl@0: speedy.Resume(); sl@0: sl@0: test.Next(_L("Wait for speedy to start")); sl@0: client.Wait(); sl@0: sl@0: globSem1.Wait(); // wait for proc2 to be nice & quiet sl@0: test.Printf(_L("Starting speed test...\n")); sl@0: User::After(300000); sl@0: TInt b=speedCount; sl@0: User::After(3000000); sl@0: TInt n=speedCount; sl@0: test.Printf(_L("Count = %d in 1 second\n"),(n-b)/3); sl@0: sl@0: test.Next(_L("Tell second process speed tests are done")); sl@0: globSem2.Signal(); sl@0: sl@0: test.Next(_L("Process Logon")); sl@0: User::WaitForRequest(stat); sl@0: const TDesC& cat=proc.ExitCategory(); sl@0: test.Printf(_L("Exit category = %S\n"),&cat); sl@0: test.Printf(_L("Exit reason = %x\n"),proc.ExitReason()); sl@0: test.Printf(_L("Exit type = %x\n"),proc.ExitType()); sl@0: sl@0: test(stat==KErrNone); sl@0: test(proc.ExitCategory()==_L("Kill")); sl@0: test(proc.ExitReason()==KErrNone); sl@0: test(proc.ExitType()==EExitKill); sl@0: test(notStat==KErrNone); sl@0: test.Next(_L("Test LogonCancel to dead process is ok")); sl@0: r=proc.LogonCancel(stat); sl@0: test(r==KErrGeneral); sl@0: globSem1.Close(); sl@0: globSem2.Close(); sl@0: client.Close(); sl@0: sl@0: User::WaitForRequest(speedyStatus); sl@0: test(speedyStatus==KErrServerTerminated); sl@0: test(speedy.ExitReason()==KErrServerTerminated); sl@0: test(speedy.ExitType()==EExitKill); sl@0: CLOSE_AND_WAIT(speedy); sl@0: CLOSE_AND_WAIT(proc); sl@0: sl@0: User::After(5000000); // wait for MMC session to disappear sl@0: sl@0: test.Next(_L("Test rename of the processes with duplicate names")); sl@0: r = DupRenameProcTest(0); sl@0: test(r==KErrNone); sl@0: sl@0: TestProcessRename(); sl@0: sl@0: test.Next(_L("Check for kernel alloc heaven")); sl@0: __KHEAP_MARKEND; sl@0: sl@0: test.End(); sl@0: sl@0: return(KErrNone); sl@0: } sl@0: sl@0: