kerneltest/e32test/power/t_domain_slave.cpp
changeset 245 647ab20fee2e
parent 244 a77889bee936
child 252 0a40b8675b23
equal deleted inserted replaced
244:a77889bee936 245:647ab20fee2e
     1 // Copyright (c) 2002-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32test\power\t_domain_slave.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32power.h>
       
    19 #include <e32test.h>
       
    20 #include <domainmember.h>
       
    21 #include <domainmanager.h>
       
    22 #include <e32panic.h>
       
    23 #include <e32debug.h>
       
    24 
       
    25 LOCAL_D RTest test(_L(" T_DOMAIN_SLAVE "));
       
    26 
       
    27 // This will be run in its own thread as part of test #1. It should get killed when trying to connect 
       
    28 // to the manager without appropriate caps set
       
    29 TInt IncorrectClient(TAny*)
       
    30 {
       
    31     	RDmDomain domain;
       
    32 		TInt r = domain.Connect(KDmIdRoot);
       
    33 
       
    34 		RDmDomainManager manager;
       
    35 		r = manager.Connect();
       
    36 
       
    37         return(r);
       
    38 }
       
    39 
       
    40 GLDEF_C TInt E32Main()
       
    41 	{
       
    42 	test.Title();
       
    43 	test.Start(_L("Testing"));
       
    44 
       
    45 //	test.Next(_L("test security"));
       
    46 
       
    47 	// Get arguments from the command line
       
    48 	TInt len = User::CommandLineLength();
       
    49 	test (len);
       
    50 	TInt size = len * sizeof(TUint16);
       
    51 	test (size == sizeof(TInt));
       
    52 	TInt arg;
       
    53 	TPtr cmd((TUint16*) &arg, len);
       
    54 	User::CommandLine(cmd);
       
    55 
       
    56 	TInt expected_result = PlatSec::IsCapabilityEnforced(ECapabilityPowerMgmt) ? KErrPermissionDenied : KErrNone;
       
    57 
       
    58 	switch(arg)
       
    59 		{
       
    60 	case 0:
       
    61 		{
       
    62         // This is the original t_domain_slave test, minus the panicking parts which now get
       
    63         // tested as case 1.
       
    64 
       
    65         test.Next(_L("test security -- 0"));       
       
    66 
       
    67 		RDmDomain domain;
       
    68 		TInt r = domain.Connect(KDmIdRoot);
       
    69 		test (r == expected_result);
       
    70 
       
    71 		break;
       
    72 		}
       
    73     case 1:
       
    74         {
       
    75 
       
    76         test.Next(_L("test security -- 1")); 
       
    77         
       
    78         TBool jit = User::JustInTime();
       
    79 
       
    80         User::SetJustInTime(EFalse);
       
    81 
       
    82         _LIT(KPanicThread, "PanicThread");
       
    83 
       
    84         RThread testThread;
       
    85 
       
    86         TInt tt=testThread.Create(KPanicThread, IncorrectClient, KDefaultStackSize, 
       
    87             NULL, NULL);
       
    88 
       
    89         test (KErrNone == tt);
       
    90 
       
    91         TRequestStatus tStatus;
       
    92   //      testThread.Logon(tStatus);
       
    93 
       
    94         RUndertaker deathChecker;
       
    95         TInt dcOK = deathChecker.Create();
       
    96 
       
    97         test (KErrNone == dcOK);
       
    98 
       
    99         TInt nextDeadThread;
       
   100 
       
   101         deathChecker.Logon(tStatus, nextDeadThread);
       
   102 
       
   103         // threads are created in a suspended state. calling resume here starts the thread.
       
   104         testThread.Resume();
       
   105         User::WaitForRequest(tStatus);
       
   106 
       
   107         // If thread suicided for the correct reason --> successful test
       
   108         // NB. KErrPermissionDenied means that the server refused the 
       
   109         // connection because of incorrect capabilities
       
   110 
       
   111         RThread corpse;
       
   112         corpse.SetHandle(nextDeadThread);
       
   113 
       
   114         RDebug::Printf("Subthread exit type: %d", corpse.ExitType() );
       
   115 
       
   116         RDebug::Printf("Subthread exit reason: %d",corpse.ExitReason() );
       
   117 
       
   118         test (corpse.ExitType() == EExitKill);
       
   119 
       
   120         test (corpse.ExitReason() == KErrPermissionDenied);
       
   121 
       
   122         corpse.Close();
       
   123   
       
   124         // close the RUndertaker and test thread
       
   125         deathChecker.Close();
       
   126 		CLOSE_AND_WAIT(testThread);
       
   127 
       
   128         User::SetJustInTime(jit);
       
   129 
       
   130 		break;
       
   131         }
       
   132 	default:
       
   133 		User::Panic(_L("USER"), EInvariantFalse);
       
   134 		break;
       
   135 		}
       
   136 
       
   137 	test.End();
       
   138 
       
   139 	return KErrNone;
       
   140 	}