source: mainline/uspace/drv/bus/usb/usbdiag/tests.c@ ff16da5f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ff16da5f was ff16da5f, checked in by Petr Mánek <petr.manek@…>, 8 years ago

usbdiag: added isochronous test

  • Property mode set to 100644
File size: 6.1 KB
Line 
1/*
2 * Copyright (c) 2017 Petr Manek
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 drvusbdiag
30 * @{
31 */
32/**
33 * @file
34 * Code for executing diagnostic tests.
35 */
36#include <errno.h>
37#include <str_error.h>
38#include <usb/debug.h>
39#include "tests.h"
40
41#define NAME "usbdiag"
42
43
44int usb_diag_stress_intr_out(usb_diag_dev_t *dev, int cycles, size_t size)
45{
46 if (!dev)
47 return EBADMEM;
48
49 char *buffer = (char *) malloc(size);
50 if (!buffer)
51 return ENOMEM;
52
53 memset(buffer, 42, size);
54
55 // TODO: Are we sure that no other test is running on this endpoint?
56
57 usb_log_info("Performing interrupt out stress test on device %s.", ddf_fun_get_name(dev->fun));
58 int rc = EOK;
59 for (int i = 0; i < cycles; ++i) {
60 // Write buffer to device.
61 if ((rc = usb_pipe_write(dev->intr_out, buffer, size))) {
62 usb_log_error("Interrupt OUT write failed. %s\n", str_error(rc));
63 break;
64 }
65 }
66
67 free(buffer);
68 return rc;
69}
70
71int usb_diag_stress_intr_in(usb_diag_dev_t *dev, int cycles, size_t size)
72{
73 if (!dev)
74 return EBADMEM;
75
76 char *buffer = (char *) malloc(size);
77 if (!buffer)
78 return ENOMEM;
79
80 // TODO: Are we sure that no other test is running on this endpoint?
81
82 usb_log_info("Performing interrupt in stress test on device %s.", ddf_fun_get_name(dev->fun));
83 int rc = EOK;
84 for (int i = 0; i < cycles; ++i) {
85 // Read device's response.
86 size_t remaining = size;
87 size_t transferred;
88
89 while (remaining > 0) {
90 if ((rc = usb_pipe_read(dev->intr_in, buffer + size - remaining, remaining, &transferred))) {
91 usb_log_error("Interrupt IN read failed. %s\n", str_error(rc));
92 break;
93 }
94
95 if (transferred > remaining) {
96 usb_log_error("Interrupt IN read more than expected.\n");
97 rc = EINVAL;
98 break;
99 }
100
101 remaining -= transferred;
102 }
103
104 if (rc)
105 break;
106 }
107
108 free(buffer);
109 return rc;
110}
111
112int usb_diag_stress_bulk_out(usb_diag_dev_t *dev, int cycles, size_t size)
113{
114 if (!dev)
115 return EBADMEM;
116
117 char *buffer = (char *) malloc(size);
118 if (!buffer)
119 return ENOMEM;
120
121 memset(buffer, 42, size);
122
123 // TODO: Are we sure that no other test is running on this endpoint?
124
125 usb_log_info("Performing bulk out stress test on device %s.", ddf_fun_get_name(dev->fun));
126 int rc = EOK;
127 for (int i = 0; i < cycles; ++i) {
128 // Write buffer to device.
129 if ((rc = usb_pipe_write(dev->bulk_out, buffer, size))) {
130 usb_log_error("Bulk OUT write failed. %s\n", str_error(rc));
131 break;
132 }
133 }
134
135 free(buffer);
136 return rc;
137}
138
139int usb_diag_stress_bulk_in(usb_diag_dev_t *dev, int cycles, size_t size)
140{
141 if (!dev)
142 return EBADMEM;
143
144 char *buffer = (char *) malloc(size);
145 if (!buffer)
146 return ENOMEM;
147
148 // TODO: Are we sure that no other test is running on this endpoint?
149
150 usb_log_info("Performing bulk in stress test on device %s.", ddf_fun_get_name(dev->fun));
151 int rc = EOK;
152 for (int i = 0; i < cycles; ++i) {
153 // Read device's response.
154 size_t remaining = size;
155 size_t transferred;
156
157 while (remaining > 0) {
158 if ((rc = usb_pipe_read(dev->bulk_in, buffer + size - remaining, remaining, &transferred))) {
159 usb_log_error("Bulk IN read failed. %s\n", str_error(rc));
160 break;
161 }
162
163 if (transferred > remaining) {
164 usb_log_error("Bulk IN read more than expected.\n");
165 rc = EINVAL;
166 break;
167 }
168
169 remaining -= transferred;
170 }
171
172 if (rc)
173 break;
174 }
175
176 free(buffer);
177 return rc;
178}
179
180int usb_diag_stress_isoch_out(usb_diag_dev_t *dev, int cycles, size_t size)
181{
182 if (!dev)
183 return EBADMEM;
184
185 char *buffer = (char *) malloc(size);
186 if (!buffer)
187 return ENOMEM;
188
189 memset(buffer, 42, size);
190
191 // TODO: Are we sure that no other test is running on this endpoint?
192
193 usb_log_info("Performing isochronous out stress test on device %s.", ddf_fun_get_name(dev->fun));
194 int rc = EOK;
195 for (int i = 0; i < cycles; ++i) {
196 // Write buffer to device.
197 if ((rc = usb_pipe_write(dev->isoch_out, buffer, size))) {
198 usb_log_error("Isochronous OUT write failed. %s\n", str_error(rc));
199 break;
200 }
201 }
202
203 free(buffer);
204 return rc;
205}
206
207int usb_diag_stress_isoch_in(usb_diag_dev_t *dev, int cycles, size_t size)
208{
209 if (!dev)
210 return EBADMEM;
211
212 char *buffer = (char *) malloc(size);
213 if (!buffer)
214 return ENOMEM;
215
216 // TODO: Are we sure that no other test is running on this endpoint?
217
218 usb_log_info("Performing isochronous in stress test on device %s.", ddf_fun_get_name(dev->fun));
219 int rc = EOK;
220 for (int i = 0; i < cycles; ++i) {
221 // Read device's response.
222 size_t remaining = size;
223 size_t transferred;
224
225 while (remaining > 0) {
226 if ((rc = usb_pipe_read(dev->isoch_in, buffer + size - remaining, remaining, &transferred))) {
227 usb_log_error("Isochronous IN read failed. %s\n", str_error(rc));
228 break;
229 }
230
231 if (transferred > remaining) {
232 usb_log_error("Isochronous IN read more than expected.\n");
233 rc = EINVAL;
234 break;
235 }
236
237 remaining -= transferred;
238 }
239
240 if (rc)
241 break;
242 }
243
244 free(buffer);
245 return rc;
246}
247
248/**
249 * @}
250 */
Note: See TracBrowser for help on using the repository browser.