| 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 stress tests.
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #include <stdio.h>
|
|---|
| 38 | #include <errno.h>
|
|---|
| 39 | #include <str_error.h>
|
|---|
| 40 | #include <usbdiag_iface.h>
|
|---|
| 41 | #include "commands.h"
|
|---|
| 42 | #include "test.h"
|
|---|
| 43 |
|
|---|
| 44 | #define NAME "tmon"
|
|---|
| 45 |
|
|---|
| 46 | typedef struct tmon_stress_test_params {
|
|---|
| 47 | tmon_test_params_t base; /* inheritance */
|
|---|
| 48 | int cycles;
|
|---|
| 49 | size_t size;
|
|---|
| 50 | } tmon_stress_test_params_t;
|
|---|
| 51 |
|
|---|
| 52 | static int read_params(int argc, char *argv[], tmon_test_params_t **params)
|
|---|
| 53 | {
|
|---|
| 54 | tmon_stress_test_params_t *p = (tmon_stress_test_params_t *) malloc(sizeof(tmon_stress_test_params_t));
|
|---|
| 55 | if (!p)
|
|---|
| 56 | return ENOMEM;
|
|---|
| 57 |
|
|---|
| 58 | // Default values.
|
|---|
| 59 | p->cycles = 1024;
|
|---|
| 60 | p->size = 65024;
|
|---|
| 61 |
|
|---|
| 62 | // TODO: Parse argc, argv here.
|
|---|
| 63 |
|
|---|
| 64 | *params = (tmon_test_params_t *) p;
|
|---|
| 65 | return EOK;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | static int run_intr_in(async_exch_t *exch, const tmon_test_params_t *generic_params)
|
|---|
| 69 | {
|
|---|
| 70 | const tmon_stress_test_params_t *params = (tmon_stress_test_params_t *) generic_params;
|
|---|
| 71 | printf("Executing interrupt in stress test.\n"
|
|---|
| 72 | " Packet count: %d\n"
|
|---|
| 73 | " Packet size: %ld\n", params->cycles, params->size);
|
|---|
| 74 |
|
|---|
| 75 | int rc = usbdiag_stress_intr_in(exch, params->cycles, params->size);
|
|---|
| 76 | if (rc) {
|
|---|
| 77 | printf(NAME ": Test failed. %s\n", str_error(rc));
|
|---|
| 78 | return 1;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | return 0;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | static int run_intr_out(async_exch_t *exch, const tmon_test_params_t *generic_params)
|
|---|
| 85 | {
|
|---|
| 86 | const tmon_stress_test_params_t *params = (tmon_stress_test_params_t *) generic_params;
|
|---|
| 87 | printf("Executing interrupt out stress test.\n"
|
|---|
| 88 | " Packet count: %d\n"
|
|---|
| 89 | " Packet size: %ld\n", params->cycles, params->size);
|
|---|
| 90 |
|
|---|
| 91 | int rc = usbdiag_stress_intr_out(exch, params->cycles, params->size);
|
|---|
| 92 | if (rc) {
|
|---|
| 93 | printf(NAME ": Test failed. %s\n", str_error(rc));
|
|---|
| 94 | return 1;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | return 0;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | static int run_bulk_in(async_exch_t *exch, const tmon_test_params_t *generic_params)
|
|---|
| 101 | {
|
|---|
| 102 | const tmon_stress_test_params_t *params = (tmon_stress_test_params_t *) generic_params;
|
|---|
| 103 | printf("Executing bulk in stress test.\n"
|
|---|
| 104 | " Packet count: %d\n"
|
|---|
| 105 | " Packet size: %ld\n", params->cycles, params->size);
|
|---|
| 106 |
|
|---|
| 107 | int rc = usbdiag_stress_bulk_in(exch, params->cycles, params->size);
|
|---|
| 108 | if (rc) {
|
|---|
| 109 | printf(NAME ": Test failed. %s\n", str_error(rc));
|
|---|
| 110 | return 1;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | return 0;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | static int run_bulk_out(async_exch_t *exch, const tmon_test_params_t *generic_params)
|
|---|
| 117 | {
|
|---|
| 118 | const tmon_stress_test_params_t *params = (tmon_stress_test_params_t *) generic_params;
|
|---|
| 119 | printf("Executing bulk out stress test.\n"
|
|---|
| 120 | " Packet count: %d\n"
|
|---|
| 121 | " Packet size: %ld\n", params->cycles, params->size);
|
|---|
| 122 |
|
|---|
| 123 | int rc = usbdiag_stress_bulk_out(exch, params->cycles, params->size);
|
|---|
| 124 | if (rc) {
|
|---|
| 125 | printf(NAME ": Test failed. %s\n", str_error(rc));
|
|---|
| 126 | return 1;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | return 0;
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | static int run_isoch_in(async_exch_t *exch, const tmon_test_params_t *generic_params)
|
|---|
| 133 | {
|
|---|
| 134 | const tmon_stress_test_params_t *params = (tmon_stress_test_params_t *) generic_params;
|
|---|
| 135 | printf("Executing isochronous in stress test.\n"
|
|---|
| 136 | " Packet count: %d\n"
|
|---|
| 137 | " Packet size: %ld\n", params->cycles, params->size);
|
|---|
| 138 |
|
|---|
| 139 | int rc = usbdiag_stress_isoch_in(exch, params->cycles, params->size);
|
|---|
| 140 | if (rc) {
|
|---|
| 141 | printf(NAME ": Test failed. %s\n", str_error(rc));
|
|---|
| 142 | return 1;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | return 0;
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | static int run_isoch_out(async_exch_t *exch, const tmon_test_params_t *generic_params)
|
|---|
| 149 | {
|
|---|
| 150 | const tmon_stress_test_params_t *params = (tmon_stress_test_params_t *) generic_params;
|
|---|
| 151 | printf("Executing isochronous out stress test.\n"
|
|---|
| 152 | " Packet count: %d\n"
|
|---|
| 153 | " Packet size: %ld\n", params->cycles, params->size);
|
|---|
| 154 |
|
|---|
| 155 | int rc = usbdiag_stress_isoch_out(exch, params->cycles, params->size);
|
|---|
| 156 | if (rc) {
|
|---|
| 157 | printf(NAME ": Test failed. %s\n", str_error(rc));
|
|---|
| 158 | return 1;
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | return 0;
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | int tmon_stress_intr_in(int argc, char *argv[])
|
|---|
| 165 | {
|
|---|
| 166 | static const tmon_test_ops_t ops = {
|
|---|
| 167 | .run = run_intr_in,
|
|---|
| 168 | .read_params = read_params
|
|---|
| 169 | };
|
|---|
| 170 |
|
|---|
| 171 | return tmon_test_main(argc, argv, &ops);
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | int tmon_stress_intr_out(int argc, char *argv[])
|
|---|
| 175 | {
|
|---|
| 176 | static const tmon_test_ops_t ops = {
|
|---|
| 177 | .run = run_intr_out,
|
|---|
| 178 | .read_params = read_params
|
|---|
| 179 | };
|
|---|
| 180 |
|
|---|
| 181 | return tmon_test_main(argc, argv, &ops);
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | int tmon_stress_bulk_in(int argc, char *argv[])
|
|---|
| 185 | {
|
|---|
| 186 | static const tmon_test_ops_t ops = {
|
|---|
| 187 | .run = run_bulk_in,
|
|---|
| 188 | .read_params = read_params
|
|---|
| 189 | };
|
|---|
| 190 |
|
|---|
| 191 | return tmon_test_main(argc, argv, &ops);
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | int tmon_stress_bulk_out(int argc, char *argv[])
|
|---|
| 195 | {
|
|---|
| 196 | static const tmon_test_ops_t ops = {
|
|---|
| 197 | .run = run_bulk_out,
|
|---|
| 198 | .read_params = read_params
|
|---|
| 199 | };
|
|---|
| 200 |
|
|---|
| 201 | return tmon_test_main(argc, argv, &ops);
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | int tmon_stress_isoch_in(int argc, char *argv[])
|
|---|
| 205 | {
|
|---|
| 206 | static const tmon_test_ops_t ops = {
|
|---|
| 207 | .run = run_isoch_in,
|
|---|
| 208 | .read_params = read_params
|
|---|
| 209 | };
|
|---|
| 210 |
|
|---|
| 211 | return tmon_test_main(argc, argv, &ops);
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | int tmon_stress_isoch_out(int argc, char *argv[])
|
|---|
| 215 | {
|
|---|
| 216 | static const tmon_test_ops_t ops = {
|
|---|
| 217 | .run = run_isoch_out,
|
|---|
| 218 | .read_params = read_params
|
|---|
| 219 | };
|
|---|
| 220 |
|
|---|
| 221 | return tmon_test_main(argc, argv, &ops);
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | /** @}
|
|---|
| 225 | */
|
|---|