|
1 /* |
|
2 * Copyright (c) 2008-2010 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 virtual ~CTest(); |
|
92 |
|
93 virtual void operator()(); |
|
94 virtual void RunTest() = 0; |
|
95 virtual CTest* Clone() const = 0; |
|
96 |
|
97 virtual void SetupL(); |
|
98 |
|
99 /** |
|
100 Prints a formatted description of the test |
|
101 */ |
|
102 virtual void Announce() const; |
|
103 |
|
104 const TDesC& Name() const; |
|
105 |
|
106 /** |
|
107 Should print the type of test, with no newlines. |
|
108 eg. "Transfer", "Fragmentation" |
|
109 */ |
|
110 virtual void PrintTestType() const = 0; |
|
111 |
|
112 /** |
|
113 Display any information about test environment, with no newlines |
|
114 eg. "DMA channel 16" |
|
115 The base class version prints nothing. |
|
116 */ |
|
117 virtual void PrintTestInfo() const; |
|
118 |
|
119 protected: |
|
120 CTest(const TDesC& aName, TInt aIterations); |
|
121 CTest(const CTest& aOther); |
|
122 |
|
123 //It would be useful to have an RTest member, but this can't be |
|
124 //initialised untill the new thread is running as it will refer to |
|
125 //the creating thread |
|
126 RBuf iName; |
|
127 const TInt iIterations; |
|
128 }; |
|
129 |
|
130 /** |
|
131 Make aNumberOfThreads copies of aTest and run |
|
132 each in its own thread |
|
133 |
|
134 @param test Reference to test object |
|
135 @param aTest Referance |
|
136 */ |
|
137 void MultipleTestRun(RTest& test, const CTest& aTest, TInt aNumberOfThreads); |
|
138 |
|
139 void MultipleTestRun(const RPointerArray<CTest>& aTests); |
|
140 #endif // #ifndef __TEST_THREAD_H__ |
|
141 |