Changeset 3b5a5e3 in mainline


Ignore:
Timestamp:
2018-02-01T16:10:12Z (6 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3038d51
Parents:
8393c73b
git-author:
Petr Manek <petr.manek@…> (2018-02-01 16:09:43)
git-committer:
Petr Manek <petr.manek@…> (2018-02-01 16:10:12)
Message:

tmon: catch up with libdrv changes, simplify code

Location:
uspace/app/tmon
Files:
1 added
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/tmon/Makefile

    r8393c73b r3b5a5e3  
    3030BINARY = tmon
    3131
    32 LIBS = drv
     32LIBS = drv usb
    3333
    3434SOURCES = \
     
    3636        list.c\
    3737        tf.c\
    38         burst_tests.c\
     38        tests.c\
    3939        resolve.c
    4040
  • uspace/app/tmon/commands.h

    r8393c73b r3b5a5e3  
    4242int tmon_list(int, char **);
    4343
    44 /* Burst tests read/write into endpoints as fast as possible. */
    45 int tmon_burst_intr_in(int, char **);
    46 int tmon_burst_intr_out(int, char **);
    47 int tmon_burst_bulk_in(int, char **);
    48 int tmon_burst_bulk_out(int, char **);
    49 int tmon_burst_isoch_in(int, char **);
    50 int tmon_burst_isoch_out(int, char **);
     44/* Tests commands differ by endpoint types. */
     45int tmon_test_intr_in(int, char **);
     46int tmon_test_intr_out(int, char **);
     47int tmon_test_bulk_in(int, char **);
     48int tmon_test_bulk_out(int, char **);
     49int tmon_test_isoch_in(int, char **);
     50int tmon_test_isoch_out(int, char **);
    5151
    5252#endif /* TMON_COMMANDS_H_ */
  • uspace/app/tmon/main.c

    r8393c73b r3b5a5e3  
    6262                .name = "test-intr-in",
    6363                .description = "Read from interrupt endpoint as fast as possible.",
    64                 .action = tmon_burst_intr_in,
     64                .action = tmon_test_intr_in,
    6565        },
    6666        {
    6767                .name = "test-intr-out",
    6868                .description = "Write to interrupt endpoint as fast as possible.",
    69                 .action = tmon_burst_intr_out,
     69                .action = tmon_test_intr_out,
    7070        },
    7171        {
    7272                .name = "test-bulk-in",
    7373                .description = "Read from bulk endpoint as fast as possible.",
    74                 .action = tmon_burst_bulk_in,
     74                .action = tmon_test_bulk_in,
    7575        },
    7676        {
    7777                .name = "test-bulk-out",
    7878                .description = "Write to bulk endpoint as fast as possible.",
    79                 .action = tmon_burst_bulk_out,
     79                .action = tmon_test_bulk_out,
    8080        },
    8181        {
    8282                .name = "test-isoch-in",
    8383                .description = "Read from isochronous endpoint as fast as possible.",
    84                 .action = tmon_burst_isoch_in,
     84                .action = tmon_test_isoch_in,
    8585        },
    8686        {
    8787                .name = "test-isoch-out",
    8888                .description = "Write to isochronous endpoint as fast as possible.",
    89                 .action = tmon_burst_isoch_out,
    90         }
     89                .action = tmon_test_isoch_out,
     90        },
    9191};
    9292
     
    104104static tmon_opt_t options[] = {
    105105        {
    106                 .long_name = "cycles",
    107                 .short_name = 'n',
    108                 .description = "Set the number of read/write cycles."
     106                .long_name = "duration",
     107                .short_name = 't',
     108                .description = "Set the minimum test duration (in seconds)."
    109109        },
    110110        {
    111111                .long_name = "size",
    112112                .short_name = 's',
    113                 .description = "Set the data size transferred in a single cycle."
    114         }
     113                .description = "Set the data size (in bytes) transferred in a single cycle."
     114        },
     115        {
     116                .long_name = "validate",
     117                .short_name = 'v',
     118                .description = "Validate the correctness of transferred data (impacts performance)."
     119        },
    115120};
    116121
  • uspace/app/tmon/tf.c

    r8393c73b r3b5a5e3  
    3636
    3737#include <stdio.h>
     38#include <macros.h>
    3839#include <devman.h>
    3940#include <str_error.h>
     
    7475        }
    7576
    76         printf("Using device: %s\n", path);
     77        printf("Device: %s\n", path);
    7778
    7879        // Read test parameters from options.
    79         tmon_test_params_t *params = NULL;
     80        void *params = NULL;
    8081        if ((rc = ops->read_params(argc, argv, &params))) {
    8182                printf(NAME ": Reading test parameters failed. %s\n", str_error(rc));
     83                return 1;
     84        }
     85
     86        if ((rc = ops->pre_run(params))) {
     87                printf(NAME ": Pre-run hook failed. %s\n", str_error(rc));
    8288                return 1;
    8389        }
     
    106112}
    107113
     114/** Unit of quantity used for pretty formatting. */
     115typedef struct tmon_unit {
     116        /** Prefix letter, which is printed before the actual unit. */
     117        const char *unit;
     118        /** Factor of the unit. */
     119        double factor;
     120} tmon_unit_t;
     121
     122/** Format a value for human reading.
     123 * @param[in] val The value to format.
     124 * @param[in] fmt Format string. Must include one double and char.
     125 *
     126 * @return Heap-allocated string if successful (caller becomes its owner), NULL otherwise.
     127 */
     128static char *format_unit(double val, const char *fmt, const tmon_unit_t *units, size_t len)
     129{
     130        // Figure out the "tightest" unit.
     131        unsigned i;
     132        for (i = 0; i < len; ++i) {
     133                if (units[i].factor <= val)
     134                        break;
     135        }
     136
     137        if (i == len) --i;
     138        const char *unit = units[i].unit;
     139        double factor = units[i].factor;
     140
     141        // Format the size.
     142        const double div_size = val / factor;
     143
     144        char *out = NULL;
     145        asprintf(&out, fmt, div_size, unit);
     146
     147        return out;
     148}
     149
     150/** Static array of size units with decreasing factors. */
     151static const tmon_unit_t size_units[] = {
     152        { .unit = "EB", .factor = 1ULL << 60 },
     153        { .unit = "PB", .factor = 1ULL << 50 },
     154        { .unit = "TB", .factor = 1ULL << 40 },
     155        { .unit = "GB", .factor = 1ULL << 30 },
     156        { .unit = "MB", .factor = 1ULL << 20 },
     157        { .unit = "kB", .factor = 1ULL << 10 },
     158        { .unit = "B",  .factor = 1ULL },
     159};
     160
     161char *tmon_format_size(double val, const char *fmt)
     162{
     163        return format_unit(val, fmt, size_units, ARRAY_SIZE(size_units));
     164}
     165
     166/** Static array of duration units with decreasing factors. */
     167static const tmon_unit_t dur_units[] = {
     168        { .unit = "d",   .factor = 60 * 60 * 24 },
     169        { .unit = "h",   .factor = 60 * 60 },
     170        { .unit = "min", .factor = 60 },
     171        { .unit = "s",   .factor = 1 },
     172        { .unit = "ms",  .factor = 1e-3 },
     173        { .unit = "us",  .factor = 1e-6 },
     174        { .unit = "ns",  .factor = 1e-9 },
     175        { .unit = "ps",  .factor = 1e-12 },
     176};
     177
     178char *tmon_format_duration(usbdiag_dur_t val, const char *fmt)
     179{
     180        return format_unit(val / 1000.0, fmt, dur_units, ARRAY_SIZE(dur_units));
     181}
     182
    108183/** @}
    109184 */
  • uspace/app/tmon/tf.h

    r8393c73b r3b5a5e3  
    3838
    3939#include <async.h>
    40 
    41 /** Parameters common for all tests. */
    42 typedef struct tmon_test_params {
    43         /* Nothing here. */
    44 } tmon_test_params_t;
     40#include <usbdiag_iface.h>
    4541
    4642/** Operations to implement by all tests. */
    4743typedef struct tmon_test_ops {
    48         int (*run)(async_exch_t *, const tmon_test_params_t *);
    49         int (*read_params)(int, char **, tmon_test_params_t **);
     44        int (*pre_run)(void *);
     45        int (*run)(async_exch_t *, const void *);
     46        int (*read_params)(int, char **, void **);
    5047} tmon_test_ops_t;
    5148
    5249int tmon_test_main(int, char **, const tmon_test_ops_t *);
     50
     51char *tmon_format_size(double, const char *);
     52char *tmon_format_duration(usbdiag_dur_t, const char *);
    5353
    5454#endif /* TMON_TF_H_ */
Note: See TracChangeset for help on using the changeset viewer.