Repository navigation
fix[utest]: reset finish flags in the mailbox testcase so it can run twice - #11963
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: kernelReviewers: @GorrayLi @ReviewSun @hamburger-os @lianux-mm @wdfk-prog @xu18838022837 Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-11-02 15:53 CST)
📝 Review Instructions
|
|
独立复现了一遍,现象和根因都对得上。补一组"第一次 / 第二次"的干净对照数据。 环境
复现方式msh 里分两次执行 结果第一次: 第二次: 断言原文是 根因确认:是四个标志没清/* mailbox_tc.c:60-61 */
static uint8_t static_mb_recv_thread_finish, static_mb_send_thread_finish;
static uint8_t dynamic_mb_recv_thread_finish, dynamic_mb_send_thread_finish;它们只在工作线程里置 1( 第二次运行时, 与 #11963 里 一个可能影响别人复现的坑
我第一次就是这么踩的:自动运行先跑了一次 PASSED,然后我的第一次手动运行就 FAILED 了。要拿到干净对照,需要同时确认 复现用的临时 app 没有提交,需要的话我可以整理成 |
|
感谢独立复现,根因和改法能对上就很难得 👍 关于 你的提醒很有价值 —— 我把它当成"复现前提"记下来了:如果 CI_ACTION/自动运行开着,开机那次会消耗掉"第一次" 另外:我已经把这个分支合到最新 master(现在是 你那个"临时 app 调用 |
|
@codex review |
|
utest的命令是支持某个测试用例运行多次的。可以试试给ci的utest run加个参数,冒烟测试几次看看结果,过程中也通过ps/free命令观测到内存泄漏等问题 |
|
|
@sexenteen 注意下,下次的PR记得变基到master分支,要不然会多出一笔commit,这次我先压缩合并下了 |
|
收到,感谢提醒!后续 PR 我会用 关于你提的 utest 重复运行:我确认过 这个任务我接下来做,打算这样实现:
我先按这个思路做,方案有问题的话你直接说,我按你的意见调整。 |
|
按你的建议做了,提了 #11983(feat[utest]: repeat the automatic run and sample free/ps between loops)。 做法:
qemu-vexpress-a9 上跑 3 轮验证过:三轮 |
|
你提的"把重复运行做成自动化"这件事,#11983 已经落地了,我拿它跑了一轮,第一个成果就出来了:提了 #12033。 确认你修的那个用例已经可以重复运行
但多轮一开,别的用例的泄漏就露出来了我按"用例名 / 第一轮 / 第二轮 / 第三轮"的格式扫了一遍,堆占用是这样的( 恒定 +64,看着像"某个小对象没删"。但把 根因是 和其他用例混跑时,中间的用例会让 idle 拿到 CPU,线程被回收了,于是只剩信号量那 64 字节。 这件事和方法论有关同一个缺陷,单独跑测出来是 25 KB/轮,混跑测出来是 64 B/轮。如果只做"全套跑两轮"的对比,很可能会把它当成 64 字节的噪声放过去;反过来如果只单独跑某个用例,又会误以为"泄漏很严重但原因不明"。 所以我在 #12033 里两边的数据都给了。修法是 顺带验证了采样本身不泄漏我把 关于我原来那个临时 app你说的"整理成 |
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
Fixes #6565 (the remaining half - see the note at the end).
core.ipc_mailboxfails when it is run a second time in the same boot. Reproduced onbsp/qemu-vexpress-a9withRT_USING_UTESTCASES=yandRT_UTEST_MAILBOX=y:Cause: the four
*_thread_finishflags are only ever set to 1 by the worker threads, nevercleared. On the second run the test body's wait loop
falls through immediately, so
rt_mb_detach()is called while the worker threads started bythis run are still blocked in
rt_mb_recv(). They are then resumed with an error and keepusing a mailbox that has already been detached, which trips the object-type assertion in
_rt_mb_recv(). The dynamic variant has the same pattern and would fail the same way.你的解决方案是什么 (what is your solution)
Clear the flags in
utest_tc_init(), which the utest framework calls before each run of thetestcase:
Only
src/utest/mailbox_tc.cis touched (+11/-0). This matches what has already been said in#6565: part of the testcases were written without considering that they can be executed twice,
leaving variables/resources not reset or released.
请提供验证的bsp和config (provide the config and bsp)
CONFIG_RT_USING_UTESTCASES=y,CONFIG_RT_UTEST_MAILBOX=y(enabled temporarily forthis verification; the BSP configuration itself is not part of this PR)
Verification (
utest_run core.ipc_mailboxexecuted three times in one session, after the fix):The same build without the fix fails on run 2 as shown above.
scons -j4passes andtools/ci/clang_format_check.pyreports "clang-format check success" for the changed file.Not covered: other BSPs / real hardware (only qemu-vexpress-a9 was tested), and running the
whole utest suite (
utest_runwithout arguments) - only the mailbox testcase was exercised.Note on the rest of #6565: the other reported problem,
thread_tc.c'stest_thread_suspendsuspending another thread (which hits
RT_ASSERT(thread == rt_thread_self())), was alreadyconfirmed by the maintainers as a testcase problem and that test is already disabled, so it is
not touched here.
]
当前拉取/合并请求的状态 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 up