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