source: mainline/uspace/app/tmon/main.c@ 3b5a5e3

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3b5a5e3 was 3b5a5e3, checked in by Petr Manek <petr.manek@…>, 8 years ago

tmon: catch up with libdrv changes, simplify code

  • Property mode set to 100644
File size: 5.0 KB
RevLine 
[81ee1009]1/*
2 * Copyright (c) 2017 Petr Manek
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup tmon
30 * @{
31 */
32/**
33 * @file
34 * USB transfer debugging.
35 */
36
37#include <stdio.h>
[59958992]38#include <macros.h>
[73b0773]39#include "commands.h"
[81ee1009]40
[00d23a21]41#define NAME "tmon"
42#define INDENT " "
[81ee1009]43
[8e16454]44/** Command which is executed by tmon. */
[00d23a21]45typedef struct tmon_cmd {
[8e16454]46 /** Unique name, by which the command is executed. */
[73b0773]47 const char *name;
[8e16454]48 /** Description of the command, which is displayed in the usage string. */
[25935f1e]49 const char *description;
[8e16454]50 /** Function, which executes the command. Same as int main(int, char**). */
[73b0773]51 int (*action)(int, char **);
[00d23a21]52} tmon_cmd_t;
[64d138b]53
[8e16454]54/** Static array of commands supported by tmon. */
[00d23a21]55static tmon_cmd_t commands[] = {
[73b0773]56 {
57 .name = "list",
[25935f1e]58 .description = "Print a list of connected diagnostic devices.",
[73b0773]59 .action = tmon_list,
60 },
[e9d600c2]61 {
[2986763]62 .name = "test-intr-in",
[00d23a21]63 .description = "Read from interrupt endpoint as fast as possible.",
[3b5a5e3]64 .action = tmon_test_intr_in,
[e9d600c2]65 },
66 {
[2986763]67 .name = "test-intr-out",
[00d23a21]68 .description = "Write to interrupt endpoint as fast as possible.",
[3b5a5e3]69 .action = tmon_test_intr_out,
[e9d600c2]70 },
[2bd04b2]71 {
[2986763]72 .name = "test-bulk-in",
[00d23a21]73 .description = "Read from bulk endpoint as fast as possible.",
[3b5a5e3]74 .action = tmon_test_bulk_in,
[25935f1e]75 },
76 {
[2986763]77 .name = "test-bulk-out",
[00d23a21]78 .description = "Write to bulk endpoint as fast as possible.",
[3b5a5e3]79 .action = tmon_test_bulk_out,
[25935f1e]80 },
[ff16da5f]81 {
[2986763]82 .name = "test-isoch-in",
[00d23a21]83 .description = "Read from isochronous endpoint as fast as possible.",
[3b5a5e3]84 .action = tmon_test_isoch_in,
[ff16da5f]85 },
86 {
[2986763]87 .name = "test-isoch-out",
[00d23a21]88 .description = "Write to isochronous endpoint as fast as possible.",
[3b5a5e3]89 .action = tmon_test_isoch_out,
90 },
[00d23a21]91};
92
[8e16454]93/** Option shown in the usage string. */
[00d23a21]94typedef struct tmon_opt {
[8e16454]95 /** Long name of the option without "--" prefix. */
[00d23a21]96 const char *long_name;
[8e16454]97 /** Short name of the option without "-" prefix. */
[00d23a21]98 char short_name;
[8e16454]99 /** Description of the option displayed in the usage string. */
[00d23a21]100 const char *description;
101} tmon_opt_t;
102
[8e16454]103/** Static array of options displayed in the tmon usage string. */
[00d23a21]104static tmon_opt_t options[] = {
[73b0773]105 {
[3b5a5e3]106 .long_name = "duration",
107 .short_name = 't',
108 .description = "Set the minimum test duration (in seconds)."
[00d23a21]109 },
110 {
111 .long_name = "size",
112 .short_name = 's',
[3b5a5e3]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 },
[73b0773]120};
[64d138b]121
[8e16454]122/** Print usage string.
123 * @param[in] app_name Name to print in the invocation example.
124 */
[25935f1e]125static void print_usage(char *app_name)
126{
[00d23a21]127 puts(NAME ": benchmark USB diagnostic device\n\n");
128 printf("Usage: %s command [device] [options]\n\n", app_name);
[25935f1e]129
[59958992]130 for (unsigned i = 0; i < ARRAY_SIZE(commands); ++i) {
[00d23a21]131 printf(INDENT "%s - %s\n", commands[i].name, commands[i].description);
[25935f1e]132 }
133
[00d23a21]134 puts("\n");
[59958992]135 for (unsigned i = 0; i < ARRAY_SIZE(options); ++i) {
[00d23a21]136 printf(INDENT "-%c --%s\n" INDENT INDENT "%s\n", options[i].short_name, options[i].long_name, options[i].description);
137 }
[25935f1e]138
[00d23a21]139 puts("\nIf no device is specified, the first device is used provided that it is the only one connected. Otherwise, the command fails.\n\n");
[25935f1e]140}
141
[8e16454]142/** Main tmon entry point.
143 * @param[in] argc Number of arguments.
144 * @param[in] argv Argument values. Must point to exactly `argc` strings.
145 *
146 * @return Exit code
147 */
[73b0773]148int main(int argc, char *argv[])
[64d138b]149{
[73b0773]150 // Find a command to execute.
[00d23a21]151 tmon_cmd_t *cmd = NULL;
[59958992]152 for (unsigned i = 0; argc > 1 && i < ARRAY_SIZE(commands); ++i) {
[73b0773]153 if (str_cmp(argv[1], commands[i].name) == 0) {
154 cmd = commands + i;
155 break;
156 }
[64d138b]157 }
158
[73b0773]159 if (!cmd) {
[81ee1009]160 print_usage(argv[0]);
161 return -1;
162 }
163
[119a794]164 return cmd->action(argc - 1, argv + 1);
[81ee1009]165}
166
167/** @}
168 */
Note: See TracBrowser for help on using the repository browser.