os/kernelhwsrv/kerneltest/e32test/dmav2/test_thread.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: Some helper classes to assist with writing multi-threaded tests
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#ifndef __TEST_THREAD_H__
sl@0
    20
#define __TEST_THREAD_H__
sl@0
    21
sl@0
    22
#include <e32base.h>
sl@0
    23
#include <e32debug.h>
sl@0
    24
#define __E32TEST_EXTENSION__
sl@0
    25
#include <e32test.h>
sl@0
    26
#include <e32cmn_private.h>
sl@0
    27
sl@0
    28
_LIT(KPanicCat, "test_thread.h");
sl@0
    29
sl@0
    30
sl@0
    31
static const TInt KHeapSize=0x2000;
sl@0
    32
sl@0
    33
enum TPanicCode
sl@0
    34
	{
sl@0
    35
	EThreadCreateFailed
sl@0
    36
	};
sl@0
    37
sl@0
    38
/**
sl@0
    39
A utility class for running functions in other threads/processes
sl@0
    40
*/
sl@0
    41
class TTestRemote
sl@0
    42
	{
sl@0
    43
public:
sl@0
    44
	virtual TInt WaitForExitL() = 0;
sl@0
    45
	virtual ~TTestRemote()
sl@0
    46
		{}
sl@0
    47
sl@0
    48
	virtual void Rendezvous(TRequestStatus& aStatus) = 0;
sl@0
    49
sl@0
    50
protected:
sl@0
    51
	TTestRemote()
sl@0
    52
		{}
sl@0
    53
sl@0
    54
	static TInt RunFunctor(TAny* aFunctor);
sl@0
    55
sl@0
    56
	TRequestStatus iLogonStatus;
sl@0
    57
	static TInt iCount;
sl@0
    58
	};
sl@0
    59
sl@0
    60
class TTestThread : public TTestRemote
sl@0
    61
	{
sl@0
    62
public:
sl@0
    63
	TTestThread(const TDesC& aName, TThreadFunction aFn, TAny* aData, TBool aAutoResume=ETrue);
sl@0
    64
sl@0
    65
	/**
sl@0
    66
	Run aFunctor in another thread
sl@0
    67
	*/
sl@0
    68
	TTestThread(const TDesC& aName, TFunctor& aFunctor, TBool aAutoResume=ETrue);
sl@0
    69
sl@0
    70
	~TTestThread();
sl@0
    71
sl@0
    72
	void Resume();
sl@0
    73
sl@0
    74
	/**
sl@0
    75
	If thread exited normally, return its return code
sl@0
    76
	Otherwise, leave with exit reason
sl@0
    77
	*/
sl@0
    78
	virtual TInt WaitForExitL();
sl@0
    79
sl@0
    80
	virtual void Rendezvous(TRequestStatus& aStatus);
sl@0
    81
sl@0
    82
private:
sl@0
    83
	void Init(const TDesC& aName, TThreadFunction aFn, TAny* aData, TBool aAutoResume);
sl@0
    84
sl@0
    85
	RThread iThread;
sl@0
    86
	};
sl@0
    87
sl@0
    88
class CTest : public CBase, public TFunctor
sl@0
    89
	{
sl@0
    90
public:
sl@0
    91
	~CTest();
sl@0
    92
sl@0
    93
	virtual void operator()();
sl@0
    94
	virtual void RunTest() = 0;
sl@0
    95
	virtual CTest* Clone() const = 0;
sl@0
    96
sl@0
    97
	/**
sl@0
    98
	Prints a formatted description of the test
sl@0
    99
	*/
sl@0
   100
	void Announce() const;
sl@0
   101
sl@0
   102
	const TDesC& Name() const;
sl@0
   103
sl@0
   104
	/**
sl@0
   105
	Should print the type of test, with no newlines.
sl@0
   106
	eg. "Transfer", "Fragmentation"
sl@0
   107
	TODO drop the function, just add a test type member
sl@0
   108
	*/
sl@0
   109
	virtual void PrintTestType() const = 0;
sl@0
   110
sl@0
   111
	/**
sl@0
   112
	Display any information about test environment, with no newlines
sl@0
   113
	eg. "DMA channel 16"
sl@0
   114
	The base class version prints nothing.
sl@0
   115
	*/
sl@0
   116
	virtual void PrintTestInfo() const;
sl@0
   117
sl@0
   118
protected:
sl@0
   119
	CTest(const TDesC& aName, TInt aIterations);
sl@0
   120
	CTest(const CTest& aOther);
sl@0
   121
sl@0
   122
	//It would be useful to have an RTest member, but this can't be
sl@0
   123
	//initialised untill the new thread is running as it will refer to
sl@0
   124
	//the creating thread
sl@0
   125
	RBuf iName;
sl@0
   126
	const TInt iIterations;
sl@0
   127
	};
sl@0
   128
sl@0
   129
/**
sl@0
   130
Make aNumberOfThreads copies of aTest and run
sl@0
   131
each in its own thread
sl@0
   132
sl@0
   133
@param test Reference to test object
sl@0
   134
@param aTest Referance
sl@0
   135
*/
sl@0
   136
void MultipleTestRun(RTest& test, const CTest& aTest, TInt aNumberOfThreads);
sl@0
   137
sl@0
   138
void MultipleTestRun(const RPointerArray<CTest>& aTests);
sl@0
   139
#endif // #ifndef __TEST_THREAD_H__
sl@0
   140