Skip to content

Conversation

@extinguish
Copy link
Contributor

Summary

Extend LTP (Linux Test Project) support on NuttX to enable compilation and execution of Linux kernel testcases, adding necessary infrastructure for kernel‑level API validation:

  1. Add Linux‑compatible loop device API – Define struct loop_info and LOOP_* ioctl constants in testing/ltp/include/linux/loop.h, allowing LTP loop‑device testcases to build and run when CONFIG_DEV_LOOP=y.
  2. Fix kernel‑test build errors – Exclude nftw64 from the kernel‑test blacklist to prevent duplicate‑symbol linker conflicts (__odr_asan.*) between nftw.c and nftw64.c, ensuring clean linking of the kernel test suite.
  3. Continue kernel‑test framework expansion – Build out the LTP kernel‑test CMake infrastructure with proper header stubs, syscall mapping, and feature configuration to support kernel‑level test execution.

Impact

  1. Enables LTP Linux kernel testcases – Allows NuttX to compile and run LTP tests that exercise kernel‑level APIs (device drivers, filesystems, syscalls, etc.), significantly expanding system validation coverage.
  2. Resolves build‑time conflicts – Fixes symbol‑duplication errors that previously blocked kernel‑test linking.

Testing

  1. Verified that LTP Linux kernel testcases now build successfully without missing‑header or duplicate‑symbol errors.
  2. Confirmed that loop‑device tests compile and link when CONFIG_DEV_LOOP is enabled.

Major enhancements to LTP build system:
- Split CMakeLists.txt into shared/posix/kernel sections with unified blacklisting
- Add header stubs (linux/*.h, asm/*.h, lapi/*.h) for kernel test dependencies
- Implement syscalls.h generation via regen.sh for NuttX syscall mapping
- Define feature macros (HAVE_*, UNIT_TEST) and compiler flags for kernel tests
- Resolve naming conflicts (safe_* functions) with macro renaming

This enables LTP kernel test execution on NuttX, covering syscalls, filesystem,
device drivers, and scheduler tests.

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
Define the complete loop_info structure and LOOP_* ioctl command constants
in testing/ltp/include/linux/loop.h, matching Linux kernel's loop device
interface. This allows LTP loop device testcases to build and execute
when NuttX loop device support (CONFIG_DEV_LOOP) is available.

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
For the NuttX platform, the system call numbers themselves
are independent of the architecture(arm/x86/risc-v).
Therefore, there is no need to consider the differences
between different architectures(arm/x86/risc-v).
As a result, we can directly maintain them manually instead
of relying on the regen.sh script to generate them
dynamically. This makes it easier for maintenance, upgrading,
and modification.

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
for kernel testcases that using main() method to execute, when invoke
tst_exit() on execute finished, will report " executed from newlib!"
error, this is caused by two kinds kernel testcases are forbidded linked
together, in Linux this is OK, but for NuttX, this is necssary, so we
choose to modify the NO_NEWLIB_ASSERT macro's implementation, thus to
make kernel testcases can work in NuttX

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
blacklist nftw64 to resolve symbol duplication errors,
the following are the detailed link error info:
```
/usr/bin/ld: /home/testing/vela/cmake_out/vela_vela/apps/testing/ltp/libapps_ltp_syscalls_nftw_nftw64.a(nftw64.c.o):(.bss.__odr_asan.next_fd+0x0): multiple definition of `__odr_asan.next_fd'; /home/testing/vela/cmake_out/vela_vela/apps/testing/ltp/libapps_ltp_syscalls_nftw_nftw.a(nftw.c.o):(.bss.__odr_asan.next_fd+0x0): first defined here
/usr/bin/ld: /home/testing/vela/cmake_out/vela_vela/apps/testing/ltp/libapps_ltp_syscalls_nftw_nftw64.a(nftw64.c.o):(.bss.__odr_asan.visit+0x0): multiple definition of `__odr_asan.visit'; /home/testing/vela/cmake_out/vela_vela/apps/testing/ltp/libapps_ltp_syscalls_nftw_nftw.a(nftw.c.o):(.bss.__odr_asan.visit+0x0): first defined here
/usr/bin/ld: /home/testing/vela/cmake_out/vela_vela/apps/testing/ltp/libapps_ltp_syscalls_nftw_nftw64.a(nftw64.c.o):(.bss.__odr_asan.dirlist+0x0): multiple definition of `__odr_asan.dirlist'; /home/testing/vela/cmake_out/vela_vela/apps/testing/ltp/libapps_ltp_syscalls_nftw_nftw.a(nftw.c.o):(.bss.__odr_asan.dirlist+0x0): first defined here
/usr/bin/ld: /home/testing/vela/cmake_out/vela_vela/apps/testing/ltp/libapps_ltp_syscalls_nftw_nftw64.a(nftw64.c.o):(.bss.__odr_asan.ebuf+0x0): multiple definition of `__odr_asan.ebuf'; /home/testing/vela/cmake_out/vela_vela/apps/testing/ltp/libapps_ltp_syscalls_nftw_nftw.a(nftw.c.o):(.bss.__odr_asan.ebuf+0x0): first defined here
/usr/bin/ld: /home/testing/vela/cmake_out/vela_vela/apps/testing/ltp/libapps_ltp_syscalls_nftw_nftw64.a(nftw64.c.o):(.bss.__odr_asan.s2+0x0): multiple definition of `__odr_asan.s2'; /home/testing/vela/cmake_out/vela_vela/apps/testing/ltp/libapps_ltp_syscalls_nftw_nftw.a(nftw.c.o):(.bss.__odr_asan.s2+0x0): first defined here
/usr/bin/ld: /home/testing/vela/cmake_out/vela_vela/apps/testing/ltp/libapps_ltp_syscalls_nftw_nftw64.a(nftw64.c.o):(.bss.__odr_asan.temp+0x0): multiple definition of `__odr_asan.temp'; /home/testing/vela/cmake_out/vela_vela/apps/testing/ltp/libapps_ltp_syscalls_nftw_nftw.a(nftw.c.o):(.bss.__odr_asan.temp+0x0): first defined here
```

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
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.

2 participants