Update contrib.
1 // Copyright (c) 1998-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\device\t_dtenot.cpp
19 #include <e32base_private.h>
33 #if defined (__WINS__)
34 #define PDD_NAME _L("ECDRV.PDD")
35 #define LDD_NAME _L("ECOMM.LDD")
37 #define PDD_NAME _L("EUART")
38 #define LDD_NAME _L("ECOMM")
41 #define CHECK(r,v) {if ((r)!=(v)) {test.Printf(_L("Line %d Expected %08x Got %08x\n"),__LINE__,(v),(r)); test(0);}}
43 // Our own comms object with synchronous writes
44 class RComm : public RBusDevComm
47 TInt WriteS(const TDesC8& aDes);
48 TInt WriteS(const TDesC8& aDes,TInt aLength);
51 LOCAL_D RTest test(_L("T_DTENOT"));
54 TCommCaps2 theCapsBuf;
55 TCommCapsV02& theCaps=theCapsBuf();
57 TInt RComm::WriteS(const TDesC8& aDes)
62 return(WriteS(aDes,aDes.Length()));
65 TInt RComm::WriteS(const TDesC8& aDes,TInt aLength)
72 Write(s,aDes,aLength);
73 User::WaitForRequest(s);
77 enum TSetClearOutSignal {ESetOutSignal,EClearOutSignal};
78 enum TOutcomeExpected {EExpectNotify,EExpectTimeout};
79 enum TSigChngNotifyType {ENotifyOnInSigOnly,ENotifyOnAnyChange};
80 LOCAL_C void TestNotifySignalChange(TUint anOutSig,TSetClearOutSignal aSetClr,TUint anInSig,TOutcomeExpected anExpect,TSigChngNotifyType aType)
82 // Change the state of the specified output signal and wait up to 2 seconds for
83 // this to trigger a change notification.
88 TRequestStatus notifStatus;
89 TRequestStatus timeStatus;
92 if (aType==ENotifyOnAnyChange)
93 theSerialPort->NotifySignalChange(notifStatus,signals);
95 theSerialPort->NotifySignalChange(notifStatus,signals,anInSig);
96 // CHECK(notifStatus.Int(),KRequestPending);
97 const TUint KTimeOut=2000000;
98 tim.After(timeStatus,KTimeOut);
99 CHECK(timeStatus.Int(),KRequestPending);
100 if (aSetClr==ESetOutSignal)
101 theSerialPort->SetSignals(anOutSig,0); // Set Out signal
103 theSerialPort->SetSignals(0,anOutSig); // Clear Out signal
104 User::WaitForRequest(notifStatus,timeStatus);
105 if (notifStatus!=KRequestPending)
107 test.Printf(_L("notifStatus=%08x\n"),notifStatus.Int());
109 User::WaitForRequest(timeStatus);
110 if (anExpect==EExpectNotify)
112 // Got a notification as expected - but was it the correct notification?
113 TUint sigmask=(anInSig*KSignalChanged);
114 if (aSetClr==ESetOutSignal)
116 if (aType==ENotifyOnAnyChange)
117 {CHECK((signals&sigmask),sigmask);}
119 {CHECK(signals,sigmask);}
123 test.Printf(_L("Spurious notify %d %08x\n"),notifStatus.Int(),signals);
124 test(FALSE); // Unexpectedly got notification
129 test.Printf(_L("timeStatus=%08x\n"),timeStatus.Int());
130 theSerialPort->NotifySignalChangeCancel();
131 User::WaitForRequest(notifStatus);
132 if (anExpect==EExpectNotify)
134 test.Printf(_L("Timed Out!\n\r"));
138 test(timeStatus==KErrNone); // Success
142 GLDEF_C TInt E32Main()
144 // Test DTE serial driver change notification
147 test.SetLogged(EFalse); // Turn off serial port debugging!
150 test.Start(_L("Check loopback connector"));
153 User::CommandLine(cmd);
155 if ((cmd.Length()>0) && (cmd[0]>='0' && cmd[0]<='9'))
156 port=(TInt)(cmd[0]-'0');
158 // Read machine name to determine handshake options required
160 TInt r=HAL::Get(HAL::EMachineUid,mid);
163 TUint handshake=(KConfigFreeRTS|KConfigFreeDTR); // So we can control them ourselves
164 if (mid==HAL::EMachineUid_Brutus && port<3)
165 handshake=0; // Brutus can't support these option on ports 0-2
167 test.Printf(_L("\r\nThis test requires a loopback conector.\r\n"));
168 test.Printf(_L("<<Hit a key to continue>>\r\n"));
172 test(HAL::Get(HAL::EMachineUid, muid)==KErrNone);
173 TBool isAssabet=(muid==HAL::EMachineUid_Assabet);
175 // Load Device Drivers
176 TBuf<10> pddName=PDD_NAME;
177 test.Next(_L("Load PDDs"));
179 const TInt KMaxPdds=0;
181 const TInt KMaxPdds=10;
184 for (i=-1; i<KMaxPdds; ++i)
187 pddName.Append(TChar('0'));
189 pddName[pddName.Length()-1]=TText('0'+i);
190 r=User::LoadPhysicalDevice(pddName);
191 if (r==KErrNone || r==KErrAlreadyExists)
192 test.Printf(_L("PDD %S loaded\n"),&pddName);
195 test.Next(_L("Load LDD"));
196 r=User::LoadLogicalDevice(LDD_NAME);
197 test.Printf(_L("Load LDD Return %d\n\r"),r);
199 test.Next(_L("Create RComm object"));
200 theSerialPort=new RComm;
201 test(theSerialPort!=NULL);
203 test.Next(_L("Open:"));
204 r=theSerialPort->Open(port);
205 test.Printf(_L("Open(%d)=%d\n\r"),port,r);
208 test.Next(_L("Get caps and configure port"));
209 theSerialPort->Caps(theCapsBuf);
211 test.Printf(_L("Signals(DTR-RTS-RI-DCD-DSR-CTS) %x\n\r"),theCaps.iSignals);
212 test.Printf(_L("Notifications %x\n\r"),theCaps.iNotificationCaps);
215 TCommConfigV01& c=cBuf();
216 theSerialPort->Config(cBuf);
217 c.iHandshake=handshake;
220 c.iParity=EParityNone;
222 r=theSerialPort->SetConfig(cBuf);
227 TRequestStatus notifStatus;
228 TRequestStatus timeStatus;
230 test.Next(_L("Testing NotifySignalChange()"));
231 if (!(theCaps.iNotificationCaps & KNotifySignalsChangeSupported))
232 test.Printf(_L("WARNING - Signal change notification not supported on this platform\r\n"));
235 if ((theCaps.iSignals&(KCapsSignalCTSSupported|KCapsSignalRTSSupported))!=(KCapsSignalCTSSupported|KCapsSignalRTSSupported))
236 test.Printf(_L("WARNING - RTS/CTS not supported on this platform\r\n"));
240 TUint signals=0xffffffff;
241 theSerialPort->SetSignals(0,KSignalRTS); // Clear RTS
243 test.Next(_L("Initial notifier"));
244 theSerialPort->NotifySignalChange(notifStatus,signals);
245 User::WaitForRequest(notifStatus);
246 test(notifStatus==KErrNone); // goes off immediately the first time
247 test.Printf(_L("Signals %08x\n"),signals);
248 test((signals&(KSignalRTS|KSignalCTS))==0);
250 // Test with no signal mask set
255 // test.Next(_L(" CTS(set) notify without mask set"));
256 // TestNotifySignalChange(KSignalRTS,ESetOutSignal,KSignalCTS,EExpectNotify,ENotifyOnAnyChange);
257 // (CF) Note: This test presents some problems: we specify notification on any signal but the test only
258 // passes if the input signal specified (CTS) has changed. The test code makes a request for
259 // notification on any signal (iSignalMask=0x3f) and THEN changes an output signal (RTS) that's
260 // wired to the input signal specified (CTS). But changing an output signal launches the DFC
261 // to complete the notification request reporting a change on the output signal NOT the input
262 // signal. The only reason most platforms pass this test is because, on them, input signal changes
263 // trigger interrupts: due to the loopback between output and input signals, when the output
264 // signal changes so does the input signal and that triggers an interrupt which also launches
265 // a DFC to complete the notification request reporting a change on the input signal.
266 // The interrupt is serviced before the output signal notification DFC is scheduled and
267 // the notification request is completed with the input signal change.
268 // On Assabet Modem control signals are polled instead of generating interrupts (Intel's design
269 // flaw) and therefore the output signal change will complete the notification (in error) before
270 // the input signal change is notified.
272 test.Next(_L(" RTS(set) notify without mask set"));
273 TestNotifySignalChange(KSignalRTS,ESetOutSignal,KSignalRTS,EExpectNotify,ENotifyOnAnyChange);
274 test.Next(_L(" RTS(clear) notify without mask set"));
275 TestNotifySignalChange(KSignalRTS,EClearOutSignal,KSignalRTS,EExpectNotify,ENotifyOnAnyChange);
279 test.Next(_L(" CTS(set) notify without mask set"));
280 TestNotifySignalChange(KSignalRTS,ESetOutSignal,KSignalCTS,EExpectNotify,ENotifyOnAnyChange);
281 test.Next(_L(" CTS(clear) notify without mask set"));
282 TestNotifySignalChange(KSignalRTS,EClearOutSignal,KSignalCTS,EExpectNotify,ENotifyOnAnyChange);
285 // Test notification doesn't happen with signal mask set to some other signal
286 test.Next(_L(" No CTS(set) notify with mask set to other signal"));
287 TestNotifySignalChange(KSignalRTS,ESetOutSignal,KSignalDSR,EExpectTimeout,ENotifyOnInSigOnly);
288 TestNotifySignalChange(KSignalRTS,ESetOutSignal,KSignalCTS,EExpectNotify,ENotifyOnInSigOnly);
290 // Test notification happens with mask set to this signal
291 test.Next(_L(" CTS(clear) notify with mask set"));
292 TestNotifySignalChange(KSignalRTS,EClearOutSignal,KSignalCTS,EExpectNotify,ENotifyOnInSigOnly);
293 test.Next(_L(" CTS(set) notify with mask set"));
294 TestNotifySignalChange(KSignalRTS,ESetOutSignal,KSignalCTS,EExpectNotify,ENotifyOnInSigOnly);
297 if ((theCaps.iSignals&(KCapsSignalDSRSupported|KCapsSignalDTRSupported))!=(KCapsSignalDSRSupported|KCapsSignalDTRSupported))
298 test.Printf(_L("WARNING - DTR/DSR not supported on this platform\r\n"));
301 theSerialPort->SetSignals(0,KSignalDTR); // Clear DTR
304 // Test with no signal mask set
308 // (CF) See note above
309 test.Next(_L(" DTR(set) notify without mask set"));
310 TestNotifySignalChange(KSignalDTR,ESetOutSignal,KSignalDTR,EExpectNotify,ENotifyOnAnyChange);
311 test.Next(_L(" DTR(clear) notify without mask set"));
312 TestNotifySignalChange(KSignalDTR,EClearOutSignal,KSignalDTR,EExpectNotify,ENotifyOnAnyChange);
316 test.Next(_L(" DSR(set) notify without mask set"));
317 TestNotifySignalChange(KSignalDTR,ESetOutSignal,KSignalDSR,EExpectNotify,ENotifyOnAnyChange);
318 test.Next(_L(" DSR(clear) notify without mask set"));
319 TestNotifySignalChange(KSignalDTR,EClearOutSignal,KSignalDSR,EExpectNotify,ENotifyOnAnyChange);
322 // Test notification happens with mask set to this signal
323 test.Next(_L(" DSR(set) notify with mask set"));
324 TestNotifySignalChange(KSignalDTR,ESetOutSignal,KSignalDSR,EExpectNotify,ENotifyOnInSigOnly);
325 test.Next(_L(" DSR(clear) notify with mask set"));
326 TestNotifySignalChange(KSignalDTR,EClearOutSignal,KSignalDSR,EExpectNotify,ENotifyOnInSigOnly);
329 if (mid==HAL::EMachineUid_Series5mx ||
330 (theCaps.iSignals&(KCapsSignalDCDSupported|KCapsSignalDTRSupported))!=(KCapsSignalDCDSupported|KCapsSignalDTRSupported))
331 test.Printf(_L("WARNING - DTR/DCD not supported on this platform\r\n"));
334 // Test with no signal mask set
338 // (CF) See note above
339 test.Next(_L(" DTR(set) notify without mask set"));
340 TestNotifySignalChange(KSignalDTR,ESetOutSignal,KSignalDTR,EExpectNotify,ENotifyOnAnyChange);
341 test.Next(_L(" DTR(clear) notify without mask set"));
342 TestNotifySignalChange(KSignalDTR,EClearOutSignal,KSignalDTR,EExpectNotify,ENotifyOnAnyChange);
346 test.Next(_L(" DCD(set) notify without mask set"));
347 TestNotifySignalChange(KSignalDTR,ESetOutSignal,KSignalDCD,EExpectNotify,ENotifyOnAnyChange);
348 test.Next(_L(" DCD(clear) notify without mask set"));
349 TestNotifySignalChange(KSignalDTR,EClearOutSignal,KSignalDCD,EExpectNotify,ENotifyOnAnyChange);
353 // Test notification happens with mask set to this signal
354 test.Next(_L(" DCD(set) notify with mask set"));
355 TestNotifySignalChange(KSignalDTR,ESetOutSignal,KSignalDCD,EExpectNotify,ENotifyOnInSigOnly);
356 test.Next(_L(" DCD(clear) notify with mask set"));
357 TestNotifySignalChange(KSignalDTR,EClearOutSignal,KSignalDCD,EExpectNotify,ENotifyOnInSigOnly);
361 test.Next(_L("Testing NotifyReceiveDataAvailable()"));
362 if (!(theCaps.iNotificationCaps & KNotifyDataAvailableSupported))
363 test.Printf(_L("Data available notification not supported on this platform\r\n"));
366 TBuf8<0x10> buf1(0x10), buf2(0x10);
367 for (TInt i=0;i<0x10;i++) buf1[i]=(TUint8)i;
369 theSerialPort->ResetBuffers();
370 theSerialPort->NotifyReceiveDataAvailable(notifStatus);
371 CHECK(notifStatus.Int(),KRequestPending);
372 const TUint KTimeOut=2000000;
373 tim.After(timeStatus,KTimeOut);
374 CHECK(timeStatus.Int(),KRequestPending);
375 theSerialPort->WriteS(buf1);
376 User::WaitForRequest(notifStatus,timeStatus);
377 if (notifStatus==KErrNone)
380 CHECK(notifStatus.Int(),KErrNone);
384 test.Printf(_L("Timed Out!\n\r"));
385 theSerialPort->NotifyReceiveDataAvailableCancel();
389 CHECK(theSerialPort->QueryReceiveBuffer(),0x10);
391 theSerialPort->Read(notifStatus,buf2,0x10);
392 User::WaitForRequest(notifStatus);
393 test(buf1.Compare(buf2)==0);
396 theSerialPort->Close();
397 test.Printf(_L("<<Hit a key to end>>\r\n"));