1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/TSTLIB/tirpong.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,126 @@
1.4 +/*
1.5 +* Copyright (c) 1997-2007 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include <stdlib.h> /* definition of exit() */
1.23 +#include <stdio.h>
1.24 +#include <errno.h>
1.25 +#include <string.h>
1.26 +#include <sys/unistd.h>
1.27 +#include <sys/ioctl.h>
1.28 +#include "CTEST.H"
1.29 +
1.30 +int port;
1.31 +
1.32 +/**
1.33 +@SYMTestCaseID SYSLIB-STDLIB-CT-1107
1.34 +@SYMTestCaseDesc Tests for serial port
1.35 +@SYMTestPriority High
1.36 +@SYMTestActions Tests for notification support
1.37 +@SYMTestExpectedResults Test must not fail
1.38 +@SYMREQ REQ0000
1.39 +*/
1.40 +void Watcher(void)
1.41 + {
1.42 + int res;
1.43 + int notify[2] = {0,0};
1.44 + int supported = 0;
1.45 +
1.46 +
1.47 + res = ioctl(port, COMMIOCTL_NOTIFYSUPPORTED, &supported);
1.48 + printf("\nsupported notifies are %08lx\n",supported);
1.49 + while (-1 != res)
1.50 + {
1.51 + notify[0] = supported;
1.52 + res = ioctl(port, COMMIOCTL_NOTIFY, ¬ify[0]);
1.53 + printf("\n**Notify** res = %d params %d, %d, errno %d\n",res, notify[0], notify[1],errno);
1.54 + }
1.55 +
1.56 + }
1.57 +
1.58 +/**
1.59 +@SYMTestCaseID SYSLIB-STDLIB-CT-1108
1.60 +@SYMTestCaseDesc Tests for serial port
1.61 +@SYMTestPriority High
1.62 +@SYMTestActions Tests for writing and reading to a port
1.63 +@SYMTestExpectedResults Test must not fail
1.64 +@SYMREQ REQ0000
1.65 +*/
1.66 +void pong(void)
1.67 + {
1.68 + char buf1[50];
1.69 + char buf2[50];
1.70 + char * rptr;
1.71 + char * wptr;
1.72 + char * tptr;
1.73 +
1.74 + int err = 0;
1.75 + int timeout = 5000; //5 seconds
1.76 + int threshold = -1;
1.77 +
1.78 + rptr = buf1;
1.79 + wptr = buf2;
1.80 +
1.81 + printf("port is %d\n",port);
1.82 + ioctl(port, COMMIOCTL_SETREADTHRESHOLD, &threshold);
1.83 + ioctl(port, COMMIOCTL_SETREADTIMEOUT, &timeout);
1.84 +
1.85 + strcpy(buf2,"pong");
1.86 + while (err >= 0)
1.87 + {
1.88 + err = write(port, wptr, strlen(wptr));
1.89 + if (err >= 0)
1.90 + {
1.91 + err = read(port,rptr, 50);
1.92 + if (err >= 0)
1.93 + {
1.94 + rptr[err] = 0;
1.95 +// printf ("read %s, written %s\n",rptr, wptr);
1.96 + tptr = rptr;
1.97 + rptr = wptr;
1.98 + wptr = tptr;
1.99 + }
1.100 + }
1.101 + }
1.102 +
1.103 + }
1.104 +
1.105 +
1.106 +int main(void)
1.107 + {
1.108 + void* t1;
1.109 + void* t2;
1.110 +
1.111 + start_posix_server(); /* calls SpawnPosixServer from C++ code */
1.112 +
1.113 + port = open("IRCOM1:", 0);
1.114 +
1.115 + t1 = create_thread(Watcher, "watcher");
1.116 + t2 = create_thread(pong, "pong");
1.117 +
1.118 + start_thread(t1);
1.119 + start_thread(t2);
1.120 +
1.121 + wait_for_thread(t2);
1.122 +
1.123 + close(port);
1.124 +
1.125 + wait_for_thread(t1);
1.126 +
1.127 + return 0;
1.128 + }
1.129 +