Subversion Repositories HelenOS

Rev

Rev 4264 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4264 Rev 4401
Line 30... Line 30...
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 <ipc/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"
Line 82... Line 82...
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 = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP,
87
    device_phone = devmap_device_connect(handle, 0);
88
        DEVMAP_CONNECT_TO_DEVICE, handle);
-
 
89
 
-
 
90
    if (device_phone < 0) {
88
    if (device_phone < 0) {
91
        printf("Failed to connect to devmap as client (handle = %u).\n",
89
        printf("Failed to connect to device (handle = %u).\n",
92
            handle);
90
            handle);
93
        return -1;
91
        return -1;
94
    }
92
    }
95
/* 
-
 
96
 *  device_phone = (int) IPC_GET_ARG5(answer);
-
 
97
 */
93
 
98
    printf("Connected to device.\n");
94
    printf("Connected to device.\n");
99
    ipc_call_sync_1_0(device_phone, 1024, 1025);
-
 
100
/*
-
 
101
 * ipc_hangup(device_phone);
-
 
102
 */
-
 
103
    ipc_hangup(device_phone);
95
    ipc_hangup(device_phone);
104
 
96
 
105
    return EOK;
97
    return EOK;
106
}
98
}
107
 
99
 
Line 119... Line 111...
119
 
111
 
120
*/
112
*/
121
    return EOK;
113
    return EOK;
122
}
114
}
123
 
115
 
124
/**
-
 
125
 *
-
 
126
 */
-
 
127
static int driver_register(char *name)
-
 
128
{
-
 
129
    ipcarg_t retval;
-
 
130
    aid_t req;
-
 
131
    ipc_call_t answer;
-
 
132
    int phone;
-
 
133
    ipcarg_t callback_phonehash;
-
 
134
 
-
 
135
    phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAP, DEVMAP_DRIVER, 0);
-
 
136
    if (phone < 0) {
-
 
137
        printf("Failed to connect to device mapper\n");
-
 
138
        return -1;
-
 
139
    }
-
 
140
   
-
 
141
    req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer);
-
 
142
 
-
 
143
    retval = ipc_data_write_start(phone, (char *)name, str_size(name) + 1);
-
 
144
 
-
 
145
    if (retval != EOK) {
-
 
146
        async_wait_for(req, NULL);
-
 
147
        return -1;
-
 
148
    }
-
 
149
 
-
 
150
    async_set_client_connection(driver_client_connection);
-
 
151
 
-
 
152
    ipc_connect_to_me(phone, 0, 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");  
-
 
157
        async_wait_for(req, NULL);
-
 
158
        return -1;
-
 
159
    }
-
 
160
*/
-
 
161
    async_wait_for(req, &retval);
-
 
162
    printf("Driver '%s' registered.\n", name);
-
 
163
 
-
 
164
    return phone;
-
 
165
}
-
 
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,
-
 
174
        &answer);
-
 
175
 
-
 
176
    retval = ipc_data_write_start(driver_phone, name, str_size(name) + 1);
-
 
177
 
-
 
178
    if (retval != EOK) {
-
 
179
        printf("Failed to send device name '%s'.\n", name);
-
 
180
        async_wait_for(req, NULL);
-
 
181
        return retval;
-
 
182
    }
-
 
183
 
-
 
184
    async_wait_for(req, &retval);
-
 
185
 
-
 
186
    if (NULL != handle) {
-
 
187
        *handle = -1;
-
 
188
    }
-
 
189
 
-
 
190
    if (EOK == retval) {
-
 
191
       
-
 
192
        if (NULL != handle) {
-
 
193
            *handle = (int) IPC_GET_ARG1(answer);
-
 
194
        }
-
 
195
        printf("Device '%s' has handle %u.\n", name,
-
 
196
            (int) IPC_GET_ARG1(answer));
-
 
197
    } else {
-
 
198
        printf("Failed to get handle for device '%s'.\n", name);
-
 
199
    }
-
 
200
 
-
 
201
    return retval;
-
 
202
}
-
 
203
 
-
 
204
/** Register new device.
-
 
205
 * @param driver_phone
-
 
206
 * @param name Device name.
-
 
207
 * @param handle Output variable. Handle to the created instance of device.
-
 
208
 */
-
 
209
static int device_register(int driver_phone, char *name, int *handle)
-
 
210
{
-
 
211
    ipcarg_t retval;
-
 
212
    aid_t req;
-
 
213
    ipc_call_t answer;
-
 
214
 
-
 
215
    req = async_send_2(driver_phone, DEVMAP_DEVICE_REGISTER, 0, 0, &answer);
-
 
216
 
-
 
217
    retval = ipc_data_write_start(driver_phone, (char *)name,
-
 
218
        str_size(name) + 1);
-
 
219
 
-
 
220
    if (retval != EOK) {
-
 
221
        printf("Failed to send device name '%s'.\n", name);
-
 
222
        async_wait_for(req, NULL);
-
 
223
        return retval;
-
 
224
    }
-
 
225
 
-
 
226
    async_wait_for(req, &retval);
-
 
227
 
-
 
228
    if (NULL != handle) {
-
 
229
        *handle = -1;
-
 
230
    }
-
 
231
 
-
 
232
    if (EOK == retval) {
-
 
233
       
-
 
234
        if (NULL != handle) {
-
 
235
            *handle = (int) IPC_GET_ARG1(answer);
-
 
236
        }
-
 
237
        printf("Device registered with handle %u.\n",
-
 
238
            (int) IPC_GET_ARG1(answer));
-
 
239
    }
-
 
240
 
-
 
241
    return retval;
-
 
242
}
-
 
243
 
-
 
244
/** Test DevMap from the driver's point of view.
116
/** Test DevMap from the driver's point of view.
245
 *
117
 *
246
 *
118
 *
247
 */
119
 */
248
char * test_devmap1(bool quiet)
120
char * test_devmap1(bool quiet)
Line 250... Line 122...
250
    int driver_phone;
122
    int driver_phone;
251
    int dev1_handle;
123
    int dev1_handle;
252
    int dev2_handle;
124
    int dev2_handle;
253
    int dev3_handle;
125
    int dev3_handle;
254
    int handle;
126
    int handle;
-
 
127
    int rc;
255
 
128
 
256
    /* Register new driver */
129
    /* Register new driver */
257
    driver_phone = driver_register("TestDriver");
130
    driver_phone = devmap_driver_register("TestDriver",
-
 
131
        driver_client_connection);
258
 
132
 
259
    if (driver_phone < 0) {
133
    if (driver_phone < 0) {
260
        return "Error: Cannot register driver.\n"; 
134
        return "Error: Cannot register driver.\n"; 
261
    }
135
    }
262
 
136
 
263
    /* Register new device dev1*/
137
    /* Register new device dev1. */
264
    if (EOK != device_register(driver_phone, TEST_DEVICE1, &dev1_handle)) {
138
    rc = devmap_device_register(driver_phone, TEST_DEVICE1, &dev1_handle);
-
 
139
    if (rc != EOK) {
265
        ipc_hangup(driver_phone);
140
        ipc_hangup(driver_phone);
266
        return "Error: cannot register device.\n";
141
        return "Error: cannot register device.\n";
267
    }
142
    }
268
 
143
 
-
 
144
    /*
269
    /* Get handle for dev2 (Should fail unless device is already
145
     * Get handle for dev2 (Should fail unless device is already registered
270
     * registered by someone else)
146
     * by someone else).
271
     */
147
     */
272
    if (EOK == device_get_handle(driver_phone, TEST_DEVICE2, &handle)) {
148
    rc = devmap_device_get_handle(TEST_DEVICE2, &handle, 0);
-
 
149
    if (rc == EOK) {
273
        ipc_hangup(driver_phone);
150
        ipc_hangup(driver_phone);
274
        return "Error: got handle for dev2 before it was registered.\n";
151
        return "Error: got handle for dev2 before it was registered.\n";
275
    }
152
    }
276
 
153
 
277
    /* Register new device dev2*/
154
    /* Register new device dev2. */
278
    if (EOK != device_register(driver_phone, TEST_DEVICE2, &dev2_handle)) {
155
    rc = devmap_device_register(driver_phone, TEST_DEVICE2, &dev2_handle);
-
 
156
    if (rc != EOK) {
279
        ipc_hangup(driver_phone);
157
        ipc_hangup(driver_phone);
280
        return "Error: cannot register device dev2.\n";
158
        return "Error: cannot register device dev2.\n";
281
    }
159
    }
282
 
160
 
283
    /* Register again device dev1 */
161
    /* Register device dev1 again. */
284
    if (EOK == device_register(driver_phone, TEST_DEVICE1, &dev3_handle)) {
162
    rc = devmap_device_register(driver_phone, TEST_DEVICE1, &dev3_handle);
-
 
163
    if (rc == EOK) {
285
        return "Error: dev1 registered twice.\n";
164
        return "Error: dev1 registered twice.\n";
286
    }
165
    }
287
 
166
 
288
    /* Get handle for dev1*/
167
    /* Get handle for dev1. */
289
    if (EOK != device_get_handle(driver_phone, TEST_DEVICE1, &handle)) {
168
    rc = devmap_device_get_handle(TEST_DEVICE1, &handle, 0);
-
 
169
    if (rc != EOK) {
290
        ipc_hangup(driver_phone);
170
        ipc_hangup(driver_phone);
291
        return "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n";
171
        return "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n";
292
    }
172
    }
293
 
173
 
294
    if (handle != dev1_handle) {
174
    if (handle != dev1_handle) {
295
        ipc_hangup(driver_phone);
175
        ipc_hangup(driver_phone);
296
        return "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n";
176
        return "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n";
297
    }
177
    }
298
 
178
 
299
    if (EOK != device_client(dev1_handle)) {
179
    if (device_client(dev1_handle) != EOK) {
300
        ipc_hangup(driver_phone);
180
        ipc_hangup(driver_phone);
301
        return "Error: failed client test for 'DEVMAP_DEVICE1'.\n";
181
        return "Error: failed client test for 'DEVMAP_DEVICE1'.\n";
302
    }
182
    }
303
 
183
 
304
    /* TODO: */
184
    /* TODO: */