|
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 the License "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 // e32test/iic/t_iic.cpp |
|
15 // |
|
16 |
|
17 // This file interacts with test-specific LDD to instigate tests of functionality |
|
18 // that would normally be invoked by kernel-side device driver clients of the IIC. |
|
19 #include <e32test.h> |
|
20 #include <e32cmn.h> |
|
21 #include <e32cmn_private.h> |
|
22 #include <e32def.h> |
|
23 #include <e32def_private.h> |
|
24 #include "t_iic.h" |
|
25 |
|
26 //for memory leak checking |
|
27 #include <e32svr.h> |
|
28 #include <u32hal.h> |
|
29 |
|
30 _LIT(testName,"t_iic"); |
|
31 |
|
32 _LIT(KIicProxyFileNameCtrlLess, "iic_client_ctrless.ldd"); // Kernel-side proxy LDD acting as a client of the IIC |
|
33 _LIT(KIicProxyFileNameRootCtrlLess, "iic_client_ctrless"); |
|
34 _LIT(KIicProxySlaveFileNameCtrlLess, "iic_slaveclient_ctrless.ldd"); // Kernel-side proxy LDD acting as a slave client of the IIC |
|
35 _LIT(KIicProxySlaveFileNameRootCtrlLess, "iic_slaveclient_ctrless"); |
|
36 _LIT(KIicProxyFileName, "iic_client.ldd"); // Kernel-side proxy LDD acting as a client of the IIC |
|
37 _LIT(KIicProxyFileNameRoot, "iic_client"); |
|
38 _LIT(KIicProxySlaveFileName, "iic_slaveclient.ldd"); // Kernel-side proxy LDD acting as a slave client of the IIC |
|
39 _LIT(KIicProxySlaveFileNameRoot, "iic_slaveclient"); |
|
40 |
|
41 #ifdef IIC_SIMULATED_PSL |
|
42 _LIT(KSpiFileNameCtrlLess, "spi_ctrless.pdd"); // Simulated PSL bus implementation |
|
43 _LIT(KI2cFileNameCtrlLess, "i2c_ctrless.pdd"); // Simulated PSL bus implementation |
|
44 _LIT(KIicPslFileName, "iic_testpsl.pdd"); // Simulated PSL implementation |
|
45 _LIT(KSpiFileName, "spi.pdd"); // Simulated PSL bus implementation |
|
46 _LIT(KI2cFileName, "i2c.pdd"); // Simulated PSL bus implementation |
|
47 #endif |
|
48 |
|
49 _LIT(KIicPslFileNameRoot, "iic.pdd"); |
|
50 |
|
51 // Specify a stand-alone channel |
|
52 GLDEF_D TBool aStandAloneChan; |
|
53 |
|
54 GLDEF_D RTest gTest(testName); |
|
55 |
|
56 |
|
57 // SPI has Master channel numbers 1,2 and 4, Slave channel number 3 |
|
58 GLDEF_D RBusDevIicClient gChanMasterSpi; |
|
59 GLDEF_D RBusDevIicClient gChanSlaveSpi; |
|
60 |
|
61 // I2C has Master channel numbers 10 and 11, if built with MASTER_MODE, only |
|
62 // I2C has Slave channel numbers 12 and 13, if built with SLAVE_MODE, only |
|
63 // I2C has Master channel number 10 and Slave channel number 11 if built with both MASTER_MODE and SLAVE_MODE |
|
64 GLDEF_D RBusDevIicClient gChanMasterI2c; |
|
65 GLDEF_D RBusDevIicClient gChanSlaveI2c; |
|
66 |
|
67 LOCAL_C TInt CreateSingleUserSideTransfer(TUsideTferDesc*& aTfer, TInt8 aType, TInt8 aBufGran, TDes8* aBuf, TUsideTferDesc* aNext) |
|
68 // Utility function to create a single transfer |
|
69 { |
|
70 aTfer = new TUsideTferDesc(); |
|
71 if(aTfer==NULL) |
|
72 return KErrNoMemory; |
|
73 aTfer->iType=aType; |
|
74 aTfer->iBufGranularity=aBufGran; |
|
75 aTfer->iBuffer = aBuf; |
|
76 aTfer->iNext = aNext; |
|
77 return KErrNone; |
|
78 } |
|
79 |
|
80 LOCAL_C TInt CreateSingleUserSideTransaction(TUsideTracnDesc*& aTracn, TBusType aType, TDes8* aHdr, TUsideTferDesc* aHalfDupTrans, TUsideTferDesc* aFullDupTrans, TUint8 aFlags, TAny* aPreambleArg, TAny* aMultiTranscArg) |
|
81 // Utility function to create a single transaction |
|
82 { |
|
83 aTracn = new TUsideTracnDesc(); |
|
84 if(aTracn==NULL) |
|
85 return KErrNoMemory; |
|
86 aTracn->iType=aType; |
|
87 aTracn->iHeader=aHdr; |
|
88 aTracn->iHalfDuplexTrans=aHalfDupTrans; |
|
89 aTracn->iFullDuplexTrans=aFullDupTrans; |
|
90 aTracn->iFlags=aFlags; |
|
91 aTracn->iPreambleArg = aPreambleArg; |
|
92 aTracn->iMultiTranscArg = aMultiTranscArg; |
|
93 return KErrNone; |
|
94 } |
|
95 |
|
96 |
|
97 //---------------------------------------------------------------------------------------------- |
|
98 //! @SYMTestCaseID KBASE-T_IIC-2402 |
|
99 //! @SYMTestType UT |
|
100 //! @SYMPREQ PREQ2128,2129 |
|
101 //! @SYMTestCaseDesc This test case test the Master channel basic functionality |
|
102 //! @SYMTestActions 0) Create a transaction and invoke the synchronous Queue Transaction API |
|
103 //! |
|
104 //! 1) Re-use the transaction and invoke asynchronous Queue Transaction API. Wait for |
|
105 //| the TRequestStatus to be completed. |
|
106 //! |
|
107 //! 2) Instruct the Kernel-side proxy client to instigate testing of priority queuing. |
|
108 //! The proxy uses controlIO to block the transaction queue, then queues 5 transactions in reverse |
|
109 //! priority order. The proxy then uses controlIO to unblock the transaction queue and checks that |
|
110 //! the transactions complete in priority order. |
|
111 //! |
|
112 //! 3) Attempt to cancel a previously-completed asynchronous request for a queued transaction |
|
113 //! |
|
114 //! 4) Use controlio to block request completion. Issue two asynchronous Queue Transaction requests. |
|
115 //! Request cancellation of the second transaction. Wait for completion of the TRequestStatus for |
|
116 //! the second request. Attempt to de-register the channel. Use controlio to unblock request completion. |
|
117 //! Wait for completion of the TRequestStatus for the first request. |
|
118 //! |
|
119 //! 5) Attempt to de-register a channel that is not busy. |
|
120 //! |
|
121 //! 6) Attempt to queue a transaction on an invalid (de-registered) channel |
|
122 //! |
|
123 //! 7) Instruct the Kernel-side proxy client to instigate construction of a valid full duplex transaction. |
|
124 //! |
|
125 //! 8) Instruct the Kernel-side proxy client to instigate construction of a invalid full duplex transaction, |
|
126 //! where both transfer in same direction |
|
127 //! |
|
128 //! 9) Instruct the Kernel-side proxy client to instigate construction of a invalid full duplex transaction, |
|
129 //! where with different node length (not the number of node on opposite linklist ) at the same |
|
130 //! position on the opposite transfer linklist |
|
131 //! |
|
132 //! 10) Instruct the Kernel-side proxy client to instigate construction of a valid full duplex transaction, |
|
133 //! with different size for the last node |
|
134 //! |
|
135 //! 11) Instruct the Kernel-side proxy client to instigate construction of a valid full duplex transaction, |
|
136 //! with different number of transfer |
|
137 //! |
|
138 //! |
|
139 //! @SYMTestExpectedResults 0) Kernel-side proxy client should return with KErrNone, exits otherwise. |
|
140 //! 1) Kernel-side proxy client should return with KErrNone, exits otherwise. TRequestStatus should |
|
141 //! be set to KErrNone, exits otherwise. |
|
142 //! 2) Kernel-side proxy client should return with KErrNone, exits otherwise. |
|
143 //! 3) Kernel-side proxy client should return with KErrNone, exits otherwise.TRequestStatus should |
|
144 //! be set to KErrNone, exits otherwise. |
|
145 //! 4) The TRequestStatus for the cancelled request should be set to KErrCancel, exits otherwise. |
|
146 //! The attempt to de-register the channel should return KErrInUse, exits otherwise. The |
|
147 //! TRequestStatus for the first request should be set to KErrNone, exits otherwise. |
|
148 //! 5) Kernel-side proxy client should return with KErrNone or KErrArgument, exits otherwise. |
|
149 //! 6) Kernel-side proxy client should return with KErrArgument, exits otherwise. |
|
150 //! 7) Kernel-side proxy client should return with KErrNone, exits otherwise. |
|
151 //! 8) Kernel-side proxy client should return with KErrNotSupported, exits otherwise. |
|
152 //! 9) Kernel-side proxy client should return with KErrNotSupported, exits otherwise. |
|
153 //! 10) Kernel-side proxy client should return with KErrNone, exits otherwise. |
|
154 //! 11) Kernel-side proxy client should return with KErrNone, exits otherwise. |
|
155 //! |
|
156 //! @SYMTestPriority High |
|
157 //! @SYMTestStatus Implemented |
|
158 //---------------------------------------------------------------------------------------------- |
|
159 LOCAL_C TInt MasterBasicTests() |
|
160 // |
|
161 // Exercise the Master Channel API with trivial data |
|
162 // |
|
163 { |
|
164 gTest.Printf(_L("\n\nStarting MasterBasicTests\n")); |
|
165 |
|
166 TInt r=KErrNone; |
|
167 |
|
168 TUint32 busIdSpi = 0; |
|
169 |
|
170 // Use the SPI bus |
|
171 // SPI uses channel numbers 1,2,3 and 4 |
|
172 SET_BUS_TYPE(busIdSpi,ESpi); |
|
173 SET_CHAN_NUM(busIdSpi,2); |
|
174 TConfigSpiBufV01* spiBuf = NULL; |
|
175 // aDeviceId=1 ... 100kHz ... aTimeoutPeriod=100 ... aTransactionWaitCycles=10 - arbitrary paarmeters. |
|
176 r = CreateSpiBuf(spiBuf, ESpiWordWidth_8, 100000, ESpiPolarityLowRisingEdge, 100 ,ELittleEndian, EMsbFirst, 10, ESpiCSPinActiveLow); |
|
177 gTest(r==KErrNone); |
|
178 |
|
179 // Use a single transfer |
|
180 _LIT(halfDuplexText,"Half Duplex Text"); |
|
181 TBuf8<17> halfDuplexBuf_8; |
|
182 halfDuplexBuf_8.Copy(halfDuplexText); |
|
183 TUsideTferDesc* tfer = NULL; |
|
184 r = CreateSingleUserSideTransfer(tfer, EMasterWrite, 8, &halfDuplexBuf_8, NULL); |
|
185 gTest(r==KErrNone); |
|
186 |
|
187 // Create the transaction object |
|
188 TUsideTracnDesc* tracn = NULL; |
|
189 r = CreateSingleUserSideTransaction(tracn, ESpi, spiBuf, tfer, NULL, 0, NULL, NULL); |
|
190 gTest(r==KErrNone); |
|
191 |
|
192 // Test basic queueing operations |
|
193 // inline TInt QueueTransaction(TInt aBusId, TUsideTracnDesc* aTransaction) |
|
194 gTest.Printf(_L("\n\nStarting synchronous QueueTransaction \n")); |
|
195 r = gChanMasterSpi.QueueTransaction(busIdSpi, tracn); |
|
196 gTest.Printf(_L("Synchronous QueueTransaction returned = %d\n"),r); |
|
197 gTest(r==KErrNone); |
|
198 // inline void QueueTransaction(TRequestStatus& aStatus, TInt aBusId, TUsideTracnDesc* aTransaction) |
|
199 gTest.Printf(_L("\n\nStarting asynchronous QueueTransaction \n")); |
|
200 TRequestStatus status; |
|
201 |
|
202 gChanMasterSpi.QueueTransaction(status, busIdSpi, tracn); |
|
203 User::WaitForRequest(status); |
|
204 if(status != KErrNone) |
|
205 { |
|
206 gTest.Printf(_L("TRequestStatus value after queue = %d\n"), status.Int()); |
|
207 gTest(EFalse); |
|
208 } |
|
209 |
|
210 // Test message with priorities |
|
211 gTest.Printf(_L("\n\nStarting test for message with priorities\n\n"),r); |
|
212 r = gChanMasterSpi.TestPriority(busIdSpi); |
|
213 gTest(r==KErrNone); |
|
214 |
|
215 // Test cancel operation (on previously completed request) |
|
216 |
|
217 // inline void CancelAsyncOperation(TRequestStatus* aStatus, TInt aBusId) {TInt* parms[2]; parms[0]=(TInt*)aStatus; parms[1]=(TInt*)aBusId;DoCancel((TInt)&parms[0]);} |
|
218 gTest.Printf(_L("\n\nStarting CancelAsyncOperation \n")); |
|
219 gChanMasterSpi.CancelAsyncOperation(&status, busIdSpi); |
|
220 if(status == KRequestPending) |
|
221 User::WaitForRequest(status); |
|
222 if(status != KErrNone) |
|
223 { |
|
224 gTest.Printf(_L("TRequestStatus value after (belated) cancel = %d\n"), status.Int()); |
|
225 gTest(EFalse); |
|
226 } |
|
227 |
|
228 // Test cancel operation (on pending request) |
|
229 // Also test that a channel with a transaction queued can not be de-registered. |
|
230 // For this: |
|
231 // (1) create a second transaction object |
|
232 // (2) use controlio/StaticExtension to block request completion |
|
233 // (3) use asynchronous queue transaction for the two transaction objects |
|
234 // (4) request cancellation of the second request |
|
235 // (5) check that the TRequestStatus object associated with the second request is completed with KErrCancel |
|
236 // (6) check that attempt to de-register the channel fails with KErrInUse |
|
237 // (7) use controlio/StaticExtension to unblock request completion |
|
238 // (8) check that the TRequestStatus object associated with the first request is completed with KErrNone |
|
239 // |
|
240 gTest.Printf(_L("\n\nStarting (successful) cancellation test\n\n"),r); |
|
241 _LIT(halfDuplexText2,"2 Half Duplex Text 2"); |
|
242 TBuf8<21> halfDuplexBuf2_8; |
|
243 halfDuplexBuf2_8.Copy(halfDuplexText2); |
|
244 TUsideTferDesc* tfer2 = NULL; |
|
245 r = CreateSingleUserSideTransfer(tfer2, EMasterRead, 16, &halfDuplexBuf2_8, NULL); |
|
246 gTest(r == KErrNone); |
|
247 |
|
248 TUsideTracnDesc* tracn2 = NULL; |
|
249 delete spiBuf; |
|
250 spiBuf = NULL; |
|
251 |
|
252 // aDeviceId=1 ... 100kHz ... aTimeoutPeriod=100 ... aTransactionWaitCycles=10 - arbitrary paarmeters. |
|
253 r = CreateSpiBuf(spiBuf, ESpiWordWidth_8, 100000, ESpiPolarityLowRisingEdge, 100 ,ELittleEndian, EMsbFirst, 10, ESpiCSPinActiveLow); |
|
254 gTest(r == KErrNone); |
|
255 |
|
256 r = CreateSingleUserSideTransaction(tracn2, ESpi, spiBuf, tfer2, NULL, 0, NULL, NULL); |
|
257 gTest(r == KErrNone); |
|
258 |
|
259 // |
|
260 gTest.Printf(_L("Invoking BlockReqCompletion\n")); |
|
261 r = gChanMasterSpi.BlockReqCompletion(busIdSpi); |
|
262 gTest.Printf(_L("BlockReqCompletion returned = %d\n"),r); |
|
263 gTest(r == KErrNone); |
|
264 |
|
265 // |
|
266 gTest.Printf(_L("Queueing first transaction \n")); |
|
267 gChanMasterSpi.QueueTransaction(status, busIdSpi, tracn); |
|
268 TRequestStatus status2; |
|
269 |
|
270 gTest.Printf(_L("Queueing second transaction \n")); |
|
271 gChanMasterSpi.QueueTransaction(status2, busIdSpi, tracn2); |
|
272 // |
|
273 User::After(50000); |
|
274 // |
|
275 gTest.Printf(_L("Issuing Cancel for second transaction\n")); |
|
276 gChanMasterSpi.CancelAsyncOperation(&status2, busIdSpi); |
|
277 gTest.Printf(_L("Returned from Cancel for second transaction\n")); |
|
278 if(status2 == KRequestPending) |
|
279 User::WaitForRequest(status2); |
|
280 if(status2 != KErrCancel) |
|
281 { |
|
282 gTest.Printf(_L("TRequestStatus (2) value after cancel = %d\n"), status2.Int()); |
|
283 gTest(EFalse); |
|
284 } |
|
285 |
|
286 // If it is stand-alone channel, the client is reponsible for channel creation. |
|
287 // So the RegisterChan and DeRegisterChan are not needed. |
|
288 if (aStandAloneChan == 0) |
|
289 { |
|
290 gTest.Printf(_L("Invoking DeRegisterChan\n")); |
|
291 r = gChanMasterSpi.DeRegisterChan(busIdSpi); |
|
292 |
|
293 gTest.Printf(_L("DeRegisterChan returned = %d\n"),r); |
|
294 gTest(r==KErrInUse); |
|
295 } |
|
296 // |
|
297 gTest.Printf(_L("Invoking UnlockReqCompletion\n")); |
|
298 r = gChanMasterSpi.UnblockReqCompletion(busIdSpi); |
|
299 gTest.Printf(_L("UnblockReqCompletion returned = %d\n"),r); |
|
300 // |
|
301 User::After(50000); |
|
302 // |
|
303 User::WaitForRequest(status); |
|
304 if(status != KErrNone) |
|
305 { |
|
306 gTest.Printf(_L("TRequestStatus value after queue = %d\n"), status.Int()); |
|
307 gTest(EFalse); |
|
308 } |
|
309 |
|
310 // Clean up |
|
311 delete spiBuf; |
|
312 delete tfer; |
|
313 delete tracn; |
|
314 delete tfer2; |
|
315 delete tracn2; |
|
316 |
|
317 gTest.Printf(_L("\n\nStarting full duplex transaction creation test\n\n"),r); |
|
318 |
|
319 TUint32 busIdSpiFd = 0; |
|
320 |
|
321 // Use the SPI bus |
|
322 // SPI uses channel numbers 1,2,3 and 4 |
|
323 SET_BUS_TYPE(busIdSpi,ESpi); |
|
324 SET_CHAN_NUM(busIdSpi,4); |
|
325 |
|
326 // Test creating a valid full duplex transaction |
|
327 gTest.Printf(_L("\n\nStarting valid full duplex transaction test\n\n"),r); |
|
328 r = gChanMasterSpi.TestValidFullDuplexTrans(busIdSpiFd); |
|
329 gTest(r==KErrNone); |
|
330 |
|
331 // Test creating a full duplex transaction with both transfer in same direction (invalid) |
|
332 gTest.Printf(_L("\n\nStarting invalid direction full duplex transaction test\n\n"),r); |
|
333 r = gChanMasterSpi.TestInvalidFullDuplexTrans1(busIdSpiFd); |
|
334 gTest.Printf(_L("Full duplex transaction with invalid direction returned = %d\n"),r); |
|
335 gTest(r==KErrNotSupported); |
|
336 |
|
337 // Test creating a full duplex transaction with different node length (not the number of node on opposite linklist ) |
|
338 // at the same position on the opposite transfer linklist |
|
339 gTest.Printf(_L("\n\nStarting invalid transfer length full duplex transaction test\n\n"),r); |
|
340 r = gChanMasterSpi.TestInvalidFullDuplexTrans2(busIdSpiFd); |
|
341 gTest(r==KErrNotSupported); |
|
342 |
|
343 // Test creating a valid full duplex transaction with different size for the last node |
|
344 gTest.Printf(_L("\n\nStarting valid full duplex transaction test with diff size last node\n\n"),r); |
|
345 r = gChanMasterSpi.TestLastNodeFullDuplexTrans(busIdSpiFd); |
|
346 gTest(r==KErrNone); |
|
347 |
|
348 // Test creating a valid full duplex transaction with different number of transfer |
|
349 gTest.Printf(_L("\n\nStarting valid full duplex transaction test with diff number of transfer\n\n"),r); |
|
350 r = gChanMasterSpi.TestDiffNodeNumFullDuplexTrans(busIdSpiFd); |
|
351 gTest(r==KErrNone); |
|
352 |
|
353 return KErrNone; |
|
354 } |
|
355 |
|
356 |
|
357 //---------------------------------------------------------------------------------------------- |
|
358 //! @SYMTestCaseID KBASE-T_IIC-2403 |
|
359 //! @SYMTestType UT |
|
360 //! @SYMPREQ PREQ2128,2129 |
|
361 //! @SYMTestCaseDesc This test case tests the Master channel data handling for transactions |
|
362 //! @SYMTestActions 0) Instruct the kernel-side proxy to construct a transaction of pre-defined data |
|
363 //! and inform the simulated bus to expect to receive this data. Then the proxy invokes |
|
364 //! the synchronous Queue Transaction API. On receipt of the transaction, the simulated bus |
|
365 //! checks the header and transafer content of the transaction to confirm that it is correct. |
|
366 //! |
|
367 //! @SYMTestExpectedResults 0) Kernel-side proxy client should return with KErrNone, exits otherwise. |
|
368 //! |
|
369 //! @SYMTestPriority High |
|
370 //! @SYMTestStatus Implemented |
|
371 //---------------------------------------------------------------------------------------------- |
|
372 LOCAL_C TInt MasterTransactionTests() |
|
373 // |
|
374 // Exercise the Master Channel API with trivial data |
|
375 // |
|
376 { |
|
377 gTest.Printf(_L("\n\nStarting MasterTransactionTests\n")); |
|
378 |
|
379 TInt r = KErrNone; |
|
380 |
|
381 // Prove that the simulated bus can access the transfer data contained within a transaction |
|
382 // Do this by instructing the proxy client to: |
|
383 // (1) Inform the bus of the test about to be informed |
|
384 // (2) Send a transaction with a known number of transfers with known data |
|
385 // (3) Check the result announced by the bus. |
|
386 // |
|
387 // Use the SPI bus |
|
388 // SPI uses channel numbers 1,2,3 and 4 |
|
389 TUint32 busIdSpi = 0; |
|
390 SET_BUS_TYPE(busIdSpi,ESpi); |
|
391 SET_CHAN_NUM(busIdSpi,4); // Master, Full-duplex - required by TestBufferReUse |
|
392 r = gChanMasterSpi.TestTracnOne(busIdSpi); |
|
393 gTest.Printf(_L("TestTracnOne returned = %d\n"),r); |
|
394 gTest(r==KErrNone); |
|
395 |
|
396 // Test that transfer and transaction buffers can be modifed for re-use |
|
397 // This test modifies the content of a full-duplex transaction - so a full-duplex channel must be used |
|
398 TRequestStatus status; |
|
399 gChanMasterSpi.TestBufferReUse(busIdSpi, status); |
|
400 User::WaitForRequest(status); |
|
401 r=status.Int(); |
|
402 if(r != KErrNone) |
|
403 { |
|
404 gTest.Printf(_L("TRequestStatus value after CaptureChannel = %d\n"),r); |
|
405 gTest(r==KErrCompletion); |
|
406 } |
|
407 |
|
408 return KErrNone; |
|
409 } |
|
410 |
|
411 //---------------------------------------------------------------------------------------------- |
|
412 //! @SYMTestCaseID KBASE-T_IIC-2401 |
|
413 //! @SYMTestType UT |
|
414 //! @SYMPREQ PREQ2128,2129 |
|
415 //! @SYMTestCaseDesc This test case test the Master channel preamble and multi-transaction functionality. |
|
416 //! @SYMTestActions 0) Create a transaction that requires preamble support, and queue it for processing |
|
417 //! |
|
418 //! 1) If the test has been invoked for preamble testing, wait for the preamble-specific |
|
419 //! TRequestStatus to be completed. |
|
420 //! |
|
421 //! 2) If the test has been invoked for multi-transaction testing, wait for the multi-transaction |
|
422 //! -specific TRequestStatus to be completed. |
|
423 //! |
|
424 //! |
|
425 //! @SYMTestExpectedResults 0) Kernel-side proxy client should return with KErrNone, exits otherwise. |
|
426 //! 1) If waiting on the preamble-specific TRequestStatus, it should be set to KErrNone, exists otherwise. |
|
427 //! 2) If waiting on the multi-transaction-specific TRequestStatus, it should be set to KErrNone, exists otherwise. |
|
428 //! |
|
429 //! @SYMTestPriority High |
|
430 //! @SYMTestStatus Implemented |
|
431 //---------------------------------------------------------------------------------------------- |
|
432 LOCAL_C TInt MasterExtTests(TUint8 aFlags) |
|
433 // |
|
434 // Exercise the Master Channel API for Preamble functionality |
|
435 // |
|
436 |
|
437 // For the multi-transaction test, a bus Master might not know |
|
438 // how much data to write to a Slave until it performs a single read on it. |
|
439 // However, specifying a read separately from the subsequent write |
|
440 // introduces the risk of allowing another transaction to go ahead of the |
|
441 // following write and thus invalidating it. The multi-transaction feature of IIC |
|
442 // allows a callback to be called(in the context of the bus channel) after |
|
443 // the transfers of a preliminary transaction have taken place |
|
444 // (could be a single read), without completing the overall transaction, |
|
445 // then extend the delayed transaction by inserting more transfers |
|
446 // |
|
447 { |
|
448 gTest.Printf(_L("\n\nStarting MasterExtTests\n")); |
|
449 |
|
450 TInt r = KErrNone; |
|
451 |
|
452 // Create a transaction that requires preamble support |
|
453 // To prove required operation has executed, make callback complete a TRequestStatus object |
|
454 TRequestStatus preamblestatus; |
|
455 TRequestStatus multitranscstatus; |
|
456 |
|
457 // Use the SPI bus |
|
458 // SPI uses channel numbers 1,2,3 and 4 |
|
459 TUint32 busIdSpi = 0; |
|
460 SET_BUS_TYPE(busIdSpi, ESpi); |
|
461 SET_CHAN_NUM(busIdSpi, 1); |
|
462 TConfigSpiBufV01* spiBuf = NULL; |
|
463 // aDeviceId=1 ... 100kHz ... aTimeoutPeriod=100 ... aTransactionWaitCycles=10 - arbitrary paarmeters. |
|
464 r = CreateSpiBuf(spiBuf, ESpiWordWidth_8, 100000, |
|
465 ESpiPolarityLowRisingEdge, 100, ELittleEndian, EMsbFirst, 10, |
|
466 ESpiCSPinActiveLow); |
|
467 if (r != KErrNone) |
|
468 return r; |
|
469 |
|
470 // Use a single transfer |
|
471 _LIT(extText, "Ext Text"); |
|
472 TBuf8<14> extBuf_8; |
|
473 extBuf_8.Copy(extText); |
|
474 TUsideTferDesc* tfer = NULL; |
|
475 r = CreateSingleUserSideTransfer(tfer, EMasterRead, 8, &extBuf_8, NULL); |
|
476 if (r != KErrNone) |
|
477 { |
|
478 delete spiBuf; |
|
479 return r; |
|
480 } |
|
481 |
|
482 // Create the transaction object |
|
483 TUsideTracnDesc* tracn = NULL; |
|
484 r = CreateSingleUserSideTransaction(tracn, ESpi, spiBuf, tfer, NULL, |
|
485 aFlags, (TAny*) &preamblestatus, (TAny*) &multitranscstatus); |
|
486 |
|
487 if (r != KErrNone) |
|
488 { |
|
489 delete spiBuf; |
|
490 delete tfer; |
|
491 return r; |
|
492 } |
|
493 |
|
494 // Send the transaction to the kernel-side proxy |
|
495 // inline TInt QueueTransaction(TInt aBusId, TUsideTracnDesc* aTransaction) |
|
496 gTest.Printf(_L("\nInvoke synchronous QueueTransaction for preamble test %x\n"), tracn); |
|
497 |
|
498 r = gChanMasterSpi.QueueTransaction(busIdSpi, tracn); |
|
499 gTest.Printf(_L("synchronous QueueTransaction returned = %d\n"), r); |
|
500 |
|
501 if (r == KErrNone) |
|
502 { |
|
503 // ... and wait for the TRequestStatus object to be completed |
|
504 if (aFlags & KTransactionWithPreamble) |
|
505 { |
|
506 User::WaitForRequest(preamblestatus); |
|
507 r = preamblestatus.Int(); |
|
508 if (r != KErrNone) |
|
509 { |
|
510 gTest.Printf(_L("MasterPreambleTests: TRequestStatus completed with = %d\n"), r); |
|
511 } |
|
512 } |
|
513 |
|
514 |
|
515 if (aFlags & KTransactionWithMultiTransc) |
|
516 { |
|
517 User::WaitForRequest(multitranscstatus); |
|
518 if (r != KErrNone) |
|
519 { |
|
520 gTest.Printf(_L("MasterMultiTranscTests: TRequestStatus completed with = %d\n"), r); |
|
521 } |
|
522 } |
|
523 } |
|
524 |
|
525 delete spiBuf; |
|
526 delete tfer; |
|
527 delete tracn; |
|
528 |
|
529 return r; |
|
530 } |
|
531 |
|
532 #ifdef SLAVE_MODE |
|
533 LOCAL_C TInt CreateSlaveChanI2cConfig(TConfigI2cBufV01*& aI2cBuf, TUint32& aBusIdI2c, TUint8 aChanNum) |
|
534 { |
|
535 // Initialise TConfigI2cBufV01 and the Bus Realisation Config for gChanSlaveI2c. |
|
536 // Customised: |
|
537 // - token containing the bus realisation variability. |
|
538 // - pointer to a descriptor containing the device specific configuration option applicable to all transactions. |
|
539 // - reference to variable to hold a platform-specific cookie that uniquely identifies the channel instance to be |
|
540 // used by this client |
|
541 aBusIdI2c = 0; |
|
542 SET_BUS_TYPE(aBusIdI2c,EI2c); |
|
543 SET_CHAN_NUM(aBusIdI2c,aChanNum); |
|
544 // |
|
545 // clock speed=36Hz, aTimeoutPeriod=100 - arbitrary parameter |
|
546 TInt r=CreateI2cBuf(aI2cBuf, EI2cAddr7Bit, 36, ELittleEndian, 100); |
|
547 return r; |
|
548 } |
|
549 |
|
550 LOCAL_C TInt SyncCaptureGChanSlaveI2c(TInt& aChanId, TConfigI2cBufV01* aI2cBuf, TUint32 aBusIdI2c) |
|
551 { |
|
552 // Synchronous capture of a Slave channel. Need to provide: |
|
553 // - token containing the bus realisation variability. |
|
554 // - pointer to a descriptor containing the device specific configuration option applicable to all transactions. |
|
555 // - reference to variable to hold a platform-specific cookie that uniquely identifies the channel instance to be used by this client |
|
556 gTest.Printf(_L("\n\nStarting synchronous CaptureChannel \n")); |
|
557 TInt r = gChanSlaveI2c.CaptureChannel(aBusIdI2c, aI2cBuf, aChanId ); |
|
558 gTest.Printf(_L("Synchronous CaptureChannel returned = %d, aChanId=0x%x\n"),r,aChanId); |
|
559 return r; |
|
560 } |
|
561 |
|
562 |
|
563 LOCAL_C TInt AsyncCaptureGChanSlaveI2c(TInt& aChanId, TConfigI2cBufV01* aI2cBuf, TUint32 aBusIdI2c) |
|
564 { |
|
565 // Asynchronous capture of a Slave channel. Need to provide: |
|
566 // - token containing the bus realisation variability. |
|
567 // - pointer to a descriptor containing the device specific configuration option applicable to all transactions. |
|
568 // - reference to variable to hold a platform-specific cookie that uniquely identifies the channel instance to be used by this client |
|
569 // - pointer to TRequestStatus used to indicate operation completion |
|
570 gTest.Printf(_L("\n\nStarting asynchronous CaptureChannel \n")); |
|
571 TRequestStatus status; |
|
572 TInt r = gChanSlaveI2c.CaptureChannel(aBusIdI2c, aI2cBuf, aChanId, status ); |
|
573 gTest(r==KErrNone); |
|
574 User::WaitForRequest(status); |
|
575 r=status.Int(); |
|
576 if(r != KErrCompletion) |
|
577 { |
|
578 gTest.Printf(_L("TRequestStatus value after CaptureChannel = %d\n"),r); |
|
579 gTest(r==KErrCompletion); |
|
580 } |
|
581 gTest.Printf(_L("Asynchronous CaptureChannel gave aChanId=0x%x\n"),aChanId); |
|
582 return KErrNone; |
|
583 } |
|
584 #endif |
|
585 //---------------------------------------------------------------------------------------------- |
|
586 //! @SYMTestCaseID KBASE-T_IIC-2399 |
|
587 //! @SYMTestType UT |
|
588 //! @SYMPREQ PREQ2128,2129 |
|
589 //! @SYMTestCaseDesc This test case tests Slave channel capture and release APIs. |
|
590 //! @SYMTestActions 0) Perform synchronous capture of a channel |
|
591 //! |
|
592 //! 1) Release the channel |
|
593 //! |
|
594 //! 2) Perform asynchronous capture of a channel |
|
595 //! |
|
596 //! 3) Attempt synchronous capture of a channel that is already captured |
|
597 //! |
|
598 //! 4) Attempt asynchronous capture of a channel that is already captured |
|
599 //! |
|
600 //! 5) Release the channel |
|
601 //! |
|
602 //! @SYMTestExpectedResults 0) Kernel-side proxy client should return with KErrCompletion, exits otherwise. |
|
603 //! 1) Kernel-side proxy client should return with KErrNone, exits otherwise. |
|
604 //! 2) Kernel-side proxy client should return with KErrNone, exits otherwise. |
|
605 //! 3) Kernel-side proxy client should return with KErrInUse, exits otherwise. |
|
606 //! 4) Kernel-side proxy client should return with KErrNone, exits otherwise. The associated |
|
607 //! TRequestStatus should be set to KErrInUse, exits otherwise. |
|
608 //! 5) Kernel-side proxy client should return with KErrNone, exits otherwise. |
|
609 //! |
|
610 //! @SYMTestPriority High |
|
611 //! @SYMTestStatus Implemented |
|
612 //---------------------------------------------------------------------------------------------- |
|
613 LOCAL_C TInt SlaveChannelCaptureReleaseTests() |
|
614 // |
|
615 // Exercise the Slave Channel API for channel capture and release |
|
616 // |
|
617 { |
|
618 gTest.Printf(_L("\n\nStarting SlaveChannelCaptureReleaseTests\n")); |
|
619 TInt r=KErrNone; |
|
620 #ifdef SLAVE_MODE |
|
621 |
|
622 // Create a I2C configuration buffer and the configuration data for use in capturing gChanSlaveI2c |
|
623 TUint32 busIdI2c = 0; |
|
624 TConfigI2cBufV01* i2cBuf=NULL; |
|
625 r=CreateSlaveChanI2cConfig(i2cBuf, busIdI2c, 11); // 11 is the Slave channel number |
|
626 gTest(r==KErrNone); |
|
627 |
|
628 // Synchronous capture of a Slave channel. |
|
629 TInt chanId = 0; // Initialise to zero to silence compiler ... |
|
630 r=SyncCaptureGChanSlaveI2c(chanId, i2cBuf, busIdI2c); |
|
631 gTest(r==KErrNone); |
|
632 // |
|
633 // Release the channel |
|
634 gTest.Printf(_L("\n\nInvoke ReleaseChannel for chanId=0x%x \n"),chanId); |
|
635 r = gChanSlaveI2c.ReleaseChannel( chanId ); |
|
636 gTest.Printf(_L("ReleaseChannel returned = %d\n"),r); |
|
637 gTest(r==KErrNone); |
|
638 // |
|
639 // Asynchronous capture of a Slave channel. |
|
640 chanId = 0; // Re-initialise to zero to silence compiler ... |
|
641 r=AsyncCaptureGChanSlaveI2c(chanId, i2cBuf, busIdI2c); |
|
642 gTest(r==KErrNone); |
|
643 |
|
644 // Try capturing a slave channel that is already captured |
|
645 // |
|
646 // Create another instance of a client, and use to attempt duplicated capture |
|
647 TInt dumChanId = 0; // Initialise to zero to silence compiler ... |
|
648 RBusDevIicClient tempChanSlaveI2c; |
|
649 TBufC<24> proxySlaveName; |
|
650 if(aStandAloneChan == 0) |
|
651 proxySlaveName = KIicProxySlaveFileNameRoot; |
|
652 else |
|
653 proxySlaveName = KIicProxySlaveFileNameRootCtrlLess; |
|
654 r = tempChanSlaveI2c.Open(proxySlaveName); |
|
655 gTest(r==KErrNone); |
|
656 r = tempChanSlaveI2c.InitSlaveClient(); |
|
657 gTest(r==KErrNone); |
|
658 // |
|
659 // Synchronous capture |
|
660 gTest.Printf(_L("\n\nStarting attempted synchronous CaptureChannel of previously-captured channel\n")); |
|
661 r = tempChanSlaveI2c.CaptureChannel(busIdI2c, i2cBuf, dumChanId ); |
|
662 gTest.Printf(_L("Synchronous CaptureChannel returned = %d, dumChanId=0x%x\n"),r,dumChanId); |
|
663 gTest(r==KErrInUse); |
|
664 // |
|
665 // Asynchronous capture |
|
666 dumChanId = 0; |
|
667 gTest.Printf(_L("\n\nStarting attempted asynchronous CaptureChannel of previously-captured channel\n")); |
|
668 TRequestStatus status; |
|
669 r = tempChanSlaveI2c.CaptureChannel(busIdI2c, i2cBuf, dumChanId, status ); |
|
670 gTest(r==KErrNone); |
|
671 User::WaitForRequest(status); |
|
672 r=status.Int(); |
|
673 if(r != KErrInUse) |
|
674 { |
|
675 gTest.Printf(_L("TRequestStatus value after attempted CaptureChannel of previously-captured channel = %d\n"),r); |
|
676 gTest(r==KErrInUse); |
|
677 } |
|
678 gTest.Printf(_L("Asynchronous CaptureChannel gave dumChanId=0x%x\n"),dumChanId); |
|
679 |
|
680 tempChanSlaveI2c.Close(); |
|
681 // |
|
682 // Clean up, release the channel |
|
683 r = gChanSlaveI2c.ReleaseChannel( chanId ); |
|
684 gTest.Printf(_L("ReleaseChannel returned = %d\n"),r); |
|
685 gTest(r==KErrNone); |
|
686 |
|
687 delete i2cBuf; |
|
688 #else |
|
689 gTest.Printf(_L("\nSlaveChannelCaptureReleaseTests only supported when SLAVE_MODE is defined\n")); |
|
690 #endif |
|
691 return r; |
|
692 } |
|
693 |
|
694 //---------------------------------------------------------------------------------------------- |
|
695 //! @SYMTestCaseID KBASE-T_IIC-2400 |
|
696 //! @SYMTestType UT |
|
697 //! @SYMPREQ PREQ2128,2129 |
|
698 //! @SYMTestCaseDesc This test case tests Slave channel capture operation for receive and transmit of data |
|
699 //! @SYMTestActions 0) Check that the timeout threshold values can be updated |
|
700 //! |
|
701 //! 1) Check that an Rx Buffer can be registered, and that a replacement buffer can be registered in its place |
|
702 //! if a notification has not been requested. |
|
703 //! |
|
704 //! 2) Specify a notification trigger for Rx events |
|
705 //! |
|
706 //! 3) Attempt to register a replacement Rx buffer |
|
707 //! |
|
708 //! 4) Use controlIO to instruct the simulated bus to indicate that it has received the required number of words |
|
709 //! and wait for the TRequestStatus to be completed. |
|
710 //! |
|
711 //! 5) Specify a notification trigger for Rx events, use controlIO to instruct the simulated bus to indicate that |
|
712 //! it has received less than the required number of words and wait for the TRequestStatus to be completed. |
|
713 //! |
|
714 //! 6) Specify a notification trigger for Rx events, use controlIO to instruct the simulated bus to indicate that |
|
715 //! it has received more than the required number of words and wait for the TRequestStatus to be completed. |
|
716 //! |
|
717 //! 7) Repeat steps 1-6, but for Tx |
|
718 //! |
|
719 //! 8) Specify a notification trigger for Rx and Tx events. Use controlIO to instruct the simulated bus to indicate that |
|
720 //! it has received the required number of words, then that it has transmitted the required number of words, and wait |
|
721 //! for the TRequestStatus to be completed. |
|
722 //! |
|
723 //! 9) Repeat step 8, but simulate Tx, then Rx. |
|
724 //! |
|
725 //! 10) Specify a notification trigger for bus error events. Use controlIO to instruct the simulated bus to indicate that |
|
726 //! it has encountered a bus error, and wait for the TRequestStatus to be completed. |
|
727 //! |
|
728 //! 11) Use controlIO to instruct the simulated bus to block Master response. Specify a notification trigger for bus error |
|
729 //! events. Use controlIO to instruct the simulated bus to indicate that it has received more than the required number |
|
730 //! of words. Wait for the TRequestStatus to be completed (with KErrNone). Specify a notification trigger for Tx and |
|
731 //! Tx Overrun, then use controlIO to instruct the simulated bus to unblock Master responses.Wait for the TRequestStatus |
|
732 //! to be completed. |
|
733 //! |
|
734 //! @SYMTestExpectedResults 0) Kernel-side proxy client should return with KErrNone, exits otherwise. |
|
735 //! 1) Kernel-side proxy client should return with KErrNone, exits otherwise. |
|
736 //! 2) Kernel-side proxy client should return with KErrNone, exits otherwise. |
|
737 //! 3) Kernel-side proxy client should return with KErrAlreadyExists, exits otherwise. |
|
738 //! 4) Kernel-side proxy client should return with KErrNone, exits otherwise. The associated |
|
739 //! TRequestStatus should be set to KErrNone, exits otherwise. |
|
740 //! 5) Kernel-side proxy client should return with KErrNone for both API calls, exits otherwise. The associated |
|
741 //! TRequestStatus should be set to KErrNone, exits otherwise. |
|
742 //! 6) Kernel-side proxy client should return with KErrNone for both API calls, exits otherwise. The associated |
|
743 //! TRequestStatus should be set to KErrNone, exits otherwise. |
|
744 //! 7) Results should be the same as for steps 1-6. |
|
745 //! 8) Kernel-side proxy client should return with KErrNone for each API call, exits otherwise. The associated |
|
746 //! TRequestStatus should be set to KErrNone, exits otherwise. |
|
747 //! 9) Kernel-side proxy client should return with KErrNone for each API call, exits otherwise. The associated |
|
748 //! TRequestStatus should be set to KErrNone, exits otherwise. |
|
749 //! 10) Kernel-side proxy client should return with KErrNone for each API call, exits otherwise. The associated |
|
750 //! TRequestStatus should be set to KErrNone, exits otherwise. |
|
751 //! 11) Kernel-side proxy client should return with KErrNone for each API call, exits otherwise. The associated |
|
752 //! TRequestStatus should be set to KErrNone in both cases, exits otherwise. |
|
753 //! |
|
754 //! @SYMTestPriority High |
|
755 //! @SYMTestStatus Implemented |
|
756 //---------------------------------------------------------------------------------------------- |
|
757 |
|
758 LOCAL_C TInt SlaveRxTxNotificationTests() |
|
759 // |
|
760 // Exercise the Slave channel operation for receive and transmit of data |
|
761 // |
|
762 |
|
763 // The means to supply a buffer to be filled with data received from the Master, and the number of words expected. |
|
764 // It is only after the reception of the number of words specified that the notification should be issued |
|
765 // (or on under-run/overrun/timeout/bus specific error). |
|
766 // |
|
767 // The means to supply a buffer with data to be transmitted to the Master, and the number of words to transmit. |
|
768 // It is only after the transmission of the number of words specified that the notification should be issued |
|
769 // (or under-run/overrun/timeout/bus specific error). |
|
770 // |
|
771 // The means to enable and disable the events which will trigger the notification callback. These events are: |
|
772 // 1) the complete reception of the number of words specified, |
|
773 // 2) the complete transmission of the number of words specified, |
|
774 // 3) errors: receive buffer under-run (the Master terminates the transaction or reverts the direction of |
|
775 // transfer before all expected data has been received), receive buffer overrun |
|
776 // (Master attempts to write more data than this channel expected to receive), transmit buffer overrun |
|
777 // (Master attempts to read more data than supplied by client), transmit buffer under-run |
|
778 // (the Master terminates the transaction or reverts the direction of transfer before all expected data |
|
779 // has been transmitted to it), access timeout(1) error, or bus specific error (e.g. collision, framing). |
|
780 { |
|
781 gTest.Printf(_L("\n\nStarting SlaveRxTxNotificationTests\n")); |
|
782 TInt r=KErrNone; |
|
783 #ifdef SLAVE_MODE |
|
784 |
|
785 //Configure and capture a channel |
|
786 gTest.Printf(_L("Create and capture channel\n")); |
|
787 TUint32 busIdI2c; |
|
788 TConfigI2cBufV01* i2cBuf=NULL; |
|
789 r=CreateSlaveChanI2cConfig(i2cBuf, busIdI2c, 11); // 11 is the Slave channel number |
|
790 gTest(r==KErrNone); |
|
791 |
|
792 TInt chanId = 0; // Initialise to zero to silence compiler ... |
|
793 r=SyncCaptureGChanSlaveI2c(chanId, i2cBuf, busIdI2c); |
|
794 gTest(r==KErrNone); |
|
795 |
|
796 // Update wait times for Master and Client |
|
797 // Delegate the operation of this test to the proxy client (iic_client). The proxy will read, modify, and reinstate |
|
798 // the timeout values. |
|
799 gTest.Printf(_L("Starting UpdateTimeoutValues\n")); |
|
800 r=gChanSlaveI2c.UpdateTimeoutValues(busIdI2c, chanId); |
|
801 gTest(r==KErrNone); |
|
802 |
|
803 |
|
804 // Receive and transmit buffers must be created by the client in Kernel heap and remain in their ownership throughout. |
|
805 // Therefore, the kernel-side proxy will provide the buffer |
|
806 // The buffers are of size KRxBufSizeInBytes and KRxBufSizeInBytes (currently 64) |
|
807 |
|
808 // |
|
809 // Rx tests |
|
810 // |
|
811 |
|
812 // For Rx, specify buffer granularity=4 (32-bit words), 8 words to receive, offset of 16 bytes |
|
813 // 64 bytes as 16 words: words 0-3 offset, words 4-11 data, words 12-15 unused |
|
814 gTest.Printf(_L("Starting RegisterRxBuffer\n")); |
|
815 r=gChanSlaveI2c.RegisterRxBuffer(chanId, 4, 8, 16); |
|
816 gTest(r==KErrNone); |
|
817 // |
|
818 // If a buffer is already registered but a notification has not yet been requested the API should return KErrNone |
|
819 gTest.Printf(_L("Starting (repeated) RegisterRxBuffer\n")); |
|
820 r=gChanSlaveI2c.RegisterRxBuffer(chanId, 4, 8, 16); |
|
821 gTest(r==KErrNone); |
|
822 // |
|
823 // Now set the notification trigger |
|
824 TRequestStatus status; |
|
825 TInt triggerMask=ERxAllBytes; |
|
826 gTest.Printf(_L("Starting SetNotificationTrigger with ERxAllBytes\n")); |
|
827 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); |
|
828 gTest(r==KErrNone); |
|
829 // |
|
830 // If a buffer is registered and a notification has been requested the API should return KErrAlreadyExists |
|
831 gTest.Printf(_L("Starting RegisterRxBuffer (to be rejected)\n")); |
|
832 r=gChanSlaveI2c.RegisterRxBuffer(chanId, 4, 8, 16); |
|
833 gTest(r==KErrAlreadyExists); |
|
834 // |
|
835 // Now instruct the bus implementation to represent receipt of the required number of words from the bus master. |
|
836 gTest.Printf(_L("Starting SimulateRxNWords\n")); |
|
837 r=gChanSlaveI2c.SimulateRxNWords(busIdI2c, chanId, 8); |
|
838 gTest(r==KErrNone); |
|
839 // |
|
840 // Wait for the notification |
|
841 User::WaitForRequest(status); |
|
842 r=status.Int(); |
|
843 if(r != KErrNone) |
|
844 { |
|
845 gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r); |
|
846 gTest(r==KErrNone); |
|
847 } |
|
848 gTest.Printf(_L("Starting Rx test completed OK\n")); |
|
849 // |
|
850 // Repeat for each error condition. Re-use the buffer previously registered. |
|
851 // |
|
852 // |
|
853 triggerMask=ERxAllBytes|ERxUnderrun; |
|
854 gTest.Printf(_L("Starting SetNotificationTrigger with ERxAllBytes\n")); |
|
855 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); |
|
856 gTest(r==KErrNone); |
|
857 // Now instruct the bus implementation to represent the bus master transmitting less words than anticipated (Rx Underrun) |
|
858 gTest.Printf(_L("Starting SimulateRxNWords for Underrun\n")); |
|
859 r=gChanSlaveI2c.SimulateRxNWords(busIdI2c, chanId, 6); |
|
860 gTest(r==KErrNone); |
|
861 // |
|
862 // Wait for the notification |
|
863 User::WaitForRequest(status); |
|
864 r=status.Int(); |
|
865 if(r != KErrNone) |
|
866 { |
|
867 gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r); |
|
868 gTest(r==KErrNone); |
|
869 } |
|
870 gTest.Printf(_L("Rx Underrun test completed OK\n")); |
|
871 // Re-set the notification trigger |
|
872 triggerMask=ERxAllBytes|ERxOverrun; |
|
873 gTest.Printf(_L("Starting SetNotificationTrigger\n")); |
|
874 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); |
|
875 gTest(r==KErrNone); |
|
876 // Now instruct the bus implementation to represent the bus master attempting to transmit more words than |
|
877 // anticipated (Rx Overrun) |
|
878 gTest.Printf(_L("Starting SimulateRxNWords for Overrun\n")); |
|
879 r=gChanSlaveI2c.SimulateRxNWords(busIdI2c, chanId, 10); |
|
880 gTest(r==KErrNone); |
|
881 // |
|
882 // Wait for the notification |
|
883 User::WaitForRequest(status); |
|
884 r=status.Int(); |
|
885 if(r != KErrNone) |
|
886 { |
|
887 gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r); |
|
888 gTest(r==KErrNone); |
|
889 } |
|
890 gTest.Printf(_L("Rx Overrun test completed OK\n")); |
|
891 |
|
892 // |
|
893 // Tx tests |
|
894 // |
|
895 |
|
896 // For Tx, specify buffer granularity=4 (32-bit words), 12 words to transmit, offset of 8 bytes |
|
897 // 64 bytes as 16 words: words 0-1 offset, words 2-13 data, words 14-15 unused |
|
898 gTest.Printf(_L("\nStarting RegisterTxBuffer\n")); |
|
899 r=gChanSlaveI2c.RegisterTxBuffer(chanId, 4, 12, 8); |
|
900 gTest(r==KErrNone); |
|
901 // |
|
902 // If a buffer is already registered but a notification has not yet been requested the API should return KErrNone |
|
903 gTest.Printf(_L("Starting (repeated) RegisterTxBuffer\n")); |
|
904 r=gChanSlaveI2c.RegisterTxBuffer(chanId, 4, 12, 8); |
|
905 gTest(r==KErrNone); |
|
906 // |
|
907 |
|
908 // Re-set the notification trigger |
|
909 // Now set the notification trigger |
|
910 gTest.Printf(_L("Starting SetNotificationTrigger\n")); |
|
911 triggerMask=ETxAllBytes; |
|
912 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); |
|
913 gTest(r==KErrNone); |
|
914 // |
|
915 // If a buffer is already registered, a subsequent request to do the same should return KErrAlreadyExists |
|
916 gTest.Printf(_L("Starting RegisterTxBuffer (to be rejected)\n")); |
|
917 r=gChanSlaveI2c.RegisterTxBuffer(chanId, 4, 12, 8); |
|
918 gTest(r==KErrAlreadyExists); |
|
919 // |
|
920 // Now instruct the bus implementation to represent transmission of the required number of words to the bus master. |
|
921 gTest.Printf(_L("Starting SimulateTxNWords (to be rejected)\n")); |
|
922 r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 12); |
|
923 gTest(r==KErrNone); |
|
924 // |
|
925 // Wait for the notification |
|
926 User::WaitForRequest(status); |
|
927 r=status.Int(); |
|
928 if(r != KErrNone) |
|
929 { |
|
930 gTest.Printf(_L("TRequestStatus value after transmitting data = %d\n"),r); |
|
931 gTest(r==KErrNone); |
|
932 } |
|
933 gTest.Printf(_L("Tx test completed OK\n")); |
|
934 // |
|
935 // Repeat for each error condition. Re-use the buffer previously registered |
|
936 // |
|
937 // Re-set the notification trigger |
|
938 gTest.Printf(_L("Starting SetNotificationTrigger\n")); |
|
939 triggerMask=ETxAllBytes|ETxOverrun; |
|
940 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); |
|
941 gTest(r==KErrNone); |
|
942 // Now instruct the bus implementation to represent transmission of less than the required number of words |
|
943 // to the bus master (Tx Overrun) |
|
944 gTest.Printf(_L("Starting SimulateTxNWords for Tx Overrun\n")); |
|
945 r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 10); |
|
946 gTest(r==KErrNone); |
|
947 // |
|
948 // Wait for the notification |
|
949 User::WaitForRequest(status); |
|
950 r=status.Int(); |
|
951 if(r != KErrNone) |
|
952 { |
|
953 gTest.Printf(_L("TRequestStatus value after transmitting data = %d\n"),r); |
|
954 gTest(r==KErrNone); |
|
955 } |
|
956 gTest.Printf(_L("Tx Overrun test completed OK\n")); |
|
957 // Re-set the notification trigger |
|
958 triggerMask=ETxAllBytes|ETxUnderrun; |
|
959 gTest.Printf(_L("Starting SetNotificationTrigger\n")); |
|
960 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); |
|
961 gTest(r==KErrNone); |
|
962 // Now instruct the bus implementation to represent the bus master attempting to read more words than |
|
963 // anticipated (Tx Underrun) |
|
964 gTest.Printf(_L("Starting SimulateTxNWords for Tx Underrun\n")); |
|
965 r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 14); |
|
966 gTest(r==KErrNone); |
|
967 // |
|
968 // Wait for the notification |
|
969 User::WaitForRequest(status); |
|
970 r=status.Int(); |
|
971 if(r != KErrNone) |
|
972 { |
|
973 gTest.Printf(_L("TRequestStatus value after transmitting data = %d\n"),r); |
|
974 gTest(r==KErrNone); |
|
975 } |
|
976 gTest.Printf(_L("Tx Underrun test completed OK\n")); |
|
977 |
|
978 // |
|
979 // Simultaneous Rx,Tx tests |
|
980 // |
|
981 // For these tests, the proxy client (iic_slaveclient) will check that the expected results are witnessed |
|
982 // in the required order, and will complete the TRequestStatus when the sequence is complete (or error occurs). |
|
983 // |
|
984 // Set the notification trigger for both Rx and Tx |
|
985 triggerMask=ERxAllBytes|ETxAllBytes; |
|
986 gTest.Printf(_L("\nStarting SetNotificationTrigger with ERxAllBytes|ETxAllBytes\n")); |
|
987 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); |
|
988 gTest(r==KErrNone); |
|
989 // Now instruct the bus implementation to represent receipt of the required number of words from the bus master. |
|
990 gTest.Printf(_L("Starting SimulateRxNWords\n")); |
|
991 r=gChanSlaveI2c.SimulateRxNWords(busIdI2c, chanId, 8); |
|
992 gTest(r==KErrNone); |
|
993 // Now instruct the bus implementation to represent transmission of the required number of words to the bus master. |
|
994 gTest.Printf(_L("Starting SimulateTxNWords\n")); |
|
995 r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 12); |
|
996 gTest(r==KErrNone); |
|
997 // |
|
998 // Wait for the notification |
|
999 User::WaitForRequest(status); |
|
1000 r=status.Int(); |
|
1001 if(r != KErrNone) |
|
1002 { |
|
1003 gTest.Printf(_L("TRequestStatus value after receiving and transmitting data = %d\n"),r); |
|
1004 gTest(r==KErrNone); |
|
1005 } |
|
1006 gTest.Printf(_L("Rx, Tx test completed OK\n")); |
|
1007 // |
|
1008 // Set the notification trigger for both Rx and Tx |
|
1009 gTest.Printf(_L("Starting SetNotificationTrigger with ERxAllBytes|ETxAllBytes\n")); |
|
1010 triggerMask=ERxAllBytes|ETxAllBytes; |
|
1011 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); |
|
1012 gTest(r==KErrNone); |
|
1013 // Now instruct the bus implementation to represent transmission of the required number of words to the bus master. |
|
1014 gTest.Printf(_L("Starting SimulateTxNWords\n")); |
|
1015 r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 12); |
|
1016 gTest(r==KErrNone); |
|
1017 // Now instruct the bus implementation to represent receipt of the required number of words from the bus master. |
|
1018 gTest.Printf(_L("Starting SimulateRxNWords\n")); |
|
1019 r=gChanSlaveI2c.SimulateRxNWords(busIdI2c, chanId, 8); |
|
1020 gTest(r==KErrNone); |
|
1021 // |
|
1022 // Wait for the notification |
|
1023 User::WaitForRequest(status); |
|
1024 r=status.Int(); |
|
1025 if(r != KErrNone) |
|
1026 { |
|
1027 gTest.Printf(_L("TRequestStatus value after receiving and transmitting data = %d\n"),r); |
|
1028 gTest(r==KErrNone); |
|
1029 } |
|
1030 gTest.Printf(_L("Tx, Rx test completed OK\n")); |
|
1031 // |
|
1032 // Set the notification trigger for both Rx and Tx |
|
1033 gTest.Printf(_L("Starting SetNotificationTrigger with ERxAllBytes|ETxAllBytes\n")); |
|
1034 triggerMask=ERxAllBytes|ETxAllBytes; |
|
1035 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); |
|
1036 gTest(r==KErrNone); |
|
1037 // Now instruct the bus implementation to represent simultaneous transmission of the required number of words (12) |
|
1038 // to the bus master and receipt of the required number of words (8) from the bus master |
|
1039 gTest.Printf(_L("Starting SimulateRxTxNWords\n")); |
|
1040 r=gChanSlaveI2c.SimulateRxTxNWords(busIdI2c, chanId, 8, 12); |
|
1041 gTest(r==KErrNone); |
|
1042 // |
|
1043 // Wait for the notification |
|
1044 User::WaitForRequest(status); |
|
1045 r=status.Int(); |
|
1046 if(r != KErrNone) |
|
1047 { |
|
1048 gTest.Printf(_L("TRequestStatus value after receiving and transmitting data = %d\n"),r); |
|
1049 gTest(r==KErrNone); |
|
1050 } |
|
1051 gTest.Printf(_L("Tx with Rx test completed OK\n")); |
|
1052 |
|
1053 // Clear the trigger mask - this is just invoking SetNotificationTrigger with a zero trigger |
|
1054 // so that no subsequent triggers are expected (and so no TRequestStatus is provided) |
|
1055 gTest.Printf(_L("Starting SetNotificationTrigger with 0\n")); |
|
1056 triggerMask=0; |
|
1057 r=gChanSlaveI2c.SetNotifNoTrigger(chanId,triggerMask); |
|
1058 gTest(r==KErrNone); |
|
1059 |
|
1060 // |
|
1061 // Rx Overrun and Tx Underrun when both Rx and Tx notifications are requested |
|
1062 // |
|
1063 gTest.Printf(_L("Starting RxOverrun-TxUnderrun with simultaneous Rx,Tx notification requests\n")); |
|
1064 gChanSlaveI2c.TestOverrunUnderrun(busIdI2c,chanId,status); |
|
1065 // |
|
1066 // Wait for the notification |
|
1067 User::WaitForRequest(status); |
|
1068 r=status.Int(); |
|
1069 if(r != KErrNone) |
|
1070 { |
|
1071 gTest.Printf(_L("TRequestStatus value after RxOverrun-TxUnderrun with simultaneous Rx,Tx notification requests= %d\n"),r); |
|
1072 gTest(r==KErrNone); |
|
1073 } |
|
1074 gTest.Printf(_L("RxOverrun-TxUnderrun with simultaneous Rx,Tx notification requests test completed OK\n")); |
|
1075 |
|
1076 |
|
1077 // |
|
1078 // Bus Error tests |
|
1079 // |
|
1080 |
|
1081 // Simulate a bus error |
|
1082 // A bus error will cause all pending bus activity to be aborted. |
|
1083 // Request a notification, then simulate a bus error |
|
1084 triggerMask=ERxAllBytes|ETxAllBytes; |
|
1085 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); |
|
1086 gTest(r==KErrNone); |
|
1087 gTest.Printf(_L("Starting SimulateBusErr\n")); |
|
1088 r = gChanSlaveI2c.SimulateBusErr(busIdI2c,chanId); |
|
1089 gTest(r==KErrNone); |
|
1090 // |
|
1091 // Wait for the notification |
|
1092 User::WaitForRequest(status); |
|
1093 r=status.Int(); |
|
1094 if(r != KErrNone) |
|
1095 { |
|
1096 gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r); |
|
1097 gTest(r==KErrNone); |
|
1098 } |
|
1099 gTest.Printf(_L("Bus error test completed OK\n")); |
|
1100 |
|
1101 // Clear the trigger mask and prepare for the next test |
|
1102 // This is unnecessary if the SetNotificationTrigger for the following test |
|
1103 // is called within the timeout period applied for Client responses ... |
|
1104 // but it represents a Client ending a transaction cleanly, and so is |
|
1105 // left here as an example |
|
1106 gTest.Printf(_L("\nStarting SetNotificationTrigger with 0\n")); |
|
1107 triggerMask=0; |
|
1108 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); |
|
1109 gTest(r==KErrNone); |
|
1110 |
|
1111 // Simulate Master timeout |
|
1112 // Do this by: |
|
1113 // - Requesting a trigger for Tx |
|
1114 // - simulating the Master performing a read (ie the PSL indicates a Tx event) to start the transaction |
|
1115 // - provide a buffer for Tx, and request notification of Tx events, ie wait for Master response |
|
1116 // - block the PSL Tx notification to the PIL, so that the PIL timeout timer expires when a simulated Tx event |
|
1117 // is next requested |
|
1118 // |
|
1119 // Indicate the test to be performed |
|
1120 gTest.Printf(_L("\nStarting BlockNotification\n")); |
|
1121 // Register a buffer for Tx, then set the notification trigger |
|
1122 gTest.Printf(_L("RegisterTxBuffer - for Master to start the transaction\n")); |
|
1123 r=gChanSlaveI2c.RegisterTxBuffer(chanId, 4, 12, 8); |
|
1124 gTest(r==KErrNone); |
|
1125 gTest.Printf(_L("SetNotificationTrigger - for Master to start the transaction\n")); |
|
1126 triggerMask=ETxAllBytes; |
|
1127 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); |
|
1128 gTest(r==KErrNone); |
|
1129 // Now instruct the bus implementation to simulate the Master reading the expected number of words |
|
1130 gTest.Printf(_L("Starting SimulateTxNWords\n")); |
|
1131 r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 12); |
|
1132 gTest(r==KErrNone); |
|
1133 // Wait for the notification |
|
1134 User::WaitForRequest(status); |
|
1135 gTest.Printf(_L("Status request completed\n")); |
|
1136 r=status.Int(); |
|
1137 if(r != KErrNone) |
|
1138 { |
|
1139 gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r); |
|
1140 gTest(r==KErrNone); |
|
1141 } |
|
1142 // Client is now expected to perform its part of the transaction - so pretend we need another Tx |
|
1143 // - but block completion of the Tx so that we generate a bus error |
|
1144 gTest.Printf(_L("SetNotificationTrigger - for second part of the transaction\n")); |
|
1145 triggerMask=ETxAllBytes; |
|
1146 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); |
|
1147 gTest(r==KErrNone); |
|
1148 gTest.Printf(_L("BlockNotification\n")); |
|
1149 r=gChanSlaveI2c.BlockNotification(busIdI2c, chanId); |
|
1150 gTest(r==KErrNone); |
|
1151 // Now instruct the bus implementation to represent the bus master attempting to read the required number of words |
|
1152 gTest.Printf(_L("\nStarting SimulateTxNWords\n")); |
|
1153 r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 12); |
|
1154 gTest(r==KErrNone); |
|
1155 // |
|
1156 // Wait for the notification |
|
1157 User::WaitForRequest(status); |
|
1158 r=status.Int(); |
|
1159 if(r != KErrNone) |
|
1160 { |
|
1161 gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r); |
|
1162 gTest(r==KErrNone); |
|
1163 } |
|
1164 gTest.Printf(_L("Blocked notification test completed OK\n")); |
|
1165 // Re-set the notification trigger - for the 'blocked' Tx |
|
1166 // This is required because, in the event of a bus error, the set of requested Rx,Tx |
|
1167 // flags are cleared |
|
1168 gTest.Printf(_L("Starting SetNotificationTrigger with ETxAllBytes\n")); |
|
1169 triggerMask=ETxAllBytes; |
|
1170 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); |
|
1171 gTest(r==KErrNone); |
|
1172 // Remove the block |
|
1173 gTest.Printf(_L("Starting UnblockNotification\n")); |
|
1174 r=gChanSlaveI2c.UnblockNotification(busIdI2c, chanId); |
|
1175 gTest(r==KErrNone); |
|
1176 // |
|
1177 // Wait for the notification |
|
1178 User::WaitForRequest(status); |
|
1179 r=status.Int(); |
|
1180 if(r != KErrNone) |
|
1181 { |
|
1182 gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r); |
|
1183 gTest(r==KErrNone); |
|
1184 } |
|
1185 gTest.Printf(_L("UnBlocked notification test completed OK\n")); |
|
1186 // Clear the trigger mask |
|
1187 gTest.Printf(_L("Starting SetNotificationTrigger with 0\n")); |
|
1188 triggerMask=0; |
|
1189 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); |
|
1190 gTest(r==KErrNone); |
|
1191 |
|
1192 // Release the channel |
|
1193 r = gChanSlaveI2c.ReleaseChannel( chanId ); |
|
1194 gTest(r==KErrNone); |
|
1195 |
|
1196 delete i2cBuf; |
|
1197 #else |
|
1198 gTest.Printf(_L("\nSlaveRxTxNotificationTests only supported when SLAVE_MODE is defined\n")); |
|
1199 #endif |
|
1200 |
|
1201 return r; |
|
1202 } |
|
1203 |
|
1204 //---------------------------------------------------------------------------------------------- |
|
1205 //! @SYMTestCaseID KBASE-T_IIC-2404 |
|
1206 //! @SYMTestType UT |
|
1207 //! @SYMPREQ PREQ2128,2129 |
|
1208 //! @SYMTestCaseDesc This test case tests that MasterSlave channels can only be used in one mode at a time, and that |
|
1209 //! if captured for Slave operation or with transactions queued for Master operation the channel can |
|
1210 //! not be de-registered. |
|
1211 //! @SYMTestActions 0) Capture the channel for Slave operation. Attempt to synchronously queue a transaction |
|
1212 //! on the channel. Attempt to asynchronously queue a transaction on the channel. Attempt |
|
1213 //! to de-register the channel.Release the Slave channel |
|
1214 //! |
|
1215 //! 1) Use controlio to block completion of queued transactions. Request asynchronous queue |
|
1216 //! transaction. Attempt to capture the channel for Slave operation. Attempt to de-register |
|
1217 //! the channel. Unblock completion of transactions and wait for the TRequestStatus for the |
|
1218 //! transaction to be completed. |
|
1219 //! |
|
1220 //! @SYMTestExpectedResults 0) Once captured for Slave operation, attempts to queue a transaction or de-register the channel |
|
1221 //! return KErrInUse, exits otherwise. |
|
1222 //! 1) With a transaction queued, attempt to capture the channel returns KErrInUse, exits otherwise. |
|
1223 //! Attempt to de-register channel returns KErrInUse, exits otherwise. The TRequestStatus should |
|
1224 //! be set to KErrTimedOut, exits otherwise. |
|
1225 //! |
|
1226 //! |
|
1227 //! @SYMTestPriority High |
|
1228 //! @SYMTestStatus Implemented |
|
1229 //---------------------------------------------------------------------------------------------- |
|
1230 LOCAL_C TInt MasterSlaveAcquisitionTests() |
|
1231 // |
|
1232 // Test to check that: |
|
1233 // (1) A Master-Slave channel that has been captured for use in Slave mode will not allow requests for |
|
1234 // queing transactions to be accepted |
|
1235 // (2) A Master-Slave channel that has been captured for use in Slave mode can not be de-registered |
|
1236 // (3) A Master-Slave channel that has one or more transactions queued in its Master channel transaction queue |
|
1237 // can not be captured for use in Slave Made |
|
1238 // (4) A Master-Slave channel that has one or more transactions queued in its Master channel transaction queue |
|
1239 // can not be de-registered |
|
1240 // |
|
1241 { |
|
1242 gTest.Printf(_L("\n\nStarting MasterSlaveAcquisitionTests\n")); |
|
1243 TInt r=KErrNone; |
|
1244 |
|
1245 #if defined(MASTER_MODE) && defined(SLAVE_MODE) |
|
1246 // Create a Master-Slave channel |
|
1247 RBusDevIicClient chanMasterSlaveI2c; |
|
1248 TBufC<18> proxyName; |
|
1249 if(!aStandAloneChan) |
|
1250 proxyName = KIicProxyFileNameRoot; |
|
1251 else |
|
1252 proxyName = KIicProxyFileNameRootCtrlLess; |
|
1253 r = chanMasterSlaveI2c.Open(proxyName); |
|
1254 gTest(r==KErrNone); |
|
1255 r = chanMasterSlaveI2c.InitSlaveClient(); // Initialise callback used for Slave processing |
|
1256 gTest(r==KErrNone); |
|
1257 // |
|
1258 // Capture the channel for Slave operation |
|
1259 // Attempt to synchronously queue a transaction on the channel - expect KErrInUse as a response |
|
1260 // Attempt to asynchronously queue a transaction on the channel - expect KErrInUse as a response |
|
1261 // Attempt to de-register the channel - expect KErrInUse as a response |
|
1262 // Release the Slave channel |
|
1263 // |
|
1264 // Create a I2C configuration buffer and the configuration data for use in capturing gChanSlaveI2c |
|
1265 TUint32 busIdI2c = 0; |
|
1266 TConfigI2cBufV01* i2cBuf=NULL; |
|
1267 r=CreateSlaveChanI2cConfig(i2cBuf, busIdI2c, 12); // 12 is the MasterSlave channel number |
|
1268 gTest(r==KErrNone); |
|
1269 TInt chanId; |
|
1270 |
|
1271 gTest.Printf(_L("\nStarting synchronous CaptureChannel \n")); |
|
1272 r = chanMasterSlaveI2c.CaptureChannel(busIdI2c, i2cBuf, chanId ); |
|
1273 gTest.Printf(_L("Synchronous CaptureChannel returned = %d, chanId=0x%x\n"),r,chanId); |
|
1274 gTest(r==KErrNone); |
|
1275 // |
|
1276 _LIT(halfDuplexText,"Half Duplex Text"); |
|
1277 TBuf8<17> halfDuplexBuf_8; |
|
1278 halfDuplexBuf_8.Copy(halfDuplexText); |
|
1279 TUsideTferDesc* tfer = NULL; |
|
1280 r=CreateSingleUserSideTransfer(tfer, EMasterWrite, 8, &halfDuplexBuf_8, NULL); |
|
1281 if(r!=KErrNone) |
|
1282 return r; |
|
1283 if(tfer==NULL) |
|
1284 return KErrGeneral; |
|
1285 // |
|
1286 TUsideTracnDesc* tracn = NULL; |
|
1287 r = CreateSingleUserSideTransaction(tracn, EI2c, i2cBuf, tfer, NULL, 0, NULL, NULL); |
|
1288 if(r!=KErrNone) |
|
1289 return r; |
|
1290 if(tracn==NULL) |
|
1291 return KErrGeneral; |
|
1292 |
|
1293 |
|
1294 gTest.Printf(_L("\nStarting synchronous QueueTransaction \n")); |
|
1295 r = chanMasterSlaveI2c.QueueTransaction(busIdI2c, tracn); |
|
1296 gTest.Printf(_L("Synchronous QueueTransaction returned = %d\n"),r); |
|
1297 gTest(r==KErrInUse); |
|
1298 gTest.Printf(_L("\nStarting asynchronous QueueTransaction \n")); |
|
1299 TRequestStatus status; |
|
1300 chanMasterSlaveI2c.QueueTransaction(status, busIdI2c, tracn); |
|
1301 User::WaitForRequest(status); |
|
1302 if(status != KErrInUse) |
|
1303 { |
|
1304 gTest.Printf(_L("TRequestStatus value after queue = %d\n"),status.Int()); |
|
1305 gTest(r==KErrInUse); |
|
1306 } |
|
1307 // |
|
1308 // // If it is stand-alone channel, the client is responsible for channel creation. |
|
1309 // // So the RegisterChan and DeRegisterChan are not needed. |
|
1310 if(aStandAloneChan == 0) |
|
1311 { |
|
1312 gTest.Printf(_L("\nStarting deregistration of captured channel\n")); |
|
1313 r = chanMasterSlaveI2c.DeRegisterChan(busIdI2c); |
|
1314 gTest.Printf(_L("DeRegisterChan returned = %d\n"),r); |
|
1315 gTest(r==KErrInUse); |
|
1316 } |
|
1317 |
|
1318 gTest.Printf(_L("\nInvoke ReleaseChannel for chanId=0x%x \n"),chanId); |
|
1319 r = chanMasterSlaveI2c.ReleaseChannel( chanId ); |
|
1320 gTest.Printf(_L("ReleaseChannel returned = %d\n"),r); |
|
1321 gTest(r==KErrNone); |
|
1322 |
|
1323 // |
|
1324 // Use ControlIO/StaticExtension to block transactions on the Master Channel |
|
1325 // Queue an asynchronous transaction on the channel |
|
1326 // Attempt to capture the channel for Slave operation - expect KErrInUse as a response |
|
1327 // Attempt to de-register the channel - expect KErrInUse as a response |
|
1328 // Unblock the channel |
|
1329 // Check for (timed out) completion of the transaction |
|
1330 // |
|
1331 gTest.Printf(_L("Invoking BlockReqCompletion\n")); |
|
1332 r = chanMasterSlaveI2c.BlockReqCompletion(busIdI2c); |
|
1333 gTest.Printf(_L("BlockReqCompletion returned = %d\n"),r); |
|
1334 // |
|
1335 gTest.Printf(_L("Queueing first transaction \n")); |
|
1336 chanMasterSlaveI2c.QueueTransaction(status, busIdI2c, tracn); |
|
1337 // |
|
1338 User::After(50000); |
|
1339 // |
|
1340 gTest.Printf(_L("\nStarting synchronous CaptureChannel \n")); |
|
1341 r = chanMasterSlaveI2c.CaptureChannel(busIdI2c, i2cBuf, chanId ); |
|
1342 gTest.Printf(_L("Synchronous CaptureChannel returned = %d, chanId=0x%x\n"),r,chanId); |
|
1343 gTest(r==KErrInUse); |
|
1344 |
|
1345 // If it is stand-alone channel, the client is responsible for channel creation. |
|
1346 // So the RegisterChan and DeRegisterChan are not needed. |
|
1347 if(aStandAloneChan == 0) |
|
1348 { |
|
1349 gTest.Printf(_L("\nStarting deregistration of channel\n")); |
|
1350 r = chanMasterSlaveI2c.DeRegisterChan(busIdI2c); |
|
1351 gTest.Printf(_L("DeRegisterChan returned = %d\n"),r); |
|
1352 gTest(r==KErrInUse); |
|
1353 } |
|
1354 gTest.Printf(_L("Invoking UnlockReqCompletion\n")); |
|
1355 r = chanMasterSlaveI2c.UnblockReqCompletion(busIdI2c); |
|
1356 gTest.Printf(_L("UnblockReqCompletion returned = %d\n"),r); |
|
1357 // |
|
1358 User::After(50000); |
|
1359 // |
|
1360 User::WaitForRequest(status); |
|
1361 r=status.Int(); |
|
1362 if(r != KErrTimedOut) |
|
1363 { |
|
1364 gTest.Printf(_L("TRequestStatus value after queue = %d\n"),r); |
|
1365 gTest(r==KErrTimedOut); |
|
1366 } |
|
1367 r=KErrNone; // Ensure error code is not propagated |
|
1368 |
|
1369 delete i2cBuf; |
|
1370 delete tfer; |
|
1371 delete tracn; |
|
1372 chanMasterSlaveI2c.Close(); |
|
1373 #else |
|
1374 gTest.Printf(_L("\nMasterSlaveAcquisitionTests only supported when both MASTER_MODE and SLAVE_MODE are defined\n")); |
|
1375 #endif |
|
1376 |
|
1377 return r; |
|
1378 } |
|
1379 |
|
1380 //---------------------------------------------------------------------------------------------- |
|
1381 //! @SYMTestCaseID KBASE-T_IIC-2404 |
|
1382 //! @SYMTestType UT |
|
1383 //! @SYMDEF DEF141732 |
|
1384 //! @SYMTestCaseDesc This test case tests the inline functions of DIicBusChannel interface. |
|
1385 //! @SYMTestActions Call Kernel-side proxy client function to perform interface tests. |
|
1386 //! @SYMTestExpectedResults Kernel-side proxy client should return with KErrNone. |
|
1387 //! @SYMTestPriority Medium |
|
1388 //! @SYMTestStatus Implemented |
|
1389 //---------------------------------------------------------------------------------------------- |
|
1390 LOCAL_C TInt IicInterfaceInlineTests() |
|
1391 { |
|
1392 if(aStandAloneChan == 1) |
|
1393 { |
|
1394 gTest.Printf(_L("\n\nStarting IicInterfaceInlineTests\n")); |
|
1395 TInt r=KErrNone; |
|
1396 r = gChanMasterSpi.TestIiicChannelInlineFunc(); |
|
1397 return r; |
|
1398 } |
|
1399 else |
|
1400 { |
|
1401 gTest.Printf(_L("\nIicInterfaceInlineTests can only be run in Standalone mode\n")); |
|
1402 return KErrNone; |
|
1403 } |
|
1404 } |
|
1405 |
|
1406 LOCAL_C TInt RunTests() |
|
1407 // |
|
1408 // Utility method to invoke the separate tests |
|
1409 // |
|
1410 { |
|
1411 TInt r =KErrNone; |
|
1412 r = IicInterfaceInlineTests(); |
|
1413 if(r!=KErrNone) |
|
1414 return r; |
|
1415 |
|
1416 r = MasterBasicTests(); |
|
1417 if(r!=KErrNone) |
|
1418 return r; |
|
1419 |
|
1420 r = SlaveRxTxNotificationTests(); |
|
1421 if(r!=KErrNone) |
|
1422 return r; |
|
1423 |
|
1424 r = SlaveChannelCaptureReleaseTests(); |
|
1425 if(r!=KErrNone) |
|
1426 return r; |
|
1427 |
|
1428 r = MasterExtTests(KTransactionWithPreamble); |
|
1429 if(r!=KErrNone) |
|
1430 return r; |
|
1431 |
|
1432 r = MasterExtTests(KTransactionWithMultiTransc); |
|
1433 if(r!=KErrNone) |
|
1434 return r; |
|
1435 |
|
1436 r = MasterExtTests(KTransactionWithMultiTransc|KTransactionWithPreamble); |
|
1437 if(r!=KErrNone) |
|
1438 return r; |
|
1439 |
|
1440 r = MasterTransactionTests(); |
|
1441 if(r!=KErrNone) |
|
1442 return r; |
|
1443 |
|
1444 r = MasterSlaveAcquisitionTests(); |
|
1445 if(r!=KErrNone) |
|
1446 return r; |
|
1447 |
|
1448 return KErrNone; |
|
1449 } |
|
1450 |
|
1451 GLDEF_C TInt E32Main() |
|
1452 // |
|
1453 // Main |
|
1454 // |
|
1455 { |
|
1456 gTest.Title(); |
|
1457 gTest.Start(_L("Test IIC API\n")); |
|
1458 |
|
1459 TInt r = KErrNone; |
|
1460 |
|
1461 #ifdef IIC_SIMULATED_PSL |
|
1462 gTest.Next(_L("Start the IIC with controller test\n")); |
|
1463 aStandAloneChan = 0; |
|
1464 gTest.Next(_L("Load Simulated IIC PSL bus driver")); |
|
1465 r = User::LoadPhysicalDevice(KIicPslFileName); |
|
1466 gTest.Printf(_L("return value r=%d"),r); |
|
1467 gTest(r==KErrNone || r==KErrAlreadyExists); |
|
1468 |
|
1469 gTest.Next(_L("Load Simulated PSL SPI bus driver")); |
|
1470 r = User::LoadPhysicalDevice(KSpiFileName); |
|
1471 gTest.Printf(_L("return value r=%d"),r); |
|
1472 gTest(r==KErrNone || r==KErrAlreadyExists); |
|
1473 |
|
1474 gTest.Next(_L("Load Simulated PSL I2C bus driver")); |
|
1475 r = User::LoadPhysicalDevice(KI2cFileName); |
|
1476 gTest.Printf(_L("return value r=%d"),r); |
|
1477 gTest(r==KErrNone || r==KErrAlreadyExists); |
|
1478 |
|
1479 gTest.Next(_L("Load kernel-side proxy IIC client")); |
|
1480 r = User::LoadLogicalDevice(KIicProxyFileName); |
|
1481 gTest(r==KErrNone || r==KErrAlreadyExists); |
|
1482 |
|
1483 gTest.Next(_L("Load kernel-side proxy IIC slave client")); |
|
1484 r = User::LoadLogicalDevice(KIicProxySlaveFileName); |
|
1485 gTest(r==KErrNone || r==KErrAlreadyExists); |
|
1486 |
|
1487 __KHEAP_MARK; |
|
1488 // First ascertain what bus options are available. |
|
1489 |
|
1490 // SPI has Master channel numbers 1,2 and 4, Slave channel number 3 |
|
1491 // Open a Master SPI channel to the kernel side proxy |
|
1492 TBufC<30> proxyName(KIicProxyFileNameRoot); |
|
1493 r = gChanMasterSpi.Open(proxyName); |
|
1494 gTest(r==KErrNone); |
|
1495 |
|
1496 // I2C has Master channel numbers 10 and 11, if built with MASTER_MODE, only |
|
1497 // I2C has Slave channel numbers 12 and 13, if built with SLAVE_MODE, only |
|
1498 // I2C has Master channel number 10 and Slave channel numer 11 if built with both MASTER_MODE and SLAVE_MODE |
|
1499 // Open a Master I2C channel to the kernel side proxy |
|
1500 r = gChanMasterI2c.Open(proxyName); |
|
1501 gTest(r==KErrNone); |
|
1502 TBufC<15> proxySlaveName(KIicProxySlaveFileNameRoot); |
|
1503 r = gChanSlaveI2c.Open(proxySlaveName); |
|
1504 gTest(r==KErrNone); |
|
1505 r = gChanSlaveI2c.InitSlaveClient(); |
|
1506 gTest(r==KErrNone); |
|
1507 |
|
1508 // Instigate tests |
|
1509 r = RunTests(); |
|
1510 gTest(r==KErrNone); |
|
1511 |
|
1512 gTest.Printf(_L("Tests completed OK, about to close channel\n")); |
|
1513 |
|
1514 gChanMasterSpi.Close(); |
|
1515 gChanMasterI2c.Close(); |
|
1516 gChanSlaveI2c.Close(); |
|
1517 |
|
1518 UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0); |
|
1519 __KHEAP_MARKEND; |
|
1520 |
|
1521 gTest.Next(_L("Free kernel-side proxy IIC client")); |
|
1522 TInt err = User::FreeLogicalDevice(KIicProxyFileNameRoot); |
|
1523 gTest(err==KErrNone || err==KErrAlreadyExists); |
|
1524 |
|
1525 gTest.Next(_L("Free kernel-side proxy IIC slave client")); |
|
1526 err = User::FreeLogicalDevice(KIicProxySlaveFileNameRoot); |
|
1527 gTest(err==KErrNone || err==KErrAlreadyExists); |
|
1528 |
|
1529 gTest.Next(_L("Free Simulated PSL I2C bus driver")); |
|
1530 err = User::FreePhysicalDevice(KI2cFileName); |
|
1531 gTest(err==KErrNone); |
|
1532 |
|
1533 gTest.Next(_L("Free Simulated PSL SPI bus driver")); |
|
1534 err = User::FreePhysicalDevice(KSpiFileName); |
|
1535 gTest(err==KErrNone); |
|
1536 |
|
1537 gTest.Next(_L("Free Simulated IIC PSL bus driver")); |
|
1538 err = User::FreePhysicalDevice(KIicPslFileNameRoot); |
|
1539 gTest(err==KErrNone); |
|
1540 |
|
1541 gTest.Next(_L("Start the controller-less IIC test\n")); |
|
1542 aStandAloneChan = 1; |
|
1543 |
|
1544 gTest.Next(_L("Load Simulated PSL SPI bus driver")); |
|
1545 r = User::LoadPhysicalDevice(KSpiFileNameCtrlLess); |
|
1546 gTest.Printf(_L("return value r=%d"),r); |
|
1547 gTest(r==KErrNone || r==KErrAlreadyExists); |
|
1548 |
|
1549 gTest.Next(_L("Load Simulated PSL I2C bus driver")); |
|
1550 r = User::LoadPhysicalDevice(KI2cFileNameCtrlLess); |
|
1551 gTest.Printf(_L("return value r=%d"),r); |
|
1552 gTest(r==KErrNone || r==KErrAlreadyExists); |
|
1553 |
|
1554 gTest.Next(_L("Load kernel-side proxy IIC client")); |
|
1555 r = User::LoadLogicalDevice(KIicProxyFileNameCtrlLess); |
|
1556 gTest(r==KErrNone || r==KErrAlreadyExists); |
|
1557 |
|
1558 gTest.Next(_L("Load kernel-side proxy IIC slave client")); |
|
1559 r = User::LoadLogicalDevice(KIicProxySlaveFileNameCtrlLess); |
|
1560 gTest(r==KErrNone || r==KErrAlreadyExists); |
|
1561 |
|
1562 // First ascertain what bus options are available. |
|
1563 __KHEAP_MARK; |
|
1564 // SPI has Master channel numbers 1,2 and 4, Slave channel number 3 |
|
1565 // Open a Master SPI channel to the kernel side proxy |
|
1566 TBufC<30> proxyNameCtrlLess(KIicProxyFileNameRootCtrlLess); |
|
1567 r = gChanMasterSpi.Open(proxyNameCtrlLess); |
|
1568 gTest(r==KErrNone); |
|
1569 |
|
1570 // I2C has Master channel numbers 10 and 11, if built with MASTER_MODE, only |
|
1571 // I2C has Slave channel numbers 12 and 13, if built with SLAVE_MODE, only |
|
1572 // I2C has Master channel number 10 and Slave channel numer 11 if built with both MASTER_MODE and SLAVE_MODE |
|
1573 // Open a Master I2C channel to the kernel side proxy |
|
1574 r = gChanMasterI2c.Open(proxyNameCtrlLess); |
|
1575 |
|
1576 gTest(r==KErrNone); |
|
1577 TBufC<35> proxySlaveNameCtrlLess(KIicProxySlaveFileNameRootCtrlLess); |
|
1578 |
|
1579 r = gChanSlaveI2c.Open(proxySlaveNameCtrlLess); |
|
1580 gTest(r==KErrNone); |
|
1581 r = gChanSlaveI2c.InitSlaveClient(); |
|
1582 gTest(r==KErrNone); |
|
1583 |
|
1584 // Instigate tests |
|
1585 r = RunTests(); |
|
1586 gTest(r==KErrNone); |
|
1587 |
|
1588 gTest.Printf(_L("Tests completed OK, about to close channel\n")); |
|
1589 |
|
1590 gChanMasterSpi.Close(); |
|
1591 gChanMasterI2c.Close(); |
|
1592 gChanSlaveI2c.Close(); |
|
1593 |
|
1594 UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0); |
|
1595 __KHEAP_MARKEND; |
|
1596 |
|
1597 gTest.Next(_L("Free kernel-side proxy IIC client")); |
|
1598 |
|
1599 err = User::FreeLogicalDevice(KIicProxyFileNameRootCtrlLess); |
|
1600 gTest(err==KErrNone || err==KErrAlreadyExists); |
|
1601 gTest.Next(_L("Free kernel-side proxy IIC slave client")); |
|
1602 err = User::FreeLogicalDevice(KIicProxySlaveFileNameRootCtrlLess); |
|
1603 gTest(err==KErrNone || err==KErrAlreadyExists); |
|
1604 |
|
1605 gTest.Next(_L("Free Simulated PSL I2C bus driver")); |
|
1606 err = User::FreePhysicalDevice(KI2cFileNameCtrlLess); |
|
1607 gTest(err==KErrNone); |
|
1608 |
|
1609 gTest.Next(_L("Free Simulated PSL SPI bus driver")); |
|
1610 err = User::FreePhysicalDevice(KSpiFileNameCtrlLess); |
|
1611 gTest(err==KErrNone); |
|
1612 #else |
|
1613 gTest.Printf(_L("Don't do the test if it is not IIC_SIMULATED_PSL")); |
|
1614 #endif |
|
1615 gTest.End(); |
|
1616 return r; |
|
1617 } |
|
1618 |