Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ |
| 2 | |
Andrew Jeffery | 2cda40f | 2020-02-28 15:26:20 +1030 | [diff] [blame] | 3 | #ifdef HAVE_CONFIG_H |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 4 | #include "config.h" |
Andrew Jeffery | 2cda40f | 2020-02-28 15:26:20 +1030 | [diff] [blame] | 5 | #endif |
| 6 | |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 7 | #define ASTLPC_VER_CUR 2 |
Andrew Jeffery | df5f6b9 | 2020-05-12 21:39:06 +0930 | [diff] [blame] | 8 | #include "astlpc.c" |
| 9 | |
| 10 | #ifdef pr_fmt |
| 11 | #undef pr_fmt |
| 12 | #define pr_fmt(x) "test: " x |
| 13 | #endif |
| 14 | |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 15 | #include "libmctp-astlpc.h" |
| 16 | #include "libmctp-log.h" |
Przemyslaw Czarnowski | ff25d7e | 2020-03-26 11:39:37 +0100 | [diff] [blame] | 17 | #include "container_of.h" |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 18 | |
| 19 | #ifdef NDEBUG |
| 20 | #undef NDEBUG |
| 21 | #endif |
| 22 | |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 23 | #include <assert.h> |
Andrew Jeffery | 91f09ed | 2020-05-22 20:52:26 +0930 | [diff] [blame] | 24 | #include <limits.h> |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 25 | #include <stdint.h> |
| 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <string.h> |
Andrew Jeffery | c2b833e | 2020-10-28 14:28:37 +1030 | [diff] [blame^] | 29 | #include <sys/random.h> |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 30 | |
Andrew Jeffery | 91f09ed | 2020-05-22 20:52:26 +0930 | [diff] [blame] | 31 | #ifndef ARRAY_SIZE |
| 32 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 33 | #endif |
| 34 | |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 35 | struct mctp_binding_astlpc_mmio { |
| 36 | struct mctp_binding_astlpc astlpc; |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 37 | bool bmc; |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 38 | |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 39 | uint8_t (*kcs)[2]; |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 40 | |
| 41 | size_t lpc_size; |
| 42 | uint8_t *lpc; |
| 43 | }; |
| 44 | |
Andrew Jeffery | 5a7c2db | 2020-05-22 20:13:42 +0930 | [diff] [blame] | 45 | struct astlpc_endpoint { |
| 46 | struct mctp_binding_astlpc_mmio mmio; |
| 47 | struct mctp_binding_astlpc *astlpc; |
| 48 | struct mctp *mctp; |
| 49 | }; |
| 50 | |
| 51 | struct astlpc_test { |
| 52 | struct astlpc_endpoint bmc; |
| 53 | struct astlpc_endpoint host; |
| 54 | uint8_t kcs[2]; |
| 55 | uint8_t *lpc_mem; |
| 56 | |
| 57 | void *msg; |
| 58 | uint8_t count; |
| 59 | }; |
| 60 | |
| 61 | #define binding_to_mmio(b) \ |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 62 | container_of(b, struct mctp_binding_astlpc_mmio, astlpc) |
| 63 | |
Andrew Jeffery | 53ea147 | 2020-05-23 21:06:24 +0930 | [diff] [blame] | 64 | static int mctp_astlpc_mmio_kcs_read(void *data, |
| 65 | enum mctp_binding_astlpc_kcs_reg reg, |
| 66 | uint8_t *val) |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 67 | { |
| 68 | struct mctp_binding_astlpc_mmio *mmio = binding_to_mmio(data); |
| 69 | |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 70 | *val = (*mmio->kcs)[reg]; |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 71 | |
Andrew Jeffery | d3c0bf0 | 2020-05-28 15:28:40 +0930 | [diff] [blame] | 72 | mctp_prdebug("%s: 0x%hhx from %s", __func__, *val, |
| 73 | reg ? "status" : "data"); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 74 | |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 75 | if (reg == MCTP_ASTLPC_KCS_REG_DATA) { |
| 76 | uint8_t flag = mmio->bmc ? KCS_STATUS_IBF : KCS_STATUS_OBF; |
| 77 | (*mmio->kcs)[MCTP_ASTLPC_KCS_REG_STATUS] &= ~flag; |
| 78 | } |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
Andrew Jeffery | 53ea147 | 2020-05-23 21:06:24 +0930 | [diff] [blame] | 83 | static int mctp_astlpc_mmio_kcs_write(void *data, |
| 84 | enum mctp_binding_astlpc_kcs_reg reg, |
| 85 | uint8_t val) |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 86 | { |
| 87 | struct mctp_binding_astlpc_mmio *mmio = binding_to_mmio(data); |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 88 | uint8_t *regp; |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 89 | |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 90 | assert(reg == MCTP_ASTLPC_KCS_REG_DATA || |
| 91 | reg == MCTP_ASTLPC_KCS_REG_STATUS); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 92 | |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 93 | if (reg == MCTP_ASTLPC_KCS_REG_DATA) { |
| 94 | uint8_t flag = mmio->bmc ? KCS_STATUS_OBF : KCS_STATUS_IBF; |
| 95 | (*mmio->kcs)[MCTP_ASTLPC_KCS_REG_STATUS] |= flag; |
| 96 | } |
| 97 | |
| 98 | regp = &(*mmio->kcs)[reg]; |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 99 | if (reg == MCTP_ASTLPC_KCS_REG_STATUS) |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 100 | *regp = (val & ~0xbU) | (val & *regp & 1); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 101 | else |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 102 | *regp = val; |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 103 | |
Andrew Jeffery | d3c0bf0 | 2020-05-28 15:28:40 +0930 | [diff] [blame] | 104 | mctp_prdebug("%s: 0x%hhx to %s", __func__, val, |
| 105 | reg ? "status" : "data"); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 106 | |
| 107 | return 0; |
| 108 | } |
Andrew Jeffery | 85c04e4 | 2020-10-28 14:27:15 +1030 | [diff] [blame] | 109 | |
| 110 | static const struct mctp_binding_astlpc_ops astlpc_direct_mmio_ops = { |
| 111 | .kcs_read = mctp_astlpc_mmio_kcs_read, |
| 112 | .kcs_write = mctp_astlpc_mmio_kcs_write, |
| 113 | }; |
| 114 | |
Andrew Jeffery | 06b2cd8 | 2020-03-17 23:12:27 +1030 | [diff] [blame] | 115 | int mctp_astlpc_mmio_lpc_read(void *data, void *buf, long offset, size_t len) |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 116 | { |
| 117 | struct mctp_binding_astlpc_mmio *mmio = binding_to_mmio(data); |
| 118 | |
Andrew Jeffery | 1dbf021 | 2020-05-12 13:53:50 +0930 | [diff] [blame] | 119 | mctp_prdebug("%s: %zu bytes from 0x%lx", __func__, len, offset); |
| 120 | |
Andrew Jeffery | 06b2cd8 | 2020-03-17 23:12:27 +1030 | [diff] [blame] | 121 | assert(offset >= 0L); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 122 | assert(offset + len < mmio->lpc_size); |
| 123 | |
| 124 | memcpy(buf, mmio->lpc + offset, len); |
| 125 | |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 126 | return 0; |
| 127 | } |
| 128 | |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 129 | int mctp_astlpc_mmio_lpc_write(void *data, const void *buf, long offset, |
| 130 | size_t len) |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 131 | { |
| 132 | struct mctp_binding_astlpc_mmio *mmio = binding_to_mmio(data); |
| 133 | |
Andrew Jeffery | 1dbf021 | 2020-05-12 13:53:50 +0930 | [diff] [blame] | 134 | mctp_prdebug("%s: %zu bytes to 0x%lx", __func__, len, offset); |
| 135 | |
Andrew Jeffery | 06b2cd8 | 2020-03-17 23:12:27 +1030 | [diff] [blame] | 136 | assert(offset >= 0L); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 137 | assert(offset + len < mmio->lpc_size); |
| 138 | |
| 139 | memcpy(mmio->lpc + offset, buf, len); |
| 140 | |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 141 | return 0; |
| 142 | } |
| 143 | |
Andrew Jeffery | 85c04e4 | 2020-10-28 14:27:15 +1030 | [diff] [blame] | 144 | static const struct mctp_binding_astlpc_ops astlpc_indirect_mmio_ops = { |
| 145 | .kcs_read = mctp_astlpc_mmio_kcs_read, |
| 146 | .kcs_write = mctp_astlpc_mmio_kcs_write, |
| 147 | .lpc_read = mctp_astlpc_mmio_lpc_read, |
| 148 | .lpc_write = mctp_astlpc_mmio_lpc_write, |
| 149 | }; |
| 150 | |
Andrew Jeffery | b93b611 | 2020-06-05 14:13:44 +0930 | [diff] [blame] | 151 | #define __unused __attribute__((unused)) |
| 152 | |
| 153 | static void rx_message(uint8_t eid __unused, void *data __unused, void *msg, |
| 154 | size_t len) |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 155 | { |
Andrew Jeffery | 5a7c2db | 2020-05-22 20:13:42 +0930 | [diff] [blame] | 156 | struct astlpc_test *test = data; |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 157 | |
Andrew Jeffery | 5a7c2db | 2020-05-22 20:13:42 +0930 | [diff] [blame] | 158 | mctp_prdebug("MCTP message received: msg: %p, len %zd", msg, len); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 159 | |
Andrew Jeffery | 5a7c2db | 2020-05-22 20:13:42 +0930 | [diff] [blame] | 160 | assert(len > 0); |
| 161 | assert(msg); |
| 162 | assert(test); |
| 163 | assert(test->msg); |
| 164 | assert(!memcmp(test->msg, msg, len)); |
| 165 | |
| 166 | test->count++; |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 167 | } |
| 168 | |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 169 | static int endpoint_init(struct astlpc_endpoint *ep, mctp_eid_t eid, |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 170 | uint8_t mode, uint32_t mtu, uint8_t (*kcs)[2], |
| 171 | void *lpc_mem) |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 172 | { |
| 173 | /* |
| 174 | * Configure the direction of the KCS interface so we know whether to |
| 175 | * set or clear IBF or OBF on writes or reads. |
| 176 | */ |
| 177 | ep->mmio.bmc = (mode == MCTP_BINDING_ASTLPC_MODE_BMC); |
| 178 | |
| 179 | ep->mctp = mctp_init(); |
| 180 | assert(ep->mctp); |
| 181 | |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 182 | /* Inject KCS registers */ |
| 183 | ep->mmio.kcs = kcs; |
| 184 | |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 185 | /* Initialise the binding */ |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 186 | ep->astlpc = mctp_astlpc_init(mode, mtu, lpc_mem, |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 187 | &astlpc_direct_mmio_ops, &ep->mmio); |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 188 | assert(ep->astlpc); |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 189 | |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 190 | return mctp_register_bus(ep->mctp, &ep->astlpc->binding, eid); |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | static void endpoint_destroy(struct astlpc_endpoint *ep) |
| 194 | { |
| 195 | mctp_astlpc_destroy(ep->astlpc); |
| 196 | mctp_destroy(ep->mctp); |
| 197 | } |
| 198 | |
Andrew Jeffery | cb5d55c | 2020-05-22 13:26:27 +0930 | [diff] [blame] | 199 | static void network_init(struct astlpc_test *ctx) |
| 200 | { |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 201 | int rc; |
| 202 | |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 203 | ctx->lpc_mem = calloc(1, 1 * 1024 * 1024); |
Andrew Jeffery | cb5d55c | 2020-05-22 13:26:27 +0930 | [diff] [blame] | 204 | assert(ctx->lpc_mem); |
| 205 | |
| 206 | /* BMC initialisation */ |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 207 | rc = endpoint_init(&ctx->bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, MCTP_BTU, |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 208 | &ctx->kcs, ctx->lpc_mem); |
| 209 | assert(!rc); |
Andrew Jeffery | 3f32507 | 2020-05-28 09:19:51 +0930 | [diff] [blame] | 210 | assert(ctx->kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_BMC_READY); |
Andrew Jeffery | cb5d55c | 2020-05-22 13:26:27 +0930 | [diff] [blame] | 211 | |
| 212 | /* Host initialisation */ |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 213 | rc = endpoint_init(&ctx->host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 214 | MCTP_BTU, &ctx->kcs, ctx->lpc_mem); |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 215 | assert(!rc); |
Andrew Jeffery | cb5d55c | 2020-05-22 13:26:27 +0930 | [diff] [blame] | 216 | |
| 217 | /* BMC processes host channel init request, alerts host */ |
| 218 | mctp_astlpc_poll(ctx->bmc.astlpc); |
Andrew Jeffery | 3f32507 | 2020-05-28 09:19:51 +0930 | [diff] [blame] | 219 | assert(ctx->kcs[MCTP_ASTLPC_KCS_REG_STATUS] & |
| 220 | KCS_STATUS_CHANNEL_ACTIVE); |
| 221 | assert(ctx->kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0xff); |
Andrew Jeffery | cb5d55c | 2020-05-22 13:26:27 +0930 | [diff] [blame] | 222 | |
| 223 | /* Host dequeues channel init result */ |
| 224 | mctp_astlpc_poll(ctx->host.astlpc); |
| 225 | } |
| 226 | |
| 227 | static void network_destroy(struct astlpc_test *ctx) |
| 228 | { |
| 229 | endpoint_destroy(&ctx->bmc); |
| 230 | endpoint_destroy(&ctx->host); |
| 231 | free(ctx->lpc_mem); |
| 232 | } |
| 233 | |
Andrew Jeffery | 129ef93 | 2020-05-22 16:24:19 +0930 | [diff] [blame] | 234 | static void astlpc_assert_tx_packet(struct astlpc_endpoint *src, |
| 235 | const void *expected, size_t len) |
| 236 | { |
| 237 | const size_t tx_body = src->astlpc->layout.tx.offset + 4 + 4; |
| 238 | const void *test = ((char *)src->astlpc->lpc_map) + tx_body; |
| 239 | assert(!memcmp(test, expected, len)); |
| 240 | } |
| 241 | |
Andrew Jeffery | e756de8 | 2020-05-22 12:30:58 +0930 | [diff] [blame] | 242 | static void astlpc_test_packetised_message_bmc_to_host(void) |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 243 | { |
Andrew Jeffery | cb5d55c | 2020-05-22 13:26:27 +0930 | [diff] [blame] | 244 | struct astlpc_test ctx = { 0 }; |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 245 | uint8_t msg[2 * MCTP_BTU]; |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 246 | int rc; |
| 247 | |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 248 | /* Test harness initialisation */ |
| 249 | |
Andrew Jeffery | 5a7c2db | 2020-05-22 20:13:42 +0930 | [diff] [blame] | 250 | network_init(&ctx); |
| 251 | |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 252 | memset(&msg[0], 0x5a, MCTP_BTU); |
| 253 | memset(&msg[MCTP_BTU], 0xa5, MCTP_BTU); |
| 254 | |
Andrew Jeffery | 5a7c2db | 2020-05-22 20:13:42 +0930 | [diff] [blame] | 255 | ctx.msg = &msg[0]; |
| 256 | ctx.count = 0; |
| 257 | mctp_set_rx_all(ctx.host.mctp, rx_message, &ctx); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 258 | |
| 259 | /* BMC sends a message */ |
Andrew Jeffery | cb5d55c | 2020-05-22 13:26:27 +0930 | [diff] [blame] | 260 | rc = mctp_message_tx(ctx.bmc.mctp, 9, msg, sizeof(msg)); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 261 | assert(rc == 0); |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 262 | |
Andrew Jeffery | 129ef93 | 2020-05-22 16:24:19 +0930 | [diff] [blame] | 263 | /* Host receives the first packet */ |
Andrew Jeffery | cb5d55c | 2020-05-22 13:26:27 +0930 | [diff] [blame] | 264 | mctp_astlpc_poll(ctx.host.astlpc); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 265 | |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 266 | /* BMC dequeues ownership hand-over and sends the queued packet */ |
Andrew Jeffery | cb5d55c | 2020-05-22 13:26:27 +0930 | [diff] [blame] | 267 | rc = mctp_astlpc_poll(ctx.bmc.astlpc); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 268 | assert(rc == 0); |
| 269 | |
Andrew Jeffery | 129ef93 | 2020-05-22 16:24:19 +0930 | [diff] [blame] | 270 | /* Host receives the next packet */ |
Andrew Jeffery | cb5d55c | 2020-05-22 13:26:27 +0930 | [diff] [blame] | 271 | assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF); |
| 272 | assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x01); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 273 | |
Andrew Jeffery | 129ef93 | 2020-05-22 16:24:19 +0930 | [diff] [blame] | 274 | astlpc_assert_tx_packet(&ctx.bmc, &msg[MCTP_BTU], MCTP_BTU); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 275 | |
Andrew Jeffery | 5a7c2db | 2020-05-22 20:13:42 +0930 | [diff] [blame] | 276 | /* Host receives final packet */ |
| 277 | mctp_astlpc_poll(ctx.host.astlpc); |
| 278 | assert(ctx.count == 1); |
| 279 | |
Andrew Jeffery | cb5d55c | 2020-05-22 13:26:27 +0930 | [diff] [blame] | 280 | network_destroy(&ctx); |
Andrew Jeffery | e756de8 | 2020-05-22 12:30:58 +0930 | [diff] [blame] | 281 | } |
| 282 | |
Andrew Jeffery | ec9a006 | 2020-05-22 21:21:55 +0930 | [diff] [blame] | 283 | static void astlpc_test_simple_message_host_to_bmc(void) |
| 284 | { |
| 285 | struct astlpc_test ctx = { 0 }; |
| 286 | uint8_t msg[MCTP_BTU]; |
| 287 | int rc; |
| 288 | |
| 289 | /* Test harness initialisation */ |
| 290 | |
| 291 | network_init(&ctx); |
| 292 | |
| 293 | memset(&msg[0], 0xa5, MCTP_BTU); |
| 294 | |
| 295 | ctx.msg = &msg[0]; |
| 296 | ctx.count = 0; |
| 297 | mctp_set_rx_all(ctx.bmc.mctp, rx_message, &ctx); |
| 298 | |
| 299 | /* Host sends the single-packet message */ |
| 300 | rc = mctp_message_tx(ctx.host.mctp, 8, msg, sizeof(msg)); |
| 301 | assert(rc == 0); |
| 302 | assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_IBF); |
| 303 | assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x01); |
| 304 | |
| 305 | astlpc_assert_tx_packet(&ctx.host, &msg[0], MCTP_BTU); |
| 306 | |
| 307 | /* BMC receives the single-packet message */ |
| 308 | mctp_astlpc_poll(ctx.bmc.astlpc); |
| 309 | assert(ctx.count == 1); |
| 310 | |
| 311 | /* BMC returns Tx area ownership to Host */ |
| 312 | assert(!(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_IBF)); |
| 313 | assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x02); |
| 314 | assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF); |
| 315 | |
| 316 | /* Host dequeues ownership hand-over and sends the queued packet */ |
| 317 | rc = mctp_astlpc_poll(ctx.host.astlpc); |
| 318 | assert(rc == 0); |
| 319 | |
| 320 | network_destroy(&ctx); |
| 321 | } |
| 322 | |
Andrew Jeffery | 8f3eb72 | 2020-05-22 20:23:49 +0930 | [diff] [blame] | 323 | static void astlpc_test_simple_message_bmc_to_host(void) |
| 324 | { |
| 325 | struct astlpc_test ctx = { 0 }; |
| 326 | uint8_t msg[MCTP_BTU]; |
| 327 | int rc; |
| 328 | |
| 329 | /* Test harness initialisation */ |
| 330 | |
| 331 | network_init(&ctx); |
| 332 | |
| 333 | memset(&msg[0], 0x5a, MCTP_BTU); |
| 334 | |
| 335 | ctx.msg = &msg[0]; |
| 336 | ctx.count = 0; |
| 337 | mctp_set_rx_all(ctx.host.mctp, rx_message, &ctx); |
| 338 | |
| 339 | /* BMC sends the single-packet message */ |
| 340 | rc = mctp_message_tx(ctx.bmc.mctp, 9, msg, sizeof(msg)); |
| 341 | assert(rc == 0); |
| 342 | assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF); |
| 343 | assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x01); |
| 344 | |
| 345 | astlpc_assert_tx_packet(&ctx.bmc, &msg[0], MCTP_BTU); |
| 346 | |
| 347 | /* Host receives the single-packet message */ |
| 348 | mctp_astlpc_poll(ctx.host.astlpc); |
| 349 | assert(ctx.count == 1); |
| 350 | |
| 351 | /* Host returns Rx area ownership to BMC */ |
| 352 | assert(!(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF)); |
| 353 | assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x02); |
| 354 | assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_IBF); |
| 355 | |
| 356 | /* BMC dequeues ownership hand-over and sends the queued packet */ |
| 357 | rc = mctp_astlpc_poll(ctx.bmc.astlpc); |
| 358 | assert(rc == 0); |
| 359 | |
| 360 | network_destroy(&ctx); |
| 361 | } |
| 362 | |
Andrew Jeffery | f1cdb16 | 2020-05-23 21:25:21 +0930 | [diff] [blame] | 363 | static void astlpc_test_host_before_bmc(void) |
| 364 | { |
| 365 | struct mctp_binding_astlpc_mmio mmio = { 0 }; |
| 366 | struct mctp_binding_astlpc *astlpc; |
| 367 | uint8_t kcs[2] = { 0 }; |
| 368 | struct mctp *mctp; |
| 369 | int rc; |
| 370 | |
| 371 | mctp = mctp_init(); |
| 372 | assert(mctp); |
| 373 | |
| 374 | /* Inject KCS registers */ |
| 375 | mmio.kcs = &kcs; |
| 376 | |
| 377 | /* Initialise the binding */ |
| 378 | astlpc = mctp_astlpc_init(MCTP_BINDING_ASTLPC_MODE_HOST, MCTP_BTU, NULL, |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 379 | &astlpc_direct_mmio_ops, &mmio); |
Andrew Jeffery | f1cdb16 | 2020-05-23 21:25:21 +0930 | [diff] [blame] | 380 | |
| 381 | /* Register the binding to trigger the start-up sequence */ |
| 382 | rc = mctp_register_bus(mctp, &astlpc->binding, 8); |
| 383 | |
| 384 | /* Start-up should fail as we haven't initialised the BMC */ |
| 385 | assert(rc < 0); |
| 386 | |
| 387 | mctp_astlpc_destroy(astlpc); |
| 388 | mctp_destroy(mctp); |
| 389 | } |
| 390 | |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 391 | static void astlpc_test_bad_version(void) |
| 392 | { |
| 393 | assert(0 == |
| 394 | mctp_astlpc_negotiate_version(ASTLPC_VER_BAD, ASTLPC_VER_CUR, |
| 395 | ASTLPC_VER_MIN, ASTLPC_VER_CUR)); |
| 396 | assert(0 == |
| 397 | mctp_astlpc_negotiate_version(ASTLPC_VER_MIN, ASTLPC_VER_BAD, |
| 398 | ASTLPC_VER_MIN, ASTLPC_VER_CUR)); |
| 399 | assert(0 == |
| 400 | mctp_astlpc_negotiate_version(ASTLPC_VER_MIN, ASTLPC_VER_CUR, |
| 401 | ASTLPC_VER_BAD, ASTLPC_VER_CUR)); |
| 402 | assert(0 == |
| 403 | mctp_astlpc_negotiate_version(ASTLPC_VER_MIN, ASTLPC_VER_CUR, |
| 404 | ASTLPC_VER_MIN, ASTLPC_VER_BAD)); |
| 405 | assert(0 == mctp_astlpc_negotiate_version( |
| 406 | ASTLPC_VER_CUR + 1, ASTLPC_VER_CUR, ASTLPC_VER_MIN, |
| 407 | ASTLPC_VER_CUR + 1)); |
| 408 | assert(0 == mctp_astlpc_negotiate_version( |
| 409 | ASTLPC_VER_MIN, ASTLPC_VER_CUR + 1, |
| 410 | ASTLPC_VER_CUR + 1, ASTLPC_VER_CUR)); |
| 411 | } |
| 412 | |
| 413 | static void astlpc_test_incompatible_versions(void) |
| 414 | { |
| 415 | assert(0 == mctp_astlpc_negotiate_version( |
| 416 | ASTLPC_VER_CUR, ASTLPC_VER_CUR, ASTLPC_VER_CUR + 1, |
| 417 | ASTLPC_VER_CUR + 1)); |
| 418 | assert(0 == mctp_astlpc_negotiate_version( |
| 419 | ASTLPC_VER_CUR + 1, ASTLPC_VER_CUR + 1, |
| 420 | ASTLPC_VER_CUR, ASTLPC_VER_CUR)); |
| 421 | } |
| 422 | |
| 423 | static void astlpc_test_choose_bmc_ver_cur(void) |
| 424 | { |
| 425 | assert(2 == mctp_astlpc_negotiate_version(1, 2, 2, 3)); |
| 426 | } |
| 427 | |
| 428 | static void astlpc_test_choose_host_ver_cur(void) |
| 429 | { |
| 430 | assert(2 == mctp_astlpc_negotiate_version(2, 3, 1, 2)); |
| 431 | } |
| 432 | |
| 433 | static void astlpc_test_version_host_fails_negotiation(void) |
Andrew Jeffery | f1a2131 | 2020-05-22 12:48:21 +0930 | [diff] [blame] | 434 | { |
| 435 | struct astlpc_endpoint bmc, host; |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 436 | struct mctp_lpcmap_hdr *hdr; |
Andrew Jeffery | f1a2131 | 2020-05-22 12:48:21 +0930 | [diff] [blame] | 437 | uint8_t kcs[2] = { 0 }; |
Andrew Jeffery | f1a2131 | 2020-05-22 12:48:21 +0930 | [diff] [blame] | 438 | void *lpc_mem; |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 439 | int rc; |
Andrew Jeffery | f1a2131 | 2020-05-22 12:48:21 +0930 | [diff] [blame] | 440 | |
| 441 | /* Test harness initialisation */ |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 442 | lpc_mem = calloc(1, 1 * 1024 * 1024); |
Andrew Jeffery | f1a2131 | 2020-05-22 12:48:21 +0930 | [diff] [blame] | 443 | assert(lpc_mem); |
| 444 | |
Andrew Jeffery | 8f3eb72 | 2020-05-22 20:23:49 +0930 | [diff] [blame] | 445 | /* BMC initialisation */ |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 446 | rc = endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, MCTP_BTU, |
| 447 | &kcs, lpc_mem); |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 448 | assert(!rc); |
| 449 | |
| 450 | /* Now the BMC is initialised, break its version announcement */ |
| 451 | hdr = lpc_mem; |
| 452 | hdr->bmc_ver_cur = ASTLPC_VER_BAD; |
| 453 | |
| 454 | /* Host initialisation */ |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 455 | rc = endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, MCTP_BTU, |
| 456 | &kcs, lpc_mem); |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 457 | assert(rc < 0); |
| 458 | |
| 459 | endpoint_destroy(&bmc); |
| 460 | endpoint_destroy(&host); |
| 461 | free(lpc_mem); |
| 462 | } |
| 463 | |
| 464 | static void astlpc_test_version_bmc_fails_negotiation(void) |
| 465 | { |
| 466 | struct astlpc_endpoint bmc, host; |
| 467 | struct mctp_lpcmap_hdr *hdr; |
| 468 | uint8_t kcs[2] = { 0 }; |
| 469 | void *lpc_mem; |
| 470 | int rc; |
| 471 | |
| 472 | /* Test harness initialisation */ |
| 473 | lpc_mem = calloc(1, 1 * 1024 * 1024); |
| 474 | assert(lpc_mem); |
| 475 | |
| 476 | /* BMC initialisation */ |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 477 | rc = endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, MCTP_BTU, |
| 478 | &kcs, lpc_mem); |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 479 | assert(!rc); |
| 480 | |
| 481 | /* Host initialisation */ |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 482 | rc = endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, MCTP_BTU, |
| 483 | &kcs, lpc_mem); |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 484 | assert(!rc); |
| 485 | |
| 486 | /* Now the host is initialised, break its version announcement */ |
| 487 | hdr = lpc_mem; |
| 488 | hdr->host_ver_cur = ASTLPC_VER_BAD; |
| 489 | |
| 490 | /* Poll the BMC to detect the broken host version */ |
| 491 | mctp_astlpc_poll(bmc.astlpc); |
| 492 | assert(!(kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_CHANNEL_ACTIVE)); |
| 493 | |
| 494 | /* Poll the host so it detects failed negotiation */ |
| 495 | rc = mctp_astlpc_poll(host.astlpc); |
| 496 | assert(rc < 0); |
| 497 | |
| 498 | endpoint_destroy(&bmc); |
| 499 | endpoint_destroy(&host); |
| 500 | free(lpc_mem); |
| 501 | } |
| 502 | |
| 503 | static void astlpc_test_simple_init(void) |
| 504 | { |
| 505 | struct astlpc_endpoint bmc, host; |
| 506 | uint8_t kcs[2] = { 0 }; |
| 507 | void *lpc_mem; |
| 508 | int rc; |
| 509 | |
| 510 | /* Test harness initialisation */ |
| 511 | lpc_mem = calloc(1, 1 * 1024 * 1024); |
| 512 | assert(lpc_mem); |
| 513 | |
| 514 | /* BMC initialisation */ |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 515 | rc = endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, MCTP_BTU, |
| 516 | &kcs, lpc_mem); |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 517 | assert(!rc); |
Andrew Jeffery | f1a2131 | 2020-05-22 12:48:21 +0930 | [diff] [blame] | 518 | |
| 519 | /* Verify the BMC binding was initialised */ |
| 520 | assert(kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_BMC_READY); |
| 521 | |
Andrew Jeffery | 8f3eb72 | 2020-05-22 20:23:49 +0930 | [diff] [blame] | 522 | /* Host initialisation */ |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 523 | rc = endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, MCTP_BTU, |
| 524 | &kcs, lpc_mem); |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 525 | assert(!rc); |
Andrew Jeffery | f1a2131 | 2020-05-22 12:48:21 +0930 | [diff] [blame] | 526 | |
| 527 | /* Host sends channel init command */ |
| 528 | assert(kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_IBF); |
| 529 | assert(kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x00); |
| 530 | |
| 531 | /* BMC receives host channel init request */ |
| 532 | mctp_astlpc_poll(bmc.astlpc); |
| 533 | |
| 534 | /* BMC sends init response */ |
| 535 | assert(kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF); |
| 536 | assert(kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_CHANNEL_ACTIVE); |
| 537 | assert(kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0xff); |
| 538 | |
| 539 | /* Host dequeues data */ |
| 540 | mctp_astlpc_poll(host.astlpc); |
| 541 | |
| 542 | endpoint_destroy(&bmc); |
| 543 | endpoint_destroy(&host); |
| 544 | free(lpc_mem); |
| 545 | } |
| 546 | |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 547 | static void astlpc_test_simple_indirect_message_bmc_to_host(void) |
| 548 | { |
| 549 | struct astlpc_test ctx = { 0 }; |
| 550 | uint8_t kcs[2] = { 0 }; |
| 551 | uint8_t msg[MCTP_BTU]; |
| 552 | int rc; |
| 553 | |
| 554 | ctx.lpc_mem = calloc(1, LPC_WIN_SIZE); |
| 555 | assert(ctx.lpc_mem); |
| 556 | |
| 557 | /* Test message data */ |
| 558 | memset(&msg[0], 0x5a, MCTP_BTU); |
| 559 | |
| 560 | /* Manually set up the network so we can inject the indirect ops */ |
| 561 | |
| 562 | /* BMC initialisation */ |
| 563 | ctx.bmc.mmio.bmc = true; |
| 564 | ctx.bmc.mctp = mctp_init(); |
| 565 | assert(ctx.bmc.mctp); |
| 566 | ctx.bmc.mmio.kcs = &kcs; |
| 567 | ctx.bmc.mmio.lpc = ctx.lpc_mem; |
| 568 | ctx.bmc.mmio.lpc_size = LPC_WIN_SIZE; |
| 569 | ctx.bmc.astlpc = |
| 570 | mctp_astlpc_init(MCTP_BINDING_ASTLPC_MODE_BMC, MCTP_BTU, NULL, |
| 571 | &astlpc_indirect_mmio_ops, &ctx.bmc.mmio); |
| 572 | mctp_register_bus(ctx.bmc.mctp, &ctx.bmc.astlpc->binding, 8); |
| 573 | |
| 574 | /* Host initialisation */ |
| 575 | ctx.host.mmio.bmc = false; |
| 576 | ctx.host.mctp = mctp_init(); |
| 577 | assert(ctx.host.mctp); |
| 578 | ctx.host.mmio.kcs = &kcs; |
| 579 | ctx.host.mmio.lpc = ctx.lpc_mem; |
| 580 | ctx.host.mmio.lpc_size = LPC_WIN_SIZE; |
| 581 | ctx.host.astlpc = |
| 582 | mctp_astlpc_init(MCTP_BINDING_ASTLPC_MODE_HOST, MCTP_BTU, NULL, |
| 583 | &astlpc_indirect_mmio_ops, &ctx.host.mmio); |
| 584 | mctp_register_bus(ctx.host.mctp, &ctx.host.astlpc->binding, 9); |
| 585 | |
| 586 | /* BMC processes host channel init request, alerts host */ |
| 587 | mctp_astlpc_poll(ctx.bmc.astlpc); |
| 588 | |
| 589 | /* Host dequeues channel init result */ |
| 590 | mctp_astlpc_poll(ctx.host.astlpc); |
| 591 | |
| 592 | ctx.msg = &msg[0]; |
| 593 | ctx.count = 0; |
| 594 | mctp_set_rx_all(ctx.host.mctp, rx_message, &ctx); |
| 595 | |
| 596 | /* BMC sends the single-packet message */ |
| 597 | rc = mctp_message_tx(ctx.bmc.mctp, 9, msg, sizeof(msg)); |
| 598 | assert(rc == 0); |
| 599 | |
| 600 | /* Host receives the single-packet message */ |
| 601 | rc = mctp_astlpc_poll(ctx.host.astlpc); |
| 602 | assert(rc == 0); |
| 603 | assert(ctx.count == 1); |
| 604 | |
| 605 | /* BMC dequeues ownership hand-over and sends the queued packet */ |
| 606 | rc = mctp_astlpc_poll(ctx.bmc.astlpc); |
| 607 | assert(rc == 0); |
| 608 | |
| 609 | /* Can still tear-down the network in the normal fashion */ |
| 610 | network_destroy(&ctx); |
| 611 | } |
| 612 | |
Andrew Jeffery | d0f5da0 | 2020-05-28 09:12:55 +0930 | [diff] [blame] | 613 | static void astlpc_test_host_tx_bmc_gone(void) |
| 614 | { |
| 615 | struct astlpc_test ctx = { 0 }; |
| 616 | uint8_t unwritten[MCTP_BTU]; |
| 617 | uint8_t msg[MCTP_BTU]; |
| 618 | int rc; |
| 619 | |
| 620 | /* Test harness initialisation */ |
| 621 | |
| 622 | network_init(&ctx); |
| 623 | |
| 624 | memset(&msg[0], 0x5a, sizeof(msg)); |
| 625 | memset(&unwritten[0], 0, sizeof(unwritten)); |
| 626 | |
| 627 | ctx.msg = &msg[0]; |
| 628 | ctx.count = 0; |
| 629 | |
| 630 | /* Clear bmc-ready */ |
| 631 | endpoint_destroy(&ctx.bmc); |
| 632 | |
| 633 | /* Host detects that the BMC is disabled */ |
| 634 | mctp_astlpc_poll(ctx.host.astlpc); |
| 635 | |
| 636 | /* Host attempts to send the single-packet message, but is prevented */ |
| 637 | rc = mctp_message_tx(ctx.host.mctp, 8, msg, sizeof(msg)); |
| 638 | assert(rc == 0); |
| 639 | assert(!(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF)); |
| 640 | astlpc_assert_tx_packet(&ctx.host, &unwritten[0], MCTP_BTU); |
| 641 | |
| 642 | /* BMC comes back */ |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 643 | rc = endpoint_init(&ctx.bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, MCTP_BTU, |
| 644 | &ctx.kcs, ctx.lpc_mem); |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 645 | assert(!rc); |
Andrew Jeffery | d0f5da0 | 2020-05-28 09:12:55 +0930 | [diff] [blame] | 646 | mctp_set_rx_all(ctx.bmc.mctp, rx_message, &ctx); |
| 647 | |
| 648 | /* Host triggers channel init */ |
| 649 | mctp_astlpc_poll(ctx.host.astlpc); |
| 650 | |
| 651 | /* BMC handles channel init */ |
| 652 | mctp_astlpc_poll(ctx.bmc.astlpc); |
| 653 | |
| 654 | /* Host completes channel init, flushing the Tx queue */ |
| 655 | mctp_astlpc_poll(ctx.host.astlpc); |
| 656 | |
| 657 | /* BMC receives the single-packet message */ |
| 658 | mctp_astlpc_poll(ctx.bmc.astlpc); |
| 659 | assert(ctx.count == 1); |
| 660 | |
| 661 | network_destroy(&ctx); |
| 662 | } |
| 663 | |
Andrew Jeffery | f3d94dc | 2020-05-28 10:50:18 +0930 | [diff] [blame] | 664 | static void astlpc_test_poll_not_ready(void) |
| 665 | { |
| 666 | struct astlpc_endpoint bmc; |
| 667 | uint8_t kcs[2] = { 0 }; |
| 668 | void *lpc_mem; |
| 669 | int rc; |
| 670 | |
| 671 | /* Test harness initialisation */ |
| 672 | lpc_mem = calloc(1, 1 * 1024 * 1024); |
| 673 | assert(lpc_mem); |
| 674 | |
| 675 | /* BMC initialisation */ |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 676 | rc = endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, MCTP_BTU, |
| 677 | &kcs, lpc_mem); |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 678 | assert(!rc); |
Andrew Jeffery | f3d94dc | 2020-05-28 10:50:18 +0930 | [diff] [blame] | 679 | |
| 680 | /* Check for a command despite none present */ |
| 681 | rc = mctp_astlpc_poll(bmc.astlpc); |
| 682 | |
| 683 | /* Make sure it doesn't fail */ |
| 684 | assert(rc == 0); |
| 685 | |
| 686 | endpoint_destroy(&bmc); |
| 687 | free(lpc_mem); |
| 688 | } |
| 689 | |
Andrew Jeffery | 67655e8 | 2020-05-28 10:51:27 +0930 | [diff] [blame] | 690 | static void astlpc_test_undefined_command(void) |
| 691 | { |
| 692 | struct astlpc_endpoint bmc; |
| 693 | uint8_t kcs[2] = { 0 }; |
| 694 | void *lpc_mem; |
| 695 | int rc; |
| 696 | |
| 697 | /* Test harness initialisation */ |
| 698 | lpc_mem = calloc(1, 1 * 1024 * 1024); |
| 699 | assert(lpc_mem); |
| 700 | |
| 701 | /* BMC initialisation */ |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 702 | rc = endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, MCTP_BTU, |
| 703 | &kcs, lpc_mem); |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 704 | assert(!rc); |
Andrew Jeffery | 67655e8 | 2020-05-28 10:51:27 +0930 | [diff] [blame] | 705 | |
| 706 | /* 0x5a isn't legal in v1 or v2 */ |
| 707 | kcs[MCTP_ASTLPC_KCS_REG_DATA] = 0x5a; |
| 708 | kcs[MCTP_ASTLPC_KCS_REG_STATUS] |= KCS_STATUS_IBF; |
| 709 | |
| 710 | /* Check for a command despite none present */ |
| 711 | rc = mctp_astlpc_poll(bmc.astlpc); |
| 712 | |
| 713 | /* Make sure it doesn't fail, bad command should be discarded */ |
| 714 | assert(rc == 0); |
| 715 | |
| 716 | endpoint_destroy(&bmc); |
| 717 | free(lpc_mem); |
| 718 | } |
| 719 | |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 720 | #define BUFFER_MIN ASTLPC_PACKET_SIZE(MCTP_PACKET_SIZE(MCTP_BTU)) |
| 721 | |
| 722 | static void astlpc_test_buffers_rx_offset_overflow(void) |
| 723 | { |
| 724 | struct mctp_astlpc_layout l = { |
| 725 | .rx = { UINT32_MAX, BUFFER_MIN }, |
| 726 | .tx = { control_size, BUFFER_MIN }, |
| 727 | }; |
| 728 | |
| 729 | assert(!mctp_astlpc_layout_validate(&l)); |
| 730 | } |
| 731 | |
| 732 | static void astlpc_test_buffers_tx_offset_overflow(void) |
| 733 | { |
| 734 | struct mctp_astlpc_layout l = { |
| 735 | .rx = { control_size, BUFFER_MIN }, |
| 736 | .tx = { UINT32_MAX, BUFFER_MIN }, |
| 737 | }; |
| 738 | |
| 739 | assert(!mctp_astlpc_layout_validate(&l)); |
| 740 | } |
| 741 | |
| 742 | static void astlpc_test_buffers_rx_size_overflow(void) |
| 743 | { |
| 744 | struct mctp_astlpc_layout l = { |
| 745 | .rx = { control_size + BUFFER_MIN, UINT32_MAX }, |
| 746 | .tx = { control_size, BUFFER_MIN }, |
| 747 | }; |
| 748 | |
| 749 | assert(!mctp_astlpc_layout_validate(&l)); |
| 750 | } |
| 751 | |
| 752 | static void astlpc_test_buffers_tx_size_overflow(void) |
| 753 | { |
| 754 | struct mctp_astlpc_layout l = { |
| 755 | .rx = { control_size, BUFFER_MIN }, |
| 756 | .tx = { control_size + BUFFER_MIN, UINT32_MAX }, |
| 757 | }; |
| 758 | |
| 759 | assert(!mctp_astlpc_layout_validate(&l)); |
| 760 | } |
| 761 | |
| 762 | static void astlpc_test_buffers_rx_window_violation(void) |
| 763 | { |
| 764 | struct mctp_astlpc_layout l = { |
| 765 | .rx = { LPC_WIN_SIZE - BUFFER_MIN + 1, BUFFER_MIN }, |
| 766 | .tx = { control_size, BUFFER_MIN }, |
| 767 | }; |
| 768 | |
| 769 | assert(!mctp_astlpc_layout_validate(&l)); |
| 770 | } |
| 771 | |
| 772 | static void astlpc_test_buffers_tx_window_violation(void) |
| 773 | { |
| 774 | struct mctp_astlpc_layout l = { |
| 775 | .rx = { control_size, BUFFER_MIN }, |
| 776 | .tx = { LPC_WIN_SIZE - BUFFER_MIN + 1, BUFFER_MIN }, |
| 777 | }; |
| 778 | |
| 779 | assert(!mctp_astlpc_layout_validate(&l)); |
| 780 | } |
| 781 | |
| 782 | static void astlpc_test_buffers_rx_size_fails_btu(void) |
| 783 | { |
| 784 | struct mctp_astlpc_layout l = { |
| 785 | .rx = { control_size, BUFFER_MIN - 1 }, |
| 786 | .tx = { control_size + BUFFER_MIN, BUFFER_MIN }, |
| 787 | }; |
| 788 | |
| 789 | assert(!mctp_astlpc_layout_validate(&l)); |
| 790 | } |
| 791 | |
| 792 | static void astlpc_test_buffers_tx_size_fails_btu(void) |
| 793 | { |
| 794 | struct mctp_astlpc_layout l = { |
| 795 | .rx = { control_size, BUFFER_MIN }, |
| 796 | .tx = { control_size + BUFFER_MIN, BUFFER_MIN - 1 }, |
| 797 | }; |
| 798 | |
| 799 | assert(!mctp_astlpc_layout_validate(&l)); |
| 800 | } |
| 801 | |
| 802 | static void astlpc_test_buffers_overlap_rx_low(void) |
| 803 | { |
| 804 | struct mctp_astlpc_layout l = { |
| 805 | .rx = { control_size, 2 * BUFFER_MIN }, |
| 806 | .tx = { control_size + BUFFER_MIN, 2 * BUFFER_MIN }, |
| 807 | }; |
| 808 | |
| 809 | assert(!mctp_astlpc_layout_validate(&l)); |
| 810 | } |
| 811 | |
| 812 | static void astlpc_test_buffers_overlap_tx_low(void) |
| 813 | { |
| 814 | struct mctp_astlpc_layout l = { |
| 815 | .rx = { control_size + BUFFER_MIN, 2 * BUFFER_MIN }, |
| 816 | .tx = { control_size, 2 * BUFFER_MIN }, |
| 817 | }; |
| 818 | |
| 819 | assert(!mctp_astlpc_layout_validate(&l)); |
| 820 | } |
| 821 | |
| 822 | static void astlpc_test_buffers_overlap_exact(void) |
| 823 | { |
| 824 | struct mctp_astlpc_layout l = { |
| 825 | .rx = { control_size, 2 * BUFFER_MIN }, |
| 826 | .tx = { control_size, 2 * BUFFER_MIN }, |
| 827 | }; |
| 828 | |
| 829 | assert(!mctp_astlpc_layout_validate(&l)); |
| 830 | } |
| 831 | |
| 832 | static void astlpc_test_buffers_overlap_control(void) |
| 833 | { |
| 834 | struct mctp_astlpc_layout l = { |
| 835 | .rx = { 0, BUFFER_MIN }, |
| 836 | .tx = { control_size + BUFFER_MIN, BUFFER_MIN }, |
| 837 | }; |
| 838 | |
| 839 | assert(!mctp_astlpc_layout_validate(&l)); |
| 840 | } |
| 841 | |
| 842 | static void astlpc_test_buffers_bad_host_proposal(void) |
| 843 | { |
| 844 | struct astlpc_endpoint bmc, host; |
| 845 | struct mctp_lpcmap_hdr *hdr; |
| 846 | uint8_t kcs[2] = { 0 }; |
| 847 | void *lpc_mem; |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 848 | int rc; |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 849 | |
| 850 | /* Test harness initialisation */ |
| 851 | lpc_mem = calloc(1, 1 * 1024 * 1024); |
| 852 | assert(lpc_mem); |
| 853 | |
| 854 | /* BMC initialisation */ |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 855 | rc = endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, MCTP_BTU, |
| 856 | &kcs, lpc_mem); |
| 857 | assert(!rc); |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 858 | |
| 859 | /* Host initialisation */ |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 860 | rc = endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, MCTP_BTU, |
| 861 | &kcs, lpc_mem); |
| 862 | assert(!rc); |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 863 | |
| 864 | /* |
| 865 | * Now that the host has initialised the control area, break |
| 866 | * something before polling the BMC |
| 867 | */ |
| 868 | hdr = lpc_mem; |
| 869 | hdr->layout.rx_size = 0; |
| 870 | |
| 871 | mctp_astlpc_poll(bmc.astlpc); |
| 872 | |
| 873 | /* Make sure the BMC has not set the channel to active */ |
| 874 | assert(!(kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_CHANNEL_ACTIVE)); |
| 875 | |
| 876 | endpoint_destroy(&host); |
| 877 | endpoint_destroy(&bmc); |
| 878 | free(lpc_mem); |
| 879 | } |
| 880 | |
| 881 | static void astlpc_test_buffers_bad_bmc_proposal(void) |
| 882 | { |
| 883 | struct astlpc_endpoint bmc, host; |
| 884 | struct mctp_lpcmap_hdr *hdr; |
| 885 | uint8_t kcs[2] = { 0 }; |
| 886 | void *lpc_mem; |
| 887 | int rc; |
| 888 | |
| 889 | /* Test harness initialisation */ |
| 890 | lpc_mem = calloc(1, 1 * 1024 * 1024); |
| 891 | assert(lpc_mem); |
| 892 | |
| 893 | /* BMC initialisation */ |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 894 | rc = endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, MCTP_BTU, |
| 895 | &kcs, lpc_mem); |
| 896 | assert(!rc); |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 897 | |
| 898 | /* |
| 899 | * Now that the BMC has initialised the control area, break something |
| 900 | * before initialising the host |
| 901 | */ |
| 902 | hdr = lpc_mem; |
| 903 | hdr->layout.rx_size = 0; |
| 904 | |
| 905 | /* Host initialisation: Fails due to bad layout */ |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 906 | rc = endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, MCTP_BTU, |
| 907 | &kcs, lpc_mem); |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 908 | assert(rc < 0); |
| 909 | |
| 910 | endpoint_destroy(&host); |
| 911 | endpoint_destroy(&bmc); |
| 912 | free(lpc_mem); |
| 913 | } |
| 914 | |
| 915 | static void astlpc_test_buffers_bad_bmc_negotiation(void) |
| 916 | { |
| 917 | struct astlpc_endpoint bmc, host; |
| 918 | struct mctp_lpcmap_hdr *hdr; |
| 919 | uint8_t kcs[2] = { 0 }; |
| 920 | void *lpc_mem; |
| 921 | int rc; |
| 922 | |
| 923 | /* Test harness initialisation */ |
| 924 | lpc_mem = calloc(1, 1 * 1024 * 1024); |
| 925 | assert(lpc_mem); |
| 926 | |
| 927 | /* BMC initialisation */ |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 928 | rc = endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, MCTP_BTU, |
| 929 | &kcs, lpc_mem); |
| 930 | assert(!rc); |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 931 | |
| 932 | /* Host initialisation */ |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 933 | rc = endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, MCTP_BTU, |
| 934 | &kcs, lpc_mem); |
| 935 | assert(!rc); |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 936 | |
| 937 | mctp_astlpc_poll(bmc.astlpc); |
| 938 | |
| 939 | /* |
| 940 | * Now that the BMC has initialised the control area, break something |
| 941 | * before polling the host |
| 942 | */ |
| 943 | hdr = lpc_mem; |
| 944 | hdr->layout.rx_size = 0; |
| 945 | |
| 946 | rc = mctp_astlpc_poll(host.astlpc); |
| 947 | assert(rc < 0); |
| 948 | |
| 949 | endpoint_destroy(&host); |
| 950 | endpoint_destroy(&bmc); |
| 951 | free(lpc_mem); |
| 952 | } |
| 953 | |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 954 | static void astlpc_test_buffers_bad_host_init(void) |
| 955 | { |
| 956 | struct astlpc_endpoint host; |
| 957 | uint8_t kcs[2] = { 0 }; |
| 958 | void *lpc_mem; |
| 959 | int rc; |
| 960 | |
| 961 | /* Test harness initialisation */ |
| 962 | lpc_mem = calloc(1, 1 * 1024 * 1024); |
| 963 | assert(lpc_mem); |
| 964 | |
| 965 | host.mctp = mctp_init(); |
| 966 | assert(host.mctp); |
| 967 | host.mmio.kcs = &kcs; |
| 968 | host.mmio.bmc = false; |
| 969 | |
| 970 | /* Set the MTU to 0 to provoke a failure */ |
| 971 | host.astlpc = |
| 972 | mctp_astlpc_init(MCTP_BINDING_ASTLPC_MODE_HOST, 0, lpc_mem, |
| 973 | &astlpc_direct_mmio_ops, &host.mmio); |
| 974 | |
| 975 | rc = mctp_register_bus(host.mctp, &host.astlpc->binding, 8); |
| 976 | assert(rc < 0); |
| 977 | |
| 978 | mctp_astlpc_destroy(host.astlpc); |
| 979 | mctp_destroy(host.mctp); |
| 980 | free(lpc_mem); |
| 981 | } |
| 982 | |
| 983 | static void astlpc_test_negotiate_increased_mtu(void) |
| 984 | { |
| 985 | struct astlpc_endpoint bmc, host; |
| 986 | uint8_t kcs[2] = { 0 }; |
| 987 | void *lpc_mem; |
| 988 | int rc; |
| 989 | |
| 990 | /* Test harness initialisation */ |
| 991 | lpc_mem = calloc(1, 1 * 1024 * 1024); |
| 992 | assert(lpc_mem); |
| 993 | |
| 994 | /* BMC initialisation */ |
| 995 | rc = endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, 3 * MCTP_BTU, |
| 996 | &kcs, lpc_mem); |
| 997 | assert(!rc); |
| 998 | |
| 999 | /* Host initialisation */ |
| 1000 | rc = endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, |
| 1001 | 2 * MCTP_BTU, &kcs, lpc_mem); |
| 1002 | assert(!rc); |
| 1003 | |
| 1004 | rc = mctp_astlpc_poll(bmc.astlpc); |
| 1005 | assert(rc == 0); |
| 1006 | |
| 1007 | rc = mctp_astlpc_poll(host.astlpc); |
| 1008 | assert(rc == 0); |
| 1009 | |
| 1010 | endpoint_destroy(&host); |
| 1011 | endpoint_destroy(&bmc); |
| 1012 | free(lpc_mem); |
| 1013 | } |
| 1014 | |
| 1015 | static void astlpc_test_negotiate_mtu_low_high(void) |
| 1016 | { |
| 1017 | struct astlpc_endpoint bmc, host; |
| 1018 | uint8_t kcs[2] = { 0 }; |
| 1019 | void *lpc_mem; |
| 1020 | int rc; |
| 1021 | |
| 1022 | /* Test harness initialisation */ |
| 1023 | lpc_mem = calloc(1, 1 * 1024 * 1024); |
| 1024 | assert(lpc_mem); |
| 1025 | |
| 1026 | /* BMC initialisation */ |
| 1027 | rc = endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, 3 * MCTP_BTU, |
| 1028 | &kcs, lpc_mem); |
| 1029 | assert(!rc); |
| 1030 | |
| 1031 | /* Host initialisation with low MTU */ |
| 1032 | rc = endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, |
| 1033 | 2 * MCTP_BTU, &kcs, lpc_mem); |
| 1034 | assert(!rc); |
| 1035 | |
| 1036 | /* Process low MTU proposal */ |
| 1037 | rc = mctp_astlpc_poll(bmc.astlpc); |
| 1038 | assert(rc == 0); |
| 1039 | |
| 1040 | /* Accept low MTU proposal */ |
| 1041 | rc = mctp_astlpc_poll(host.astlpc); |
| 1042 | assert(rc == 0); |
| 1043 | |
| 1044 | assert(host.astlpc->layout.rx.size == |
| 1045 | ASTLPC_PACKET_SIZE(MCTP_PACKET_SIZE(2 * MCTP_BTU))); |
| 1046 | |
| 1047 | /* Tear-down the host so we can bring up a new one */ |
| 1048 | endpoint_destroy(&host); |
| 1049 | |
| 1050 | /* |
| 1051 | * Bring up a new host endpoint with a higher MTU than we previously |
| 1052 | * negotiated |
| 1053 | */ |
| 1054 | rc = endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, |
| 1055 | 3 * MCTP_BTU, &kcs, lpc_mem); |
| 1056 | assert(!rc); |
| 1057 | |
| 1058 | /* Process high MTU proposal */ |
| 1059 | rc = mctp_astlpc_poll(bmc.astlpc); |
| 1060 | assert(rc == 0); |
| 1061 | |
| 1062 | /* Accept high MTU proposal */ |
| 1063 | rc = mctp_astlpc_poll(host.astlpc); |
| 1064 | assert(rc == 0); |
| 1065 | |
| 1066 | assert(host.astlpc->layout.rx.size == |
| 1067 | ASTLPC_PACKET_SIZE(MCTP_PACKET_SIZE(3 * MCTP_BTU))); |
| 1068 | |
| 1069 | endpoint_destroy(&host); |
| 1070 | endpoint_destroy(&bmc); |
| 1071 | free(lpc_mem); |
| 1072 | } |
| 1073 | |
Andrew Jeffery | c2b833e | 2020-10-28 14:28:37 +1030 | [diff] [blame^] | 1074 | static void astlpc_test_send_large_packet(void) |
| 1075 | { |
| 1076 | struct astlpc_endpoint *bmc, *host; |
| 1077 | struct astlpc_test ctx; |
| 1078 | uint8_t kcs[2] = { 0 }; |
| 1079 | void *lpc_mem; |
| 1080 | int rc; |
| 1081 | |
| 1082 | host = &ctx.host; |
| 1083 | bmc = &ctx.bmc; |
| 1084 | |
| 1085 | /* Test harness initialisation */ |
| 1086 | lpc_mem = calloc(1, 1 * 1024 * 1024); |
| 1087 | assert(lpc_mem); |
| 1088 | |
| 1089 | /* BMC initialisation */ |
| 1090 | rc = endpoint_init(bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, 8192, &kcs, |
| 1091 | lpc_mem); |
| 1092 | assert(!rc); |
| 1093 | |
| 1094 | /* Host initialisation */ |
| 1095 | rc = endpoint_init(host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, 8192, &kcs, |
| 1096 | lpc_mem); |
| 1097 | assert(!rc); |
| 1098 | |
| 1099 | ctx.count = 0; |
| 1100 | mctp_set_rx_all(bmc->mctp, rx_message, &ctx); |
| 1101 | |
| 1102 | rc = mctp_astlpc_poll(bmc->astlpc); |
| 1103 | assert(rc == 0); |
| 1104 | |
| 1105 | rc = mctp_astlpc_poll(host->astlpc); |
| 1106 | assert(rc == 0); |
| 1107 | |
| 1108 | ctx.msg = malloc(2 * MCTP_BODY_SIZE(8192)); |
| 1109 | assert(ctx.msg); |
| 1110 | |
| 1111 | memset(ctx.msg, 0x5a, 2 * MCTP_BODY_SIZE(8192)); |
| 1112 | |
| 1113 | rc = mctp_message_tx(host->mctp, 8, ctx.msg, 2 * MCTP_BODY_SIZE(8192)); |
| 1114 | assert(rc == 0); |
| 1115 | rc = mctp_astlpc_poll(bmc->astlpc); |
| 1116 | assert(rc == 0); |
| 1117 | rc = mctp_astlpc_poll(host->astlpc); |
| 1118 | assert(rc == 0); |
| 1119 | rc = mctp_astlpc_poll(bmc->astlpc); |
| 1120 | assert(rc == 0); |
| 1121 | rc = mctp_astlpc_poll(host->astlpc); |
| 1122 | assert(rc == 0); |
| 1123 | |
| 1124 | assert(ctx.count == 1); |
| 1125 | |
| 1126 | free(ctx.msg); |
| 1127 | endpoint_destroy(host); |
| 1128 | endpoint_destroy(bmc); |
| 1129 | free(lpc_mem); |
| 1130 | } |
| 1131 | |
Andrew Jeffery | 91f09ed | 2020-05-22 20:52:26 +0930 | [diff] [blame] | 1132 | /* clang-format off */ |
| 1133 | #define TEST_CASE(test) { #test, test } |
| 1134 | static const struct { |
| 1135 | const char *name; |
| 1136 | void (*test)(void); |
| 1137 | } astlpc_tests[] = { |
| 1138 | TEST_CASE(astlpc_test_simple_init), |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 1139 | TEST_CASE(astlpc_test_bad_version), |
| 1140 | TEST_CASE(astlpc_test_incompatible_versions), |
| 1141 | TEST_CASE(astlpc_test_choose_bmc_ver_cur), |
| 1142 | TEST_CASE(astlpc_test_choose_host_ver_cur), |
| 1143 | TEST_CASE(astlpc_test_version_host_fails_negotiation), |
| 1144 | TEST_CASE(astlpc_test_version_bmc_fails_negotiation), |
Andrew Jeffery | f1cdb16 | 2020-05-23 21:25:21 +0930 | [diff] [blame] | 1145 | TEST_CASE(astlpc_test_host_before_bmc), |
Andrew Jeffery | 91f09ed | 2020-05-22 20:52:26 +0930 | [diff] [blame] | 1146 | TEST_CASE(astlpc_test_simple_message_bmc_to_host), |
Andrew Jeffery | ec9a006 | 2020-05-22 21:21:55 +0930 | [diff] [blame] | 1147 | TEST_CASE(astlpc_test_simple_message_host_to_bmc), |
Andrew Jeffery | 91f09ed | 2020-05-22 20:52:26 +0930 | [diff] [blame] | 1148 | TEST_CASE(astlpc_test_packetised_message_bmc_to_host), |
Andrew Jeffery | d0f5da0 | 2020-05-28 09:12:55 +0930 | [diff] [blame] | 1149 | TEST_CASE(astlpc_test_simple_indirect_message_bmc_to_host), |
| 1150 | TEST_CASE(astlpc_test_host_tx_bmc_gone), |
Andrew Jeffery | f3d94dc | 2020-05-28 10:50:18 +0930 | [diff] [blame] | 1151 | TEST_CASE(astlpc_test_poll_not_ready), |
Andrew Jeffery | 67655e8 | 2020-05-28 10:51:27 +0930 | [diff] [blame] | 1152 | TEST_CASE(astlpc_test_undefined_command), |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 1153 | TEST_CASE(astlpc_test_buffers_rx_offset_overflow), |
| 1154 | TEST_CASE(astlpc_test_buffers_tx_offset_overflow), |
| 1155 | TEST_CASE(astlpc_test_buffers_rx_size_overflow), |
| 1156 | TEST_CASE(astlpc_test_buffers_tx_size_overflow), |
| 1157 | TEST_CASE(astlpc_test_buffers_rx_window_violation), |
| 1158 | TEST_CASE(astlpc_test_buffers_tx_window_violation), |
| 1159 | TEST_CASE(astlpc_test_buffers_rx_size_fails_btu), |
| 1160 | TEST_CASE(astlpc_test_buffers_tx_size_fails_btu), |
| 1161 | TEST_CASE(astlpc_test_buffers_overlap_rx_low), |
| 1162 | TEST_CASE(astlpc_test_buffers_overlap_tx_low), |
| 1163 | TEST_CASE(astlpc_test_buffers_bad_host_proposal), |
| 1164 | TEST_CASE(astlpc_test_buffers_bad_bmc_proposal), |
| 1165 | TEST_CASE(astlpc_test_buffers_bad_bmc_negotiation), |
| 1166 | TEST_CASE(astlpc_test_buffers_overlap_exact), |
| 1167 | TEST_CASE(astlpc_test_buffers_overlap_control), |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 1168 | TEST_CASE(astlpc_test_buffers_bad_host_init), |
| 1169 | TEST_CASE(astlpc_test_negotiate_increased_mtu), |
| 1170 | TEST_CASE(astlpc_test_negotiate_mtu_low_high), |
Andrew Jeffery | c2b833e | 2020-10-28 14:28:37 +1030 | [diff] [blame^] | 1171 | TEST_CASE(astlpc_test_send_large_packet), |
Andrew Jeffery | 91f09ed | 2020-05-22 20:52:26 +0930 | [diff] [blame] | 1172 | }; |
| 1173 | /* clang-format on */ |
| 1174 | |
| 1175 | #ifndef BUILD_ASSERT |
| 1176 | #define BUILD_ASSERT(x) \ |
| 1177 | do { \ |
| 1178 | (void)sizeof(char[0 - (!(x))]); \ |
| 1179 | } while (0) |
| 1180 | #endif |
| 1181 | |
Andrew Jeffery | e756de8 | 2020-05-22 12:30:58 +0930 | [diff] [blame] | 1182 | int main(void) |
| 1183 | { |
Andrew Jeffery | 91f09ed | 2020-05-22 20:52:26 +0930 | [diff] [blame] | 1184 | size_t i; |
| 1185 | |
Andrew Jeffery | e756de8 | 2020-05-22 12:30:58 +0930 | [diff] [blame] | 1186 | mctp_set_log_stdio(MCTP_LOG_DEBUG); |
| 1187 | |
Andrew Jeffery | 91f09ed | 2020-05-22 20:52:26 +0930 | [diff] [blame] | 1188 | BUILD_ASSERT(ARRAY_SIZE(astlpc_tests) < SIZE_MAX); |
| 1189 | for (i = 0; i < ARRAY_SIZE(astlpc_tests); i++) { |
| 1190 | mctp_prlog(MCTP_LOG_DEBUG, "begin: %s", astlpc_tests[i].name); |
| 1191 | astlpc_tests[i].test(); |
| 1192 | mctp_prlog(MCTP_LOG_DEBUG, "end: %s\n", astlpc_tests[i].name); |
| 1193 | } |
Andrew Jeffery | 11b7e92 | 2020-03-10 23:37:09 +1030 | [diff] [blame] | 1194 | |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 1195 | return 0; |
| 1196 | } |