1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/TSTLIB/tser3.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,211 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <estlib.h>
1.20 +#include <stdlib.h> /* definition of exit() */
1.21 +#include <stdio.h>
1.22 +#include <errno.h>
1.23 +#include <string.h>
1.24 +#include <sys/unistd.h>
1.25 +#include <sys/ioctl.h>
1.26 +#include "CTEST.H"
1.27 +
1.28 +#ifdef __cplusplus
1.29 +extern "C" {
1.30 +#endif
1.31 +
1.32 +
1.33 +#define SIZE 10000
1.34 +
1.35 +int ReaderPort;
1.36 +int WriterPort;
1.37 +
1.38 +/**
1.39 +@SYMTestCaseID SYSLIB-STDLIB-CT-1102
1.40 +@SYMTestCaseDesc Tests for serial port
1.41 +@SYMTestPriority High
1.42 +@SYMTestActions Tests by writing a string buffer to the port
1.43 +@SYMTestExpectedResults Test must not fail
1.44 +@SYMREQ REQ0000
1.45 +*/
1.46 +void Writer()
1.47 + {
1.48 + char *buffer;
1.49 +
1.50 + buffer = (char*)malloc(SIZE);
1.51 + memset(buffer, '*', SIZE);
1.52 +
1.53 + printf("\nbig write\n");
1.54 + (void)write(WriterPort, buffer, SIZE);
1.55 + (void)errno;
1.56 + printf("\n>>Writer<<small read\n");
1.57 + read(WriterPort,buffer,1);
1.58 + printf("\nbig write\n");
1.59 + write(WriterPort, buffer, SIZE);
1.60 + printf("\n>>Writer<<small read\n");
1.61 + read(WriterPort,buffer,1);
1.62 +
1.63 + }
1.64 +
1.65 +/**
1.66 +@SYMTestCaseID SYSLIB-STDLIB-CT-1103
1.67 +@SYMTestCaseDesc Tests for serial port
1.68 +@SYMTestPriority High
1.69 +@SYMTestActions Notifies on a read operation
1.70 +@SYMTestExpectedResults Test must not fail
1.71 +@SYMREQ REQ0000
1.72 +*/
1.73 +void Watcher()
1.74 + {
1.75 + int res=0;
1.76 + int notify[2] = {0,0};
1.77 + int supported = 0;
1.78 +
1.79 +
1.80 + res = ioctl(ReaderPort, COMMIOCTL_NOTIFYSUPPORTED, &supported);
1.81 + printf("\nsupported notifies are %08x\n",supported);
1.82 + while (-1 != res)
1.83 + {
1.84 + notify[0] = supported;
1.85 + printf("asking for %08x\n",notify[0]);
1.86 + res = ioctl(ReaderPort, COMMIOCTL_NOTIFY, ¬ify[0]);
1.87 + printf("\n**Notify** res = %d params %d, %d, errno %d\n",res, notify[0], notify[1],errno);
1.88 + }
1.89 +
1.90 + }
1.91 +
1.92 +/**
1.93 +@SYMTestCaseID SYSLIB-STDLIB-CT-1104
1.94 +@SYMTestCaseDesc Tests for serial port
1.95 +@SYMTestPriority High
1.96 +@SYMTestActions Reads to buffer from serial port,test for failure conditions
1.97 +@SYMTestExpectedResults Test must not fail
1.98 +@SYMREQ REQ0000
1.99 +*/
1.100 +void Reader()
1.101 + {
1.102 + int res;
1.103 + char *buffer, *p;
1.104 + int x;
1.105 +
1.106 +
1.107 +
1.108 + buffer = (char*)malloc(SIZE*2);
1.109 +
1.110 + res = 0;
1.111 + p = buffer;
1.112 +
1.113 +
1.114 + x = 5000;
1.115 + res = ioctl(ReaderPort, COMMIOCTL_SETREADTIMEOUT, &x);
1.116 +
1.117 + for(x = 0;;x++)
1.118 + {
1.119 + res = read(ReaderPort, p, 100);
1.120 + if (res > 0)
1.121 + {
1.122 + putchar('.');
1.123 + p += res;
1.124 + }
1.125 + else
1.126 + {
1.127 + printf("\nread failed with errno %d\n",errno);
1.128 + break;
1.129 + }
1.130 + }
1.131 +
1.132 + printf("\n>>Reader<<small write\n");
1.133 + res = write(ReaderPort, buffer ,1);
1.134 +
1.135 + printf("\n>>Reader<<set threshold\n");
1.136 + x = 100;
1.137 + res = ioctl(ReaderPort, COMMIOCTL_SETREADTHRESHOLD, &x);
1.138 + p = buffer;
1.139 +
1.140 + printf("\nAnd again with a threshold of 100\n");
1.141 +
1.142 + for(x = 0;;x++)
1.143 + {
1.144 + res = read(ReaderPort, p, 100);
1.145 + if (res > 0)
1.146 + {
1.147 + putchar('.');
1.148 + p += res;
1.149 + }
1.150 + else
1.151 + {
1.152 + printf("\nread failed with errno %d\n",errno);
1.153 + break;
1.154 + }
1.155 + }
1.156 +
1.157 + printf("\n>>Reader<<Small write\n");
1.158 + write(ReaderPort, buffer ,1);
1.159 +
1.160 +
1.161 + }
1.162 +
1.163 +#ifdef __cplusplus
1.164 +}
1.165 +#endif
1.166 +
1.167 +int main(int, char**)
1.168 + {
1.169 + void* t1;
1.170 + void* t2;
1.171 + void* t3;
1.172 +
1.173 + SerialConfig sc;
1.174 +
1.175 + start_posix_server(); /* calls SpawnPosixServer from C++ code */
1.176 +
1.177 + WriterPort = open("COM1:",0);
1.178 + if (-1 == WriterPort)
1.179 + exit(-1);
1.180 + (void)ioctl(WriterPort, COMMIOCTL_GETCONFIG, &sc);
1.181 + sc.iHandshake = 0;
1.182 + sc.iRate = Bps115200;
1.183 + sc.iParity = ParityNone;
1.184 + (void)ioctl(WriterPort, COMMIOCTL_SETCONFIG, &sc);
1.185 +
1.186 + ReaderPort = open("COM2:",0);
1.187 + if (-1 == ReaderPort)
1.188 + exit(-2);
1.189 + (void)ioctl(ReaderPort, COMMIOCTL_GETCONFIG, &sc);
1.190 + sc.iHandshake = 0;
1.191 + sc.iRate = Bps115200;
1.192 + sc.iParity = ParityNone;
1.193 + (void)ioctl(ReaderPort, COMMIOCTL_SETCONFIG, &sc);
1.194 +
1.195 + t3 = create_thread(Watcher, "watcher1");
1.196 + t1 = create_thread(Reader, "reader");
1.197 + t2 = create_thread(Writer, "writer");
1.198 +
1.199 + start_thread(t3);
1.200 + start_thread(t2);
1.201 + start_thread(t1);
1.202 +
1.203 + (void)wait_for_thread(t1);
1.204 + (void)wait_for_thread(t2);
1.205 +
1.206 + close(WriterPort);
1.207 + close(ReaderPort);
1.208 + (void)wait_for_thread(t3);
1.209 + printf("\nPress a key\n");
1.210 + getchar();
1.211 + return 0;
1.212 + }
1.213 +
1.214 +