| 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 drvusbdiag
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /**
|
|---|
| 33 | * @file
|
|---|
| 34 | * Code for executing diagnostic tests.
|
|---|
| 35 | */
|
|---|
| 36 | #include <errno.h>
|
|---|
| 37 | #include <str_error.h>
|
|---|
| 38 | #include <usb/debug.h>
|
|---|
| 39 | #include "tests.h"
|
|---|
| 40 |
|
|---|
| 41 | #define NAME "usbdiag"
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 | int usb_diag_stress_intr_out(usb_diag_dev_t *dev, int cycles, size_t size)
|
|---|
| 45 | {
|
|---|
| 46 | if (!dev)
|
|---|
| 47 | return EBADMEM;
|
|---|
| 48 |
|
|---|
| 49 | char *buffer = (char *) malloc(size);
|
|---|
| 50 | if (!buffer)
|
|---|
| 51 | return ENOMEM;
|
|---|
| 52 |
|
|---|
| 53 | memset(buffer, 42, size);
|
|---|
| 54 |
|
|---|
| 55 | // TODO: Are we sure that no other test is running on this endpoint?
|
|---|
| 56 |
|
|---|
| 57 | usb_log_info("Performing interrupt out stress test on device %s.", ddf_fun_get_name(dev->fun));
|
|---|
| 58 | int rc = EOK;
|
|---|
| 59 | for (int i = 0; i < cycles; ++i) {
|
|---|
| 60 | // Write buffer to device.
|
|---|
| 61 | if ((rc = usb_pipe_write(dev->intr_out, buffer, size))) {
|
|---|
| 62 | usb_log_error("Interrupt OUT write failed. %s\n", str_error(rc));
|
|---|
| 63 | break;
|
|---|
| 64 | }
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | free(buffer);
|
|---|
| 68 | return rc;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | int usb_diag_stress_intr_in(usb_diag_dev_t *dev, int cycles, size_t size)
|
|---|
| 72 | {
|
|---|
| 73 | if (!dev)
|
|---|
| 74 | return EBADMEM;
|
|---|
| 75 |
|
|---|
| 76 | char *buffer = (char *) malloc(size);
|
|---|
| 77 | if (!buffer)
|
|---|
| 78 | return ENOMEM;
|
|---|
| 79 |
|
|---|
| 80 | // TODO: Are we sure that no other test is running on this endpoint?
|
|---|
| 81 |
|
|---|
| 82 | usb_log_info("Performing interrupt in stress test on device %s.", ddf_fun_get_name(dev->fun));
|
|---|
| 83 | int rc = EOK;
|
|---|
| 84 | for (int i = 0; i < cycles; ++i) {
|
|---|
| 85 | // Read device's response.
|
|---|
| 86 | size_t remaining = size;
|
|---|
| 87 | size_t transferred;
|
|---|
| 88 |
|
|---|
| 89 | while (remaining > 0) {
|
|---|
| 90 | if ((rc = usb_pipe_read(dev->intr_in, buffer + size - remaining, remaining, &transferred))) {
|
|---|
| 91 | usb_log_error("Interrupt IN read failed. %s\n", str_error(rc));
|
|---|
| 92 | break;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | if (transferred > remaining) {
|
|---|
| 96 | usb_log_error("Interrupt IN read more than expected.\n");
|
|---|
| 97 | rc = EINVAL;
|
|---|
| 98 | break;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | remaining -= transferred;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | if (rc)
|
|---|
| 105 | break;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | free(buffer);
|
|---|
| 109 | return rc;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | int usb_diag_stress_bulk_out(usb_diag_dev_t *dev, int cycles, size_t size)
|
|---|
| 113 | {
|
|---|
| 114 | if (!dev)
|
|---|
| 115 | return EBADMEM;
|
|---|
| 116 |
|
|---|
| 117 | char *buffer = (char *) malloc(size);
|
|---|
| 118 | if (!buffer)
|
|---|
| 119 | return ENOMEM;
|
|---|
| 120 |
|
|---|
| 121 | memset(buffer, 42, size);
|
|---|
| 122 |
|
|---|
| 123 | // TODO: Are we sure that no other test is running on this endpoint?
|
|---|
| 124 |
|
|---|
| 125 | usb_log_info("Performing bulk out stress test on device %s.", ddf_fun_get_name(dev->fun));
|
|---|
| 126 | int rc = EOK;
|
|---|
| 127 | for (int i = 0; i < cycles; ++i) {
|
|---|
| 128 | // Write buffer to device.
|
|---|
| 129 | if ((rc = usb_pipe_write(dev->bulk_out, buffer, size))) {
|
|---|
| 130 | usb_log_error("Bulk OUT write failed. %s\n", str_error(rc));
|
|---|
| 131 | break;
|
|---|
| 132 | }
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | free(buffer);
|
|---|
| 136 | return rc;
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | int usb_diag_stress_bulk_in(usb_diag_dev_t *dev, int cycles, size_t size)
|
|---|
| 140 | {
|
|---|
| 141 | if (!dev)
|
|---|
| 142 | return EBADMEM;
|
|---|
| 143 |
|
|---|
| 144 | char *buffer = (char *) malloc(size);
|
|---|
| 145 | if (!buffer)
|
|---|
| 146 | return ENOMEM;
|
|---|
| 147 |
|
|---|
| 148 | // TODO: Are we sure that no other test is running on this endpoint?
|
|---|
| 149 |
|
|---|
| 150 | usb_log_info("Performing bulk in stress test on device %s.", ddf_fun_get_name(dev->fun));
|
|---|
| 151 | int rc = EOK;
|
|---|
| 152 | for (int i = 0; i < cycles; ++i) {
|
|---|
| 153 | // Read device's response.
|
|---|
| 154 | size_t remaining = size;
|
|---|
| 155 | size_t transferred;
|
|---|
| 156 |
|
|---|
| 157 | while (remaining > 0) {
|
|---|
| 158 | if ((rc = usb_pipe_read(dev->bulk_in, buffer + size - remaining, remaining, &transferred))) {
|
|---|
| 159 | usb_log_error("Bulk IN read failed. %s\n", str_error(rc));
|
|---|
| 160 | break;
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | if (transferred > remaining) {
|
|---|
| 164 | usb_log_error("Bulk IN read more than expected.\n");
|
|---|
| 165 | rc = EINVAL;
|
|---|
| 166 | break;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | remaining -= transferred;
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | if (rc)
|
|---|
| 173 | break;
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | free(buffer);
|
|---|
| 177 | return rc;
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | /**
|
|---|
| 181 | * @}
|
|---|
| 182 | */
|
|---|