Changeset 3b5a5e3 in mainline
- Timestamp:
- 2018-02-01T16:10:12Z (7 years ago)
- 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)
- Location:
- uspace/app/tmon
- Files:
-
- 1 added
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tmon/Makefile
r8393c73b r3b5a5e3 30 30 BINARY = tmon 31 31 32 LIBS = drv 32 LIBS = drv usb 33 33 34 34 SOURCES = \ … … 36 36 list.c\ 37 37 tf.c\ 38 burst_tests.c\38 tests.c\ 39 39 resolve.c 40 40 -
uspace/app/tmon/commands.h
r8393c73b r3b5a5e3 42 42 int tmon_list(int, char **); 43 43 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. */ 45 int tmon_test_intr_in(int, char **); 46 int tmon_test_intr_out(int, char **); 47 int tmon_test_bulk_in(int, char **); 48 int tmon_test_bulk_out(int, char **); 49 int tmon_test_isoch_in(int, char **); 50 int tmon_test_isoch_out(int, char **); 51 51 52 52 #endif /* TMON_COMMANDS_H_ */ -
uspace/app/tmon/main.c
r8393c73b r3b5a5e3 62 62 .name = "test-intr-in", 63 63 .description = "Read from interrupt endpoint as fast as possible.", 64 .action = tmon_ burst_intr_in,64 .action = tmon_test_intr_in, 65 65 }, 66 66 { 67 67 .name = "test-intr-out", 68 68 .description = "Write to interrupt endpoint as fast as possible.", 69 .action = tmon_ burst_intr_out,69 .action = tmon_test_intr_out, 70 70 }, 71 71 { 72 72 .name = "test-bulk-in", 73 73 .description = "Read from bulk endpoint as fast as possible.", 74 .action = tmon_ burst_bulk_in,74 .action = tmon_test_bulk_in, 75 75 }, 76 76 { 77 77 .name = "test-bulk-out", 78 78 .description = "Write to bulk endpoint as fast as possible.", 79 .action = tmon_ burst_bulk_out,79 .action = tmon_test_bulk_out, 80 80 }, 81 81 { 82 82 .name = "test-isoch-in", 83 83 .description = "Read from isochronous endpoint as fast as possible.", 84 .action = tmon_ burst_isoch_in,84 .action = tmon_test_isoch_in, 85 85 }, 86 86 { 87 87 .name = "test-isoch-out", 88 88 .description = "Write to isochronous endpoint as fast as possible.", 89 .action = tmon_ burst_isoch_out,90 } 89 .action = tmon_test_isoch_out, 90 }, 91 91 }; 92 92 … … 104 104 static tmon_opt_t options[] = { 105 105 { 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)." 109 109 }, 110 110 { 111 111 .long_name = "size", 112 112 .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 }, 115 120 }; 116 121 -
uspace/app/tmon/tf.c
r8393c73b r3b5a5e3 36 36 37 37 #include <stdio.h> 38 #include <macros.h> 38 39 #include <devman.h> 39 40 #include <str_error.h> … … 74 75 } 75 76 76 printf(" Using device: %s\n", path);77 printf("Device: %s\n", path); 77 78 78 79 // Read test parameters from options. 79 tmon_test_params_t*params = NULL;80 void *params = NULL; 80 81 if ((rc = ops->read_params(argc, argv, ¶ms))) { 81 82 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)); 82 88 return 1; 83 89 } … … 106 112 } 107 113 114 /** Unit of quantity used for pretty formatting. */ 115 typedef 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 */ 128 static 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. */ 151 static 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 161 char *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. */ 167 static 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 178 char *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 108 183 /** @} 109 184 */ -
uspace/app/tmon/tf.h
r8393c73b r3b5a5e3 38 38 39 39 #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> 45 41 46 42 /** Operations to implement by all tests. */ 47 43 typedef 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 **); 50 47 } tmon_test_ops_t; 51 48 52 49 int tmon_test_main(int, char **, const tmon_test_ops_t *); 50 51 char *tmon_format_size(double, const char *); 52 char *tmon_format_duration(usbdiag_dur_t, const char *); 53 53 54 54 #endif /* TMON_TF_H_ */
Note:
See TracChangeset
for help on using the changeset viewer.