| 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 = 65432;
|
|---|
| 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 | int tmon_stress_intr_in(int argc, char *argv[])
|
|---|
| 133 | {
|
|---|
| 134 | static const tmon_test_ops_t ops = {
|
|---|
| 135 | .run = run_intr_in,
|
|---|
| 136 | .read_params = read_params
|
|---|
| 137 | };
|
|---|
| 138 |
|
|---|
| 139 | return tmon_test_main(argc, argv, &ops);
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | int tmon_stress_intr_out(int argc, char *argv[])
|
|---|
| 143 | {
|
|---|
| 144 | static const tmon_test_ops_t ops = {
|
|---|
| 145 | .run = run_intr_out,
|
|---|
| 146 | .read_params = read_params
|
|---|
| 147 | };
|
|---|
| 148 |
|
|---|
| 149 | return tmon_test_main(argc, argv, &ops);
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | int tmon_stress_bulk_in(int argc, char *argv[])
|
|---|
| 153 | {
|
|---|
| 154 | static const tmon_test_ops_t ops = {
|
|---|
| 155 | .run = run_bulk_in,
|
|---|
| 156 | .read_params = read_params
|
|---|
| 157 | };
|
|---|
| 158 |
|
|---|
| 159 | return tmon_test_main(argc, argv, &ops);
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | int tmon_stress_bulk_out(int argc, char *argv[])
|
|---|
| 163 | {
|
|---|
| 164 | static const tmon_test_ops_t ops = {
|
|---|
| 165 | .run = run_bulk_out,
|
|---|
| 166 | .read_params = read_params
|
|---|
| 167 | };
|
|---|
| 168 |
|
|---|
| 169 | return tmon_test_main(argc, argv, &ops);
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | /** @}
|
|---|
| 173 | */
|
|---|