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