1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/TSTLIB/tsersig.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,126 @@
1.4 +/*
1.5 +* Copyright (c) 1997-2009 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 +
1.23 +#include <stdlib.h> /* definition of exit() */
1.24 +#include <stdio.h>
1.25 +#include <errno.h>
1.26 +#include <string.h>
1.27 +#include <sys/unistd.h>
1.28 +#include <sys/ioctl.h>
1.29 +#include "CTEST.H"
1.30 +
1.31 +
1.32 +int GlobalPort;
1.33 +
1.34 +/**
1.35 +@SYMTestCaseID SYSLIB-STDLIB-CT-1109
1.36 +@SYMTestCaseDesc Tests for serial port
1.37 +@SYMTestPriority High
1.38 +@SYMTestActions Open and configures the serial ports
1.39 +@SYMTestExpectedResults Test must not fail
1.40 +@SYMREQ REQ0000
1.41 +*/
1.42 +void OpenAndConfigure(void)
1.43 + {
1.44 + SerialConfig sc;
1.45 +
1.46 + GlobalPort = open("COM1:",0);
1.47 + (void)ioctl(GlobalPort, COMMIOCTL_GETCONFIG, &sc);
1.48 + sc.iRate = Bps57600;
1.49 + sc.iParity = ParityNone;
1.50 + (void)ioctl(GlobalPort, COMMIOCTL_SETCONFIG, &sc);
1.51 + }
1.52 +
1.53 +/**
1.54 +@SYMTestCaseID SYSLIB-STDLIB-CT-1110
1.55 +@SYMTestCaseDesc Tests for serial port
1.56 +@SYMTestPriority High
1.57 +@SYMTestActions Notifies a thread for events on port
1.58 +@SYMTestExpectedResults Test must not fail
1.59 +@SYMREQ REQ0000
1.60 +*/
1.61 +
1.62 +void WaitForNotifyThread(void)
1.63 + {
1.64 + int val[2];
1.65 + int ret = 0;
1.66 + int signals = 0;
1.67 +
1.68 +
1.69 + while (ret != -1)
1.70 + {
1.71 + val[0] = 0;
1.72 + val[1] = -1;
1.73 + ret = ioctl(GlobalPort, COMMIOCTL_NOTIFYSUPPORTED, &signals);
1.74 + val[0] = KNotifyDataAvailable;
1.75 + ret = ioctl(GlobalPort, COMMIOCTL_NOTIFY, &val[0]);
1.76 + if ((ret != -1) || (val[0] != KNotifyDataAvailable))
1.77 + printf("NotifyThread returned %d, val[0] %d when checking data available\n", ret, val[0]);
1.78 +
1.79 +
1.80 + val[0] = signals & ~KNotifyDataAvailable; //no data avail as it returns an error
1.81 + ret = ioctl(GlobalPort, COMMIOCTL_NOTIFY, &val[0]);
1.82 + printf("NotifyThread ret = %d, val[0] is %d, val[1] is %d, errno is %d\n", ret, val[0], val[1], errno);
1.83 +
1.84 + }
1.85 + }
1.86 +
1.87 +/**
1.88 +@SYMTestCaseID SYSLIB-STDLIB-CT-1111
1.89 +@SYMTestCaseDesc Tests for serial port
1.90 +@SYMTestPriority High
1.91 +@SYMTestActions Keep reading infinitely from the port
1.92 +@SYMTestExpectedResults Test must not fail
1.93 +@SYMREQ REQ0000
1.94 +*/
1.95 +void readloop(void)
1.96 + {
1.97 + char buf[100];
1.98 + int readcount = 10;
1.99 +
1.100 + while (readcount-- > 0)
1.101 + {
1.102 + read(GlobalPort, buf, 100);
1.103 + printf("ReadThread got %x\n", buf[0]);
1.104 + }
1.105 + }
1.106 +
1.107 +int main(void)
1.108 + {
1.109 + void* t1;
1.110 + void*t2;
1.111 +
1.112 + start_posix_server(); /* calls SpawnPosixServer from C++ code */
1.113 +
1.114 + OpenAndConfigure();
1.115 +
1.116 +
1.117 + t1 = create_thread(WaitForNotifyThread, "notify");
1.118 + t2 = create_thread(readloop, "readloop");
1.119 +
1.120 + start_thread(t1);
1.121 + start_thread(t2);
1.122 +
1.123 + (void)wait_for_thread(t2);
1.124 + close(GlobalPort); //closing the port will force a notify
1.125 + (void)wait_for_thread(t1);
1.126 +
1.127 + return 0;
1.128 + }
1.129 +