cederom commented on PR #4136:
URL: https://github.com/apache/nuttx-apps/pull/4136#issuecomment-7247645266

   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:
   
   ```make
   ifeq ($(CONFIG_ARCH_TOOLCHAIN_CLANG)$(CONFIG_ARCH_TOOLCHAIN_ARMCLANG),)
   CFLAGS += -Wno-use-after-free -Wno-stringop-overflow
   endif
   ```
   
   ```cmake
   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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to