test[CI][littlefs]: add RT-Thread QEMU smoke coverage#36
Conversation
add DFS v2 mount, dentry, vnode and filesystem type registration paths for littlefs centralize DFS ABI differences across DFS v2, RT-Thread 5.x DFS v1 and legacy DFS layouts adapt read/write/lseek signatures and explicit offset handling for DFS v2 keep legacy DFS v1 behavior through compatibility macros verify basic build and QEMU littlefs DFS v2 smoke flow on bsp/qemu-vexpress-a9
avoid copying DFS_PATH_MAX bytes into struct dirent d_name use the actual d_name buffer size when filling littlefs directory entries keep d_namlen consistent with the copied name length after truncation fix stack corruption observed when listing littlefs directories on DFS v2
add RT-Thread qemu-vexpress-a9 compile checks for littlefs DFS profiles cover legacy DFS, RT-Thread 5.x DFS v1, DFS v2, and master builds reuse a prepared RT-Thread checkout across profile builds to reduce repeated downloads upload per-profile build logs for CI failure diagnosis
WalkthroughThis PR refactors dfs_lfs.c to support DFS v1/v2 ABIs and adds end-to-end CI: a composite action to set up toolchain/env, a build script that clones/prepares RT-Thread and runs SCons, a GitHub Actions workflow, pinned CI Python deps, QEMU MTD emulation, and smoke-test applications. ChangesDFS/LittleFS Multi-ABI Support & CI Integration
Sequence DiagramsequenceDiagram
actor User
participant GH as GitHub Actions
participant Cache as Cache/Artifacts
participant Action as setup-rtthread-build
participant Build as build.sh
participant RTT as RT-Thread
participant QEMU as QEMU Emulator
User->>GH: push / open PR / dispatch
GH->>Action: run composite action (setup toolchain/env)
Action->>Cache: restore ARM GCC cache
alt cache miss
Action->>Cache: download+verify toolchain -> install
end
GH->>Build: invoke build.sh
Build->>RTT: prepare sources / copy package / apply Kconfig
Build->>RTT: run SCons -> produce ELF
Build->>Build: verify ELF symbols
alt rtthread-run-smoke enabled
Build->>QEMU: launch emulator
QEMU->>QEMU: run littlefs_smoke_run (write/read/list/remount)
QEMU-->>Build: emit PASS/FAIL marker in log
Build->>QEMU: stop emulator
end
Build->>Cache: upload logs/artifacts
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
.github/ci/rtthread-littlefs/smoke/qemu_lfs_mtd.c (1)
73-86: ⚡ Quick winAlign macro guards with
dfs_lfs.cpattern for consistency.Lines 73 and 82 use
RT_VERSION_CHECKwithout adefined(RT_VERSION_CHECK)guard, whiledfs_lfs.cin the same codebase consistently wraps similar checks. Consider adding the guard for defensive programming consistency, even thoughRT_VERSION_CHECKis defined in all tested RT-Thread versions (v4.1.1 and later).Suggested fix
-#if RTTHREAD_VERSION >= RT_VERSION_CHECK(5, 0, 0) +#if defined(RT_VERSION_CHECK) && (RTTHREAD_VERSION >= RT_VERSION_CHECK(5, 0, 0)) typedef rt_ssize_t qemu_lfs_mtd_rw_ret_t; `#else` typedef rt_size_t qemu_lfs_mtd_rw_ret_t; -#endif /* RTTHREAD_VERSION >= RT_VERSION_CHECK(5, 0, 0) */ +#endif /* defined(RT_VERSION_CHECK) && (RTTHREAD_VERSION >= RT_VERSION_CHECK(5, 0, 0)) */ /** * `@brief` Length type used by RT-Thread MTD NOR callbacks. */ -#if RTTHREAD_VERSION >= RT_VERSION_CHECK(5, 0, 0) +#if defined(RT_VERSION_CHECK) && (RTTHREAD_VERSION >= RT_VERSION_CHECK(5, 0, 0)) typedef rt_size_t qemu_lfs_mtd_len_t; `#else` typedef rt_uint32_t qemu_lfs_mtd_len_t; -#endif /* RTTHREAD_VERSION >= RT_VERSION_CHECK(5, 0, 0) */ +#endif /* defined(RT_VERSION_CHECK) && (RTTHREAD_VERSION >= RT_VERSION_CHECK(5, 0, 0)) */🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/ci/rtthread-littlefs/smoke/qemu_lfs_mtd.c around lines 73 - 86, The RT_VERSION_CHECK macro uses should be guarded like in dfs_lfs.c to avoid undefined-macro issues: update the two typedef conditionals around qemu_lfs_mtd_rw_ret_t and qemu_lfs_mtd_len_t to use a combined preprocessor check (e.g., `#if` defined(RT_VERSION_CHECK) && RTTHREAD_VERSION >= RT_VERSION_CHECK(5, 0, 0)) and keep the existing else branches unchanged so behavior is identical when RT_VERSION_CHECK is unavailable.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/actions/setup-rtthread-build/action.yml:
- Around line 21-24: Change the input name and verification algorithm from MD5
to SHA-256: rename the input key arm-gcc-md5 to arm-gcc-sha256, update its
description to say "Expected SHA-256 checksum for the ARM GCC toolchain
archive", and replace the default MD5 hex with the correct SHA-256 hex. Then
update all places that reference arm-gcc-md5 (workflow steps, scripts, and
checksum checks) to use arm-gcc-sha256 and change the verification command to
use sha256sum (or an equivalent SHA-256 check) instead of md5sum so the CI
actually verifies using SHA-256.
In @.github/ci/rtthread-littlefs/build.sh:
- Around line 667-683: Wrap the blocking git clone in a timeout so stalled
clones don't hang the retry loop: replace the plain git clone call inside the
while loop with a timed invocation such as timeout --preserve-status
"$CLONE_TIMEOUT" git clone --depth 1 --branch "$rtthread_ref"
https://github.com/RT-Thread/rt-thread.git "$rtthread_dir" and ensure a sensible
default CLONE_TIMEOUT is defined (e.g. export
CLONE_TIMEOUT="${CLONE_TIMEOUT:-300}") so the loop reacts to timeout failures
and proceeds to the rm -rf / retry logic and ultimately calls fail if all
attempts exhaust.
In `@dfs_lfs.c`:
- Around line 1249-1255: The _dfs_lfs_dentry_rename handler currently always
calls _dfs_lfs_rename using old_dentry->mnt and will forward
new_dentry->pathname into the wrong FS when the destination is on a different
mount; modify _dfs_lfs_dentry_rename to compare old_dentry->mnt and
new_dentry->mnt and if they differ return -EXDEV, otherwise call
_dfs_lfs_rename(old_dentry->mnt, old_dentry->pathname, new_dentry->pathname).
Ensure you reference the dfs_dentry struct fields mnt and pathname and return
the POSIX cross-device error -EXDEV for cross-mount renames.
- Around line 1135-1147: The code currently converts offset into an unsigned
directory index before calling lfs_dir_seek, which permits negative or unaligned
offsets to wrap or desynchronize; before computing off and calling lfs_dir_seek
(in the DFS_LFS_FILE_TYPE(file) == FT_DIRECTORY branch), validate offset is
non-negative and aligned to sizeof(struct dirent) and return -EINVAL if not;
then compute off = offset / sizeof(struct dirent) and call lfs_dir_seek as
before, ensuring any casts to lfs_off_t/lfs_soff_t are done after the
validation.
---
Nitpick comments:
In @.github/ci/rtthread-littlefs/smoke/qemu_lfs_mtd.c:
- Around line 73-86: The RT_VERSION_CHECK macro uses should be guarded like in
dfs_lfs.c to avoid undefined-macro issues: update the two typedef conditionals
around qemu_lfs_mtd_rw_ret_t and qemu_lfs_mtd_len_t to use a combined
preprocessor check (e.g., `#if` defined(RT_VERSION_CHECK) && RTTHREAD_VERSION >=
RT_VERSION_CHECK(5, 0, 0)) and keep the existing else branches unchanged so
behavior is identical when RT_VERSION_CHECK is unavailable.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 489be611-da60-4f28-b0a8-7b939a837a43
📒 Files selected for processing (8)
.github/actions/setup-rtthread-build/action.yml.github/ci/rtthread-littlefs/build.sh.github/ci/rtthread-littlefs/requirements.txt.github/ci/rtthread-littlefs/smoke/littlefs_compile_check.c.github/ci/rtthread-littlefs/smoke/littlefs_smoke.c.github/ci/rtthread-littlefs/smoke/qemu_lfs_mtd.c.github/workflows/rtthread.ymldfs_lfs.c
| arm-gcc-md5: | ||
| description: Expected MD5 checksum for the ARM GCC toolchain archive. | ||
| required: false | ||
| default: 2383e4eb4ea23f248d33adc70dc3227e |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
cat -n .github/actions/setup-rtthread-build/action.ymlRepository: RT-Thread-packages/littlefs
Length of output: 9548
Use SHA-256 instead of MD5 for the toolchain archive check.
The downloaded compiler is a high-trust artifact in the CI supply chain. MD5 is cryptographically broken and should not be used for integrity verification of build tools, as it cannot guarantee protection against intentional modification.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/actions/setup-rtthread-build/action.yml around lines 21 - 24, Change
the input name and verification algorithm from MD5 to SHA-256: rename the input
key arm-gcc-md5 to arm-gcc-sha256, update its description to say "Expected
SHA-256 checksum for the ARM GCC toolchain archive", and replace the default MD5
hex with the correct SHA-256 hex. Then update all places that reference
arm-gcc-md5 (workflow steps, scripts, and checksum checks) to use arm-gcc-sha256
and change the verification command to use sha256sum (or an equivalent SHA-256
check) instead of md5sum so the CI actually verifies using SHA-256.
- add QEMU littlefs smoke sources for RT-Thread BSP validation - split RT-Thread tag and master checks into separate GitHub Actions matrix jobs - add RT-Thread source archive/cache handling to reduce repeated clone cost - run compile and smoke verification against qemu-vexpress-a9 DFS v1/v2 profiles
reject cross-mount dentry rename with -EXDEV before using the old mount context validate directory lseek offsets before converting them to littlefs directory positions return -EINVAL for negative or non-dirent-aligned directory offsets
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
.github/actions/setup-rtthread-build/action.yml (1)
21-24:⚠️ Potential issue | 🟠 Major | ⚡ Quick winMD5 integrity check still flagged.
The
arm-gcc-md5input and correspondingmd5sum -cverification at line 201 still rely on MD5 for a high-trust build artifact. SHA-256 is the appropriate algorithm here; ARM publishes SHA-256 sums alongside the toolchain archives.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/actions/setup-rtthread-build/action.yml around lines 21 - 24, The workflow still uses MD5: update the action input and verification to SHA-256 by renaming the input arm-gcc-md5 to arm-gcc-sha256 (and update its description), replace any md5sum -c usage with sha256sum -c in the verification step (the place currently invoking md5sum -c), and replace the default checksum value with the published SHA-256 for the ARM GCC archive so the integrity check uses SHA-256 end-to-end.
🧹 Nitpick comments (2)
.github/workflows/rtthread.yml (1)
70-77: 💤 Low valueSet a short
retention-dayson the inter-job source artifact.
rtthread-master-sourceis only consumed bytest-littlefs-masterin the same run, but defaults to 90-day retention. Settingretention-days: 1(or a similar small value) avoids accumulating large tarballs in the repository's artifact storage.♻️ Proposed change
- name: Upload RT-Thread master source uses: actions/upload-artifact@v4 with: name: rtthread-master-source path: | _ci/artifacts/rt-thread-master.tar _ci/artifacts/rt-thread-master.sha if-no-files-found: error + retention-days: 1🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/workflows/rtthread.yml around lines 70 - 77, The artifact upload step "Upload RT-Thread master source" currently leaves artifacts with the default retention and should be updated to avoid long-term storage; add a retention-days field under the step's with block (for the artifact named rtthread-master-source) — e.g., add retention-days: 1 so the actions/upload-artifact@v4 invocation that publishes rtthread-master-source keeps the tarball only for the short desired period..github/ci/rtthread-littlefs/smoke/qemu_lfs_mtd.c (1)
25-29: 💤 Low valueDrop the unused
lfsrootMTD instance.Only
lfsnoris consumed bylittlefs_smoke.c; thelfsrootdevice is registered, zero-filled, and never mounted. Each instance carries a 512 KiB staticstorage[]buffer in BSS, so this wastes ~512 KiB and adds maintenance noise. ReduceQEMU_LFS_MTD_DEVICE_COUNTto 1 and drop thelfsrootentry unless a future test plans to use it.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/ci/rtthread-littlefs/smoke/qemu_lfs_mtd.c around lines 25 - 29, Remove the unused "lfsroot" MTD instance and shrink the static device table to only the used "lfsnor" entry: update QEMU_LFS_MTD_DEVICE_COUNT from 2 to 1 and change the qemu_lfs_mtd_devices initializer to contain just { .name = "lfsnor" }; ensure any code that iterates or indexes qemu_lfs_mtd_devices still respects the new count (symbols: QEMU_LFS_MTD_DEVICE_COUNT, qemu_lfs_mtd_devices, "lfsroot", "lfsnor", and any consumers such as littlefs_smoke.c).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/ci/rtthread-littlefs/smoke/littlefs_smoke.c:
- Around line 270-274: The mkdir call creating LFS_SMOKE_DIR uses mode 0 which
yields no permission bits; change the mode passed to mkdir in the littlefs_smoke
setup to a sensible permission like 0755 so the directory is created
readable/executable by owner/group/others and subsequent filesystem layers can
traverse it; update the call that currently returns
littlefs_smoke_fail("mkdir-dir", ret) on error (the mkdir invocation referencing
LFS_SMOKE_DIR) to use 0755 as the mode argument.
---
Duplicate comments:
In @.github/actions/setup-rtthread-build/action.yml:
- Around line 21-24: The workflow still uses MD5: update the action input and
verification to SHA-256 by renaming the input arm-gcc-md5 to arm-gcc-sha256 (and
update its description), replace any md5sum -c usage with sha256sum -c in the
verification step (the place currently invoking md5sum -c), and replace the
default checksum value with the published SHA-256 for the ARM GCC archive so the
integrity check uses SHA-256 end-to-end.
---
Nitpick comments:
In @.github/ci/rtthread-littlefs/smoke/qemu_lfs_mtd.c:
- Around line 25-29: Remove the unused "lfsroot" MTD instance and shrink the
static device table to only the used "lfsnor" entry: update
QEMU_LFS_MTD_DEVICE_COUNT from 2 to 1 and change the qemu_lfs_mtd_devices
initializer to contain just { .name = "lfsnor" }; ensure any code that iterates
or indexes qemu_lfs_mtd_devices still respects the new count (symbols:
QEMU_LFS_MTD_DEVICE_COUNT, qemu_lfs_mtd_devices, "lfsroot", "lfsnor", and any
consumers such as littlefs_smoke.c).
In @.github/workflows/rtthread.yml:
- Around line 70-77: The artifact upload step "Upload RT-Thread master source"
currently leaves artifacts with the default retention and should be updated to
avoid long-term storage; add a retention-days field under the step's with block
(for the artifact named rtthread-master-source) — e.g., add retention-days: 1 so
the actions/upload-artifact@v4 invocation that publishes rtthread-master-source
keeps the tarball only for the short desired period.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3af99aa9-59b4-43d4-986d-e316627f5114
📒 Files selected for processing (8)
.github/actions/setup-rtthread-build/action.yml.github/ci/rtthread-littlefs/build.sh.github/ci/rtthread-littlefs/requirements.txt.github/ci/rtthread-littlefs/smoke/littlefs_compile_check.c.github/ci/rtthread-littlefs/smoke/littlefs_smoke.c.github/ci/rtthread-littlefs/smoke/qemu_lfs_mtd.c.github/workflows/rtthread.ymldfs_lfs.c
🚧 Files skipped from review as they are similar to previous changes (1)
- dfs_lfs.c
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
当前 RT-Thread littlefs 包 CI 主要覆盖多版本编译检查,缺少在 QEMU BSP 上执行 littlefs 文件系统基本读写、目录遍历和卸载重挂载流程的自动化 smoke test。
该 PR 增加 qemu-vexpress-a9 场景下的 littlefs smoke test,并将 RT-Thread tag 与 master 的测试拆分为独立矩阵任务,提升 CI 覆盖度和失败定位效率。
你的解决方案是什么 (what is your solution)
.github/ci/rtthread-littlefs/build.sh中增加可选的RTTHREAD_RUN_SMOKE流程。.github/workflows/rtthread.yml拆分为 tag profile 和 master profile 两类 job,并加入 ARM GCC、Python 依赖、RT-Thread source 和 QEMU 相关准备步骤。.github/ci/rtthread-littlefs/requirements.txt固定kconfiglib与scons版本。请提供验证的bsp和config (provide the config and bsp)
BSP:
bsp/qemu-vexpress-a9.config:
RTTHREAD_DFS_VERSION=v1RTTHREAD_DFS_VERSION=v2RTTHREAD_RUN_SMOKE=1RT_USING_DFSDFS_USING_POSIXDFS_USING_WORKDIRRT_USING_DFS_DEVFSRT_USING_DFS_ROMFSRT_USING_DFS_TMPFSRT_USING_MTD_NORPKG_USING_LITTLEFSRT_USING_DFS_V1或RT_USING_DFS_V2action: 本地输入中未提供可引用的 GitHub Actions 成功链接;提交 PR 前请替换为当前 PR 分支对应的成功 workflow 链接。
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned upSummary by CodeRabbit