-
Notifications
You must be signed in to change notification settings - Fork 5.2k
utest: re-org utest framework (initial version) #10534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
@Yaochenger @kurisaW 请 review。 |
📌 Code Review Assignment🏷️ Tag: componentsReviewers: Maihuanyi Changed Files (Click to expand)
🏷️ Tag: kernelReviewers: GorrayLi ReviewSun hamburger-os lianux-mm wdfk-prog xu18838022837 Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2025-07-25 15:35 CST)
📝 Review Instructions
|
a15c073
to
84bad87
Compare
改了,但是 ci 又报了其他的错误 :( |
修改建议:
建议修改为:
将rsource "$RTT_DIR替换为source "$(RTT_DIR) |
7be5936
to
d23006e
Compare
9a92ff8
to
1d38849
Compare
Change the entry of utest's Kconfig from examples/utest/testcases/Kconfig to components/utilities/utest/Kconfig. In the future, the testcase source code of utest will be placed in each module for maintenance, but the entry of Kconfig will all be placed in components/utilities/utest/Kconfig for unified maintenance. In this way, when executing menuconfig, people can enter and configure from one place, avoiding searching for utest configuration switches here and ther in the menuconfig interface. For each module, you can maintain unit-test in a unified manner in the following way: - Create a subdirectory named 'utest' in the directory where your module is located. - Store the following files in the utest subdirectory: - Unit test case program source code files for this module. - Kconfig file, add configuration options for the unit test files of this module, the recommended option is named RT_UTEST_TC_USING_XXXX, XXXX is the global unique module name of this module. - SConscript file, note that when adding src files, in addition to relying on RT_UTEST_TC_USING_XXXX, you must also rely on RT_UTEST_USING_ALL_CASES, the two dependencies are in an "or" relationship. The role of RT_UTEST_USING_ALL_CASES is that once this option is turned on, all unit tests will be enabled to avoid selecting one by one. Signed-off-by: Chen Wang <[email protected]>
Signed-off-by: Chen Wang <[email protected]>
Signed-off-by: Chen Wang <[email protected]>
1d38849
to
92aa975
Compare
我发现导致 dist 的 ci 失败的原因是在于运行 def bsp_update_kconfig_testcases(dist_dir):
# delete testcases in rt-thread/Kconfig
if not os.path.isfile(os.path.join(dist_dir, 'rt-thread/Kconfig')):
return
with open(os.path.join(dist_dir, 'rt-thread/Kconfig'), 'r') as f:
data = f.readlines()
with open(os.path.join(dist_dir, 'rt-thread/Kconfig'), 'w') as f:
for line in data:
if line.find('examples/utest/testcases/Kconfig') == -1:
f.write(line) 会跳过 cd bsp/stm32/stm32f407-atk-explorer/
scons --dist
cd dist/project/rt-thread/
scons --menuconfig
scons: Reading SConscript files ...
menuconfig: rt-thread/components/utilities/utest/Kconfig:10: 'rt-thread/components/utilities/utest/../../../examples/utest/testcases/utest/Kconfig' not found (in 'rsource "../../../examples/utest/testcases/utest/Kconfig"'). Check that environment variables are set correctly (e.g. $srctree, which is unset or blank). Also note that unset environment variables expand to the empty string. 但具体原因不知道是否有人可以解释一下, dist 中这里这么做的目的是什么,我发现在 dist 后的 这实际上存在一个悖论,就是以后 utest 的内容我们在 dist 中是否需要保留?因为以后的设计思路是 utest 的 testcase 都会放到各个模块自己的目录下,不像现在都是放在 example 的 utest 下,所以我不清楚当时设计 dist 时是怎么考虑这个问题的。如果沿袭原来的思路,utest 的testcase 是不参与 dist 的,但是按照我现在的思路,utest 作为每个模块的组成部分,和 example 不是一回事情。dist 时我理解是需要和模块一起打包的。 此外,我发现和 bsp_update_kconfig_testcases 类似的处理还有一处,就是 tools/env_utility.py 中的 exclude_utestcases 函数。摘录如下: # Exclude utestcases
def exclude_utestcases(RTT_ROOT):
if os.path.isfile(os.path.join(RTT_ROOT, 'examples/utest/testcases/Kconfig')):
return
if not os.path.isfile(os.path.join(RTT_ROOT, 'Kconfig')):
return
with open(os.path.join(RTT_ROOT, 'Kconfig'), 'r') as f:
data = f.readlines()
with open(os.path.join(RTT_ROOT, 'Kconfig'), 'w') as f:
for line in data:
if line.find('examples/utest/testcases/Kconfig') == -1:
f.write(line) 这里也有类似的逻辑,搜索 exclude_utestcases 的调用处,分别是在 tools/env_utility.py 中的 menuconfig/guiconfig/defconfig 三处,目前还不清楚这里是何目的? |
我个人猜测example原本的目的是不应该参与构建的(除了utest目录,其余似乎看起来都没有加构建脚本),仅作为一个参考设计,因此在dist中会被排除构建,所以起初utest被放到example中就是不合理的,建议直接放到如下路径,后面再慢慢推动utest的分布式构建: components/utilities/utest 另外针对你的解决方法,我持赞同意见:
|
我也同意这种改法,将example中的部分逐渐分布到各个目录下面,dist出的工程也可也保留测试用例内容 |
具体需求来源参考:#10513。
本 PR 是本工作的第一步,主要做了如下工作:
将 utest 的 Kconfig 的入口从
examples/utest/testcases/Kconfig
改为components/utilities/utest/Kconfig
。单元测试对于内核来说是一个非常重要的模块,放在 examples 下不合适。以后的 utest 的 testcase 源码会分别放到各个模块下自己维护,但是 Kconfig 的入口会放在
components/utilities/utest/Kconfig
中统一维护。这样在执行诸如 menuconfig 时可以统一从一个地方进入进行配置,避免在 menuconfig 界面中到处寻找 utest 的配置开关。对于各个模块来说,以后可以按照如下方式统一维护单元测试用例:
utest
的子目录RT_UTEST_TC_USING_XXXX
,XXXX 为本模块的全局唯一模块名。RT_UTEST_TC_USING_XXXX
还要依赖RT_UTEST_USING_ALL_CASES
,两者是 or 的关系。RT_UTEST_USING_ALL_CASES
的作用是一旦打开这个选项,则所有的单元测试都会启用,避免逐个选择。目前整个内核源码树下基于 utest 框架实现的单元测试,除了
examples/utest/testcases
外,只有components/drivers/audio/utest/
和src/klibc/utest/
两处,本 PR 将这两处的 Kconfig 选项也集成到components/utilities/utest/Kconfig
下。注意:本 PR 并没有将
examples/utest/testcases
下的 c 源码挪到他们该属于的模块下去,这部分工作将作为后续工作逐渐展开。本 PR 为方便 review,分为三个 commit:
examples/utest/testcases/Kconfig
改为components/utilities/utest/Kconfig
。src/klibc/utest/
的 Kconfig 选项也集成到components/utilities/utest/Kconfig
下。components/drivers/audio/utest/
的 Kconfig 选项也集成到components/utilities/utest/Kconfig
下。