Rev 4401 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4401 | Rev 4416 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2007 Josef Cejka |
2 | * Copyright (c) 2007 Josef Cejka |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #include <stdio.h> |
29 | #include <stdio.h> |
30 | #include <unistd.h> |
30 | #include <unistd.h> |
31 | #include <ipc/ipc.h> |
31 | #include <ipc/ipc.h> |
32 | #include <ipc/services.h> |
32 | #include <ipc/services.h> |
33 | #include <async.h> |
33 | #include <async.h> |
34 | #include <errno.h> |
34 | #include <errno.h> |
35 | #include <devmap.h> |
35 | #include <devmap.h> |
36 | #include "../tester.h" |
36 | #include "../tester.h" |
37 | 37 | ||
38 | #include <time.h> |
38 | #include <time.h> |
39 | 39 | ||
40 | #define TEST_DEVICE1 "TestDevice1" |
40 | #define TEST_DEVICE1 "TestDevice1" |
41 | #define TEST_DEVICE2 "TestDevice2" |
41 | #define TEST_DEVICE2 "TestDevice2" |
42 | 42 | ||
43 | /** Handle requests from clients |
43 | /** Handle requests from clients |
44 | * |
44 | * |
45 | */ |
45 | */ |
46 | static void driver_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
46 | static void driver_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
47 | { |
47 | { |
48 | ipc_callid_t callid; |
48 | ipc_callid_t callid; |
49 | ipc_call_t call; |
49 | ipc_call_t call; |
50 | int retval; |
50 | int retval; |
51 | 51 | ||
52 | printf("connected: method=%u arg1=%u, arg2=%u arg3=%u.\n", |
52 | printf("connected: method=%u arg1=%u, arg2=%u arg3=%u.\n", |
53 | IPC_GET_METHOD(*icall), IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall), |
53 | IPC_GET_METHOD(*icall), IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall), |
54 | IPC_GET_ARG3(*icall)); |
54 | IPC_GET_ARG3(*icall)); |
55 | 55 | ||
56 | printf("driver_client_connection.\n"); |
56 | printf("driver_client_connection.\n"); |
57 | ipc_answer_0(iid, EOK); |
57 | ipc_answer_0(iid, EOK); |
58 | 58 | ||
59 | /* Ignore parameters, the connection is already opened */ |
59 | /* Ignore parameters, the connection is already opened */ |
60 | while (1) { |
60 | while (1) { |
61 | callid = async_get_call(&call); |
61 | callid = async_get_call(&call); |
62 | retval = EOK; |
62 | retval = EOK; |
63 | printf("method=%u arg1=%u, arg2=%u arg3=%u.\n", |
63 | printf("method=%u arg1=%u, arg2=%u arg3=%u.\n", |
64 | IPC_GET_METHOD(call), IPC_GET_ARG1(call), |
64 | IPC_GET_METHOD(call), IPC_GET_ARG1(call), |
65 | IPC_GET_ARG2(call), IPC_GET_ARG3(call)); |
65 | IPC_GET_ARG2(call), IPC_GET_ARG3(call)); |
66 | switch (IPC_GET_METHOD(call)) { |
66 | switch (IPC_GET_METHOD(call)) { |
67 | case IPC_M_PHONE_HUNGUP: |
67 | case IPC_M_PHONE_HUNGUP: |
68 | /* TODO: Handle hangup */ |
68 | /* TODO: Handle hangup */ |
69 | return; |
69 | return; |
70 | default: |
70 | default: |
71 | printf("Unknown device method %u.\n", |
71 | printf("Unknown device method %u.\n", |
72 | IPC_GET_METHOD(call)); |
72 | IPC_GET_METHOD(call)); |
73 | retval = ENOENT; |
73 | retval = ENOENT; |
74 | } |
74 | } |
75 | ipc_answer_0(callid, retval); |
75 | ipc_answer_0(callid, retval); |
76 | } |
76 | } |
77 | return; |
77 | return; |
78 | } |
78 | } |
79 | 79 | ||
80 | static int device_client_fibril(void *arg) |
80 | static int device_client_fibril(void *arg) |
81 | { |
81 | { |
82 | int handle; |
82 | int handle; |
83 | int device_phone; |
83 | int device_phone; |
84 | 84 | ||
85 | handle = (int)arg; |
85 | handle = (int)arg; |
86 | 86 | ||
87 | device_phone = devmap_device_connect(handle, 0); |
87 | device_phone = devmap_device_connect(handle, 0); |
88 | if (device_phone < 0) { |
88 | if (device_phone < 0) { |
89 | printf("Failed to connect to device (handle = %u).\n", |
89 | printf("Failed to connect to device (handle = %u).\n", |
90 | handle); |
90 | handle); |
91 | return -1; |
91 | return -1; |
92 | } |
92 | } |
93 | 93 | ||
94 | printf("Connected to device.\n"); |
94 | printf("Connected to device.\n"); |
95 | ipc_hangup(device_phone); |
95 | ipc_hangup(device_phone); |
96 | 96 | ||
97 | return EOK; |
97 | return EOK; |
98 | } |
98 | } |
99 | 99 | ||
100 | /** Communication test with device. |
100 | /** Communication test with device. |
101 | * @param handle handle to tested instance. |
101 | * @param handle handle to tested instance. |
102 | */ |
102 | */ |
103 | static int device_client(int handle) |
103 | static int device_client(int handle) |
104 | { |
104 | { |
105 | /* fid_t fid; |
105 | /* fid_t fid; |
106 | ipc_call_t call; |
106 | ipc_call_t call; |
107 | ipc_callid_t callid; |
107 | ipc_callid_t callid; |
108 | 108 | ||
109 | fid = fibril_create(device_client_fibril, (void *)handle); |
109 | fid = fibril_create(device_client_fibril, (void *)handle); |
110 | fibril_add_ready(fid); |
110 | fibril_add_ready(fid); |
111 | 111 | ||
112 | */ |
112 | */ |
113 | return EOK; |
113 | return EOK; |
114 | } |
114 | } |
115 | 115 | ||
116 | /** Test DevMap from the driver's point of view. |
116 | /** Test DevMap from the driver's point of view. |
117 | * |
117 | * |
118 | * |
118 | * |
119 | */ |
119 | */ |
120 | char * test_devmap1(bool quiet) |
120 | char * test_devmap1(bool quiet) |
121 | { |
121 | { |
122 | int driver_phone; |
122 | const char *retval = NULL; |
123 | int dev1_handle; |
- | |
124 | int dev2_handle; |
- | |
125 | int dev3_handle; |
- | |
126 | int handle; |
- | |
127 | int rc; |
- | |
128 | 123 | ||
129 | /* Register new driver */ |
124 | /* Register new driver */ |
130 | driver_phone = devmap_driver_register("TestDriver", |
125 | int rc = devmap_driver_register("TestDriver", driver_client_connection); |
131 | driver_client_connection); |
- | |
132 | - | ||
133 | if (driver_phone < 0) { |
126 | if (rc < 0) { |
134 | return "Error: Cannot register driver.\n"; |
127 | retval = "Error: Cannot register driver.\n"; |
- | 128 | goto out; |
|
135 | } |
129 | } |
136 | 130 | ||
137 | /* Register new device dev1. */ |
131 | /* Register new device dev1. */ |
- | 132 | dev_handle_t dev1_handle; |
|
138 | rc = devmap_device_register(driver_phone, TEST_DEVICE1, &dev1_handle); |
133 | rc = devmap_device_register(TEST_DEVICE1, &dev1_handle); |
139 | if (rc != EOK) { |
134 | if (rc != EOK) { |
140 | ipc_hangup(driver_phone); |
- | |
141 | return "Error: cannot register device.\n"; |
135 | retval = "Error: cannot register device.\n"; |
- | 136 | goto out; |
|
142 | } |
137 | } |
143 | 138 | ||
144 | /* |
139 | /* |
145 | * Get handle for dev2 (Should fail unless device is already registered |
140 | * Get handle for dev2 (Should fail unless device is already registered |
146 | * by someone else). |
141 | * by someone else). |
147 | */ |
142 | */ |
- | 143 | dev_handle_t handle; |
|
148 | rc = devmap_device_get_handle(TEST_DEVICE2, &handle, 0); |
144 | rc = devmap_device_get_handle(TEST_DEVICE2, &handle, 0); |
149 | if (rc == EOK) { |
145 | if (rc == EOK) { |
150 | ipc_hangup(driver_phone); |
- | |
151 | return "Error: got handle for dev2 before it was registered.\n"; |
146 | retval = "Error: got handle for dev2 before it was registered.\n"; |
- | 147 | goto out; |
|
152 | } |
148 | } |
153 | 149 | ||
154 | /* Register new device dev2. */ |
150 | /* Register new device dev2. */ |
- | 151 | dev_handle_t dev2_handle; |
|
155 | rc = devmap_device_register(driver_phone, TEST_DEVICE2, &dev2_handle); |
152 | rc = devmap_device_register(TEST_DEVICE2, &dev2_handle); |
156 | if (rc != EOK) { |
153 | if (rc != EOK) { |
157 | ipc_hangup(driver_phone); |
- | |
158 | return "Error: cannot register device dev2.\n"; |
154 | retval = "Error: cannot register device dev2.\n"; |
- | 155 | goto out; |
|
159 | } |
156 | } |
160 | 157 | ||
161 | /* Register device dev1 again. */ |
158 | /* Register device dev1 again. */ |
- | 159 | dev_handle_t dev3_handle; |
|
162 | rc = devmap_device_register(driver_phone, TEST_DEVICE1, &dev3_handle); |
160 | rc = devmap_device_register(TEST_DEVICE1, &dev3_handle); |
163 | if (rc == EOK) { |
161 | if (rc == EOK) { |
164 | return "Error: dev1 registered twice.\n"; |
162 | retval = "Error: dev1 registered twice.\n"; |
- | 163 | goto out; |
|
165 | } |
164 | } |
166 | 165 | ||
167 | /* Get handle for dev1. */ |
166 | /* Get handle for dev1. */ |
168 | rc = devmap_device_get_handle(TEST_DEVICE1, &handle, 0); |
167 | rc = devmap_device_get_handle(TEST_DEVICE1, &handle, 0); |
169 | if (rc != EOK) { |
168 | if (rc != EOK) { |
170 | ipc_hangup(driver_phone); |
- | |
171 | return "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n"; |
169 | retval = "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n"; |
- | 170 | goto out; |
|
172 | } |
171 | } |
173 | 172 | ||
174 | if (handle != dev1_handle) { |
173 | if (handle != dev1_handle) { |
175 | ipc_hangup(driver_phone); |
- | |
176 | return "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n"; |
174 | retval = "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n"; |
- | 175 | goto out; |
|
177 | } |
176 | } |
178 | 177 | ||
179 | if (device_client(dev1_handle) != EOK) { |
178 | if (device_client(dev1_handle) != EOK) { |
180 | ipc_hangup(driver_phone); |
- | |
181 | return "Error: failed client test for 'DEVMAP_DEVICE1'.\n"; |
179 | retval = "Error: failed client test for 'DEVMAP_DEVICE1'.\n"; |
- | 180 | goto out; |
|
182 | } |
181 | } |
183 | 182 | ||
184 | /* TODO: */ |
- | |
185 | 183 | out: |
|
- | 184 | devmap_hangup_phone(DEVMAP_DRIVER); |
|
186 | ipc_hangup(driver_phone); |
185 | devmap_hangup_phone(DEVMAP_CLIENT); |
187 | 186 | ||
188 | return NULL; |
187 | return NULL; |
189 | } |
188 | } |
190 | 189 | ||
191 | char *test_devmap2(bool quiet) |
190 | char *test_devmap2(bool quiet) |
192 | { |
191 | { |
193 | /*TODO: Full automatic test */ |
192 | /*TODO: Full automatic test */ |
194 | return NULL; |
193 | return NULL; |
195 | } |
194 | } |
196 | 195 | ||
197 | char *test_devmap3(bool quiet) |
196 | char *test_devmap3(bool quiet) |
198 | { |
197 | { |
199 | /* TODO: allow user to call test functions in random order */ |
198 | /* TODO: allow user to call test functions in random order */ |
200 | return NULL; |
199 | return NULL; |
201 | } |
200 | } |
202 | 201 | ||
203 | 202 |