|
1 // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 |
|
13 |
|
14 /** |
|
15 @file |
|
16 @test |
|
17 @internalComponent - Internal Symbian test code |
|
18 */ |
|
19 |
|
20 |
|
21 #ifndef __REMOTETESTBASE_H__ |
|
22 #define __REMOTETESTBASE_H__ |
|
23 |
|
24 |
|
25 #include <e32base.h> |
|
26 #include <e32msgqueue.h> |
|
27 #include <test/tefexportconst.h> |
|
28 #include "eglendpointwrap.h" |
|
29 #include "egltest_commscommon.h" |
|
30 |
|
31 |
|
32 class CRemoteTestStepBase; |
|
33 class CRemoteTestEnv; |
|
34 |
|
35 |
|
36 //Active object used to generate a timeout if worker thread takes too long. |
|
37 class CTimeoutTimer : public CTimer |
|
38 { |
|
39 public: |
|
40 static CTimeoutTimer* NewL(CRemoteTestEnv& aEnv, TInt aPriority); |
|
41 ~CTimeoutTimer(); |
|
42 |
|
43 private: |
|
44 CTimeoutTimer(CRemoteTestEnv& aEnv, TInt aPriority); |
|
45 void ConstructL(); |
|
46 void RunL(); |
|
47 |
|
48 private: |
|
49 CRemoteTestEnv& iEnv; |
|
50 }; |
|
51 |
|
52 |
|
53 //Active object used to listen to the worker thread to see if it panics. |
|
54 class CWorkerListener : public CActive |
|
55 { |
|
56 public: |
|
57 static CWorkerListener* NewL(CRemoteTestEnv& aEnv, TInt aPriority); |
|
58 ~CWorkerListener(); |
|
59 void Listen(RThread& aThread); |
|
60 |
|
61 private: |
|
62 CWorkerListener(CRemoteTestEnv& aEnv, TInt aPriority); |
|
63 void ConstructL(); |
|
64 void RunL(); |
|
65 void DoCancel(); |
|
66 |
|
67 private: |
|
68 CRemoteTestEnv& iEnv; |
|
69 RThread* iThread; |
|
70 }; |
|
71 |
|
72 |
|
73 //Active object used to listen for test case completion from the worker thread. |
|
74 class CTestCaseListener : public CActive |
|
75 { |
|
76 public: |
|
77 static CTestCaseListener* NewL(CRemoteTestEnv& aEnv, TInt aPriority); |
|
78 ~CTestCaseListener(); |
|
79 void Listen(); |
|
80 |
|
81 private: |
|
82 CTestCaseListener(CRemoteTestEnv& aEnv, TInt aPriority); |
|
83 void ConstructL(); |
|
84 void RunL(); |
|
85 void DoCancel(); |
|
86 |
|
87 private: |
|
88 CRemoteTestEnv& iEnv; |
|
89 }; |
|
90 |
|
91 |
|
92 //This class provides the remote test environment. CreateRemoteTestStepL() |
|
93 //Should be edited to return an instance of a derived CRemoteTestStepBase |
|
94 //class that corresponds with the passed in aTestUid. |
|
95 class CRemoteTestEnv : public CActive |
|
96 { |
|
97 public: |
|
98 static CRemoteTestEnv* NewL(); |
|
99 virtual ~CRemoteTestEnv(); |
|
100 |
|
101 void StartReceivingCmds(); |
|
102 CRemoteTestStepBase* CreateRemoteTestStepL(TTestUid aTestUid); |
|
103 |
|
104 void SendResult(TRemoteTestVerdict aVerdict); |
|
105 void SendLog(const TDesC8& aFile, TInt aLine, TInt aSeverity, const TDesC& aMessage); |
|
106 |
|
107 void TestCaseCompleted(); |
|
108 void TestCaseTimedOut(); |
|
109 void WorkerExitted(); |
|
110 |
|
111 protected: |
|
112 CRemoteTestEnv(); |
|
113 void ConstructL(); |
|
114 |
|
115 private: |
|
116 void RunL(); |
|
117 void DoCancel(); |
|
118 |
|
119 void ReceiveCmd(); |
|
120 TBool SetupTestStep(); |
|
121 |
|
122 //These functions run in the context of the worker thread. |
|
123 void RunCurrentTestStepL(); |
|
124 static TInt TestThreadEntryPoint(TAny* aSelf); |
|
125 |
|
126 void DoEglHeapMark(); |
|
127 void DoEglHeapCheck(); |
|
128 |
|
129 private: |
|
130 RMsgQueue<TRemoteTestResult> iResultOutQueue; |
|
131 RMsgQueue<TRemoteTestParamsPacket> iParamsInQueue; |
|
132 |
|
133 CRemoteTestStepBase* iCurTestStep; |
|
134 TRemoteTestParamsPacket iCurTestCaseParamsPacket; |
|
135 TRemoteTestVerdict iCurTestCaseVerdict; |
|
136 RThread iCurWorker; |
|
137 |
|
138 TThreadId iSupervisorId; |
|
139 TRequestStatus iNotifyRunTestCase; |
|
140 |
|
141 CTimeoutTimer* iTimeoutTimer; |
|
142 CWorkerListener* iWorkerListener; |
|
143 CTestCaseListener* iTestCaseListener; |
|
144 }; |
|
145 |
|
146 |
|
147 //This is the base class for all remote test steps. Derived classes should implement |
|
148 //DoRemoteTestStepL(), and return the result of the test as a TVerdict. |
|
149 class CRemoteTestStepBase : public CBase, public MLog |
|
150 { |
|
151 public: |
|
152 virtual ~CRemoteTestStepBase(); |
|
153 |
|
154 virtual TRemoteTestVerdict DoStartRemoteTestStepL(const TRemoteTestParams& aMessageIn); |
|
155 virtual TRemoteTestVerdict DoRunRemoteTestCaseL(TInt aTestCase, const TRemoteTestParams& aMessageIn) = 0; |
|
156 virtual TRemoteTestVerdict DoEndRemoteTestStepL(const TRemoteTestParams& aMessageIn); |
|
157 |
|
158 virtual TInt Timeout() const; |
|
159 |
|
160 void Log(const TText8* aFile, TInt aLine, TInt aSeverity, TRefByValue<const TDesC> aFmt, ...); |
|
161 const TEglEndpointWrap& EglEndpoint() const; |
|
162 |
|
163 void EglStartL(); |
|
164 void EglEndL(); |
|
165 |
|
166 protected: |
|
167 CRemoteTestStepBase(TTestUid aUid); |
|
168 |
|
169 private: |
|
170 friend class CRemoteTestEnv; |
|
171 //Function called by CRemoteTestEnv. |
|
172 //It should NOT be called by a derived class during construction. |
|
173 void ConstructL(CRemoteTestEnv& aTestEnv); |
|
174 |
|
175 private: |
|
176 const TTestUid iUid; |
|
177 TInt iCurrentTestCase; |
|
178 CRemoteTestEnv* iTestEnv; |
|
179 TEglEndpointWrap iEndpoint; |
|
180 }; |
|
181 |
|
182 |
|
183 // Logger Macros - based on TEF but for use with CRemoteTestStepBase. |
|
184 //The severity enumeration is from TEF. |
|
185 #define REMOTE_INFO_PRINTF1(p1) Log(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1)) |
|
186 #define REMOTE_INFO_PRINTF2(p1, p2) Log(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2)) |
|
187 #define REMOTE_INFO_PRINTF3(p1, p2, p3) Log(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3)) |
|
188 #define REMOTE_INFO_PRINTF4(p1, p2, p3, p4) Log(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3), (p4)) |
|
189 #define REMOTE_INFO_PRINTF5(p1, p2, p3, p4, p5) Log(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3), (p4), (p5)) |
|
190 #define REMOTE_INFO_PRINTF6(p1, p2, p3, p4, p5, p6) Log(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3), (p4), (p5), (p6)) |
|
191 #define REMOTE_INFO_PRINTF7(p1, p2, p3, p4, p5, p6, p7) Log(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7)) |
|
192 |
|
193 #define REMOTE_WARN_PRINTF1(p1) Log(((TText8*)__FILE__), __LINE__, ESevrWarn, (p1)) |
|
194 #define REMOTE_WARN_PRINTF2(p1, p2) Log(((TText8*)__FILE__), __LINE__, ESevrWarn, (p1), (p2)) |
|
195 #define REMOTE_WARN_PRINTF3(p1, p2, p3) Log(((TText8*)__FILE__), __LINE__, ESevrWarn, (p1), (p2), (p3)) |
|
196 #define REMOTE_WARN_PRINTF4(p1, p2, p3, p4) Log(((TText8*)__FILE__), __LINE__, ESevrWarn, (p1), (p2), (p3), (p4)) |
|
197 #define REMOTE_WARN_PRINTF5(p1, p2, p3, p4, p5) Log(((TText8*)__FILE__), __LINE__, ESevrWarn, (p1), (p2), (p3), (p4), (p5)) |
|
198 #define REMOTE_WARN_PRINTF6(p1, p2, p3, p4, p5, p6) Log(((TText8*)__FILE__), __LINE__, ESevrWarn, (p1), (p2), (p3), (p4), (p5), (p6)) |
|
199 #define REMOTE_WARN_PRINTF7(p1, p2, p3, p4, p5, p6, p7) Log(((TText8*)__FILE__), __LINE__, ESevrWarn, (p1), (p2), (p3), (p4), (p5), (p6), (p7)) |
|
200 |
|
201 #define REMOTE_ERR_PRINTF1(p1) Log(((TText8*)__FILE__), __LINE__, ESevrErr, (p1)) |
|
202 #define REMOTE_ERR_PRINTF2(p1, p2) Log(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2)) |
|
203 #define REMOTE_ERR_PRINTF3(p1, p2, p3) Log(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2), (p3)) |
|
204 #define REMOTE_ERR_PRINTF4(p1, p2, p3, p4) Log(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2), (p3), (p4)) |
|
205 #define REMOTE_ERR_PRINTF5(p1, p2, p3, p4, p5) Log(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2), (p3), (p4), (p5)) |
|
206 #define REMOTE_ERR_PRINTF6(p1, p2, p3, p4, p5, p6) Log(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2), (p3), (p4), (p5), (p6)) |
|
207 #define REMOTE_ERR_PRINTF7(p1, p2, p3, p4, p5, p6, p7) Log(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2), (p3), (p4), (p5), (p6), (p7)) |
|
208 |
|
209 |
|
210 #endif |