Skip to content

testing/mm: more iob test cases and GCC-only kasantest flags - #4136

Merged
xiaoxiang781216 merged 5 commits into
apache:masterfrom
huojianchaoyy:ap-mm-iob-tests-v3
Nov 27, 2026
Merged

xiaoxiang781216 merged 5 commits into
apache:masterfrom
huojianchaoyy:ap-mm-iob-tests-v3

Conversation

@huojianchaoyy

Copy link
Copy Markdown

Note: Please adhere to Contributing Guidelines.

Summary

IOB test cases and a kasantest build fix from Xiaomi Vela.

  • testing/mm/iob: add iob test for various iob api: besides the throttled/unthrottled copy test, cases for allocation and free, copy in and out, queue operations, chains, clone, pack and contig, packet length update, queue concatenation, tailroom, and the chain-end flag that a queue keeps in the low bits of io_flink.
  • tesitng/mm/iob: fix compile break: iob_add_queue() and iob_concat_queue() cannot fail (the queue allocates nothing, both return 0), so the test no longer checks their return value; the error paths free the queue they filled.
  • testing/mm/iob: add regression test for extended tail chain: a chain extended with iob_copyin() after it was enqueued, then another chain enqueued behind it; covers 69c67a58493.
  • testing/mm/kasantest: guard GCC-only warning flags: -Wno-use-after-free and -Wno-stringop-overflow are passed only with a GCC toolchain, clang warns about these unknown -Wno- options. The other half of the original change, printing tv_sec as intmax_t, is in master already (f9f59bd); the -fno-builtin of master stays.

One follow-up commit, right after the commit it fixes: testing/mm/iob: fix the nxstyle and codespell errors, one-line if statements and a comment that codespell reads as a misspelling.

Impact

  • Test code only: testing/mm/iob and the build flags of testing/mm/kasantest.
  • "Test 10: IOB Pointer Low-Bit Flags" builds four chains of 3, 2, 3 and 1 IOBs, so the iob test needs CONFIG_IOB_NBUFFERS >= 9. With fewer IOBs (sim:nsh has 8) that case fails to allocate its last chain and the test stops there. sim:citest has 128.
  • GCC builds of kasantest keep the same flags.

Testing

Host: Ubuntu 22.04 x86_64, GCC 13.4.0 (sim), CMake 3.23 + Ninja 1.10. Base: nuttx-apps master 9cd18a2, nuttx master f284e6d7a75.

./tools/checkpatch.sh -c -u -m -g HEAD~5..HEAD passes.

Every commit builds without warnings (CMake, incremental) for sim:nsh with MM_IOB, TESTING_IOB, IOB_NBUFFERS=64, MM_KASAN and TESTING_KASAN; the head also builds with Make. kasantest.c is compiled with -fno-builtin -Wno-error -Wno-array-bounds -Wno-unused-value -Wno-unused-variable -Wno-free-nonheap-object -O0 -Wno-use-after-free -Wno-stringop-overflow, the flags of master.

sim:nsh as above, iob:

Test 1 PASSED
...
Test 10 PASSED
Original IOB Test PASSED
=== Test 12: IOB Queue Extend Enqueued Tail Chain ===
Test 12 PASSED
==================================================
ALL IOB TESTS PASSED!
==================================================

With the 8 IOBs of sim:nsh the run stops at Test 10 (ERROR: Failed to allocate first IOB in chain), see Impact.

Not tested: a clang build (no clang toolchain on this host), real hardware.

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

@huojianchaoyy please fix the conflict

Donny9 and others added 5 commits November 27, 2026 11:45
So far the test only copied data in and out of IOBs from a throttled
and an unthrottled thread.  Add test cases for the rest of the IOB API:
allocation and free, copy in and out, queue operations, chains, clone,
pack and contig, packet length update, queue concatenation, tailroom,
and the chain-end flag that a queue keeps in the low bits of io_flink.

