os/kernelhwsrv/kerneltest/e32test/debug/t_debugapi.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) 2005-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\debug\t_debugapi.cpp
sl@0
    15
// User-side harness for LDD-based debug agent that checks debug API 
sl@0
    16
// interface provided by kernel extension kdebug.dll (ARMv5) or kdebugv6 (ARMv6).
sl@0
    17
// It uses debug port to print the list of processes, threads, etc.
sl@0
    18
// Usage: t_debugapi [process] [thread] [chunk] [ipaccess]
sl@0
    19
// Performs all steps if there are no input arguments.
sl@0
    20
// The test is automated (does not require any input argument or manual assistance, but needs
sl@0
    21
// non-standard image file that includes kdebug.dll (ARMv5 based target) or kdebugV6.dll  
sl@0
    22
// (ARMv6 based target). It can be achieved by adding: #define STOP_MODE_DEBUGGING in .oby/iby file.
sl@0
    23
// Supported and tested on H2 (ARMv5) and integrator_1136 (ARMv6) platforms.
sl@0
    24
// It requires D_DEBUGAPI.DLL as well.
sl@0
    25
// Using debug interfaca only, it completes (prints) the list of:
sl@0
    26
// - processes;
sl@0
    27
// - threads;
sl@0
    28
// - chunks;
sl@0
    29
// in the system. On multiple-memory-model based target (ARMv6 architecture), 
sl@0
    30
// it also reads from address space of another process. This part is not checked 
sl@0
    31
// on moving-memory-model target (ARMv5) (e.g. always passes).
sl@0
    32
// Note: The test may cause system fail on ARM1136(r0p2) with L210 cache due to Erratum 317041.
sl@0
    33
// In that case, uncomment two relevant lines in DDebugAPIChecker::ReadFromOtherProcessArmv6 (in
sl@0
    34
// d_debugapi.cia) and rebuild d_debugapi.ldd.
sl@0
    35
// 
sl@0
    36
//
sl@0
    37
sl@0
    38
//! @file t_debugapi.h
sl@0
    39
//! @SYMTestCaseID KBASE/T_DEBUGAPI
sl@0
    40
//! @SYMTestType UT
sl@0
    41
//! @SYMTestCaseDesc
sl@0
    42
//! @SYMREQ PREQ835
sl@0
    43
//! @SYMTestActions
sl@0
    44
//! @SYMTestExpectedResults Test program completes with no errors.
sl@0
    45
//! @SYMTestPriority Low
sl@0
    46
//! @SYMTestStatus Defined
sl@0
    47
sl@0
    48
sl@0
    49
#include <e32test.h>
sl@0
    50
#include "d_debugapi.h"
sl@0
    51
sl@0
    52
RTest test(_L("T_DebugAPI"));
sl@0
    53
sl@0
    54
_LIT(KProcessName,"t_DebugAPI.exe");
sl@0
    55
_LIT(KProcess,"Process");
sl@0
    56
_LIT(KChunk,"Chunk");
sl@0
    57
_LIT(KThread,"Thread");
sl@0
    58
_LIT(KIPAccess,"IPAccess");
sl@0
    59
_LIT(KIPAccessStep2,"IPAccessStep2");
sl@0
    60
sl@0
    61
TBuf<64> command;
sl@0
    62
sl@0
    63
//The main program for the first instance of the process.
sl@0
    64
