source: mainline/uspace/app/tester/devmap/devmap1.c@ cb41a5e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since cb41a5e was cb41a5e, checked in by Martin Decky <martin@…>, 17 years ago

improve devmap interface
remove spared device

  • Property mode set to 100644
File size: 5.1 KB
RevLine 
[798f364]1/*
2 * Copyright (c) 2007 Josef Cejka
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
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
15 * derived from this software without specific prior written permission.
16 *
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
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <stdio.h>
30#include <unistd.h>
31#include <ipc/ipc.h>
32#include <ipc/services.h>
33#include <async.h>
34#include <errno.h>
[1090b8c]35#include <devmap.h>
[798f364]36#include "../tester.h"
37
[b61d47d]38#include <time.h>
39
40#define TEST_DEVICE1 "TestDevice1"
41#define TEST_DEVICE2 "TestDevice2"
42
43/** Handle requests from clients
44 *
45 */
46static void driver_client_connection(ipc_callid_t iid, ipc_call_t *icall)
[798f364]47{
[b61d47d]48 ipc_callid_t callid;
49 ipc_call_t call;
[798f364]50 int retval;
[b61d47d]51
[36d852c]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),
54 IPC_GET_ARG3(*icall));
[b61d47d]55
56 printf("driver_client_connection.\n");
57 ipc_answer_0(iid, EOK);
58
59 /* Ignore parameters, the connection is already opened */
60 while (1) {
61 callid = async_get_call(&call);
62 retval = EOK;
[36d852c]63 printf("method=%u arg1=%u, arg2=%u arg3=%u.\n",
64 IPC_GET_METHOD(call), IPC_GET_ARG1(call),
65 IPC_GET_ARG2(call), IPC_GET_ARG3(call));
[b61d47d]66 switch (IPC_GET_METHOD(call)) {
67 case IPC_M_PHONE_HUNGUP:
68 /* TODO: Handle hangup */
69 return;
70 default:
[36d852c]71 printf("Unknown device method %u.\n",
72 IPC_GET_METHOD(call));
[b61d47d]73 retval = ENOENT;
74 }
75 ipc_answer_0(callid, retval);
76 }
77 return;
78}
79
80static int device_client_fibril(void *arg)
81{
82 int handle;
83 int device_phone;
84
85 handle = (int)arg;
86
[1090b8c]87 device_phone = devmap_device_connect(handle, 0);
[b61d47d]88 if (device_phone < 0) {
[1090b8c]89 printf("Failed to connect to device (handle = %u).\n",
[36d852c]90 handle);
[b61d47d]91 return -1;
92 }
[1090b8c]93
[b61d47d]94 printf("Connected to device.\n");
95 ipc_hangup(device_phone);
96
97 return EOK;
98}
99
100/** Communication test with device.
101 * @param handle handle to tested instance.
102 */
103static int device_client(int handle)
104{
105/* fid_t fid;
106 ipc_call_t call;
107 ipc_callid_t callid;
108
109 fid = fibril_create(device_client_fibril, (void *)handle);
110 fibril_add_ready(fid);
111
112*/
113 return EOK;
114}
115
[798f364]116/** Test DevMap from the driver's point of view.
117 *
118 *
119 */
120char * test_devmap1(bool quiet)
121{
[cb41a5e]122 const char *retval = NULL;
123
[798f364]124 /* Register new driver */
[cb41a5e]125 int rc = devmap_driver_register("TestDriver", driver_client_connection);
126 if (rc < 0) {
127 retval = "Error: Cannot register driver.\n";
128 goto out;
[798f364]129 }
[cb41a5e]130
[1090b8c]131 /* Register new device dev1. */
[cb41a5e]132 dev_handle_t dev1_handle;
133 rc = devmap_device_register(TEST_DEVICE1, &dev1_handle);
[1090b8c]134 if (rc != EOK) {
[cb41a5e]135 retval = "Error: cannot register device.\n";
136 goto out;
[798f364]137 }
[cb41a5e]138
[1090b8c]139 /*
140 * Get handle for dev2 (Should fail unless device is already registered
141 * by someone else).
[798f364]142 */
[cb41a5e]143 dev_handle_t handle;
[1090b8c]144 rc = devmap_device_get_handle(TEST_DEVICE2, &handle, 0);
145 if (rc == EOK) {
[cb41a5e]146 retval = "Error: got handle for dev2 before it was registered.\n";
147 goto out;
[b61d47d]148 }
[cb41a5e]149
[1090b8c]150 /* Register new device dev2. */
[cb41a5e]151 dev_handle_t dev2_handle;
152 rc = devmap_device_register(TEST_DEVICE2, &dev2_handle);
[1090b8c]153 if (rc != EOK) {
[cb41a5e]154 retval = "Error: cannot register device dev2.\n";
155 goto out;
[798f364]156 }
[cb41a5e]157
[1090b8c]158 /* Register device dev1 again. */
[cb41a5e]159 dev_handle_t dev3_handle;
160 rc = devmap_device_register(TEST_DEVICE1, &dev3_handle);
[1090b8c]161 if (rc == EOK) {
[cb41a5e]162 retval = "Error: dev1 registered twice.\n";
163 goto out;
[798f364]164 }
[cb41a5e]165
[1090b8c]166 /* Get handle for dev1. */
167 rc = devmap_device_get_handle(TEST_DEVICE1, &handle, 0);
168 if (rc != EOK) {
[cb41a5e]169 retval = "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n";
170 goto out;
[b61d47d]171 }
[cb41a5e]172
[b61d47d]173 if (handle != dev1_handle) {
[cb41a5e]174 retval = "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n";
175 goto out;
[b61d47d]176 }
[cb41a5e]177
[1090b8c]178 if (device_client(dev1_handle) != EOK) {
[cb41a5e]179 retval = "Error: failed client test for 'DEVMAP_DEVICE1'.\n";
180 goto out;
[b61d47d]181 }
[cb41a5e]182
183out:
184 devmap_hangup_phone(DEVMAP_DRIVER);
185 devmap_hangup_phone(DEVMAP_CLIENT);
186
[798f364]187 return NULL;
188}
189
190char *test_devmap2(bool quiet)
191{
192 /*TODO: Full automatic test */
193 return NULL;
194}
195
196char *test_devmap3(bool quiet)
197{
198 /* TODO: allow user to call test functions in random order */
199 return NULL;
200}
201
Note: See TracBrowser for help on using the repository browser.