sl@0: /* sl@0: * Copyright (c) 1997-2007 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: #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: sl@0: sl@0: int port; sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STDLIB-CT-1105 sl@0: @SYMTestCaseDesc Tests for serial port sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for notification support sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void Watcher(void) sl@0: { sl@0: int res; sl@0: int notify[2] = {0,0}; sl@0: int supported = 0; sl@0: sl@0: sl@0: res = ioctl(port, COMMIOCTL_NOTIFYSUPPORTED, &supported); sl@0: printf("\nsupported notifies are %08lx\n",supported); sl@0: while (-1 != res) sl@0: { sl@0: notify[0] = supported; sl@0: res = ioctl(port, COMMIOCTL_NOTIFY, ¬ify[0]); sl@0: printf("\n**Notify** res = %d params %d, %d, errno %d\n",res, notify[0], notify[1],errno); sl@0: } sl@0: sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STDLIB-CT-1106 sl@0: @SYMTestCaseDesc Tests for communication over the port sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for reading and writing to a port back sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void ping(void) sl@0: { sl@0: char buf1[50]; sl@0: char buf2[50]; sl@0: char* rptr =buf1; sl@0: char* wptr = buf2; sl@0: char * tptr; sl@0: sl@0: sl@0: int err = 0; sl@0: int timeout = 5000; //5 seconds sl@0: int threshold = -1; sl@0: sl@0: printf("port is %d\n",port); sl@0: ioctl(port, COMMIOCTL_SETREADTHRESHOLD, &threshold); sl@0: ioctl(port, COMMIOCTL_SETREADTIMEOUT, &timeout); sl@0: sl@0: strcpy(wptr, "ping"); sl@0: while (err >= 0) sl@0: { sl@0: err = read(port,rptr, 50); sl@0: if (err >= 0) sl@0: { sl@0: rptr[err] = 0; sl@0: err = write(port, wptr, strlen(wptr)); sl@0: // printf("read %s, written %s\n", rptr, wptr); sl@0: tptr = wptr; sl@0: wptr = rptr; sl@0: rptr = tptr; sl@0: sl@0: } sl@0: sl@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: port = open("IRCOM1:", 0); sl@0: sl@0: t1 = create_thread(Watcher, "watcher"); sl@0: t2 = create_thread(ping, "ping"); sl@0: sl@0: start_thread(t1); sl@0: start_thread(t2); sl@0: sl@0: wait_for_thread(t2); sl@0: sl@0: close(port); sl@0: sl@0: wait_for_thread(t1); sl@0: sl@0: return 0; sl@0: } sl@0: