2 * Copyright (c) 2019 Jiri Svoboda
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
30 #include <str_error.h>
31 #include <ipc/services.h>
32 #include <io/chardev.h>
34 #include "../tester.h"
36 #define SMALL_BUFFER_SIZE 64
37 #define LARGE_BUFFER_SIZE (DATA_XFER_LIMIT * 4)
39 static char small_buffer
[SMALL_BUFFER_SIZE
];
40 static char large_buffer
[LARGE_BUFFER_SIZE
];
42 /** Test device that always performs small transfers. */
43 static const char *test_chardev1_smallx(void)
51 TPRINTF("Test small transfer character device operations\n");
53 rc
= loc_service_get_id(SERVICE_NAME_CHARDEV_TEST_SMALLX
, &sid
, 0);
55 return "Failed resolving test device "
56 SERVICE_NAME_CHARDEV_TEST_SMALLX
;
59 sess
= loc_service_connect(sid
, INTERFACE_DDF
, 0);
61 return "Failed connecting test device";
63 rc
= chardev_open(sess
, &chardev
);
66 return "Failed opening test device";
69 rc
= chardev_write(chardev
, small_buffer
, SMALL_BUFFER_SIZE
, &nbytes
);
71 chardev_close(chardev
);
73 return "Failed sending data";
76 TPRINTF("Sent %zu bytes\n", nbytes
);
78 rc
= chardev_read(chardev
, small_buffer
, SMALL_BUFFER_SIZE
, &nbytes
,
81 chardev_close(chardev
);
83 return "Failed receiving data";
86 TPRINTF("Received %zu bytes\n", nbytes
);
88 chardev_close(chardev
);
95 /** Test device that always performs large transfers. */
96 static const char *test_chardev1_largex(void)
104 TPRINTF("Test large transfer character device operations\n");
106 rc
= loc_service_get_id(SERVICE_NAME_CHARDEV_TEST_LARGEX
, &sid
, 0);
108 return "Failed resolving test device "
109 SERVICE_NAME_CHARDEV_TEST_LARGEX
;
112 sess
= loc_service_connect(sid
, INTERFACE_DDF
, 0);
114 return "Failed connecting test device";
116 rc
= chardev_open(sess
, &chardev
);
119 return "Failed opening test device";
122 rc
= chardev_write(chardev
, large_buffer
, LARGE_BUFFER_SIZE
, &nbytes
);
124 chardev_close(chardev
);
126 return "Failed sending data";
129 TPRINTF("Sent %zu bytes\n", nbytes
);
131 rc
= chardev_read(chardev
, large_buffer
, LARGE_BUFFER_SIZE
, &nbytes
,
134 chardev_close(chardev
);
136 return "Failed receiving data";
139 TPRINTF("Received %zu bytes\n", nbytes
);
141 chardev_close(chardev
);
148 /** Test device where all transfers return partial success. */
149 static const char *test_chardev1_partialx(void)
157 TPRINTF("Test partially-successful character device operations\n");
159 rc
= loc_service_get_id(SERVICE_NAME_CHARDEV_TEST_PARTIALX
, &sid
, 0);
161 return "Failed resolving test device "
162 SERVICE_NAME_CHARDEV_TEST_SMALLX
;
165 sess
= loc_service_connect(sid
, INTERFACE_DDF
, 0);
167 return "Failed connecting test device";
169 rc
= chardev_open(sess
, &chardev
);
172 return "Failed opening test device";
175 rc
= chardev_write(chardev
, small_buffer
, SMALL_BUFFER_SIZE
, &nbytes
);
176 if (rc
!= EIO
|| nbytes
!= 1) {
177 chardev_close(chardev
);
179 return "Failed sending data";
182 TPRINTF("Sent %zu bytes and got rc = %s (expected)\n", nbytes
,
185 rc
= chardev_read(chardev
, small_buffer
, SMALL_BUFFER_SIZE
, &nbytes
,
187 if (rc
!= EIO
|| nbytes
!= 1) {
188 chardev_close(chardev
);
190 return "Failed receiving data";
193 TPRINTF("Received %zu bytes and got rc = %s (expected)\n", nbytes
,
196 chardev_close(chardev
);
203 const char *test_chardev1(void)
207 s
= test_chardev1_smallx();
211 s
= test_chardev1_largex();
215 return test_chardev1_partialx();