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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8df2eab was 798f364, checked in by Josef Cejka <malyzelenyhnus@…>, 18 years ago

New version of device mapper.
Added devmap test to tester.

  • Property mode set to 100644
File size: 4.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>
35#include <../../../srv/devmap/devmap.h>
36#include "../tester.h"
37
38static int driver_register(char *name)
39{
40 int retval;
41 aid_t req;
42 ipc_call_t answer;
43 int phone;
44 ipcarg_t callback_phonehash;
45
46 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_DRIVER);
47
48 while (phone < 0) {
49 usleep(100000);
50 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_DRIVER);
51 }
52
53 req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer);
54
55 retval = ipc_data_send(phone, (char *)name, strlen(name));
56
57 if (retval != EOK) {
58 async_wait_for(req, NULL);
59 return -1;
60 }
61
62 ipc_connect_to_me(phone, 0, 0, &callback_phonehash);
63
64 async_wait_for(req, NULL);
65 printf("Driver '%s' registered.\n", name);
66
67 return phone;
68}
69
70static int device_register(int driver_phone, char *name, int *handle)
71{
72 ipcarg_t retval;
73 aid_t req;
74 ipc_call_t answer;
75
76 req = async_send_2(driver_phone, DEVMAP_DEVICE_REGISTER, 0, 0, &answer);
77
78 retval = ipc_data_send(driver_phone, (char *)name, strlen(name));
79
80 if (retval != EOK) {
81 printf("Failed to send device name '%s'.\n", name);
82 async_wait_for(req, NULL);
83 return retval;
84 }
85
86 async_wait_for(req, &retval);
87
88 if (NULL != handle) {
89 *handle = -1;
90 }
91
92 if (EOK == retval) {
93
94 if (NULL != handle) {
95 *handle = (int) IPC_GET_ARG1(answer);
96 }
97 printf("Device registered with handle %u.\n", (int) IPC_GET_ARG1(answer));
98 }
99
100 return retval;
101}
102
103/** Test DevMap from the driver's point of view.
104 *
105 *
106 */
107char * test_devmap1(bool quiet)
108{
109 int driver_phone;
110 int dev1_handle;
111 int dev2_handle;
112 int dev3_handle;
113
114 /* Register new driver */
115 driver_phone = driver_register("TestDriver");
116
117 if (driver_phone < 0) {
118 return "Error: Cannot register driver.\n";
119 }
120
121 /* Register new device dev1*/
122 if (EOK != device_register(driver_phone, "TestDevice1", &dev1_handle)) {
123 ipc_hangup(driver_phone);
124 return "Error: cannot register device.\n";
125 }
126
127 /* TODO: get handle for dev1*/
128
129 /* TODO: get handle for dev2 (Should fail unless device is already
130 * registered by someone else)
131 */
132
133 /* Register new device dev2*/
134 if (EOK != device_register(driver_phone, "TestDevice2", &dev2_handle)) {
135 ipc_hangup(driver_phone);
136 return "Error: cannot register device dev2.\n";
137 }
138
139
140 /* Register again device dev1 */
141 if (EOK == device_register(driver_phone, "TestDevice1", &dev3_handle)) {
142 return "Error: dev1 registered twice.\n";
143 }
144
145 /* TODO: get handle for dev2 */
146
147 /* TODO: */
148
149 ipc_hangup(driver_phone);
150
151 return NULL;
152}
153
154char *test_devmap2(bool quiet)
155{
156 /*TODO: Full automatic test */
157 return NULL;
158}
159
160char *test_devmap3(bool quiet)
161{
162 /* TODO: allow user to call test functions in random order */
163 return NULL;
164}
165
Note: See TracBrowser for help on using the repository browser.