void Main()
sl@0
    65
	{
sl@0
    66
	RDebugAPIChecker debugAPI;
sl@0
    67
	TInt r;
sl@0
    68
	TBool checkAll = EFalse;
sl@0
    69
sl@0
    70
	if (command.Length() == 0)	
sl@0
    71
		checkAll = ETrue;
sl@0
    72
sl@0
    73
	r = User::LoadLogicalDevice(_L("D_DebugAPI.LDD"));
sl@0
    74
	test(r == KErrNone || r == KErrAlreadyExists);
sl@0
    75
	test (debugAPI.Open() == KErrNone);
sl@0
    76
sl@0
    77
	if (checkAll || command.FindF(KProcess) >= 0)
sl@0
    78
		{
sl@0
    79
		test.Next(_L("Printing process info"));
sl@0
    80
		test(debugAPI.Process() == KErrNone);
sl@0
    81
		}
sl@0
    82
sl@0
    83
	if (checkAll || command.FindF(KChunk) >= 0)
sl@0
    84
		{
sl@0
    85
		test.Next(_L("Printing chunk info"));
sl@0
    86
		test(debugAPI.Chunk() == KErrNone);
sl@0
    87
		}
sl@0
    88
sl@0
    89
	if (checkAll || command.FindF(KThread) >= 0)
sl@0
    90
		{
sl@0
    91
		test.Next(_L("Printing thread info"));
sl@0
    92
		test(debugAPI.Thread() == KErrNone);
sl@0
    93
		}
sl@0
    94
sl@0
    95
	if (checkAll || command.FindF(KIPAccess) >= 0)
sl@0
    96
		{
sl@0
    97
		test.Next(_L("KIPAccess"));
sl@0
    98
sl@0
    99
		RProcess process;
sl@0
   100
		TRequestStatus status;
sl@0
   101
		
sl@0
   102
		//The other process will try to read this variable.
sl@0
   103
		TInt probeVariable = 0x55555555;
sl@0
   104
		TUint id = process.Id();
sl@0
   105
		TBuf<64> command;
sl@0
   106
		command.Format(_L("%08x %08x %08x IPAccessStep2"), id, &probeVariable, probeVariable);
sl@0
   107
sl@0
   108
		test(process.Create(KProcessName, command) == KErrNone);
sl@0
   109
		process.Logon(status);
sl@0
   110
		process.Resume();
sl@0
   111
		User::WaitForRequest(status);
sl@0
   112
		test(process.ExitType() == EExitKill);
sl@0
   113
		test(process.ExitReason() == KErrNone);
sl@0
   114
		process.Close();
sl@0
   115
sl@0
   116
		//Now try another value.
sl@0
   117
		probeVariable = 0xaaaaaaaa;
sl@0
   118
		command.Format(_L("%08x %08x %08x IPAccessStep2"), id, &probeVariable, probeVariable);
sl@0
   119
sl@0
   120
		test(process.Create(KProcessName, command) == KErrNone);
sl@0
   121
		process.Logon(status);
sl@0
   122
		process.Resume();
sl@0
   123
		User::WaitForRequest(status);
sl@0
   124
		test(process.ExitType() == EExitKill);
sl@0
   125
		test(process.ExitReason() == KErrNone);
sl@0
   126
		process.Close();
sl@0
   127
		}
sl@0
   128
sl@0
   129
	debugAPI.Close();
sl@0
   130
	r = User::FreeLogicalDevice(KTestLddName);
sl@0
   131
	test(r == KErrNone || r == KErrNotFound);
sl@0
   132
	}
sl@0
   133
sl@0
   134
/**
sl@0
   135
The main program for the second instance of the process.
sl@0
   136
We need two processes two check inter-process data access.
sl@0
   137
*/
sl@0
   138
void SecondProcessMain()
sl@0
   139
	{
sl@0
   140
	RDebugAPIChecker debugAPI;
sl@0
   141
	TInt r;
sl@0
   142
	
sl@0
   143
	r = User::LoadLogicalDevice(_L("D_DebugAPI.LDD"));
sl@0
   144
	test(r == KErrNone || r == KErrAlreadyExists);
sl@0
   145
	test (debugAPI.Open() == KErrNone);
sl@0
   146
sl@0
   147
	if (command.FindF(KIPAccessStep2) >= 0)
sl@0
   148
		{
sl@0
   149
		RDebugAPIChecker::IPAccessArgs args;
sl@0
   150
sl@0
   151
		TPtrC ptr = command.Mid(0,8);
sl@0
   152
		TLex lex(ptr);
sl@0
   153
		lex.Val(args.iProcessID, EHex);
sl@0
   154
sl@0
   155
		ptr.Set(command.Mid(9,8));
sl@0
   156
		lex.Assign(ptr);
sl@0
   157
		lex.Val(args.iAddress, EHex);
sl@0
   158
sl@0
   159
		ptr.Set(command.Mid(18,8));
sl@0
   160
		lex.Assign(ptr);
sl@0
   161
		lex.Val(args.iValue, EHex);
sl@0
   162
sl@0
   163
		r = debugAPI.IPAccess(&args);
sl@0
   164
		test(r == KErrNone || r==KErrNotSupported);
sl@0
   165
		}
sl@0
   166
sl@0
   167
	debugAPI.Close();
sl@0
   168
	r = User::FreeLogicalDevice(KTestLddName);
sl@0
   169
	}
sl@0
   170
sl@0
   171
TInt E32Main()
sl@0
   172
	{
sl@0
   173
	test.Title();
sl@0
   174
	__UHEAP_MARK;
sl@0
   175
sl@0
   176
	User::CommandLine(command);
sl@0
   177
sl@0
   178
	if (command.FindF(KIPAccessStep2) < 0) //The second process is recognized by the specific input parameter
sl@0
   179
		{
sl@0
   180
		//This is the first instance of the running process.
sl@0
   181
		test.Start(_L("Testing Debug API"));
sl@0
   182
		Main();
sl@0
   183
		test.End();
sl@0
   184
		}
sl@0
   185
	else
sl@0
   186
		{
sl@0
   187
		//This is the second instance of the running process.
sl@0
   188
		SecondProcessMain();
sl@0
   189
		}
sl@0
   190
sl@0
   191
	__UHEAP_MARKEND;
sl@0
   192
	return 0;
sl@0
   193
	}