1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/dmav2/test_thread.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,140 @@
1.4 +/*
1.5 +* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description: Some helper classes to assist with writing multi-threaded tests
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#ifndef __TEST_THREAD_H__
1.23 +#define __TEST_THREAD_H__
1.24 +
1.25 +#include <e32base.h>
1.26 +#include <e32debug.h>
1.27 +#define __E32TEST_EXTENSION__
1.28 +#include <e32test.h>
1.29 +#include <e32cmn_private.h>
1.30 +
1.31 +_LIT(KPanicCat, "test_thread.h");
1.32 +
1.33 +
1.34 +static const TInt KHeapSize=0x2000;
1.35 +
1.36 +enum TPanicCode
1.37 + {
1.38 + EThreadCreateFailed
1.39 + };
1.40 +
1.41 +/**
1.42 +A utility class for running functions in other threads/processes
1.43 +*/
1.44 +class TTestRemote
1.45 + {
1.46 +public:
1.47 + virtual TInt WaitForExitL() = 0;
1.48 + virtual ~TTestRemote()
1.49 + {}
1.50 +
1.51 + virtual void Rendezvous(TRequestStatus& aStatus) = 0;
1.52 +
1.53 +protected:
1.54 + TTestRemote()
1.55 + {}
1.56 +
1.57 + static TInt RunFunctor(TAny* aFunctor);
1.58 +
1.59 + TRequestStatus iLogonStatus;
1.60 + static TInt iCount;
1.61 + };
1.62 +
1.63 +class TTestThread : public TTestRemote
1.64 + {
1.65 +public:
1.66 + TTestThread(const TDesC& aName, TThreadFunction aFn, TAny* aData, TBool aAutoResume=ETrue);
1.67 +
1.68 + /**
1.69 + Run aFunctor in another thread
1.70 + */
1.71 + TTestThread(const TDesC& aName, TFunctor& aFunctor, TBool aAutoResume=ETrue);
1.72 +
1.73 + ~TTestThread();
1.74 +
1.75 + void Resume();
1.76 +
1.77 + /**
1.78 + If thread exited normally, return its return code
1.79 + Otherwise, leave with exit reason
1.80 + */
1.81 + virtual TInt WaitForExitL();
1.82 +
1.83 + virtual void Rendezvous(TRequestStatus& aStatus);
1.84 +
1.85 +private:
1.86 + void Init(const TDesC& aName, TThreadFunction aFn, TAny* aData, TBool aAutoResume);
1.87 +
1.88 + RThread iThread;
1.89 + };
1.90 +
1.91 +class CTest : public CBase, public TFunctor
1.92 + {
1.93 +public:
1.94 + ~CTest();
1.95 +
1.96 + virtual void operator()();
1.97 + virtual void RunTest() = 0;
1.98 + virtual CTest* Clone() const = 0;
1.99 +
1.100 + /**
1.101 + Prints a formatted description of the test
1.102 + */
1.103 + void Announce() const;
1.104 +
1.105 + const TDesC& Name() const;
1.106 +
1.107 + /**
1.108 + Should print the type of test, with no newlines.
1.109 + eg. "Transfer", "Fragmentation"
1.110 + TODO drop the function, just add a test type member
1.111 + */
1.112 + virtual void PrintTestType() const = 0;
1.113 +
1.114 + /**
1.115 + Display any information about test environment, with no newlines
1.116 + eg. "DMA channel 16"
1.117 + The base class version prints nothing.
1.118 + */
1.119 + virtual void PrintTestInfo() const;
1.120 +
1.121 +protected:
1.122 + CTest(const TDesC& aName, TInt aIterations);
1.123 + CTest(const CTest& aOther);
1.124 +
1.125 + //It would be useful to have an RTest member, but this can't be
1.126 + //initialised untill the new thread is running as it will refer to
1.127 + //the creating thread
1.128 + RBuf iName;
1.129 + const TInt iIterations;
1.130 + };
1.131 +
1.132 +/**
1.133 +Make aNumberOfThreads copies of aTest and run
1.134 +each in its own thread
1.135 +
1.136 +@param test Reference to test object
1.137 +@param aTest Referance
1.138 +*/
1.139 +void MultipleTestRun(RTest& test, const CTest& aTest, TInt aNumberOfThreads);
1.140 +
1.141 +void MultipleTestRun(const RPointerArray<CTest>& aTests);
1.142 +#endif // #ifndef __TEST_THREAD_H__
1.143 +