os/kernelhwsrv/kerneltest/e32test/power/t_domain_slave.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/power/t_domain_slave.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,140 @@
     1.4 +// Copyright (c) 2002-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\power\t_domain_slave.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32power.h>
    1.22 +#include <e32test.h>
    1.23 +#include <domainmember.h>
    1.24 +#include <domainmanager.h>
    1.25 +#include <e32panic.h>
    1.26 +#include <e32debug.h>
    1.27 +
    1.28 +LOCAL_D RTest test(_L(" T_DOMAIN_SLAVE "));
    1.29 +
    1.30 +// This will be run in its own thread as part of test #1. It should get killed when trying to connect 
    1.31 +// to the manager without appropriate caps set
    1.32 +TInt IncorrectClient(TAny*)
    1.33 +{
    1.34 +    	RDmDomain domain;
    1.35 +		TInt r = domain.Connect(KDmIdRoot);
    1.36 +
    1.37 +		RDmDomainManager manager;
    1.38 +		r = manager.Connect();
    1.39 +
    1.40 +        return(r);
    1.41 +}
    1.42 +
    1.43 +GLDEF_C TInt E32Main()
    1.44 +	{
    1.45 +	test.Title();
    1.46 +	test.Start(_L("Testing"));
    1.47 +
    1.48 +//	test.Next(_L("test security"));
    1.49 +
    1.50 +	// Get arguments from the command line
    1.51 +	TInt len = User::CommandLineLength();
    1.52 +	test (len);
    1.53 +	TInt size = len * sizeof(TUint16);
    1.54 +	test (size == sizeof(TInt));
    1.55 +	TInt arg;
    1.56 +	TPtr cmd((TUint16*) &arg, len);
    1.57 +	User::CommandLine(cmd);
    1.58 +
    1.59 +	TInt expected_result = PlatSec::IsCapabilityEnforced(ECapabilityPowerMgmt) ? KErrPermissionDenied : KErrNone;
    1.60 +
    1.61 +	switch(arg)
    1.62 +		{
    1.63 +	case 0:
    1.64 +		{
    1.65 +        // This is the original t_domain_slave test, minus the panicking parts which now get
    1.66 +        // tested as case 1.
    1.67 +
    1.68 +        test.Next(_L("test security -- 0"));       
    1.69 +
    1.70 +		RDmDomain domain;
    1.71 +		TInt r = domain.Connect(KDmIdRoot);
    1.72 +		test (r == expected_result);
    1.73 +
    1.74 +		break;
    1.75 +		}
    1.76 +    case 1:
    1.77 +        {
    1.78 +
    1.79 +        test.Next(_L("test security -- 1")); 
    1.80 +        
    1.81 +        TBool jit = User::JustInTime();
    1.82 +
    1.83 +        User::SetJustInTime(EFalse);
    1.84 +
    1.85 +        _LIT(KPanicThread, "PanicThread");
    1.86 +
    1.87 +        RThread testThread;
    1.88 +
    1.89 +        TInt tt=testThread.Create(KPanicThread, IncorrectClient, KDefaultStackSize, 
    1.90 +            NULL, NULL);
    1.91 +
    1.92 +        test (KErrNone == tt);
    1.93 +
    1.94 +        TRequestStatus tStatus;
    1.95 +  //      testThread.Logon(tStatus);
    1.96 +
    1.97 +        RUndertaker deathChecker;
    1.98 +        TInt dcOK = deathChecker.Create();
    1.99 +
   1.100 +        test (KErrNone == dcOK);
   1.101 +
   1.102 +        TInt nextDeadThread;
   1.103 +
   1.104 +        deathChecker.Logon(tStatus, nextDeadThread);
   1.105 +
   1.106 +        // threads are created in a suspended state. calling resume here starts the thread.
   1.107 +        testThread.Resume();
   1.108 +        User::WaitForRequest(tStatus);
   1.109 +
   1.110 +        // If thread suicided for the correct reason --> successful test
   1.111 +        // NB. KErrPermissionDenied means that the server refused the 
   1.112 +        // connection because of incorrect capabilities
   1.113 +
   1.114 +        RThread corpse;
   1.115 +        corpse.SetHandle(nextDeadThread);
   1.116 +
   1.117 +        RDebug::Printf("Subthread exit type: %d", corpse.ExitType() );
   1.118 +
   1.119 +        RDebug::Printf("Subthread exit reason: %d",corpse.ExitReason() );
   1.120 +
   1.121 +        test (corpse.ExitType() == EExitKill);
   1.122 +
   1.123 +        test (corpse.ExitReason() == KErrPermissionDenied);
   1.124 +
   1.125 +        corpse.Close();
   1.126 +  
   1.127 +        // close the RUndertaker and test thread
   1.128 +        deathChecker.Close();
   1.129 +		CLOSE_AND_WAIT(testThread);
   1.130 +
   1.131 +        User::SetJustInTime(jit);
   1.132 +
   1.133 +		break;
   1.134 +        }
   1.135 +	default:
   1.136 +		User::Panic(_L("USER"), EInvariantFalse);
   1.137 +		break;
   1.138 +		}
   1.139 +
   1.140 +	test.End();
   1.141 +
   1.142 +	return KErrNone;
   1.143 +	}