1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/TSTLIB/tirping.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,125 @@
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 +
1.31 +
1.32 +
1.33 +int port;
1.34 +
1.35 +/**
1.36 +@SYMTestCaseID SYSLIB-STDLIB-CT-1105
1.37 +@SYMTestCaseDesc Tests for serial port
1.38 +@SYMTestPriority High
1.39 +@SYMTestActions Tests for notification support
1.40 +@SYMTestExpectedResults Test must not fail
1.41 +@SYMREQ REQ0000
1.42 +*/
1.43 +void Watcher(void)
1.44 + {
1.45 + int res;
1.46 + int notify[2] = {0,0};
1.47 + int supported = 0;
1.48 +
1.49 +
1.50 + res = ioctl(port, COMMIOCTL_NOTIFYSUPPORTED, &supported);
1.51 + printf("\nsupported notifies are %08lx\n",supported);
1.52 + while (-1 != res)
1.53 + {
1.54 + notify[0] = supported;
1.55 + res = ioctl(port, COMMIOCTL_NOTIFY, ¬ify[0]);
1.56 + printf("\n**Notify** res = %d params %d, %d, errno %d\n",res, notify[0], notify[1],errno);
1.57 + }
1.58 +
1.59 + }
1.60 +
1.61 +/**
1.62 +@SYMTestCaseID SYSLIB-STDLIB-CT-1106
1.63 +@SYMTestCaseDesc Tests for communication over the port
1.64 +@SYMTestPriority High
1.65 +@SYMTestActions Tests for reading and writing to a port back
1.66 +@SYMTestExpectedResults Test must not fail
1.67 +@SYMREQ REQ0000
1.68 +*/
1.69 +void ping(void)
1.70 + {
1.71 + char buf1[50];
1.72 + char buf2[50];
1.73 + char* rptr =buf1;
1.74 + char* wptr = buf2;
1.75 + char * tptr;
1.76 +
1.77 +
1.78 + int err = 0;
1.79 + int timeout = 5000; //5 seconds
1.80 + int threshold = -1;
1.81 +
1.82 + printf("port is %d\n",port);
1.83 + ioctl(port, COMMIOCTL_SETREADTHRESHOLD, &threshold);
1.84 + ioctl(port, COMMIOCTL_SETREADTIMEOUT, &timeout);
1.85 +
1.86 + strcpy(wptr, "ping");
1.87 + while (err >= 0)
1.88 + {
1.89 + err = read(port,rptr, 50);
1.90 + if (err >= 0)
1.91 + {
1.92 + rptr[err] = 0;
1.93 + err = write(port, wptr, strlen(wptr));
1.94 +// printf("read %s, written %s\n", rptr, wptr);
1.95 + tptr = wptr;
1.96 + wptr = rptr;
1.97 + rptr = tptr;
1.98 +
1.99 + }
1.100 +
1.101 + }
1.102 + }
1.103 +
1.104 +
1.105 +int main(void)
1.106 + {
1.107 + void* t1;
1.108 + void* t2;
1.109 +
1.110 + start_posix_server(); /* calls SpawnPosixServer from C++ code */
1.111 +
1.112 + port = open("IRCOM1:", 0);
1.113 +
1.114 + t1 = create_thread(Watcher, "watcher");
1.115 + t2 = create_thread(ping, "ping");
1.116 +
1.117 + start_thread(t1);
1.118 + start_thread(t2);
1.119 +
1.120 + wait_for_thread(t2);
1.121 +
1.122 + close(port);
1.123 +
1.124 + wait_for_thread(t1);
1.125 +
1.126 + return 0;
1.127 + }
1.128 +