net: mctp: usblib: Complete rx tests

Add rx tests without spanning, covering cases where a packet is shorter
than allowed without spanning, isn't completed within one submission.

Fully cover rx functions except for memory allocation failures and
trivial functions.

Signed-off-by: James Lee <james@codeconstruct.com.au>
Link: https://patch.msgid.link/20261014-dev-mctp-usb-lib-test-v3-4-ee5bc3ea1db1@codeconstruct.com.au
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
James Lee 2026-10-14 12:47:34 +08:00 committed by Jakub Kicinski
parent c0a372f729
commit 40e59c00ae

View File

@ -527,6 +527,66 @@ static void mctp_usblib_test_rx_invalid_dmtf_id(struct kunit *test)
KUNIT_EXPECT_EQ(test, dev->rx_pkts.qlen, 0);
}
static void mctp_usblib_test_rx_nonspanning_tiny(struct kunit *test)
{
struct mctp_usblib_test_dev *dev;
struct mctp_usblib_test_ctx *ctx;
struct mctp_usblib_rx *rx;
size_t len, buflen;
u8 pktbuf[3];
void *buf;
int rc;
ctx = mctp_usblib_test_init(test);
rx = mctp_usblib_test_rx_init(test, false);
dev = ctx->dev;
len = sizeof(pktbuf);
mctp_usblib_test_init_pkt(pktbuf, len, len);
buflen = 0;
rc = mctp_usblib_rx_prepare(dev->ndev, rx, &buf, &buflen, GFP_KERNEL);
KUNIT_ASSERT_EQ(test, rc, 0);
KUNIT_ASSERT_GE(test, buflen, len);
memcpy(buf, pktbuf, len);
rc = mctp_usblib_rx_complete(dev->ndev, rx, len);
KUNIT_EXPECT_EQ(test, rc, -ENOMSG);
KUNIT_EXPECT_NULL(test, rx->skb);
KUNIT_EXPECT_EQ(test, dev->rx_pkts.qlen, 0);
}
static void mctp_usblib_test_rx_nonspanning_partial(struct kunit *test)
{
struct mctp_usblib_test_dev *dev;
struct mctp_usblib_test_ctx *ctx;
struct mctp_usblib_rx *rx;
size_t len, buflen;
u8 pktbuf[20];
void *buf;
int rc;
ctx = mctp_usblib_test_init(test);
rx = mctp_usblib_test_rx_init(test, false);
dev = ctx->dev;
len = sizeof(pktbuf);
mctp_usblib_test_init_pkt(pktbuf, len, len + 1);
buflen = 0;
rc = mctp_usblib_rx_prepare(dev->ndev, rx, &buf, &buflen, GFP_KERNEL);
KUNIT_ASSERT_EQ(test, rc, 0);
KUNIT_ASSERT_GE(test, buflen, len);
memcpy(buf, pktbuf, len);
rc = mctp_usblib_rx_complete(dev->ndev, rx, len);
KUNIT_EXPECT_EQ(test, rc, -EPROTO);
KUNIT_EXPECT_NULL(test, rx->skb);
KUNIT_EXPECT_EQ(test, dev->rx_pkts.qlen, 0);
}
static struct kunit_case mctp_usblib_test_cases[] = {
KUNIT_CASE(mctp_usblib_test_rx_single),
KUNIT_CASE_PARAM(mctp_usblib_test_rx_pkt_span,
@ -534,6 +594,8 @@ static struct kunit_case mctp_usblib_test_cases[] = {
KUNIT_CASE(mctp_usblib_test_rx_header_splits),
KUNIT_CASE(mctp_usblib_test_rx_short_packet),
KUNIT_CASE(mctp_usblib_test_rx_invalid_dmtf_id),
KUNIT_CASE(mctp_usblib_test_rx_nonspanning_tiny),
KUNIT_CASE(mctp_usblib_test_rx_nonspanning_partial),
{}
};