Rev 2594 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2594 | Rev 2635 | ||
---|---|---|---|
Line 33... | Line 33... | ||
33 | #include <async.h> |
33 | #include <async.h> |
34 | #include <errno.h> |
34 | #include <errno.h> |
35 | #include <../../../srv/devmap/devmap.h> |
35 | #include <../../../srv/devmap/devmap.h> |
36 | #include "../tester.h" |
36 | #include "../tester.h" |
37 | 37 | ||
- | 38 | #include <time.h> |
|
- | 39 | ||
- | 40 | #define TEST_DEVICE1 "TestDevice1" |
|
- | 41 | #define TEST_DEVICE2 "TestDevice2" |
|
- | 42 | ||
38 | static int driver_register(char *name) |
43 | /** Handle requests from clients |
- | 44 | * |
|
- | 45 | */ |
|
- | 46 | static void driver_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
|
39 | { |
47 | { |
- | 48 | ipc_callid_t callid; |
|
- | 49 | ipc_call_t call; |
|
40 | int retval; |
50 | int retval; |
- | 51 | ||
- | 52 | printf("connected: method=%u arg1=%u, arg2=%u arg3=%u.\n", IPC_GET_METHOD(*icall), |
|
- | 53 | IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall), IPC_GET_ARG3(*icall)); |
|
- | 54 | ||
- | 55 | printf("driver_client_connection.\n"); |
|
- | 56 | ipc_answer_0(iid, EOK); |
|
- | 57 | ||
- | 58 | /* Ignore parameters, the connection is already opened */ |
|
- | 59 | while (1) { |
|
- | 60 | callid = async_get_call(&call); |
|
- | 61 | retval = EOK; |
|
- | 62 | printf("method=%u arg1=%u, arg2=%u arg3=%u.\n", IPC_GET_METHOD(call), |
|
- | 63 | IPC_GET_ARG1(call), IPC_GET_ARG2(call), IPC_GET_ARG3(call)); |
|
- | 64 | switch (IPC_GET_METHOD(call)) { |
|
- | 65 | case IPC_M_PHONE_HUNGUP: |
|
- | 66 | /* TODO: Handle hangup */ |
|
- | 67 | return; |
|
- | 68 | default: |
|
- | 69 | printf("Unknown device method %u.\n", IPC_GET_METHOD(call)); |
|
- | 70 | retval = ENOENT; |
|
- | 71 | } |
|
- | 72 | ipc_answer_0(callid, retval); |
|
- | 73 | } |
|
- | 74 | return; |
|
- | 75 | } |
|
- | 76 | ||
- | 77 | static int device_client_fibril(void *arg) |
|
- | 78 | { |
|
- | 79 | int handle; |
|
- | 80 | int device_phone; |
|
- | 81 | ||
- | 82 | handle = (int)arg; |
|
- | 83 | ||
- | 84 | device_phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, \ |
|
- | 85 | DEVMAP_CONNECT_TO_DEVICE, handle); |
|
- | 86 | ||
- | 87 | if (device_phone < 0) { |
|
- | 88 | printf("Failed to connect to devmap as client (handle = %u).\n", |
|
- | 89 | handle); |
|
- | 90 | return -1; |
|
- | 91 | } |
|
- | 92 | /* |
|
- | 93 | * device_phone = (int) IPC_GET_ARG3(answer); |
|
- | 94 | */ |
|
- | 95 | printf("Connected to device.\n"); |
|
- | 96 | ipc_call_sync_1_0(device_phone, 1024, 1025); |
|
- | 97 | /* |
|
- | 98 | * ipc_hangup(device_phone); |
|
- | 99 | */ |
|
- | 100 | ipc_hangup(device_phone); |
|
- | 101 | ||
- | 102 | return EOK; |
|
- | 103 | } |
|
- | 104 | ||
- | 105 | /** Communication test with device. |
|
- | 106 | * @param handle handle to tested instance. |
|
- | 107 | */ |
|
- | 108 | static int device_client(int handle) |
|
- | 109 | { |
|
- | 110 | /* fid_t fid; |
|
- | 111 | ipc_call_t call; |
|
- | 112 | ipc_callid_t callid; |
|
- | 113 | ||
- | 114 | fid = fibril_create(device_client_fibril, (void *)handle); |
|
- | 115 | fibril_add_ready(fid); |
|
- | 116 | ||
- | 117 | */ |
|
- | 118 | return EOK; |
|
- | 119 | } |
|
- | 120 | ||
- | 121 | /** |
|
- | 122 | * |
|
- | 123 | */ |
|
- | 124 | static int driver_register(char *name) |
|
- | 125 | { |
|
- | 126 | ipcarg_t retval; |
|
41 | aid_t req; |
127 | aid_t req; |
42 | ipc_call_t answer; |
128 | ipc_call_t answer; |
43 | int phone; |
129 | int phone; |
44 | ipcarg_t callback_phonehash; |
130 | ipcarg_t callback_phonehash; |
45 | 131 | ||
46 | phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_DRIVER); |
132 | phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, |
- | 133 | DEVMAP_DRIVER, 0); |
|
47 | 134 | ||
48 | while (phone < 0) { |
135 | while (phone < 0) { |
49 | usleep(100000); |
136 | usleep(100000); |
50 | phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_DRIVER); |
137 | phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, |
- | 138 | DEVMAP_DRIVER, 0); |
|
51 | } |
139 | } |
52 | 140 | ||
53 | req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer); |
141 | req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer); |
54 | 142 | ||
55 | retval = ipc_data_send(phone, (char *)name, strlen(name)); |
143 | retval = ipc_data_send(phone, (char *)name, strlen(name) + 1); |
56 | 144 | ||
57 | if (retval != EOK) { |
145 | if (retval != EOK) { |
58 | async_wait_for(req, NULL); |
146 | async_wait_for(req, NULL); |
59 | return -1; |
147 | return -1; |
60 | } |
148 | } |
61 | 149 | ||
62 | ipc_connect_to_me(phone, 0, 0, &callback_phonehash); |
150 | async_set_client_connection(driver_client_connection); |
63 | 151 | ||
- | 152 | ipc_connect_to_me(phone, 0, 0, &callback_phonehash); |
|
- | 153 | /* |
|
- | 154 | if (NULL == async_new_connection(callback_phonehash, 0, NULL, |
|
- | 155 | driver_client_connection)) { |
|
- | 156 | printf("Failed to create new fibril.\n"); |
|
64 | async_wait_for(req, NULL); |
157 | async_wait_for(req, NULL); |
- | 158 | return -1; |
|
- | 159 | } |
|
- | 160 | */ |
|
- | 161 | async_wait_for(req, &retval); |
|
65 | printf("Driver '%s' registered.\n", name); |
162 | printf("Driver '%s' registered.\n", name); |
66 | 163 | ||
67 | return phone; |
164 | return phone; |
68 | } |
165 | } |
69 | 166 | ||
- | 167 | static int device_get_handle(int driver_phone, char *name, int *handle) |
|
- | 168 | { |
|
- | 169 | ipcarg_t retval; |
|
- | 170 | aid_t req; |
|
- | 171 | ipc_call_t answer; |
|
- | 172 | ||
- | 173 | req = async_send_2(driver_phone, DEVMAP_DEVICE_GET_HANDLE, 0, 0, &answer); |
|
- | 174 | ||
- | 175 | retval = ipc_data_send(driver_phone, name, strlen(name) + 1); |
|
- | 176 | ||
- | 177 | if (retval != EOK) { |
|
- | 178 | printf("Failed to send device name '%s'.\n", name); |
|
- | 179 | async_wait_for(req, NULL); |
|
- | 180 | return retval; |
|
- | 181 | } |
|
- | 182 | ||
- | 183 | async_wait_for(req, &retval); |
|
- | 184 | ||
- | 185 | if (NULL != handle) { |
|
- | 186 | *handle = -1; |
|
- | 187 | } |
|
- | 188 | ||
- | 189 | if (EOK == retval) { |
|
- | 190 | ||
- | 191 | if (NULL != handle) { |
|
- | 192 | *handle = (int) IPC_GET_ARG1(answer); |
|
- | 193 | } |
|
- | 194 | printf("Device '%s' has handle %u.\n", name, (int) IPC_GET_ARG1(answer)); |
|
- | 195 | } else { |
|
- | 196 | printf("Failed to get handle for device '%s'.\n", name); |
|
- | 197 | } |
|
- | 198 | ||
- | 199 | return retval; |
|
- | 200 | } |
|
- | 201 | ||
- | 202 | /** Register new device. |
|
- | 203 | * @param driver_phone |
|
- | 204 | * @param name Device name. |
|
- | 205 | * @param handle Output variable. Handle to the created instance of device. |
|
- | 206 | */ |
|
70 | static int device_register(int driver_phone, char *name, int *handle) |
207 | static int device_register(int driver_phone, char *name, int *handle) |
71 | { |
208 | { |
72 | ipcarg_t retval; |
209 | ipcarg_t retval; |
73 | aid_t req; |
210 | aid_t req; |
74 | ipc_call_t answer; |
211 | ipc_call_t answer; |
75 | 212 | ||
76 | req = async_send_2(driver_phone, DEVMAP_DEVICE_REGISTER, 0, 0, &answer); |
213 | req = async_send_2(driver_phone, DEVMAP_DEVICE_REGISTER, 0, 0, &answer); |
77 | 214 | ||
78 | retval = ipc_data_send(driver_phone, (char *)name, strlen(name)); |
215 | retval = ipc_data_send(driver_phone, (char *)name, strlen(name) + 1); |
79 | 216 | ||
80 | if (retval != EOK) { |
217 | if (retval != EOK) { |
81 | printf("Failed to send device name '%s'.\n", name); |
218 | printf("Failed to send device name '%s'.\n", name); |
82 | async_wait_for(req, NULL); |
219 | async_wait_for(req, NULL); |
83 | return retval; |
220 | return retval; |
Line 108... | Line 245... | ||
108 | { |
245 | { |
109 | int driver_phone; |
246 | int driver_phone; |
110 | int dev1_handle; |
247 | int dev1_handle; |
111 | int dev2_handle; |
248 | int dev2_handle; |
112 | int dev3_handle; |
249 | int dev3_handle; |
- | 250 | int handle; |
|
113 | 251 | ||
114 | /* Register new driver */ |
252 | /* Register new driver */ |
115 | driver_phone = driver_register("TestDriver"); |
253 | driver_phone = driver_register("TestDriver"); |
116 | 254 | ||
117 | if (driver_phone < 0) { |
255 | if (driver_phone < 0) { |
118 | return "Error: Cannot register driver.\n"; |
256 | return "Error: Cannot register driver.\n"; |
119 | } |
257 | } |
120 | 258 | ||
121 | /* Register new device dev1*/ |
259 | /* Register new device dev1*/ |
122 | if (EOK != device_register(driver_phone, "TestDevice1", &dev1_handle)) { |
260 | if (EOK != device_register(driver_phone, TEST_DEVICE1, &dev1_handle)) { |
123 | ipc_hangup(driver_phone); |
261 | ipc_hangup(driver_phone); |
124 | return "Error: cannot register device.\n"; |
262 | return "Error: cannot register device.\n"; |
125 | } |
263 | } |
126 | 264 | ||
127 | /* TODO: get handle for dev1*/ |
- | |
128 | - | ||
129 | /* TODO: get handle for dev2 (Should fail unless device is already |
265 | /* Get handle for dev2 (Should fail unless device is already |
130 | * registered by someone else) |
266 | * registered by someone else) |
131 | */ |
267 | */ |
- | 268 | if (EOK == device_get_handle(driver_phone, TEST_DEVICE2, &handle)) { |
|
- | 269 | ipc_hangup(driver_phone); |
|
- | 270 | return "Error: got handle for dev2 before it was registered.\n"; |
|
- | 271 | } |
|
132 | 272 | ||
133 | /* Register new device dev2*/ |
273 | /* Register new device dev2*/ |
134 | if (EOK != device_register(driver_phone, "TestDevice2", &dev2_handle)) { |
274 | if (EOK != device_register(driver_phone, TEST_DEVICE2, &dev2_handle)) { |
135 | ipc_hangup(driver_phone); |
275 | ipc_hangup(driver_phone); |
136 | return "Error: cannot register device dev2.\n"; |
276 | return "Error: cannot register device dev2.\n"; |
137 | } |
277 | } |
138 | 278 | ||
139 | - | ||
140 | /* Register again device dev1 */ |
279 | /* Register again device dev1 */ |
141 | if (EOK == device_register(driver_phone, "TestDevice1", &dev3_handle)) { |
280 | if (EOK == device_register(driver_phone, TEST_DEVICE1, &dev3_handle)) { |
142 | return "Error: dev1 registered twice.\n"; |
281 | return "Error: dev1 registered twice.\n"; |
143 | } |
282 | } |
144 | 283 | ||
145 | /* TODO: get handle for dev2 */ |
284 | /* Get handle for dev1*/ |
- | 285 | if (EOK != device_get_handle(driver_phone, TEST_DEVICE1, &handle)) { |
|
- | 286 | ipc_hangup(driver_phone); |
|
- | 287 | return "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n"; |
|
- | 288 | } |
|
- | 289 | ||
- | 290 | if (handle != dev1_handle) { |
|
- | 291 | ipc_hangup(driver_phone); |
|
- | 292 | return "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n"; |
|
- | 293 | } |
|
- | 294 | ||
- | 295 | if (EOK != device_client(dev1_handle)) { |
|
- | 296 | ipc_hangup(driver_phone); |
|
- | 297 | return "Error: failed client test for 'DEVMAP_DEVICE1'.\n"; |
|
- | 298 | } |
|
146 | 299 | ||
147 | /* TODO: */ |
300 | /* TODO: */ |
148 | 301 | ||
149 | ipc_hangup(driver_phone); |
302 | ipc_hangup(driver_phone); |
150 | 303 |