Changeset fd312d5 in mainline
- Timestamp:
- 2017-12-20T16:06:56Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cec130b
- Parents:
- f98f4b7
- Location:
- uspace
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tmon/commands.h
rf98f4b7 rfd312d5 38 38 39 39 int tmon_list(int, char **); 40 int tmon_test_bulk(int, char **); 40 int tmon_stress_bulk_in(int, char **); 41 int tmon_stress_bulk_out(int, char **); 41 42 42 43 #endif /* TMON_COMMANDS_H_ */ -
uspace/app/tmon/main.c
rf98f4b7 rfd312d5 40 40 #define NAME "tmon" 41 41 42 static int fallback(int argc, char *argv[])43 {44 // FIXME45 printf(NAME ": Not implemented, lol!\n");46 return 1;47 }48 49 42 typedef struct { 50 43 const char *name; … … 60 53 }, 61 54 { 62 .name = " test-bulk",63 .description = " Benchmark bulkendpoints of a diagnostic device.",64 .action = tmon_ test_bulk,55 .name = "stress-bulk-in", 56 .description = "Stress benchmark bulk in endpoints of a diagnostic device.", 57 .action = tmon_stress_bulk_in, 65 58 }, 66 59 { 67 .name = "test-intr", 68 .description = "Benchmark interrupt endpoints of a diagnostic device.", 69 .action = fallback, 70 }, 71 { 72 .name = "test-isoch", 73 .description = "Benchmark isochronous endpoints of a diagnostic device.", 74 .action = fallback, 60 .name = "stress-bulk-out", 61 .description = "Benchmark bulk out endpoints of a diagnostic device.", 62 .action = tmon_stress_bulk_out, 75 63 }, 76 64 { -
uspace/app/tmon/test.c
rf98f4b7 rfd312d5 114 114 } 115 115 116 static int bulk_worker(devman_handle_t fun) {116 static int stress_bulk_in(devman_handle_t fun) { 117 117 async_sess_t *sess = usbdiag_connect(fun); 118 118 async_exch_t *exch = async_exchange_begin(sess); 119 119 120 // TODO: do some testing121 int y;122 int rc = usbdiag_ test(exch, 4200, &y);120 const int cycles = 1024; 121 const size_t size = 65432; 122 int rc = usbdiag_stress_bulk_in(exch, cycles, size); 123 123 124 124 if (rc) { 125 125 printf(NAME ": %s\n", str_error(rc)); 126 } else {127 printf("The number is %d.\n", y);128 126 } 129 127 … … 133 131 } 134 132 135 int tmon_test_bulk(int argc, char *argv[]) 133 static int stress_bulk_out(devman_handle_t fun) { 134 async_sess_t *sess = usbdiag_connect(fun); 135 async_exch_t *exch = async_exchange_begin(sess); 136 137 const int cycles = 1024; 138 const size_t size = 65432; 139 int rc = usbdiag_stress_bulk_out(exch, cycles, size); 140 141 if (rc) { 142 printf(NAME ": %s\n", str_error(rc)); 143 } 144 145 async_exchange_end(exch); 146 usbdiag_disconnect(sess); 147 return 0; 148 } 149 150 int tmon_stress_bulk_in(int argc, char *argv[]) 136 151 { 137 return resolve_and_test(argc, argv, bulk_worker); 152 return resolve_and_test(argc, argv, stress_bulk_in); 153 } 154 155 int tmon_stress_bulk_out(int argc, char *argv[]) 156 { 157 return resolve_and_test(argc, argv, stress_bulk_out); 138 158 } 139 159 -
uspace/drv/bus/usb/usbdiag/Makefile
rf98f4b7 rfd312d5 35 35 SOURCES = \ 36 36 device.c \ 37 tests.c \ 37 38 main.c \ 38 39 -
uspace/drv/bus/usb/usbdiag/device.c
rf98f4b7 rfd312d5 41 41 42 42 #include "device.h" 43 #include "tests.h" 43 44 44 45 #define NAME "usbdiag" 45 46 46 47 static int some_test(ddf_fun_t *fun, int x, int *y) 48 { 49 int rc = EOK; 50 usb_diag_dev_t *dev = ddf_fun_to_usb_diag_dev(fun); 51 52 const size_t size = min(dev->bulk_in->desc.max_packet_size, dev->bulk_out->desc.max_packet_size); 53 char *buffer = (char *) malloc(size); 54 memset(buffer, 42, sizeof(buffer)); 55 56 // Write buffer to device. 57 if ((rc = usb_pipe_write(dev->bulk_out, buffer, size))) { 58 usb_log_error("Bulk OUT write failed. %s\n", str_error(rc)); 47 #define TRANSLATE_FUNC_NAME(fun) translate_##fun 48 #define TRANSLATE_FUNC(fun) \ 49 static int TRANSLATE_FUNC_NAME(fun)(ddf_fun_t *f, int cycles, size_t size)\ 50 {\ 51 usb_diag_dev_t *dev = ddf_fun_to_usb_diag_dev(f);\ 52 return fun(dev, cycles, size);\ 59 53 } 60 54 61 // Read device's response. 62 size_t remaining = size; 63 size_t transferred; 64 while (remaining > 0) { 65 if ((rc = usb_pipe_read(dev->bulk_in, buffer + size - remaining, remaining, &transferred))) { 66 usb_log_error("Bulk IN read failed. %s\n", str_error(rc)); 67 break; 68 } 69 70 if (transferred > remaining) { 71 usb_log_error("Bulk IN read more than expected.\n"); 72 rc = EINVAL; 73 break; 74 } 75 76 remaining -= transferred; 77 } 78 79 // TODO: Check output? 80 81 free(buffer); 82 83 *y = x + 42; 84 return rc; 85 } 55 TRANSLATE_FUNC(usb_diag_stress_bulk_out) 56 TRANSLATE_FUNC(usb_diag_stress_bulk_in) 86 57 87 58 static usbdiag_iface_t diag_interface = { 88 .test = some_test, 59 .stress_bulk_out = TRANSLATE_FUNC_NAME(usb_diag_stress_bulk_out), 60 .stress_bulk_in = TRANSLATE_FUNC_NAME(usb_diag_stress_bulk_in) 89 61 }; 62 63 #undef TRANSLATE_FUNC_NAME 64 #undef TRANSLATE_FUNC 90 65 91 66 static ddf_dev_ops_t diag_ops = { … … 105 80 dev->fun = fun; 106 81 107 usb_endpoint_mapping_t *epm_out = usb_device_get_mapped_ep(dev->usb_dev, USB_DIAG_EP_BULK_OUT); 108 usb_endpoint_mapping_t *epm_in = usb_device_get_mapped_ep(dev->usb_dev, USB_DIAG_EP_BULK_IN); 82 #define _MAP_EP(target, ep_no) do {\ 83 usb_endpoint_mapping_t *epm = usb_device_get_mapped_ep(dev->usb_dev, USB_DIAG_EP_##ep_no);\ 84 if (!epm || !epm->present) {\ 85 usb_log_error("Failed to map endpoint: " #ep_no ".\n");\ 86 rc = ENOENT;\ 87 goto err_fun;\ 88 }\ 89 target = &epm->pipe;\ 90 } while (0); 109 91 110 if (!epm_in || !epm_out || !epm_in->present || !epm_out->present) { 111 usb_log_error("Required EPs were not mapped.\n"); 112 rc = ENOENT; 113 goto err_fun; 114 } 92 _MAP_EP(dev->intr_in, INTR_IN); 93 _MAP_EP(dev->intr_out, INTR_OUT); 94 _MAP_EP(dev->bulk_in, BULK_IN); 95 _MAP_EP(dev->bulk_out, BULK_OUT); 96 _MAP_EP(dev->isoch_in, ISOCH_IN); 97 _MAP_EP(dev->isoch_out, ISOCH_OUT); 115 98 116 dev->bulk_out = &epm_out->pipe; 117 dev->bulk_in = &epm_in->pipe; 99 #undef _MAP_EP 118 100 119 101 return EOK; -
uspace/drv/bus/usb/usbdiag/device.h
rf98f4b7 rfd312d5 52 52 usb_device_t *usb_dev; 53 53 ddf_fun_t *fun; 54 usb_pipe_t *intr_in; 55 usb_pipe_t *intr_out; 54 56 usb_pipe_t *bulk_in; 55 57 usb_pipe_t *bulk_out; 58 usb_pipe_t *isoch_in; 59 usb_pipe_t *isoch_out; 56 60 } usb_diag_dev_t; 57 61 -
uspace/lib/drv/generic/remote_usbdiag.c
rf98f4b7 rfd312d5 43 43 44 44 typedef enum { 45 IPC_M_USBDIAG_TEST, 45 IPC_M_USBDIAG_STRESS_BULK_OUT, 46 IPC_M_USBDIAG_STRESS_BULK_IN 46 47 } usb_iface_funcs_t; 47 48 … … 57 58 } 58 59 59 int usbdiag_ test(async_exch_t *exch, int x, int *y)60 int usbdiag_stress_bulk_out(async_exch_t *exch, int cycles, size_t size) 60 61 { 61 62 if (!exch) 62 63 return EBADMEM; 63 64 64 sysarg_t y_; 65 const int ret = async_req_2_1(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_TEST, x, &y_); 66 67 if (y) 68 *y = (int) y_; 69 70 return ret; 65 return async_req_3_0(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_STRESS_BULK_OUT, cycles, size); 71 66 } 72 67 73 static void remote_usbdiag_test(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 68 int usbdiag_stress_bulk_in(async_exch_t *exch, int cycles, size_t size) 69 { 70 if (!exch) 71 return EBADMEM; 72 73 return async_req_3_0(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_STRESS_BULK_IN, cycles, size); 74 } 75 76 static void remote_usbdiag_stress_bulk_out(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 77 static void remote_usbdiag_stress_bulk_in(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 74 78 75 79 /** Remote USB diagnostic interface operations. */ 76 80 static const remote_iface_func_ptr_t remote_usbdiag_iface_ops [] = { 77 [IPC_M_USBDIAG_TEST] = remote_usbdiag_test, 81 [IPC_M_USBDIAG_STRESS_BULK_OUT] = remote_usbdiag_stress_bulk_out, 82 [IPC_M_USBDIAG_STRESS_BULK_IN] = remote_usbdiag_stress_bulk_in, 78 83 }; 79 84 … … 84 89 }; 85 90 86 void remote_usbdiag_ test(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)91 void remote_usbdiag_stress_bulk_out(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call) 87 92 { 88 93 const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface; 89 94 90 if (diag_iface-> test == NULL) {95 if (diag_iface->stress_bulk_out == NULL) { 91 96 async_answer_0(callid, ENOTSUP); 92 97 return; 93 98 } 94 99 95 int x = DEV_IPC_GET_ARG1(*call); 96 int y; 97 const int ret = diag_iface->test(fun, x, &y); 98 if (ret != EOK) { 99 async_answer_0(callid, ret); 100 } else { 101 async_answer_1(callid, EOK, y); 100 int cycles = DEV_IPC_GET_ARG1(*call); 101 size_t size = DEV_IPC_GET_ARG2(*call); 102 const int ret = diag_iface->stress_bulk_out(fun, cycles, size); 103 async_answer_0(callid, ret); 104 } 105 106 void remote_usbdiag_stress_bulk_in(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call) 107 { 108 const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface; 109 110 if (diag_iface->stress_bulk_in == NULL) { 111 async_answer_0(callid, ENOTSUP); 112 return; 102 113 } 114 115 int cycles = DEV_IPC_GET_ARG1(*call); 116 size_t size = DEV_IPC_GET_ARG2(*call); 117 const int ret = diag_iface->stress_bulk_in(fun, cycles, size); 118 async_answer_0(callid, ret); 103 119 } 104 120 -
uspace/lib/drv/include/usbdiag_iface.h
rf98f4b7 rfd312d5 45 45 async_sess_t *usbdiag_connect(devman_handle_t); 46 46 void usbdiag_disconnect(async_sess_t*); 47 int usbdiag_test(async_exch_t*, int, int*); 47 int usbdiag_stress_bulk_in(async_exch_t*, int, size_t); 48 int usbdiag_stress_bulk_out(async_exch_t*, int, size_t); 48 49 49 50 /** USB diagnostic device communication interface. */ 50 51 typedef struct { 51 int (*test)(ddf_fun_t*, int, int*); 52 int (*stress_bulk_in)(ddf_fun_t*, int, size_t); 53 int (*stress_bulk_out)(ddf_fun_t*, int, size_t); 52 54 } usbdiag_iface_t; 53 55
Note:
See TracChangeset
for help on using the changeset viewer.