|
1 // Copyright (c) 2008-2009 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 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include "tipcfuzz_step.h" |
|
23 |
|
24 // Structure to hold server data to Fuzz. |
|
25 // To add tests for new servers, extend the array referring to the class definition. |
|
26 const TIpcFuzzTestParams KTestParameters[] = |
|
27 { |
|
28 { _S("!SysStateMgr"), 7, TVersion(0,1,1),2 }, |
|
29 { _S("!SusAdaptionSrv"), 30, TVersion(0,1,1),1}, |
|
30 { _S("!SusUtilSrv"), 6, TVersion(0,1,1),1} |
|
31 }; |
|
32 |
|
33 // Constants for the data index count |
|
34 const TInt K8BitDataDescCount = 9; |
|
35 const TInt K16BitDataDescCount = 9; |
|
36 const TInt KIntDataCount = 10; |
|
37 |
|
38 // Destructor |
|
39 CIpcFuzzTest::~CIpcFuzzTest() |
|
40 { |
|
41 } |
|
42 |
|
43 // Constructor |
|
44 CIpcFuzzTest::CIpcFuzzTest() |
|
45 { |
|
46 SetTestStepName(KTIpcFuzzStep); |
|
47 } |
|
48 |
|
49 // Constructor |
|
50 RIpcFuzzTest::RIpcFuzzTest() |
|
51 { |
|
52 } |
|
53 |
|
54 // Destructor |
|
55 RIpcFuzzTest::~RIpcFuzzTest() |
|
56 { |
|
57 Close(); |
|
58 } |
|
59 |
|
60 TVerdict CIpcFuzzTest::doTestStepPreambleL() |
|
61 { |
|
62 return CTestStep::doTestStepPreambleL(); |
|
63 } |
|
64 |
|
65 TVerdict CIpcFuzzTest::doTestStepPostambleL() |
|
66 { |
|
67 return CTestStep::doTestStepPostambleL(); |
|
68 } |
|
69 |
|
70 TVerdict CIpcFuzzTest::doTestStepL() |
|
71 { |
|
72 INFO_PRINTF1(_L("CIpcFuzzTest started...")); |
|
73 |
|
74 __UHEAP_MARK; |
|
75 doTestIpcFuzzL(); |
|
76 __UHEAP_MARKEND; |
|
77 |
|
78 INFO_PRINTF1(_L("...CIpcFuzzTest completed!")); |
|
79 return TestStepResult(); |
|
80 } |
|
81 |
|
82 /** |
|
83 Old Test CaseID APPFWK-IPCFUZZ-0001 |
|
84 New Test CaseID DEVSRVS-SSMA-IPCFUZZ-0001 |
|
85 */ |
|
86 void CIpcFuzzTest::doTestIpcFuzzL() |
|
87 { |
|
88 INFO_PRINTF1(_L("APPFWK-IPCFUZZ-0001:IpcFuzz Logic started")); |
|
89 RIpcFuzzTest rIpcTest; |
|
90 CleanupClosePushL(rIpcTest); |
|
91 |
|
92 CIpcFuzzer* ipcFuzzer = CIpcFuzzer::NewL(); |
|
93 CleanupStack::PushL(ipcFuzzer); |
|
94 |
|
95 TInt testIdx = (sizeof(KTestParameters)/sizeof(TIpcFuzzTestParams)); |
|
96 |
|
97 for(TInt i=0; i<testIdx; i++) |
|
98 { |
|
99 iTestParameters = &(KTestParameters[i]); |
|
100 INFO_PRINTF2(_L("IpcFuzz starts on Server:%s"),iTestParameters->iServerName); |
|
101 TRAPD(err,rIpcTest.IpcFuzzLogicL(ipcFuzzer, *iTestParameters)); |
|
102 TEST(err==KErrNone); |
|
103 INFO_PRINTF2(_L("IpcFuzz ends on Server:%s"),iTestParameters->iServerName); |
|
104 } |
|
105 |
|
106 CleanupStack::PopAndDestroy(ipcFuzzer); |
|
107 CleanupStack::PopAndDestroy(&rIpcTest); |
|
108 } |
|
109 |
|
110 // Fuzzy Logic method, which prepares the junk data (8 & 16 bit descriptor, integer) to be sent to server. |
|
111 void RIpcFuzzTest::IpcFuzzLogicL(CIpcFuzzer* aIpcFuzzer, const TIpcFuzzTestParams& aTestParameters) |
|
112 { |
|
113 TBuf<15> serverName(aTestParameters.iServerName); |
|
114 TVersion serverVersion(aTestParameters.iServerVersion); |
|
115 |
|
116 RDebug::Print(_L(">>> Server Name:%S"),&serverName); |
|
117 //Creates session with the server |
|
118 TInt ret = CreateSession(serverName,serverVersion); |
|
119 User::LeaveIfError(ret); |
|
120 RDebug::Print(_L(">>> Successfully created a session with the Server:%S"),&serverName); |
|
121 |
|
122 HBufC8* buf8 = NULL; |
|
123 HBufC* buf16 = NULL; |
|
124 TInt data = 0; |
|
125 |
|
126 TInt iteration = 1; |
|
127 TInt caseIdx = 1; |
|
128 |
|
129 while(iteration<4) |
|
130 { |
|
131 caseIdx = 1; |
|
132 switch(iteration) |
|
133 { |
|
134 case 1: |
|
135 { |
|
136 while(caseIdx<K8BitDataDescCount) |
|
137 { |
|
138 // Gets the 8 bit desc data. |
|
139 buf8 = aIpcFuzzer->GetDescData8L(caseIdx); |
|
140 if(buf8) |
|
141 { |
|
142 TPtr8 ptr8 = buf8->Des(); |
|
143 // Package the arguments to send to server. |
|
144 IpcFuzzerL(&ptr8, aTestParameters, serverName); |
|
145 delete buf8; |
|
146 buf8 = NULL; |
|
147 } |
|
148 caseIdx++; |
|
149 } |
|
150 } |
|
151 break; |
|
152 case 2: |
|
153 { |
|
154 while(caseIdx<K16BitDataDescCount) |
|
155 { |
|
156 // Gets the 16 bit desc data. |
|
157 buf16 = aIpcFuzzer->GetDescData16L(caseIdx); |
|
158 if(buf16) |
|
159 { |
|
160 TPtr ptr16 = buf16->Des(); |
|
161 // Package the arguments to send to server. |
|
162 IpcFuzzerL(&ptr16, aTestParameters, serverName); |
|
163 delete buf16; |
|
164 buf16 = NULL; |
|
165 } |
|
166 caseIdx++; |
|
167 } |
|
168 } |
|
169 break; |
|
170 case 3: |
|
171 { |
|
172 while(caseIdx<KIntDataCount) |
|
173 { |
|
174 // Get integer data. |
|
175 data = aIpcFuzzer->GetIntData(caseIdx); |
|
176 // Package the arguments to send to server. |
|
177 IpcFuzzerL(data, aTestParameters, serverName); |
|
178 caseIdx++; |
|
179 } |
|
180 } |
|
181 break; |
|
182 default: |
|
183 break; |
|
184 } |
|
185 iteration++; |
|
186 } |
|
187 } |
|
188 |
|
189 // The overloaded method which takes 8 bit pointer descriptor along with the test parameters |
|
190 // data. Package the arguments to send to server. |
|
191 void RIpcFuzzTest::IpcFuzzerL(TPtr8* aPtr, const TIpcFuzzTestParams& aTestParameters, TBuf<15> aServerName) |
|
192 { |
|
193 TIpcArgs args; |
|
194 TInt msgSlotCnt = aTestParameters.iMsgSlotCount; |
|
195 TInt opcode=0; |
|
196 |
|
197 for (TInt msgSlot=0;msgSlot<msgSlotCnt;msgSlot++) |
|
198 { |
|
199 // loop executes for number of message slots |
|
200 opcode=0; |
|
201 // Sets the argument value |
|
202 args.Set(msgSlot, aPtr); |
|
203 SendMessageToServerL(opcode, aTestParameters.iOpcodeCount, args, aServerName); |
|
204 } |
|
205 } |
|
206 |
|
207 // The overloaded method which takes 16 bit pointer descriptor along with the test parameters |
|
208 // data. Package the arguments to send to server. |
|
209 void RIpcFuzzTest::IpcFuzzerL(TPtr* aPtr, const TIpcFuzzTestParams& aTestParameters, TBuf<15> aServerName) |
|
210 { |
|
211 TIpcArgs args; |
|
212 TInt msgSlotCnt = aTestParameters.iMsgSlotCount; |
|
213 TInt opcode=0; |
|
214 |
|
215 for (TInt msgSlot=0;msgSlot<msgSlotCnt;msgSlot++) |
|
216 { |
|
217 // loop executes for number of message slots |
|
218 opcode=0; |
|
219 // Sets the argument value |
|
220 args.Set(msgSlot, aPtr); |
|
221 SendMessageToServerL(opcode, aTestParameters.iOpcodeCount, args, aServerName); |
|
222 } |
|
223 } |
|
224 |
|
225 // The overloaded method which takes unsigned integer value along with the test parameters |
|
226 // data. Package the arguments to send to server. |
|
227 void RIpcFuzzTest::IpcFuzzerL(TUint aData, const TIpcFuzzTestParams& aTestParameters, TBuf<15> aServerName) |
|
228 { |
|
229 TIpcArgs args; |
|
230 TInt msgSlotCnt = aTestParameters.iMsgSlotCount; |
|
231 TInt opcode=0; |
|
232 |
|
233 for (TInt msgSlot=0;msgSlot<msgSlotCnt;msgSlot++) |
|
234 { |
|
235 // loop executes for number of message slots |
|
236 opcode=0; |
|
237 // Sets the argument value |
|
238 args.Set(msgSlot, aData); |
|
239 SendMessageToServerL(opcode, aTestParameters.iOpcodeCount, args, aServerName); |
|
240 } |
|
241 } |
|
242 |
|
243 // Sends a message to the server and waits for the reply. An opcode specifies the service |
|
244 // required. A set of message arguments is passed that can be used to specify client addresses, |
|
245 // which the server can use to read from and write to client address space. |
|
246 void RIpcFuzzTest::SendMessageToServerL(TInt& aOpcode,const TInt& aOpcodeCnt,TIpcArgs& aIpcArgs, TBuf<15> aServerName) |
|
247 { |
|
248 while(aOpcode<aOpcodeCnt) |
|
249 { |
|
250 aOpcode++; |
|
251 //sends a packaged data to server to execute particular function at the given Opcode. |
|
252 TInt ret = SendReceive(aOpcode, aIpcArgs); |
|
253 |
|
254 // We are checking for just BAD error codes that should not be returned by the server |
|
255 // For e.g. KErrServerTerminated should never be returned, so we are failing the test here. |
|
256 // Other normal error codes such as KErrArgument, KErrNotSupported, KErrOverflow, |
|
257 // KErrBadDescriptor..etc are normal in the course of validation and so the test does not |
|
258 // check that. |
|
259 // Use the epocwind.out file to see the error returned from server for each fuzzy test call. |
|
260 if(ret==KErrServerTerminated) |
|
261 { |
|
262 RDebug::Print(_L("-- Server Response code===>%d on Opcode:%d"),ret,aOpcode); |
|
263 User::Leave(KErrServerTerminated); |
|
264 } |
|
265 //SusAdaptionSrv panics when we try to load the same library twice, hence we are cleaning up after every call to SusAdaptionSrv |
|
266 if (aServerName.Compare(_L("!SusAdaptionSrv")) == 0) |
|
267 { |
|
268 TInt opcode = 30; |
|
269 TInt ret2 = SendReceive(opcode, aIpcArgs); |
|
270 RDebug::Print(_L("-- Cleaning up: ret %d"), ret2); |
|
271 } |
|
272 RDebug::Print(_L("-- Server Response code===>%d on Opcode:%d"),ret,aOpcode); |
|
273 } |
|
274 } |
|
275 |