1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/debug/t_debugapi.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,193 @@
1.4 +// Copyright (c) 2005-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\debug\t_debugapi.cpp
1.18 +// User-side harness for LDD-based debug agent that checks debug API
1.19 +// interface provided by kernel extension kdebug.dll (ARMv5) or kdebugv6 (ARMv6).
1.20 +// It uses debug port to print the list of processes, threads, etc.
1.21 +// Usage: t_debugapi [process] [thread] [chunk] [ipaccess]
1.22 +// Performs all steps if there are no input arguments.
1.23 +// The test is automated (does not require any input argument or manual assistance, but needs
1.24 +// non-standard image file that includes kdebug.dll (ARMv5 based target) or kdebugV6.dll
1.25 +// (ARMv6 based target). It can be achieved by adding: #define STOP_MODE_DEBUGGING in .oby/iby file.
1.26 +// Supported and tested on H2 (ARMv5) and integrator_1136 (ARMv6) platforms.
1.27 +// It requires D_DEBUGAPI.DLL as well.
1.28 +// Using debug interfaca only, it completes (prints) the list of:
1.29 +// - processes;
1.30 +// - threads;
1.31 +// - chunks;
1.32 +// in the system. On multiple-memory-model based target (ARMv6 architecture),
1.33 +// it also reads from address space of another process. This part is not checked
1.34 +// on moving-memory-model target (ARMv5) (e.g. always passes).
1.35 +// Note: The test may cause system fail on ARM1136(r0p2) with L210 cache due to Erratum 317041.
1.36 +// In that case, uncomment two relevant lines in DDebugAPIChecker::ReadFromOtherProcessArmv6 (in
1.37 +// d_debugapi.cia) and rebuild d_debugapi.ldd.
1.38 +//
1.39 +//
1.40 +
1.41 +//! @file t_debugapi.h
1.42 +//! @SYMTestCaseID KBASE/T_DEBUGAPI
1.43 +//! @SYMTestType UT
1.44 +//! @SYMTestCaseDesc
1.45 +//! @SYMREQ PREQ835
1.46 +//! @SYMTestActions
1.47 +//! @SYMTestExpectedResults Test program completes with no errors.
1.48 +//! @SYMTestPriority Low
1.49 +//! @SYMTestStatus Defined
1.50 +
1.51 +
1.52 +#include <e32test.h>
1.53 +#include "d_debugapi.h"
1.54 +
1.55 +RTest test(_L("T_DebugAPI"));
1.56 +
1.57 +_LIT(KProcessName,"t_DebugAPI.exe");
1.58 +_LIT(KProcess,"Process");
1.59 +_LIT(KChunk,"Chunk");
1.60 +_LIT(KThread,"Thread");
1.61 +_LIT(KIPAccess,"IPAccess");
1.62 +_LIT(KIPAccessStep2,"IPAccessStep2");
1.63 +
1.64 +TBuf<64> command;
1.65 +
1.66 +//The main program for the first instance of the process.
1.67 +void Main()
1.68 + {
1.69 + RDebugAPIChecker debugAPI;
1.70 + TInt r;
1.71 + TBool checkAll = EFalse;
1.72 +
1.73 + if (command.Length() == 0)
1.74 + checkAll = ETrue;
1.75 +
1.76 + r = User::LoadLogicalDevice(_L("D_DebugAPI.LDD"));
1.77 + test(r == KErrNone || r == KErrAlreadyExists);
1.78 + test (debugAPI.Open() == KErrNone);
1.79 +
1.80 + if (checkAll || command.FindF(KProcess) >= 0)
1.81 + {
1.82 + test.Next(_L("Printing process info"));
1.83 + test(debugAPI.Process() == KErrNone);
1.84 + }
1.85 +
1.86 + if (checkAll || command.FindF(KChunk) >= 0)
1.87 + {
1.88 + test.Next(_L("Printing chunk info"));
1.89 + test(debugAPI.Chunk() == KErrNone);
1.90 + }
1.91 +
1.92 + if (checkAll || command.FindF(KThread) >= 0)
1.93 + {
1.94 + test.Next(_L("Printing thread info"));
1.95 + test(debugAPI.Thread() == KErrNone);
1.96 + }
1.97 +
1.98 + if (checkAll || command.FindF(KIPAccess) >= 0)
1.99 + {
1.100 + test.Next(_L("KIPAccess"));
1.101 +
1.102 + RProcess process;
1.103 + TRequestStatus status;
1.104 +
1.105 + //The other process will try to read this variable.
1.106 + TInt probeVariable = 0x55555555;
1.107 + TUint id = process.Id();
1.108 + TBuf<64> command;
1.109 + command.Format(_L("%08x %08x %08x IPAccessStep2"), id, &probeVariable, probeVariable);
1.110 +
1.111 + test(process.Create(KProcessName, command) == KErrNone);
1.112 + process.Logon(status);
1.113 + process.Resume();
1.114 + User::WaitForRequest(status);
1.115 + test(process.ExitType() == EExitKill);
1.116 + test(process.ExitReason() == KErrNone);
1.117 + process.Close();
1.118 +
1.119 + //Now try another value.
1.120 + probeVariable = 0xaaaaaaaa;
1.121 + command.Format(_L("%08x %08x %08x IPAccessStep2"), id, &probeVariable, probeVariable);
1.122 +
1.123 + test(process.Create(KProcessName, command) == KErrNone);
1.124 + process.Logon(status);
1.125 + process.Resume();
1.126 + User::WaitForRequest(status);
1.127 + test(process.ExitType() == EExitKill);
1.128 + test(process.ExitReason() == KErrNone);
1.129 + process.Close();
1.130 + }
1.131 +
1.132 + debugAPI.Close();
1.133 + r = User::FreeLogicalDevice(KTestLddName);
1.134 + test(r == KErrNone || r == KErrNotFound);
1.135 + }
1.136 +
1.137 +/**
1.138 +The main program for the second instance of the process.
1.139 +We need two processes two check inter-process data access.
1.140 +*/
1.141 +void SecondProcessMain()
1.142 + {
1.143 + RDebugAPIChecker debugAPI;
1.144 + TInt r;
1.145 +
1.146 + r = User::LoadLogicalDevice(_L("D_DebugAPI.LDD"));
1.147 + test(r == KErrNone || r == KErrAlreadyExists);
1.148 + test (debugAPI.Open() == KErrNone);
1.149 +
1.150 + if (command.FindF(KIPAccessStep2) >= 0)
1.151 + {
1.152 + RDebugAPIChecker::IPAccessArgs args;
1.153 +
1.154 + TPtrC ptr = command.Mid(0,8);
1.155 + TLex lex(ptr);
1.156 + lex.Val(args.iProcessID, EHex);
1.157 +
1.158 + ptr.Set(command.Mid(9,8));
1.159 + lex.Assign(ptr);
1.160 + lex.Val(args.iAddress, EHex);
1.161 +
1.162 + ptr.Set(command.Mid(18,8));
1.163 + lex.Assign(ptr);
1.164 + lex.Val(args.iValue, EHex);
1.165 +
1.166 + r = debugAPI.IPAccess(&args);
1.167 + test(r == KErrNone || r==KErrNotSupported);
1.168 + }
1.169 +
1.170 + debugAPI.Close();
1.171 + r = User::FreeLogicalDevice(KTestLddName);
1.172 + }
1.173 +
1.174 +TInt E32Main()
1.175 + {
1.176 + test.Title();
1.177 + __UHEAP_MARK;
1.178 +
1.179 + User::CommandLine(command);
1.180 +
1.181 + if (command.FindF(KIPAccessStep2) < 0) //The second process is recognized by the specific input parameter
1.182 + {
1.183 + //This is the first instance of the running process.
1.184 + test.Start(_L("Testing Debug API"));
1.185 + Main();
1.186 + test.End();
1.187 + }
1.188 + else
1.189 + {
1.190 + //This is the second instance of the running process.
1.191 + SecondProcessMain();
1.192 + }
1.193 +
1.194 + __UHEAP_MARKEND;
1.195 + return 0;
1.196 + }