Assisted-by: Kiro:claude-opus-5-5
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
Put the statement of the one-line if blocks that free the IOBs after a
failed allocation on its own line in braces ("Statement on same line as
'if'"), and name the function in the comment that codespell reads as a
misspelling of "copying".

Assisted-by: Kiro:claude-opus-5-5
Signed-off-by: huojianchao <huojianchao@xiaomi.com>
iob_add_queue() and iob_concat_queue() cannot fail: the queue links the
IOBs through the low bits of io_flink and allocates nothing, and both
return 0.  Drop the checks of their return value, and free the queue on
the error paths that return after it was filled.

Assisted-by: Kiro:claude-opus-5-5
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
Enqueue a chain, extend it past one IOB via iob_copyin(), then
enqueue another chain and verify neither is truncated.

Assisted-by: Kiro:claude-opus-5-5
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
-Wuse-after-free and -Wstringop-overflow exist only in GCC, so clang
warns about the -Wno- forms.  Apply them only for GCC toolchains;
-Wno-unknown-warning-option is no fix either, as GCC rejects that flag.

The other part of the original change, printing tv_sec as intmax_t, is
upstream already as f9f59bd.

Assisted-by: Kiro:claude-opus-5-5
Signed-off-by: hujun5 <hujun5@xiaomi.com>
@xiaoxiang781216
xiaoxiang781216 merged commit bae17b3 into apache:master Nov 27, 2026
41 checks passed
@cederom

cederom commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Thanks for the extra IOB coverage and the regression test for apache/nuttx 69c67a584. I checked everything against current nuttx master. Some changes are needed before merge.

testing/mm/kasantest: guard GCC-only warning flags

CONFIG_ARCH_TOOLCHAIN_GCC doesn't mean "the compiler is GCC" on all arches. Only arm, arm64, avr, sim, tricore and xtensa select it. RISCV_TOOLCHAIN_GNU_RV64, RISCV_TOOLCHAIN_GNU_RV32 and RISCV_TOOLCHAIN_GNU_RV64ILP32 only select ARCH_TOOLCHAIN_GNU. x86_64, mips, sparc and the others select no toolchain symbol at all. So on RISC-V + GCC this change silently drops -Wno-use-after-free -Wno-stringop-overflow, and the warnings the flags were added for come back. (They're not fatal because of -Wno-error, so CI won't notice. The in-tree kasantest configs are only qemu-armv8a and qemu-armv7a.)

Excluding the clang-based toolchains is safer than requiring GCC:

ifeq ($(CONFIG_ARCH_TOOLCHAIN_CLANG)$(CONFIG_ARCH_TOOLCHAIN_ARMCLANG),)
CFLAGS += -Wno-use-after-free -Wno-stringop-overflow
endif
if(NOT CONFIG_ARCH_TOOLCHAIN_CLANG AND NOT CONFIG_ARCH_TOOLCHAIN_ARMCLANG)
  list(APPEND CFLAGS -Wno-use-after-free -Wno-stringop-overflow)
endif()

(Making the RISC-V GNU choices also select ARCH_TOOLCHAIN_GCC in nuttx would be good too, but that's a separate kernel PR.)

Wording nits, checked with gcc 13 and clang 18:

  • clang doesn't reject -Wno-use-after-free / -Wno-stringop-overflow. It warns (-Wunknown-warning-option) and compiles. Please say "warns about" in both comments.
  • The commit message says GCC "rejects" -Wno-unknown-warning-option. It doesn't. GCC accepts unknown -Wno-* options silently and only prints unrecognized command-line option ... may have been intended to silence earlier diagnostics when some other diagnostic is emitted. kasantest always emits diagnostics, so the conclusion stands, but the reason given is wrong. The in-file comment ("warns about it in turn") is closer to right.

testing/mm/iob

Commit structure. bfd77e58 ("tesitng/mm/iob: fix compile break" — typo) and a689c008 (nxstyle/codespell) are fixups of f23d8c24. As things stand, f23d8c24 doesn't build on its own, which breaks bisect. Please squash them into f23d8c24. Also, the kasantest commit has nothing to do with IOB. A separate PR would let it land on its own.

Test 10 makes the suite fail on the default config. test_iob_pointer_flags() needs 9 IOBs (via iob_tryalloc()), and as the description says, sim:nsh has 8. Because main() stops at the first failure, Test 11 and Test 12, the new regression test, never run there either. Please check iob_navail(false) up front and skip the test with a message (not a failure) when there aren't enough buffers. Moving Test 12 ahead of Tests 10/11 would help too.

Test 12 doesn't detect the bug the way its comment says. I traced the pre-69c67a584 iob_add_queue(): IOB_FLAG_SET(qh_tail, chain2, IOB_CHAIN_END) overwrites chain1's head io_flink and orphans its second IOB. Then:

  • iob_get_queue_entry_count() still returns 2 (head(END) -> chain2(END)).
  • iob_get_queue_size() adds up the chain heads' io_pktlen, and chain1's head still holds 5 + biglen, so the size check passes too.

The only check that catches the bug is count_chain_iobs(removed) < 2 after dequeue. Please fix the comment ("Both helpers ... so a corrupted boundary shows up here" isn't true), and consider stronger checks:

  • record iob_navail(false) at the start and compare at the end (the orphaned IOB is a leak);
  • iob_copyout() the dequeued chain1 and check that the returned length is chain1_pktlen and the data is "hello" followed by 0xa5.

69c67a584 fixed iob_concat_queue() as well, but that path isn't tested. It would be worth adding the same extend-then-concat sequence.

DEBUGASSERT used as a test check. Tests 1, 3, 4, 5, 7, 8 and parts of 12 check their results only with DEBUGASSERT(). That expands to ((void)(1 || (f))) without CONFIG_DEBUG_ASSERTIONS, so in those builds the tests always "PASS". The existing code in this file uses ASSERT(), or returns -1 the way the tests already do on allocation failure. Please do the same.

Tests that check nothing. Test 9 (tailroom) and most of Test 6 (pack/contig/reserve) only print values. For example, check iob_tailroom() against IOB_BUFSIZE(iob) - 50 after the copy-in, check io_offset == 10 after iob_reserve(), and verify the data after iob_pack().

Smaller things:

  • Test 1 assumes nothing else allocates IOBs between iob_navail() calls. With networking active, that's racy.
  • Test 10 error paths: when removed is non-NULL but not the expected chain, it is leaked (goto cleanup only frees the queue). Test 10 also prints "expected 4" for the entry count without checking it.
  • print_iob_queue() / Test 10 print non-ASCII characters (└─>, ✓), which garble on many serial consoles. Please use ASCII.
  • <setjmp.h> and <stdarg.h> are unused.
  • test_iob_queue_extend_tail() ("Test 12") sits between Test 8 and Test 9 in the file. Please move it into numeric order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants