source: mainline/uspace/lib/dispcfg/src/testdc.c

Last change on this file was cdf5361, checked in by Jiri Svoboda <jiri@…>, 2 years ago

Factor out test display service

So that we can use it in display-cfg unit tests.

  • Property mode set to 100644
File size: 5.8 KB
Line 
1/*
2 * Copyright (c) 2023 Jiri Svoboda
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/** @addtogroup libdispcfg
30 * @{
31 */
32/**
33 * @file
34 * @brief Display configuration test service
35 */
36
37#include <errno.h>
38#include <dispcfg.h>
39#include <dispcfg_srv.h>
40#include <fibril_synch.h>
41#include <str.h>
42#include <testdc.h>
43
44static errno_t test_get_seat_list(void *, dispcfg_seat_list_t **);
45static errno_t test_get_seat_info(void *, sysarg_t, dispcfg_seat_info_t **);
46static errno_t test_seat_create(void *, const char *, sysarg_t *);
47static errno_t test_seat_delete(void *, sysarg_t);
48static errno_t test_dev_assign(void *, sysarg_t, sysarg_t);
49static errno_t test_dev_unassign(void *, sysarg_t);
50static errno_t test_get_asgn_dev_list(void *, sysarg_t, dispcfg_dev_list_t **);
51static errno_t test_get_event(void *, dispcfg_ev_t *);
52
53static void test_seat_added(void *, sysarg_t);
54static void test_seat_removed(void *, sysarg_t);
55
56static dispcfg_ops_t test_dispcfg_srv_ops = {
57 .get_seat_list = test_get_seat_list,
58 .get_seat_info = test_get_seat_info,
59 .seat_create = test_seat_create,
60 .seat_delete = test_seat_delete,
61 .dev_assign = test_dev_assign,
62 .dev_unassign = test_dev_unassign,
63 .get_asgn_dev_list = test_get_asgn_dev_list,
64 .get_event = test_get_event
65};
66
67dispcfg_cb_t test_dispcfg_cb = {
68 .seat_added = test_seat_added,
69 .seat_removed = test_seat_removed
70};
71
72/** Test seat management service connection. */
73void test_dispcfg_conn(ipc_call_t *icall, void *arg)
74{
75 test_response_t *resp = (test_response_t *) arg;
76 dispcfg_srv_t srv;
77
78 /* Set up protocol structure */
79 dispcfg_srv_initialize(&srv);
80 srv.ops = &test_dispcfg_srv_ops;
81 srv.arg = arg;
82 resp->srv = &srv;
83
84 /* Handle connection */
85 dispcfg_conn(icall, &srv);
86
87 resp->srv = NULL;
88}
89
90static void test_seat_added(void *arg, sysarg_t seat_id)
91{
92 test_response_t *resp = (test_response_t *) arg;
93
94 resp->revent.etype = dcev_seat_added;
95
96 fibril_mutex_lock(&resp->event_lock);
97 resp->seat_added_called = true;
98 resp->seat_added_seat_id = seat_id;
99 fibril_condvar_broadcast(&resp->event_cv);
100 fibril_mutex_unlock(&resp->event_lock);
101}
102
103static void test_seat_removed(void *arg, sysarg_t seat_id)
104{
105 test_response_t *resp = (test_response_t *) arg;
106
107 resp->revent.etype = dcev_seat_removed;
108
109 fibril_mutex_lock(&resp->event_lock);
110 resp->seat_removed_called = true;
111 resp->seat_removed_seat_id = seat_id;
112 fibril_condvar_broadcast(&resp->event_cv);
113 fibril_mutex_unlock(&resp->event_lock);
114}
115
116static errno_t test_get_seat_list(void *arg, dispcfg_seat_list_t **rlist)
117{
118 test_response_t *resp = (test_response_t *) arg;
119
120 resp->get_seat_list_called = true;
121
122 if (resp->rc != EOK)
123 return resp->rc;
124
125 *rlist = resp->get_seat_list_rlist;
126 return EOK;
127}
128
129static errno_t test_get_seat_info(void *arg, sysarg_t seat_id,
130 dispcfg_seat_info_t **rinfo)
131{
132 test_response_t *resp = (test_response_t *) arg;
133
134 resp->get_seat_info_called = true;
135 resp->get_seat_info_seat_id = seat_id;
136
137 if (resp->rc != EOK)
138 return resp->rc;
139
140 *rinfo = resp->get_seat_info_rinfo;
141 return EOK;
142}
143
144static errno_t test_seat_create(void *arg, const char *name, sysarg_t *rseat_id)
145{
146 test_response_t *resp = (test_response_t *) arg;
147
148 resp->seat_create_called = true;
149 resp->seat_create_name = str_dup(name);
150 *rseat_id = resp->seat_create_seat_id;
151 return resp->rc;
152}
153
154static errno_t test_seat_delete(void *arg, sysarg_t seat_id)
155{
156 test_response_t *resp = (test_response_t *) arg;
157
158 resp->seat_delete_called = true;
159 resp->seat_delete_seat_id = seat_id;
160 return resp->rc;
161}
162
163static errno_t test_dev_assign(void *arg, sysarg_t svc_id, sysarg_t seat_id)
164{
165 test_response_t *resp = (test_response_t *) arg;
166
167 resp->dev_assign_called = true;
168 resp->dev_assign_svc_id = svc_id;
169 resp->dev_assign_seat_id = seat_id;
170 return resp->rc;
171}
172
173static errno_t test_dev_unassign(void *arg, sysarg_t svc_id)
174{
175 test_response_t *resp = (test_response_t *) arg;
176
177 resp->dev_unassign_called = true;
178 resp->dev_unassign_svc_id = svc_id;
179 return resp->rc;
180}
181
182static errno_t test_get_asgn_dev_list(void *arg, sysarg_t seat_id,
183 dispcfg_dev_list_t **rlist)
184{
185 test_response_t *resp = (test_response_t *) arg;
186
187 resp->get_asgn_dev_list_called = true;
188 resp->get_asgn_dev_list_seat_id = seat_id;
189
190 if (resp->rc != EOK)
191 return resp->rc;
192
193 *rlist = resp->get_asgn_dev_list_rlist;
194 return EOK;
195}
196
197static errno_t test_get_event(void *arg, dispcfg_ev_t *event)
198{
199 test_response_t *resp = (test_response_t *) arg;
200
201 resp->get_event_called = true;
202 if (resp->event_cnt > 0) {
203 --resp->event_cnt;
204 *event = resp->event;
205 return EOK;
206 }
207
208 return ENOENT;
209}
210
211/** @}
212 */
Note: See TracBrowser for help on using the repository browser.