blob: 6de249a6f72457ced7451c01664195872d45e1df [file] [log] [blame]
Andrew Jeffery0247c732020-02-06 11:48:52 +10301/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
2
Andrew Jeffery2cda40f2020-02-28 15:26:20 +10303#ifdef HAVE_CONFIG_H
Andrew Jeffery0247c732020-02-06 11:48:52 +10304#include "config.h"
Andrew Jeffery2cda40f2020-02-28 15:26:20 +10305#endif
6
Andrew Jeffery3a540662020-05-26 19:55:30 +09307#define ASTLPC_VER_CUR 2
Andrew Jefferydf5f6b92020-05-12 21:39:06 +09308#include "astlpc.c"
9
10#ifdef pr_fmt
11#undef pr_fmt
12#define pr_fmt(x) "test: " x
13#endif
14
Andrew Jeffery0247c732020-02-06 11:48:52 +103015#include "libmctp-astlpc.h"
16#include "libmctp-log.h"
Przemyslaw Czarnowskiff25d7e2020-03-26 11:39:37 +010017#include "container_of.h"
Andrew Jeffery0247c732020-02-06 11:48:52 +103018
19#ifdef NDEBUG
20#undef NDEBUG
21#endif
22
Andrew Jeffery0247c732020-02-06 11:48:52 +103023#include <assert.h>
Andrew Jeffery91f09ed2020-05-22 20:52:26 +093024#include <limits.h>
Andrew Jeffery0247c732020-02-06 11:48:52 +103025#include <stdint.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29
Andrew Jeffery91f09ed2020-05-22 20:52:26 +093030#ifndef ARRAY_SIZE
31#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
32#endif
33
Andrew Jeffery0247c732020-02-06 11:48:52 +103034struct mctp_binding_astlpc_mmio {
35 struct mctp_binding_astlpc astlpc;
Andrew Jefferyd5e3cd72020-05-12 22:10:22 +093036 bool bmc;
Andrew Jeffery0247c732020-02-06 11:48:52 +103037
Andrew Jefferyd5e3cd72020-05-12 22:10:22 +093038 uint8_t (*kcs)[2];
Andrew Jeffery0247c732020-02-06 11:48:52 +103039
40 size_t lpc_size;
41 uint8_t *lpc;
42};
43
Andrew Jeffery5a7c2db2020-05-22 20:13:42 +093044struct astlpc_endpoint {
45 struct mctp_binding_astlpc_mmio mmio;
46 struct mctp_binding_astlpc *astlpc;
47 struct mctp *mctp;
48};
49
50struct astlpc_test {
51 struct astlpc_endpoint bmc;
52 struct astlpc_endpoint host;
53 uint8_t kcs[2];
54 uint8_t *lpc_mem;
55
56 void *msg;
57 uint8_t count;
58};
59
60#define binding_to_mmio(b) \
Andrew Jeffery0247c732020-02-06 11:48:52 +103061 container_of(b, struct mctp_binding_astlpc_mmio, astlpc)
62
Andrew Jeffery53ea1472020-05-23 21:06:24 +093063static int mctp_astlpc_mmio_kcs_read(void *data,
64 enum mctp_binding_astlpc_kcs_reg reg,
65 uint8_t *val)
Andrew Jeffery0247c732020-02-06 11:48:52 +103066{
67 struct mctp_binding_astlpc_mmio *mmio = binding_to_mmio(data);
68
Andrew Jefferyd5e3cd72020-05-12 22:10:22 +093069 *val = (*mmio->kcs)[reg];
Andrew Jeffery0247c732020-02-06 11:48:52 +103070
Andrew Jefferyd3c0bf02020-05-28 15:28:40 +093071 mctp_prdebug("%s: 0x%hhx from %s", __func__, *val,
72 reg ? "status" : "data");
Andrew Jeffery0247c732020-02-06 11:48:52 +103073
Andrew Jefferyd5e3cd72020-05-12 22:10:22 +093074 if (reg == MCTP_ASTLPC_KCS_REG_DATA) {
75 uint8_t flag = mmio->bmc ? KCS_STATUS_IBF : KCS_STATUS_OBF;
76 (*mmio->kcs)[MCTP_ASTLPC_KCS_REG_STATUS] &= ~flag;
77 }
Andrew Jeffery0247c732020-02-06 11:48:52 +103078
79 return 0;
80}
81
Andrew Jeffery53ea1472020-05-23 21:06:24 +093082static int mctp_astlpc_mmio_kcs_write(void *data,
83 enum mctp_binding_astlpc_kcs_reg reg,
84 uint8_t val)
Andrew Jeffery0247c732020-02-06 11:48:52 +103085{
86 struct mctp_binding_astlpc_mmio *mmio = binding_to_mmio(data);
Andrew Jefferyd5e3cd72020-05-12 22:10:22 +093087 uint8_t *regp;
Andrew Jeffery0247c732020-02-06 11:48:52 +103088
Andrew Jefferyd5e3cd72020-05-12 22:10:22 +093089 assert(reg == MCTP_ASTLPC_KCS_REG_DATA ||
90 reg == MCTP_ASTLPC_KCS_REG_STATUS);
Andrew Jeffery0247c732020-02-06 11:48:52 +103091
Andrew Jefferyd5e3cd72020-05-12 22:10:22 +093092 if (reg == MCTP_ASTLPC_KCS_REG_DATA) {
93 uint8_t flag = mmio->bmc ? KCS_STATUS_OBF : KCS_STATUS_IBF;
94 (*mmio->kcs)[MCTP_ASTLPC_KCS_REG_STATUS] |= flag;
95 }
96
97 regp = &(*mmio->kcs)[reg];
Andrew Jeffery0247c732020-02-06 11:48:52 +103098 if (reg == MCTP_ASTLPC_KCS_REG_STATUS)
Andrew Jefferyd5e3cd72020-05-12 22:10:22 +093099 *regp = (val & ~0xbU) | (val & *regp & 1);
Andrew Jeffery0247c732020-02-06 11:48:52 +1030100 else
Andrew Jefferyd5e3cd72020-05-12 22:10:22 +0930101 *regp = val;
Andrew Jeffery0247c732020-02-06 11:48:52 +1030102
Andrew Jefferyd3c0bf02020-05-28 15:28:40 +0930103 mctp_prdebug("%s: 0x%hhx to %s", __func__, val,
104 reg ? "status" : "data");
Andrew Jeffery0247c732020-02-06 11:48:52 +1030105
106 return 0;
107}
Andrew Jeffery06b2cd82020-03-17 23:12:27 +1030108int mctp_astlpc_mmio_lpc_read(void *data, void *buf, long offset, size_t len)
Andrew Jeffery0247c732020-02-06 11:48:52 +1030109{
110 struct mctp_binding_astlpc_mmio *mmio = binding_to_mmio(data);
111
Andrew Jeffery1dbf0212020-05-12 13:53:50 +0930112 mctp_prdebug("%s: %zu bytes from 0x%lx", __func__, len, offset);
113
Andrew Jeffery06b2cd82020-03-17 23:12:27 +1030114 assert(offset >= 0L);
Andrew Jeffery0247c732020-02-06 11:48:52 +1030115 assert(offset + len < mmio->lpc_size);
116
117 memcpy(buf, mmio->lpc + offset, len);
118
Andrew Jeffery0247c732020-02-06 11:48:52 +1030119 return 0;
120}
121
Andrew Jeffery55fb90b2020-05-12 13:54:37 +0930122int mctp_astlpc_mmio_lpc_write(void *data, const void *buf, long offset,
123 size_t len)
Andrew Jeffery0247c732020-02-06 11:48:52 +1030124{
125 struct mctp_binding_astlpc_mmio *mmio = binding_to_mmio(data);
126
Andrew Jeffery1dbf0212020-05-12 13:53:50 +0930127 mctp_prdebug("%s: %zu bytes to 0x%lx", __func__, len, offset);
128
Andrew Jeffery06b2cd82020-03-17 23:12:27 +1030129 assert(offset >= 0L);
Andrew Jeffery0247c732020-02-06 11:48:52 +1030130 assert(offset + len < mmio->lpc_size);
131
132 memcpy(mmio->lpc + offset, buf, len);
133
Andrew Jeffery0247c732020-02-06 11:48:52 +1030134 return 0;
135}
136
Andrew Jefferyb93b6112020-06-05 14:13:44 +0930137#define __unused __attribute__((unused))
138
139static void rx_message(uint8_t eid __unused, void *data __unused, void *msg,
140 size_t len)
Andrew Jeffery0247c732020-02-06 11:48:52 +1030141{
Andrew Jeffery5a7c2db2020-05-22 20:13:42 +0930142 struct astlpc_test *test = data;
Andrew Jeffery0247c732020-02-06 11:48:52 +1030143
Andrew Jeffery5a7c2db2020-05-22 20:13:42 +0930144 mctp_prdebug("MCTP message received: msg: %p, len %zd", msg, len);
Andrew Jeffery0247c732020-02-06 11:48:52 +1030145
Andrew Jeffery5a7c2db2020-05-22 20:13:42 +0930146 assert(len > 0);
147 assert(msg);
148 assert(test);
149 assert(test->msg);
150 assert(!memcmp(test->msg, msg, len));
151
152 test->count++;
Andrew Jeffery0247c732020-02-06 11:48:52 +1030153}
154
Andrew Jeffery55fb90b2020-05-12 13:54:37 +0930155static const struct mctp_binding_astlpc_ops astlpc_direct_mmio_ops = {
156 .kcs_read = mctp_astlpc_mmio_kcs_read,
157 .kcs_write = mctp_astlpc_mmio_kcs_write,
158};
159
160static const struct mctp_binding_astlpc_ops astlpc_indirect_mmio_ops = {
Andrew Jeffery0247c732020-02-06 11:48:52 +1030161 .kcs_read = mctp_astlpc_mmio_kcs_read,
162 .kcs_write = mctp_astlpc_mmio_kcs_write,
163 .lpc_read = mctp_astlpc_mmio_lpc_read,
164 .lpc_write = mctp_astlpc_mmio_lpc_write,
165};
166
Andrew Jeffery4e8264b2020-05-23 20:34:33 +0930167static int endpoint_init(struct astlpc_endpoint *ep, mctp_eid_t eid,
168 uint8_t mode, uint8_t (*kcs)[2], void *lpc_mem)
Andrew Jefferyd5e3cd72020-05-12 22:10:22 +0930169{
170 /*
171 * Configure the direction of the KCS interface so we know whether to
172 * set or clear IBF or OBF on writes or reads.
173 */
174 ep->mmio.bmc = (mode == MCTP_BINDING_ASTLPC_MODE_BMC);
175
176 ep->mctp = mctp_init();
177 assert(ep->mctp);
178
Andrew Jefferyd5e3cd72020-05-12 22:10:22 +0930179 /* Inject KCS registers */
180 ep->mmio.kcs = kcs;
181
Andrew Jefferyd5e3cd72020-05-12 22:10:22 +0930182 /* Initialise the binding */
Andrew Jeffery129ef932020-05-22 16:24:19 +0930183 ep->astlpc = mctp_astlpc_init(mode, MCTP_BTU, lpc_mem,
Andrew Jeffery55fb90b2020-05-12 13:54:37 +0930184 &astlpc_direct_mmio_ops, &ep->mmio);
Andrew Jeffery3a540662020-05-26 19:55:30 +0930185 assert(ep->astlpc);
Andrew Jefferyd5e3cd72020-05-12 22:10:22 +0930186
Andrew Jeffery4e8264b2020-05-23 20:34:33 +0930187 return mctp_register_bus(ep->mctp, &ep->astlpc->binding, eid);
Andrew Jefferyd5e3cd72020-05-12 22:10:22 +0930188}
189
190static void endpoint_destroy(struct astlpc_endpoint *ep)
191{
192 mctp_astlpc_destroy(ep->astlpc);
193 mctp_destroy(ep->mctp);
194}
195
Andrew Jefferycb5d55c2020-05-22 13:26:27 +0930196static void network_init(struct astlpc_test *ctx)
197{
Andrew Jeffery4e8264b2020-05-23 20:34:33 +0930198 int rc;
199
Andrew Jeffery55fb90b2020-05-12 13:54:37 +0930200 ctx->lpc_mem = calloc(1, 1 * 1024 * 1024);
Andrew Jefferycb5d55c2020-05-22 13:26:27 +0930201 assert(ctx->lpc_mem);
202
203 /* BMC initialisation */
Andrew Jeffery4e8264b2020-05-23 20:34:33 +0930204 rc = endpoint_init(&ctx->bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC,
205 &ctx->kcs, ctx->lpc_mem);
206 assert(!rc);
Andrew Jeffery3f325072020-05-28 09:19:51 +0930207 assert(ctx->kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_BMC_READY);
Andrew Jefferycb5d55c2020-05-22 13:26:27 +0930208
209 /* Host initialisation */
Andrew Jeffery4e8264b2020-05-23 20:34:33 +0930210 rc = endpoint_init(&ctx->host, 9, MCTP_BINDING_ASTLPC_MODE_HOST,
211 &ctx->kcs, ctx->lpc_mem);
212 assert(!rc);
Andrew Jefferycb5d55c2020-05-22 13:26:27 +0930213
214 /* BMC processes host channel init request, alerts host */
215 mctp_astlpc_poll(ctx->bmc.astlpc);
Andrew Jeffery3f325072020-05-28 09:19:51 +0930216 assert(ctx->kcs[MCTP_ASTLPC_KCS_REG_STATUS] &
217 KCS_STATUS_CHANNEL_ACTIVE);
218 assert(ctx->kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0xff);
Andrew Jefferycb5d55c2020-05-22 13:26:27 +0930219
220 /* Host dequeues channel init result */
221 mctp_astlpc_poll(ctx->host.astlpc);
222}
223
224static void network_destroy(struct astlpc_test *ctx)
225{
226 endpoint_destroy(&ctx->bmc);
227 endpoint_destroy(&ctx->host);
228 free(ctx->lpc_mem);
229}
230
Andrew Jeffery129ef932020-05-22 16:24:19 +0930231static void astlpc_assert_tx_packet(struct astlpc_endpoint *src,
232 const void *expected, size_t len)
233{
234 const size_t tx_body = src->astlpc->layout.tx.offset + 4 + 4;
235 const void *test = ((char *)src->astlpc->lpc_map) + tx_body;
236 assert(!memcmp(test, expected, len));
237}
238
Andrew Jefferye756de82020-05-22 12:30:58 +0930239static void astlpc_test_packetised_message_bmc_to_host(void)
Andrew Jefferyd5e3cd72020-05-12 22:10:22 +0930240{
Andrew Jefferycb5d55c2020-05-22 13:26:27 +0930241 struct astlpc_test ctx = { 0 };
Andrew Jefferyd5e3cd72020-05-12 22:10:22 +0930242 uint8_t msg[2 * MCTP_BTU];
Andrew Jeffery0247c732020-02-06 11:48:52 +1030243 int rc;
244
Andrew Jefferyd5e3cd72020-05-12 22:10:22 +0930245 /* Test harness initialisation */
246
Andrew Jeffery5a7c2db2020-05-22 20:13:42 +0930247 network_init(&ctx);
248
Andrew Jeffery0247c732020-02-06 11:48:52 +1030249 memset(&msg[0], 0x5a, MCTP_BTU);
250 memset(&msg[MCTP_BTU], 0xa5, MCTP_BTU);
251
Andrew Jeffery5a7c2db2020-05-22 20:13:42 +0930252 ctx.msg = &msg[0];
253 ctx.count = 0;
254 mctp_set_rx_all(ctx.host.mctp, rx_message, &ctx);
Andrew Jeffery0247c732020-02-06 11:48:52 +1030255
256 /* BMC sends a message */
Andrew Jefferycb5d55c2020-05-22 13:26:27 +0930257 rc = mctp_message_tx(ctx.bmc.mctp, 9, msg, sizeof(msg));
Andrew Jeffery0247c732020-02-06 11:48:52 +1030258 assert(rc == 0);
Andrew Jefferyd5e3cd72020-05-12 22:10:22 +0930259
Andrew Jeffery129ef932020-05-22 16:24:19 +0930260 /* Host receives the first packet */
Andrew Jefferycb5d55c2020-05-22 13:26:27 +0930261 mctp_astlpc_poll(ctx.host.astlpc);
Andrew Jeffery0247c732020-02-06 11:48:52 +1030262
Andrew Jeffery0247c732020-02-06 11:48:52 +1030263 /* BMC dequeues ownership hand-over and sends the queued packet */
Andrew Jefferycb5d55c2020-05-22 13:26:27 +0930264 rc = mctp_astlpc_poll(ctx.bmc.astlpc);
Andrew Jeffery0247c732020-02-06 11:48:52 +1030265 assert(rc == 0);
266
Andrew Jeffery129ef932020-05-22 16:24:19 +0930267 /* Host receives the next packet */
Andrew Jefferycb5d55c2020-05-22 13:26:27 +0930268 assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF);
269 assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x01);
Andrew Jeffery0247c732020-02-06 11:48:52 +1030270
Andrew Jeffery129ef932020-05-22 16:24:19 +0930271 astlpc_assert_tx_packet(&ctx.bmc, &msg[MCTP_BTU], MCTP_BTU);
Andrew Jeffery0247c732020-02-06 11:48:52 +1030272
Andrew Jeffery5a7c2db2020-05-22 20:13:42 +0930273 /* Host receives final packet */
274 mctp_astlpc_poll(ctx.host.astlpc);
275 assert(ctx.count == 1);
276
Andrew Jefferycb5d55c2020-05-22 13:26:27 +0930277 network_destroy(&ctx);
Andrew Jefferye756de82020-05-22 12:30:58 +0930278}
279
Andrew Jefferyec9a0062020-05-22 21:21:55 +0930280static void astlpc_test_simple_message_host_to_bmc(void)
281{
282 struct astlpc_test ctx = { 0 };
283 uint8_t msg[MCTP_BTU];
284 int rc;
285
286 /* Test harness initialisation */
287
288 network_init(&ctx);
289
290 memset(&msg[0], 0xa5, MCTP_BTU);
291
292 ctx.msg = &msg[0];
293 ctx.count = 0;
294 mctp_set_rx_all(ctx.bmc.mctp, rx_message, &ctx);
295
296 /* Host sends the single-packet message */
297 rc = mctp_message_tx(ctx.host.mctp, 8, msg, sizeof(msg));
298 assert(rc == 0);
299 assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_IBF);
300 assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x01);
301
302 astlpc_assert_tx_packet(&ctx.host, &msg[0], MCTP_BTU);
303
304 /* BMC receives the single-packet message */
305 mctp_astlpc_poll(ctx.bmc.astlpc);
306 assert(ctx.count == 1);
307
308 /* BMC returns Tx area ownership to Host */
309 assert(!(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_IBF));
310 assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x02);
311 assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF);
312
313 /* Host dequeues ownership hand-over and sends the queued packet */
314 rc = mctp_astlpc_poll(ctx.host.astlpc);
315 assert(rc == 0);
316
317 network_destroy(&ctx);
318}
319
Andrew Jeffery8f3eb722020-05-22 20:23:49 +0930320static void astlpc_test_simple_message_bmc_to_host(void)
321{
322 struct astlpc_test ctx = { 0 };
323 uint8_t msg[MCTP_BTU];
324 int rc;
325
326 /* Test harness initialisation */
327
328 network_init(&ctx);
329
330 memset(&msg[0], 0x5a, MCTP_BTU);
331
332 ctx.msg = &msg[0];
333 ctx.count = 0;
334 mctp_set_rx_all(ctx.host.mctp, rx_message, &ctx);
335
336 /* BMC sends the single-packet message */
337 rc = mctp_message_tx(ctx.bmc.mctp, 9, msg, sizeof(msg));
338 assert(rc == 0);
339 assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF);
340 assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x01);
341
342 astlpc_assert_tx_packet(&ctx.bmc, &msg[0], MCTP_BTU);
343
344 /* Host receives the single-packet message */
345 mctp_astlpc_poll(ctx.host.astlpc);
346 assert(ctx.count == 1);
347
348 /* Host returns Rx area ownership to BMC */
349 assert(!(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF));
350 assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x02);
351 assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_IBF);
352
353 /* BMC dequeues ownership hand-over and sends the queued packet */
354 rc = mctp_astlpc_poll(ctx.bmc.astlpc);
355 assert(rc == 0);
356
357 network_destroy(&ctx);
358}
359
Andrew Jefferyf1cdb162020-05-23 21:25:21 +0930360static void astlpc_test_host_before_bmc(void)
361{
362 struct mctp_binding_astlpc_mmio mmio = { 0 };
363 struct mctp_binding_astlpc *astlpc;
364 uint8_t kcs[2] = { 0 };
365 struct mctp *mctp;
366 int rc;
367
368 mctp = mctp_init();
369 assert(mctp);
370
371 /* Inject KCS registers */
372 mmio.kcs = &kcs;
373
374 /* Initialise the binding */
375 astlpc = mctp_astlpc_init(MCTP_BINDING_ASTLPC_MODE_HOST, MCTP_BTU, NULL,
Andrew Jeffery55fb90b2020-05-12 13:54:37 +0930376 &astlpc_direct_mmio_ops, &mmio);
Andrew Jefferyf1cdb162020-05-23 21:25:21 +0930377
378 /* Register the binding to trigger the start-up sequence */
379 rc = mctp_register_bus(mctp, &astlpc->binding, 8);
380
381 /* Start-up should fail as we haven't initialised the BMC */
382 assert(rc < 0);
383
384 mctp_astlpc_destroy(astlpc);
385 mctp_destroy(mctp);
386}
387
Andrew Jeffery4e8264b2020-05-23 20:34:33 +0930388static void astlpc_test_bad_version(void)
389{
390 assert(0 ==
391 mctp_astlpc_negotiate_version(ASTLPC_VER_BAD, ASTLPC_VER_CUR,
392 ASTLPC_VER_MIN, ASTLPC_VER_CUR));
393 assert(0 ==
394 mctp_astlpc_negotiate_version(ASTLPC_VER_MIN, ASTLPC_VER_BAD,
395 ASTLPC_VER_MIN, ASTLPC_VER_CUR));
396 assert(0 ==
397 mctp_astlpc_negotiate_version(ASTLPC_VER_MIN, ASTLPC_VER_CUR,
398 ASTLPC_VER_BAD, ASTLPC_VER_CUR));
399 assert(0 ==
400 mctp_astlpc_negotiate_version(ASTLPC_VER_MIN, ASTLPC_VER_CUR,
401 ASTLPC_VER_MIN, ASTLPC_VER_BAD));
402 assert(0 == mctp_astlpc_negotiate_version(
403 ASTLPC_VER_CUR + 1, ASTLPC_VER_CUR, ASTLPC_VER_MIN,
404 ASTLPC_VER_CUR + 1));
405 assert(0 == mctp_astlpc_negotiate_version(
406 ASTLPC_VER_MIN, ASTLPC_VER_CUR + 1,
407 ASTLPC_VER_CUR + 1, ASTLPC_VER_CUR));
408}
409
410static void astlpc_test_incompatible_versions(void)
411{
412 assert(0 == mctp_astlpc_negotiate_version(
413 ASTLPC_VER_CUR, ASTLPC_VER_CUR, ASTLPC_VER_CUR + 1,
414 ASTLPC_VER_CUR + 1));
415 assert(0 == mctp_astlpc_negotiate_version(
416 ASTLPC_VER_CUR + 1, ASTLPC_VER_CUR + 1,
417 ASTLPC_VER_CUR, ASTLPC_VER_CUR));
418}
419
420static void astlpc_test_choose_bmc_ver_cur(void)
421{
422 assert(2 == mctp_astlpc_negotiate_version(1, 2, 2, 3));
423}
424
425static void astlpc_test_choose_host_ver_cur(void)
426{
427 assert(2 == mctp_astlpc_negotiate_version(2, 3, 1, 2));
428}
429
430static void astlpc_test_version_host_fails_negotiation(void)
Andrew Jefferyf1a21312020-05-22 12:48:21 +0930431{
432 struct astlpc_endpoint bmc, host;
Andrew Jeffery4e8264b2020-05-23 20:34:33 +0930433 struct mctp_lpcmap_hdr *hdr;
Andrew Jefferyf1a21312020-05-22 12:48:21 +0930434 uint8_t kcs[2] = { 0 };
Andrew Jefferyf1a21312020-05-22 12:48:21 +0930435 void *lpc_mem;
Andrew Jeffery4e8264b2020-05-23 20:34:33 +0930436 int rc;
Andrew Jefferyf1a21312020-05-22 12:48:21 +0930437
438 /* Test harness initialisation */
Andrew Jeffery55fb90b2020-05-12 13:54:37 +0930439 lpc_mem = calloc(1, 1 * 1024 * 1024);
Andrew Jefferyf1a21312020-05-22 12:48:21 +0930440 assert(lpc_mem);
441
Andrew Jeffery8f3eb722020-05-22 20:23:49 +0930442 /* BMC initialisation */
Andrew Jeffery4e8264b2020-05-23 20:34:33 +0930443 rc = endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, &kcs,
444 lpc_mem);
445 assert(!rc);
446
447 /* Now the BMC is initialised, break its version announcement */
448 hdr = lpc_mem;
449 hdr->bmc_ver_cur = ASTLPC_VER_BAD;
450
451 /* Host initialisation */
452 rc = endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, &kcs,
453 lpc_mem);
454 assert(rc < 0);
455
456 endpoint_destroy(&bmc);
457 endpoint_destroy(&host);
458 free(lpc_mem);
459}
460
461static void astlpc_test_version_bmc_fails_negotiation(void)
462{
463 struct astlpc_endpoint bmc, host;
464 struct mctp_lpcmap_hdr *hdr;
465 uint8_t kcs[2] = { 0 };
466 void *lpc_mem;
467 int rc;
468
469 /* Test harness initialisation */
470 lpc_mem = calloc(1, 1 * 1024 * 1024);
471 assert(lpc_mem);
472
473 /* BMC initialisation */
474 rc = endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, &kcs,
475 lpc_mem);
476 assert(!rc);
477
478 /* Host initialisation */
479 rc = endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, &kcs,
480 lpc_mem);
481 assert(!rc);
482
483 /* Now the host is initialised, break its version announcement */
484 hdr = lpc_mem;
485 hdr->host_ver_cur = ASTLPC_VER_BAD;
486
487 /* Poll the BMC to detect the broken host version */
488 mctp_astlpc_poll(bmc.astlpc);
489 assert(!(kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_CHANNEL_ACTIVE));
490
491 /* Poll the host so it detects failed negotiation */
492 rc = mctp_astlpc_poll(host.astlpc);
493 assert(rc < 0);
494
495 endpoint_destroy(&bmc);
496 endpoint_destroy(&host);
497 free(lpc_mem);
498}
499
500static void astlpc_test_simple_init(void)
501{
502 struct astlpc_endpoint bmc, host;
503 uint8_t kcs[2] = { 0 };
504 void *lpc_mem;
505 int rc;
506
507 /* Test harness initialisation */
508 lpc_mem = calloc(1, 1 * 1024 * 1024);
509 assert(lpc_mem);
510
511 /* BMC initialisation */
512 rc = endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, &kcs,
513 lpc_mem);
514 assert(!rc);
Andrew Jefferyf1a21312020-05-22 12:48:21 +0930515
516 /* Verify the BMC binding was initialised */
517 assert(kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_BMC_READY);
518
Andrew Jeffery8f3eb722020-05-22 20:23:49 +0930519 /* Host initialisation */
Andrew Jeffery4e8264b2020-05-23 20:34:33 +0930520 rc = endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, &kcs,
521 lpc_mem);
522 assert(!rc);
Andrew Jefferyf1a21312020-05-22 12:48:21 +0930523
524 /* Host sends channel init command */
525 assert(kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_IBF);
526 assert(kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x00);
527
528 /* BMC receives host channel init request */
529 mctp_astlpc_poll(bmc.astlpc);
530
531 /* BMC sends init response */
532 assert(kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF);
533 assert(kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_CHANNEL_ACTIVE);
534 assert(kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0xff);
535
536 /* Host dequeues data */
537 mctp_astlpc_poll(host.astlpc);
538
539 endpoint_destroy(&bmc);
540 endpoint_destroy(&host);
541 free(lpc_mem);
542}
543
Andrew Jeffery55fb90b2020-05-12 13:54:37 +0930544static void astlpc_test_simple_indirect_message_bmc_to_host(void)
545{
546 struct astlpc_test ctx = { 0 };
547 uint8_t kcs[2] = { 0 };
548 uint8_t msg[MCTP_BTU];
549 int rc;
550
551 ctx.lpc_mem = calloc(1, LPC_WIN_SIZE);
552 assert(ctx.lpc_mem);
553
554 /* Test message data */
555 memset(&msg[0], 0x5a, MCTP_BTU);
556
557 /* Manually set up the network so we can inject the indirect ops */
558
559 /* BMC initialisation */
560 ctx.bmc.mmio.bmc = true;
561 ctx.bmc.mctp = mctp_init();
562 assert(ctx.bmc.mctp);
563 ctx.bmc.mmio.kcs = &kcs;
564 ctx.bmc.mmio.lpc = ctx.lpc_mem;
565 ctx.bmc.mmio.lpc_size = LPC_WIN_SIZE;
566 ctx.bmc.astlpc =
567 mctp_astlpc_init(MCTP_BINDING_ASTLPC_MODE_BMC, MCTP_BTU, NULL,
568 &astlpc_indirect_mmio_ops, &ctx.bmc.mmio);
569 mctp_register_bus(ctx.bmc.mctp, &ctx.bmc.astlpc->binding, 8);
570
571 /* Host initialisation */
572 ctx.host.mmio.bmc = false;
573 ctx.host.mctp = mctp_init();
574 assert(ctx.host.mctp);
575 ctx.host.mmio.kcs = &kcs;
576 ctx.host.mmio.lpc = ctx.lpc_mem;
577 ctx.host.mmio.lpc_size = LPC_WIN_SIZE;
578 ctx.host.astlpc =
579 mctp_astlpc_init(MCTP_BINDING_ASTLPC_MODE_HOST, MCTP_BTU, NULL,
580 &astlpc_indirect_mmio_ops, &ctx.host.mmio);
581 mctp_register_bus(ctx.host.mctp, &ctx.host.astlpc->binding, 9);
582
583 /* BMC processes host channel init request, alerts host */
584 mctp_astlpc_poll(ctx.bmc.astlpc);
585
586 /* Host dequeues channel init result */
587 mctp_astlpc_poll(ctx.host.astlpc);
588
589 ctx.msg = &msg[0];
590 ctx.count = 0;
591 mctp_set_rx_all(ctx.host.mctp, rx_message, &ctx);
592
593 /* BMC sends the single-packet message */
594 rc = mctp_message_tx(ctx.bmc.mctp, 9, msg, sizeof(msg));
595 assert(rc == 0);
596
597 /* Host receives the single-packet message */
598 rc = mctp_astlpc_poll(ctx.host.astlpc);
599 assert(rc == 0);
600 assert(ctx.count == 1);
601
602 /* BMC dequeues ownership hand-over and sends the queued packet */
603 rc = mctp_astlpc_poll(ctx.bmc.astlpc);
604 assert(rc == 0);
605
606 /* Can still tear-down the network in the normal fashion */
607 network_destroy(&ctx);
608}
609
Andrew Jefferyd0f5da02020-05-28 09:12:55 +0930610static void astlpc_test_host_tx_bmc_gone(void)
611{
612 struct astlpc_test ctx = { 0 };
613 uint8_t unwritten[MCTP_BTU];
614 uint8_t msg[MCTP_BTU];
615 int rc;
616
617 /* Test harness initialisation */
618
619 network_init(&ctx);
620
621 memset(&msg[0], 0x5a, sizeof(msg));
622 memset(&unwritten[0], 0, sizeof(unwritten));
623
624 ctx.msg = &msg[0];
625 ctx.count = 0;
626
627 /* Clear bmc-ready */
628 endpoint_destroy(&ctx.bmc);
629
630 /* Host detects that the BMC is disabled */
631 mctp_astlpc_poll(ctx.host.astlpc);
632
633 /* Host attempts to send the single-packet message, but is prevented */
634 rc = mctp_message_tx(ctx.host.mctp, 8, msg, sizeof(msg));
635 assert(rc == 0);
636 assert(!(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF));
637 astlpc_assert_tx_packet(&ctx.host, &unwritten[0], MCTP_BTU);
638
639 /* BMC comes back */
Andrew Jeffery4e8264b2020-05-23 20:34:33 +0930640 rc = endpoint_init(&ctx.bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, &ctx.kcs,
641 ctx.lpc_mem);
642 assert(!rc);
Andrew Jefferyd0f5da02020-05-28 09:12:55 +0930643 mctp_set_rx_all(ctx.bmc.mctp, rx_message, &ctx);
644
645 /* Host triggers channel init */
646 mctp_astlpc_poll(ctx.host.astlpc);
647
648 /* BMC handles channel init */
649 mctp_astlpc_poll(ctx.bmc.astlpc);
650
651 /* Host completes channel init, flushing the Tx queue */
652 mctp_astlpc_poll(ctx.host.astlpc);
653
654 /* BMC receives the single-packet message */
655 mctp_astlpc_poll(ctx.bmc.astlpc);
656 assert(ctx.count == 1);
657
658 network_destroy(&ctx);
659}
660
Andrew Jefferyf3d94dc2020-05-28 10:50:18 +0930661static void astlpc_test_poll_not_ready(void)
662{
663 struct astlpc_endpoint bmc;
664 uint8_t kcs[2] = { 0 };
665 void *lpc_mem;
666 int rc;
667
668 /* Test harness initialisation */
669 lpc_mem = calloc(1, 1 * 1024 * 1024);
670 assert(lpc_mem);
671
672 /* BMC initialisation */
Andrew Jeffery4e8264b2020-05-23 20:34:33 +0930673 rc = endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, &kcs,
674 lpc_mem);
675 assert(!rc);
Andrew Jefferyf3d94dc2020-05-28 10:50:18 +0930676
677 /* Check for a command despite none present */
678 rc = mctp_astlpc_poll(bmc.astlpc);
679
680 /* Make sure it doesn't fail */
681 assert(rc == 0);
682
683 endpoint_destroy(&bmc);
684 free(lpc_mem);
685}
686
Andrew Jeffery67655e82020-05-28 10:51:27 +0930687static void astlpc_test_undefined_command(void)
688{
689 struct astlpc_endpoint bmc;
690 uint8_t kcs[2] = { 0 };
691 void *lpc_mem;
692 int rc;
693
694 /* Test harness initialisation */
695 lpc_mem = calloc(1, 1 * 1024 * 1024);
696 assert(lpc_mem);
697
698 /* BMC initialisation */
Andrew Jeffery4e8264b2020-05-23 20:34:33 +0930699 rc = endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, &kcs,
700 lpc_mem);
701 assert(!rc);
Andrew Jeffery67655e82020-05-28 10:51:27 +0930702
703 /* 0x5a isn't legal in v1 or v2 */
704 kcs[MCTP_ASTLPC_KCS_REG_DATA] = 0x5a;
705 kcs[MCTP_ASTLPC_KCS_REG_STATUS] |= KCS_STATUS_IBF;
706
707 /* Check for a command despite none present */
708 rc = mctp_astlpc_poll(bmc.astlpc);
709
710 /* Make sure it doesn't fail, bad command should be discarded */
711 assert(rc == 0);
712
713 endpoint_destroy(&bmc);
714 free(lpc_mem);
715}
716
Andrew Jeffery3a540662020-05-26 19:55:30 +0930717#define BUFFER_MIN ASTLPC_PACKET_SIZE(MCTP_PACKET_SIZE(MCTP_BTU))
718
719static void astlpc_test_buffers_rx_offset_overflow(void)
720{
721 struct mctp_astlpc_layout l = {
722 .rx = { UINT32_MAX, BUFFER_MIN },
723 .tx = { control_size, BUFFER_MIN },
724 };
725
726 assert(!mctp_astlpc_layout_validate(&l));
727}
728
729static void astlpc_test_buffers_tx_offset_overflow(void)
730{
731 struct mctp_astlpc_layout l = {
732 .rx = { control_size, BUFFER_MIN },
733 .tx = { UINT32_MAX, BUFFER_MIN },
734 };
735
736 assert(!mctp_astlpc_layout_validate(&l));
737}
738
739static void astlpc_test_buffers_rx_size_overflow(void)
740{
741 struct mctp_astlpc_layout l = {
742 .rx = { control_size + BUFFER_MIN, UINT32_MAX },
743 .tx = { control_size, BUFFER_MIN },
744 };
745
746 assert(!mctp_astlpc_layout_validate(&l));
747}
748
749static void astlpc_test_buffers_tx_size_overflow(void)
750{
751 struct mctp_astlpc_layout l = {
752 .rx = { control_size, BUFFER_MIN },
753 .tx = { control_size + BUFFER_MIN, UINT32_MAX },
754 };
755
756 assert(!mctp_astlpc_layout_validate(&l));
757}
758
759static void astlpc_test_buffers_rx_window_violation(void)
760{
761 struct mctp_astlpc_layout l = {
762 .rx = { LPC_WIN_SIZE - BUFFER_MIN + 1, BUFFER_MIN },
763 .tx = { control_size, BUFFER_MIN },
764 };
765
766 assert(!mctp_astlpc_layout_validate(&l));
767}
768
769static void astlpc_test_buffers_tx_window_violation(void)
770{
771 struct mctp_astlpc_layout l = {
772 .rx = { control_size, BUFFER_MIN },
773 .tx = { LPC_WIN_SIZE - BUFFER_MIN + 1, BUFFER_MIN },
774 };
775
776 assert(!mctp_astlpc_layout_validate(&l));
777}
778
779static void astlpc_test_buffers_rx_size_fails_btu(void)
780{
781 struct mctp_astlpc_layout l = {
782 .rx = { control_size, BUFFER_MIN - 1 },
783 .tx = { control_size + BUFFER_MIN, BUFFER_MIN },
784 };
785
786 assert(!mctp_astlpc_layout_validate(&l));
787}
788
789static void astlpc_test_buffers_tx_size_fails_btu(void)
790{
791 struct mctp_astlpc_layout l = {
792 .rx = { control_size, BUFFER_MIN },
793 .tx = { control_size + BUFFER_MIN, BUFFER_MIN - 1 },
794 };
795
796 assert(!mctp_astlpc_layout_validate(&l));
797}
798
799static void astlpc_test_buffers_overlap_rx_low(void)
800{
801 struct mctp_astlpc_layout l = {
802 .rx = { control_size, 2 * BUFFER_MIN },
803 .tx = { control_size + BUFFER_MIN, 2 * BUFFER_MIN },
804 };
805
806 assert(!mctp_astlpc_layout_validate(&l));
807}
808
809static void astlpc_test_buffers_overlap_tx_low(void)
810{
811 struct mctp_astlpc_layout l = {
812 .rx = { control_size + BUFFER_MIN, 2 * BUFFER_MIN },
813 .tx = { control_size, 2 * BUFFER_MIN },
814 };
815
816 assert(!mctp_astlpc_layout_validate(&l));
817}
818
819static void astlpc_test_buffers_overlap_exact(void)
820{
821 struct mctp_astlpc_layout l = {
822 .rx = { control_size, 2 * BUFFER_MIN },
823 .tx = { control_size, 2 * BUFFER_MIN },
824 };
825
826 assert(!mctp_astlpc_layout_validate(&l));
827}
828
829static void astlpc_test_buffers_overlap_control(void)
830{
831 struct mctp_astlpc_layout l = {
832 .rx = { 0, BUFFER_MIN },
833 .tx = { control_size + BUFFER_MIN, BUFFER_MIN },
834 };
835
836 assert(!mctp_astlpc_layout_validate(&l));
837}
838
839static void astlpc_test_buffers_bad_host_proposal(void)
840{
841 struct astlpc_endpoint bmc, host;
842 struct mctp_lpcmap_hdr *hdr;
843 uint8_t kcs[2] = { 0 };
844 void *lpc_mem;
845
846 /* Test harness initialisation */
847 lpc_mem = calloc(1, 1 * 1024 * 1024);
848 assert(lpc_mem);
849
850 /* BMC initialisation */
851 endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, &kcs, lpc_mem);
852
853 /* Host initialisation */
854 endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, &kcs, lpc_mem);
855
856 /*
857 * Now that the host has initialised the control area, break
858 * something before polling the BMC
859 */
860 hdr = lpc_mem;
861 hdr->layout.rx_size = 0;
862
863 mctp_astlpc_poll(bmc.astlpc);
864
865 /* Make sure the BMC has not set the channel to active */
866 assert(!(kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_CHANNEL_ACTIVE));
867
868 endpoint_destroy(&host);
869 endpoint_destroy(&bmc);
870 free(lpc_mem);
871}
872
873static void astlpc_test_buffers_bad_bmc_proposal(void)
874{
875 struct astlpc_endpoint bmc, host;
876 struct mctp_lpcmap_hdr *hdr;
877 uint8_t kcs[2] = { 0 };
878 void *lpc_mem;
879 int rc;
880
881 /* Test harness initialisation */
882 lpc_mem = calloc(1, 1 * 1024 * 1024);
883 assert(lpc_mem);
884
885 /* BMC initialisation */
886 endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, &kcs, lpc_mem);
887
888 /*
889 * Now that the BMC has initialised the control area, break something
890 * before initialising the host
891 */
892 hdr = lpc_mem;
893 hdr->layout.rx_size = 0;
894
895 /* Host initialisation: Fails due to bad layout */
896 rc = endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, &kcs,
897 lpc_mem);
898 assert(rc < 0);
899
900 endpoint_destroy(&host);
901 endpoint_destroy(&bmc);
902 free(lpc_mem);
903}
904
905static void astlpc_test_buffers_bad_bmc_negotiation(void)
906{
907 struct astlpc_endpoint bmc, host;
908 struct mctp_lpcmap_hdr *hdr;
909 uint8_t kcs[2] = { 0 };
910 void *lpc_mem;
911 int rc;
912
913 /* Test harness initialisation */
914 lpc_mem = calloc(1, 1 * 1024 * 1024);
915 assert(lpc_mem);
916
917 /* BMC initialisation */
918 endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, &kcs, lpc_mem);
919
920 /* Host initialisation */
921 endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, &kcs, lpc_mem);
922
923 mctp_astlpc_poll(bmc.astlpc);
924
925 /*
926 * Now that the BMC has initialised the control area, break something
927 * before polling the host
928 */
929 hdr = lpc_mem;
930 hdr->layout.rx_size = 0;
931
932 rc = mctp_astlpc_poll(host.astlpc);
933 assert(rc < 0);
934
935 endpoint_destroy(&host);
936 endpoint_destroy(&bmc);
937 free(lpc_mem);
938}
939
Andrew Jeffery91f09ed2020-05-22 20:52:26 +0930940/* clang-format off */
941#define TEST_CASE(test) { #test, test }
942static const struct {
943 const char *name;
944 void (*test)(void);
945} astlpc_tests[] = {
946 TEST_CASE(astlpc_test_simple_init),
Andrew Jeffery4e8264b2020-05-23 20:34:33 +0930947 TEST_CASE(astlpc_test_bad_version),
948 TEST_CASE(astlpc_test_incompatible_versions),
949 TEST_CASE(astlpc_test_choose_bmc_ver_cur),
950 TEST_CASE(astlpc_test_choose_host_ver_cur),
951 TEST_CASE(astlpc_test_version_host_fails_negotiation),
952 TEST_CASE(astlpc_test_version_bmc_fails_negotiation),
Andrew Jefferyf1cdb162020-05-23 21:25:21 +0930953 TEST_CASE(astlpc_test_host_before_bmc),
Andrew Jeffery91f09ed2020-05-22 20:52:26 +0930954 TEST_CASE(astlpc_test_simple_message_bmc_to_host),
Andrew Jefferyec9a0062020-05-22 21:21:55 +0930955 TEST_CASE(astlpc_test_simple_message_host_to_bmc),
Andrew Jeffery91f09ed2020-05-22 20:52:26 +0930956 TEST_CASE(astlpc_test_packetised_message_bmc_to_host),
Andrew Jefferyd0f5da02020-05-28 09:12:55 +0930957 TEST_CASE(astlpc_test_simple_indirect_message_bmc_to_host),
958 TEST_CASE(astlpc_test_host_tx_bmc_gone),
Andrew Jefferyf3d94dc2020-05-28 10:50:18 +0930959 TEST_CASE(astlpc_test_poll_not_ready),
Andrew Jeffery67655e82020-05-28 10:51:27 +0930960 TEST_CASE(astlpc_test_undefined_command),
Andrew Jeffery3a540662020-05-26 19:55:30 +0930961 TEST_CASE(astlpc_test_buffers_rx_offset_overflow),
962 TEST_CASE(astlpc_test_buffers_tx_offset_overflow),
963 TEST_CASE(astlpc_test_buffers_rx_size_overflow),
964 TEST_CASE(astlpc_test_buffers_tx_size_overflow),
965 TEST_CASE(astlpc_test_buffers_rx_window_violation),
966 TEST_CASE(astlpc_test_buffers_tx_window_violation),
967 TEST_CASE(astlpc_test_buffers_rx_size_fails_btu),
968 TEST_CASE(astlpc_test_buffers_tx_size_fails_btu),
969 TEST_CASE(astlpc_test_buffers_overlap_rx_low),
970 TEST_CASE(astlpc_test_buffers_overlap_tx_low),
971 TEST_CASE(astlpc_test_buffers_bad_host_proposal),
972 TEST_CASE(astlpc_test_buffers_bad_bmc_proposal),
973 TEST_CASE(astlpc_test_buffers_bad_bmc_negotiation),
974 TEST_CASE(astlpc_test_buffers_overlap_exact),
975 TEST_CASE(astlpc_test_buffers_overlap_control),
Andrew Jeffery91f09ed2020-05-22 20:52:26 +0930976};
977/* clang-format on */
978
979#ifndef BUILD_ASSERT
980#define BUILD_ASSERT(x) \
981 do { \
982 (void)sizeof(char[0 - (!(x))]); \
983 } while (0)
984#endif
985
Andrew Jefferye756de82020-05-22 12:30:58 +0930986int main(void)
987{
Andrew Jeffery91f09ed2020-05-22 20:52:26 +0930988 size_t i;
989
Andrew Jefferye756de82020-05-22 12:30:58 +0930990 mctp_set_log_stdio(MCTP_LOG_DEBUG);
991
Andrew Jeffery91f09ed2020-05-22 20:52:26 +0930992 BUILD_ASSERT(ARRAY_SIZE(astlpc_tests) < SIZE_MAX);
993 for (i = 0; i < ARRAY_SIZE(astlpc_tests); i++) {
994 mctp_prlog(MCTP_LOG_DEBUG, "begin: %s", astlpc_tests[i].name);
995 astlpc_tests[i].test();
996 mctp_prlog(MCTP_LOG_DEBUG, "end: %s\n", astlpc_tests[i].name);
997 }
Andrew Jeffery11b7e922020-03-10 23:37:09 +1030998
Andrew Jeffery0247c732020-02-06 11:48:52 +1030999 return 0;
1000}