diff --git a/core.c b/core.c index 02d86cd5..0f7fb2fd 100644 --- a/core.c +++ b/core.c @@ -16,6 +16,7 @@ #include "libmctp-alloc.h" #include "libmctp-log.h" #include "libmctp-cmds.h" +#include "range.h" /* Internal data structures */ @@ -214,7 +215,7 @@ static int mctp_msg_ctx_add_pkt(struct mctp_msg_ctx *ctx, /* @todo: finer-grained allocation */ if (!ctx->buf_alloc_size) { - new_alloc_size = 4096; + new_alloc_size = MAX(len, 4096UL); } else { new_alloc_size = ctx->buf_alloc_size * 2; } diff --git a/tests/test_astlpc.c b/tests/test_astlpc.c index 4baafb95..693ce60d 100644 --- a/tests/test_astlpc.c +++ b/tests/test_astlpc.c @@ -26,6 +26,7 @@ #include #include #include +#include #ifndef ARRAY_SIZE #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) @@ -1070,6 +1071,64 @@ static void astlpc_test_negotiate_mtu_low_high(void) free(lpc_mem); } +static void astlpc_test_send_large_packet(void) +{ + struct astlpc_endpoint *bmc, *host; + struct astlpc_test ctx; + uint8_t kcs[2] = { 0 }; + void *lpc_mem; + int rc; + + host = &ctx.host; + bmc = &ctx.bmc; + + /* Test harness initialisation */ + lpc_mem = calloc(1, 1 * 1024 * 1024); + assert(lpc_mem); + + /* BMC initialisation */ + rc = endpoint_init(bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, 8192, &kcs, + lpc_mem); + assert(!rc); + + /* Host initialisation */ + rc = endpoint_init(host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, 8192, &kcs, + lpc_mem); + assert(!rc); + + ctx.count = 0; + mctp_set_rx_all(bmc->mctp, rx_message, &ctx); + + rc = mctp_astlpc_poll(bmc->astlpc); + assert(rc == 0); + + rc = mctp_astlpc_poll(host->astlpc); + assert(rc == 0); + + ctx.msg = malloc(2 * MCTP_BODY_SIZE(8192)); + assert(ctx.msg); + + memset(ctx.msg, 0x5a, 2 * MCTP_BODY_SIZE(8192)); + + rc = mctp_message_tx(host->mctp, 8, ctx.msg, 2 * MCTP_BODY_SIZE(8192)); + assert(rc == 0); + rc = mctp_astlpc_poll(bmc->astlpc); + assert(rc == 0); + rc = mctp_astlpc_poll(host->astlpc); + assert(rc == 0); + rc = mctp_astlpc_poll(bmc->astlpc); + assert(rc == 0); + rc = mctp_astlpc_poll(host->astlpc); + assert(rc == 0); + + assert(ctx.count == 1); + + free(ctx.msg); + endpoint_destroy(host); + endpoint_destroy(bmc); + free(lpc_mem); +} + /* clang-format off */ #define TEST_CASE(test) { #test, test } static const struct { @@ -1109,6 +1168,7 @@ static const struct { TEST_CASE(astlpc_test_buffers_bad_host_init), TEST_CASE(astlpc_test_negotiate_increased_mtu), TEST_CASE(astlpc_test_negotiate_mtu_low_high), + TEST_CASE(astlpc_test_send_large_packet), }; /* clang-format on */