Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset fd312d5 in mainline


Ignore:
Timestamp:
2017-12-20T16:06:56Z (4 years ago)
Author:
Petr Mánek <petr.manek@…>
Branches:
lfn, master
Children:
cec130b
Parents:
f98f4b7
Message:

usbdiag: more robust testing framework, added bulk in stress test, refactored remote usbdiag interface, new command for tmon

Location:
uspace
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/tmon/commands.h

    rf98f4b7 rfd312d5  
    3838
    3939int tmon_list(int, char **);
    40 int tmon_test_bulk(int, char **);
     40int tmon_stress_bulk_in(int, char **);
     41int tmon_stress_bulk_out(int, char **);
    4142
    4243#endif /* TMON_COMMANDS_H_ */
  • uspace/app/tmon/main.c

    rf98f4b7 rfd312d5  
    4040#define NAME "tmon"
    4141
    42 static int fallback(int argc, char *argv[])
    43 {
    44         // FIXME
    45         printf(NAME ": Not implemented, lol!\n");
    46         return 1;
    47 }
    48 
    4942typedef struct {
    5043        const char *name;
     
    6053        },
    6154        {
    62                 .name = "test-bulk",
    63                 .description = "Benchmark bulk endpoints 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,
    6558        },
    6659        {
    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,
    7563        },
    7664        {
  • uspace/app/tmon/test.c

    rf98f4b7 rfd312d5  
    114114}
    115115
    116 static int bulk_worker(devman_handle_t fun) {
     116static int stress_bulk_in(devman_handle_t fun) {
    117117        async_sess_t *sess = usbdiag_connect(fun);
    118118        async_exch_t *exch = async_exchange_begin(sess);
    119119
    120         // TODO: do some testing
    121         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);
    123123
    124124        if (rc) {
    125125                printf(NAME ": %s\n", str_error(rc));
    126         } else {
    127                 printf("The number is %d.\n", y);
    128126        }
    129127
     
    133131}
    134132
    135 int tmon_test_bulk(int argc, char *argv[])
     133static 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
     150int tmon_stress_bulk_in(int argc, char *argv[])
    136151{
    137         return resolve_and_test(argc, argv, bulk_worker);
     152        return resolve_and_test(argc, argv, stress_bulk_in);
     153}
     154
     155int tmon_stress_bulk_out(int argc, char *argv[])
     156{
     157        return resolve_and_test(argc, argv, stress_bulk_out);
    138158}
    139159
  • uspace/drv/bus/usb/usbdiag/Makefile

    rf98f4b7 rfd312d5  
    3535SOURCES = \
    3636        device.c \
     37        tests.c \
    3738        main.c \
    3839
  • uspace/drv/bus/usb/usbdiag/device.c

    rf98f4b7 rfd312d5  
    4141
    4242#include "device.h"
     43#include "tests.h"
    4344
    4445#define NAME "usbdiag"
    4546
    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);\
    5953        }
    6054
    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 }
     55TRANSLATE_FUNC(usb_diag_stress_bulk_out)
     56TRANSLATE_FUNC(usb_diag_stress_bulk_in)
    8657
    8758static 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)
    8961};
     62
     63#undef TRANSLATE_FUNC_NAME
     64#undef TRANSLATE_FUNC
    9065
    9166static ddf_dev_ops_t diag_ops = {
     
    10580        dev->fun = fun;
    10681
    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);
    10991
    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);
    11598
    116         dev->bulk_out = &epm_out->pipe;
    117         dev->bulk_in = &epm_in->pipe;
     99#undef _MAP_EP
    118100
    119101        return EOK;
  • uspace/drv/bus/usb/usbdiag/device.h

    rf98f4b7 rfd312d5  
    5252        usb_device_t *usb_dev;
    5353        ddf_fun_t *fun;
     54        usb_pipe_t *intr_in;
     55        usb_pipe_t *intr_out;
    5456        usb_pipe_t *bulk_in;
    5557        usb_pipe_t *bulk_out;
     58        usb_pipe_t *isoch_in;
     59        usb_pipe_t *isoch_out;
    5660} usb_diag_dev_t;
    5761
  • uspace/lib/drv/generic/remote_usbdiag.c

    rf98f4b7 rfd312d5  
    4343
    4444typedef enum {
    45         IPC_M_USBDIAG_TEST,
     45        IPC_M_USBDIAG_STRESS_BULK_OUT,
     46        IPC_M_USBDIAG_STRESS_BULK_IN
    4647} usb_iface_funcs_t;
    4748
     
    5758}
    5859
    59 int usbdiag_test(async_exch_t *exch, int x, int *y)
     60int usbdiag_stress_bulk_out(async_exch_t *exch, int cycles, size_t size)
    6061{
    6162        if (!exch)
    6263                return EBADMEM;
    6364
    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);
    7166}
    7267
    73 static void remote_usbdiag_test(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     68int 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
     76static void remote_usbdiag_stress_bulk_out(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     77static void remote_usbdiag_stress_bulk_in(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    7478
    7579/** Remote USB diagnostic interface operations. */
    7680static 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,
    7883};
    7984
     
    8489};
    8590
    86 void remote_usbdiag_test(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
     91void remote_usbdiag_stress_bulk_out(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
    8792{
    8893        const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
    8994
    90         if (diag_iface->test == NULL) {
     95        if (diag_iface->stress_bulk_out == NULL) {
    9196                async_answer_0(callid, ENOTSUP);
    9297                return;
    9398        }
    9499
    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
     106void 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;
    102113        }
     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);
    103119}
    104120
  • uspace/lib/drv/include/usbdiag_iface.h

    rf98f4b7 rfd312d5  
    4545async_sess_t *usbdiag_connect(devman_handle_t);
    4646void usbdiag_disconnect(async_sess_t*);
    47 int usbdiag_test(async_exch_t*, int, int*);
     47int usbdiag_stress_bulk_in(async_exch_t*, int, size_t);
     48int usbdiag_stress_bulk_out(async_exch_t*, int, size_t);
    4849
    4950/** USB diagnostic device communication interface. */
    5051typedef 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);
    5254} usbdiag_iface_t;
    5355
Note: See TracChangeset for help on using the changeset viewer.