Changeset 119a794 in mainline for uspace/app/tmon/stress_test.c


Ignore:
Timestamp:
2017-12-22T11:17:25Z (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:
ab8e0f5
Parents:
ff16da5f
Message:

tmon: use getopt for customize read/write count and size

File:
1 edited

Legend:

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

    rff16da5f r119a794  
    3838#include <errno.h>
    3939#include <str_error.h>
     40#include <getopt.h>
    4041#include <usbdiag_iface.h>
    4142#include "commands.h"
     
    4647typedef struct tmon_stress_test_params {
    4748        tmon_test_params_t base; /* inheritance */
    48         int cycles;
     49        uint32_t cycles;
    4950        size_t size;
    5051} tmon_stress_test_params_t;
    5152
     53static struct option long_options[] = {
     54        {"cycles", required_argument, NULL, 'n'},
     55        {"size", required_argument, NULL, 's'},
     56        {0, 0, NULL, 0}
     57};
     58
     59static const char *short_options = "n:s:";
     60
    5261static int read_params(int argc, char *argv[], tmon_test_params_t **params)
    5362{
     63        int rc;
    5464        tmon_stress_test_params_t *p = (tmon_stress_test_params_t *) malloc(sizeof(tmon_stress_test_params_t));
    5565        if (!p)
     
    5767
    5868        // Default values.
    59         p->cycles = 1024;
    60         p->size = 65024;
    61 
    62         // TODO: Parse argc, argv here.
     69        p->cycles = 256;
     70        p->size = 1024;
     71
     72        // Parse other than default values.
     73        int c;
     74        for (c = 0, optreset = 1, optind = 0; c != -1;) {
     75                c = getopt_long(argc, argv, short_options, long_options, NULL);
     76                switch (c) {
     77                case -1:
     78                        break;
     79                case 'n':
     80                        if (!optarg || str_uint32_t(optarg, NULL, 10, false, &p->cycles) != EOK) {
     81                                puts(NAME ": Invalid number of cycles.\n");
     82                                rc = EINVAL;
     83                                goto err_malloc;
     84                        }
     85                        break;
     86                case 's':
     87                        if (!optarg || str_size_t(optarg, NULL, 10, false, &p->size) != EOK) {
     88                                puts(NAME ": Invalid data size.\n");
     89                                rc = EINVAL;
     90                                goto err_malloc;
     91                        }
     92                        break;
     93                }
     94        }
    6395
    6496        *params = (tmon_test_params_t *) p;
    6597        return EOK;
     98
     99err_malloc:
     100        free(p);
     101        *params = NULL;
     102        return rc;
    66103}
    67104
     
    70107        const tmon_stress_test_params_t *params = (tmon_stress_test_params_t *) generic_params;
    71108        printf("Executing interrupt in stress test.\n"
    72             "      Packet count: %d\n"
    73             "      Packet size: %ld\n", params->cycles, params->size);
     109            "      Number of cycles: %d\n"
     110            "      Data size: %ld B\n", params->cycles, params->size);
    74111
    75112        int rc = usbdiag_stress_intr_in(exch, params->cycles, params->size);
     
    86123        const tmon_stress_test_params_t *params = (tmon_stress_test_params_t *) generic_params;
    87124        printf("Executing interrupt out stress test.\n"
    88             "      Packet count: %d\n"
    89             "      Packet size: %ld\n", params->cycles, params->size);
     125            "      Number of cycles: %d\n"
     126            "      Data size: %ld B\n", params->cycles, params->size);
    90127
    91128        int rc = usbdiag_stress_intr_out(exch, params->cycles, params->size);
     
    102139        const tmon_stress_test_params_t *params = (tmon_stress_test_params_t *) generic_params;
    103140        printf("Executing bulk in stress test.\n"
    104             "      Packet count: %d\n"
    105             "      Packet size: %ld\n", params->cycles, params->size);
     141            "      Number of cycles: %d\n"
     142            "      Data size: %ld B\n", params->cycles, params->size);
    106143
    107144        int rc = usbdiag_stress_bulk_in(exch, params->cycles, params->size);
     
    118155        const tmon_stress_test_params_t *params = (tmon_stress_test_params_t *) generic_params;
    119156        printf("Executing bulk out stress test.\n"
    120             "      Packet count: %d\n"
    121             "      Packet size: %ld\n", params->cycles, params->size);
     157            "      Number of cycles: %d\n"
     158            "      Data size: %ld B\n", params->cycles, params->size);
    122159
    123160        int rc = usbdiag_stress_bulk_out(exch, params->cycles, params->size);
     
    134171        const tmon_stress_test_params_t *params = (tmon_stress_test_params_t *) generic_params;
    135172        printf("Executing isochronous in stress test.\n"
    136             "      Packet count: %d\n"
    137             "      Packet size: %ld\n", params->cycles, params->size);
     173            "      Number of cycles: %d\n"
     174            "      Data size: %ld B\n", params->cycles, params->size);
    138175
    139176        int rc = usbdiag_stress_isoch_in(exch, params->cycles, params->size);
     
    150187        const tmon_stress_test_params_t *params = (tmon_stress_test_params_t *) generic_params;
    151188        printf("Executing isochronous out stress test.\n"
    152             "      Packet count: %d\n"
    153             "      Packet size: %ld\n", params->cycles, params->size);
     189            "      Number of cycles: %d\n"
     190            "      Data size: %ld B\n", params->cycles, params->size);
    154191
    155192        int rc = usbdiag_stress_isoch_out(exch, params->cycles, params->size);
Note: See TracChangeset for help on using the changeset viewer.