sl@0: /* sl@0: * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #include /* definition of exit() */ sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "CTEST.H" sl@0: sl@0: sl@0: int GlobalPort; sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STDLIB-CT-1109 sl@0: @SYMTestCaseDesc Tests for serial port sl@0: @SYMTestPriority High sl@0: @SYMTestActions Open and configures the serial ports sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void OpenAndConfigure(void) sl@0: { sl@0: SerialConfig sc; sl@0: sl@0: GlobalPort = open("COM1:",0); sl@0: (void)ioctl(GlobalPort, COMMIOCTL_GETCONFIG, &sc); sl@0: sc.iRate = Bps57600; sl@0: sc.iParity = ParityNone; sl@0: (void)ioctl(GlobalPort, COMMIOCTL_SETCONFIG, &sc); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STDLIB-CT-1110 sl@0: @SYMTestCaseDesc Tests for serial port sl@0: @SYMTestPriority High sl@0: @SYMTestActions Notifies a thread for events on port sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void WaitForNotifyThread(void) sl@0: { sl@0: int val[2]; sl@0: int ret = 0; sl@0: int signals = 0; sl@0: sl@0: sl@0: while (ret != -1) sl@0: { sl@0: val[0] = 0; sl@0: val[1] = -1; sl@0: ret = ioctl(GlobalPort, COMMIOCTL_NOTIFYSUPPORTED, &signals); sl@0: val[0] = KNotifyDataAvailable; sl@0: ret = ioctl(GlobalPort, COMMIOCTL_NOTIFY, &val[0]); sl@0: if ((ret != -1) || (val[0] != KNotifyDataAvailable)) sl@0: printf("NotifyThread returned %d, val[0] %d when checking data available\n", ret, val[0]); sl@0: sl@0: sl@0: val[0] = signals & ~KNotifyDataAvailable; //no data avail as it returns an error sl@0: ret = ioctl(GlobalPort, COMMIOCTL_NOTIFY, &val[0]); sl@0: printf("NotifyThread ret = %d, val[0] is %d, val[1] is %d, errno is %d\n", ret, val[0], val[1], errno); sl@0: sl@0: } sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STDLIB-CT-1111 sl@0: @SYMTestCaseDesc Tests for serial port sl@0: @SYMTestPriority High sl@0: @SYMTestActions Keep reading infinitely from the port sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void readloop(void) sl@0: { sl@0: char buf[100]; sl@0: int readcount = 10; sl@0: sl@0: while (readcount-- > 0) sl@0: { sl@0: read(GlobalPort, buf, 100); sl@0: printf("ReadThread got %x\n", buf[0]); sl@0: } sl@0: } sl@0: sl@0: int main(void) sl@0: { sl@0: void* t1; sl@0: void*t2; sl@0: sl@0: start_posix_server(); /* calls SpawnPosixServer from C++ code */ sl@0: sl@0: OpenAndConfigure(); sl@0: sl@0: sl@0: t1 = create_thread(WaitForNotifyThread, "notify"); sl@0: t2 = create_thread(readloop, "readloop"); sl@0: sl@0: start_thread(t1); sl@0: start_thread(t2); sl@0: sl@0: (void)wait_for_thread(t2); sl@0: close(GlobalPort); //closing the port will force a notify sl@0: (void)wait_for_thread(t1); sl@0: sl@0: return 0; sl@0: } sl@0: