os/kernelhwsrv/kerneltest/e32test/rm_debug/t_rmdebug.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2006-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
// Tests the functionality of the run mode debug device driver.
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32base.h>
sl@0
    19
#include <e32base_private.h>
sl@0
    20
#include <e32cons.h>
sl@0
    21
#include <e32test.h>
sl@0
    22
#include <e32ldr.h>
sl@0
    23
#include <f32dbg.h>
sl@0
    24
#include "d_rmdebugclient.h"
sl@0
    25
#include "d_rmdebugthread.h"
sl@0
    26
#include "t_rmdebug.h"
sl@0
    27
sl@0
    28
IMPORT_C TInt StartDebugThread(RThread& aServerThread);
sl@0
    29
IMPORT_D extern TInt TestData;
sl@0
    30
IMPORT_D extern TBuf8<SYMBIAN_RMDBG_MEMORYSIZE> gMemoryAccessBytes;
sl@0
    31
sl@0
    32
LOCAL_D RTest test(_L("T_RMDEBUG"));
sl@0
    33
sl@0
    34
CRunModeAgent::CRunModeAgent()
sl@0
    35
//
sl@0
    36
// CRunModeAgent constructor
sl@0
    37
//
sl@0
    38
	{
sl@0
    39
	}
sl@0
    40
sl@0
    41
CRunModeAgent* CRunModeAgent::NewL()
sl@0
    42
//
sl@0
    43
// CRunModeAgent::NewL
sl@0
    44
//
sl@0
    45
	{
sl@0
    46
	CRunModeAgent* self = new(ELeave) CRunModeAgent();
sl@0
    47
sl@0
    48
  	self->ConstructL();
sl@0
    49
sl@0
    50
   if (self->iState != ERunModeAgentRunning)
sl@0
    51
       {
sl@0
    52
       delete self;
sl@0
    53
       self = NULL;
sl@0
    54
       }       
sl@0
    55
	return self;
sl@0
    56
	}
sl@0
    57
sl@0
    58
CRunModeAgent::~CRunModeAgent()
sl@0
    59
//
sl@0
    60
// CRunModeAgent destructor
sl@0
    61
//
sl@0
    62
	{
sl@0
    63
	iServSession.Close();
sl@0
    64
	iDebugThread.Close();
sl@0
    65
   iState = ERunModeAgentUnInit;
sl@0
    66
	}
sl@0
    67
sl@0
    68
void CRunModeAgent::ConstructL()
sl@0
    69
//
sl@0
    70
// CRunModeAgent::ConstructL
sl@0
    71
//
sl@0
    72
	{
sl@0
    73
	TInt err;
sl@0
    74
	err = StartDebugThread(iDebugThread);
sl@0
    75
sl@0
    76
	if (err == KErrNone)
sl@0
    77
		{
sl@0
    78
		if (iServSession.Open() == KErrNone)
sl@0
    79
           {
sl@0
    80
           iState = ERunModeAgentRunning;
sl@0
    81
           }
sl@0
    82
       else
sl@0
    83
           {
sl@0
    84
           iState = ERunModeAgentUnInit;
sl@0
    85
           }
sl@0
    86
		}
sl@0
    87
	else
sl@0
    88
		{
sl@0
    89
		User::Panic(_L("Can't start debug thread"), err);
sl@0
    90
		}
sl@0
    91
}
sl@0
    92
sl@0
    93
sl@0
    94
sl@0
    95
CRunModeAgent *RunModeAgent;
sl@0
    96
sl@0
    97
// Test process names
sl@0
    98
_LIT(ProcessName1,"T_RMDEBUG");
sl@0
    99
_LIT(ProcessName1a,"t_rmdebug");
sl@0
   100
//_LIT(ProcessName2,"ekern");
sl@0
   101
//_LIT(ProcessName3,"efile");
sl@0
   102
_LIT(KWildCard,"*");
sl@0
   103
sl@0
   104
sl@0
   105
//---------------------------------------------
sl@0
   106
//! @SYMTestCaseID KBase-0185
sl@0
   107
