Changeset d37dd3b9 in mainline


Ignore:
Timestamp:
2017-12-21T09:37:58Z (6 years ago)
Author:
Petr Mánek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0fbe27d
Parents:
ad2a8b1
Message:

tmon: more refactoring, removed some duplicate code, included resolving files, printing more error messages

Location:
uspace/app/tmon
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/tmon/test.c

    rad2a8b1 rd37dd3b9  
    4848#define DEFAULT_SIZE    65432
    4949
    50 static int resolve_and_test(int argc, char *argv[], int (*test)(devman_handle_t, int, size_t)) {
     50static int resolve_and_test(int argc, char *argv[], int (*test)(async_exch_t *, int, size_t)) {
    5151        devman_handle_t fun = -1;
    5252
     
    6262        }
    6363
    64         int rc;
     64        int rc, ec;
    6565        char path[MAX_PATH_LENGTH];
    6666        if ((rc = devman_fun_get_path(fun, path, sizeof(path)))) {
     
    7373        // TODO: Read options here.
    7474
    75         return test(fun, DEFAULT_CYCLES, DEFAULT_SIZE);
    76 }
    77 
    78 static int stress_intr_in(devman_handle_t fun, int cycles, size_t size) {
    7975        async_sess_t *sess = usbdiag_connect(fun);
    80         async_exch_t *exch = async_exchange_begin(sess);
    81 
    82         int rc = usbdiag_stress_intr_in(exch, cycles, size);
    83         int ec = 0;
    84 
    85         if (rc) {
    86                 printf(NAME ": %s\n", str_error(rc));
    87                 ec = 1;
     76        if (!sess) {
     77                printf(NAME ": Could not connect to the device.\n");
     78                return 1;
    8879        }
    8980
     81        async_exch_t *exch = async_exchange_begin(sess);
     82        if (!exch) {
     83                printf(NAME ": Could not start exchange with the device.\n");
     84                ec = 1;
     85                goto err_sess;
     86        }
     87
     88        ec = test(exch, DEFAULT_CYCLES, DEFAULT_SIZE);
    9089        async_exchange_end(exch);
     90
     91err_sess:
    9192        usbdiag_disconnect(sess);
    9293        return ec;
    9394}
    9495
    95 static int stress_intr_out(devman_handle_t fun, int cycles, size_t size) {
    96         async_sess_t *sess = usbdiag_connect(fun);
    97         async_exch_t *exch = async_exchange_begin(sess);
    98 
    99         int rc = usbdiag_stress_intr_out(exch, cycles, size);
    100         int ec = 0;
    101 
     96static int stress_intr_in(async_exch_t *exch, int cycles, size_t size)
     97{
     98        int rc = usbdiag_stress_intr_in(exch, cycles, size);
    10299        if (rc) {
    103100                printf(NAME ": %s\n", str_error(rc));
    104                 ec = 1;
     101                return 1;
    105102        }
    106103
    107         async_exchange_end(exch);
    108         usbdiag_disconnect(sess);
    109         return ec;
     104        return 0;
    110105}
    111106
    112 static int stress_bulk_in(devman_handle_t fun, int cycles, size_t size) {
    113         async_sess_t *sess = usbdiag_connect(fun);
    114         async_exch_t *exch = async_exchange_begin(sess);
    115 
    116         int rc = usbdiag_stress_bulk_in(exch, cycles, size);
    117         int ec = 0;
    118 
     107static int stress_intr_out(async_exch_t *exch, int cycles, size_t size)
     108{
     109        int rc = usbdiag_stress_intr_out(exch, cycles, size);
    119110        if (rc) {
    120111                printf(NAME ": %s\n", str_error(rc));
    121                 ec = 1;
     112                return 1;
    122113        }
    123114
    124         async_exchange_end(exch);
    125         usbdiag_disconnect(sess);
    126         return ec;
     115        return 0;
    127116}
    128117
    129 static int stress_bulk_out(devman_handle_t fun, int cycles, size_t size) {
    130         async_sess_t *sess = usbdiag_connect(fun);
    131         async_exch_t *exch = async_exchange_begin(sess);
    132 
    133         int rc = usbdiag_stress_bulk_out(exch, cycles, size);
    134         int ec = 0;
    135 
     118static int stress_bulk_in(async_exch_t *exch, int cycles, size_t size)
     119{
     120        int rc = usbdiag_stress_bulk_in(exch, cycles, size);
    136121        if (rc) {
    137122                printf(NAME ": %s\n", str_error(rc));
    138                 ec = 1;
     123                return 1;
    139124        }
    140125
    141         async_exchange_end(exch);
    142         usbdiag_disconnect(sess);
    143         return ec;
     126        return 0;
     127}
     128
     129static int stress_bulk_out(async_exch_t *exch, int cycles, size_t size)
     130{
     131        int rc = usbdiag_stress_bulk_out(exch, cycles, size);
     132        if (rc) {
     133                printf(NAME ": %s\n", str_error(rc));
     134                return 1;
     135        }
     136
     137        return 0;
    144138}
    145139
Note: See TracChangeset for help on using the changeset viewer.