|
1 /* |
|
2 * Copyright (c) 1997-2009 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 |
|
20 #include <stdlib.h> /* definition of exit() */ |
|
21 #include <stdio.h> |
|
22 #include <errno.h> |
|
23 #include <string.h> |
|
24 #include <sys/unistd.h> |
|
25 #include <sys/ioctl.h> |
|
26 #include "CTEST.H" |
|
27 |
|
28 |
|
29 int GlobalPort; |
|
30 |
|
31 /** |
|
32 @SYMTestCaseID SYSLIB-STDLIB-CT-1109 |
|
33 @SYMTestCaseDesc Tests for serial port |
|
34 @SYMTestPriority High |
|
35 @SYMTestActions Open and configures the serial ports |
|
36 @SYMTestExpectedResults Test must not fail |
|
37 @SYMREQ REQ0000 |
|
38 */ |
|
39 void OpenAndConfigure(void) |
|
40 { |
|
41 SerialConfig sc; |
|
42 |
|
43 GlobalPort = open("COM1:",0); |
|
44 (void)ioctl(GlobalPort, COMMIOCTL_GETCONFIG, &sc); |
|
45 sc.iRate = Bps57600; |
|
46 sc.iParity = ParityNone; |
|
47 (void)ioctl(GlobalPort, COMMIOCTL_SETCONFIG, &sc); |
|
48 } |
|
49 |
|
50 /** |
|
51 @SYMTestCaseID SYSLIB-STDLIB-CT-1110 |
|
52 @SYMTestCaseDesc Tests for serial port |
|
53 @SYMTestPriority High |
|
54 @SYMTestActions Notifies a thread for events on port |
|
55 @SYMTestExpectedResults Test must not fail |
|
56 @SYMREQ REQ0000 |
|
57 */ |
|
58 |
|
59 void WaitForNotifyThread(void) |
|
60 { |
|
61 int val[2]; |
|
62 int ret = 0; |
|
63 int signals = 0; |
|
64 |
|
65 |
|
66 while (ret != -1) |
|
67 { |
|
68 val[0] = 0; |
|
69 val[1] = -1; |
|
70 ret = ioctl(GlobalPort, COMMIOCTL_NOTIFYSUPPORTED, &signals); |
|
71 val[0] = KNotifyDataAvailable; |
|
72 ret = ioctl(GlobalPort, COMMIOCTL_NOTIFY, &val[0]); |
|
73 if ((ret != -1) || (val[0] != KNotifyDataAvailable)) |
|
74 printf("NotifyThread returned %d, val[0] %d when checking data available\n", ret, val[0]); |
|
75 |
|
76 |
|
77 val[0] = signals & ~KNotifyDataAvailable; //no data avail as it returns an error |
|
78 ret = ioctl(GlobalPort, COMMIOCTL_NOTIFY, &val[0]); |
|
79 printf("NotifyThread ret = %d, val[0] is %d, val[1] is %d, errno is %d\n", ret, val[0], val[1], errno); |
|
80 |
|
81 } |
|
82 } |
|
83 |
|
84 /** |
|
85 @SYMTestCaseID SYSLIB-STDLIB-CT-1111 |
|
86 @SYMTestCaseDesc Tests for serial port |
|
87 @SYMTestPriority High |
|
88 @SYMTestActions Keep reading infinitely from the port |
|
89 @SYMTestExpectedResults Test must not fail |
|
90 @SYMREQ REQ0000 |
|
91 */ |
|
92 void readloop(void) |
|
93 { |
|
94 char buf[100]; |
|
95 int readcount = 10; |
|
96 |
|
97 while (readcount-- > 0) |
|
98 { |
|
99 read(GlobalPort, buf, 100); |
|
100 printf("ReadThread got %x\n", buf[0]); |
|
101 } |
|
102 } |
|
103 |
|
104 int main(void) |
|
105 { |
|
106 void* t1; |
|
107 void*t2; |
|
108 |
|
109 start_posix_server(); /* calls SpawnPosixServer from C++ code */ |
|
110 |
|
111 OpenAndConfigure(); |
|
112 |
|
113 |
|
114 t1 = create_thread(WaitForNotifyThread, "notify"); |
|
115 t2 = create_thread(readloop, "readloop"); |
|
116 |
|
117 start_thread(t1); |
|
118 start_thread(t2); |
|
119 |
|
120 (void)wait_for_thread(t2); |
|
121 close(GlobalPort); //closing the port will force a notify |
|
122 (void)wait_for_thread(t1); |
|
123 |
|
124 return 0; |
|
125 } |
|
126 |