|
1 /* |
|
2 * Copyright (c) 1997-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <stdlib.h> /* definition of exit() */ |
|
20 #include <stdio.h> |
|
21 #include <errno.h> |
|
22 #include <string.h> |
|
23 #include <sys/unistd.h> |
|
24 #include <sys/ioctl.h> |
|
25 #include "CTEST.H" |
|
26 |
|
27 int port; |
|
28 |
|
29 /** |
|
30 @SYMTestCaseID SYSLIB-STDLIB-CT-1107 |
|
31 @SYMTestCaseDesc Tests for serial port |
|
32 @SYMTestPriority High |
|
33 @SYMTestActions Tests for notification support |
|
34 @SYMTestExpectedResults Test must not fail |
|
35 @SYMREQ REQ0000 |
|
36 */ |
|
37 void Watcher(void) |
|
38 { |
|
39 int res; |
|
40 int notify[2] = {0,0}; |
|
41 int supported = 0; |
|
42 |
|
43 |
|
44 res = ioctl(port, COMMIOCTL_NOTIFYSUPPORTED, &supported); |
|
45 printf("\nsupported notifies are %08lx\n",supported); |
|
46 while (-1 != res) |
|
47 { |
|
48 notify[0] = supported; |
|
49 res = ioctl(port, COMMIOCTL_NOTIFY, ¬ify[0]); |
|
50 printf("\n**Notify** res = %d params %d, %d, errno %d\n",res, notify[0], notify[1],errno); |
|
51 } |
|
52 |
|
53 } |
|
54 |
|
55 /** |
|
56 @SYMTestCaseID SYSLIB-STDLIB-CT-1108 |
|
57 @SYMTestCaseDesc Tests for serial port |
|
58 @SYMTestPriority High |
|
59 @SYMTestActions Tests for writing and reading to a port |
|
60 @SYMTestExpectedResults Test must not fail |
|
61 @SYMREQ REQ0000 |
|
62 */ |
|
63 void pong(void) |
|
64 { |
|
65 char buf1[50]; |
|
66 char buf2[50]; |
|
67 char * rptr; |
|
68 char * wptr; |
|
69 char * tptr; |
|
70 |
|
71 int err = 0; |
|
72 int timeout = 5000; //5 seconds |
|
73 int threshold = -1; |
|
74 |
|
75 rptr = buf1; |
|
76 wptr = buf2; |
|
77 |
|
78 printf("port is %d\n",port); |
|
79 ioctl(port, COMMIOCTL_SETREADTHRESHOLD, &threshold); |
|
80 ioctl(port, COMMIOCTL_SETREADTIMEOUT, &timeout); |
|
81 |
|
82 strcpy(buf2,"pong"); |
|
83 while (err >= 0) |
|
84 { |
|
85 err = write(port, wptr, strlen(wptr)); |
|
86 if (err >= 0) |
|
87 { |
|
88 err = read(port,rptr, 50); |
|
89 if (err >= 0) |
|
90 { |
|
91 rptr[err] = 0; |
|
92 // printf ("read %s, written %s\n",rptr, wptr); |
|
93 tptr = rptr; |
|
94 rptr = wptr; |
|
95 wptr = tptr; |
|
96 } |
|
97 } |
|
98 } |
|
99 |
|
100 } |
|
101 |
|
102 |
|
103 int main(void) |
|
104 { |
|
105 void* t1; |
|
106 void* t2; |
|
107 |
|
108 start_posix_server(); /* calls SpawnPosixServer from C++ code */ |
|
109 |
|
110 port = open("IRCOM1:", 0); |
|
111 |
|
112 t1 = create_thread(Watcher, "watcher"); |
|
113 t2 = create_thread(pong, "pong"); |
|
114 |
|
115 start_thread(t1); |
|
116 start_thread(t2); |
|
117 |
|
118 wait_for_thread(t2); |
|
119 |
|
120 close(port); |
|
121 |
|
122 wait_for_thread(t1); |
|
123 |
|
124 return 0; |
|
125 } |
|
126 |