//! @SYMTestType 
sl@0
   108
//! @SYMPREQ PREQ1426
sl@0
   109
//! @SYMTestCaseDesc Test reading process list
sl@0
   110
//! @SYMTestActions Several calls to read the process list
sl@0
   111
//! @SYMTestExpectedResults KErrNone and the owning process ID set
sl@0
   112
//! @SYMTestPriority High
sl@0
   113
//! @SYMTestStatus Implemented
sl@0
   114
//---------------------------------------------
sl@0
   115
void CRunModeAgent::TestProcessList()
sl@0
   116
	{
sl@0
   117
	TInt    err=KErrNone;
sl@0
   118
	TBool	found = FALSE;
sl@0
   119
sl@0
   120
	test.Next(_L("TestProcessList - Read Process List\n"));
sl@0
   121
sl@0
   122
	TFindProcess find(KWildCard);
sl@0
   123
	TFullName name;
sl@0
   124
	while(find.Next(name)==KErrNone)
sl@0
   125
		{
sl@0
   126
		RProcess process;
sl@0
   127
		err = process.Open(find);
sl@0
   128
		if (err == KErrNone)
sl@0
   129
			{
sl@0
   130
			if ((name.Find(ProcessName1) != KErrNotFound) ||
sl@0
   131
				(name.Find(ProcessName1a) != KErrNotFound))
sl@0
   132
				{				
sl@0
   133
					iProcessID = process.Id();
sl@0
   134
					found = TRUE;				
sl@0
   135
				}
sl@0
   136
			process.Close();				
sl@0
   137
			}
sl@0
   138
	   }   
sl@0
   139
	test(found== TRUE);   
sl@0
   140
	}
sl@0
   141
sl@0
   142
// Test thread name
sl@0
   143
_LIT(ThreadName1,"DebugThread");
sl@0
   144
sl@0
   145
//---------------------------------------------
sl@0
   146
//! @SYMTestCaseID KBase-0186
sl@0
   147
//! @SYMTestType 
sl@0
   148
//! @SYMPREQ PREQ1426
sl@0
   149
//! @SYMTestCaseDesc Test reading thread list
sl@0
   150
//! @SYMTestActions Several calls to read the thread list
sl@0
   151
//! @SYMTestExpectedResults KErrNone and the debug thread ID set
sl@0
   152
//! @SYMTestPriority High
sl@0
   153
//! @SYMTestStatus Implemented
sl@0
   154
//---------------------------------------------
sl@0
   155
void CRunModeAgent::TestThreadList()
sl@0
   156
	{
sl@0
   157
	TInt        err=KErrNone;
sl@0
   158
	TBool       found = FALSE;
sl@0
   159
sl@0
   160
	test.Next(_L("TestThreadList - Read Thread List\n"));
sl@0
   161
sl@0
   162
   	TFindThread find(KWildCard);
sl@0
   163
	TFullName name;
sl@0
   164
	while(find.Next(name)==KErrNone)
sl@0
   165
		{
sl@0
   166
		RThread thread;
sl@0
   167
		err = thread.Open(find);
sl@0
   168
       	if (err == KErrNone)
sl@0
   169
			{
sl@0
   170
			RProcess process;
sl@0
   171
			thread.Process(process);
sl@0
   172
			if (((TUint32)process.Id() == iProcessID) &&
sl@0
   173
				(name.Find(ThreadName1) != KErrNotFound))
sl@0
   174
				{
sl@0
   175
				found = TRUE;           
sl@0
   176
				iThreadID = thread.Id();
sl@0
   177
				}
sl@0
   178
			}
sl@0
   179
			thread.Close();
sl@0
   180
   		}   
sl@0
   181
sl@0
   182
	test(found==TRUE);   
sl@0
   183
	}
sl@0
   184
sl@0
   185
   
sl@0
   186
//---------------------------------------------
sl@0
   187
//! @SYMTestCaseID KBase-0187
sl@0
   188
//! @SYMTestType 
sl@0
   189
//! @SYMPREQ PREQ1426
sl@0
   190
//! @SYMTestCaseDesc Test reading and writing thread memory
sl@0
   191
//! @SYMTestActions Several call to read and write blocks of thread memory
sl@0
   192
//! @SYMTestExpectedResults KErrNone
sl@0
   193
//! @SYMTestPriority High
sl@0
   194
//! @SYMTestStatus Implemented
sl@0
   195
//---------------------------------------------
sl@0
   196
void CRunModeAgent::TestMemoryAccess()
sl@0
   197
{
sl@0
   198
	TInt err=KErrNone;
sl@0
   199
	TMemoryInfo MemoryInfo;
sl@0
   200
	TInt i;
sl@0
   201
sl@0
   202
	test.Next(_L("TestMemoryAccess - Read Memory\n"));     
sl@0
   203
sl@0
   204
	for (i = 0; i < SYMBIAN_RMDBG_MEMORYSIZE; i++)
sl@0
   205
		{
sl@0
   206
		gMemoryAccessBytes.Append(i);
sl@0
   207
		}
sl@0
   208
sl@0
   209
	MemoryInfo.iAddress = (TUint32)(&gMemoryAccessBytes[0]);
sl@0
   210
	MemoryInfo.iSize = SYMBIAN_RMDBG_MEMORYSIZE;
sl@0
   211
sl@0
   212
	HBufC8 *data = HBufC8::NewLC(SYMBIAN_RMDBG_MEMORYSIZE);
sl@0
   213
	TPtr8 ptr_memread(data->Des());   
sl@0
   214
	MemoryInfo.iDataPtr = &ptr_memread;
sl@0
   215
sl@0
   216
//	test.Printf(_L("Read address = 0x%x Read size = 0x%x\n"),MemoryInfo.iAddress,MemoryInfo.iSize);
sl@0
   217
sl@0
   218
	err = iServSession.ReadMemory(iThreadID, &MemoryInfo);
sl@0
   219
sl@0
   220
	for (i = 0; i < MemoryInfo.iSize; i++)
sl@0
   221
		{
sl@0
   222
		if (ptr_memread.Ptr()[i] != gMemoryAccessBytes[i])
sl@0
   223
			{
sl@0
   224
			err = KErrCorrupt;       		
sl@0
   225
			}
sl@0
   226
		}
sl@0
   227
sl@0
   228
sl@0
   229
	// Test out writing memory.   
sl@0
   230
	test.Next(_L("TestMemoryAccess - Write Memory\n"));
sl@0
   231
//	test.Printf(_L("Write address = 0x%x Write size = 0x%x\n"),MemoryInfo.iAddress,MemoryInfo.iSize);
sl@0
   232
	if (err== KErrNone)
sl@0
   233
		{
sl@0
   234
		// Now reset the buffer
sl@0
   235
		for (i = 0; i < SYMBIAN_RMDBG_MEMORYSIZE; i++)
sl@0
   236
			{
sl@0
   237
			gMemoryAccessBytes[i] = 0;
sl@0
   238
			}      
sl@0
   239
sl@0
   240
		// Write our data into the buffer
sl@0
   241
		err = iServSession.WriteMemory(iThreadID, &MemoryInfo);
sl@0
   242
sl@0
   243
		for (i = 0; i < MemoryInfo.iSize; i++)
sl@0
   244
			{
sl@0
   245
			if (ptr_memread.Ptr()[i] != gMemoryAccessBytes[i])
sl@0
   246
				{
sl@0
   247
				err = KErrCorrupt;       		
sl@0
   248
				}
sl@0
   249
			}
sl@0
   250
sl@0
   251
		}
sl@0
   252
sl@0
   253
	if (gMemoryAccessBytes[5] == 0)
sl@0
   254
		{
sl@0
   255
		err = KErrCorrupt;
sl@0
   256
		}
sl@0
   257
sl@0
   258
	CleanupStack::PopAndDestroy(data);       
sl@0
   259
	test(err==KErrNone);   
sl@0
   260
	}
sl@0
   261
sl@0
   262
sl@0
   263
//---------------------------------------------
sl@0
   264
//! @SYMTestCaseID KBase-0188
sl@0
   265
//! @SYMTestType 
sl@0
   266
//! @SYMPREQ PREQ1426
sl@0
   267
//! @SYMTestCaseDesc Test suspending and resuming a task
sl@0
   268
//! @SYMTestActions Suspends a thread checks the contents of a variable then waits and tests it hasnt changed
sl@0
   269
//! @SYMTestExpectedResults KErrNone
sl@0
   270
//! @SYMTestPriority High
sl@0
   271
//! @SYMTestStatus Implemented
sl@0
   272
//---------------------------------------------
sl@0
   273
void CRunModeAgent::TestSuspendResume()
sl@0
   274
	{
sl@0
   275
	TInt err;
sl@0
   276
sl@0
   277
	test.Next(_L("TestSuspendResume - Suspend\n"));
sl@0
   278
	// Suspend the thread
sl@0
   279
	err = iServSession.SuspendThread(iThreadID);
sl@0
   280
	test(err==KErrNone);
sl@0
   281
	TInt localtestdata;
sl@0
   282
	localtestdata = TestData;
sl@0
   283
sl@0
   284
	// Wait 3 seconds (suspends this thread) and hopefully resumes the
sl@0
   285
	// thread we are controlling via the iServSession.SuspendThread request
sl@0
   286
	User::After(3000000);
sl@0
   287
sl@0
   288
	// Now check data hasnt changed
sl@0
   289
	test(localtestdata==TestData);
sl@0
   290
sl@0
   291
	// Resume the thread
sl@0
   292
	test.Next(_L("TestSuspendResume - Resume\n"));
sl@0
   293
	err = iServSession.ResumeThread(iThreadID);
sl@0
   294
	test(err==KErrNone);
sl@0
   295
sl@0
   296
	// Wait 3 seconds (suspends this thread) and hopefully resumes the
sl@0
   297
	// thread we are controlling via the iServSession.SuspendThread request
sl@0
   298
	User::After(3000000);
sl@0
   299
sl@0
   300
	// Now check that the thread being controlled has resumed and is
sl@0
   301
	// updating the variable
sl@0
   302
	test(localtestdata!=TestData);
sl@0
   303
	}
sl@0
   304
   
sl@0
   305
void CRunModeAgent::ClientAppL()
sl@0
   306
//
sl@0
   307
// Performs each test in turn
sl@0
   308
//
sl@0
   309
	{
sl@0
   310
	test.Start(_L("ClientAppL"));
sl@0
   311
sl@0
   312
	TestProcessList();
sl@0
   313
	TestThreadList();
sl@0
   314
	TestMemoryAccess();
sl@0
   315
	TestSuspendResume();
sl@0
   316
	test.End();   
sl@0
   317
	}
sl@0
   318
sl@0
   319
GLDEF_C TInt E32Main()
sl@0
   320
//
sl@0
   321
// Entry point for run mode debug driver test
sl@0
   322
//
sl@0
   323
	{
sl@0
   324
   TInt ret = KErrNone;
sl@0
   325
   
sl@0
   326
	// client
sl@0
   327
	CTrapCleanup* trap = CTrapCleanup::New();
sl@0
   328
	if (!trap)
sl@0
   329
		return KErrNoMemory;
sl@0
   330
sl@0
   331
   RunModeAgent = CRunModeAgent::NewL();
sl@0
   332
   if (RunModeAgent != NULL)
sl@0
   333
       {
sl@0
   334
   	test.Title();
sl@0
   335
sl@0
   336
        __UHEAP_MARK;
sl@0
   337
	    TRAPD(r,RunModeAgent->ClientAppL());
sl@0
   338
       ret = r;
sl@0
   339
	    __UHEAP_MARKEND;
sl@0
   340
sl@0
   341
	    delete RunModeAgent;
sl@0
   342
       }
sl@0
   343
       
sl@0
   344
	delete trap;
sl@0
   345
sl@0
   346
	return ret;
sl@0
   347
	}