source: mainline/uspace/app/tmon/test.c@ e9d600c2

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

usbdiag: added interrupt endpoint tests, printing tmon device path

  • Property mode set to 100644
File size: 5.5 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 tmon
30 * @{
31 */
32/**
33 * @file
34 * USB transfer debugging.
35 */
36
37#include <stdio.h>
38#include <devman.h>
39#include <loc.h>
40#include <errno.h>
41#include <str_error.h>
42#include <usbdiag_iface.h>
43#include "commands.h"
44
45#define NAME "tmon"
46#define MAX_PATH_LENGTH 1024
47
48#define DEFAULT_CYCLES 1024
49#define DEFAULT_SIZE 65432
50
51static int resolve_default_fun(devman_handle_t *fun)
52{
53 category_id_t diag_cat;
54 service_id_t *svcs;
55 size_t count;
56 int rc;
57
58 if ((rc = loc_category_get_id(USBDIAG_CATEGORY, &diag_cat, 0))) {
59 printf(NAME ": Error resolving category '%s'", USBDIAG_CATEGORY);
60 return rc;
61 }
62
63 if ((rc = loc_category_get_svcs(diag_cat, &svcs, &count))) {
64 printf(NAME ": Error getting list of diagnostic devices.\n");
65 return rc;
66 }
67
68 // There must be exactly one diagnostic device for this to work.
69 if (count != 1) {
70 if (count) {
71 printf(NAME ": Found %ld devices. Please specify which to use.\n", count);
72 } else {
73 printf(NAME ": No diagnostic devices found.\n");
74 }
75 return ENOENT;
76 }
77
78 if ((rc = devman_fun_sid_to_handle(svcs[0], fun))) {
79 printf(NAME ": Error resolving handle of device with SID %ld.\n", svcs[0]);
80 return rc;
81 }
82
83 return EOK;
84}
85
86static int resolve_named_fun(const char *dev_path, devman_handle_t *fun)
87{
88 int rc;
89 service_id_t svc;
90 if ((rc = loc_service_get_id(dev_path, &svc, IPC_FLAG_BLOCKING))) {
91 printf(NAME ": Error resolving device. %s\n", str_error(rc));
92 return rc;
93 }
94
95 if ((rc = devman_fun_sid_to_handle(svc, fun))) {
96 printf(NAME ": Error resolving handle of device with SID %ld.\n", svc);
97 return rc;
98 }
99
100 return EOK;
101}
102
103static int resolve_and_test(int argc, char *argv[], int (*test)(devman_handle_t, int, size_t)) {
104 devman_handle_t fun = -1;
105
106 if (argc == 0) {
107 if (resolve_default_fun(&fun))
108 return 1;
109 } else if (argc == 1) {
110 if (resolve_named_fun(argv[0], &fun))
111 return 1;
112 } else {
113 printf(NAME ": Too many arguments provided.\n");
114 return 1;
115 }
116
117 int rc;
118 char path[MAX_PATH_LENGTH];
119 if ((rc = devman_fun_get_path(fun, path, sizeof(path)))) {
120 printf(NAME ": Error resolving path of device with handle %ld. %s\n", fun, str_error(rc));
121 return 1;
122 }
123
124 printf("Using device: %s\n", path);
125
126 // TODO: Read options here.
127
128 return test(fun, DEFAULT_CYCLES, DEFAULT_SIZE);
129}
130
131static int stress_intr_in(devman_handle_t fun, int cycles, size_t size) {
132 async_sess_t *sess = usbdiag_connect(fun);
133 async_exch_t *exch = async_exchange_begin(sess);
134
135 int rc = usbdiag_stress_intr_in(exch, cycles, size);
136 int ec = 0;
137
138 if (rc) {
139 printf(NAME ": %s\n", str_error(rc));
140 ec = 1;
141 }
142
143 async_exchange_end(exch);
144 usbdiag_disconnect(sess);
145 return ec;
146}
147
148static int stress_intr_out(devman_handle_t fun, int cycles, size_t size) {
149 async_sess_t *sess = usbdiag_connect(fun);
150 async_exch_t *exch = async_exchange_begin(sess);
151
152 int rc = usbdiag_stress_intr_out(exch, cycles, size);
153 int ec = 0;
154
155 if (rc) {
156 printf(NAME ": %s\n", str_error(rc));
157 ec = 1;
158 }
159
160 async_exchange_end(exch);
161 usbdiag_disconnect(sess);
162 return ec;
163}
164
165static int stress_bulk_in(devman_handle_t fun, int cycles, size_t size) {
166 async_sess_t *sess = usbdiag_connect(fun);
167 async_exch_t *exch = async_exchange_begin(sess);
168
169 int rc = usbdiag_stress_bulk_in(exch, cycles, size);
170 int ec = 0;
171
172 if (rc) {
173 printf(NAME ": %s\n", str_error(rc));
174 ec = 1;
175 }
176
177 async_exchange_end(exch);
178 usbdiag_disconnect(sess);
179 return ec;
180}
181
182static int stress_bulk_out(devman_handle_t fun, int cycles, size_t size) {
183 async_sess_t *sess = usbdiag_connect(fun);
184 async_exch_t *exch = async_exchange_begin(sess);
185
186 int rc = usbdiag_stress_bulk_out(exch, cycles, size);
187 int ec = 0;
188
189 if (rc) {
190 printf(NAME ": %s\n", str_error(rc));
191 ec = 1;
192 }
193
194 async_exchange_end(exch);
195 usbdiag_disconnect(sess);
196 return ec;
197}
198
199int tmon_stress_intr_in(int argc, char *argv[])
200{
201 return resolve_and_test(argc, argv, stress_intr_in);
202}
203
204int tmon_stress_intr_out(int argc, char *argv[])
205{
206 return resolve_and_test(argc, argv, stress_intr_out);
207}
208
209int tmon_stress_bulk_in(int argc, char *argv[])
210{
211 return resolve_and_test(argc, argv, stress_bulk_in);
212}
213
214int tmon_stress_bulk_out(int argc, char *argv[])
215{
216 return resolve_and_test(argc, argv, stress_bulk_out);
217}
218
219/** @}
220 */
Note: See TracBrowser for help on using the repository browser.