This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 6ad0a54d47e5bb3c3b59744c5615262a504754f1 Author: huojianchao <[email protected]> AuthorDate: Mon Nov 30 11:24:10 2026 +0800 testing/mm/iob: check the results of the pack and tailroom tests Test 6 (pack, contig, reserve) and Test 9 (tailroom) printed the values they were meant to test but checked none of them. Check the length, offset and data after iob_pack(), iob_contig() and iob_reserve(), and check iob_tailroom() before and after the copy-in. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: huojianchao <[email protected]> --- testing/mm/iob/iob_main.c | 73 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 5 deletions(-) diff --git a/testing/mm/iob/iob_main.c b/testing/mm/iob/iob_main.c index 2a730ce42..d125df6a4 100644 --- a/testing/mm/iob/iob_main.c +++ b/testing/mm/iob/iob_main.c @@ -889,6 +889,7 @@ static int test_iob_pack_contig(void) { FAR struct iob_s *iob; uint8_t data[100]; + uint8_t verify[100]; int i; int ret; @@ -910,7 +911,13 @@ static int test_iob_pack_contig(void) data[i] = i & 0xff; } - iob_copyin(iob, data, sizeof(data), 0, false); + ret = iob_copyin(iob, data, sizeof(data), 0, false); + if (ret != sizeof(data)) + { + printf("ERROR: iob_copyin failed, ret=%d\n", ret); + iob_free_chain(iob); + return -1; + } printf("Original io_pktlen=%u, io_offset=%u, io_len=%u\n", iob->io_pktlen, iob->io_offset, iob->io_len); @@ -928,6 +935,18 @@ static int test_iob_pack_contig(void) printf("After pack: io_pktlen=%u, io_offset=%u, io_len=%u\n", iob->io_pktlen, iob->io_offset, iob->io_len); + /* Packing moves the data to the start of the buffers and keeps it */ + + memset(verify, 0, sizeof(verify)); + if (iob->io_pktlen != sizeof(data) || iob->io_offset != 0 || + iob_copyout(verify, iob, sizeof(verify), 0) != sizeof(verify) || + memcmp(verify, data, sizeof(data)) != 0) + { + printf("ERROR: Wrong length, offset or data after iob_pack\n"); + iob_free_chain(iob); + return -1; + } + /* Test contig - ensure contiguous space */ printf("Testing contig (50 bytes)...\n"); @@ -939,13 +958,36 @@ static int test_iob_pack_contig(void) return -1; } + /* The first 50 bytes are now in the head IOB, with the data unchanged */ + + memset(verify, 0, sizeof(verify)); + if (iob->io_len < 50 || iob->io_pktlen != sizeof(data) || + iob_copyout(verify, iob, sizeof(verify), 0) != sizeof(verify) || + memcmp(verify, data, sizeof(data)) != 0) + { + printf("ERROR: Wrong length or data after iob_contig\n"); + iob_free_chain(iob); + return -1; + } + printf("Contig success\n"); - /* Test reserve */ + /* Test reserve: the headroom replaces the first 10 bytes of data */ printf("Testing reserve (10 bytes headroom)...\n"); iob_reserve(iob, 10); - printf("After reserve: io_offset=%u\n", iob->io_offset); + printf("After reserve: io_offset=%u, io_pktlen=%u\n", + iob->io_offset, iob->io_pktlen); + + memset(verify, 0, sizeof(verify)); + if (iob->io_offset != 10 || iob->io_pktlen != sizeof(data) - 10 || + iob_copyout(verify, iob, sizeof(verify), 0) != sizeof(data) - 10 || + memcmp(verify, &data[10], sizeof(data) - 10) != 0) + { + printf("ERROR: Wrong offset, length or data after iob_reserve\n"); + iob_free_chain(iob); + return -1; + } /* Clean up */ @@ -1336,10 +1378,17 @@ static int test_iob_tailroom(void) return -1; } - /* Check initial tailroom */ + /* Check initial tailroom: all of the buffer after io_offset */ tailroom = iob_tailroom(iob); printf("Initial tailroom: %u bytes\n", tailroom); + if (tailroom != IOB_BUFSIZE(iob) - iob->io_offset) + { + printf("ERROR: Initial tailroom %u, expected %u\n", + tailroom, IOB_BUFSIZE(iob) - iob->io_offset); + iob_free_chain(iob); + return -1; + } /* Add some data */ @@ -1348,7 +1397,12 @@ static int test_iob_tailroom(void) data[i] = i & 0xff; } - iob_copyin(iob, data, sizeof(data), 0, false); + if (iob_copyin(iob, data, sizeof(data), 0, false) != sizeof(data)) + { + printf("ERROR: iob_copyin failed\n"); + iob_free_chain(iob); + return -1; + } /* Check tailroom after adding data */ @@ -1356,6 +1410,15 @@ static int test_iob_tailroom(void) printf("Tailroom after adding %zu bytes: %u bytes\n", sizeof(data), tailroom); + if (IOB_BUFSIZE(iob) >= sizeof(data) + iob->io_offset && + tailroom != IOB_BUFSIZE(iob) - iob->io_offset - sizeof(data)) + { + printf("ERROR: Tailroom %u, expected %zu\n", tailroom, + IOB_BUFSIZE(iob) - iob->io_offset - sizeof(data)); + iob_free_chain(iob); + return -1; + } + /* Clean up */ iob_free_chain(iob);
