sl@0: // Copyright (c) 2005-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\system\t_svr_connect.cpp sl@0: // Overview: sl@0: // Tests correct operation of server when interleaving connect/disconnect/ sl@0: // other messages and creating the user-side session object (setting the sl@0: // session cookie) in interesting manners. sl@0: // Tests that clients/servers are panicked when performing illegal operations sl@0: // w.r.t. server connection, i.e. a client thread may not send more than one sl@0: // connect message simultaneously, nor may it send another connect message sl@0: // once a connect message has been successfully completed. Similarly, a server sl@0: // may not set the cookie twice nor may it set the cookie to be NULL. Also, a sl@0: // server may only set the cookie from a connect message and from no other. sl@0: // API Information: sl@0: // RServer2 sl@0: // Details: sl@0: // - Test asynchronous server connect in various ways. Verify results sl@0: // are as expected. sl@0: // - Test illegal client/server behaviour. Verify threads are panicked, sl@0: // as expected. sl@0: // Platforms/Drives/Compatibility: sl@0: // All. sl@0: // Assumptions/Requirement/Pre-requisites: sl@0: // None. sl@0: // Failures and causes: sl@0: // Failure of this test would be caused by an incorrect modification of sl@0: // the internal client/server mechanism in the kernel. sl@0: // Base Port information: sl@0: // This is a unit test of the client/server mechanism within the kernel. sl@0: // It should be invariant to base ports. If the kernel proper has not been sl@0: // modified, this test should not fail with any new base port. sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include "../misc/int_svr_calls.h" sl@0: #include sl@0: sl@0: _LIT(KTestName, "t_svr_connect"); sl@0: LOCAL_D RTest test(KTestName); sl@0: LOCAL_D RTest test_client(KTestName); sl@0: LOCAL_D RTest test_server(KTestName); sl@0: sl@0: _LIT(KServerName, "t_svr_connect"); sl@0: _LIT8(KServerName8, "t_svr_connect"); sl@0: _LIT(KMainThread, "main thread"); sl@0: _LIT(KServerThread, "server thread"); sl@0: _LIT(KClientThread, "client thread"); sl@0: _LIT(KClientThread2, "client thread2"); sl@0: _LIT(KClientThread3, "client thread3"); sl@0: sl@0: class RTestServer : public RSessionBase sl@0: { sl@0: public: sl@0: inline static TInt CreateSession(TInt aMsgSlots) { return SessionCreate(KServerName8,aMsgSlots,NULL,EIpcSession_Sharable); } sl@0: }; sl@0: sl@0: // Messages to send: sl@0: // sl@0: // connect, 1 sl@0: // a.n.other, 2 sl@0: // disconnect 3 sl@0: // sl@0: // Things to do in the server: sl@0: // sl@0: // recieve connect 4 sl@0: // set cookie 5 sl@0: // complete connect 6 sl@0: // receive a.n.other 7 sl@0: // complete a.n.other 8 sl@0: // receive disconnect 9 sl@0: // complete disconnect 10 sl@0: // sl@0: sl@0: enum TMsgType sl@0: { sl@0: EConnect = -1, sl@0: EDisConnect = -2, sl@0: EANOther = 1, sl@0: EANOther2 = 2, sl@0: EMsgCount = 4 sl@0: }; sl@0: sl@0: enum TServerControl sl@0: { sl@0: EReceiveMsg = 0, sl@0: EReceiveBlocked = 1, sl@0: EWaitForReceive = 2, sl@0: ESetCookie = 3, sl@0: ESetNullCookie = 4, sl@0: ECompleteMsg = 5, sl@0: EServerDie = 6 sl@0: }; sl@0: sl@0: enum TClientControl sl@0: { sl@0: ESendMsg = 0, sl@0: EWaitMsg = 1, sl@0: ECreateSession = 2, sl@0: EClientDie = 3, sl@0: ESetCritical = 4 sl@0: }; sl@0: sl@0: static TMsgType TheMsgType; sl@0: static TServerControl TheServerControl; sl@0: static TClientControl TheClientControl; sl@0: static RSemaphore ServerSemaphore; sl@0: static RSemaphore ClientSemaphore; sl@0: static RSemaphore TaskCompletionSemaphore; sl@0: static RMessage2 Msgs[EMsgCount]; sl@0: static RServer2 Server; sl@0: static RThread ServerThread; sl@0: static RThread ClientThread; sl@0: static RTestServer ServerHandle; sl@0: static TRequestStatus ConnectStatus; sl@0: static TRequestStatus ANOtherStatus; sl@0: static TRequestStatus ANOther2Status; sl@0: static TRequestStatus ServerReceiveStatus; sl@0: static TInt TheNumberOfMsgSlots; sl@0: static TInt ErrorExpected; sl@0: static User::TCritical CriticalLevel; sl@0: sl@0: sl@0: static const TAny* const KSessionCookie = (const TAny*)0x12345; sl@0: static TRequestStatus* volatile KNullReference = 0; sl@0: sl@0: void DoServerAction(); sl@0: void DoClientAction(); sl@0: TInt Index(); sl@0: sl@0: TInt TestThreadServer(TAny*) sl@0: { sl@0: test_server(Server.CreateGlobal(KServerName) == KErrNone); sl@0: RThread::Rendezvous(KErrNone); sl@0: sl@0: for (;;) sl@0: { sl@0: ServerSemaphore.Wait(); sl@0: DoServerAction(); sl@0: TaskCompletionSemaphore.Signal(); sl@0: } sl@0: } sl@0: sl@0: TInt Index() sl@0: { sl@0: switch (TheMsgType) sl@0: { sl@0: case EConnect: sl@0: return 0; sl@0: case EDisConnect: sl@0: return 3; sl@0: case EANOther: sl@0: return 1; sl@0: case EANOther2: sl@0: return 2; sl@0: default: sl@0: return -1; sl@0: }; sl@0: } sl@0: sl@0: TRequestStatus& RequestStatus() sl@0: { sl@0: switch (TheMsgType) sl@0: { sl@0: case EConnect: sl@0: return ConnectStatus; sl@0: case EANOther: sl@0: return ANOtherStatus; sl@0: case EANOther2: sl@0: return ANOther2Status; sl@0: default: sl@0: User::Invariant(); sl@0: }; sl@0: return *(TRequestStatus*)KNullReference; sl@0: } sl@0: sl@0: void DoServerAction() sl@0: { sl@0: switch (TheServerControl) sl@0: { sl@0: case EReceiveMsg: sl@0: { sl@0: RMessage2& msg = Msgs[Index()]; sl@0: Server.Receive(msg); sl@0: test_server(msg.Function() == TheMsgType); sl@0: } sl@0: break; sl@0: case EReceiveBlocked: sl@0: { sl@0: RMessage2& msg = Msgs[Index()]; sl@0: Server.Receive(msg, ServerReceiveStatus); sl@0: test_server(ServerReceiveStatus.Int() == KRequestPending); sl@0: } sl@0: break; sl@0: case EWaitForReceive: sl@0: { sl@0: User::WaitForRequest(ServerReceiveStatus); sl@0: test_server(ServerReceiveStatus.Int() == KErrNone); sl@0: test_server(Msgs[Index()].Function() == TheMsgType); sl@0: } sl@0: break; sl@0: case ESetCookie: sl@0: { sl@0: SetSessionPtr(Msgs[Index()].Handle(), KSessionCookie); sl@0: } sl@0: break; sl@0: case ESetNullCookie: sl@0: { sl@0: SetSessionPtr(Msgs[Index()].Handle(), NULL); sl@0: } sl@0: break; sl@0: case ECompleteMsg: sl@0: { sl@0: Msgs[Index()].Complete(KErrNone); sl@0: } sl@0: break; sl@0: case EServerDie: sl@0: { sl@0: User::Exit(0); sl@0: } sl@0: break; sl@0: default: sl@0: { sl@0: } sl@0: break; sl@0: }; sl@0: } sl@0: sl@0: void StartServer() sl@0: { sl@0: ServerThread.Create(KServerThread, TestThreadServer, KDefaultStackSize, 4096, 4096, NULL); sl@0: sl@0: TRequestStatus started; sl@0: ServerThread.Rendezvous(started); sl@0: sl@0: ServerThread.Resume(); sl@0: User::WaitForRequest(started); sl@0: sl@0: test(started.Int() == KErrNone); sl@0: } sl@0: sl@0: void StopServer() sl@0: { sl@0: TRequestStatus logon; sl@0: ServerThread.Logon(logon); sl@0: sl@0: TheServerControl = EServerDie; sl@0: ServerSemaphore.Signal(); sl@0: sl@0: User::WaitForRequest(logon); sl@0: test(logon.Int() == KErrNone); sl@0: sl@0: CLOSE_AND_WAIT(ServerThread); sl@0: } sl@0: sl@0: TInt TestThreadClient(TAny*) sl@0: { sl@0: RThread::Rendezvous(KErrNone); sl@0: sl@0: for (;;) sl@0: { sl@0: ClientSemaphore.Wait(); sl@0: DoClientAction(); sl@0: TaskCompletionSemaphore.Signal(); sl@0: } sl@0: } sl@0: sl@0: void DoClientAction() sl@0: { sl@0: switch (TheClientControl) sl@0: { sl@0: case ESendMsg: sl@0: { sl@0: if (TheMsgType == EDisConnect) sl@0: ServerHandle.Close(); sl@0: else sl@0: SessionSend(ServerHandle.Handle(), TheMsgType, NULL, &RequestStatus()); sl@0: } sl@0: break; sl@0: case EWaitMsg: sl@0: { sl@0: User::WaitForRequest(RequestStatus()); sl@0: } sl@0: break; sl@0: case ECreateSession: sl@0: { sl@0: TInt err = ServerHandle.SetReturnedHandle(RTestServer::CreateSession(TheNumberOfMsgSlots)); sl@0: sl@0: if (err != ErrorExpected) sl@0: { sl@0: test_client.Printf(_L("Error returned = %d\n"),err); sl@0: test_client(EFalse,__LINE__); sl@0: } sl@0: } sl@0: break; sl@0: case EClientDie: sl@0: { sl@0: User::SetCritical(User::ENotCritical); sl@0: User::Exit(0); sl@0: } sl@0: break; sl@0: case ESetCritical: sl@0: { sl@0: User::SetCritical(CriticalLevel); sl@0: break; sl@0: } sl@0: default: sl@0: { sl@0: } sl@0: break; sl@0: }; sl@0: } sl@0: sl@0: // I'm lazy and I haven't completed all the IPC the client thread does, sl@0: // so even when the client thread panics, the DObject is still kept alive sl@0: // until the server goes away. Therefore if I want another client I rename. sl@0: void StartClient(const TDesC& aName) sl@0: { sl@0: ClientThread.Create(aName, TestThreadClient, KDefaultStackSize, 4096, 4096, NULL); sl@0: sl@0: TRequestStatus started; sl@0: ClientThread.Rendezvous(started); sl@0: sl@0: ClientThread.Resume(); sl@0: User::WaitForRequest(started); sl@0: sl@0: test(started.Int() == KErrNone); sl@0: } sl@0: sl@0: void StartClient() sl@0: { sl@0: StartClient(KClientThread); sl@0: } sl@0: sl@0: void StopClient() sl@0: { sl@0: TRequestStatus logon; sl@0: ClientThread.Logon(logon); sl@0: sl@0: TheClientControl = EClientDie; sl@0: ClientSemaphore.Signal(); sl@0: sl@0: User::WaitForRequest(logon); sl@0: test(logon.Int() == KErrNone); sl@0: sl@0: CLOSE_AND_WAIT(ClientThread); sl@0: } sl@0: sl@0: void CreateSemaphores() sl@0: { sl@0: TInt err = ServerSemaphore.CreateLocal(0); sl@0: test(err == KErrNone); sl@0: err = ClientSemaphore.CreateLocal(0); sl@0: test(err == KErrNone); sl@0: err = TaskCompletionSemaphore.CreateLocal(0); sl@0: test(err == KErrNone); sl@0: } sl@0: sl@0: void CloseSemaphores() sl@0: { sl@0: ServerSemaphore.Close(); sl@0: ClientSemaphore.Close(); sl@0: TaskCompletionSemaphore.Close(); sl@0: } sl@0: sl@0: void CreateSession(TInt aErrorExpected=KErrNone, TInt aMsgSlots=-1) sl@0: { sl@0: TheClientControl = ECreateSession; sl@0: TheNumberOfMsgSlots = aMsgSlots; sl@0: ErrorExpected=aErrorExpected; sl@0: ClientSemaphore.Signal(); sl@0: TaskCompletionSemaphore.Wait(); sl@0: } sl@0: sl@0: void SendMsg(TMsgType aType) sl@0: { sl@0: TheClientControl = ESendMsg; sl@0: TheMsgType = aType; sl@0: ClientSemaphore.Signal(); sl@0: TaskCompletionSemaphore.Wait(); sl@0: } sl@0: sl@0: void SendMsg_NoWait(TMsgType aType) sl@0: { sl@0: TheClientControl = ESendMsg; sl@0: TheMsgType = aType; sl@0: ClientSemaphore.Signal(); sl@0: } sl@0: sl@0: void WaitMsg(TMsgType aType) sl@0: { sl@0: TheClientControl = EWaitMsg; sl@0: TheMsgType = aType; sl@0: ClientSemaphore.Signal(); sl@0: TaskCompletionSemaphore.Wait(); sl@0: } sl@0: sl@0: void ReceiveBlocked(TMsgType aType) sl@0: { sl@0: TheServerControl = EReceiveBlocked; sl@0: TheMsgType = aType; sl@0: ServerSemaphore.Signal(); sl@0: TaskCompletionSemaphore.Wait(); sl@0: } sl@0: sl@0: void WaitForReceive(TMsgType aType) sl@0: { sl@0: TheServerControl = EWaitForReceive; sl@0: TheMsgType = aType; sl@0: ServerSemaphore.Signal(); sl@0: TaskCompletionSemaphore.Wait(); sl@0: } sl@0: sl@0: void ReceiveMsg(TMsgType aType) sl@0: { sl@0: TheServerControl = EReceiveMsg; sl@0: TheMsgType = aType; sl@0: ServerSemaphore.Signal(); sl@0: TaskCompletionSemaphore.Wait(); sl@0: } sl@0: sl@0: void CompleteMsg(TMsgType aType) sl@0: { sl@0: TheServerControl = ECompleteMsg; sl@0: TheMsgType = aType; sl@0: ServerSemaphore.Signal(); sl@0: TaskCompletionSemaphore.Wait(); sl@0: } sl@0: sl@0: void SetCookie() sl@0: { sl@0: TheServerControl = ESetCookie; sl@0: TheMsgType = EConnect; sl@0: ServerSemaphore.Signal(); sl@0: TaskCompletionSemaphore.Wait(); sl@0: } sl@0: sl@0: void SetCookie_NoWait() sl@0: { sl@0: TheServerControl = ESetCookie; sl@0: TheMsgType = EConnect; sl@0: ServerSemaphore.Signal(); sl@0: } sl@0: sl@0: void SetNullCookie() sl@0: { sl@0: TheServerControl = ESetNullCookie; sl@0: TheMsgType = EConnect; sl@0: ServerSemaphore.Signal(); sl@0: } sl@0: sl@0: void SetBadCookie(TMsgType aType) sl@0: { sl@0: TheServerControl = ESetCookie; sl@0: test(aType != EConnect); sl@0: TheMsgType = aType; sl@0: ServerSemaphore.Signal(); sl@0: } sl@0: void SetClientCritical(User::TCritical aCritical) sl@0: { sl@0: TheClientControl = ESetCritical; sl@0: CriticalLevel=aCritical; sl@0: ClientSemaphore.Signal(); sl@0: TaskCompletionSemaphore.Wait(); sl@0: } sl@0: sl@0: void Test1() sl@0: { sl@0: test.Next(_L("Create session with test server")); sl@0: CreateSession(); sl@0: test.Next(_L("Send connect message")); sl@0: SendMsg(EConnect); sl@0: test.Next(_L("Send A.N.Other message")); sl@0: SendMsg(EANOther); sl@0: test.Next(_L("Sending disconnect message")); sl@0: SendMsg(EDisConnect); sl@0: test.Next(_L("Receive A.N.Other message")); sl@0: ReceiveMsg(EANOther); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: test.Next(_L("Receive disconnect message")); sl@0: ReceiveMsg(EDisConnect); sl@0: test.Next(_L("Check the session has gone")); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: test.Next(_L("Set up receive for next test")); sl@0: ReceiveBlocked(EConnect); sl@0: } sl@0: sl@0: void Test2() sl@0: { sl@0: test.Next(_L("Create session with test server")); sl@0: CreateSession(); sl@0: test.Next(_L("Send connect message")); sl@0: SendMsg(EConnect); sl@0: test.Next(_L("Send A.N.Other message")); sl@0: SendMsg(EANOther); sl@0: test.Next(_L("Receive connect message")); sl@0: WaitForReceive(EConnect); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: test.Next(_L("Receive A.N.Other message")); sl@0: ReceiveMsg(EANOther); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: test.Next(_L("Sending disconnect message")); sl@0: SendMsg(EDisConnect); sl@0: test.Next(_L("Await disconnect message")); sl@0: ReceiveBlocked(EDisConnect); sl@0: test.Next(_L("Set cookie")); sl@0: SetCookie(); sl@0: test.Next(_L("Check disconnect message received")); sl@0: WaitForReceive(EDisConnect); sl@0: test(Msgs[Index()].Session() == KSessionCookie); sl@0: test.Next(_L("Complete connect message")); sl@0: CompleteMsg(EConnect); sl@0: } sl@0: sl@0: void Test2a() sl@0: { sl@0: CreateSession(); sl@0: SendMsg(EConnect); sl@0: SendMsg(EANOther); sl@0: ReceiveMsg(EConnect); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: ReceiveMsg(EANOther); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: SendMsg(EDisConnect); sl@0: ReceiveBlocked(EDisConnect); sl@0: CompleteMsg(EConnect); sl@0: WaitForReceive(EDisConnect); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: } sl@0: sl@0: void Test2b() sl@0: { sl@0: CreateSession(); sl@0: SendMsg(EConnect); sl@0: SendMsg(EANOther); sl@0: ReceiveMsg(EConnect); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: SetCookie(); sl@0: ReceiveMsg(EANOther); sl@0: test(Msgs[Index()].Session() == KSessionCookie); sl@0: SendMsg(EDisConnect); sl@0: ReceiveMsg(EDisConnect); sl@0: test(Msgs[Index()].Session() == KSessionCookie); sl@0: } sl@0: sl@0: void Test3() sl@0: { sl@0: CreateSession(); sl@0: SendMsg(EConnect); sl@0: ReceiveMsg(EConnect); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: SendMsg(EANOther); sl@0: ReceiveMsg(EANOther); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: SendMsg(EDisConnect); sl@0: ReceiveBlocked(EDisConnect); sl@0: SetCookie(); sl@0: WaitForReceive(EDisConnect); sl@0: test(Msgs[Index()].Session() == KSessionCookie); sl@0: CompleteMsg(EConnect); sl@0: } sl@0: sl@0: void Test3a() sl@0: { sl@0: CreateSession(); sl@0: SendMsg(EConnect); sl@0: ReceiveMsg(EConnect); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: SendMsg(EANOther); sl@0: ReceiveMsg(EANOther); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: SendMsg(EDisConnect); sl@0: ReceiveBlocked(EDisConnect); sl@0: CompleteMsg(EConnect); sl@0: WaitForReceive(EDisConnect); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: } sl@0: sl@0: void Test3b() sl@0: { sl@0: CreateSession(); sl@0: SendMsg(EConnect); sl@0: ReceiveMsg(EConnect); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: SetCookie(); sl@0: SendMsg(EANOther); sl@0: ReceiveMsg(EANOther); sl@0: test(Msgs[Index()].Session() == KSessionCookie); sl@0: SendMsg(EDisConnect); sl@0: ReceiveMsg(EDisConnect); sl@0: test(Msgs[Index()].Session() == KSessionCookie); sl@0: } sl@0: sl@0: void Test4() sl@0: { sl@0: CreateSession(); sl@0: SendMsg(EANOther); sl@0: SendMsg(EConnect); sl@0: SendMsg(EANOther2); sl@0: SendMsg(EDisConnect); sl@0: ReceiveMsg(EANOther); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: ReceiveMsg(EANOther2); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: ReceiveMsg(EDisConnect); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: } sl@0: sl@0: void Test5() sl@0: { sl@0: CreateSession(); sl@0: SendMsg(EANOther); sl@0: SendMsg(EConnect); sl@0: SendMsg(EANOther2); sl@0: ReceiveMsg(EANOther); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: SendMsg(EDisConnect); sl@0: ReceiveMsg(EANOther2); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: ReceiveMsg(EDisConnect); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: ReceiveBlocked(EANOther); sl@0: } sl@0: sl@0: void Test6() sl@0: { sl@0: CreateSession(); sl@0: SendMsg(EANOther); sl@0: SendMsg(EConnect); sl@0: SendMsg(EANOther2); sl@0: WaitForReceive(EANOther); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: ReceiveMsg(EConnect); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: ReceiveMsg(EANOther2); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: SendMsg(EDisConnect); sl@0: ReceiveBlocked(EDisConnect); sl@0: SetCookie(); sl@0: WaitForReceive(EDisConnect); sl@0: test(Msgs[Index()].Session() == KSessionCookie); sl@0: CompleteMsg(EConnect); sl@0: } sl@0: sl@0: void Test6a() sl@0: { sl@0: CreateSession(); sl@0: SendMsg(EANOther); sl@0: SendMsg(EConnect); sl@0: SendMsg(EANOther2); sl@0: ReceiveMsg(EANOther); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: ReceiveMsg(EConnect); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: ReceiveMsg(EANOther2); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: SendMsg(EDisConnect); sl@0: ReceiveBlocked(EDisConnect); sl@0: CompleteMsg(EConnect); sl@0: WaitForReceive(EDisConnect); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: } sl@0: sl@0: void Test6b() sl@0: { sl@0: CreateSession(); sl@0: SendMsg(EANOther); sl@0: SendMsg(EConnect); sl@0: SendMsg(EANOther2); sl@0: ReceiveMsg(EANOther); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: ReceiveMsg(EConnect); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: SetCookie(); sl@0: ReceiveMsg(EANOther2); sl@0: test(Msgs[Index()].Session() == KSessionCookie); sl@0: SendMsg(EDisConnect); sl@0: ReceiveMsg(EDisConnect); sl@0: test(Msgs[Index()].Session() == KSessionCookie); sl@0: } sl@0: sl@0: void Test7() sl@0: { sl@0: CreateSession(); sl@0: SendMsg(EANOther); sl@0: SendMsg(EConnect); sl@0: ReceiveMsg(EANOther); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: SendMsg(EANOther2); sl@0: ReceiveMsg(EConnect); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: SetCookie(); sl@0: ReceiveMsg(EANOther2); sl@0: test(Msgs[Index()].Session() == KSessionCookie); sl@0: SendMsg(EDisConnect); sl@0: ReceiveMsg(EDisConnect); sl@0: test(Msgs[Index()].Session() == KSessionCookie); sl@0: } sl@0: sl@0: void Test8() sl@0: { sl@0: CreateSession(); sl@0: SendMsg(EANOther); sl@0: SendMsg(EConnect); sl@0: ReceiveMsg(EANOther); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: ReceiveMsg(EConnect); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: SetCookie(); sl@0: SendMsg(EANOther2); sl@0: ReceiveMsg(EANOther2); sl@0: test(Msgs[Index()].Session() == KSessionCookie); sl@0: SendMsg(EDisConnect); sl@0: ReceiveMsg(EDisConnect); sl@0: test(Msgs[Index()].Session() == KSessionCookie); sl@0: } sl@0: sl@0: void Test9() sl@0: { sl@0: CreateSession(); sl@0: SendMsg(EANOther); sl@0: ReceiveMsg(EANOther); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: SendMsg(EConnect); sl@0: ReceiveMsg(EConnect); sl@0: test(Msgs[Index()].Session() == NULL); sl@0: SetCookie(); sl@0: SendMsg(EANOther2); sl@0: ReceiveMsg(EANOther2); sl@0: test(Msgs[Index()].Session() == KSessionCookie); sl@0: SendMsg(EDisConnect); sl@0: ReceiveMsg(EDisConnect); sl@0: test(Msgs[Index()].Session() == KSessionCookie); sl@0: } sl@0: sl@0: void Test10() sl@0: { sl@0: // Try connecting with too many message slots sl@0: // (Check for DEF091903 regression) sl@0: CreateSession(KErrArgument, 1000); sl@0: } sl@0: sl@0: _LIT(KKernExec, "KERN-EXEC"); sl@0: sl@0: void CheckClientDeath(TInt aReason) sl@0: { sl@0: TRequestStatus logon; sl@0: sl@0: ClientThread.Logon(logon); sl@0: User::WaitForRequest(logon); sl@0: sl@0: test(ClientThread.ExitType() == EExitPanic); sl@0: test(ClientThread.ExitCategory() == KKernExec); sl@0: test(ClientThread.ExitReason() == aReason); sl@0: sl@0: ClientThread.Close(); sl@0: ClientThread.SetHandle(KNullHandle); sl@0: } sl@0: sl@0: void CheckServerDeath(TInt aReason) sl@0: { sl@0: TRequestStatus logon; sl@0: sl@0: ServerThread.Logon(logon); sl@0: User::WaitForRequest(logon); sl@0: sl@0: test(ServerThread.ExitType() == EExitPanic); sl@0: test(ServerThread.ExitCategory() == KKernExec); sl@0: test(ServerThread.ExitReason() == aReason); sl@0: sl@0: CLOSE_AND_WAIT(ServerThread); sl@0: ServerThread.SetHandle(KNullHandle); sl@0: } sl@0: sl@0: void TestNaughty() sl@0: { sl@0: TBool jit = User::JustInTime(); sl@0: User::SetJustInTime(EFalse); sl@0: sl@0: SetClientCritical(User::ENotCritical); sl@0: test.Next(_L("Two connect msgs at once is naughty")); sl@0: CreateSession(); sl@0: SendMsg(EConnect); sl@0: ReceiveMsg(EConnect); sl@0: SetCookie(); sl@0: SendMsg_NoWait(EConnect); sl@0: CheckClientDeath(ERequestAlreadyPending); sl@0: StartClient(KClientThread2); sl@0: test.Next(_L("Another connect message after a sucessful connect msg is naughty")); sl@0: CreateSession(); sl@0: SendMsg(EConnect); sl@0: ReceiveMsg(EConnect); sl@0: SetCookie(); sl@0: CompleteMsg(EConnect); sl@0: SendMsg_NoWait(EConnect); sl@0: CheckClientDeath(ESessionAlreadyConnected); sl@0: StartClient(KClientThread3); sl@0: sl@0: test.Next(_L("A null session cookie is naughty")); sl@0: CreateSession(); sl@0: SendMsg(EConnect); sl@0: ReceiveMsg(EConnect); sl@0: SetNullCookie(); sl@0: CheckServerDeath(ESessionNullCookie); sl@0: StartServer(); sl@0: sl@0: test.Next(_L("Setting the session cookie twice is naughty")); sl@0: CreateSession(); sl@0: SendMsg(EConnect); sl@0: ReceiveMsg(EConnect); sl@0: SetCookie(); sl@0: SetCookie_NoWait(); sl@0: CheckServerDeath(ESessionCookieAlreadySet); sl@0: StartServer(); sl@0: sl@0: test.Next(_L("Trying to set the session cookie from a non-connect message is naughty")); sl@0: CreateSession(); sl@0: SendMsg(EConnect); sl@0: ReceiveMsg(EConnect); sl@0: SendMsg(EANOther); sl@0: ReceiveMsg(EANOther); sl@0: SetBadCookie(EANOther); sl@0: CheckServerDeath(ESessionInvalidCookieMsg); sl@0: StartServer(); sl@0: sl@0: User::SetJustInTime(jit); sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: User::RenameThread(KMainThread); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: test.Title(); sl@0: sl@0: test.Start(_L("Creating semaphores")); sl@0: CreateSemaphores(); sl@0: sl@0: test.Next(_L("Starting test server")); sl@0: StartServer(); sl@0: sl@0: test.Next(_L("Starting test client")); sl@0: StartClient(); sl@0: SetClientCritical(User::EProcessCritical); sl@0: // test combinations of receiving messages with messages sent by the client in the sl@0: // correct order (w.r.t to each other, but not necessarily to when messages are received) sl@0: test.Next(_L("Sending in order")); sl@0: test.Next(_L("1")); sl@0: Test1(); sl@0: test.Next(_L("2")); sl@0: Test2(); sl@0: test.Next(_L("2a")); sl@0: Test2a(); sl@0: test.Next(_L("2b")); sl@0: Test2b(); sl@0: test.Next(_L("3")); sl@0: Test3(); sl@0: test.Next(_L("3a")); sl@0: Test3a(); sl@0: test.Next(_L("3b")); sl@0: Test3b(); sl@0: sl@0: // test combinations of receiving messages with messages sent by the client in the sl@0: // wrong order (w.r.t to each other, but not necessarily to when messages are received) sl@0: test.Next(_L("Sending out of order")); sl@0: test.Next(_L("4")); sl@0: Test4(); sl@0: test.Next(_L("5")); sl@0: Test5(); sl@0: test.Next(_L("6")); sl@0: Test6(); sl@0: test.Next(_L("6a")); sl@0: Test6a(); sl@0: test.Next(_L("6b")); sl@0: Test6b(); sl@0: test.Next(_L("7")); sl@0: Test7(); sl@0: test.Next(_L("8")); sl@0: Test8(); sl@0: test.Next(_L("9")); sl@0: Test9(); sl@0: test.Next(_L("10")); sl@0: Test10(); sl@0: sl@0: test.Next(_L("Test other naughty behaviour is trapped")); sl@0: TestNaughty(); sl@0: sl@0: test.Next(_L("Stopping test client")); sl@0: StopClient(); sl@0: sl@0: test.Next(_L("Stopping test server")); sl@0: StopServer(); sl@0: sl@0: test.Next(_L("Closing semaphores")); sl@0: CloseSemaphores(); sl@0: sl@0: test.End(); sl@0: test.Close(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: return KErrNone; sl@0: }