Update contrib.
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
20 #include <stdlib.h> /* definition of exit() */
24 #include <sys/unistd.h>
25 #include <sys/ioctl.h>
35 @SYMTestCaseID SYSLIB-STDLIB-CT-1099
36 @SYMTestCaseDesc Tests for serial port
38 @SYMTestActions Tests for serial port,and under posix server
39 @SYMTestExpectedResults Test must not fail
42 void DoTests(char*port)
52 SerialConfig newconfig;
57 memset(&newconfig, 0, sizeof(newconfig));
59 test_Next("Open port");
61 port1 = open(port, 0); //exclusive
65 //this one should fail
66 port2 = open(port, 0);
67 test_errno(-1==port2, EACCES);
70 test_Next("set signals");
71 //play with the signals
72 ret = ioctl(port1, COMMIOCTL_SETSIGNALS, &sigs[0]);
75 test_Next("get signals");
76 ret = ioctl(port1, COMMIOCTL_GETSIGNALS, &sig);
79 //try changing the settings
80 test_Next("port configuration");
81 ret = ioctl(port1, COMMIOCTL_GETCONFIG, &config);
83 config.iRate = Bps115200;
84 config.iDataBits = DBits6;
85 config.iStopBits=Stop2;
86 config.iParity=ParityOdd;
88 config.iParityError=ConfigParityErrorFail;
90 config.iSpecialRate=0;
91 config.iTerminatorCount=0;
92 config.iTerminator[0]=0;
95 config.iParityErrorChar=3;
96 config.iSIREnable=SIRDisable;
97 config.iSIRSettings=0;
99 ret = ioctl(port1, COMMIOCTL_SETCONFIG, &config);
100 ret = ioctl(port1, COMMIOCTL_GETCONFIG, &newconfig);
102 test(config.iRate == newconfig.iRate);
103 test(config.iDataBits==newconfig.iDataBits);
104 test(config.iStopBits==newconfig.iStopBits);
105 test(config.iParity==newconfig.iParity);
106 test(config.iHandshake==newconfig.iHandshake);
107 test(config.iParityError==newconfig.iParityError);
108 test(config.iFifo==newconfig.iFifo);
109 test(config.iSpecialRate==newconfig.iSpecialRate);
110 test(config.iTerminatorCount==newconfig.iTerminatorCount);
111 test(config.iTerminator[0]==newconfig.iTerminator[0]);
112 test(config.iXonChar==newconfig.iXonChar);
113 test(config.iXoffChar==newconfig.iXoffChar);
114 test(config.iParityErrorChar==newconfig.iParityErrorChar);
115 test(config.iSIREnable==newconfig.iSIREnable);
116 test(config.iSIRSettings==newconfig.iSIRSettings);
118 test_Next("Buffer lengths");
120 ret = ioctl(port1, COMMIOCTL_GETBUFFERLENGTH, &int1);
125 ret = ioctl(port1, COMMIOCTL_SETBUFFERLENGTH, &int1);
129 ret = ioctl(port1, COMMIOCTL_GETBUFFERLENGTH, &int2);
135 ret = ioctl(port1, COMMIOCTL_SETBUFFERLENGTH, &int1);
138 ret = ioctl(port1, COMMIOCTL_GETBUFFERLENGTH, &int1);
140 test(int1 == int2); //shoudn't have changed, val too big.
145 ret = ioctl(port1, COMMIOCTL_BREAK, &sig);
146 //break isn't supported
147 test_errno(-1==ret, ENOSYS);
150 test_Next("read timeout");
152 ret = ioctl(port1, COMMIOCTL_SETREADTIMEOUT, &int1);
156 ret = ioctl(port1, COMMIOCTL_GETREADTIMEOUT, &int2);
161 test_Next("read threshold");
163 ret = ioctl(port1, COMMIOCTL_SETREADTHRESHOLD, &int1);
167 ret = ioctl(port1, COMMIOCTL_GETREADTHRESHOLD, &int2);
174 test_Next("test notifications supported");
175 ret = ioctl(port1, COMMIOCTL_NOTIFYSUPPORTED, &int1);
176 test((int1 & (KNotifyFramingError|KNotifyOverrunError|KNotifyParityError)) == (KNotifyFramingError|KNotifyOverrunError|KNotifyParityError));
177 printf("Notifications supported are %08x\n",int1);
179 test_Next("Test read timeout with a threshold");
181 ret = ioctl(port1, COMMIOCTL_SETREADTIMEOUT, &int2);
185 ret = ioctl(port1, COMMIOCTL_SETREADTHRESHOLD, &int1);
188 ret = read(port1, buffer, size);
189 test_errno(-1==ret, ETIMEDOUT);
191 //no threshold, but with a 1 second timeout
192 test_Next("no threshold with timeout");
194 ret = ioctl(port1, COMMIOCTL_SETREADTIMEOUT, &int2);
198 ret = ioctl(port1, COMMIOCTL_SETREADTHRESHOLD, &int1);
201 ret = read(port1, buffer, size);
202 test_errno(-1==ret, ETIMEDOUT);
208 printf("failed to open port %s with errno %d\n", port,errno);
213 void DoTestsSerial(void)
233 test_Title("Serial port test1");
234 test_Next("Do tests with local server for COM1:");
236 test_Next("Do tests with local server for COM2:");
238 test_Next("Do tests with local server for COM3:");
240 test_Next("Do tests with local server for COM4:");
244 start_posix_server(); /* calls SpawnPosixServer from C++ code */
247 test_Next("Do tests with posix server for COM1:");
248 client=create_thread(DoTestsSerial, "serial tests");
251 start_thread(client);
252 err=wait_for_thread(client);