HelenOS sources
This source file includes following definitions.
- print_usage
- main
#include <stdio.h>
#include <stddef.h>
#include <str.h>
#include <macros.h>
#include "commands.h"
#define NAME "tmon"
#define INDENT " "
typedef struct tmon_cmd {
const char *name;
const char *description;
int (*action)(int, char **);
} tmon_cmd_t;
static tmon_cmd_t commands[] = {
{
.name = "list",
.description = "Print a list of connected diagnostic devices.",
.action = tmon_list,
},
{
.name = "test-intr-in",
.description = "Read from interrupt endpoint as fast as possible.",
.action = tmon_test_intr_in,
},
{
.name = "test-intr-out",
.description = "Write to interrupt endpoint as fast as possible.",
.action = tmon_test_intr_out,
},
{
.name = "test-bulk-in",
.description = "Read from bulk endpoint as fast as possible.",
.action = tmon_test_bulk_in,
},
{
.name = "test-bulk-out",
.description = "Write to bulk endpoint as fast as possible.",
.action = tmon_test_bulk_out,
},
{
.name = "test-isoch-in",
.description = "Read from isochronous endpoint as fast as possible.",
.action = tmon_test_isoch_in,
},
{
.name = "test-isoch-out",
.description = "Write to isochronous endpoint as fast as possible.",
.action = tmon_test_isoch_out,
},
};
typedef struct tmon_opt {
const char *long_name;
char short_name;
const char *description;
} tmon_opt_t;
static tmon_opt_t options[] = {
{
.long_name = "duration",
.short_name = 't',
.description = "Set the minimum test duration (in seconds)."
},
{
.long_name = "size",
.short_name = 's',
.description = "Set the data size (in bytes) transferred in a single cycle."
},
{
.long_name = "validate",
.short_name = 'v',
.description = "Validate the correctness of transferred data (impacts performance)."
},
};
static void print_usage(char *app_name)
{
puts(NAME ": benchmark USB diagnostic device\n");
printf("Usage: %s command [device] [options]\n\n", app_name);
for (unsigned i = 0; i < ARRAY_SIZE(commands); ++i) {
printf(INDENT "%s - %s\n", commands[i].name, commands[i].description);
}
puts("");
for (unsigned i = 0; i < ARRAY_SIZE(options); ++i) {
printf(INDENT "-%c --%s\n" INDENT INDENT "%s\n", options[i].short_name, options[i].long_name, options[i].description);
}
puts("\nIf no device is specified, the first device is used provided that it is the only one connected. Otherwise, the command fails.\n");
}
int main(int argc, char *argv[])
{
tmon_cmd_t *cmd = NULL;
for (unsigned i = 0; argc > 1 && i < ARRAY_SIZE(commands); ++i) {
if (str_cmp(argv[1], commands[i].name) == 0) {
cmd = commands + i;
break;
}
}
if (!cmd) {
print_usage(argv[0]);
return -1;
}
return cmd->action(argc - 1, argv + 1);
}
HelenOS homepage, sources at GitHub