[145d4e2e] | 1 | /*
|
---|
| 2 | * Copyright (c) 2024 Jiri Svoboda
|
---|
| 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 | #include <ata/ata.h>
|
---|
| 30 | #include <errno.h>
|
---|
| 31 | #include <pcut/pcut.h>
|
---|
| 32 |
|
---|
| 33 | PCUT_INIT;
|
---|
| 34 |
|
---|
| 35 | PCUT_TEST_SUITE(ata);
|
---|
| 36 |
|
---|
| 37 | static void test_write_data_16(void *, uint16_t *, size_t);
|
---|
| 38 | static void test_read_data_16(void *, uint16_t *, size_t);
|
---|
| 39 | static void test_write_cmd_8(void *, uint16_t, uint8_t);
|
---|
| 40 | static uint8_t test_read_cmd_8(void *, uint16_t);
|
---|
| 41 | static void test_write_ctl_8(void *, uint16_t, uint8_t);
|
---|
| 42 | static uint8_t test_read_ctl_8(void *, uint16_t);
|
---|
| 43 | static errno_t test_irq_enable(void *);
|
---|
| 44 | static errno_t test_irq_disable(void *);
|
---|
| 45 | static void test_dma_chan_setup(void *, void *, size_t, ata_dma_dir_t);
|
---|
| 46 | static void test_dma_chan_teardown(void *);
|
---|
| 47 | static errno_t test_add_device(void *, unsigned, void *);
|
---|
| 48 | static errno_t test_remove_device(void *, unsigned);
|
---|
| 49 | static void test_msg_note(void *, char *);
|
---|
| 50 | static void test_msg_error(void *, char *);
|
---|
| 51 | static void test_msg_warn(void *, char *);
|
---|
| 52 | static void test_msg_debug(void *, char *);
|
---|
| 53 |
|
---|
| 54 | /** ata_channel_create() / ata_channel_destroy() can be called */
|
---|
| 55 | PCUT_TEST(channel_create_destroy)
|
---|
| 56 | {
|
---|
| 57 | ata_params_t params;
|
---|
| 58 | ata_channel_t *chan;
|
---|
| 59 | errno_t rc;
|
---|
| 60 |
|
---|
| 61 | memset(¶ms, 0, sizeof(params));
|
---|
| 62 | params.write_data_16 = test_write_data_16;
|
---|
| 63 | params.read_data_16 = test_read_data_16;
|
---|
| 64 | params.write_cmd_8 = test_write_cmd_8;
|
---|
| 65 | params.read_cmd_8 = test_read_cmd_8;
|
---|
| 66 | params.write_ctl_8 = test_write_ctl_8;
|
---|
| 67 | params.read_ctl_8 = test_read_ctl_8;
|
---|
| 68 | params.irq_enable = test_irq_enable;
|
---|
| 69 | params.irq_disable = test_irq_disable;
|
---|
| 70 | params.dma_chan_setup = test_dma_chan_setup;
|
---|
| 71 | params.dma_chan_teardown = test_dma_chan_teardown;
|
---|
| 72 | params.add_device = test_add_device;
|
---|
| 73 | params.remove_device = test_remove_device;
|
---|
| 74 | params.msg_note = test_msg_note;
|
---|
| 75 | params.msg_error = test_msg_error;
|
---|
| 76 | params.msg_warn = test_msg_warn;
|
---|
| 77 | params.msg_debug = test_msg_debug;
|
---|
| 78 |
|
---|
| 79 | chan = NULL;
|
---|
| 80 | rc = ata_channel_create(¶ms, &chan);
|
---|
| 81 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 82 |
|
---|
| 83 | ata_channel_destroy(chan);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | /** ata_channel_initialize() can be called */
|
---|
| 87 | PCUT_TEST(channel_initialize)
|
---|
| 88 | {
|
---|
| 89 | ata_params_t params;
|
---|
| 90 | ata_channel_t *chan;
|
---|
| 91 | errno_t rc;
|
---|
| 92 |
|
---|
| 93 | memset(¶ms, 0, sizeof(params));
|
---|
| 94 | params.write_data_16 = test_write_data_16;
|
---|
| 95 | params.read_data_16 = test_read_data_16;
|
---|
| 96 | params.write_cmd_8 = test_write_cmd_8;
|
---|
| 97 | params.read_cmd_8 = test_read_cmd_8;
|
---|
| 98 | params.write_ctl_8 = test_write_ctl_8;
|
---|
| 99 | params.read_ctl_8 = test_read_ctl_8;
|
---|
| 100 | params.irq_enable = test_irq_enable;
|
---|
| 101 | params.irq_disable = test_irq_disable;
|
---|
| 102 | params.dma_chan_setup = test_dma_chan_setup;
|
---|
| 103 | params.dma_chan_teardown = test_dma_chan_teardown;
|
---|
| 104 | params.add_device = test_add_device;
|
---|
| 105 | params.remove_device = test_remove_device;
|
---|
| 106 | params.msg_note = test_msg_note;
|
---|
| 107 | params.msg_error = test_msg_error;
|
---|
| 108 | params.msg_warn = test_msg_warn;
|
---|
| 109 | params.msg_debug = test_msg_debug;
|
---|
| 110 |
|
---|
| 111 | chan = NULL;
|
---|
| 112 | rc = ata_channel_create(¶ms, &chan);
|
---|
| 113 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 114 |
|
---|
| 115 | rc = ata_channel_initialize(chan);
|
---|
| 116 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 117 |
|
---|
| 118 | ata_channel_destroy(chan);
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | static void test_write_data_16(void *arg, uint16_t *data, size_t nwords)
|
---|
| 122 | {
|
---|
| 123 | (void)arg;
|
---|
| 124 | (void)data;
|
---|
| 125 | (void)nwords;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | static void test_read_data_16(void *arg, uint16_t *buf, size_t nwords)
|
---|
| 129 | {
|
---|
| 130 | (void)arg;
|
---|
| 131 | (void)buf;
|
---|
| 132 | (void)nwords;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | static void test_write_cmd_8(void *arg, uint16_t off, uint8_t value)
|
---|
| 136 | {
|
---|
| 137 | (void)arg;
|
---|
| 138 | (void)off;
|
---|
| 139 | (void)value;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | static uint8_t test_read_cmd_8(void *arg, uint16_t off)
|
---|
| 143 | {
|
---|
| 144 | (void)arg;
|
---|
| 145 |
|
---|
| 146 | if (off == REG_STATUS) {
|
---|
| 147 | /*
|
---|
| 148 | * This allows us to pass device initialization without
|
---|
| 149 | * timing out.
|
---|
| 150 | */
|
---|
| 151 | return SR_DRQ;
|
---|
| 152 | }
|
---|
| 153 | return 0;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | static void test_write_ctl_8(void *arg, uint16_t off, uint8_t value)
|
---|
| 157 | {
|
---|
| 158 | (void)arg;
|
---|
| 159 | (void)off;
|
---|
| 160 | (void)value;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | static uint8_t test_read_ctl_8(void *arg, uint16_t off)
|
---|
| 164 | {
|
---|
| 165 | (void)arg;
|
---|
| 166 | (void)off;
|
---|
| 167 | return 0;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | static errno_t test_irq_enable(void *arg)
|
---|
| 171 | {
|
---|
| 172 | (void)arg;
|
---|
| 173 | return EOK;
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | static errno_t test_irq_disable(void *arg)
|
---|
| 177 | {
|
---|
| 178 | (void)arg;
|
---|
| 179 | return EOK;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | static void test_dma_chan_setup(void *arg, void *buf, size_t buf_size,
|
---|
| 183 | ata_dma_dir_t dir)
|
---|
| 184 | {
|
---|
| 185 | (void)arg;
|
---|
| 186 | (void)buf;
|
---|
| 187 | (void)buf_size;
|
---|
| 188 | (void)dir;
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | static void test_dma_chan_teardown(void *arg)
|
---|
| 192 | {
|
---|
| 193 | (void)arg;
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | static errno_t test_add_device(void *arg, unsigned idx, void *charg)
|
---|
| 197 | {
|
---|
| 198 | (void)arg;
|
---|
| 199 | (void)idx;
|
---|
| 200 | (void)charg;
|
---|
| 201 | return EOK;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | static errno_t test_remove_device(void *arg, unsigned idx)
|
---|
| 205 | {
|
---|
| 206 | (void)arg;
|
---|
| 207 | (void)idx;
|
---|
| 208 | return EOK;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | static void test_msg_note(void *arg, char *msg)
|
---|
| 212 | {
|
---|
| 213 | (void)arg;
|
---|
| 214 | (void)msg;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | static void test_msg_error(void *arg, char *msg)
|
---|
| 218 | {
|
---|
| 219 | (void)arg;
|
---|
| 220 | (void)msg;
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | static void test_msg_warn(void *arg, char *msg)
|
---|
| 224 | {
|
---|
| 225 | (void)arg;
|
---|
| 226 | (void)msg;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | static void test_msg_debug(void *arg, char *msg)
|
---|
| 230 | {
|
---|
| 231 | (void)arg;
|
---|
| 232 | (void)msg;
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | PCUT_EXPORT(ata);
|
---|